From cbd8d4c0f1f96eab2fe09fae8b11d4ff962f388e Mon Sep 17 00:00:00 2001 From: Nikhil Saraf <nsaraf98@gmail.com> Date: Sat, 4 Nov 2023 19:36:25 +0530 Subject: [PATCH] docs(changeset): added boxes for build logging to make it prettier --- .changeset/neat-hotels-drive.md | 5 ++ packages/vinxi/bin/cli.mjs | 2 - packages/vinxi/lib/app.js | 6 +- packages/vinxi/lib/build.js | 24 +++++- packages/vinxi/lib/load-app.js | 10 +-- packages/vinxi/package.json | 67 +++++++++++++---- pnpm-lock.yaml | 126 +++++++++++++++----------------- 7 files changed, 146 insertions(+), 94 deletions(-) create mode 100644 .changeset/neat-hotels-drive.md diff --git a/.changeset/neat-hotels-drive.md b/.changeset/neat-hotels-drive.md new file mode 100644 index 00000000..3481aa5b --- /dev/null +++ b/.changeset/neat-hotels-drive.md @@ -0,0 +1,5 @@ +--- +"vinxi": patch +--- + +added boxes for build logging to make it prettier diff --git a/packages/vinxi/bin/cli.mjs b/packages/vinxi/bin/cli.mjs index 8ec62faf..057862ad 100755 --- a/packages/vinxi/bin/cli.mjs +++ b/packages/vinxi/bin/cli.mjs @@ -13,8 +13,6 @@ async function main() { const command = args._[0]; const rootDir = resolve(args._[1] || "."); - console.log(args); - const configFile = args.config; globalThis.MANIFEST = {}; const app = await loadApp(configFile, args); diff --git a/packages/vinxi/lib/app.js b/packages/vinxi/lib/app.js index c17f2e0c..a3c48390 100644 --- a/packages/vinxi/lib/app.js +++ b/packages/vinxi/lib/app.js @@ -47,7 +47,11 @@ export function createApp({ const output = result.args[0].router ? [c.yellow(result.args[0].router?.name), result.name] : [result.name]; - consola.log(c.blue("vinxi"), c.green("hook"), ...output); + consola.log( + c.dim(c.blue("vinxi")), + c.dim(c.green("hook")), + ...output.map(c.dim), + ); }); // if (devtools) { // routers = [devtoolsClient(), devtoolsRpc(), ...routers]; diff --git a/packages/vinxi/lib/build.js b/packages/vinxi/lib/build.js index 5714170a..13afa32e 100644 --- a/packages/vinxi/lib/build.js +++ b/packages/vinxi/lib/build.js @@ -1,3 +1,4 @@ +import boxen from "boxen"; import { mkdir, rm, writeFile } from "fs/promises"; import { H3Event, createApp } from "h3"; import { createRequire } from "module"; @@ -9,7 +10,7 @@ import { pathToFileURL } from "node:url"; import { chunksServerVirtualModule } from "./chunks.js"; import { createIncomingMessage, createServerResponse } from "./http-stream.js"; import invariant from "./invariant.js"; -import { consola, withLogger } from "./logger.js"; +import { c, consola, log, withLogger } from "./logger.js"; import { createSPAManifest } from "./manifest/spa-manifest.js"; import { handlerModule, @@ -34,6 +35,12 @@ const require = createRequire(import.meta.url); * @param {BuildConfig} buildConfig */ export async function createBuild(app, buildConfig) { + console.log("\n"); + console.log( + boxen(`⚙ ${c.green("Building your app...")}`, { + padding: { left: 1, right: 4 }, + }), + ); await app.hooks.callHook("app:build:start", { app, buildConfig }); const { existsSync, promises: fsPromises, readFileSync } = await import("fs"); const { join } = await import("./path.js"); @@ -266,6 +273,13 @@ export async function createBuild(app, buildConfig) { }, }); + console.log("\n"); + console.log( + boxen(`⚙ ${c.green(`Preparing app for ${nitro.options.preset}...`)}`, { + padding: { left: 1, right: 4 }, + }), + ); + nitro.options.appConfigFiles = []; nitro.logger = consola.withTag(app.config.name); @@ -308,6 +322,12 @@ async function createViteBuild(config) { * @param {import("./router-mode.js").Router} router */ async function createRouterBuild(app, router) { + console.log("\n"); + console.log( + boxen(c.green(`📦 Compiling ${router.name} router...`), { + padding: { left: 1, right: 4 }, + }), + ); await app.hooks.callHook("app:build:router:start", { app, router }); let buildRouter = router; if (router.mode === "spa" && !router.handler.endsWith(".html")) { @@ -375,7 +395,7 @@ async function createRouterBuild(app, router) { }; } - console.log(`building router ${router.name} in ${router.mode} mode`); + log(`building router ${router.name} in ${router.mode} mode`); const viteBuildConfig = { router: buildRouter, diff --git a/packages/vinxi/lib/load-app.js b/packages/vinxi/lib/load-app.js index 1c3a16b5..366d6854 100644 --- a/packages/vinxi/lib/load-app.js +++ b/packages/vinxi/lib/load-app.js @@ -1,8 +1,8 @@ import { loadConfig } from "c12"; -import chokidar from "chokidar"; import { fileURLToPath } from "url"; import { createApp } from "./app.js"; +import { log } from "./logger.js"; /** * @@ -11,7 +11,6 @@ import { createApp } from "./app.js"; */ export async function loadApp(configFile = undefined, args = {}) { const stacks = typeof args.s === "string" ? [args.s] : args.s ?? []; - console.log(stacks); /** @type {{ config: import("./app.js").App }}*/ try { let { config: app } = await loadConfig( @@ -42,14 +41,15 @@ export async function loadApp(configFile = undefined, args = {}) { }); if (config.config) { - console.warn("Found vite.config.js with app config"); + log("Found vite.config.js with app config"); // @ts-expect-error trying to send c12's config as app // return config; } else { - console.warn("No app config found. Assuming SPA app."); + log("No app config found. Assuming SPA app."); if (stacks.length) { + log("Applying stacks:", ...stacks); return applyStacks(createApp({}), stacks); } @@ -98,8 +98,6 @@ async function applyStacks(app, s) { }), ); - console.log(stacks); - for (const stack of stacks) { await app.stack(stack); } diff --git a/packages/vinxi/package.json b/packages/vinxi/package.json index 9f20e1fe..6bdb52e0 100644 --- a/packages/vinxi/package.json +++ b/packages/vinxi/package.json @@ -3,7 +3,15 @@ "version": "0.0.43", "type": "module", "author": "Nikhil Saraf <nsaraf98@gmail.com>", - "files": ["bin", "lib", "public", "runtime", "types", "dist/types", "*.d.ts"], + "files": [ + "bin", + "lib", + "public", + "runtime", + "types", + "dist/types", + "*.d.ts" + ], "scripts": { "types": "npm run tsc", "tsc": "rm -rf dist/types && tsc; cp -r types dist/types/types" @@ -78,20 +86,48 @@ }, "typesVersions": { "*": { - ".": ["./dist/types/lib/index.d.ts"], - "dev-server": ["./dist/types/lib/dev-server.d.ts"], - "server": ["./dist/types/runtime/server.d.ts"], - "party": ["./dist/types/runtime/party.d.ts"], - "css": ["./dist/types/runtime/style.d.ts"], - "client": ["./dist/types/runtime/client.d.ts"], - "fs-router": ["./dist/types/lib/fs-router.d.ts"], - "types/server": ["./types/server.d.ts"], - "types/client": ["./types/client.d.ts"], - "routes": ["./types/routes.d.ts"], - "lib/invariant": ["./dist/types/lib/invariant.d.ts"], - "plugins/config": ["./dist/types/lib/plugins/config.d.ts"], - "plugins/virtual": ["./dist/types/lib/plugins/virtual.d.ts"], - "lib/path": ["./dist/types/lib/path.d.ts"] + ".": [ + "./dist/types/lib/index.d.ts" + ], + "dev-server": [ + "./dist/types/lib/dev-server.d.ts" + ], + "server": [ + "./dist/types/runtime/server.d.ts" + ], + "party": [ + "./dist/types/runtime/party.d.ts" + ], + "css": [ + "./dist/types/runtime/style.d.ts" + ], + "client": [ + "./dist/types/runtime/client.d.ts" + ], + "fs-router": [ + "./dist/types/lib/fs-router.d.ts" + ], + "types/server": [ + "./types/server.d.ts" + ], + "types/client": [ + "./types/client.d.ts" + ], + "routes": [ + "./types/routes.d.ts" + ], + "lib/invariant": [ + "./dist/types/lib/invariant.d.ts" + ], + "plugins/config": [ + "./dist/types/lib/plugins/config.d.ts" + ], + "plugins/virtual": [ + "./dist/types/lib/plugins/virtual.d.ts" + ], + "lib/path": [ + "./dist/types/lib/path.d.ts" + ] } }, "dependencies": { @@ -103,6 +139,7 @@ "@types/ws": "^8.5.5", "@vinxi/devtools": "workspace:^", "@vinxi/listhen": "^1.5.5", + "boxen": "^7.1.1", "c12": "^1.4.2", "chokidar": "^3.5.3", "consola": "^3.2.3", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 5e916817..e8d8e0d3 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -152,15 +152,15 @@ importers: '@picocss/pico': specifier: ^1.5.10 version: 1.5.10 - '@vinxi/server-components': - specifier: 0.0.35 - version: link:../../../../packages/vinxi-server-components '@vinxi/react': specifier: 0.0.11 version: link:../../../../packages/vinxi-react '@vinxi/react-server-dom': specifier: 0.0.3 version: 0.0.3(react-dom@0.0.0-experimental-035a41c4e-20230704)(react@0.0.0-experimental-035a41c4e-20230704)(vite@4.5.0) + '@vinxi/server-components': + specifier: 0.0.35 + version: link:../../../../packages/vinxi-server-components '@vinxi/server-functions': specifier: 0.0.35 version: link:../../../../packages/vinxi-server-functions @@ -762,7 +762,7 @@ importers: specifier: ^1.5.10 version: 1.5.10 '@vinxi/server-functions': - specifier: workspace:^ + specifier: 0.0.35 version: link:../../../packages/vinxi-server-functions autoprefixer: specifier: ^10.4.15 @@ -873,6 +873,9 @@ importers: '@vinxi/listhen': specifier: ^1.5.5 version: 1.5.5 + boxen: + specifier: ^7.1.1 + version: 7.1.1 c12: specifier: ^1.4.2 version: 1.5.1 @@ -950,7 +953,7 @@ importers: version: 1.7.4 unimport: specifier: ^3.2.0 - version: 3.4.0(rollup@3.29.4) + version: 3.4.0(rollup@4.2.0) unstorage: specifier: ^1.9.0 version: 1.9.0 @@ -978,7 +981,7 @@ importers: version: 0.2.14 vite-plugin-inspect: specifier: ^0.7.38 - version: 0.7.41(vite@4.5.0) + version: 0.7.41(rollup@4.2.0)(vite@4.5.0) ws: specifier: ^8.13.0 version: 8.14.2 @@ -1376,15 +1379,15 @@ importers: '@picocss/pico': specifier: ^1.5.10 version: 1.5.10 - '@vinxi/server-components': - specifier: 0.0.35 - version: link:../../../packages/vinxi-server-components '@vinxi/react': specifier: 0.0.11 version: link:../../../packages/vinxi-react '@vinxi/react-server-dom': specifier: 0.0.3 version: 0.0.3(react-dom@0.0.0-experimental-035a41c4e-20230704)(react@0.0.0-experimental-035a41c4e-20230704)(vite@4.5.0) + '@vinxi/server-components': + specifier: 0.0.35 + version: link:../../../packages/vinxi-server-components '@vinxi/server-functions': specifier: 0.0.35 version: link:../../../packages/vinxi-server-functions @@ -4833,6 +4836,7 @@ packages: estree-walker: 2.0.2 picomatch: 2.3.1 rollup: 3.29.4 + dev: false /@rollup/pluginutils@5.0.5(rollup@4.2.0): resolution: {integrity: sha512-6aEYR910NyP73oHiJglti74iRyOwgFU4x3meH/H8OJx6Ry0j6cOVZ5X/wTvub7G7Ao6qaHBEaNsV3GLJkSsF+Q==} @@ -4847,14 +4851,12 @@ packages: estree-walker: 2.0.2 picomatch: 2.3.1 rollup: 4.2.0 - dev: false /@rollup/rollup-android-arm-eabi@4.2.0: resolution: {integrity: sha512-8PlggAxGxavr+pkCNeV1TM2wTb2o+cUWDg9M1cm9nR27Dsn287uZtSLYXoQqQcmq+sYfF7lHfd3sWJJinH9GmA==} cpu: [arm] os: [android] requiresBuild: true - dev: false optional: true /@rollup/rollup-android-arm64@4.2.0: @@ -4862,7 +4864,6 @@ packages: cpu: [arm64] os: [android] requiresBuild: true - dev: false optional: true /@rollup/rollup-darwin-arm64@4.2.0: @@ -4870,7 +4871,6 @@ packages: cpu: [arm64] os: [darwin] requiresBuild: true - dev: false optional: true /@rollup/rollup-darwin-x64@4.2.0: @@ -4878,7 +4878,6 @@ packages: cpu: [x64] os: [darwin] requiresBuild: true - dev: false optional: true /@rollup/rollup-linux-arm-gnueabihf@4.2.0: @@ -4886,7 +4885,6 @@ packages: cpu: [arm] os: [linux] requiresBuild: true - dev: false optional: true /@rollup/rollup-linux-arm64-gnu@4.2.0: @@ -4894,7 +4892,6 @@ packages: cpu: [arm64] os: [linux] requiresBuild: true - dev: false optional: true /@rollup/rollup-linux-arm64-musl@4.2.0: @@ -4902,7 +4899,6 @@ packages: cpu: [arm64] os: [linux] requiresBuild: true - dev: false optional: true /@rollup/rollup-linux-x64-gnu@4.2.0: @@ -4910,7 +4906,6 @@ packages: cpu: [x64] os: [linux] requiresBuild: true - dev: false optional: true /@rollup/rollup-linux-x64-musl@4.2.0: @@ -4918,7 +4913,6 @@ packages: cpu: [x64] os: [linux] requiresBuild: true - dev: false optional: true /@rollup/rollup-win32-arm64-msvc@4.2.0: @@ -4926,7 +4920,6 @@ packages: cpu: [arm64] os: [win32] requiresBuild: true - dev: false optional: true /@rollup/rollup-win32-ia32-msvc@4.2.0: @@ -4934,7 +4927,6 @@ packages: cpu: [ia32] os: [win32] requiresBuild: true - dev: false optional: true /@rollup/rollup-win32-x64-msvc@4.2.0: @@ -4942,7 +4934,6 @@ packages: cpu: [x64] os: [win32] requiresBuild: true - dev: false optional: true /@sideway/address@4.1.4: @@ -5518,7 +5509,7 @@ packages: hasBin: true dependencies: '@ampproject/remapping': 2.2.1 - '@rollup/pluginutils': 5.0.5(rollup@3.29.4) + '@rollup/pluginutils': 5.0.5(rollup@4.2.0) '@unocss/config': 0.56.5 '@unocss/core': 0.56.5 '@unocss/preset-uno': 0.56.5 @@ -5693,7 +5684,7 @@ packages: vite: ^2.9.0 || ^3.0.0-0 || ^4.0.0 dependencies: '@ampproject/remapping': 2.2.1 - '@rollup/pluginutils': 5.0.5(rollup@3.29.4) + '@rollup/pluginutils': 5.0.5(rollup@4.2.0) '@unocss/config': 0.56.5 '@unocss/core': 0.56.5 '@unocss/inspector': 0.56.5 @@ -5959,6 +5950,12 @@ packages: '@algolia/transporter': 4.20.0 dev: false + /ansi-align@3.0.1: + resolution: {integrity: sha512-IOfwwBF5iczOjp/WeY4YxyjqAFMQoZufdQWDd19SEExbVLNXqvpzSJ/M7Za4/sCPmQ0+GRquoA7bGcINcxew6w==} + dependencies: + string-width: 4.2.3 + dev: false + /ansi-colors@4.1.3: resolution: {integrity: sha512-/6w/C21Pm1A7aZitlI5Ni/2J6FFQN8i1Cvz3kHABAAbw93v/NlvKdVOqz7CCWz/3iv/JplRSEEZ83XION15ovw==} engines: {node: '>=6'} @@ -6248,6 +6245,20 @@ packages: resolution: {integrity: sha512-JZOSA7Mo9sNGB8+UjSgzdLtokWAky1zbztM3WRLCbZ70/3cTANmQmOdR7y2g+J0e2WXywy1yS468tY+IruqEww==} dev: false + /boxen@7.1.1: + resolution: {integrity: sha512-2hCgjEmP8YLWQ130n2FerGv7rYpfBmnmp9Uy2Le1vge6X3gZIfSmEzP5QTDElFxcvVcXlEn8Aq6MU/PZygIOog==} + engines: {node: '>=14.16'} + dependencies: + ansi-align: 3.0.1 + camelcase: 7.0.1 + chalk: 5.3.0 + cli-boxes: 3.0.0 + string-width: 5.1.2 + type-fest: 2.19.0 + widest-line: 4.0.1 + wrap-ansi: 8.1.0 + dev: false + /bplist-parser@0.2.0: resolution: {integrity: sha512-z0M+byMThzQmD9NILRniCUXYsYpjwnlO8N5uCFaCqIOpqRsJCrQL9NK3JsD67CN5a08nF5oIL2bD6loTdHOuKw==} engines: {node: '>= 5.10.0'} @@ -6373,6 +6384,11 @@ packages: engines: {node: '>=6'} dev: false + /camelcase@7.0.1: + resolution: {integrity: sha512-xlx1yCK2Oc1APsPXDL2LdlNP6+uu8OCDdhOBSVT279M/S+y75O30C2VuD8T2ogdePBBl7PfPF4504tnLgX3zfw==} + engines: {node: '>=14.16'} + dev: false + /caniuse-lite@1.0.30001559: resolution: {integrity: sha512-cPiMKZgqgkg5LY3/ntGeLFUpi6tzddBNS58A4tnTgQw1zON7u2sZMU7SzOeVH4tj20++9ggL+V6FDOFMTaFFYA==} @@ -6505,6 +6521,11 @@ packages: resolution: {integrity: sha512-CSbhY4cFEJRe6/GQzIk5qXZ4Jeg5pcsP7b5peFSDpffpe1cqjASH/n9UTjBwOp6XpMSTwQ8Za2K5V02ueA7Tmw==} dev: true + /cli-boxes@3.0.0: + resolution: {integrity: sha512-/lzGpEWL/8PfI0BmBOPRwp0c/wFNX1RdUML3jK/RcSBA9T8mZDdQpqYBKtCFTOfQbwPqWEOpjqW+Fnayc0969g==} + engines: {node: '>=10'} + dev: false + /cli-truncate@3.1.0: resolution: {integrity: sha512-wfOBkjXteqSnI59oPcJkcPl/ZmwvMMOj340qUIY1SKZCv0B9Cf4D4fAucRkIKQmsIuYK3x1rrgU7MeGRruiuiA==} engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} @@ -10265,7 +10286,6 @@ packages: '@rollup/rollup-win32-ia32-msvc': 4.2.0 '@rollup/rollup-win32-x64-msvc': 4.2.0 fsevents: 2.3.3 - dev: false /run-applescript@5.0.0: resolution: {integrity: sha512-XcT5rBksx1QdIhlFOCtgZkB99ZEouFZ1E2Kc2LHqNW13U3/74YGdkQRmThTwxy4QIyookibDKYZOPqX//6BlAg==} @@ -11033,6 +11053,11 @@ packages: engines: {node: '>=8'} dev: false + /type-fest@2.19.0: + resolution: {integrity: sha512-RAH822pAdBgcNMAfWnCBU3CFZcfZ/i1eZjwFU/dsLKumyuuP3niueg2UAukXYF0E2AAoc82ZSSf9J0WQBinzHA==} + engines: {node: '>=12.20'} + dev: false + /type-fest@3.13.1: resolution: {integrity: sha512-tLq3bSNx+xSpwvAJnzrK0Ep5CLNWjvFTOp71URMaAEWBfRb9nnJiBoUe0tF8bI4ZFO3omgBR6NvnbzVUT3Ly4g==} engines: {node: '>=14.16'} @@ -11177,24 +11202,6 @@ packages: vfile: 4.2.1 dev: false - /unimport@3.4.0: - resolution: {integrity: sha512-M/lfFEgufIT156QAr/jWHLUn55kEmxBBiQsMxvRSIbquwmeJEyQYgshHDEvQDWlSJrVOOTAgnJ3FvlsrpGkanA==} - dependencies: - '@rollup/pluginutils': 5.0.5(rollup@3.29.4) - escape-string-regexp: 5.0.0 - fast-glob: 3.3.1 - local-pkg: 0.4.3 - magic-string: 0.30.5 - mlly: 1.4.2 - pathe: 1.1.1 - pkg-types: 1.0.3 - scule: 1.0.0 - strip-literal: 1.3.0 - unplugin: 1.5.0 - transitivePeerDependencies: - - rollup - dev: false - /unimport@3.4.0(rollup@3.29.4): resolution: {integrity: sha512-M/lfFEgufIT156QAr/jWHLUn55kEmxBBiQsMxvRSIbquwmeJEyQYgshHDEvQDWlSJrVOOTAgnJ3FvlsrpGkanA==} dependencies: @@ -11607,7 +11614,7 @@ packages: serve-static: 1.15.0 ufo: 1.3.1 unenv: 1.7.4 - unimport: 3.4.0 + unimport: 3.4.0(rollup@4.2.0) unstorage: 1.9.0 vite: 4.3.9(@types/node@18.18.8) zod: 3.22.4 @@ -11747,30 +11754,6 @@ packages: - supports-color dev: false - /vite-plugin-inspect@0.7.41(vite@4.5.0): - resolution: {integrity: sha512-gASdFRO4CHDQF8qAk9LZEJyzlIJM4bFvDn7hz0e2r1PS6uq+yukd8+jHctOAbvCceQoTS5iDAgd4/mWcGWYoMw==} - engines: {node: '>=14'} - peerDependencies: - '@nuxt/kit': '*' - vite: ^3.1.0 || ^4.0.0 || ^5.0.0-0 - peerDependenciesMeta: - '@nuxt/kit': - optional: true - dependencies: - '@antfu/utils': 0.7.6 - '@rollup/pluginutils': 5.0.5(rollup@3.29.4) - debug: 4.3.4 - error-stack-parser-es: 0.1.1 - fs-extra: 11.1.1 - open: 9.1.0 - picocolors: 1.0.0 - sirv: 2.0.3 - vite: 4.5.0(@types/node@14.18.63) - transitivePeerDependencies: - - rollup - - supports-color - dev: false - /vite-plugin-solid@2.7.2(solid-js@1.8.5)(vite@4.5.0): resolution: {integrity: sha512-GV2SMLAibOoXe76i02AsjAg7sbm/0lngBlERvJKVN67HOrJsHcWgkt0R6sfGLDJuFkv2aBe14Zm4vJcNME+7zw==} peerDependencies: @@ -12094,6 +12077,13 @@ packages: string-width: 4.2.3 dev: false + /widest-line@4.0.1: + resolution: {integrity: sha512-o0cyEG0e8GPzT4iGHphIOh0cJOV8fivsXxddQasHPHfoZf1ZexrfeA21w2NaEN1RHE+fXlfISmOE8R9N3u3Qig==} + engines: {node: '>=12'} + dependencies: + string-width: 5.1.2 + dev: false + /wouter@2.12.1(react@0.0.0-experimental-035a41c4e-20230704): resolution: {integrity: sha512-G7a6JMSLSNcu6o8gdOfIzqxuo8Qx1qs+9rpVnlurH69angsSFPZP5gESNuVNeJct/MGpQg191pDo4HUjTx7IIQ==} peerDependencies: