Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/run.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env node
import { runCLI } from "../dist/index.js";
import { runCLI } from "../dist/cli/index.js";

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments about output changes below


// Disable Clack spinners and animations in non-interactive environments.
// Clack only checks the CI env var, so we set it when stdin/stdout aren't TTYs.
Expand Down
56 changes: 56 additions & 0 deletions infra/build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { watch } from "node:fs";
import chalk from "chalk";

const runBuild = async () => {
const result = await Bun.build({
entrypoints: ["./src/cli/index.ts"],
outdir: "./dist/cli",

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving pure cli code into dedicated folder in dist.
This way we can safely add another output in dist (like for additional entries) without concerning with files overriding each other.

target: "node",
format: "esm",
sourcemap: "inline",
});

if (!result.success) {
console.error(chalk.red.bold("\n✗ Build failed\n"));
for (const log of result.logs) {
console.error(chalk.red(` ${log}`));
}
process.exit(1);
}

return result;
};

const formatOutput = (outputs: { path: string }[]) => {
return outputs.map((o) => chalk.cyan(o.path)).join("\n ");
};

if (process.argv.includes("--watch")) {
console.log(chalk.yellow("Watching for changes..."));

const changeHandler = async (event: "rename" | "change", filename: string | null) => {
const time = new Date().toLocaleTimeString();
console.log(chalk.dim(`[${time}]`), chalk.gray(`${filename} ${event}d`));

const result = await runBuild();
console.log(
chalk.green(` ✓ Rebuilt`),
chalk.dim(`→`),
formatOutput(result.outputs)
);
};

await runBuild();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Watch mode should start with fully building the code, otherwise it will wait for the first change to happen.


for (const dir of ["./src"]) {
watch(dir, { recursive: true }, changeHandler);
}

// Keep process alive
await new Promise(() => {});
} else {
const result = await runBuild();
console.log(chalk.green.bold(`\n✓ Build complete\n`));
console.log(chalk.dim(" Output:"));
console.log(` ${formatOutput(result.outputs)}\n`);
}
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
"bin"
],
"scripts": {
"build": "rm -rf dist && bun build src/cli/index.ts --outdir dist --target node --format esm --sourcemap=inline && cp -r templates dist/",
"build": "bun run clean && cp -r templates dist/ && bun run infra/build.ts",
"build:watch": "bun run clean && cp -r templates dist/ && bun run infra/build.ts --watch",
"typecheck": "tsc --noEmit",
"dev": "./bin/dev.ts",
"start": "./bin/run.js",
"clean": "rm -rf dist",
"clean": "rm -rf dist && mkdir -p dist",

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

recreating dist folder, so I could copy templates folder before running bun build

"lint": "biome check src tests",
"lint:fix": "biome check --write src tests",
"test": "vitest run",
Expand Down
4 changes: 2 additions & 2 deletions src/core/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from "@/core/project/schema.js";

// After bundling, import.meta.url points to dist/cli/index.js
// Templates are copied to dist/cli/templates/
// Templates are copied to dist/templates/

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment was originally incorrect. templates were always in dist/templates/

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice one

const __dirname = dirname(fileURLToPath(import.meta.url));

export function getBase44GlobalDir(): string {
Expand All @@ -20,7 +20,7 @@ export function getAuthFilePath(): string {
}

export function getTemplatesDir(): string {
return join(__dirname, "templates");
return join(__dirname, "../templates");

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since cli code is now in dist/cli - this path should change

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we just need to make sure it's working fine in dev + in dist

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when you say dev, what do you mean?
aren't templates used only for creation of the new app?
I tested it for creation and it works fine.

}

export function getTemplatesIndexPath(): string {
Expand Down
2 changes: 1 addition & 1 deletion tests/cli/testkit/CLITestkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type { CLIResult } from "./CLIResultMatcher.js";
import { CLIResultMatcher } from "./CLIResultMatcher.js";

const __dirname = dirname(fileURLToPath(import.meta.url));
const DIST_INDEX_PATH = join(__dirname, "../../../dist/index.js");
const DIST_INDEX_PATH = join(__dirname, "../../../dist/cli/index.js");

/** Type for CLIContext */
interface CLIContext {
Expand Down
Loading