Skip to content

Commit

Permalink
Regex parse, parse bad args, examples, bundles.
Browse files Browse the repository at this point in the history
  • Loading branch information
FS-Frost committed May 31, 2024
1 parent d3219eb commit d2dd23f
Show file tree
Hide file tree
Showing 28 changed files with 563 additions and 31,335 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,14 @@ jobs:
run: |
bun test
- name: Bundle
run: |
bun bundle && \
mv ./build ./examples/build
- name: Generate docs
run: |
bunx typedoc src/asu.ts --out ./examples/docs
bun docs
- name: Deploy
uses: JamesIves/github-pages-deploy-action@4.1.7
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore

/examples/build
/examples/bundles/files.json
/examples/docs
/temp

Expand Down
29 changes: 12 additions & 17 deletions build.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { BuildConfig, Target } from "bun";
import fs from "node:fs/promises";

const buildDir = "./examples/build";
{
console.log("Generating declaration file...");
const cmdAArgs: string[] = ["bun", "dts-bundle-generator", "src/asu.ts", "--out-file", "build/asu.d.ts", "--no-check"];
const cmdAArgs: string[] = ["bun", "dts-bundle-generator", "src/asu.ts", "--out-file", `${buildDir}/asu.d.ts`, "--no-check"];
console.log(cmdAArgs.join(" "));
const cmdResult = Bun.spawnSync(cmdAArgs);
if (!cmdResult.success) {
Expand All @@ -13,9 +14,7 @@ import fs from "node:fs/promises";
}
}

const dtsContent = await fs.readFile("./build/asu.d.ts");

const buildDir = "./build";
const dtsContent = await fs.readFile(`${buildDir}/asu.d.ts`);
if (await fs.exists(buildDir)) {
await fs.rm(buildDir, {
recursive: true,
Expand All @@ -25,7 +24,7 @@ if (await fs.exists(buildDir)) {

const config: BuildConfig = {
entrypoints: ["./src/asu.ts"],
outdir: "./build",
outdir: buildDir,
sourcemap: "external",
};

Expand All @@ -40,30 +39,26 @@ for (const target of targets) {
config.naming = {
entry: `asu.${target}.js`,
};

let fileName = `asu.${target}.d.ts`;
await Bun.build(config);
await fs.writeFile(`./build/asu.${target}.d.ts`, dtsContent);
await fs.writeFile(`${buildDir}/${fileName}`, dtsContent);

config.minify = true;
config.naming = {
entry: `asu.${target}.min.js`,
};

fileName = `asu.${target}.min.d.ts`;
await Bun.build(config);
await fs.writeFile(`./build/asu.${target}.min.d.ts`, dtsContent);
await fs.writeFile(`${buildDir}/${fileName}`, dtsContent);
}

console.log(`Out directory: ${buildDir}`);

{
console.log("Copying browser build to examples...");
const cmdArgs: string[] = ["cp", "build/asu.browser.js", "examples/asu.browser.js"];
console.log(cmdArgs.join(" "));
const cmdResult = Bun.spawnSync(cmdArgs);
if (!cmdResult.success) {
console.error(`ERROR: failed to copy browser build to examples with exit code ${cmdResult.exitCode}`);
console.error(cmdResult.stderr.toString());
process.exit(1);
}

const files = await fs.readdir(buildDir);
await fs.writeFile(`./examples/bundles/files.json`, JSON.stringify(files, null, 2));
}

console.log("DONE");
Loading

0 comments on commit d2dd23f

Please sign in to comment.