-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-quip-app.js
executable file
·115 lines (104 loc) · 3.56 KB
/
build-quip-app.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
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/env node
const path = require('path');
const childProcess = require('child_process');
const fs = require('fs');
const semver = require('semver');
const commandLineArgs = require('command-line-args')
require('dotenv').config();
const definitions = [
{ name: 'command', defaultOption: true },
];
const options = commandLineArgs(definitions, { stopAtFirstUnknown: true });
if (!options.command) {
console.error('build-quip-app: you must supply a build command');
process.exit(1);
}
switch (options.command) {
case 'build':
buildQuip(options._unknown);
break;
case 'version':
changeVersion(options._unknown);
break;
default:
console.error(`build-quip-app: unknown build command '${options.command}'`);
process.exit(1);
}
function buildQuip(args) {
const definitions = [
{
name: 'manifest', alias: 'm', defaultValue: './app/manifest.json'
},
{
name: 'output', alias: 'o'
},
{
name: 'no-increment', type: Boolean,
},
{
name: 'no-build', type: Boolean,
},
{
name: 'app-id', type: String,
},
{
name: 'version-name', type: String,
},
{
name: 'version-number', type: Number,
},
{
name: 'build-command', type: String, defaultValue: 'npm run build',
}
];
const options = commandLineArgs(definitions, { argv: args, stopAtFirstUnknown: true });
const manifest = require(path.join(process.cwd(), options.manifest));
manifest.id = process.env.QUIP_APP_ID || options['app-id'] || manifest.id;
manifest.version_name = process.env.QUIP_VERSION_NAME || options['version-name'] || manifest.version_name;
if (!options['no-increment']) {
manifest.version_number = process.env.QUIP_VERSION_NUMBER || options['version-number'] || (manifest.version_number + 1);
console.log(`build-quip-app: the new version number is ${manifest.version_number}`);
}
fs.writeFileSync(options.output || options.manifest, JSON.stringify(manifest, null, 4));
if (!options['no-build']) {
childProcess.execSync(options['build-command'], { stdio: 'inherit' });
}
}
function changeVersion(args) {
const VERSION_LEVELS = ['major', 'minor', 'patch', 'premajor', 'preminor', 'prepatch', 'prerelease'];
const definitions = [
{
name: 'manifest', alias: 'm', defaultValue: './app/manifest.json'
},
{
name: 'output', alias: 'o'
},
{
name: 'version-name', type: String, defaultOption: true
},
];
const options = commandLineArgs(definitions, { argv: args, stopAtFirstUnknown: true });
const manifest = require(path.join(process.cwd(), options.manifest));
const versionName = manifest.version_name;
const increment = (options['version-name'] || '').toLowerCase().trim();
if (!increment) {
console.log(`build-quip-app: no version-name has been provided`);
process.exit(0);
}
if (VERSION_LEVELS.find((item) => item === increment)) {
if (!semver.valid(versionName)) {
console.error(`build-quip-app: ${versionName} is not in semver format`);
process.exit(1);
}
const newVersionName = semver.inc(versionName, increment, { loose: true });
manifest.version_name = newVersionName;
} else {
if (increment === '' || increment === 'version') {
console.error(`build-quip-app: version name must be one of ${VERSION_LEVELS.join(', ')} or the new version name`)
process.exit(1);
}
manifest.version_name = increment;
}
console.log(`build-quip-app: the new version name is ${manifest.version_name}`);
fs.writeFileSync(options.output || options.manifest, JSON.stringify(manifest, null, 4));
}