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
/
build.js
48 lines (40 loc) · 1.6 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
const { readFile, writeFile, rm } = require('fs').promises;
const { readdirSync, existsSync } = require('fs');
const admZip = require('adm-zip');
const { version } = require('./package.json');
const getCurrentXml = async (path, name) => {
let xml;
if (existsSync(`${path !== '' ? path + '/' : ''}${name}.xml`)) {
xml = await readFile(`${path !== '' ? path + '/' : ''}${name}.xml`, {
encoding: 'utf8',
});
return xml.replace(/{{version}}/g, version);
}
}
const zipExtension = async (path, name, type) => {
const noRoot = path.replace(`${process.cwd()}/`, '');
xml = await getCurrentXml(path, name);
const zip = new admZip();
readdirSync(path, { withFileTypes: true })
.filter(item => !/(^|\/)\.[^/.]/g.test(item.name))
.forEach(file => {
if (file.isDirectory()) {
if (file.name === 'Templates') return;
zip.addLocalFolder(`${noRoot}/${file.name}`, file.name, /^(?!\.DS_Store)/);
} else if (file.name === `${name}.xml`) {
zip.addFile(file.name, xml);
} else if (!['composer.json', 'composer.lock', '.DS_Store'].includes(file.name)) {
zip.addLocalFile(`${noRoot}/${file.name}`, false);
}
});
zip.addLocalFolder(`src_vendor/vendor/intervention/image/src/Intervention/Image`, 'src/Freebies/Intervention/Image', /^(?!\.DS_Store)/);
zip.getEntries().forEach(entry => {
if (/^\.DS_Store/.test(entry.entryName)) {
zip.deleteFile(entry.entryName);
}
});
await writeFile(`public/dist/lib_ttc_${version}.zip`, zip.toBuffer());
}
(async function exec() {
await zipExtension(`${process.cwd()}/src/libraries/Ttc`, `Ttc`, 'libraries');
})();