forked from framework7io/framework7-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·102 lines (92 loc) · 3 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
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
101
102
#!/usr/bin/env node
/* eslint no-console: off */
const program = require('commander');
const logSymbols = require('log-symbols');
const checkUpdate = require('./utils/check-update');
const spinner = require('./utils/spinner');
const log = require('./utils/log');
const getCurrentProject = require('./utils/get-current-project');
const getOptions = require('./create/utils/get-options');
const createApp = require('./create/index');
const generateAssets = require('./assets/index');
const server = require('./ui/server');
const pkg = require('./package.json');
const cwd = process.cwd();
const logger = {
statusStart: (text) => spinner.start(text),
statusDone: (text) => spinner.done(text),
statusError: (text) => spinner.error(text),
text: (text) => log.text(text),
error: (text) => log.error(text),
};
/* =============================================
Commands
============================================= */
program
.version(pkg.version)
.usage('<command> [options]')
.command('create')
.option('--skipUpdate', 'Skip checking for update of framework7-cli')
.option('--ui', 'Launch new app creation UI')
.option('-P, --port <n>', 'Specify UI server port. By default it is 3001', parseInt)
.description('Create a new Framework7 project')
.action(async (options) => {
// Check update
if (options.skipUpdate === undefined) {
await checkUpdate();
}
const currentProject = getCurrentProject(cwd);
if (currentProject) {
log.text(`${logSymbols.error} Framework7 project already set up in current directory`);
process.exit(1);
}
if (options.ui) {
spinner.start('Launching Framework7 UI server');
server('/create/', options.port);
spinner.end('Launching Framework7 UI server');
} else {
const opts = await getOptions();
await createApp(
{
cwd,
...opts,
},
logger,
);
process.exit(0);
}
});
program
.command('assets')
.alias('generate-assets')
.option('--skipUpdate', 'Skip checking for update of framework7-cli')
.option('--ui', 'Launch assets generation UI')
.option('-P, --port <n>', 'Specify UI server port. By default it is 3001', parseInt)
.description('Generate Framework7 app icons and splash screens')
.action(async (options) => {
// Check update
if (options.skipUpdate === undefined) {
await checkUpdate();
}
const currentProject = getCurrentProject(cwd);
if (!currentProject) {
log.text(`${logSymbols.error} Framework7 project not found in current directory`);
process.exit(1);
}
if (options.ui) {
spinner.start('Launching Framework7 UI server');
server('/assets/', options.port);
spinner.end('Launching Framework7 UI server');
} else {
await generateAssets({}, currentProject, logger);
process.exit(0);
}
});
program.on('command:*', (cmd) => {
program.outputHelp();
log.text(`\n Unknown command ${cmd}`);
});
program.parse(process.argv);
if (!program.args.length) {
program.outputHelp();
}