This repository has been archived by the owner on Apr 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 52
/
build.js
61 lines (53 loc) · 1.57 KB
/
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
const yargs = require('yargs');
const glob = require('glob');
const npmRun = require('npm-run');
const fs = require('fs');
const argv = yargs
.option('provider', {
alias: 'p',
default: null
})
.argv;
(function () {
const providers = glob
.sync(`./server/lib/senders/*.js`)
.map((filepath) => {
const dirs = filepath.split('/');
const name = dirs[dirs.length - 1];
return name.replace('.js', '');
});
if (argv.provider) {
if (providers.indexOf(argv.provider) < 0) {
console.log(`Unsupported provider - ${argv.provider}`);
process.exit(1);
}
buildProvider(argv.provider);
} else {
console.log('Provider not specified. Building all known providers...');
providers.forEach(buildProvider);
}
process.exit(0);
}());
function buildProvider (providerName) {
console.log(`Building logs-to-${providerName} extension...`);
prepareDirectory(providerName);
npmRun.sync(`rimraf dist/${providerName}`);
const command = `npm run prepareWebtask -- --provider=${providerName} && ` +
`cross-env A0EXT_PROVIDER=${providerName} a0-ext build:server ./webtask.js ./dist/${providerName}`;
try {
npmRun.sync(command);
npmRun.sync(`cp ./webtask.json ./dist/${providerName}/webtask.json`);
console.log(`Complete! See "dist/${providerName}"`);
} catch (e) {
console.log(`Error occurred while trying to build ${providerName}`, e);
process.exit(1);
}
}
function prepareDirectory (providerName) {
const dir = `./dist/${providerName}`;
try {
fs.statSync(dir);
} catch(e) {
fs.mkdirSync(dir);
}
}