-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsc4pac.js
69 lines (63 loc) · 1.86 KB
/
sc4pac.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
64
65
66
67
68
69
// # install.js
import fs from 'node:fs';
import path from 'node:path';
import cp from 'node:child_process';
import { pathToFileURL } from 'node:url';
import { Glob } from 'glob';
import { hideBin } from 'yargs/helpers';
import yargs from 'yargs/yargs';
import { parseAllDocuments } from 'yaml';
import { Minimatch } from 'minimatch';
import standardDeps from './standard-deps.js';
import standardVariants from './standard-variants.js';
// Parse the regular expressions for the packages
const { argv } = yargs(hideBin(process.argv));
const matchers = argv._.map(pattern => new Minimatch(pattern));
// Loop all packages
const glob = new Glob('**/*.yaml', {
cwd: path.resolve(import.meta.dirname, '../src'),
absolute: true,
});
const packages = glob
.walkSync()
.map(file => {
let contents = fs.readFileSync(file);
let docs = parseAllDocuments(String(contents));
return docs
.map(doc => doc.toJSON())
.filter(doc => !doc.assetId)
.map(pkg => `${pkg.group}:${pkg.name}`)
.filter(id => matchers.some(mm => mm.match(id)));
})
.flat()
.sort();
// Always add a bunch of dependencies that come in handy when testing.
packages.push(...standardDeps);
// Now generate the sc4pac-plugins.json file.
const pluginsRoot = path.resolve(import.meta.dirname, '../dist/plugins');
const cacheRoot = process.env.SC4PAC_CACHE_ROOT;
const json = {
config: {
pluginsRoot,
cacheRoot,
tempRoot: `.${path.sep}temp`,
variant: {
...standardVariants,
},
channels: [
'https://memo33.github.io/sc4pac/channel/',
pathToFileURL(path.resolve(import.meta.dirname, '../dist/channel'))+'/',
],
},
explicit: packages,
};
await fs.promises.mkdir(pluginsRoot, { recursive: true });
await fs.promises.writeFile(
path.join(pluginsRoot, 'sc4pac-plugins.json'),
JSON.stringify(json, null, 2),
);
// Now run sc4pac.
cp.execSync('sc4pac update -y', {
cwd: pluginsRoot,
stdio: 'inherit',
});