Skip to content

Commit db78224

Browse files
committed
ci(package): update package version before shipping
1 parent d6bb484 commit db78224

File tree

4 files changed

+89
-18
lines changed

4 files changed

+89
-18
lines changed

package-lock.json

+66-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+4-6
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,15 @@
66
"scripts": {
77
"prebuild": "npm run clean",
88
"build": "tsc -p ./tsconfig.json",
9+
"postbuild": "npm run package",
910
"clean": "rimraf ./dist",
1011
"check": "npm run lint && npm run build && npm test",
1112
"commit": "commit",
1213
"lint": "tslint -p ./tsconfig.json",
1314
"test": "jest --coverage",
14-
"prepackage": "npm run build",
1515
"package": "ts-node ./support/package.ts",
16-
"release": "git checkout master && git pull origin master && standard-version",
17-
"preship-it": "npm run package",
18-
"ship-it": "git push --follow-tags origin master && cd ./dist && npm publish"
16+
"release": "git checkout master && git pull origin master && standard-version && ts-node ./support/updatePackageVersion.ts",
17+
"ship": "git push --follow-tags origin master && cd ./dist && npm publish"
1918
},
2019
"keywords": [
2120
"compare",
@@ -39,11 +38,10 @@
3938
"devDependencies": {
4039
"@commitlint/cli": "^7.2.1",
4140
"@commitlint/prompt-cli": "^7.5.0",
42-
"@types/app-root-path": "^1.2.4",
4341
"@types/jest": "^24.0.0",
4442
"@types/node": "^11.9.0",
45-
"app-root-path": "^2.1.0",
4643
"coveralls": "^3.0.2",
44+
"get-root-path": "^2.0.2",
4745
"husky": "^1.1.2",
4846
"jest": "^24.3.1",
4947
"replace": "^1.0.0",

support/package.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import * as root from 'app-root-path';
21
import * as fs from 'fs';
2+
import { rootPath } from 'get-root-path';
3+
import * as path from 'path';
34

4-
fs.copyFileSync(root.resolve('./package.json'), root.resolve('./dist/package.json'));
5+
fs.copyFileSync(path.join(rootPath, 'package.json'), path.join(rootPath, 'dist/package.json'));
6+
fs.copyFileSync(path.join(rootPath, 'README.md'), path.join(rootPath, 'dist/README.md'));
57

6-
fs.copyFileSync(root.resolve('./README.md'), root.resolve('./dist/README.md'));
7-
8-
const packageJson = JSON.parse(fs.readFileSync('./dist/package.json', 'utf8'));
8+
const packageJson = JSON.parse(fs.readFileSync(path.join(rootPath, 'dist/package.json'), 'utf8'));
99

1010
delete packageJson.private;
1111
delete packageJson.scripts;
1212
delete packageJson.devDependencies;
1313

14-
fs.writeFileSync(root.resolve('./dist/package.json'), JSON.stringify(packageJson, null, ' '), 'utf8');
14+
fs.writeFileSync(path.join(rootPath, 'dist/package.json'), JSON.stringify(packageJson, null, ' '), 'utf8');

support/updatePackageVersion.ts

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import * as fs from 'fs';
2+
import { rootPath } from 'get-root-path';
3+
import * as path from 'path';
4+
5+
const sourcePackageFileName = path.join(rootPath, 'package.json');
6+
const destinationPackageFileName = path.join(rootPath, 'dist/package.json');
7+
8+
const sourcePackage = JSON.parse(fs.readFileSync(sourcePackageFileName, 'utf-8'));
9+
const destinationPackage = JSON.parse(fs.readFileSync(destinationPackageFileName, 'utf-8'));
10+
11+
destinationPackage.version = sourcePackage.version;
12+
13+
fs.writeFileSync(destinationPackageFileName, JSON.stringify(destinationPackage, null, ' '), 'utf-8');

0 commit comments

Comments
 (0)