1 | const stiks = require('../dist');
|
2 | const log = stiks.log;
|
3 | const argv = stiks.argv;
|
4 | const colurs = stiks.colurs.get();
|
5 | const chek = stiks.chek;
|
6 | const exec = stiks.exec;
|
7 | const pkg = stiks.pkg();
|
8 | const build = pkg && pkg.build;
|
9 |
|
10 |
|
11 | if (!build)
|
12 | log.error('whoops looks like you forgot to configure package.json "build".').exit();
|
13 |
|
14 |
|
15 | const parsed = argv.parse();
|
16 | const cmdOpts = argv.options;
|
17 | let cmd, opts;
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 | function normalize(cmds, options) {
|
27 | options = options || argv.options;
|
28 | if (chek.isString(cmds))
|
29 | cmds = cmds.split(' ');
|
30 | if (chek.isString(options))
|
31 | options = options.split(' ');
|
32 | const output = cmds;
|
33 |
|
34 | options.forEach((o) => {
|
35 | if (!chek.contains(output, o))
|
36 | output.push(o);
|
37 | });
|
38 | return output;
|
39 | }
|
40 |
|
41 |
|
42 | const actions = {
|
43 |
|
44 | clean: () => {
|
45 | stiks.clean(build.clean);
|
46 | log.debug(`cleaned ${pkg.name}.`);
|
47 | return actions;
|
48 | },
|
49 |
|
50 | copy: () => {
|
51 | stiks.copy(build.copy);
|
52 | return actions;
|
53 | },
|
54 |
|
55 | compile: () => {
|
56 | opts = '-p ./src/tsconfig.json'
|
57 | cmd = normalize('./node_modules/typescript/bin/tsc', opts);
|
58 | exec.node(cmd);
|
59 | log.debug(`compiled ${pkg.name}.`);
|
60 | return actions;
|
61 | },
|
62 |
|
63 | docs: () => {
|
64 | opts = '--out ./docs ./src --options ./typedoc.json';
|
65 | cmd = normalize('./node_modules/typedoc/bin/typedoc', opts);
|
66 | exec.node(cmd);
|
67 | log.debug(`built typedoc for ${pkg.name}.`);
|
68 | return actions;
|
69 | },
|
70 |
|
71 | bump: () => {
|
72 | stiks.bump();
|
73 | log.debug(`bumped ${pkg.name}.`);
|
74 | return actions;
|
75 | },
|
76 |
|
77 | build: () => {
|
78 | actions.clean()
|
79 | .copy()
|
80 | .compile();
|
81 | log.info(`${pkg.name} was built.`);
|
82 | return actions;
|
83 | },
|
84 |
|
85 | commit: () => {
|
86 | if (!/-[a-zA-Z]{0,7}?m/g.test(cmdOpts.join(' ')))
|
87 | opts = ['-am', '"auto commit"'];
|
88 | cmd = normalize('commit', opts);
|
89 | exec.command('git', 'add .');
|
90 | exec.command('git', cmd);
|
91 | exec.command('git', 'push');
|
92 | log.debug(`committed ${pkg.name}.`);
|
93 | return actions;
|
94 | },
|
95 |
|
96 | publish() {
|
97 | exec.npm('publish');
|
98 | log.debug(`published ${pkg.name}.`);
|
99 | return actions;
|
100 | },
|
101 |
|
102 | release: () => {
|
103 | actions.build()
|
104 | .docs()
|
105 | .bump()
|
106 | .commit()
|
107 | .publish();
|
108 | log.info(`published ${pkg.name}.`);
|
109 | return actions;
|
110 | },
|
111 |
|
112 | test: () => {
|
113 | exec.command('mocha', '--opts ./src/mocha.opts');
|
114 | },
|
115 |
|
116 | exit: (msg) => {
|
117 | if (msg)
|
118 | log.write(msg).exit();
|
119 | process.exit(0);
|
120 | }
|
121 |
|
122 | };
|
123 |
|
124 | if (!actions[parsed.cmd])
|
125 | log.error(new Error(`Failed to run command ${parsed.cmd}, the command does not exist.`)).exit();
|
126 |
|
127 |
|
128 | actions[parsed.cmd]();
|