-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathutils.ts
103 lines (89 loc) · 3.39 KB
/
utils.ts
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
import * as fs from 'fs-extra';
const constants = {
RAW_BUILD_FILE_FILEPATH: '../build/mturk-engine.latest.raw.user.js',
CDN_BUILD_FILE_FILEPATH: '../build/mturk-engine.latest.user.js',
VERSION_NUMBER: process.argv[2]
};
export const generateRelease = async () => {
try {
// These things can happen concurrently.
await Promise.all([
createRawBuildFile(),
createCdnTemplate(),
deleteExtraneousFiles()
]);
await deleteStaticDirectory();
} catch (e) {
// tslint:disable-next-line:no-console
console.log(e);
process.exit(1);
}
};
const findSourceCodeFile = async () => {
const files = await fs.readdir('../build/static/js');
return files.find(filePath => !filePath.includes('.map'));
};
const deleteStaticDirectory = () => fs.remove('../build/static');
const deleteExtraneousFiles = () =>
Promise.all([
fs.unlink('../build/asset-manifest.json'),
fs.unlink('../build/service-worker.js'),
fs.unlink('../build/index.html')
]);
const createRawBuildFile = async () => {
const sourceCodeFile = await findSourceCodeFile();
await fs.createFile(constants.RAW_BUILD_FILE_FILEPATH);
await fs.writeFile(
constants.RAW_BUILD_FILE_FILEPATH,
rawUserScriptBoilerPlate
);
const sourceCode = await fs.readFile(`../build/static/js/${sourceCodeFile}`);
await fs.appendFile(constants.RAW_BUILD_FILE_FILEPATH, sourceCode);
};
const createCdnTemplate = async () => {
await fs.createFile(constants.CDN_BUILD_FILE_FILEPATH);
await fs.writeFile(
constants.CDN_BUILD_FILE_FILEPATH,
cdnUserScriptBoilerPlate
);
};
// tslint:disable:max-line-length
const rawUserScriptBoilerPlate = `// ==UserScript==
// @name Mturk Engine (Raw)
// @namespace https://github.com/Anveio/mturk-engine/
// @version ${constants.VERSION_NUMBER}
// @description Earn money more efficiently on Amazon's Mechanical Turk work platform.
// @author Anveio (Shovon Hasan)
// @license MIT
// @match https://worker.mturk.com/?mturkengine
// @match https://www.mturk.com/?mturkengine
// @grant none
// ==/UserScript==
/**
* After downloading this script visit https://worker.mturk.com/?mturkengine
*
* Mturk Engine is free and open source. Visit this project's github page at: https://github.com/Anveio/mturk-engine
* There you can view the source code, post issues, submit changes, suggest features, and download the latest version.
* Changelogs are available at: https://github.com/Anveio/mturk-engine/releases
*/
`;
const cdnUserScriptBoilerPlate = `// ==UserScript==
// @name Mturk Engine
// @namespace https://github.com/Anveio/mturk-engine/
// @version ${constants.VERSION_NUMBER}
// @description Earn money more efficiently on Amazon's Mechanical Turk work platform.
// @author Anveio (Shovon Hasan)
// @license MIT
// @match https://worker.mturk.com/?mturkengine
// @match https://www.mturk.com/?mturkengine
// @require [[[ Replace with rawgit URL. ]]]
// @grant none
// ==/UserScript==
/**
* After downloading this script visit https://worker.mturk.com/?mturkengine
*
* Mturk Engine is free and open source. Visit this project's github page at: https://github.com/Anveio/mturk-engine
* There you can view the source code, post issues, submit changes, suggest features, and download the latest version.
* Changelogs are available at: https://github.com/Anveio/mturk-engine/releases
*/
`;