This repository has been archived by the owner on Jul 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.js
63 lines (53 loc) · 1.82 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
const { copy, move, existsSync, mkdirSync, readFileSync, writeFileSync, createWriteStream } = require('fs-extra');
const { execSync } = require('child_process');
const { promisify } = require("es6-promisify");
const rimraf = require('rimraf')
const PromiseRimraf = promisify(rimraf);
const Archiver = require('archiver');
const package = require('./package.json');
const root = process.cwd();
PromiseRimraf('./package')
.then(() => {
execSync('npx rollup --config');
copy('./src/admin', './package/admin/')
.then(() => {
move('./package/admin/addlazyloading.xml', './package/addlazyloading.xml')
.then(() => {
if (!existsSync('./docs')) {
mkdirSync('./docs')
}
let xml = readFileSync('./package/addlazyloading.xml', { encoding: 'utf8' });
xml = xml.replace('{{version}}', package.version)
writeFileSync('./package/addlazyloading.xml', xml, { encoding: 'utf8' });
makePackage();
})
});
});
const makePackage = () => {
// Package it
const output = createWriteStream(`${root}/docs/com_addlazyloading_${package.version}.zip`);
let archive = Archiver('zip', {
zlib: { level: 9 }
});
output.on('close', function () {
console.log(`docs/com_addlazyloading_${package.version}.zip created: ${archive.pointer()} total bytes`);
});
output.on('end', function () {
console.log('Data has been drained');
});
// good practice to catch warnings (ie stat failures and other non-blocking errors)
archive.on('warning', function (err) {
if (err.code === 'ENOENT') {
// log warning
} else {
// throw error
throw err;
}
});
archive.on('error', function (err) {
throw err;
});
archive.pipe(output);
archive.directory('package/', false);
archive.finalize();
};