Update logs

This commit is contained in:
Benjamin Toby 2026-03-18 18:02:11 +01:00
parent 9be3ceb642
commit c2c63a1a99
11 changed files with 63 additions and 15 deletions

View File

@ -2,7 +2,7 @@
"name": "@moduletrace/bunext", "name": "@moduletrace/bunext",
"module": "index.ts", "module": "index.ts",
"type": "module", "type": "module",
"version": "1.0.1", "version": "1.0.2",
"bin": { "bin": {
"bunext": "dist/index.js" "bunext": "dist/index.js"
}, },

View File

@ -3,12 +3,14 @@ import grabConfig from "../../functions/grab-config";
import init from "../../functions/init"; import init from "../../functions/init";
import type { BunextConfig } from "../../types"; import type { BunextConfig } from "../../types";
import allPagesBundler from "../../functions/bundler/all-pages-bundler"; import allPagesBundler from "../../functions/bundler/all-pages-bundler";
import { log } from "../../utils/log";
export default function () { export default function () {
return new Command("build") return new Command("build")
.description("Build Project") .description("Build Project")
.action(async () => { .action(async () => {
console.log(`Building Project ...`); log.banner();
log.build("Building Project ...");
process.env.NODE_ENV = "production"; process.env.NODE_ENV = "production";

View File

@ -3,12 +3,14 @@ import grabConfig from "../../functions/grab-config";
import startServer from "../../functions/server/start-server"; import startServer from "../../functions/server/start-server";
import init from "../../functions/init"; import init from "../../functions/init";
import type { BunextConfig } from "../../types"; import type { BunextConfig } from "../../types";
import { log } from "../../utils/log";
export default function () { export default function () {
return new Command("dev") return new Command("dev")
.description("Run development server") .description("Run development server")
.action(async () => { .action(async () => {
console.log(`Running development server ...`); log.banner();
log.info("Running development server ...");
await init(); await init();

View File

@ -2,12 +2,14 @@ import { Command } from "commander";
import grabConfig from "../../functions/grab-config"; import grabConfig from "../../functions/grab-config";
import startServer from "../../functions/server/start-server"; import startServer from "../../functions/server/start-server";
import init from "../../functions/init"; import init from "../../functions/init";
import { log } from "../../utils/log";
export default function () { export default function () {
return new Command("start") return new Command("start")
.description("Start production server") .description("Start production server")
.action(async () => { .action(async () => {
console.log(`Starting production server ...`); log.banner();
log.info("Starting production server ...");
await init(); await init();

View File

@ -11,6 +11,7 @@ import isDevelopment from "../../utils/is-development";
import type { BundlerCTXMap } from "../../types"; import type { BundlerCTXMap } from "../../types";
import { execSync } from "child_process"; import { execSync } from "child_process";
import grabConstants from "../../utils/grab-constants"; import grabConstants from "../../utils/grab-constants";
import { log } from "../../utils/log";
const { HYDRATION_DST_DIR, PAGES_DIR, HYDRATION_DST_DIR_MAP_JSON_FILE } = const { HYDRATION_DST_DIR, PAGES_DIR, HYDRATION_DST_DIR_MAP_JSON_FILE } =
grabDirNames(); grabDirNames();
@ -94,8 +95,10 @@ export default async function allPagesBundler(params?: Params) {
const artifactTracker: esbuild.Plugin = { const artifactTracker: esbuild.Plugin = {
name: "artifact-tracker", name: "artifact-tracker",
setup(build) { setup(build) {
let buildStart = 0;
build.onStart(() => { build.onStart(() => {
console.time("build"); buildStart = performance.now();
}); });
build.onEnd((result) => { build.onEnd((result) => {
@ -150,7 +153,8 @@ export default async function allPagesBundler(params?: Params) {
); );
} }
console.timeEnd("build"); const elapsed = (performance.now() - buildStart).toFixed(0);
log.success(`Built in ${elapsed}ms`);
if (params?.exit_after_first_build) { if (params?.exit_after_first_build) {
process.exit(); process.exit();

View File

@ -1,5 +1,6 @@
import allPagesBundler from "../bundler/all-pages-bundler"; import allPagesBundler from "../bundler/all-pages-bundler";
import serverPostBuildFn from "./server-post-build-fn"; import serverPostBuildFn from "./server-post-build-fn";
import { log } from "../../utils/log";
export default async function rebuildBundler() { export default async function rebuildBundler() {
try { try {
@ -13,6 +14,6 @@ export default async function rebuildBundler() {
post_build_fn: serverPostBuildFn, post_build_fn: serverPostBuildFn,
}); });
} catch (error: any) { } catch (error: any) {
console.error(error); log.error(error);
} }
} }

View File

@ -1,5 +1,6 @@
import _ from "lodash"; import _ from "lodash";
import AppNames from "../../utils/grab-app-names"; import AppNames from "../../utils/grab-app-names";
import { log } from "../../utils/log";
import allPagesBundler from "../bundler/all-pages-bundler"; import allPagesBundler from "../bundler/all-pages-bundler";
import serverParamsGen from "./server-params-gen"; import serverParamsGen from "./server-params-gen";
import watcher from "./watcher"; import watcher from "./watcher";
@ -32,7 +33,7 @@ export default async function startServer(params?: Params) {
readFileSync(HYDRATION_DST_DIR_MAP_JSON_FILE, "utf-8"), readFileSync(HYDRATION_DST_DIR_MAP_JSON_FILE, "utf-8"),
) as BundlerCTXMap[] | undefined; ) as BundlerCTXMap[] | undefined;
if (!artifacts?.[0]) { if (!artifacts?.[0]) {
console.error(`Please build first.`); log.error("Please build first.");
process.exit(1); process.exit(1);
} }
global.BUNDLER_CTX_MAP = artifacts; global.BUNDLER_CTX_MAP = artifacts;
@ -45,7 +46,7 @@ export default async function startServer(params?: Params) {
while (!global.IS_FIRST_BUNDLE_READY) { while (!global.IS_FIRST_BUNDLE_READY) {
if (bundle_ready_retries > MAX_BUNDLE_READY_RETRIES) { if (bundle_ready_retries > MAX_BUNDLE_READY_RETRIES) {
console.error(`Couldn't grab first bundle for dev environment`); log.error("Couldn't grab first bundle for dev environment");
process.exit(1); process.exit(1);
} }
bundle_ready_retries++; bundle_ready_retries++;
@ -56,9 +57,7 @@ export default async function startServer(params?: Params) {
global.SERVER = server; global.SERVER = server;
console.log( log.server(`http://localhost:${server.port}`);
`${name} Server Running on http://localhost:${server.port} ...`,
);
return server; return server;
} }

View File

@ -2,6 +2,7 @@ import { watch, existsSync } from "fs";
import path from "path"; import path from "path";
import grabDirNames from "../../utils/grab-dir-names"; import grabDirNames from "../../utils/grab-dir-names";
import rebuildBundler from "./rebuild-bundler"; import rebuildBundler from "./rebuild-bundler";
import { log } from "../../utils/log";
const { SRC_DIR } = grabDirNames(); const { SRC_DIR } = grabDirNames();
@ -25,11 +26,11 @@ export default function watcher() {
try { try {
global.RECOMPILING = true; global.RECOMPILING = true;
console.log(`Page ${action}: ${filename}. Rebuilding ...`); log.watch(`Page ${action}: ${filename}. Rebuilding ...`);
await rebuildBundler(); await rebuildBundler();
} catch (error: any) { } catch (error: any) {
console.error(error); log.error(error);
} finally { } finally {
global.RECOMPILING = false; global.RECOMPILING = false;
} }

View File

@ -1,4 +1,6 @@
import { log } from "./log";
export default function exitWithError(msg: string, code?: number) { export default function exitWithError(msg: string, code?: number) {
console.error(msg); log.error(msg);
process.exit(code || 1); process.exit(code || 1);
} }

View File

@ -2,6 +2,7 @@ const AppNames = {
defaultPort: 7000, defaultPort: 7000,
defaultAssetPrefix: "_bunext/static", defaultAssetPrefix: "_bunext/static",
name: "Bunext", name: "Bunext",
version: "1.0.1",
defaultDistDir: ".bunext", defaultDistDir: ".bunext",
RootPagesComponentName: "__root", RootPagesComponentName: "__root",
} as const; } as const;

34
src/utils/log.ts Normal file
View File

@ -0,0 +1,34 @@
import chalk from "chalk";
import AppNames from "./grab-app-names";
const prefix = {
info: chalk.cyan.bold(""),
success: chalk.green.bold("✓"),
error: chalk.red.bold("✗"),
warn: chalk.yellow.bold("⚠"),
build: chalk.magenta.bold("⚙"),
watch: chalk.blue.bold("◉"),
};
export const log = {
info: (msg: string) =>
console.log(`${prefix.info} ${chalk.white(msg)}`),
success: (msg: string) =>
console.log(`${prefix.success} ${chalk.green(msg)}`),
error: (msg: string | Error) =>
console.error(`${prefix.error} ${chalk.red(String(msg))}`),
warn: (msg: string) =>
console.warn(`${prefix.warn} ${chalk.yellow(msg)}`),
build: (msg: string) =>
console.log(`${prefix.build} ${chalk.magenta(msg)}`),
watch: (msg: string) =>
console.log(`${prefix.watch} ${chalk.blue(msg)}`),
server: (url: string) =>
console.log(
`${prefix.success} ${chalk.white("Server running on")} ${chalk.cyan.underline(url)}`,
),
banner: () =>
console.log(
`\n ${chalk.cyan.bold(AppNames.name)} ${chalk.gray(`v${AppNames.version}`)}\n`,
),
};