Skip to content

Commit

Permalink
fix deno gen
Browse files Browse the repository at this point in the history
  • Loading branch information
floodfx committed Feb 5, 2023
1 parent 617b3f0 commit 4673b8d
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 16 deletions.
9 changes: 9 additions & 0 deletions .changeset/twelve-cheetahs-watch.md
Original file line number Diff line number Diff line change
@@ -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
13 changes: 9 additions & 4 deletions packages/gen/dist/cli.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion packages/gen/dist/post_exec.d.mts
Original file line number Diff line number Diff line change
@@ -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;
2 changes: 2 additions & 0 deletions packages/gen/dist/post_exec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/gen/dist/yargs.d.mts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
2 changes: 1 addition & 1 deletion packages/gen/dist/yargs.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
17 changes: 11 additions & 6 deletions packages/gen/src/cli.mts
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions packages/gen/src/post_exec.mts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/gen/src/yargs.mts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down

0 comments on commit 4673b8d

Please sign in to comment.