-
Notifications
You must be signed in to change notification settings - Fork 27
/
prepare-release.ts
69 lines (55 loc) · 2.11 KB
/
prepare-release.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
59
60
61
62
63
64
65
66
67
68
69
// Copyright 2021 Google Inc. Use of this source code is governed by an
// MIT-style license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
import {promises as fs} from 'fs';
import * as shell from 'shelljs';
import * as pkg from '../package.json';
import {getEmbeddedProtocol} from './get-embedded-protocol';
import {getJSApi} from './get-js-api';
(async () => {
try {
await sanityCheckBeforeRelease();
await getEmbeddedProtocol('lib/src/vendor');
await getJSApi('lib/src/vendor');
console.log('Transpiling TS into dist.');
shell.exec('tsc');
console.log('Copying JS API types to dist.');
shell.cp('-R', 'lib/src/vendor/sass', 'dist/types');
await fs.unlink('dist/types/README.md');
// .gitignore needs to exist in dist for `npm publish` to correctly exclude
// files from the published tarball.
console.log('Copying .gitignore to dist.');
await fs.copyFile('.gitignore', 'dist/.gitignore');
console.log('Ready for publishing to npm.');
} catch (error) {
console.error(error);
process.exitCode = 1;
}
})();
// Quick sanity checks to make sure the release we are preparing is a suitable
// candidate for release.
async function sanityCheckBeforeRelease() {
console.log('Running sanity checks before releasing.');
const releaseVersion = pkg.version;
const ref = process.env['GITHUB_REF'];
if (ref !== `refs/tags/${releaseVersion}`) {
throw Error(
`GITHUB_REF ${ref} is different than the package.json version ${releaseVersion}.`
);
}
for (const [dep, version] of Object.entries(pkg.optionalDependencies)) {
if (version !== releaseVersion) {
throw Error(
`optional dependency ${dep}'s version doesn't match ${releaseVersion}.`
);
}
}
if (releaseVersion.indexOf('-dev') > 0) {
throw Error(`${releaseVersion} is a dev release.`);
}
const versionHeader = new RegExp(`^## ${releaseVersion}$`, 'm');
const changelog = await fs.readFile('CHANGELOG.md', 'utf8');
if (!changelog.match(versionHeader)) {
throw Error(`There's no CHANGELOG entry for ${releaseVersion}.`);
}
}