-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathrun.js
More file actions
91 lines (79 loc) · 2.27 KB
/
run.js
File metadata and controls
91 lines (79 loc) · 2.27 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/**
* @fileoverview
* Execute yarn scripts in the application or package directory from the project root.
*/
const { spawn } = require('child_process');
const { PACKAGES, getEnvCommand } = require('./build');
function main() {
const commands = [];
commands.push(getEnvCommand('NPM_AUTH', ''));
commands.push(cmd);
const unifiedCommand = commands.join(' && ').split(' ');
if (dir === 'cysync') {
const command = spawn(unifiedCommand.shift(), unifiedCommand, {
cwd: `${__dirname}/cysync`,
stdio: 'inherit',
shell: true
});
command.on('close', code => {
process.exit(code);
});
return;
}
if (PACKAGES.find(pkg => pkg.name === dir)) {
const command = spawn(commands.shift(), commands, {
cwd: `${__dirname}/packages/${dir}`,
stdio: 'inherit'
});
command.on('close', code => {
process.exit(code);
});
return;
}
if (dir === 'packages') {
const individualCommands = [];
PACKAGES.forEach(pkg => {
individualCommands.push(getEnvCommand('NPM_AUTH', ''));
individualCommands.push(`cd packages/${pkg.name}`);
individualCommands.push(cmd);
individualCommands.push('cd ../..');
});
const sequence = individualCommands.join(' && ').split(' ');
const command = spawn(sequence.shift(), sequence, {
shell: true,
stdio: 'inherit'
});
command.on('close', code => {
process.exit(code);
});
return;
}
if (dir === 'all') {
const individualCommands = [];
individualCommands.push('cd cysync');
individualCommands.push(cmd);
individualCommands.push('cd ..');
PACKAGES.forEach(pkg => {
individualCommands.push(`cd packages/${pkg.name}`);
individualCommands.push(cmd);
individualCommands.push('cd ../..');
});
const sequence = individualCommands.join(' && ').split(' ');
const command = spawn(sequence.shift(), sequence, {
shell: true,
stdio: 'inherit'
});
command.on('close', code => {
process.exit(code);
});
return;
}
console.error('ERR: Invalid or missing command. Aborting.');
process.exit(1);
}
const args = process.argv.slice(2);
// Either a package name, 'cysync' or 'all'
const dir = args[0];
// A (yarn) script, e.g. "yarn dev"
const cmd = args[1];
main();