forked from fantasycalendar/FoundryVTT-PotatoOrNot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildNewPackage.ts
55 lines (42 loc) · 1.6 KB
/
buildNewPackage.ts
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
import { readFile, writeFile, unlink } from 'fs/promises';
import { existsSync, createWriteStream } from 'fs';
import archiver from 'archiver';
(async() => {
// We will start by getting the package.json
const JSONFiles = await Promise.all([
readFile('./package.json', 'utf-8'),
readFile('./module.json', 'utf-8')
]);
// We will then parse the JSON
const [packageData, moduleData] = JSONFiles.map((file) => JSON.parse(file));
// If we haven't updated the version in the module.json file, we will do it now
if (packageData.version !== moduleData.version){
moduleData.version = packageData.version;
console.log(`Updated version to ${packageData.version}`);
await writeFile('./module.json', JSON.stringify(moduleData, null, 2));
}
// We will copy our root module.json into the src directory
await writeFile('./src/module.json', JSON.stringify(moduleData, null, 2));
// We will then delete the potatoOrNot.zip so we can create a new one
if (existsSync('./potatoOrNot.zip')) await unlink('./potatoOrNot.zip');
// We will then create a new zip file
const output = createWriteStream('./potatoOrNot.zip');
const archive = archiver('zip', { zlib: { level: 9 } });
output.on('close', () => {
console.log(`Created potatoOrNot.zip (${archive.pointer()} total bytes)`);
});
archive.on('warning', (err) => {
if (err.code === 'ENOENT') {
console.warn(err);
} else {
// throw error
throw err;
}
});
archive.on('error', (err) => {
throw err;
});
archive.pipe(output);
archive.directory('./src/', false);
archive.finalize();
})()