UNPKG

2.75 kBJavaScriptView Raw
1const stiks = require('../dist');
2const log = stiks.log;
3const argv = stiks.argv;
4const colurs = stiks.colurs.get();
5const chek = stiks.chek;
6const exec = stiks.exec;
7const pkg = stiks.pkg();
8const build = pkg && pkg.build;
9
10// Ensure build info.
11if (!build)
12 log.error('whoops looks like you forgot to configure package.json "build".').exit();
13
14// Parse command line arguments.
15const parsed = argv.parse();
16const cmdOpts = argv.options;
17let cmd, opts;
18
19/**
20 * Normalize
21 * Normalizes the command arguments.
22 *
23 * @param {string|array} cmds
24 * @param {string|array} options
25 */
26function 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 // Ensure we don't append dupes.
34 options.forEach((o) => {
35 if (!chek.contains(output, o))
36 output.push(o);
37 });
38 return output;
39}
40
41// Build actions.
42const 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
124if (!actions[parsed.cmd])
125 log.error(new Error(`Failed to run command ${parsed.cmd}, the command does not exist.`)).exit();
126
127// Start the chain.
128actions[parsed.cmd]();