-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
100 lines (84 loc) · 2.57 KB
/
index.js
File metadata and controls
100 lines (84 loc) · 2.57 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/env node
'use strict';
const program = require('commander');
const newProject = require('./src/new.js');
const addModule = require('./src/add.js');
const migrateProject = require('./src/migrate-crontab.js');
const options = {};
// CHECK ARGS APP:
program.version('Runnerty CLI ' + require('./package.json').version, '-v, --version');
// config path:
program.option('-c, --config <path>', `set config path to add module.`, filePath => {
options.configFilePath = filePath;
});
// without scaffold:
program.option('-ws, --without-scaffold', `do not include scaffolding in add module.`, () => {
options.withoutscaffold = true;
});
// new project with production scaffold:
program.option('-p, --prod', `to create a production project scaffold`, () => {
options.prod = true;
});
// Runnerty version:
program.option(
'-rv, --runnerty-version <version>',
`set runnerty version to install as a dependency when creating a new project`,
runnertyVersion => {
options.runnertyVersion = runnertyVersion;
}
);
// new:
program
.command('new [project]')
.alias('n')
.description('create the project')
.action(project => {
newProject(project, options);
})
.on('--help', () => {
console.log('');
console.log('Examples:');
console.log('');
console.log(' $rty new');
console.log(' $rty new my_runnerty_project');
});
// skip git:
program.option('-sg, --skip-git', `do not initialize a git repository`, skipGit => {
options.skipGit = true;
});
// migrate:
program
.command('migrate [project] [crontab_path]')
.alias('m')
.description('migrate crontab to new runnerty project')
.action((project, crontab_path) => {
migrateProject(project, crontab_path);
})
.on('--help', () => {
console.log('');
console.log('Examples:');
console.log('');
console.log(' $rty migrate my_runnerty_migrated_project');
console.log(' $rty migrate my_runnerty_migrated_project /usr/lib/cron/tabs/my_user');
});
// add module:
program
.command('add <module>')
.description('add runnerty module')
.action(module => {
addModule(module, options);
});
program.parse(process.argv);
// ==================================================================
program.on('command:*', () => {
console.error('Invalid command: %s\nSee --help for a list of available commands.', program.args.join(' '));
process.exit(1);
});
process.on('uncaughtException', err => {
console.error('error', err.stack);
});
process.on('unhandledRejection', (reason, p) => {
console.error('error', p, reason);
process.exit();
});
process.on('SIGINT', () => {});