Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(remix-dev/cli/init): add --no-delete flag #3573

Merged
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
2 changes: 2 additions & 0 deletions packages/remix-dev/__tests__/cli-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ describe("remix CLI", () => {
\`dev\` Options:
--debug Attach Node.js inspector
--port, -p Choose the port from which to run your app
\`init\` Options:
--no-delete Skip deleting the \`remix.init\` script
\`routes\` Options:
--json Print the routes as JSON
\`migrate\` Options:
Expand Down
24 changes: 24 additions & 0 deletions packages/remix-dev/__tests__/create-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,30 @@ describe("the create command", () => {
expect(fse.existsSync(path.join(projectDir, "remix.init"))).toBeFalsy();
});

it("It keeps the `remix.init` script when using the `--no-delete` flag", async () => {
let projectDir = await getProjectDir("remix-init-manual");
await run([
"create",
projectDir,
"--template",
path.join(__dirname, "fixtures", "successful-remix-init.tar.gz"),
"--no-install",
"--typescript",
]);
expect(output.trim()).toBe(
getOptOutOfInstallMessage() +
"\n\n" +
getSuccessMessage(path.join("<TEMP_DIR>", "remix-init-manual"))
);

output = "";
process.chdir(projectDir);
await run(["init", "--no-delete"]);

expect(output).toBe("");
expect(fse.existsSync(path.join(projectDir, "remix.init"))).toBeTruthy();
});

it("throws an error when invalid remix.init script when automatically ran", async () => {
let projectDir = await getProjectDir("invalid-remix-init-manual");
await expect(
Expand Down
12 changes: 10 additions & 2 deletions packages/remix-dev/cli/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,13 @@ export async function create({
spinner.clear();
}

export async function init(projectDir: string) {
type InitFlags = {
deleteScript?: boolean;
machour marked this conversation as resolved.
Show resolved Hide resolved
};
export async function init(
projectDir: string,
{ deleteScript = true }: InitFlags = {}
) {
let initScriptDir = path.join(projectDir, "remix.init");
let initScript = path.resolve(initScriptDir, "index.js");

Expand All @@ -79,7 +85,9 @@ export async function init(projectDir: string) {
try {
await initFn({ isTypeScript, packageManager, rootDirectory: projectDir });

await fse.remove(initScriptDir);
if (deleteScript) {
await fse.remove(initScriptDir);
}
} catch (error) {
if (error instanceof Error) {
error.message = `${colors.error("🚨 Oops, remix.init failed")}\n\n${
Expand Down
12 changes: 10 additions & 2 deletions packages/remix-dev/cli/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ ${colors.logoBlue("R")} ${colors.logoGreen("E")} ${colors.logoYellow(
\`dev\` Options:
--debug Attach Node.js inspector
--port, -p Choose the port from which to run your app
\`init\` Options:
--no-delete Skip deleting the \`remix.init\` script
\`routes\` Options:
--json Print the routes as JSON
\`migrate\` Options:
Expand Down Expand Up @@ -151,6 +153,7 @@ export async function run(argv: string[] = process.argv.slice(2)) {
let args = arg(
{
"--debug": Boolean,
"--no-delete": Boolean,
"--dry": Boolean,
"--force": Boolean,
"--help": Boolean,
Expand Down Expand Up @@ -192,6 +195,9 @@ export async function run(argv: string[] = process.argv.slice(2)) {
return;
}

if (args["--no-delete"]) {
flags.delete = false;
}
if (args["--no-install"]) {
flags.install = false;
}
Expand Down Expand Up @@ -408,7 +414,7 @@ export async function run(argv: string[] = process.argv.slice(2)) {
if (hasInitScript) {
if (installDeps) {
console.log("💿 Running remix.init script");
await commands.init(projectDir);
await commands.init(projectDir, { deleteScript: true });
MichaelDeBoey marked this conversation as resolved.
Show resolved Hide resolved
} else {
console.log();
console.log(
Expand Down Expand Up @@ -442,7 +448,9 @@ export async function run(argv: string[] = process.argv.slice(2)) {
break;
}
case "init":
await commands.init(input[1] || process.env.REMIX_ROOT || process.cwd());
await commands.init(input[1] || process.env.REMIX_ROOT || process.cwd(), {
deleteScript: flags.delete,
});
break;
case "routes":
await commands.routes(input[1], flags.json ? "json" : "jsx");
Expand Down