This repository has been archived by the owner on Jan 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelease.mjs
82 lines (77 loc) · 3.06 KB
/
release.mjs
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
import { promises as FS } from 'fs';
import * as Path from 'path';
import AdmZip from 'adm-zip';
import {Settings} from './settings.mjs';
import {Formatters} from './build-formatters.mjs';
Promise.resolve()
.then(() => Settings.clearTerminal())
.then(() => Settings.printBorder())
.then(() => console.log.bold.white(`Packing MVW ${Settings.package.version} Release:\n`))
.then(() => clean())
.then(() => copy())
.then(() => zip())
.then(() => bump())
.then(() => console.log.bold.green(`Release Complete!`))
.catch(e => {
console.log.bold.red(`Release Failed:`);
console.error(e);
})
.then(() => Settings.printBorder());
async function clean() {
console.log.light(`Cleaning Latest Folder...`);
await FS.rm(Settings.latestOutput, {recursive: true, force: true});
await FS.mkdir(Settings.latestOutput, {recursive: true});
console.log.light(`Cleaning Release Folder...`);
await FS.rm(Settings.releaseOutput, {recursive: true, force: true});
await FS.mkdir(Settings.releaseOutput, {recursive: true});
console.log('');
}
async function copy() {
console.log.yellow('Copying builds...');
for (var file of await FS.readdir(Settings.buildOutput)) {
var source = Path.join(Settings.buildOutput, file);
var release = Path.join(Settings.releaseOutput, Path.basename(source));
console.log.light.green(`${source}\t-> ${release}`);
await FS.copyFile(source, release);
var latest = Path.join(Settings.latestOutput, Path.basename(source));
console.log.light.green(`${source}\t-> ${latest}`);
await FS.copyFile(source, latest);
}
console.log('');
}
async function zip() {
console.log.yellow('Packing source...')
var archive = new AdmZip();
for (var config of Settings.buildConfigs) {
var name = `${Settings.package.name}-${config.name}-v${Settings.package.version}.zip`;
console.log.light.green(`${name}`);
var build = new AdmZip();
var sources = Array.from(config.sources);
while (sources.length) {
var source = sources.shift();
if ((await FS.lstat(source)).isFile()) {
console.log.light(`\t${source}`);
var code = Formatters.formatModule(source, await FS.readFile(source, 'utf8'));
build.addFile(source, Buffer.from(code, 'utf-8'));
} else {
sources.push(
...(await FS.readdir(source))
.map(fname => Path.join(source, fname))
);
}
}
var buffer = await new Promise((s,e)=>build.toBuffer(s,e));
archive.addFile(name, buffer);
}
var target = Path.join(Settings.releaseOutput, `${Settings.package.name}-${Settings.package.version}.source.zip`);
console.log.yellow(`Writing archive: ${target}\n`);
archive.writeZip(target);
}
async function bump() {
var newVersion = (split => {
split[split.length-1]=`${(parseInt(split[split.length-1])||0)+1}`;
return split.join('.');
})(Array.from(Settings.package.version.matchAll(/\d+/g)));
console.log.yellow(`Bumping version ${Settings.package.version}->${Settings.package.version=newVersion}\n`);
await FS.writeFile('./package.json', JSON.stringify(Settings.package, null, 3));
}