1 | #!/usr/bin/env node
|
2 |
|
3 | const path = require('path');
|
4 | const fs = require('fs');
|
5 | const { spawn } = require('child_process');
|
6 | const program = require('commander');
|
7 | const glob = require('glob');
|
8 | const chalk = require('chalk');
|
9 |
|
10 | const welcome = require('../lib/welcome');
|
11 | const { version } = require('../package.json');
|
12 |
|
13 | const basedir = process.cwd();
|
14 | const terminal = chalk.cyan('athena:');
|
15 |
|
16 | function validate(module) {
|
17 | const project = path.resolve(basedir, module);
|
18 |
|
19 | return fs.existsSync(project)
|
20 | ? Promise.resolve(module)
|
21 | : Promise.reject(new Error(`The package --> ${module} not exist`));
|
22 | }
|
23 |
|
24 | function make(module) {
|
25 | const mvn = spawn('mvn', [
|
26 | 'clean',
|
27 | 'install',
|
28 | '-Dmaven.test.skip=true',
|
29 | `-pl=${module}`,
|
30 | '-am',
|
31 | ]);
|
32 |
|
33 | mvn.stdout.pipe(process.stdout);
|
34 | mvn.stderr.pipe(process.stderr);
|
35 |
|
36 | return new Promise((resolve, reject) => {
|
37 | mvn.on('close', () => resolve(module));
|
38 | mvn.on('error', (error) => reject(error));
|
39 | });
|
40 | }
|
41 |
|
42 | async function pipeline(module) {
|
43 | try {
|
44 | await welcome();
|
45 | await validate(module);
|
46 | await make(module);
|
47 |
|
48 | const pattern = '*.jar';
|
49 | const context = `${module}/target`;
|
50 | const [jar] = glob.sync(pattern, { cwd: context });
|
51 | const success = chalk.cyan(`Athena make ${jar} success...`);
|
52 |
|
53 |
|
54 | console.log(`${terminal} ${success}`);
|
55 |
|
56 | } catch (err) {
|
57 |
|
58 | console.error(err.stack);
|
59 |
|
60 | process.exit(1);
|
61 | }
|
62 | }
|
63 |
|
64 | program
|
65 | .version(version)
|
66 | .usage('<module> [options]')
|
67 | .option('-c, --config <file>', 'declare athena make config file')
|
68 | .action(pipeline)
|
69 | .parse(process.argv);
|