-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpublish.ts
58 lines (50 loc) · 1.54 KB
/
publish.ts
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
/* eslint-disable @typescript-eslint/restrict-template-expressions, @typescript-eslint/no-unsafe-argument */
import semanticRelease from 'semantic-release';
import { spawnSync, SpawnSyncOptions } from 'child_process';
const spawnOptions: SpawnSyncOptions = {
stdio: 'inherit',
cwd: __dirname,
};
const build = (version: string) => {
spawnSync('yarn', ['tsc', '-p', 'tsconfig.build.json'], {
...spawnOptions,
});
spawnSync('yarn', ['workspaces', 'foreach', 'version', version], {
...spawnOptions,
});
spawnSync('yarn', ['constraints', '--fix'], {
...spawnOptions,
env: {
...process.env,
YARN_CONSTRAINTS_PATH: './constraints.deploy.pro',
},
});
};
const npmPublish = () => {
spawnSync('yarn', ['workspaces', 'foreach', '--no-private', 'npm', 'publish'], {
...spawnOptions,
});
};
const versionAndPublish = async () => {
const options = {};
const result = await semanticRelease({ ...options, dryRun: true });
if (result) {
const { lastRelease, commits, nextRelease } = result;
build(nextRelease.version);
await semanticRelease(options);
npmPublish();
console.log(`Published ${nextRelease.type} release version ${nextRelease.version} containing ${commits.length} commits.`);
if (lastRelease.version) {
console.log(`The last release was "${lastRelease.version}".`);
}
} else {
console.log('No release to publish.');
}
};
versionAndPublish().then(
() => console.log('Completed release process'),
(err) => {
console.error(err);
process.exit(-1);
},
);