forked from stevenlei/spacingjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extensions.config.js
36 lines (34 loc) · 1.17 KB
/
extensions.config.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
const fs = require('fs');
const path = require('path');
const { execSync } = require('child_process');
const PackageJSON = require('./package.json');
const ManifestJSON = require('./extensions/chrome/manifest.json');
const resolve = (dir) => path.resolve(__dirname, dir);
const versionReg = /(\d+\.\d+\.\d+)/g;
const currentVersion = PackageJSON.version;
build();
function build() {
// build to chrome
execSync(`cp dist/bundle.js extensions/chrome/bundle.js`);
// sync version
ManifestJSON.version = currentVersion;
fs.writeFileSync(
resolve('extensions/chrome/manifest.json'),
JSON.stringify(ManifestJSON, null, 2),
'utf8'
);
// pre build tampermonkey
execSync(`rm -rf extensions/tampermonkey/spacingjs_*`);
// concat content
let header = fs.readFileSync(
resolve('extensions/tampermonkey/header.js'),
'utf8'
);
header.replace(versionReg, currentVersion);
const bundle = fs.readFileSync(resolve('dist/bundle.js'), 'utf8');
const script = header + '\r\n' + bundle;
// write and prettier
const target = `extensions/tampermonkey/spacingjs_${currentVersion}.js`;
fs.writeFileSync(resolve(target), script, 'utf8');
console.log('build complete!');
}