-
Notifications
You must be signed in to change notification settings - Fork 0
/
prepare-package.js
37 lines (31 loc) · 1.11 KB
/
prepare-package.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
import {cp, readFile, writeFile} from 'fs/promises';
const [, , nextVersion] = process.argv;
const packageJson = JSON.parse(await readFile('./package.json'));
const packageLockJson = JSON.parse(await readFile('./package-lock.json'));
function toJsonString(object) {
return JSON.stringify(object, null, ' ');
}
if (nextVersion !== undefined) {
packageJson.version = nextVersion;
await writeFile('./package.json', `${toJsonString(packageJson)}\n`);
packageLockJson.version = nextVersion;
packageLockJson.packages[''].version = nextVersion;
await writeFile('./package-lock.json', `${toJsonString(packageLockJson)}\n`);
}
delete packageJson.devDependencies;
delete packageJson.private;
await Promise.all([
await cp('.gitignore', './dist/.gitignore'),
await new Promise((resolve, reject) => {
cp('CHANGELOG.md', './dist/CHANGELOG.md').then(resolve).catch((error) => {
if (error.code === 'ENOENT') {
resolve();
} else {
reject(error);
}
});
}),
await cp('LICENSE', './dist/LICENSE'),
await writeFile('./dist/package.json', `${toJsonString(packageJson)}\n`),
await cp('README.md', './dist/README.md'),
]);