-
Notifications
You must be signed in to change notification settings - Fork 778
/
Copy pathreview-package.js
89 lines (78 loc) · 2.69 KB
/
review-package.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
// Helper for reviewing build artefacts against a past release.
//
// See also RELEASE.md.
/* eslint-env node */
'use strict';
const cp = require('child_process');
const fs = require('fs');
const path = require('path');
const readline = require('readline');
const { CommandError, getDiff, downloadFile, cleanDir, isValidVersion } = require('./utils.js');
async function confirm (text) {
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
await new Promise((resolve, reject) => {
rl.question(`${text} (y/N)> `, (answer) => {
rl.close();
if (String(answer).toLowerCase() === 'y') {
resolve();
} else {
reject(new Error('Audit aborted'));
}
});
});
}
const ReleaseAssets = {
async audit (prevVersion) {
if (typeof prevVersion !== 'string' || !isValidVersion(prevVersion)) {
throw new CommandError('Invalid or missing version argument');
}
{
cleanDir(path.join(__dirname, '../temp'));
}
{
const file = 'package.json';
console.log(`Auditing ${file}...`);
const prevContent = cp.execFileSync('git', [
'show',
`${prevVersion}:package.json`
], { encoding: 'utf8' });
const tempPrevPath = path.join(__dirname, '../temp', file);
fs.writeFileSync(tempPrevPath, prevContent);
const currentPath = path.join(__dirname, '..', file);
const diff = getDiff(tempPrevPath, currentPath, { allowUnchanged: true });
if (diff === null) {
console.log(`${file} was unchanged...`);
} else {
process.stdout.write(diff);
await confirm(`Accept ${file}?`);
}
}
{
const file = 'qunit.js';
console.log(`Auditing ${file}...`);
const prevUrl = `https://code.jquery.com/qunit/qunit-${prevVersion}.js`;
const tempPrevPath = path.join(__dirname, '../temp', file);
await downloadFile(prevUrl, tempPrevPath);
const currentPath = path.join(__dirname, '../qunit', file);
process.stdout.write(getDiff(tempPrevPath, currentPath));
await confirm(`Accept ${file}?`);
}
{
const file = 'qunit.css';
console.log(`Auditing ${file}...`);
const prevUrl = `https://code.jquery.com/qunit/qunit-${prevVersion}.css`;
const tempPrevPath = path.join(__dirname, '../temp', file);
await downloadFile(prevUrl, tempPrevPath);
const currentPath = path.join(__dirname, '../qunit', file);
process.stdout.write(getDiff(tempPrevPath, currentPath));
await confirm(`Accept ${file}?`);
}
}
};
const prevVersion = process.argv[2];
(async function main () {
await ReleaseAssets.audit(prevVersion);
}()).catch(e => {
console.error(e.toString());
process.exit(1);
});