create-cloudflare 0.0.0-a986f19f → 0.0.0-a9cb8c60

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -46,7 +46,7 @@ To create a new Typescript "Hello World" worker, run:
46
46
  npm create cloudflare@latest hello-world -- --type hello-world --ts
47
47
  ```
48
48
 
49
- Current template options are: `hello-world`, `common`, or `chatgptPlugin`.
49
+ Current template options are: `hello-world`, `common`, `chatgptPlugin`, or `openapi`.
50
50
 
51
51
  #### Additional arguments
52
52
 
package/dist/cli.js CHANGED
@@ -57864,7 +57864,7 @@ var Yargs = YargsFactory(esm_default);
57864
57864
  var yargs_default = Yargs;
57865
57865
 
57866
57866
  // package.json
57867
- var version = "0.0.0-a986f19f";
57867
+ var version = "0.0.0-a9cb8c60";
57868
57868
  var devDependencies = {
57869
57869
  "@babel/parser": "^7.21.3",
57870
57870
  "@babel/types": "^7.21.4",
@@ -58504,7 +58504,7 @@ async function openInBrowser(url) {
58504
58504
  }
58505
58505
  var C3_DEFAULTS = {
58506
58506
  projectName: new import_haikunator.default().haikunate({ tokenHex: true }),
58507
- type: "hello-world",
58507
+ type: "webFramework",
58508
58508
  framework: "angular",
58509
58509
  autoUpdate: true,
58510
58510
  deploy: true,
@@ -59871,14 +59871,21 @@ var detectPackageManager = () => {
59871
59871
  case "pnpm":
59872
59872
  name2 = "pnpm";
59873
59873
  version3 = devDependencies["pnpm"].replace("^", "");
59874
+ process.env.npm_config_user_agent = "pnpm";
59874
59875
  break;
59875
59876
  case "yarn":
59876
59877
  name2 = "yarn";
59877
59878
  version3 = devDependencies["yarn"].replace("^", "");
59879
+ process.env.npm_config_user_agent = "yarn";
59880
+ break;
59881
+ case "bun":
59882
+ name2 = "bun";
59883
+ version3 = "1.0.0";
59878
59884
  break;
59879
59885
  case "npm":
59880
59886
  name2 = "npm";
59881
59887
  version3 = "0.0.0";
59888
+ process.env.npm_config_user_agent = "npm";
59882
59889
  break;
59883
59890
  }
59884
59891
  }
@@ -59917,6 +59924,14 @@ var detectPackageManager = () => {
59917
59924
  npx: "yarn",
59918
59925
  dlx: "yarn"
59919
59926
  };
59927
+ case "bun":
59928
+ return {
59929
+ name: name2,
59930
+ version: version3,
59931
+ npm: "bun",
59932
+ npx: "bunx",
59933
+ dlx: "bunx"
59934
+ };
59920
59935
  case "npm":
59921
59936
  default:
59922
59937
  return {
@@ -60047,14 +60062,18 @@ var runFrameworkGenerator = async (ctx, cmd) => {
60047
60062
  await runCommand(cmd);
60048
60063
  };
60049
60064
  var installPackages = async (packages, config14) => {
60050
- const { npm: npm13 } = detectPackageManager();
60065
+ const { npm: npm14 } = detectPackageManager();
60051
60066
  let saveFlag;
60052
60067
  let cmd;
60053
- switch (npm13) {
60068
+ switch (npm14) {
60054
60069
  case "yarn":
60055
60070
  cmd = "add";
60056
60071
  saveFlag = config14.dev ? "-D" : "";
60057
60072
  break;
60073
+ case "bun":
60074
+ cmd = "add";
60075
+ saveFlag = config14.dev ? "-d" : "";
60076
+ break;
60058
60077
  case "npm":
60059
60078
  case "pnpm":
60060
60079
  default:
@@ -60062,36 +60081,36 @@ var installPackages = async (packages, config14) => {
60062
60081
  saveFlag = config14.dev ? "--save-dev" : "--save";
60063
60082
  break;
60064
60083
  }
60065
- await runCommand(`${npm13} ${cmd} ${saveFlag} ${packages.join(" ")}`, {
60084
+ await runCommand(`${npm14} ${cmd} ${saveFlag} ${packages.join(" ")}`, {
60066
60085
  ...config14,
60067
60086
  silent: true
60068
60087
  });
60069
60088
  };
60070
60089
  var npmInstall = async () => {
60071
- const { npm: npm13 } = detectPackageManager();
60072
- await runCommand(`${npm13} install`, {
60090
+ const { npm: npm14 } = detectPackageManager();
60091
+ await runCommand(`${npm14} install`, {
60073
60092
  silent: true,
60074
60093
  startText: "Installing dependencies",
60075
- doneText: `${brandColor("installed")} ${dim(`via \`${npm13} install\``)}`
60094
+ doneText: `${brandColor("installed")} ${dim(`via \`${npm14} install\``)}`
60076
60095
  });
60077
60096
  };
60078
60097
  var resetPackageManager = async (ctx) => {
60079
- const { npm: npm13 } = detectPackageManager();
60080
- if (npm13 === "npm")
60098
+ const { npm: npm14 } = detectPackageManager();
60099
+ if (npm14 === "npm")
60081
60100
  return;
60082
60101
  const nodeModulesPath = import_path5.default.join(ctx.project.path, "node_modules");
60083
60102
  (0, import_fs5.rmSync)(nodeModulesPath, { recursive: true });
60084
60103
  const lockfilePath = import_path5.default.join(ctx.project.path, "package-lock.json");
60085
60104
  (0, import_fs5.rmSync)(lockfilePath);
60086
- await runCommand(`${npm13} install`, {
60105
+ await runCommand(`${npm14} install`, {
60087
60106
  silent: true,
60088
60107
  cwd: ctx.project.path,
60089
60108
  startText: "Installing dependencies",
60090
- doneText: `${brandColor("installed")} ${dim(`via \`${npm13} install\``)}`
60109
+ doneText: `${brandColor("installed")} ${dim(`via \`${npm14} install\``)}`
60091
60110
  });
60092
60111
  };
60093
60112
  var installWrangler = async () => {
60094
- const { npm: npm13 } = detectPackageManager();
60113
+ const { npm: npm14 } = detectPackageManager();
60095
60114
  if ((0, import_fs5.existsSync)(import_path5.default.resolve("node_modules", "wrangler"))) {
60096
60115
  return;
60097
60116
  }
@@ -60101,7 +60120,7 @@ var installWrangler = async () => {
60101
60120
  "A command line tool for building Cloudflare Workers"
60102
60121
  )}`,
