-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand.example.js
More file actions
56 lines (48 loc) · 1.66 KB
/
command.example.js
File metadata and controls
56 lines (48 loc) · 1.66 KB
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
const chalk = require('chalk');
const shell = require('shelljs');
const dotenv = require('dotenv').config();
const log = require('fancy-log');
const DIST = process.env.DIST;
const REPO = process.env.REPO;
const THEME = `${REPO}/themes/${process.env.THEME}`;
const CURRENT_BRANCH = `git symbolic-ref --short -q HEAD`;
module.exports = function () {
if (!shell.which('git')) {
log(`${chalk.red('[error]')} this script requires git`);
shell.exit(1);
}
// before install
shell.cd(REPO);
if (shell.exec(CURRENT_BRANCH).stdout.trim() !== 'master') {
log(`${chalk.red('[error]')} Wrong branch`);
shell.exit(1);
}
log(`${chalk.green('[exec]')} pull the code`);
shell.exec('git pull');
shell.exec('git submodule update');
log(`${chalk.green('[exec]')} install all dependencies`);
// theme build
shell.cd(THEME);
log(`${chalk.green('[exec]')} theme build`);
if (shell.exec('yarn').code !== 0) {
log(`${chalk.red('[error]')} theme install error`);
}
if (shell.exec('yarn build').code !== 0) {
log(`${chalk.red('[error]')} theme build error`);
}
// project build
shell.cd(REPO);
log(`${chalk.green('[exec]')} project build`);
if (shell.exec('yarn').code !== 0) {
log(`${chalk.red('[error]')} project install error`);
}
if (shell.exec('yarn build').code !== 0) {
log(`${chalk.red('[error]')} project build error`);
}
// empty dist
log(`${chalk.green('[exec]')} clean dist`);
shell.rm('-rf', `${DIST}/*`);
// transfer file
log(`${chalk.green('[exec]')} build ==> dist`);
shell.cp('-r', `${REPO}/public/*`, `${DIST}/`);
}