Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions e2e/cli-help.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ describe("nf dev --help", () => {
expect(stdout).toContain("run your game in dev mode");
expect(stdout).toContain("--directory");
expect(stdout).toContain("--generate");
expect(stdout).toContain("--editor");
});
});

Expand Down
17 changes: 10 additions & 7 deletions src/action/actions/dev.action.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type Input, getDevGenerateInput, getDirectoryInput } from "@lib/input";
import { type Input, getDevGenerateInput, getDirectoryInput, getEditorInput } from "@lib/input";
import { PackageManagerFactory } from "@lib/package-manager";
import { Messages } from "@lib/ui";

Expand All @@ -15,20 +15,22 @@ export class DevAction extends AbstractAction {
const directory = getDirectoryInput(options);
const generate = getDevGenerateInput(options);

const tasks = this.buildTaskList(directory, generate);
const editor = getEditorInput(options);
const tasks = this.buildTaskList(directory, generate, editor);
await Promise.all(tasks);

return { keepAlive: true };
}

private buildTaskList(directory: string, generate: boolean): Promise<void>[] {
private buildTaskList(directory: string, generate: boolean, editor: boolean): Promise<void>[] {
const tasks: Promise<void>[] = [];
const extraFlags = editor ? ["--editor"] : [];

if (generate) {
tasks.push(this.runSubCommand("generate", directory, { silent: true }));
tasks.push(this.runSubCommand("generate", directory, { silent: true, extraFlags }));
}

tasks.push(this.runSubCommand("build", directory, { silent: true }));
tasks.push(this.runSubCommand("build", directory, { silent: true, extraFlags }));
tasks.push(this.runSubCommand("start", directory, { silent: false }));

return tasks;
Expand All @@ -37,11 +39,12 @@ export class DevAction extends AbstractAction {
private async runSubCommand(
command: string,
directory: string,
options: { silent: boolean },
options: { silent: boolean; extraFlags?: string[] },
): Promise<void> {
await runSafe(async () => {
const packageManager = await PackageManagerFactory.find(directory);
await packageManager.runDev(directory, "nf", {}, [command, "--watch"], options.silent);
const args = [command, "--watch", ...(options.extraFlags ?? [])];
await packageManager.runDev(directory, "nf", {}, args, options.silent);
});
}
}
3 changes: 3 additions & 0 deletions src/command/commands/dev.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ interface DevOptions {
directory?: string;
config?: string;
generate?: boolean;
editor?: boolean;
}

export class DevCommand extends AbstractCommand {
Expand All @@ -18,11 +19,13 @@ export class DevCommand extends AbstractCommand {
.option("-d, --directory <directory>", "specify the working directory of the command")
.option("-c, --config <config>", "path to the config file", CONFIG_FILE_NAME)
.option("--generate", "generate app from config", false)
.option("-e, --editor", "run the editor", false)
.action(async (rawOptions: DevOptions) => {
const options = AbstractCommand.mapToInput({
directory: rawOptions.directory,
config: rawOptions.config,
generate: rawOptions.generate,
editor: rawOptions.editor,
});

await this.action.run(new Map(), options);
Expand Down
Loading