generated from Tailormap/tailormap-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
publish.js
47 lines (41 loc) · 1.52 KB
/
publish.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
const path = require("path");
const {spawn} = require("child_process");
const fs = require("fs/promises");
const runCommand = (command, args, cwd) => {
return new Promise((resolve, reject) => {
const workingDir = cwd || path.resolve(path.dirname('./'));
const cmd = spawn(command, args, {
stdio: 'inherit',
env: process.env,
cwd: workingDir,
});
cmd.on('error', err => {
console.error(err);
reject();
});
cmd.on('close', (code) => {
resolve();
});
});
};
const getPackageJsonPath = (project) => {
return path.resolve(__dirname, './projects/', project, 'package.json');
}
const getPackageJson = async (project) => {
const packageJson = await fs.readFile(getPackageJsonPath(project));
return JSON.parse(packageJson.toString());
};
const getCurrentVersion = async (project) => {
return (await getPackageJson(project)).version;
};
const publishRelease = async () => {
const project = 'hello-world';
const scope = '@tailormap-b3p';
await runCommand('npm', ['version', 'patch'], path.resolve(__dirname, './projects/', project));
await runCommand('npm', ['run', 'build-hello-world']);
await runCommand('npm', ['publish', '--scope=' + scope, '--registry=https://repo.b3p.nl/nexus/repository/npm-public'], path.resolve(__dirname, './dist/', project));
await runCommand('git', ['add', '-A']);
const currentVersion = await getCurrentVersion(project);
await runCommand('git', ['commit', '-m', `Released version ${currentVersion} of ${project} project`])
}
publishRelease();