feat: release v0.0.1
This commit is contained in:
60
scripts/build.mjs
Normal file
60
scripts/build.mjs
Normal file
@@ -0,0 +1,60 @@
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { copyFileSync, existsSync, mkdirSync, readdirSync, rmSync, statSync } from "node:fs";
|
||||
import { dirname, extname, join, relative } from "node:path";
|
||||
import { createRequire } from "node:module";
|
||||
|
||||
const require = createRequire(import.meta.url);
|
||||
const rootDir = process.cwd();
|
||||
const srcDir = join(rootDir, "src");
|
||||
const distDir = join(rootDir, "dist");
|
||||
|
||||
const ASSET_EXTENSIONS = new Set([
|
||||
".css",
|
||||
".scss",
|
||||
".svg",
|
||||
".png",
|
||||
".jpg",
|
||||
".jpeg",
|
||||
".webp",
|
||||
".gif",
|
||||
".ico",
|
||||
".json",
|
||||
]);
|
||||
|
||||
const copyAssets = directory => {
|
||||
for (const entry of readdirSync(directory)) {
|
||||
const fullPath = join(directory, entry);
|
||||
const stats = statSync(fullPath);
|
||||
if (stats.isDirectory()) {
|
||||
copyAssets(fullPath);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!ASSET_EXTENSIONS.has(extname(fullPath))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const relativePath = relative(srcDir, fullPath);
|
||||
const destinationPath = join(distDir, relativePath);
|
||||
const destinationDir = dirname(destinationPath);
|
||||
if (!existsSync(destinationDir)) {
|
||||
mkdirSync(destinationDir, { recursive: true });
|
||||
}
|
||||
copyFileSync(fullPath, destinationPath);
|
||||
}
|
||||
};
|
||||
|
||||
rmSync(distDir, { recursive: true, force: true });
|
||||
|
||||
const tscPath = require.resolve("typescript/bin/tsc");
|
||||
const tscResult = spawnSync(
|
||||
process.execPath,
|
||||
[tscPath, "-p", "tsconfig.build.json"],
|
||||
{ stdio: "inherit", cwd: rootDir },
|
||||
);
|
||||
|
||||
if (tscResult.status !== 0) {
|
||||
process.exit(tscResult.status ?? 1);
|
||||
}
|
||||
|
||||
copyAssets(srcDir);
|
||||
Reference in New Issue
Block a user