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

33 lines
1.0 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"]);
}
export async function doMerge(jsFile: string) {
const mappingFile = `${jsFile}.map`;
console.log(`Bundle -> ${jsFile.green}`);
if (!fs.existsSync(mappingFile)) {
return;
}
console.log(` -> ${mappingFile.green}`);
const mergedMap = createMergedSourceMapFromFiles([
mappingFile.replace(/bundle\//, 'build/'),
mappingFile,
], true);
await fs.promises.writeFile(mappingFile, mergedMap);
}