This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
Doric/doric-cli/src/actions.ts

37 lines
1.1 KiB
TypeScript
Raw Normal View History

2021-02-05 16:35:52 +08:00
import { Shell } from "./shell";
import { createMergedSourceMapFromFiles } from "source-map-merger"
import fs from "fs"
import { glob } from "./util";
export async function build() {
await Shell.exec("node", ["node_modules/.bin/tsc", "-p", "."]);
await Shell.exec("node", ["node_modules/.bin/rollup", "-c"]);
const bundleFiles = await glob("bundle/**/*.js");
for (let bundleFile of bundleFiles) {
await doMerge(bundleFile);
}
}
export async function clean() {
await Shell.exec("rm", ["-rf", "build"]);
await Shell.exec("rm", ["-rf", "bundle"]);
}
2021-02-05 18:20:42 +08:00
async function doMerge(jsFile: string) {
const mapFile = `${jsFile}.map`;
2021-02-05 16:35:52 +08:00
console.log(`Bundle -> ${jsFile.green}`);
2021-02-05 18:20:42 +08:00
if (!fs.existsSync(mapFile)) {
2021-02-05 16:35:52 +08:00
return;
}
2021-02-05 18:20:42 +08:00
console.log(` -> ${mapFile.green}`);
await mergeMap(mapFile);
}
export async function mergeMap(mapFile: string) {
2021-02-05 16:35:52 +08:00
const mergedMap = createMergedSourceMapFromFiles([
2021-02-05 18:20:42 +08:00
mapFile.replace(/bundle\//, 'build/'),
mapFile,
2021-02-05 16:35:52 +08:00
], true);
2021-02-05 18:20:42 +08:00
await fs.promises.writeFile(mapFile, mergedMap);
}