Skip to content

Commit

Permalink
polish: split generate into its own file (#1343)
Browse files Browse the repository at this point in the history
* polish: split generate into its own file

* Create spotty-birds-care.md

* use regular functions
  • Loading branch information
rozenmd authored Jun 23, 2022
1 parent 6426625 commit 59a83f8
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 22 deletions.
5 changes: 5 additions & 0 deletions .changeset/spotty-birds-care.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

polish: split generate into its own file
33 changes: 33 additions & 0 deletions packages/wrangler/src/generate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { DeprecationError } from "./errors";
import type { Argv, ArgumentsCamelCase } from "yargs";

interface GenerateArgs {
name: string;
template: string;
}

export function generateOptions(yargs: Argv) {
return yargs
.positional("name", {
describe: "Name of the Workers project",
default: "worker",
})
.positional("template", {
describe: "The URL of a GitHub template",
default: "https://github.com/cloudflare/worker-template",
});
}

export function generateHandler(
generateArgs: ArgumentsCamelCase<GenerateArgs>
) {
// "👯 [DEPRECATED]. Scaffold a Cloudflare Workers project from a public GitHub repository.",
throw new DeprecationError(
"`wrangler generate` has been deprecated.\n" +
"Try running `wrangler init` to generate a basic Worker, or cloning the template repository instead:\n\n" +
"```\n" +
`git clone ${generateArgs.template}\n` +
"```\n\n" +
"Please refer to https://developers.cloudflare.com/workers/wrangler/deprecations/#generate for more information."
);
}
25 changes: 3 additions & 22 deletions packages/wrangler/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import Dev from "./dev/dev";
import { confirm, prompt, select } from "./dialogs";
import { getEntry } from "./entry";
import { DeprecationError } from "./errors";
import { generateHandler, generateOptions } from "./generate";
import { initializeGit, isGitInstalled, isInsideGitRepo } from "./git-client";
import {
getKVNamespaceId,
Expand Down Expand Up @@ -284,28 +285,8 @@ function createCLIParser(argv: string[]) {
// we can do something better here, let's see
"generate [name] [template]",
false,
(yargs) => {
return yargs
.positional("name", {
describe: "Name of the Workers project",
default: "worker",
})
.positional("template", {
describe: "The URL of a GitHub template",
default: "https://github.com/cloudflare/worker-template",
});
},
(generateArgs) => {
// "👯 [DEPRECATED]. Scaffold a Cloudflare Workers project from a public GitHub repository.",
throw new DeprecationError(
"`wrangler generate` has been deprecated.\n" +
"Try running `wrangler init` to generate a basic Worker, or cloning the template repository instead:\n\n" +
"```\n" +
`git clone ${generateArgs.template}\n` +
"```\n\n" +
"Please refer to https://developers.cloudflare.com/workers/wrangler/deprecations/#generate for more information."
);
}
generateOptions,
generateHandler
);

// init
Expand Down

0 comments on commit 59a83f8

Please sign in to comment.