60103
60122
  doneText: `${brandColor("installed")} ${dim(
60104
- `via \`${npm13} install wrangler --save-dev\``
60123
+ `via \`${npm14} install wrangler --save-dev\``
60105
60124
  )}`
60106
60125
  });
60107
60126
  };
@@ -60148,8 +60167,8 @@ var listAccounts = async () => {
60148
60167
  return accounts;
60149
60168
  };
60150
60169
  async function getWorkerdCompatibilityDate() {
60151
- const { npm: npm13 } = detectPackageManager();
60152
- return runCommand(`${npm13} info workerd dist-tags.latest`, {
60170
+ const { npm: npm14 } = detectPackageManager();
60171
+ return runCommand(`${npm14} info workerd dist-tags.latest`, {
60153
60172
  silent: true,
60154
60173
  captureOutput: true,
60155
60174
  startText: "Retrieving current workerd compatibility date",
@@ -60600,10 +60619,14 @@ var config6 = {
60600
60619
  var next_default = config6;
60601
60620
 
60602
60621
  // src/frameworks/nuxt/index.ts
60603
- var { dlx: dlx7 } = detectPackageManager();
60622
+ var { npm: npm5, dlx: dlx7 } = detectPackageManager();
60604
60623
  var generate7 = async (ctx) => {
60605
60624
  const cli = getFrameworkCli(ctx);
60606
- await runFrameworkGenerator(ctx, `${dlx7} ${cli} init ${ctx.project.name}`);
60625
+ const gitFlag = ctx.args.git ? `--gitInit` : `--no-gitInit`;
60626
+ await runFrameworkGenerator(
60627
+ ctx,
60628
+ `${dlx7} ${cli} init ${ctx.project.name} --packageManager ${npm5} ${gitFlag}`
60629
+ );
60607
60630
  logRaw("");
60608
60631
  };
60609
60632
  var configure4 = async (ctx) => {
@@ -60617,8 +60640,8 @@ var config7 = {
60617
60640
  displayName: "Nuxt",
60618
60641
  packageScripts: {
60619
60642
  build: (cmd) => `NITRO_PRESET=cloudflare-pages ${cmd}`,
60620
- "pages:dev": `wrangler pages dev ${compatDateFlag()} --proxy 3000 -- npm run dev`,
60621
- "pages:deploy": "npm run build && wrangler pages deploy ./dist"
60643
+ "pages:dev": `wrangler pages dev ${compatDateFlag()} --proxy 3000 -- ${npm5} run dev`,
60644
+ "pages:deploy": `${npm5} run build && wrangler pages deploy ./dist`
60622
60645
  }
60623
60646
  };
60624
60647
  var nuxt_default = config7;
@@ -60632,19 +60655,19 @@ var package_default = {
60632
60655
  "additionally it also contains a map that maps frameworks to their respective clis"
60633
60656
  ],
60634
60657
  dependencies: {
60635
- "@angular/cli": "16.2.0",
60636
- "create-astro": "4.0.1",
60658
+ "@angular/cli": "16.2.2",
60659
+ "create-astro": "4.1.0",
60637
60660
  "create-docusaurus": "2.4.1",
60638
60661
  "create-hono": "0.2.6",
60639
60662
  "create-next-app": "13.4.19",
60640
- "create-qwik": "1.2.7",
60663
+ "create-qwik": "1.2.12",
60641
60664
  "create-react-app": "5.0.1",
60642
- "create-remix": "1.19.3",
60643
- "create-solid": "0.2.26",
60644
- "create-svelte": "4.2.0",
60645
- "create-vue": "3.6.4",
60646
- gatsby: "5.11.0",
60647
- nuxi: "3.6.5"
60665
+ "create-remix": "2.0.0",
60666
+ "create-solid": "0.3.6",
60667
+ "create-svelte": "5.1.0",
60668
+ "create-vue": "3.7.5",
60669
+ gatsby: "5.12.4",
60670
+ nuxi: "3.9.0"
60648
60671
  },
60649
60672
  frameworkCliMap: {
60650
60673
  angular: "@angular/cli",
@@ -60664,7 +60687,7 @@ var package_default = {
60664
60687
  };
60665
60688
 
60666
60689
  // src/frameworks/qwik/index.ts
60667
- var { npm: npm5, npx: npx4, dlx: dlx8 } = detectPackageManager();
60690
+ var { npm: npm6, npx: npx4, dlx: dlx8 } = detectPackageManager();
60668
60691
  var generate8 = async (ctx) => {
60669
60692
  const cli = getFrameworkCli(ctx);
60670
60693
  await runFrameworkGenerator(ctx, `${dlx8} ${cli} basic ${ctx.project.name}`);
@@ -60681,14 +60704,14 @@ var config8 = {
60681
60704
  configure: configure5,
60682
60705
  displayName: "Qwik",
60683
60706
  packageScripts: {
60684
- "pages:dev": `wrangler pages dev ${compatDateFlag()} -- ${npm5} run dev`,
60685
- "pages:deploy": `${npm5} run build && wrangler pages deploy ./dist`
60707
+ "pages:dev": `wrangler pages dev ${compatDateFlag()} -- ${npm6} run dev`,
60708
+ "pages:deploy": `${npm6} run build && wrangler pages deploy ./dist`
60686
60709
  }
60687
60710
  };
60688
60711
  var qwik_default = config8;
60689
60712
 
60690
60713
  // src/frameworks/react/index.ts
60691
- var { npm: npm6, dlx: dlx9 } = detectPackageManager();
60714
+ var { npm: npm7, dlx: dlx9 } = detectPackageManager();
60692
60715
  var generate9 = async (ctx) => {
60693
60716
  const cli = getFrameworkCli(ctx);
60694
60717
  await runFrameworkGenerator(ctx, `${dlx9} ${cli} ${ctx.project.name}`);
@@ -60702,14 +60725,14 @@ var config9 = {
60702
60725
  configure: configure6,
60703
60726
  displayName: "React",
60704
60727
  packageScripts: {
60705
- "pages:dev": `wrangler pages dev ${compatDateFlag()} --port 3000 -- ${npm6} start`,
60706
- "pages:deploy": `${npm6} run build && wrangler pages deploy ./build`
60728
+ "pages:dev": `wrangler pages dev ${compatDateFlag()} --port 3000 -- ${npm7} start`,
60729
+ "pages:deploy": `${npm7} run build && wrangler pages deploy ./build`
60707
60730
  }
60708
60731
  };
60709
60732
  var react_default = config9;
60710
60733
 
60711
60734
  // src/frameworks/remix/index.ts
60712
- var { npm: npm7, dlx: dlx10 } = detectPackageManager();
60735
+ var { npm: npm8, dlx: dlx10 } = detectPackageManager();
60713
60736
  var generate10 = async (ctx) => {
60714
60737
  const cli = getFrameworkCli(ctx);
60715
60738
  await runFrameworkGenerator(
@@ -60722,16 +60745,13 @@ var config10 = {
60722
60745
  generate: generate10,
60723
60746
  displayName: "Remix",
60724
60747
  packageScripts: {
60725
- "pages:deploy": `${npm7} run build && wrangler pages deploy ./public`
60748
+ "pages:deploy": `${npm8} run build && wrangler pages deploy ./public`
60726
60749
  },
60727
60750
  devCommand: "dev",
60728
- testFlags: ["--typescript", "--no-install"]
60751
+ testFlags: ["--typescript", "--no-install", "--no-git-init"]
60729
60752
  };
60730
60753
  var remix_default = config10;
60731
60754
 
60732
- // src/frameworks/solid/index.ts
60733
- var import_fs8 = require("fs");
60734
-
60735
60755
  // src/frameworks/solid/templates.ts
60736
60756
  var viteConfig = `
