-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.js
executable file
·83 lines (70 loc) · 1.85 KB
/
deploy.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
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
#!/usr/bin/env node
const cp = require('child_process');
const fs = require('fs');
const path = require('path');
const [_, __, ...argv] = process.argv;
const versionIndex = argv.findIndex(arg => arg === '-v' || arg === '--version');
if (versionIndex === argv.length - 1 || versionIndex === -1) {
return;
}
const version = argv[versionIndex + 1];
argv.splice(versionIndex, 2);
updateAllVersions(version);
deploy('manatea');
deploy('react-manatea');
commit(version);
addTag(version);
push();
function* listAllWorkspaces() {
const output = cp.spawnSync('yarn', ['workspaces', 'list', '--json'], {
encoding: 'utf-8',
}).stdout;
const workspaces = output.trim().split('\n').map(JSON.parse);
for (const workspace of workspaces) {
const packageJsonPath = path.join(
__dirname,
workspace.location,
'package.json',
);
const packageJson = JSON.parse(
fs.readFileSync(packageJsonPath, { encoding: 'utf-8' }),
);
yield { packageJsonPath, packageJson, name: workspace.name };
}
}
function updateAllVersions(version) {
for (const { packageJson, packageJsonPath } of listAllWorkspaces()) {
packageJson.version = version;
fs.writeFileSync(
packageJsonPath,
JSON.stringify(packageJson, null, 2) + '\n',
);
}
}
function deploy(package) {
cp.spawnSync('yarn', ['npm', 'publish', ...argv], {
cwd: path.join(__dirname, 'packages', package),
stdio: 'inherit',
});
}
function addTag(version) {
cp.spawnSync('git', ['tag', `v${version}`], {
stdio: 'inherit',
});
}
function commit(version) {
cp.spawnSync('git', ['add', '.'], {
stdio: 'inherit',
});
cp.spawnSync('git', ['commit', '-m', `v${version}`], {
stdio: 'inherit',
});
}
function push() {
cp.spawnSync('git', ['push'], {
stdio: 'inherit',
});
cp.spawnSync('git', ['push', '--tags'], {
stdio: 'inherit',
});
}