This repository has been archived by the owner on Dec 28, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
executable file
·82 lines (65 loc) · 1.72 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env node
'use strict';
const argv = require('minimist')(process.argv.slice(2));
const fs = require('fs');
const path = require('path');
const archiver = require('archiver');
const target = path.join(getPath());
const archive = archiver('zip', {});
if (!fs.existsSync(target)) {
fs.mkdirSync(target);
}
const output = fs.createWriteStream(`${target}${path.sep}${getFileName()}`);
output.on('close', () => {
console.log(archive.pointer() + ' total bytes');
console.log('archiver has been finalized and the output file descriptor has closed.');
return 0;
});
output.on('end', () => {
console.log('Data has been drained');
return 0;
});
archive.on('warning', onWarning);
archive.on('error', onError);
archive.directory('dist'+path.sep, false);
archive.pipe(output);
archive.finalize();
function getPath() {
if (argv.path) {
return argv.path;
}
return `.${path.sep}target`;
}
function getFileName() {
let languageCode;
const packageJson = JSON.parse(fs.readFileSync(path.join(`.${path.sep}package.json`), 'utf-8'));
const projectName = packageJson.name;
const version = packageJson.version;
if (argv.en) {
languageCode = 'en';
} else if (argv.de) {
languageCode = 'de';
} else if (argv.lang === 'en') {
languageCode = 'en';
} else if (argv.lang === 'de') {
languageCode = 'de';
} else if (argv.language === 'en') {
languageCode = 'en';
} else if (argv.language === 'de') {
languageCode = 'de';
} else {
languageCode = 'en';
}
return `${projectName}-v${version}-${languageCode}-dist.zip`;
}
function onWarning(err) {
console.warn(err);
if (err.code === 'ENOENT') {
// log warning
} else {
throw err;
}
}
function onError(err) {
throw err;
}