From 4673b8d785998e396af4fb4614602f6837515ef2 Mon Sep 17 00:00:00 2001 From: Donnie Flood Date: Sat, 4 Feb 2023 21:23:23 -0700 Subject: [PATCH] fix deno gen --- .changeset/twelve-cheetahs-watch.md | 9 +++++++++ packages/gen/dist/cli.mjs | 13 +++++++++---- packages/gen/dist/post_exec.d.mts | 2 +- packages/gen/dist/post_exec.mjs | 2 ++ packages/gen/dist/yargs.d.mts | 4 ++-- packages/gen/dist/yargs.mjs | 2 +- packages/gen/src/cli.mts | 17 +++++++++++------ packages/gen/src/post_exec.mts | 2 ++ packages/gen/src/yargs.mts | 4 ++-- 9 files changed, 39 insertions(+), 16 deletions(-) create mode 100644 .changeset/twelve-cheetahs-watch.md diff --git a/.changeset/twelve-cheetahs-watch.md b/.changeset/twelve-cheetahs-watch.md new file mode 100644 index 0000000..79c6f3e --- /dev/null +++ b/.changeset/twelve-cheetahs-watch.md @@ -0,0 +1,9 @@ +--- +"@liveviewjs/lambda-examples": patch +"liveviewjs": patch +"@liveviewjs/examples": patch +"@liveviewjs/express": patch +"@liveviewjs/gen": patch +--- + +Run npm install for deno client-side javascript diff --git a/packages/gen/dist/cli.mjs b/packages/gen/dist/cli.mjs index 07147ab..e6aaedd 100644 --- a/packages/gen/dist/cli.mjs +++ b/packages/gen/dist/cli.mjs @@ -10,7 +10,7 @@ import * as url from "url"; import { NullLogger } from "./null_logger.mjs"; import { changeDirMsg, installMsg, runMsg } from "./post_exec.mjs"; import { GeneratorTypePromptOptions, NamePromptOptions, NpmInstallPromptOptions } from "./prompts.mjs"; -import { genYargs, nodeYargs } from "./yargs.mjs"; +import { genYargs, projYargs } from "./yargs.mjs"; const { prompt } = enquirer; const __dirname = url.fileURLToPath(new URL(".", import.meta.url)); const templates = path.join(__dirname, "../_templates"); @@ -60,10 +60,15 @@ const run = async () => { process.env.HYGEN_OVERWRITE = "1"; } // depending on generator parse args - if (generator === "node-project") { - const yargs = nodeYargs(process.argv.slice(2)); + if (generator === "node-project" || generator === "deno-project") { + const yargs = projYargs(process.argv.slice(2)); if (yargs.install === undefined) { - yargs.install = (await prompt(NpmInstallPromptOptions)).install; + // change prompt message based on generator type + let message = NpmInstallPromptOptions.message; + if (generator === "deno-project") { + message += " (required for client-side javascript)"; + } + yargs.install = (await prompt({ ...NpmInstallPromptOptions, message })).install; } msgs.push(installMsg(generator, yargs.install)); if (yargs.install) { diff --git a/packages/gen/dist/post_exec.d.mts b/packages/gen/dist/post_exec.d.mts index 7a7bd37..4517ac3 100644 --- a/packages/gen/dist/post_exec.d.mts +++ b/packages/gen/dist/post_exec.d.mts @@ -1,4 +1,4 @@ import { GeneratorType } from "./prompts.mjs"; export declare function changeDirMsg(type: GeneratorType, name: string): string | undefined; -export declare function installMsg(type: GeneratorType, install: boolean): "Run `npm install` to install node dependencies." | undefined; +export declare function installMsg(type: GeneratorType, install: boolean): "Run `npm install` to install node dependencies." | "Run `npm install` to install node dependencies for client-side javascript." | undefined; export declare function runMsg(type: GeneratorType): "Run `npm run dev` to start your LiveViewJS project.\"" | "Run `deno run --allow-run --allow-read --allow-write --allow-net --allow-env src/server/autorun.ts` to start your LiveViewJS project.\"" | undefined; diff --git a/packages/gen/dist/post_exec.mjs b/packages/gen/dist/post_exec.mjs index 964db65..2c2665b 100644 --- a/packages/gen/dist/post_exec.mjs +++ b/packages/gen/dist/post_exec.mjs @@ -11,6 +11,8 @@ export function installMsg(type, install) { switch (type) { case "node-project": return install ? undefined : "Run `npm install` to install node dependencies."; + case "deno-project": + return install ? undefined : "Run `npm install` to install node dependencies for client-side javascript."; default: return undefined; } diff --git a/packages/gen/dist/yargs.d.mts b/packages/gen/dist/yargs.d.mts index e379be6..a0dbf07 100644 --- a/packages/gen/dist/yargs.d.mts +++ b/packages/gen/dist/yargs.d.mts @@ -5,7 +5,7 @@ export interface GenYargs { force?: boolean; } export declare const genYargs: (argv: string[]) => GenYargs; -export interface NodeProjectYargs { +export interface ProjectYargs { install?: boolean; } -export declare const nodeYargs: (argv: string[]) => NodeProjectYargs; +export declare const projYargs: (argv: string[]) => ProjectYargs; diff --git a/packages/gen/dist/yargs.mjs b/packages/gen/dist/yargs.mjs index 554dcc8..15300bc 100644 --- a/packages/gen/dist/yargs.mjs +++ b/packages/gen/dist/yargs.mjs @@ -25,7 +25,7 @@ export const genYargs = (argv) => { }) .parseSync(); }; -export const nodeYargs = (argv) => { +export const projYargs = (argv) => { return yargs(argv) .usage("Usage: $0 [generator] [args]") .options({ diff --git a/packages/gen/src/cli.mts b/packages/gen/src/cli.mts index e4702fe..d1bea82 100644 --- a/packages/gen/src/cli.mts +++ b/packages/gen/src/cli.mts @@ -11,7 +11,7 @@ import * as url from "url"; import { NullLogger } from "./null_logger.mjs"; import { changeDirMsg, installMsg, runMsg } from "./post_exec.mjs"; import { GeneratorType, GeneratorTypePromptOptions, NamePromptOptions, NpmInstallPromptOptions } from "./prompts.mjs"; -import { genYargs, nodeYargs } from "./yargs.mjs"; +import { genYargs, projYargs } from "./yargs.mjs"; const { prompt } = enquirer; const __dirname = url.fileURLToPath(new URL(".", import.meta.url)); @@ -50,9 +50,9 @@ const run = async () => { // check for common args const gyargs = genYargs(process.argv.slice(2)); - let generator = gyargs.generator; + let generator: GeneratorType | undefined = gyargs.generator as GeneratorType | undefined; if (!generator) { - generator = ((await prompt(GeneratorTypePromptOptions)) as { generator: string }).generator; + generator = ((await prompt(GeneratorTypePromptOptions)) as { generator: GeneratorType }).generator; } hygenArgs.push(generator, "new"); if (!gyargs.name) { @@ -66,10 +66,15 @@ const run = async () => { } // depending on generator parse args - if (generator === "node-project") { - const yargs = nodeYargs(process.argv.slice(2)); + if (generator === "node-project" || generator === "deno-project") { + const yargs = projYargs(process.argv.slice(2)); if (yargs.install === undefined) { - yargs.install = ((await prompt(NpmInstallPromptOptions)) as { install: boolean }).install; + // change prompt message based on generator type + let message = NpmInstallPromptOptions.message; + if (generator === "deno-project") { + message += " (required for client-side javascript)"; + } + yargs.install = ((await prompt({ ...NpmInstallPromptOptions, message })) as { install: boolean }).install; } msgs.push(installMsg(generator as GeneratorType, yargs.install)); if (yargs.install) { diff --git a/packages/gen/src/post_exec.mts b/packages/gen/src/post_exec.mts index def161f..124846c 100644 --- a/packages/gen/src/post_exec.mts +++ b/packages/gen/src/post_exec.mts @@ -14,6 +14,8 @@ export function installMsg(type: GeneratorType, install: boolean) { switch (type) { case "node-project": return install ? undefined : "Run `npm install` to install node dependencies."; + case "deno-project": + return install ? undefined : "Run `npm install` to install node dependencies for client-side javascript."; default: return undefined; } diff --git a/packages/gen/src/yargs.mts b/packages/gen/src/yargs.mts index a8479df..d45c45a 100644 --- a/packages/gen/src/yargs.mts +++ b/packages/gen/src/yargs.mts @@ -34,11 +34,11 @@ export const genYargs = (argv: string[]): GenYargs => { .parseSync(); }; -export interface NodeProjectYargs { +export interface ProjectYargs { install?: boolean; } -export const nodeYargs = (argv: string[]): NodeProjectYargs => { +export const projYargs = (argv: string[]): ProjectYargs => { return yargs(argv) .usage("Usage: $0 [generator] [args]") .options({