-
Notifications
You must be signed in to change notification settings - Fork 3
/
prepare.js
57 lines (45 loc) · 1.69 KB
/
prepare.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
const { execSync } = require('child_process');
const path = require('path');
const fs = require('fs');
function runCommand(cwd, commands) {
for (const command of commands) {
console.log(`Running command: ${command}`);
execSync(command, { cwd, stdio: 'inherit' });
}
}
runCommand(__dirname, [
'git submodule update --force',
]);
const submodulePath = path.resolve(__dirname, 'packages/graphic-walker');
runCommand(submodulePath, [
'git reset --hard',
]);
const { version, scripts } = JSON.parse(
fs.readFileSync(path.join(submodulePath, 'packages/graphic-walker', 'package.json'), 'utf8')
);
fs.writeFileSync(
path.join(submodulePath, 'packages/graphic-walker', 'package.json'),
JSON.stringify({
...JSON.parse(fs.readFileSync(path.join(submodulePath, 'packages/graphic-walker', 'package.json'), 'utf8')),
scripts: {
...scripts,
build: 'yarn vite build',
},
}, null, 2),
);
const nextVersion = version.includes('-') ? version.split('-')[0] : (v => {
const [major, minor, patch] = v.split('.');
return `${major}.${minor}.${Number(patch) + 1}`;
})(version);
const snapshotVersion = `${nextVersion}-snapshot.${Math.floor(Date.now() / 1000)}`;
runCommand(path.join(submodulePath, 'packages/graphic-walker'), [
'yarn install',
`yarn version --new-version ${snapshotVersion} --no-git-tag-version`,
'yarn build',
'yarn pack',
]);
const packName = `kanaries-graphic-walker-v${snapshotVersion}.tgz`;
const packPath = path.resolve(submodulePath, 'packages/graphic-walker', packName);
runCommand(__dirname, [
`yarn workspace web-app add @kanaries/graphic-walker@file:${packPath} --no-lockfile --no-save`,
]);