forked from arbron/fvtt-summoner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.mjs
41 lines (34 loc) · 1.11 KB
/
gulpfile.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
import fs from "fs";
import gulp from "gulp";
import nodeResolve from "@rollup/plugin-node-resolve";
import path from "path";
import { rollup } from "rollup";
/**
* Cache of the manifest file in case it needs to be accessed more than once.
* @type {object}
*/
let cached_manifest;
async function fetchManifest() {
if ( !cached_manifest ) cached_manifest = JSON.parse(await fs.promises.readFile("./module.json"));
return cached_manifest;
}
async function compileJavascript() {
const manifest = await fetchManifest();
for ( const esmodulePath of manifest.esmodules ) {
const parsedPath = path.parse(esmodulePath);
delete parsedPath.base;
const compiledPath = path.format({ ...parsedPath, name: `${parsedPath.name}-compiled` });
const sourcemapFile = path.format({ name: parsedPath.name, ext: parsedPath.ext });
const bundle = await rollup({
input: esmodulePath,
plugins: [nodeResolve()]
});
await bundle.write({
file: compiledPath,
format: "es",
sourcemap: true,
sourcemapFile: sourcemapFile
});
}
}
export const buildJS = gulp.series(compileJavascript);