-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxtask
More file actions
executable file
·40 lines (36 loc) · 1.54 KB
/
Copy pathxtask
File metadata and controls
executable file
·40 lines (36 loc) · 1.54 KB
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
#!/usr/bin/env node
const _ = require('lodash');
const parser = require('node-schedule/node_modules/cron-parser');
const moment = require('moment');
function showHelp() {
const list = [];
list.push(`* * * * * *`);
list.push(`┬ ┬ ┬ ┬ ┬ ┬`);
list.push(`│ │ │ │ │ │`);
list.push(`│ │ │ │ │ └ day of week(0 - 7)(0 or 7 is Sun)`);
list.push(`│ │ │ │ └───── month(1 - 12)`);
list.push(`│ │ │ └────────── day of month(1 - 31)`);
list.push(`│ │ └─────────────── hour(0 - 23)`);
list.push(`│ └──────────────────── minute(0 - 59)`);
list.push(`└───────────────────────── second(0 - 59, OPTIONAL)`);
console.log(list.join('\n'));
console.log();
console.log('Usage:');
console.log(' xtask "0 * * * * * " [n]');
}
function test(rule, count = 10) {
const interval = parser.parseExpression(rule || '0 0/10 * * * *');
for (let i = 0; i < count; ++i) {
console.log(moment(interval.next()._date.ts).format('YYYY-MM-DD HH:mm:ss'));
}
}
const list = process.argv.slice(2);
if (list[0] === '-h' || !list[0]) {
showHelp();
} else {
const _list = (list[0] || '').split(/\s/).filter(Boolean);
for (let i=_list.length; i<6; i++) {
_list[i] = '*';
}
test(_list.join(' '), list[1]);
}