-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathdist.js
105 lines (90 loc) · 2.95 KB
/
dist.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
const execa = require('execa');
const { remove, copy, readFile, writeFile, mkdirp, move } = require('fs-extra');
const rootDir = __dirname;
const baseDistDir = rootDir + '/dist';
const sourceDistName = 'chrome';
const execCommand2 = async (command, options) => {
options = {
showInput: true,
showStdout: true,
showStderr: true,
quiet: false,
...options,
};
if (options.quiet) {
options.showInput = false;
options.showStdout = false;
options.showStderr = false;
}
if (options.showInput) {
console.info(`> ${command.join(' ')}`);
}
const args = command;
const executableName = args[0];
args.splice(0, 1);
const promise = execa(executableName, args);
if (options.showStdout) promise.stdout.pipe(process.stdout);
if (options.showStderr) promise.stdout.pipe(process.stderr);
const result = await promise;
return result.stdout.trim();
}
const patchManifestForFirefox = async (inputPath) => {
const content = JSON.parse(await readFile(inputPath, 'utf8'));
content.browser_specific_settings = {
gecko: {
id: 'net.cozic.plugins.GitHubRawActionLogViewer@nospam',
}
}
await writeFile(inputPath, JSON.stringify(content, null, '\t'));
}
const main = async() => {
const distributions = [
{
name: 'chrome',
},
{
name: 'firefox',
postProcess: async () => {
await patchManifestForFirefox(baseDistDir + '/firefox/manifest.json');
},
},
];
for (const dist of distributions) {
if (dist.name !== sourceDistName) {
await copy(baseDistDir + '/' + sourceDistName, baseDistDir + '/' + dist.name);
}
}
for (const dist of distributions) {
const distDir = baseDistDir + '/' + dist.name;
const archiveName = dist.name + '.zip';
const archiveFullPath = baseDistDir + '/' + archiveName;
process.chdir(distDir);
await remove(archiveName);
if (dist.postProcess) await dist.postProcess();
await remove(archiveFullPath);
await execCommand2(['7z', 'a', '-tzip', archiveName, '*']);
await move(archiveName, archiveFullPath);
}
const sourceDir = baseDistDir + '/source';
const sourceArchiveName = 'source.zip';
const fullSourcePath = baseDistDir + '/' + sourceArchiveName;
await remove(sourceDir);
await mkdirp(sourceDir);
await copy(rootDir + '/src', sourceDir + '/src');
await copy(rootDir + '/dist.js', sourceDir + '/dist.js');
await copy(rootDir + '/manifest.json', sourceDir + '/manifest.json');
await copy(rootDir + '/package.json', sourceDir + '/package.json');
await copy(rootDir + '/yarn.lock', sourceDir + '/yarn.lock');
await copy(rootDir + '/icon16.png', sourceDir + '/icon16.png');
await copy(rootDir + '/icon32.png', sourceDir + '/icon32.png');
await copy(rootDir + '/icon48.png', sourceDir + '/icon48.png');
await copy(rootDir + '/icon512.png', sourceDir + '/icon512.png');
process.chdir(sourceDir);
await remove(fullSourcePath);
await execCommand2(['7z', 'a', '-tzip', 'source.zip', '*']);
await move(sourceArchiveName, fullSourcePath);
}
main().catch(error => {
console.error(error);
process.exit(1);
});