Skip to content

Commit

Permalink
Revert "Add allow-non-empty flag to create-remix CLI"
Browse files Browse the repository at this point in the history
This reverts commit 51525f2.
  • Loading branch information
brophdawg11 committed Aug 17, 2023
1 parent 51525f2 commit 57dbe57
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 50 deletions.
5 changes: 0 additions & 5 deletions .changeset/allow-non-empty.md

This file was deleted.

4 changes: 0 additions & 4 deletions docs/other-api/create-remix.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,4 @@ To create a new project from a template in a private GitHub repo, pass the `--to
</docs-info>
</aside>

### `create-remix --allow-non-empty`

By default, `create-remix` requires that the directory you are creating your app into is empty. You can disable this requirement with `--allow-non-empty`, but beware that if you have files/folders that match files/folders in the template, the template versions will **overwrite** the version in your local directory when this flag is used.

[templates]: ../pages/templates
23 changes: 1 addition & 22 deletions packages/create-remix/__tests__/create-remix-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,34 +203,13 @@ describe("create-remix CLI", () => {
expect(
stderr.trim().replace("<TEMP_DIR>\\", "<TEMP_DIR>/") // Normalize Windows path
).toMatchInlineSnapshot(
`"▲ Oh no! Project directory \\"<TEMP_DIR>/non-interactive-not-empty-dir\\" is not empty. Please use the \`--allow-non-empty\` flag if you wish to write your app into this directory."`
`"▲ Oh no! Project directory \\"<TEMP_DIR>/non-interactive-not-empty-dir\\" is not empty"`
);
expect(status).toBe(1);
expect(fse.existsSync(path.join(notEmptyDir, "package.json"))).toBeFalsy();
expect(fse.existsSync(path.join(notEmptyDir, "app/root.tsx"))).toBeFalsy();
});

it("allows non-empty directories when --allow-non-empty is specified", async () => {
let notEmptyDir = getProjectDir("non-interactive-not-empty-dir-allowed");
fse.mkdirSync(notEmptyDir);
fse.createFileSync(path.join(notEmptyDir, "some-file.txt"));

let { status, stderr, stdout } = await execCreateRemix({
args: [notEmptyDir, "--no-install", "--no-git-init", "--allow-non-empty"],
interactive: false,
});

expect(
stdout.trim().replace("<TEMP_DIR>\\", "<TEMP_DIR>/") // Normalize Windows path
).toMatch(
'Directory: Using non-empty directory "<TEMP_DIR>/non-interactive-not-empty-dir-allowed" as a project directory due to --allow-non-empty'
);
expect(stderr).toBe("");
expect(status).toBe(0);
expect(fse.existsSync(path.join(notEmptyDir, "package.json"))).toBeTruthy();
expect(fse.existsSync(path.join(notEmptyDir, "app/root.tsx"))).toBeTruthy();
});

it("works for GitHub username/repo combo", async () => {
let projectDir = getProjectDir("github-username-repo");

Expand Down
23 changes: 4 additions & 19 deletions packages/create-remix/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ async function getContext(argv: string[]): Promise<Context> {
"--V": "--version",
"--no-color": Boolean,
"--no-motion": Boolean,
"--allow-non-empty": Boolean,
},
{ argv, permissive: true }
);
Expand All @@ -111,7 +110,6 @@ async function getContext(argv: string[]): Promise<Context> {
"--no-motion": noMotion,
"--yes": yes,
"--version": versionRequested,
"--allow-non-empty": allowNonEmpty = false,
} = flags;

let cwd = flags["_"][0] as string;
Expand Down Expand Up @@ -161,7 +159,6 @@ async function getContext(argv: string[]): Promise<Context> {
template,
token,
versionRequested,
allowNonEmpty,
};

return context;
Expand All @@ -187,7 +184,6 @@ interface Context {
template?: string;
token?: string;
versionRequested?: boolean;
allowNonEmpty: boolean;
}

async function introStep(ctx: Context) {
Expand Down Expand Up @@ -217,12 +213,10 @@ async function projectNameStep(ctx: Context) {
throw new Error("No project directory provided");
}

if (!cwdIsEmpty && !ctx.allowNonEmpty) {
if (!cwdIsEmpty) {
error(
"Oh no!",
`Project directory "${color.reset(ctx.cwd)}" is not empty. ` +
"Please use the `--allow-non-empty` flag if you wish to write " +
"your app into this directory."
`Project directory "${color.reset(ctx.cwd)}" is not empty`
);
throw new Error("Project directory is not empty");
}
Expand All @@ -237,21 +231,12 @@ async function projectNameStep(ctx: Context) {
color.reset(ctx.cwd),
" as project directory",
]);
} else if (ctx.allowNonEmpty) {
info("Directory:", [
"Using non-empty directory ",
color.reset(`"${ctx.cwd}"`),
" as a project directory due to --allow-non-empty",
]);
} else {
info("Hmm...", [
color.reset(`"${ctx.cwd}"`),
" is not empty! Did you mean to use the `--allow-non-empty` flag?",
]);
info("Hmm...", [color.reset(`"${ctx.cwd}"`), " is not empty!"]);
}
}

if (!ctx.cwd || (!cwdIsEmpty && !ctx.allowNonEmpty)) {
if (!ctx.cwd || !cwdIsEmpty) {
let { name } = await ctx.prompt({
name: "name",
type: "text",
Expand Down

0 comments on commit 57dbe57

Please sign in to comment.