-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
57 lines (48 loc) · 1.36 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
var plugin = require('shelljs/plugin');
var shell = require('shelljs');
var child = require('child_process');
var path = require('path');
function sleepWithCommand(time) {
child.execSync('sleep ' + time);
}
function sleepWithNode(time) {
var pathToSleepHelper = path.join(__dirname, 'sleepHelper.js');
var cmd = [
JSON.stringify(shell.config.execPath),
JSON.stringify(pathToSleepHelper),
time,
].join(' ');
child.execSync(cmd);
}
var sleepFunc;
try {
/* eslint import/no-unresolved: 0 */
var sleep = require('sleep');
sleepFunc = sleep.sleep.bind(sleep);
exports.nativeExt = sleep.sleep.bind(sleep);
} catch (e) {
if (shell.which('sleep')) {
sleepFunc = sleepWithCommand;
} else {
sleepFunc = sleepWithNode;
}
}
function sleepImpl(options, waitTime) {
var waitInt = parseInt(waitTime, 10);
if (waitTime.toString() !== waitInt.toString()) {
plugin.error('sleep time must be an integer');
} else if (waitInt < 0) {
plugin.error('negative numbers are not supported');
}
sleepFunc(waitInt);
return '';
}
// Register the new plugin as a ShellJS command
plugin.register('sleep', sleepImpl, {
cmdOptions: {}, // There are no supported options for this command
allowGlobbing: false,
});
exports.sleep = sleepImpl;
// For testing only:
exports.sleepWithCommand = sleepWithCommand;
exports.sleepWithNode = sleepWithNode;