Update logs
This commit is contained in:
parent
9be3ceb642
commit
c2c63a1a99
@ -2,7 +2,7 @@
|
||||
"name": "@moduletrace/bunext",
|
||||
"module": "index.ts",
|
||||
"type": "module",
|
||||
"version": "1.0.1",
|
||||
"version": "1.0.2",
|
||||
"bin": {
|
||||
"bunext": "dist/index.js"
|
||||
},
|
||||
|
||||
@ -3,12 +3,14 @@ import grabConfig from "../../functions/grab-config";
|
||||
import init from "../../functions/init";
|
||||
import type { BunextConfig } from "../../types";
|
||||
import allPagesBundler from "../../functions/bundler/all-pages-bundler";
|
||||
import { log } from "../../utils/log";
|
||||
|
||||
export default function () {
|
||||
return new Command("build")
|
||||
.description("Build Project")
|
||||
.action(async () => {
|
||||
console.log(`Building Project ...`);
|
||||
log.banner();
|
||||
log.build("Building Project ...");
|
||||
|
||||
process.env.NODE_ENV = "production";
|
||||
|
||||
|
||||
@ -3,12 +3,14 @@ import grabConfig from "../../functions/grab-config";
|
||||
import startServer from "../../functions/server/start-server";
|
||||
import init from "../../functions/init";
|
||||
import type { BunextConfig } from "../../types";
|
||||
import { log } from "../../utils/log";
|
||||
|
||||
export default function () {
|
||||
return new Command("dev")
|
||||
.description("Run development server")
|
||||
.action(async () => {
|
||||
console.log(`Running development server ...`);
|
||||
log.banner();
|
||||
log.info("Running development server ...");
|
||||
|
||||
await init();
|
||||
|
||||
|
||||
@ -2,12 +2,14 @@ import { Command } from "commander";
|
||||
import grabConfig from "../../functions/grab-config";
|
||||
import startServer from "../../functions/server/start-server";
|
||||
import init from "../../functions/init";
|
||||
import { log } from "../../utils/log";
|
||||
|
||||
export default function () {
|
||||
return new Command("start")
|
||||
.description("Start production server")
|
||||
.action(async () => {
|
||||
console.log(`Starting production server ...`);
|
||||
log.banner();
|
||||
log.info("Starting production server ...");
|
||||
|
||||
await init();
|
||||
|
||||
|
||||
@ -11,6 +11,7 @@ import isDevelopment from "../../utils/is-development";
|
||||
import type { BundlerCTXMap } from "../../types";
|
||||
import { execSync } from "child_process";
|
||||
import grabConstants from "../../utils/grab-constants";
|
||||
import { log } from "../../utils/log";
|
||||
|
||||
const { HYDRATION_DST_DIR, PAGES_DIR, HYDRATION_DST_DIR_MAP_JSON_FILE } =
|
||||
grabDirNames();
|
||||
@ -94,8 +95,10 @@ export default async function allPagesBundler(params?: Params) {
|
||||
const artifactTracker: esbuild.Plugin = {
|
||||
name: "artifact-tracker",
|
||||
setup(build) {
|
||||
let buildStart = 0;
|
||||
|
||||
build.onStart(() => {
|
||||
console.time("build");
|
||||
buildStart = performance.now();
|
||||
});
|
||||
|
||||
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) {
|
||||
process.exit();
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import allPagesBundler from "../bundler/all-pages-bundler";
|
||||
import serverPostBuildFn from "./server-post-build-fn";
|
||||
import { log } from "../../utils/log";
|
||||
|
||||
export default async function rebuildBundler() {
|
||||
try {
|
||||
@ -13,6 +14,6 @@ export default async function rebuildBundler() {
|
||||
post_build_fn: serverPostBuildFn,
|
||||
});
|
||||
} catch (error: any) {
|
||||
console.error(error);
|
||||
log.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import _ from "lodash";
|
||||
import AppNames from "../../utils/grab-app-names";
|
||||
import { log } from "../../utils/log";
|
||||
import allPagesBundler from "../bundler/all-pages-bundler";
|
||||
import serverParamsGen from "./server-params-gen";
|
||||
import watcher from "./watcher";
|
||||
@ -32,7 +33,7 @@ export default async function startServer(params?: Params) {
|
||||
readFileSync(HYDRATION_DST_DIR_MAP_JSON_FILE, "utf-8"),
|
||||
) as BundlerCTXMap[] | undefined;
|
||||
if (!artifacts?.[0]) {
|
||||
console.error(`Please build first.`);
|
||||
log.error("Please build first.");
|
||||
process.exit(1);
|
||||
}
|
||||
global.BUNDLER_CTX_MAP = artifacts;
|
||||
@ -45,7 +46,7 @@ export default async function startServer(params?: Params) {
|
||||
|
||||
while (!global.IS_FIRST_BUNDLE_READY) {
|
||||
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);
|
||||
}
|
||||
bundle_ready_retries++;
|
||||
@ -56,9 +57,7 @@ export default async function startServer(params?: Params) {
|
||||
|
||||
global.SERVER = server;
|
||||
|
||||
console.log(
|
||||
`${name} Server Running on http://localhost:${server.port} ...`,
|
||||
);
|
||||
log.server(`http://localhost:${server.port}`);
|
||||
|
||||
return server;
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@ import { watch, existsSync } from "fs";
|
||||
import path from "path";
|
||||
import grabDirNames from "../../utils/grab-dir-names";
|
||||
import rebuildBundler from "./rebuild-bundler";
|
||||
import { log } from "../../utils/log";
|
||||
|
||||
const { SRC_DIR } = grabDirNames();
|
||||
|
||||
@ -25,11 +26,11 @@ export default function watcher() {
|
||||
try {
|
||||
global.RECOMPILING = true;
|
||||
|
||||
console.log(`Page ${action}: ${filename}. Rebuilding ...`);
|
||||
log.watch(`Page ${action}: ${filename}. Rebuilding ...`);
|
||||
|
||||
await rebuildBundler();
|
||||
} catch (error: any) {
|
||||
console.error(error);
|
||||
log.error(error);
|
||||
} finally {
|
||||
global.RECOMPILING = false;
|
||||
}
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
import { log } from "./log";
|
||||
|
||||
export default function exitWithError(msg: string, code?: number) {
|
||||
console.error(msg);
|
||||
log.error(msg);
|
||||
process.exit(code || 1);
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@ const AppNames = {
|
||||
defaultPort: 7000,
|
||||
defaultAssetPrefix: "_bunext/static",
|
||||
name: "Bunext",
|
||||
version: "1.0.1",
|
||||
defaultDistDir: ".bunext",
|
||||
RootPagesComponentName: "__root",
|
||||
} as const;
|
||||
|
||||
34
src/utils/log.ts
Normal file
34
src/utils/log.ts
Normal 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`,
|
||||
),
|
||||
};
|
||||
Loading…
Reference in New Issue
Block a user