forked from ionic-team/ionic-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpublish-nightly.js
More file actions
66 lines (56 loc) · 2.09 KB
/
publish-nightly.js
File metadata and controls
66 lines (56 loc) · 2.09 KB
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
var execSync = require('child_process').execSync;
var fs = require('fs');
var path = require('path');
var packageJsonPath = path.join(__dirname, '..', 'package.json');
var tempPackageJsonPath = path.join(__dirname, '..', 'package-orig.json');
var originalPackageJson = require(packageJsonPath);
/*
* This script assumes the `build` step was run prior to it
*/
function backupOriginalPackageJson() {
var originalContent = JSON.stringify(originalPackageJson, null, 2);
fs.writeFileSync(tempPackageJsonPath, originalContent);
}
function createNightlyVersionInPackageJson() {
var originalVersion = originalPackageJson.version;
originalPackageJson.version = originalVersion + '-' + createTimestamp();
fs.writeFileSync(packageJsonPath, JSON.stringify(originalPackageJson, null, 2));
}
function revertPackageJson() {
var fileContent = fs.readFileSync(tempPackageJsonPath);
fileContent = fileContent + '\n';
fs.writeFileSync(packageJsonPath, fileContent);
fs.unlinkSync(tempPackageJsonPath);
}
function createTimestamp() {
// YYYYMMDDHHMM
var d = new Date();
return d.getUTCFullYear() + // YYYY
('0' + (d.getUTCMonth() + 1)).slice(-2) + // MM
('0' + (d.getUTCDate())).slice(-2) + // DD
('0' + (d.getUTCHours())).slice(-2) + // HH
('0' + (d.getUTCMinutes())).slice(-2); // MM
}
function publishToNpm() {
var command = `npm publish --tag=nightly ${process.cwd()}`;
execSync(command);
}
function mainFunction() {
try {
console.log('Building Nightly ... BEGIN');
console.log('Backing up the original package.json');
backupOriginalPackageJson();
console.log('Creating the nightly version of package.json');
createNightlyVersionInPackageJson();
console.log('Publishing to npm');
publishToNpm();
console.log('Restoring original package.json');
revertPackageJson();
console.log('Building Nightly ... DONE');
}
catch (ex) {
console.log(`Something went wrong with publishing the nightly. This process modifies the package.json, so restore it before committing code! - ${ex.message}`);
process.exit(1);
}
}
mainFunction();