node-build.js
1.64 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
57
58
59
60
61
62
63
64
65
66
67
const shelljs = require('shelljs');
const path = require('path');
const pkg = require('../package.json');
const distDir = path.join(__dirname, '../dist/node');
shelljs.rm('-rf', distDir);
shelljs.mkdir('-p', distDir);
const cpPaths = [
'favicon.ico',
'.nvmrc',
'.npmrc',
'process.json',
'Dockerfile',
'yarn.lock',
'package.json',
'*.js',
'config',
'doraemon',
'utils',
'apps/index.html',
`dist/${pkg.name}/yoho-ssr-client-${pkg.version}.json`,
`dist/${pkg.name}/yoho-ssr-server-${pkg.version}.json`
];
new Promise(resolve => { // 加载manifest.json文件
resolve();
}).then(() => { // 拷贝node代码
cpPaths.forEach(p => {
let dist = distDir;
let file = p;
if (typeof p === 'object') {
dist = path.join(dist, p[1]);
file = p[0];
if (!shelljs.test('-e', dist)) {
shelljs.mkdir('-p', dist);
}
}
shelljs.cp('-R', path.join(__dirname, '../', file), dist);
});
}).then(() => { // 验证文件正确性
if (!shelljs.test('-e', path.join(distDir, `yoho-ssr-client-${pkg.version}.json`))) {
console.error('error:check yoho-ssr-client.json faild');
return process.exit(1); //eslint-disable-line
}
if (!shelljs.test('-e', path.join(distDir, `yoho-ssr-server-${pkg.version}.json`))) {
console.error('error:check yoho-ssr-server.json faild');
return process.exit(1); //eslint-disable-line
}
}).then(() => { // 安装依赖和清理node_modules
shelljs.cd(distDir);
if (shelljs.exec('yarn --production=true').code !== 0) {
throw 'yarn install faild';
}
}).catch(error => {
console.error(`error:${error}`);
return process.exit(1); //eslint-disable-line
});