forked from wakatime/browser-wakatime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xclap.ts
125 lines (124 loc) · 4.15 KB
/
xclap.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/* eslint-disable @typescript-eslint/no-unsafe-call */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
/* eslint-disable @typescript-eslint/no-var-requires */
import * as fs from 'fs';
import { join } from 'path';
import * as shelljs from 'shelljs';
import waitOn from 'wait-on';
const { load, exec, serial, concurrent } = require('@xarc/run');
const waitForFilesTask = (...files: string[]) => (): Promise<unknown> => {
return waitOn({
delay: 2000,
interval: 3000,
resources: [...files],
verbose: true,
});
};
const nextBuildFolder = join(__dirname, 'dist');
const ffNextBuildFolder = join(nextBuildFolder, 'firefox');
const chromeNextBuildFolder = join(nextBuildFolder, 'chrome');
const filesNeededForNextBuild = [
'manifest.json',
'background.js',
'options.js',
'options.html',
'popup.js',
'popup.html',
'public/js/browser-polyfill.min.js',
'public/css/app.css',
'graphics/wakatime-logo-16.png',
];
const chromeNextBuildFileWaitTask = waitForFilesTask(
nextBuildFolder,
chromeNextBuildFolder,
...filesNeededForNextBuild.map((f) => join(chromeNextBuildFolder, f)),
);
const ffNextBuildFileWaitTask = waitForFilesTask(
nextBuildFolder,
ffNextBuildFolder,
...filesNeededForNextBuild.map((f) => join(ffNextBuildFolder, f)),
);
const makePublicFolder = () => {
if (!fs.existsSync('public/js')) {
if (!fs.existsSync('public')) {
fs.mkdirSync('public');
}
fs.mkdirSync('public/js');
}
};
const copyFromNodeModules = () => {
fs.copyFileSync(
'node_modules/webextension-polyfill/dist/browser-polyfill.min.js',
'public/js/browser-polyfill.min.js',
);
fs.copyFileSync(
'node_modules/webextension-polyfill/dist/browser-polyfill.min.js.map',
'public/js/browser-polyfill.min.js.map',
);
shelljs.cp(
'-Rf',
join(__dirname, 'node_modules/font-awesome/fonts'),
join(__dirname, 'public/fonts/'),
);
};
load({
build: [
serial('postinstall', exec('gulp')),
'webpack',
concurrent(
exec('web-ext build'),
exec(`web-ext build -a dist/firefox/web-ext-artifacts --source-dir ${ffNextBuildFolder}`),
),
],
clean: [exec('rimraf public coverage vendor web-ext-artifacts'), 'clean:webpack'],
'clean:webpack': exec('rimraf dist'),
dev: [
'clean',
'postinstall',
concurrent('watch', 'web-ext:run:firefox-next', 'web-ext:run:chrome-next'),
],
'dev:legacy': [
'clean',
'postinstall',
concurrent(exec('gulp watch'), 'web-ext:run:firefox-legacy', 'web-ext:run:chrome-legacy'),
],
eslint: exec('eslint src . --fix'),
less: exec('lessc assets/less/app.less public/css/app.css'),
lint: ['prettier', 'eslint'],
postinstall: ['clean', makePublicFolder, copyFromNodeModules, 'less'],
prettier: [exec('prettier --write .')],
'remotedev-server': exec('remotedev --hostname=localhost --port=8000'),
test: ['build', 'lint', 'test-jest', 'test-js'],
'test-jest': [exec('jest --clearCache'), exec('jest --verbose --coverage')],
'test-jest-update': exec('jest -u'),
'test-js': 'phantomjs tests/run.js',
'wait:legacy-files': waitForFilesTask(
'manifest.json',
'public/js/browser-polyfill.min.js',
'public/js/events.js',
'options.html',
),
watch: concurrent('watch-jest', 'webpack:watch', 'remotedev-server'),
'watch-jest': exec('jest --watch'),
'web-ext:run:chrome': concurrent('web-ext:run:chrome-next', 'web-ext:run:chrome-legacy'),
'web-ext:run:chrome-legacy': [
'wait:legacy-files',
exec('web-ext run -t chromium --source-dir .'),
],
'web-ext:run:chrome-next': [
chromeNextBuildFileWaitTask,
exec('web-ext run -t chromium --source-dir dist/chrome'),
],
'web-ext:run:firefox': concurrent('web-ext:run:firefox-next', 'web-ext:run:firefox-legacy'),
'web-ext:run:firefox-legacy': [
'wait:legacy-files',
exec('web-ext run -t firefox-desktop --source-dir .'),
],
'web-ext:run:firefox-next': [
ffNextBuildFileWaitTask,
exec('web-ext run -t firefox-desktop --source-dir dist/firefox'),
],
webpack: ['clean:webpack', exec('webpack --mode production')],
'webpack:dev': ['clean:webpack', exec('webpack --mode development')],
'webpack:watch': ['clean:webpack', exec('webpack --mode development --watch')],
});