70bf21e064
Handle Changesets / Handle Changesets (push) Waiting to run
Semgrep OSS scan / semgrep-oss (push) Waiting to run
Deploy (to testing) and Test Playground Preview Worker / Deploy Playground Preview Worker (testing) (push) Has been skipped
Deploy Workers Shared Staging / Deploy Workers Shared Staging (push) Failing after 0s
Prerelease / build (push) Has been skipped
54 lines
1.5 KiB
TypeScript
54 lines
1.5 KiB
TypeScript
import { cp } from "node:fs/promises";
|
|
import { build, context } from "esbuild";
|
|
import { globSync } from "tinyglobby";
|
|
import type { BuildOptions } from "esbuild";
|
|
|
|
const run = async () => {
|
|
const argv = process.argv.slice(2);
|
|
const watchMode = argv[0] === "--watch";
|
|
|
|
const config: BuildOptions = {
|
|
entryPoints: ["./src/cli.ts"],
|
|
bundle: true,
|
|
outdir: "./dist",
|
|
platform: "node",
|
|
// This is required to support jsonc-parser. See https://github.com/microsoft/node-jsonc-parser/issues/57
|
|
mainFields: ["module", "main"],
|
|
format: "cjs",
|
|
define: {
|
|
"process.env.SPARROW_SOURCE_KEY": JSON.stringify(
|
|
process.env.SPARROW_SOURCE_KEY ?? ""
|
|
),
|
|
},
|
|
};
|
|
|
|
const runBuild = async () => {
|
|
await build(config);
|
|
// npm pack doesn't include .gitignore files (see https://github.com/npm/npm/issues/3763)
|
|
// To workaround, copy all ".gitignore" files as "__dot__gitignore" so npm pack includes them
|
|
// The latter has been added to the project's .gitignore file
|
|
// This renaming will be reversed when each template is used
|
|
// We can continue to author ".gitignore" files in each template
|
|
for (const filepath of globSync("templates*/**/.gitignore")) {
|
|
await cp(filepath, filepath.replace(".gitignore", "__dot__gitignore"));
|
|
}
|
|
};
|
|
|
|
const runWatch = async () => {
|
|
const ctx = await context(config);
|
|
await ctx.watch();
|
|
console.log("Watching...");
|
|
};
|
|
|
|
if (watchMode) {
|
|
await runWatch();
|
|
} else {
|
|
await runBuild();
|
|
}
|
|
};
|
|
|
|
run().catch((error) => {
|
|
console.error(error);
|
|
process.exit(1);
|
|
});
|