Skip to content
This repository was archived by the owner on May 1, 2020. It is now read-only.

Commit e58ca9e

Browse files
committed
chore(nightly): add the ability to release nightly builds
add the ability to release nightly builds
1 parent db79f9b commit e58ca9e

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"clean": "rimraf ./dist",
2323
"github-release": "node ./scripts/create-github-release.js",
2424
"lint": "tslint -c ./tslint.json --project ./tsconfig.json",
25+
"nightly": "npm run build && node ./scripts/publish-nightly.js",
2526
"release": "npm run build && npm run test && npm version patch && npm changelog && npm run github-release && npm publish",
2627
"test": "jasmine JASMINE_CONFIG_PATH=src/spec/jasmine.config.json || true",
2728
"watch": "npm run clean && tsc --watch"

scripts/publish-nightly.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
var execSync = require('child_process').execSync;
2+
var fs = require('fs');
3+
var path = require('path');
4+
5+
var packageJsonPath = path.join(__dirname, '..', 'package.json');
6+
var tempPackageJsonPath = path.join(__dirname, '..', 'package-orig.json');
7+
var originalPackageJson = require(packageJsonPath);
8+
9+
/*
10+
* This script assumes the `build` step was run prior to it
11+
*/
12+
13+
function backupOriginalPackageJson() {
14+
var originalContent = JSON.stringify(originalPackageJson, null, 2);
15+
fs.writeFileSync(tempPackageJsonPath, originalContent);
16+
}
17+
18+
function createNightlyVersionInPackageJson() {
19+
var originalVersion = originalPackageJson.version;
20+
originalPackageJson.version = originalVersion + '-' + createTimestamp();
21+
fs.writeFileSync(packageJsonPath, JSON.stringify(originalPackageJson, null, 2));
22+
}
23+
24+
function revertPackageJson() {
25+
var fileContent = fs.readFileSync(tempPackageJsonPath);
26+
fileContent = fileContent + '\n';
27+
fs.writeFileSync(packageJsonPath, fileContent);
28+
fs.unlinkSync(tempPackageJsonPath);
29+
}
30+
31+
function createTimestamp() {
32+
// YYYYMMDDHHMM
33+
var d = new Date();
34+
return d.getUTCFullYear() + // YYYY
35+
('0' + (d.getUTCMonth() + 1)).slice(-2) + // MM
36+
('0' + (d.getUTCDate())).slice(-2) + // DD
37+
('0' + (d.getUTCHours())).slice(-2) + // HH
38+
('0' + (d.getUTCMinutes())).slice(-2); // MM
39+
}
40+
41+
function publishToNpm() {
42+
var command = `npm publish --tag=nightly ${process.cwd()}`;
43+
execSync(command);
44+
}
45+
46+
47+
function mainFunction() {
48+
try {
49+
console.log('Building Nightly ... BEGIN');
50+
console.log('Backing up the original package.json');
51+
backupOriginalPackageJson();
52+
console.log('Creating the nightly version of package.json');
53+
createNightlyVersionInPackageJson();
54+
console.log('Publishing to npm');
55+
publishToNpm();
56+
console.log('Restoring original package.json');
57+
revertPackageJson();
58+
console.log('Building Nightly ... DONE');
59+
}
60+
catch (ex) {
61+
console.log(`Something went wrong with publishing the nightly. This process modifies the package.json, so restore it before committing code! - ${ex.message}`);
62+
process.exit(1);
63+
}
64+
}
65+
66+
mainFunction();

0 commit comments

Comments
 (0)