Skip to content

Commit 9cc08f1

Browse files
committed
Add eslint, refactor code
1 parent de8dea3 commit 9cc08f1

File tree

3 files changed

+46
-38
lines changed

3 files changed

+46
-38
lines changed

.eslintrc.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
extends: ryanzim
2+
env:
3+
node: true
4+
es6: true
5+
rules:
6+
no-console: off

cli.js

Lines changed: 34 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,7 @@ findPkg()
5252
if (!val) {
5353
console.log('Deleting script.');
5454
delete scripts[script];
55-
} else {
56-
scripts[script] = val;
57-
}
55+
} else scripts[script] = val;
5856
return fs.writeJson(pkgPath, pkg);
5957
});
6058
})
@@ -64,23 +62,8 @@ findPkg()
6462
});
6563

6664
function getScriptName() {
67-
if (script) {
68-
// Verify creation if the script does not exist:
69-
return inquirer.prompt([
70-
{
71-
type: 'confirm',
72-
name: 'create',
73-
message: `The script "${script}" does not exist. Create it?`,
74-
when: !scripts[script],
75-
},
76-
])
77-
.then(function (answers) {
78-
if (!answers.create) {
79-
console.log('Aborting');
80-
process.exit();
81-
}
82-
});
83-
} else {
65+
if (script && !scripts[script]) return confirmCreation();
66+
else {
8467
// Get choices:
8568
var choices = Object.keys(scripts).map(function (key) {
8669
return {
@@ -110,36 +93,50 @@ function getScriptName() {
11093
])
11194
.then(function (answers) {
11295
switch (answers.script) {
113-
case NEW_SCRIPT_SYMBOL:
96+
case NEW_SCRIPT_SYMBOL:
11497
// Get script name:
115-
return inquirer.prompt([{
116-
type: 'input',
117-
name: 'name',
118-
message: 'Enter the script name:',
119-
validate: function (val) {
120-
if (!val) return 'Script name must not be empty';
121-
else return true;
122-
},
123-
}])
98+
return inquirer.prompt([{
99+
type: 'input',
100+
name: 'name',
101+
message: 'Enter the script name:',
102+
validate: function (val) {
103+
if (!val) return 'Script name must not be empty';
104+
else return true;
105+
},
106+
}])
124107
.then(function (answers) {
125108
// Set it:
126109
script = answers.name;
127110
});
128-
case EXIT_SYMBOL:
129-
process.exit();
130-
default:
131-
script = answers.script;
111+
case EXIT_SYMBOL:
112+
return process.exit();
113+
default:
114+
script = answers.script;
132115
}
133116
});
134117
}
135118
}
136119

120+
function confirmCreation() {
121+
return inquirer.prompt([
122+
{
123+
type: 'confirm',
124+
name: 'create',
125+
message: `The script "${script}" does not exist. Create it?`,
126+
},
127+
])
128+
.then(function (answers) {
129+
if (!answers.create) {
130+
console.log('Aborting');
131+
process.exit();
132+
}
133+
});
134+
}
135+
137136
function pad(str1, str2) {
138137
var padLen = 60 - (str1.length + str2.length);
139138
// Ensure at least one space:
140139
var pad = ' ';
141-
for (var i = 1; i < padLen; i++) {
142-
pad += ' ';
143-
}
140+
for (var i = 1; i < padLen; i++) pad += ' ';
144141
return str1 + pad + str2;
145142
}

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,16 @@
1313
"url": "git+https://github.com/RyanZim/edit-script.git"
1414
},
1515
"scripts": {
16-
"test": "echo \"Error: no test specified\" && exit 1"
16+
"test": "echo \"Error: no test specified\" && exit 1",
17+
"lint": "eslint ."
1718
},
1819
"dependencies": {
1920
"fs-promise": "^1.0.0",
2021
"inquirer": "^2.0.0",
2122
"pkg-up": "^1.0.0"
23+
},
24+
"devDependencies": {
25+
"eslint": "^3.12.2",
26+
"eslint-config-ryanzim": "0.0.1"
2227
}
2328
}

0 commit comments

Comments
 (0)