-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
42 lines (39 loc) · 1.44 KB
/
main.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
#!/usr/bin/env node
const { program } = require('commander');
const path = require('path');
const fs = require('fs');
const DevServer = require('./src/server');
const logger = require('./src/utils/logger');
const pkgInfo = require('./package.json');
program.version(pkgInfo.version);
program.command('start')
.option('-t, --tigo-dev-config <tigoDevConfig>')
.option('-r, --rollup-config <rollupConfig>')
.action(async (options) => {
// check options
if (!options.tigoDevConfig) {
logger.error('Please specify the tigo dev config file path.');
return process.exit(-1);
}
if (!options.rollupConfig) {
logger.error('Please specify the rollup config file path.');
return process.exit(-1);
}
// check path
const { tigoDevConfig, rollupConfig } = options;
const tigoDevConfigPath = path.resolve(process.cwd(), tigoDevConfig);
if (!fs.existsSync(tigoDevConfigPath)) {
logger.error('Cannot locate the tigo dev config file.');
return process.exit(-1);
}
const rollupConfigPath = path.resolve(process.cwd(), rollupConfig);
if (!fs.existsSync(rollupConfigPath)) {
logger.error('Cannot locate the rollup config file.');
return process.exit(-1);
}
// start up dev server
const tigoConfig = JSON.parse(fs.readFileSync(tigoDevConfigPath, { encoding: 'utf8' }));
const devServer = new DevServer(tigoConfig, rollupConfigPath);
devServer.start();
});
program.parse();