diff --git a/packages/defer-rw-setup/src/cron/command.ts b/packages/defer-rw-setup/src/cron/command.ts index ab201b5..59ddb45 100644 --- a/packages/defer-rw-setup/src/cron/command.ts +++ b/packages/defer-rw-setup/src/cron/command.ts @@ -15,7 +15,6 @@ export const description = "Add a Defer CRON"; export const builder = (yargs: Yargs.Argv) => { return yargs - .commandDir("cron") .option("force", { alias: "f", default: false, diff --git a/packages/defer-rw-setup/src/cron/tasks.ts b/packages/defer-rw-setup/src/cron/tasks.ts index c4b2c72..108220d 100644 --- a/packages/defer-rw-setup/src/cron/tasks.ts +++ b/packages/defer-rw-setup/src/cron/tasks.ts @@ -1,8 +1,9 @@ import path from "path"; import { Listr } from "listr2"; import fs from "fs-extra"; -import { getPaths, writeFile } from "@redwoodjs/cli-helpers"; import humanize from "humanize-string"; +import pkg from "@redwoodjs/cli-helpers"; +const { getPaths, writeFile } = pkg; import type { FunctionOptions } from "./command"; diff --git a/packages/defer-rw-setup/src/function/command.ts b/packages/defer-rw-setup/src/function/command.ts index 63f85f1..3ce8404 100644 --- a/packages/defer-rw-setup/src/function/command.ts +++ b/packages/defer-rw-setup/src/function/command.ts @@ -15,7 +15,6 @@ export const description = "Add a Defer background function"; export const builder = (yargs: Yargs.Argv) => { return yargs - .commandDir("function") .option("force", { alias: "f", default: false, diff --git a/packages/defer-rw-setup/src/function/tasks.ts b/packages/defer-rw-setup/src/function/tasks.ts index 2fe76b4..5a84a61 100644 --- a/packages/defer-rw-setup/src/function/tasks.ts +++ b/packages/defer-rw-setup/src/function/tasks.ts @@ -1,8 +1,9 @@ import path from "path"; import { Listr } from "listr2"; import fs from "fs-extra"; -import { getPaths, writeFile } from "@redwoodjs/cli-helpers"; import humanize from "humanize-string"; +import pkg from "@redwoodjs/cli-helpers"; +const { getPaths, writeFile } = pkg; import type { FunctionOptions } from "./command"; diff --git a/packages/defer-rw-setup/src/plugin/tasks.ts b/packages/defer-rw-setup/src/plugin/tasks.ts index 3e8cbc9..ffa54d5 100644 --- a/packages/defer-rw-setup/src/plugin/tasks.ts +++ b/packages/defer-rw-setup/src/plugin/tasks.ts @@ -120,19 +120,66 @@ export const configureDeferClient = ({ ); }; -const tomlString = ` -[experimental.cli] - autoInstall = false - [[experimental.cli.plugins]] - package = "@defer/redwood"`; - export const updateTomlConfig = () => { const redwoodTomlPath = getConfigPath(); const configContent = fs.readFileSync(redwoodTomlPath, "utf-8"); if (!configContent.includes("@defer/redwood")) { - writeFile(redwoodTomlPath, configContent.concat(tomlString), { - existingFiles: "OVERWRITE", - }); + if (configContent.includes(" [experimental.cli]")) { + if (configContent.includes(" [[experimental.cli.plugins]]")) { + writeFile( + redwoodTomlPath, + configContent.concat(` + [[experimental.cli.plugins]] + package = "@defer/redwood" + + [[experimental.cli.plugins]]`), + { + existingFiles: "OVERWRITE", + } + ); + } else { + if ( + configContent.match(`[experimental.cli] + autoInstall = true`) + ) { + writeFile( + redwoodTomlPath, + configContent.concat(` +[experimental.cli] +autoInstall = true +[[experimental.cli.plugins]] + package = "@defer/redwood"`), + { + existingFiles: "OVERWRITE", + } + ); + } else { + writeFile( + redwoodTomlPath, + configContent.concat(` +[experimental.cli] +autoInstall = false +[[experimental.cli.plugins]] + package = "@defer/redwood"`), + { + existingFiles: "OVERWRITE", + } + ); + } + } + } else { + writeFile( + redwoodTomlPath, + configContent.concat(` +[experimental.cli] + autoInstall = false + [[experimental.cli.plugins]] + package = "@defer/redwood"`), + { + existingFiles: "OVERWRITE", + } + ); + } } };