60737
60757
  import solid from "solid-start/vite";
@@ -60744,15 +60764,14 @@ export default defineConfig({
60744
60764
  `;
60745
60765
 
60746
60766
  // src/frameworks/solid/index.ts
60747
- var { npm: npm8, dlx: dlx11 } = detectPackageManager();
60767
+ var { npm: npm9, dlx: dlx11 } = detectPackageManager();
60748
60768
  var generate11 = async (ctx) => {
60749
- (0, import_fs8.mkdirSync)(ctx.project.path);
60750
- process.chdir(ctx.project.path);
60751
60769
  const cli = getFrameworkCli(ctx);
60752
- await runFrameworkGenerator(ctx, `${dlx11} ${cli}`);
60770
+ await runFrameworkGenerator(ctx, `${dlx11} ${cli} ${ctx.project.name}`);
60753
60771
  logRaw("");
60754
60772
  };
60755
- var configure7 = async () => {
60773
+ var configure7 = async (ctx) => {
60774
+ process.chdir(ctx.project.path);
60756
60775
  const pkg = "solid-start-cloudflare-pages";
60757
60776
  await installPackages([pkg], {
60758
60777
  dev: true,
@@ -60762,7 +60781,7 @@ var configure7 = async () => {
60762
60781
  const viteConfigPath = usesTypescript() ? `./vite.config.ts` : `./vite.config.js`;
60763
60782
  writeFile2(viteConfigPath, viteConfig);
60764
60783
  updateStatus(
60765
- `Adding the Cloudflare Pages adapter to ${blue("vite.config.js")}`
60784
+ `Adding the Cloudflare Pages adapter to ${blue(viteConfigPath)}`
60766
60785
  );
60767
60786
  };
60768
60787
  var config11 = {
@@ -60770,8 +60789,8 @@ var config11 = {
60770
60789
  configure: configure7,
60771
60790
  displayName: "Solid",
60772
60791
  packageScripts: {
60773
- "pages:dev": `wrangler pages dev ${compatDateFlag()} --proxy 3000 -- ${npm8} run dev`,
60774
- "pages:deploy": `${npm8} run build && wrangler pages deploy ./dist/public`
60792
+ "pages:dev": `wrangler pages dev ${compatDateFlag()} --proxy 3000 -- ${npm9} run dev`,
60793
+ "pages:deploy": `${npm9} run build && wrangler pages deploy ./dist/public`
60775
60794
  }
60776
60795
  };
60777
60796
  var solid_default = config11;
@@ -60823,7 +60842,7 @@ interface Platform {
60823
60842
  `;
60824
60843
 
60825
60844
  // src/frameworks/svelte/index.ts
60826
- var { npm: npm9, dlx: dlx12 } = detectPackageManager();
60845
+ var { npm: npm10, dlx: dlx12 } = detectPackageManager();
60827
60846
  var generate12 = async (ctx) => {
60828
60847
  const cli = getFrameworkCli(ctx);
60829
60848
  await runFrameworkGenerator(ctx, `${dlx12} ${cli} ${ctx.project.name}`);
@@ -60867,14 +60886,14 @@ var config12 = {
60867
60886
  configure: configure8,
60868
60887
  displayName: "Svelte",
60869
60888
  packageScripts: {
60870
- "pages:dev": `wrangler pages dev ${compatDateFlag()} --proxy 5173 -- ${npm9} run dev`,
60871
- "pages:deploy": `NODE_VERSION=16 ${npm9} run build && wrangler pages deploy .svelte-kit/cloudflare`
60889
+ "pages:dev": `wrangler pages dev ${compatDateFlag()} --proxy 5173 -- ${npm10} run dev`,
60890
+ "pages:deploy": `${npm10} run build && wrangler pages deploy .svelte-kit/cloudflare`
60872
60891
  }
60873
60892
  };
60874
60893
  var svelte_default = config12;
60875
60894
 
60876
60895
  // src/frameworks/vue/index.ts
60877
- var { npm: npm10, dlx: dlx13 } = detectPackageManager();
60896
+ var { npm: npm11, dlx: dlx13 } = detectPackageManager();
60878
60897
  var generate13 = async (ctx) => {
60879
60898
  const cli = getFrameworkCli(ctx);
60880
60899
  await runFrameworkGenerator(ctx, `${dlx13} ${cli} ${ctx.project.name}`);
@@ -60883,8 +60902,8 @@ var config13 = {
60883
60902
  generate: generate13,
60884
60903
  displayName: "Vue",
60885
60904
  packageScripts: {
60886
- "pages:dev": `wrangler pages dev ${compatDateFlag()} --proxy 5173 -- ${npm10} run dev`,
60887
- "pages:deploy": `${npm10} run build && wrangler pages deploy ./dist`
60905
+ "pages:dev": `wrangler pages dev ${compatDateFlag()} --proxy 5173 -- ${npm11} run dev`,
60906
+ "pages:deploy": `${npm11} run build && wrangler pages deploy ./dist`
60888
60907
  },
60889
60908
  testFlags: ["--ts"]
60890
60909
  };
@@ -60927,7 +60946,7 @@ var debug = (msg) => {
60927
60946
  };
60928
60947
 
60929
60948
  // src/common.ts
60930
- var import_fs9 = require("fs");
60949
+ var import_fs8 = require("fs");
60931
60950
  var import_path7 = require("path");
60932
60951
  var import_process2 = require("process");
60933
60952
 
@@ -61023,14 +61042,14 @@ function secondsSince(start) {
61023
61042
  }
61024
61043
 
61025
61044
  // ../wrangler/package.json
61026
- var version2 = "3.7.0";
61045
+ var version2 = "3.10.1";
61027
61046
 
61028
61047
  // src/common.ts
61029
- var { name, npm: npm11 } = detectPackageManager();
61048
+ var { name, npm: npm12 } = detectPackageManager();
61030
61049
  var validateProjectDirectory = (relativePath) => {
61031
61050
  const path3 = (0, import_path7.resolve)(relativePath);
61032
- const existsAlready = (0, import_fs9.existsSync)(path3);
61033
- const isEmpty = existsAlready && (0, import_fs9.readdirSync)(path3).length === 0;
61051
+ const existsAlready = (0, import_fs8.existsSync)(path3);
61052
+ const isEmpty = existsAlready && (0, import_fs8.readdirSync)(path3).length === 0;
61034
61053
  if (existsAlready && !isEmpty) {
61035
61054
  return `Directory \`${relativePath}\` already exists and is not empty. Please choose a new name.`;
61036
61055
  }
@@ -61043,13 +61062,13 @@ var setupProjectDirectory = (args) => {
61043
61062
  }
61044
61063
  const directory = (0, import_path7.dirname)(path3);
61045
61064
  const pathBasename = (0, import_path7.basename)(path3);
61046
- (0, import_fs9.mkdirSync)(directory, { recursive: true });
61065
+ (0, import_fs8.mkdirSync)(directory, { recursive: true });
61047
61066
  (0, import_process2.chdir)(directory);
61048
61067
  return { name: pathBasename, path: path3 };
61049
61068
  };
61050
61069
  var offerToDeploy = async (ctx) => {
61051
61070
  startSection(`Deploy with Cloudflare`, `Step 3 of 3`);
61052
- const label = `deploy via \`${npm11} run ${ctx.framework?.config.deployCommand ?? "deploy"}\``;
61071
+ const label = `deploy via \`${npm12} run ${ctx.framework?.config.deployCommand ?? "deploy"}\``;
61053
61072
  ctx.args.deploy = await processArgument(ctx.args, "deploy", {
61054
61073
  type: "confirm",
61055
61074
  question: "Do you want to deploy your application?",
@@ -61071,7 +61090,7 @@ var runDeploy = async (ctx) => {
61071
61090
  return;
61072
61091
  }
61073
61092
  const baseDeployCmd = [
61074
- npm11,
61093
+ npm12,
61075
61094
  "run",
61076
61095
  ctx.framework?.config.deployCommand ?? "deploy"
61077
61096
  ];
@@ -61146,11 +61165,11 @@ var printSummary = async (ctx) => {
61146
61165
  [`Navigate to the new directory`, `cd ${ctx.project.name}`],
61147
61166
  [
61148
61167
  `Run the development server`,
61149
- `${npm11} run ${ctx.framework?.config.devCommand ?? "start"}`
61168
+ `${npm12} run ${ctx.framework?.config.devCommand ?? "start"}`
61150
61169
  ],
61151
61170
  [
61152
61171
  `Deploy your application`,
61153
- `${npm11} run ${ctx.framework?.config.deployCommand ?? "deploy"}`
61172
+ `${npm12} run ${ctx.framework?.config.deployCommand ?? "deploy"}`
61154
61173
  ],
61155
61174
  [
61156
61175
  `Read the documentation`,
@@ -61172,7 +61191,7 @@ var printSummary = async (ctx) => {
61172
61191
  `${bgGreen(" APPLICATION CREATED ")}`,
61173
61192
  `${dim(`Deploy your application with`)}`,
61174
61193
  `${blue(
61175
- `${npm11} run ${ctx.framework?.config.deployCommand ?? "deploy"}`
61194
+ `${npm12} run ${ctx.framework?.config.deployCommand ?? "deploy"}`
61176
61195
  )}`
61177
61196
  ].join(" ");
61178
61197
  logRaw(msg);
@@ -61627,6 +61646,13 @@ var templateMap = {
61627
61646
  ts: true
61628
61647
  })
61629
61648
  },
61649
+ openapi: {
61650
+ label: `OpenAPI 3.1`,
61651
+ handler: (args) => runWorkersGenerator({
61652
+ ...args,
61653
+ ts: true
61654
+ })
61655
+ },
61630
61656
  "pre-existing": {
61631
61657
  label: "Pre-existing Worker (from Dashboard)",
61632
61658
  handler: runWorkersGenerator,
@@ -61683,7 +61709,7 @@ var processArgument = async (args, name2, promptConfig) => {
61683
61709
 
61684
61710
  // src/cli.ts
61685
61711
  var import_semver2 = __toESM(require_semver2());
61686
- var { npm: npm12 } = detectPackageManager();
61712
+ var { npm: npm13 } = detectPackageManager();
61687
61713
  var main = async (argv) => {
61688
61714
  const args = await parseArgs(argv);
61689
61715
  logRaw("");
@@ -61710,7 +61736,7 @@ var isUpdateAvailable = async () => {
61710
61736
  };
61711
61737
  var runLatest = async () => {
61712
61738
  const args = process.argv.slice(2);
61713
- await runCommand(`${npm12} create cloudflare@latest ${args.join(" ")}`);
61739
+ await runCommand(`${npm13} create cloudflare@latest ${args.join(" ")}`);
61714
61740
  };
61715
61741
  var runCli = async (args) => {
61716
61742
  printBanner();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-cloudflare",
3
- "version": "0.0.0-a986f19f",
3
+ "version": "0.0.0-a9cb8c60",
4
4
  "description": "A CLI for creating and deploying new applications to Cloudflare.",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -62,10 +62,10 @@
62
62
  "@clack/core": "^0.3.2",
63
63
  "@types/semver": "^7.5.1",
64
64
  "@cloudflare/workers-tsconfig": "0.0.0",
65
- "wrangler": "3.7.0"
65
+ "wrangler": "3.10.1"
66
66
  },
67
67
  "engines": {
68
- "node": ">=16.13.0"
68
+ "node": ">=18.14.1"
69
69
  },
70
70
  "scripts": {
71
71
  "build": "node -r esbuild-register scripts/build.ts",
@@ -75,6 +75,7 @@
75
75
  "test:e2e:cleanup": "node -r esbuild-register scripts/e2eCleanup.ts",
76
76
  "test:e2e:npm": "pnpm run build && TEST_PM=npm vitest run --config ./vitest-e2e.config.ts",
77
77
  "test:e2e:pnpm": "pnpm run build && TEST_PM=pnpm vitest run --config ./vitest-e2e.config.ts",
78
+ "test:e2e:bun": "pnpm run build && TEST_PM=bun vitest run --config ./vitest-e2e.config.ts",
78
79
  "test:unit": "vitest run --config ./vitest.config.ts",
79
80
  "test:unit:watch": "vitest --config ./vitest.config.ts",
80
81
  "watch": "node -r esbuild-register scripts/build.ts --watch"
@@ -17,8 +17,8 @@ The sample plugin allows ChatGPT users to search for repositories using GitHub's
17
17
  ## Usage
18
18
 
19
19
  1. You can configure the `.well-known/ai-plugin.json` route in `index.ts`.
20
- 2. Update the OpenAPI schema in `openapi.ts`.
21
- 3. You can set up any new routes and the associated OpenAPI schema by defining new routes. See `search.ts` for an example.
20
+ 2. You can set up any new routes and the associated OpenAPI schema by defining new routes. See `search.ts` for an example.
21
+ 3. For more information read the [itty-router-openapi official documentation](https://cloudflare.github.io/itty-router-openapi/).
22
22
 
23
23
  ## Deploying to OpenAI's API
24
24
 
@@ -4,10 +4,11 @@
4
4
  "private": true,
5
5
  "scripts": {
6
6
  "deploy": "wrangler deploy",
7
+ "dev": "wrangler dev",
7
8
  "start": "wrangler dev"
8
9
  },
9
10
  "dependencies": {
10
- "@cloudflare/itty-router-openapi": "^0.1.2"
11
+ "@cloudflare/itty-router-openapi": "^1.0.1"
11
12
  },
12
13
  "devDependencies": {
13
14
  "@cloudflare/workers-types": "^4.20230404.0",
@@ -1,9 +1,4 @@
1
- import {
2
- ApiException,
3
- OpenAPIRoute,
4
- Query,
5
- ValidationError,
6
- } from "@cloudflare/itty-router-openapi";
1
+ import { OpenAPIRoute, Query } from "@cloudflare/itty-router-openapi";
7
2
 
8
3
  export class GetSearch extends OpenAPIRoute {
9
4
  static schema = {
@@ -17,6 +12,7 @@ export class GetSearch extends OpenAPIRoute {
17
12
  },
18
13
  responses: {
19
14
  "200": {
15
+ description: "Successfully response",
20
16
  schema: {
21
17
  repos: [
22
18
  {
@@ -33,7 +29,7 @@ export class GetSearch extends OpenAPIRoute {
33
29
  };
34
30
 
35
31
  async handle(request: Request, env, ctx, data: Record<string, any>) {
36
- const url = `https://api.github.com/search/repositories?q=${data.q}`;
32
+ const url = `https://api.github.com/search/repositories?q=${data.query.q}`;
37
33
 
38
34
  const resp = await fetch(url, {
39
35
  headers: {
@@ -4,6 +4,7 @@
4
4
  "private": true,
5
5
  "scripts": {
6
6
  "deploy": "wrangler deploy",
7
+ "dev": "wrangler dev",
7
8
  "start": "wrangler dev"
8
9
  },
9
10
  "devDependencies": {
@@ -4,6 +4,7 @@
4
4
  "private": true,
5
5
  "scripts": {
6
6
  "deploy": "wrangler deploy",
7
+ "dev": "wrangler dev",
7
8
  "start": "wrangler dev"
8
9
  },
9
10
  "devDependencies": {
@@ -4,6 +4,7 @@
4
4
  "private": true,
5
5
  "scripts": {
6
6
  "deploy": "wrangler deploy",
7
+ "dev": "wrangler dev",
7
8
  "start": "wrangler dev"
8
9
  },
9
10
  "devDependencies": {
@@ -4,6 +4,7 @@
4
4
  "private": true,
5
5
  "scripts": {
6
6
  "deploy": "wrangler deploy",
7
+ "dev": "wrangler dev",
7
8
  "start": "wrangler dev"
8
9
  },
9
10
  "devDependencies": {
@@ -0,0 +1,25 @@
1
+ # Cloudflare Workers OpenAPI 3.1
2
+
3
+ This is a Cloudflare Worker with OpenAPI 3.1 using [itty-router-openapi](https://github.com/cloudflare/itty-router-openapi).
4
+
5
+ This is an example project made to be used as a quick start into building OpenAPI compliant Workers that generates the
6
+ `openapi.json` schema automatically from code and validates the incoming request to the defined parameters or request body.
7
+
8
+ ## Get started
9
+
10
+ 1. Sign up for [Cloudflare Workers](https://workers.dev). The free tier is more than enough for most use cases.
11
+ 2. Clone this project and install dependencies with `npm install`
12
+ 3. Run `wrangler login` to login to your Cloudflare account in wrangler
13
+ 4. Run `wrangler deploy` to publish the API to Cloudflare Workers
14
+
15
+ ## Project structure
16
+
17
+ 1. Your main router is defined in `src/index.ts`.
18
+ 2. Each endpoint has its own file in `src/endpoints/`.
19
+ 3. For more information read the [itty-router-openapi official documentation](https://cloudflare.github.io/itty-router-openapi/).
20
+
21
+ ## Development
22
+
23
+ 1. Run `wrangler dev` to start a local instance of the API.
24
+ 2. Open `http://localhost:9000/` in your browser to see the Swagger interface where you can try the endpoints.
25
+ 3. Changes made in the `src/` folder will automatically trigger the server to reload, you only need to refresh the Swagger interface.
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "cloudflare-workers-openapi",
3
+ "version": "0.0.1",
4
+ "private": true,
5
+ "scripts": {
6
+ "deploy": "wrangler deploy",
7
+ "dev": "wrangler dev",
8
+ "start": "wrangler dev"
9
+ },
10
+ "dependencies": {
11
+ "@cloudflare/itty-router-openapi": "^1.0.1"
12
+ },
13
+ "devDependencies": {
14
+ "@cloudflare/workers-types": "^4.20230821.0",
15
+ "@types/node": "^20.5.7",
16
+ "@types/service-worker-mock": "^2.0.1",
17
+ "wrangler": "^3.0.0"
18
+ }
19
+ }
@@ -0,0 +1,48 @@
1
+ import {
2
+ OpenAPIRoute,
3
+ OpenAPIRouteSchema,
4
+ } from "@cloudflare/itty-router-openapi";
5
+ import { Task } from "../types";
6
+
7
+ export class TaskCreate extends OpenAPIRoute {
8
+ static schema: OpenAPIRouteSchema = {
9
+ tags: ["Tasks"],
10
+ summary: "Create a new Task",
11
+ requestBody: Task,
12
+ responses: {
13
+ "200": {
14
+ description: "Returns the created task",
15
+ schema: {
16
+ success: Boolean,
17
+ result: {
18
+ task: Task,
19
+ },
20
+ },
21
+ },
22
+ },
23
+ };
24
+
25
+ async handle(
26
+ request: Request,
27
+ env: any,
28
+ context: any,
29
+ data: Record<string, any>
30
+ ) {
31
+ // Retrieve the validated request body
32
+ const taskToCreate = data.body;
33
+
34
+ // Implement your own object insertion here
35
+
36
+ // return the new task
37
+ return {
38
+ success: true,
39
+ task: {
40
+ name: taskToCreate.name,
41
+ slug: taskToCreate.slug,
42
+ description: taskToCreate.description,
43
+ completed: taskToCreate.completed,
44
+ due_date: taskToCreate.due_date,
45
+ },
46
+ };
47
+ }
48
+ }
@@ -0,0 +1,55 @@
1
+ import {
2
+ OpenAPIRoute,
3
+ OpenAPIRouteSchema,
4
+ Path,
5
+ } from "@cloudflare/itty-router-openapi";
6
+ import { Task } from "../types";
7
+
8
+ export class TaskDelete extends OpenAPIRoute {
9
+ static schema: OpenAPIRouteSchema = {
10
+ tags: ["Tasks"],
11
+ summary: "Delete a Task",
12
+ parameters: {
13
+ taskSlug: Path(String, {
14
+ description: "Task slug",
15
+ }),
16
+ },
17
+ responses: {
18
+ "200": {
19
+ description: "Returns if the task was deleted successfully",
20
+ schema: {
21
+ success: Boolean,
22
+ result: {
23
+ task: Task,
24
+ },
25
+ },
26
+ },
27
+ },
28
+ };
29
+
30
+ async handle(
31
+ request: Request,
32
+ env: any,
33
+ context: any,
34
+ data: Record<string, any>
35
+ ) {
36
+ // Retrieve the validated slug
37
+ const { taskSlug } = data.params;
38
+
39
+ // Implement your own object deletion here
40
+
41
+ // Return the deleted task for confirmation
42
+ return {
43
+ result: {
44
+ task: {
45
+ name: "Build something awesome with Cloudflare Workers",
46
+ slug: taskSlug,
47
+ description: "Lorem Ipsum",
48
+ completed: true,
49
+ due_date: "2022-12-24",
50
+ },
51
+ },
52
+ success: true,
53
+ };
54
+ }
55
+ }
@@ -0,0 +1,74 @@
1
+ import {
2
+ OpenAPIRoute,
3
+ OpenAPIRouteSchema,
4
+ Path,
5
+ } from "@cloudflare/itty-router-openapi";
6
+ import { Task } from "../types";
7
+
8
+ export class TaskFetch extends OpenAPIRoute {
9
+ static schema: OpenAPIRouteSchema = {
10
+ tags: ["Tasks"],
11
+ summary: "Get a single Task by slug",
12
+ parameters: {
13
+ taskSlug: Path(String, {
14
+ description: "Task slug",
15
+ }),
16
+ },
17
+ responses: {
18
+ "200": {
19
+ description: "Returns a single task if found",
20
+ schema: {
21
+ success: Boolean,
22
+ result: {
23
+ task: Task,
24
+ },
25
+ },
26
+ },
27
+ "404": {
28
+ description: "Task not found",
29
+ schema: {
30
+ success: Boolean,
31
+ error: String,
32
+ },
33
+ },
34
+ },
35
+ };
36
+
37
+ async handle(
38
+ request: Request,
39
+ env: any,
40
+ context: any,
41
+ data: Record<string, any>
42
+ ) {
43
+ // Retrieve the validated slug
44
+ const { taskSlug } = data.params;
45
+
46
+ // Implement your own object fetch here
47
+
48
+ const exists = true;
49
+
50
+ // @ts-ignore: check if the object exists
51
+ if (exists === false) {
52
+ return Response.json(
53
+ {
54
+ success: false,
55
+ error: "Object not found",
56
+ },
57
+ {
58
+ status: 404,
59
+ }
60
+ );
61
+ }
62
+
63
+ return {
64
+ success: true,
65
+ task: {
66
+ name: "my task",
67
+ slug: taskSlug,
68
+ description: "this needs to be done",
69
+ completed: false,
70
+ due_date: new Date().toISOString().slice(0, 10),
71
+ },
72
+ };
73
+ }
74
+ }
@@ -0,0 +1,66 @@
1
+ import { Task } from "../types";
2
+ import {
3
+ OpenAPIRoute,
4
+ OpenAPIRouteSchema,
5
+ Query,
6
+ } from "@cloudflare/itty-router-openapi";
7
+
8
+ export class TaskList extends OpenAPIRoute {
9
+ static schema: OpenAPIRouteSchema = {
10
+ tags: ["Tasks"],
11
+ summary: "List Tasks",
12
+ parameters: {
13
+ page: Query(Number, {
14
+ description: "Page number",
15
+ default: 0,
16
+ }),
17
+ isCompleted: Query(Boolean, {
18
+ description: "Filter by completed flag",
19
+ required: false,
20
+ }),
21
+ },
22
+ responses: {
23
+ "200": {
24
+ description: "Returns a list of tasks",
25
+ schema: {
26
+ success: Boolean,
27
+ result: {
28
+ tasks: [Task],
29
+ },
30
+ },
31
+ },
32
+ },
33
+ };
34
+
35
+ async handle(
36
+ request: Request,
37
+ env: any,
38
+ context: any,
39
+ data: Record<string, any>
40
+ ) {
41
+ // Retrieve the validated parameters
42
+ const { page, isCompleted } = data.query;
43
+
44
+ // Implement your own object list here
45
+
46
+ return {
47
+ success: true,
48
+ tasks: [
49
+ {
50
+ name: "Clean my room",
51
+ slug: "clean-room",
52
+ description: null,
53
+ completed: false,
54
+ due_date: "2025-01-05",
55
+ },
56
+ {
57
+ name: "Build something awesome with Cloudflare Workers",
58
+ slug: "cloudflare-workers",
59
+ description: "Lorem Ipsum",
60
+ completed: true,
61
+ due_date: "2022-12-24",
62
+ },
63
+ ],
64
+ };
65
+ }
66
+ }
@@ -0,0 +1,29 @@
1
+ import { OpenAPIRouter } from "@cloudflare/itty-router-openapi";
2
+ import { TaskList } from "./endpoints/taskList";
3
+ import { TaskCreate } from "./endpoints/taskCreate";
4
+ import { TaskFetch } from "./endpoints/taskFetch";
5
+ import { TaskDelete } from "./endpoints/taskDelete";
6
+
7
+ export const router = OpenAPIRouter({
8
+ docs_url: "/",
9
+ });
10
+
11
+ router.get("/api/tasks/", TaskList);
12
+ router.post("/api/tasks/", TaskCreate);
13
+ router.get("/api/tasks/:taskSlug/", TaskFetch);
14
+ router.delete("/api/tasks/:taskSlug/", TaskDelete);
15
+
16
+ // 404 for everything else
17
+ router.all("*", () =>
18
+ Response.json(
19
+ {
20
+ success: false,
21
+ error: "Route not found",
22
+ },
23
+ { status: 404 }
24
+ )
25
+ );
26
+
27
+ export default {
28
+ fetch: router.handle,
29
+ };
@@ -0,0 +1,9 @@
1
+ import { DateTime, Str } from "@cloudflare/itty-router-openapi";
2
+
3
+ export const Task = {
4
+ name: new Str({ example: "lorem" }),
5
+ slug: String,
6
+ description: new Str({ required: false }),
7
+ completed: Boolean,
8
+ due_date: new DateTime(),
9
+ };
@@ -0,0 +1,32 @@
1
+ {
2
+ "compilerOptions": {
3
+ "allowJs": true,
4
+ "allowSyntheticDefaultImports": true,
5
+ "baseUrl": "src",
6
+ "declaration": true,
7
+ "sourceMap": true,
8
+ "esModuleInterop": true,
9
+ "inlineSourceMap": false,
10
+ "lib": ["esnext"],
11
+ "listEmittedFiles": false,
12
+ "listFiles": false,
13
+ "moduleResolution": "node",
14
+ "noFallthroughCasesInSwitch": true,
15
+ "pretty": true,
16
+ "resolveJsonModule": true,
17
+ "rootDir": ".",
18
+ "skipLibCheck": true,
19
+ "strict": false,
20
+ "traceResolution": false,
21
+ "outDir": "",
22
+ "target": "esnext",
23
+ "module": "esnext",
24
+ "types": [
25
+ "@types/node",
26
+ "@types/service-worker-mock",
27
+ "@cloudflare/workers-types"
28
+ ]
29
+ },
30
+ "exclude": ["node_modules", "dist", "tests"],
31
+ "include": ["src", "scripts"]
32
+ }
@@ -0,0 +1,3 @@
1
+ name = "<TBD>"
2
+ main = "src/index.ts"
3
+ compatibility_date = "<TBD>"
@@ -4,6 +4,7 @@
4
4
  "private": true,
5
5
  "scripts": {
6
6
  "deploy": "wrangler deploy",
7
+ "dev": "wrangler dev",
7
8
  "start": "wrangler dev"
8
9
  },
9
10
  "devDependencies": {
@@ -4,6 +4,7 @@
4
4
  "private": true,
5
5
  "scripts": {
6
6
  "deploy": "wrangler deploy",
7
+ "dev": "wrangler dev",
7
8
  "start": "wrangler dev"
8
9
  },
9
10
  "devDependencies": {
@@ -4,6 +4,7 @@
4
4
  "private": true,
5
5
  "scripts": {
6
6
  "deploy": "wrangler deploy",
7
+ "dev": "wrangler dev",
7
8
  "start": "wrangler dev"
8
9
  },
9
10
  "devDependencies": {
@@ -1,5 +1,5 @@
1
1
  name = "<TBD>"
2
- main = "src/index.ts"
2
+ main = "src/index.js"
3
3
  compatibility_date = "<TBD>"
4
4
 
5
5
  # Cron Triggers
@@ -4,6 +4,7 @@
4
4
  "private": true,
5
5
  "scripts": {
6
6
  "deploy": "wrangler deploy",
7
+ "dev": "wrangler dev",
7
8
  "start": "wrangler dev"
8
9
  },
9
10
  "devDependencies": {