-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.mjs
More file actions
58 lines (49 loc) · 1.29 KB
/
build.mjs
File metadata and controls
58 lines (49 loc) · 1.29 KB
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
import path from 'path';
import { rollup } from 'rollup';
import { babel } from '@rollup/plugin-babel';
import glob from 'glob';
import resourcedata from './resourcedata.mjs'
const srcDir = "./src";
const distDir = "./dist";
let pattern = process.argv[2] ? process.argv[2].replace(/\.js$/, '') : '*'
const build = (inputOptions, outputOptions) => {
return rollup(inputOptions)
.then(bundle => {
bundle.write(outputOptions);
})
.catch(e => {
console.log(e);
})
}
glob.sync(`${pattern}.js`, {
cwd: srcDir,
ignore: 'modules/**'
}).forEach(async entry => {
const filename = entry.replace(/\.js$/, '');
const resource = resourcedata[filename] ?? {}
let banner = `/*
* ${filename}
* Version ${resource.ver ?? '1.0'}
*
* (c) 2022 uco
*
* Released under the MIT license
* http://opensource.org/licenses/mit-license.php
*/\n\n`
if (resource.description) {
banner += `//DESCRIPTION:${resource.description}\n\n`
}
banner += `#target indesign
#targetengine 'utsutsunogare'\n\n`
banner += `var NAME = '${filename}';\n`
const inputOptions = {
input: path.resolve(srcDir, entry),
plugins: [babel({ babelHelpers: 'bundled' })]
};
const outputOptions = {
format: "es",
file: path.resolve(distDir, `${resource.name}.jsx`),
banner
};
await build(inputOptions, outputOptions);
})