Skip to content

Commit c6c55ac

Browse files
committed
feature(spawnify) madrun
1 parent 6098aa9 commit c6c55ac

File tree

6 files changed

+46
-36
lines changed

6 files changed

+46
-36
lines changed

.eslintrc

Lines changed: 0 additions & 18 deletions
This file was deleted.

.eslintrc.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"extends": [
3+
"plugin:putout/recommended",
4+
"plugin:node/recommended"
5+
],
6+
"plugins": [
7+
"putout",
8+
"node"
9+
]
10+
}

.npmignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
.*
22
*.swp
33

4+
madrun.js
5+

lib/spawnify.js

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Spawnify.prototype._onMessage = function onMessage(command, options) {
5959
'~', '>', '<', '#',
6060
'*', '&', '{', '}',
6161
'|', '\'','"', ';',
62-
'`', '$'
62+
'`', '$',
6363
];
6464

6565
const isSymbol = isContain(command, symbolsExec);
@@ -76,7 +76,7 @@ Spawnify.prototype._onMessage = function onMessage(command, options) {
7676
if (WIN)
7777
command = 'cmd /C ' + command;
7878

79-
const firstChar = command[0];
79+
const [firstChar] = command;
8080

8181
if (firstChar === ' ' || isSymbol)
8282
this._set('exec', command, options);
@@ -97,7 +97,7 @@ Spawnify.prototype._emit = function emit(event, data) {
9797
if (count(event) || event === 'error') {
9898
this.emit(event, data);
9999

100-
/*
100+
/*
101101
* when code is EACESS
102102
* close and exit events
103103
* whould not be emitted
@@ -113,7 +113,9 @@ Spawnify.prototype._emit = function emit(event, data) {
113113
};
114114

115115
Spawnify.prototype._set = function set(type, command, options) {
116-
let args, error, child;
116+
let args;
117+
let error;
118+
let child;
117119
let result;
118120

119121
assert(type, 'event could not be empty!');
@@ -129,7 +131,7 @@ Spawnify.prototype._set = function set(type, command, options) {
129131
case 'exec':
130132
result = tryCatch(exec, command, options);
131133

132-
error = result[0];
134+
[error] = result;
133135
child = result[1];
134136
break;
135137

@@ -139,7 +141,7 @@ Spawnify.prototype._set = function set(type, command, options) {
139141

140142
result = tryCatch(spawn, command, args, options);
141143

142-
error = result[0];
144+
[error] = result;
143145
child = result[1];
144146
break;
145147
}
@@ -189,20 +191,20 @@ Spawnify.prototype._setListeners = function setListeners(child) {
189191
child.stdin.on('error', (error) => {
190192
this._emit('error', newLine(error));
191193
});
192-
194+
193195
if (child.stdout) {
194196
child.stdout
195197
.pipe(win.unicodify())
196198
.setEncoding('utf8')
197199
.on('data', (data) => {
198200
this._emit('data', data);
199201
});
200-
202+
201203
child.stdout.on('error', (error) => {
202204
this._emit('error', newLine(error));
203205
});
204206
}
205-
207+
206208
if (child.stderr) {
207209
child.stderr.pipe(win.unicodify())
208210
.setEncoding('utf8')
@@ -263,15 +265,15 @@ Spawnify.prototype._onCD = function onCD(command, currDir) {
263265
CD,
264266
paramDir,
265267
'\'' + paramDir + '\'',
266-
'"' + paramDir + '"',
268+
'"' + paramDir + '"',
267269
];
268270

269-
strs.forEach((str) => {
271+
for (const str of strs) {
270272
command = command.replace(str, '');
271-
});
273+
}
272274

273275
if (!isRoot)
274-
paramDir = path.join(currDir, paramDir);
276+
paramDir = path.join(currDir, paramDir);
275277

276278
if (isWildCard)
277279
command = CD + paramDir + ' ' + command;
@@ -286,10 +288,10 @@ Spawnify.prototype._onCD = function onCD(command, currDir) {
286288
let cwd;
287289

288290
if (!error)
289-
cwd = dirs[0];
291+
[cwd] = dirs;
290292

291293
this._set('exec', command, {
292-
cwd
294+
cwd,
293295
});
294296
});
295297
};
@@ -305,7 +307,7 @@ Spawnify.prototype._getFirstWord = function getFirstWord(str) {
305307
if (!is)
306308
return str;
307309

308-
let result = str.match(regExpQuotes);
310+
let result = str.match(regExpQuotes);
309311

310312
if (result)
311313
return result[1] || str;

madrun.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
'use strict';
2+
3+
const {run} = require('madrun');
4+
5+
module.exports = {
6+
'lint': () => 'putout lib madrun.js',
7+
'fix:lint': () => run('lint', '--fix'),
8+
};
9+

package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"description": "Create new processes, change directories, auto switch between spawn and exec",
66
"homepage": "http://github.com/coderaiser/spawnify",
77
"scripts": {
8-
"lint": "eslint lib"
8+
"lint": "madrun lint",
9+
"fix:lint": "madrun fix:lint"
910
},
1011
"repository": {
1112
"type": "git",
@@ -28,7 +29,11 @@
2829
},
2930
"devDependencies": {
3031
"eslint": "^6.4.0",
31-
"eslint-plugin-node": "^9.0.1"
32+
"eslint-plugin-node": "^10.0.0",
33+
"eslint-plugin-putout": "^2.0.0",
34+
"madrun": "^3.0.5",
35+
"putout": "^6.1.0",
36+
"supertape": "^1.2.3"
3237
},
3338
"publishConfig": {
3439
"access": "public"

0 commit comments

Comments
 (0)