-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathrollup.config.js
64 lines (61 loc) · 1.5 KB
/
rollup.config.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
import { readdirSync, readFileSync, writeFileSync } from 'fs';
import typescript from 'rollup-plugin-typescript2';
const commands = Object.create(null);
export default [
{
input: {
'kernel': 'src/kernelspace/index.ts'
},
output: {
chunkFileNames: '[name].js',
entryFileNames: '[name].js',
format: 'esm',
dir: 'public/lib'
},
plugins: [
typescript()
]
},
{
input: {
'process': 'src/userspace/index.ts'
},
output: {
exports: 'named',
format: 'iife',
dir: 'public/lib'
},
plugins: [
typescript()
]
},
...readdirSync(__dirname + '/src/command')
.filter(name => name.endsWith('.ts'))
.map(name =>
[`${name.slice(0, -3)}`, `src/command/${name}`]
)
.map(([name, from]) => {
/** @type {string} */
const content = readFileSync(from, 'utf8');
const [, description = '', usage = ''] = /\/\*\*((?:.|\n)+?)(?:@usage\s([^\n]+?)\s+)?\*\//.exec(content) ?? [];
commands[name] = {
usage: usage.split(' ').filter(x => x),
description: description.replace(/^(?:\n|\s\*\s)/gm, '').trim()
};
return ({
input: {
[name]: from
},
output: {
exports: 'named',
name: 'webcontainer',
format: 'iife',
dir: 'public/command'
},
plugins: [
typescript()
]
});
})
];
writeFileSync(__dirname + '/public/command/help.json', JSON.stringify(commands));