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 0
/
build.js
40 lines (31 loc) · 1.51 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
const { copy, exists, mkdir, readFile, writeFile } = require('fs-extra').promises;
const util = require('util');
const rimRaf = util.promisify(require('rimraf'));
const { version } = require('./package.json');
(async function exec() {
await rimRaf('./dist');
await rimRaf('./package');
await copy('./src', './package');
if (!(await exists('./dist'))) {
await mkdir('./dist');
}
let xml = await readFile('./package/imageslazyloading.xml', { encoding: 'utf8' });
xml = xml.replace('{{version}}', version);
await writeFile('./package/imageslazyloading.xml', xml, { encoding: 'utf8' });
// Package it
const zip = new (require('adm-zip'));
zip.addLocalFolder('package', false);
zip.writeZip(`dist/plg_images_lazy_loading_${version}.zip`);
await rimRaf('./docs/dist');
await copy('./dist', './docs/dist');
// Update the version, docs
['docs/_coverpage.txt', 'docs/installation.txt', 'docs/component.txt'].forEach(async file => {
let cont = await readFile(file, { encoding: 'utf8' });
cont = cont.replace(/{{version}}/g, version);
cont = cont.replace(/{{download}}/g, `[Download v${version}](dist/plg_images_lazy_loading_${version}.zip ':ignore')`);
cont = cont.replace(/{{download2}}/g, `[component addlazyloading v${version}](https://ttc-freebies.github.io/com_addlazyloading/com_addlazyloading_1.0.0.zip ':ignore')`);
//{{download2}}
const ext = file === 'docs/update.txt' ? '.xml' : '.md';
await writeFile(file.replace('.txt', ext), cont, { encoding: 'utf8' });
})
})();