generated from tarkant/greasemonkey-webpack-typescript-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpost-build.js
44 lines (37 loc) · 1.3 KB
/
post-build.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
/**
* This script takes your package.json info and prepends the necessary header comments to the userscript.
* You'll have to add your @match url and @include if needed (below an example)
*
* // @match https://a-cool-website.com
* // @include /someRegExOrOtherUrl/
*/
const fs = require('fs');
const package = require('./package.json');
const distUserScript = package.name + '.user.js';
const url = package.repository.url.replace('git+', '').replace('.git', '');
const HEADER = `// ==UserScript==
// @name ${package.name}
// @namespace ${url}
// @version ${package.version}
// @description ${package.description}
// @licence ${package.license}
// @author ${package.author}
// @match http*://example.com/
// @grant none
// ==/UserScript==
`;
/**
* It's dangerous to go alone, make sure to be well equiped if you want to fiddle with this code ;D
*/
const data = fs.readFileSync('./dist/' + distUserScript);
const fd = fs.openSync('./dist/' + distUserScript, 'w+');
const insert = new Buffer.alloc(HEADER.length, HEADER);
fs.writeSync(fd, insert, 0, insert.length, 0);
fs.writeSync(fd, data, 0, data.length, insert.length);
fs.close(fd, (err) => {
if (err){
throw err;
} else {
console.info('Successfully added the header to the userscript !');
}
});