forked from CUModSquad/cu-ui-legacy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
43 lines (35 loc) · 1.2 KB
/
build.js
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
require('shelljs/global');
var fs = require('fs');
var path = require('path');
var chalk = require('chalk');
var yargs = require('yargs')
.usage('Usage: $0 (-b | --build) | (-i | --install) | (-p outputDirectory | -- publish outputDirectory)')
.alias('b', 'build')
.alias('i', 'install')
.alias('p', 'publish')
.alias('prod', 'production')
.argv;
var publish = yargs.publish || 'publish';
function getDirectories(root) {
return fs.readdirSync(root).filter(function(file) {
return fs.statSync(path.join(root, file)).isDirectory()
&& !file.startsWith('.')
&& file !== 'node_modules';
});
}
function installModule(directory) {
console.log(chalk.green(`running npm install in ${directory}`));
cd(directory);
exec(yargs.production ? 'npm install --production' : 'npm install');
cd('..');
}
function buildModule(directory) {
console.log(chalk.green(`building module at ${directory}`));
cd(directory);
exec('npm run build');
cd('..');
exec(`(robocopy ${directory}\\dist ${publish}\\${directory} /s) ^& IF %ERRORLEVEL% LEQ 1 exit 0`);
}
var directories = getDirectories('.');
if (yargs.install) directories.map(installModule);
if (yargs.build) directories.map(buildModule);