cli: doric build and doric clean
This commit is contained in:
32
doric-cli/src/actions.ts
Normal file
32
doric-cli/src/actions.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
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);
|
||||
}
|
@@ -1,6 +1,7 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import commander from "commander"
|
||||
import { build, clean } from "./actions";
|
||||
import create from "./create"
|
||||
|
||||
commander
|
||||
@@ -19,10 +20,12 @@ commander
|
||||
})
|
||||
commander
|
||||
.command('build')
|
||||
.action(function () {
|
||||
.action(async function () {
|
||||
await build();
|
||||
})
|
||||
commander
|
||||
.command('clean')
|
||||
.action(function () {
|
||||
.action(async function () {
|
||||
await clean();
|
||||
})
|
||||
commander.parse(process.argv)
|
||||
|
1
doric-cli/src/modules.d.ts
vendored
Normal file
1
doric-cli/src/modules.d.ts
vendored
Normal file
@@ -0,0 +1 @@
|
||||
declare module 'source-map-merger'
|
@@ -1,3 +1,27 @@
|
||||
import globLib, { IOptions } from "glob";
|
||||
|
||||
export function getAssetsDir() {
|
||||
return `${__dirname}/../assets`;
|
||||
}
|
||||
|
||||
export async function glob(pattern: string, options?: IOptions) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (options) {
|
||||
globLib(pattern, options, (err, ret) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
resolve(ret);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
globLib(pattern, (err, ret) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
resolve(ret);
|
||||
}
|
||||
});
|
||||
}
|
||||
}) as Promise<string[]>;
|
||||
}
|
Reference in New Issue
Block a user