Skip to content

Commit 27b14a9

Browse files
author
Kapil Rastogi
authored
Merge pull request #11 from ExpediaDotCom/improve-release-process
improving the release process for npm module
2 parents 091b1c7 + 29d4b59 commit 27b14a9

5 files changed

Lines changed: 45 additions & 2 deletions

File tree

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ script:
1919
- make build
2020

2121
before_deploy:
22+
- make prepare_publish
2223
- cd dist
2324

2425
deploy:

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ check-node-version:
1414
.PHONY: build
1515
build: check-node-version npm_install idl_codegen tslint compile test
1616

17+
.PHONY: prepare_publish
18+
prepare_publish:
19+
node scripts/version.js
20+
cp package.json dist/
21+
cp README.md dist/
22+
1723
.PHONY: test
1824
test:
1925
./node_modules/mocha/bin/mocha -r ./node_modules/ts-node/register tests/**/*.ts
@@ -22,7 +28,6 @@ test:
2228
compile:
2329
rm -rf ./dist/
2430
tsc -p tsconfig.json
25-
cp package.json dist/
2631

2732
.PHONY: tslnt
2833
tslint:

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,8 @@ make build
2323
mkdir -p logs && node dist/examples/index.js
2424
```
2525

26+
## How to release this library?
27+
28+
We publish using the git tag. The version.js under scripts/ folder verifies if new tag is greater than current published version on npm.
29+
If it is good, it updates the new version in package.json under dist/ and publish it on npm
30+

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
"mocha": "^2.5.3",
3535
"ts-node": "^7.0.0",
3636
"tslint": "^5.0.0",
37-
"typescript": "2.9.2"
37+
"typescript": "2.9.2",
38+
"npm-registry-package-info": "1.0.5",
39+
"semver": "^5.5.0"
3840
}
3941
}

scripts/version.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
const pkginfo = require('npm-registry-package-info');
2+
const semver = require('semver');
3+
const fs = require('fs');
4+
5+
6+
const moduleName = 'haystack-client';
7+
8+
const opts = {
9+
'packages': [
10+
moduleName
11+
]
12+
};
13+
14+
pkginfo(opts, (error, data) => {
15+
if (error) {
16+
throw error;
17+
}
18+
const currentVersion = data.data[moduleName]['dist-tags']['latest'];
19+
const releaseVersion = process.env.TRAVIS_TAG
20+
if (!releaseVersion) {
21+
throw new Error('No git tag commit is found, fail to release the "haystack-client" module');
22+
}
23+
if (semver.lte(releaseVersion, currentVersion)) {
24+
throw new Error(`Current haystack-client on npm registry has greater than or equal new release version ${releaseVersion}. Check your git tag version`);
25+
}
26+
const rawPackageJson = fs.readFileSync('package.json');
27+
const packageJson = JSON.parse(rawPackageJson);
28+
packageJson.version = releaseVersion;
29+
fs.writeFileSync('package.json', JSON.stringify(packageJson, null, ' '));
30+
});

0 commit comments

Comments
 (0)