forked from foliojs/png.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile.js
108 lines (86 loc) · 2.85 KB
/
Makefile.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
// https://github.com/shelljs/shelljs#command-reference
// https://devhints.io/shelljs
// https://github.com/shelljs/shelljs/wiki/The-make-utility
require('shelljs/make');
config.fatal = true;
config.verbose = true;
const readline = require('readline');
const { execFileSync } = require('child_process');
const packageJson = require('./package.json');
target.all = () => {
target.clean();
target.lint();
target.compileTS();
target.rollupUMD();
target.rollupUMDMin();
};
target.lint = () => {
exec(`prettier --loglevel error --write "src/**/*.ts"`);
exec('tslint --project ./tsconfig.json --fix');
};
target.clean = () => {
rm('-rf', 'lib');
rm('-rf', 'es');
rm('-rf', 'dist');
};
target.compileTS = () => {
target.clean();
exec('tsc --module CommonJS --outDir lib');
exec('tsc --module ES2015 --outDir es');
};
target.rollupUMD = () => {
env.UGLIFY = false;
exec(`rollup -c rollup.config.js -o dist/png-ts.js`);
};
target.rollupUMDMin = () => {
env.UGLIFY = true;
exec(`rollup -c rollup.config.js -o dist/png-ts.min.js`);
};
/* =============================== Release ================================== */
target.releaseNext = () => {
const version = `${packageJson.version}@next`;
console.log('Releasing version', version);
target.all();
execFileSync('yarn', ['publish', '--tag', 'next'], { stdio: 'inherit' });
};
// Extra confirmation to avoid accidental releases to @latest
const promptForVerionToBeReleased = async (version) => {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
const question = `Enter "${version}" to proceed with the release: `;
return new Promise((resolve) => {
rl.question(question, (answer) => {
rl.close();
resolve(answer);
});
});
};
target.releaseLatest = async () => {
const currentBranch = exec('git rev-parse --abbrev-ref HEAD').stdout.trim();
if (currentBranch !== 'master') {
console.error('Must be on `master` branch to cut an @latest release.');
return;
}
const version = `${packageJson.version}@latest`;
console.log('Releasing version', version);
target.all();
const enteredVersion = await promptForVerionToBeReleased(version);
if (enteredVersion !== version) {
console.error('Entered version does match. Aborting release.');
return;
}
execFileSync('yarn', ['publish', '--tag', 'latest'], { stdio: 'inherit' });
const tagName = `v${packageJson.version}`;
exec(`git commit -am 'Bump version to ${packageJson.version}'`);
exec('git push');
exec(`git tag ${tagName}`);
exec(`git push origin ${tagName}`);
console.log('Created git tag:', tagName);
const zipName = `png-ts_${tagName}.zip`;
exec(`zip --exclude node_modules -r ${zipName} .`);
console.log('Zip archive of', tagName, 'written to', zipName);
console.log();
console.log('🎉 Release of', version, 'complete! 🎉');
};