create-cloudflare 0.0.1 → 0.0.4

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/bin.js CHANGED
@@ -1,64 +1,2 @@
1
1
  #!/usr/bin/env node
2
- const argv = require('mri')(process.argv.slice(2), {
3
- alias: {
4
- v: 'version',
5
- h: 'help',
6
- },
7
- default: {
8
- init: true,
9
- force: false,
10
- debug: false
11
- }
12
- });
13
-
14
- /**
15
- * @param {string} msg
16
- * @returns {never}
17
- */
18
- function exit(msg, code = 1) {
19
- if (code) process.stderr.write(msg + '\n');
20
- else process.stdout.write(msg + '\n');
21
- process.exit(code);
22
- }
23
-
24
- if (argv.help) {
25
- let output = '';
26
-
27
- output += '\n Usage';
28
- output += '\n npm init cloudflare <directory> -- [options]';
29
- output += '\n pnpm create cloudflare <directory> [options]';
30
- output += '\n yarn create cloudflare <directory> [options]';
31
- output += '\n';
32
- output += '\n Options';
33
- output += '\n --force Force overwrite target directory';
34
- output += '\n --no-init Do not initialize a git repository';
35
- output += '\n --debug Print additional error details';
36
- output += '\n -v, --version Displays current version';
37
- output += '\n -h, --help Displays this message';
38
- output += '\n';
39
- output += '\n Examples';
40
- output += '\n $ npm init cloudflare my-project';
41
- output += '\n $ npm init cloudflare my-project -- --no-init';
42
- output += '\n $ npm init cloudflare my-project -- pages svelte-kit';
43
- output += '\n $ npm init cloudflare my-project -- https://github.com/user/repo.git';
44
- output += '\n $ npm init cloudflare my-project -- https://github.com/user/repo.git#branch';
45
- output += '\n';
46
-
47
- exit(output, 0);
48
- }
49
-
50
- if (argv.version) {
51
- let pkg = require('./package.json');
52
- exit(`${pkg.name}, v${pkg.version}`, 0);
53
- }
54
-
55
- (async function () {
56
- try {
57
- console.log(argv);
58
- let dir = argv._.join('-').trim().replace(/[\s_]+/g, '-');
59
- if (!dir) return exit('Missing <name> argument', 1);
60
- await require('.').setup(dir, argv);
61
- } catch (err) {
62
- exit(err && err.stack || err, 1);
63
- }
64
- })();
2
+ const r=require("mri")(process.argv.slice(2),{alias:{v:"version",h:"help"},default:{init:!0,force:!1,debug:!1}});function e(r,e=1){e?process.stderr.write(r+"\n"):process.stdout.write(r+"\n"),process.exit(e)}if(r.help){let r="";r+="\n Usage",r+="\n npm init cloudflare <directory> <source> -- [options]",r+="\n pnpm create cloudflare <directory> <source> [options]",r+="\n yarn create cloudflare <directory> <source> [options]",r+="\n",r+="\n Sources",r+="\n • Example — A name or path to an official example subdirectory.",r+="\n Visit https://github.com/cloudflare/templates for options",r+="\n • URL — Any valid git repository address.",r+="\n [user@]host.xz:path/to/repo.git[#branch]",r+="\n git://host.xz[:port]/path/to/repo.git[#branch]",r+="\n ssh://[user@]host.xz[:port]/path/to/repo.git[#branch]",r+="\n http[s]://host.xz[:port]/path/to/repo.git[#branch]",r+="\n ftp[s]://host.xz[:port]/path/to/repo.git[#branch]",r+="\n",r+="\n Options",r+="\n --force Force overwrite target directory",r+="\n --no-init Do not initialize a git repository",r+="\n --debug Print additional error details",r+="\n --version, -v Displays current version",r+="\n --help, -h Displays this message",r+="\n",r+="\n Examples",r+="\n $ npm init cloudflare my-project pages/svelte-kit -- --debug",r+="\n $ yarn create cloudflare my-project workshops/intro-workers --force",r+="\n $ pnpm create cloudflare my-project https://github.com/user/repo.git#branch",r+="\n $ npm init cloudflare my-project https://github.com/user/repo.git",r+="\n",e(r,0)}if(r.version){let r=require("./package.json");e(`${r.name}, v${r.version}`,0)}!async function(){try{let[t,o]=r._;if(!t)return e("Missing <directory> argument",1);if(!o)return e("Missing <source> argument",1);await require(".").setup(t,o,r)}catch(r){e(r instanceof Error?r.stack||r.message:r,1)}}();
package/index.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ export interface Argv {
2
+ init?: boolean;
3
+ force?: boolean;
4
+ debug?: boolean;
5
+ }
6
+
7
+ export function setup(dest: string, source: string, argv: Argv): Promise<void>;
package/index.js CHANGED
@@ -1 +1 @@
1
- const e = require('path');const r = require('fs');const { join:t } = require('path');const { promisify:s } = require('util');const { exec:o } = require('child_process');s(o);var i=r.existsSync;function f(e){return r.promises.rm(e,{recursive:!0})}async function a(r,t){let s=process.cwd(),o=e.join(s,r);if(console.log({target:o}),i(o)){if(!t.force){let r=`Refusing to overwrite existing "${e.relative(s,o)}" directory.\n`;throw r+="Please specify a different directory or use the `--force` flag.",new Error(r)}if(!o.startsWith(s))throw new Error("Refusing to manipulate the file system outside the PWD location.\nPlease specify a different target directory.");await f(o)}let a=!1,[l,n]=t._||[];if(console.log({source:l,filter:n}),!l)throw new Error("Missing source value(s).\nPlease view the `--help` text.");if(/^(https?|ftps?|file|git|ssh):\/\//.test(l))a=!0;else if(!n&&l.includes(":"))a=!0;else{if(l=l.toLowerCase(),!n)throw new Error("Missing filter");if(/^workers?/.test(l))n="workers/"+n;else{if("pages"!==l)throw new Error(`Invalid "${l}" source.`);n="pages/"+n}l="https://github.com/cloudflare/worker-examples.git"}return console.log({target:o,source:l,filter:n})}exports.setup=a;
1
+ const t = require('fs');const { tmpdir:r } = require('os');const { promisify:i } = require('util');const { join:e, relative:s } = require('path');const { exec:o } = require('child_process');const n = require('semiver');var a=i(o),c=t.existsSync;async function f(r){c(r)&&t.promises.rm(r,{recursive:!0})}var u=(...t)=>a(`git ${t.join(" ")}`),l=()=>Math.random().toString(16).substring(2),p=t=>/^(https?|ftps?|file|git|ssh):\/\//.test(t)||t.includes(":");async function h(i,o,h){let g=process.cwd();p(i)&&([i,o]=[o,i]);let m=e(g,i);if(c(m)){if(!h.force){let t=`Refusing to overwrite existing "${s(g,m)}" directory.\n`;throw t+="Please specify a different directory or use the `--force` flag.",t}m.startsWith(g)&&await f(m)}let d="",w="";p(o)?d=o:(d="https://github.com/cloudflare/templates.git",w=o),await async function(i,s,o){let c=["clone --depth 1"],{source:p,filter:h}=i,g=s,m=!1;function d(t,r){if(o.debug&&r&&r instanceof Error){let i=r.stack||r.message;t+="\n"+(i.includes("\n")?i.replace(/(\r?\n)/g,"$1 "):i)}throw t}try{var{stdout:w}=await u("version")}catch(t){return d("Missing `git` executable",t)}let[y]=/\d+.\d+.\d+/.exec(w)||[];if(!y)throw"Unknown `git` version";h&&(m=-1!==n(y,"2.26.0"),g=e(r(),l()+"-"+l()),m&&c.push("--filter=blob:none --sparse"));let b=p.lastIndexOf("#");-1===b?c.push(p):(c.push(`-b ${p.substring(b+1)}`),c.push(p.substring(0,b)));try{c.push(g),await u(...c)}catch(t){return d(`Error cloning "${p}" repository`,t)}if(h){if(m)try{await a(`git sparse-checkout set "${h}"`,{cwd:g})}catch(t){return d(`Error with "${h}" checkout`,t)}await t.promises.rename(e(g,h),s),await f(g)}if(await f(e(s,".git")),o.init){c=["init"],b=n(y,"2.26.0"),-1!==b&&c.push("-b main");try{await u(...c,s)}catch(t){return d("Error initializing repository",t)}}}({source:d,filter:w},m,h),console.log("Done~!")}exports.setup=h;
package/license ADDED
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) Luke Edwards <luke.edwards05@gmail.com> (lukeed.com)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
- "version": "0.0.1",
2
+ "version": "0.0.4",
3
3
  "name": "create-cloudflare",
4
4
  "repository": "lukeed/create-cloudflare",
5
- "description": "TODO",
5
+ "description": "Create new Cloudflare projects with one command",
6
+ "types": "index.d.ts",
6
7
  "license": "MIT",
7
8
  "bin": "bin.js",
8
9
  "author": {
@@ -13,7 +14,8 @@
13
14
  "exports": "./index.js",
14
15
  "files": [
15
16
  "bin.js",
16
- "index.js"
17
+ "index.js",
18
+ "index.d.ts"
17
19
  ],
18
20
  "engines": {
19
21
  "node": ">=12"
@@ -24,11 +26,12 @@
24
26
  },
25
27
  "dependencies": {
26
28
  "kleur": "^4.0.0",
27
- "mri": "^1.2.0"
29
+ "mri": "^1.2.0",
30
+ "semiver": "^1.1.0"
28
31
  },
29
32
  "devDependencies": {
30
- "@types/node": "17.0.29",
31
- "bundt": "2.0.0-next.2",
32
- "typescript": "4.6.3"
33
+ "@types/node": "17.0.31",
34
+ "bundt": "2.0.0-next.5",
35
+ "typescript": "4.6.4"
33
36
  }
34
37
  }
package/readme.md ADDED
@@ -0,0 +1,72 @@
1
+ # create-cloudflare [![CI](https://github.com/lukeed/create-cloudflare/workflows/CI/badge.svg)](https://github.com/lukeed/clsx/actions?query=workflow%3ACI)
2
+
3
+ > Create new Cloudflare projects with one command
4
+
5
+ ## Usage
6
+
7
+ You may use `yarn`, `pnpm`, or `npm` to invoke the [`create-cloudflare`](https://www.npmjs.com/package/create-cloudflare) package:
8
+
9
+
10
+ ```
11
+ $ npm init cloudflare <directory> <source> -- [options]
12
+ # or
13
+ $ pnpm create cloudflare <directory> <source> [options]
14
+ # or
15
+ $ yarn create cloudflare <directory> <source> [options]
16
+ ```
17
+
18
+ > **Note:** All recent versions of `npm`, `yarn`, and `pnpm` support this feature!
19
+
20
+
21
+ ### Sources
22
+
23
+ You may select the name of any subdirectory within the [`cloudflare/templates`](https://github.com/cloudflare/templates) repository to create your project; for example, `worker-typescript` and `examples/fast-google-fonts` are both valid subdirectory names.
24
+
25
+ You may also use any valid git repository address; for example:
26
+
27
+ > **Note:** Optional segments are denoted within `[]` characters.
28
+
29
+ - `[user@]host.xz:path/to/repo.git[#branch]`
30
+ - `git://host.xz[:port]/path/to/repo.git[#branch]`
31
+ - `ssh://[user@]host.xz[:port]/path/to/repo.git[#branch]`
32
+ - `http[s]://host.xz[:port]/path/to/repo.git[#branch]`
33
+ - `ftp[s]://host.xz[:port]/path/to/repo.git[#branch]`
34
+
35
+
36
+ ### Examples
37
+
38
+ To create a `my-project` directory using the [`worker-typescript`](https://github.com/cloudflare/templates/tree/main/worker-typescript) template, you may run one of the following commands:
39
+
40
+ ```sh
41
+ $ npm init cloudflare my-project worker-typescript
42
+ # or
43
+ $ yarn create cloudflare my-project worker-typescript
44
+ # or
45
+ $ pnpm create cloudflare my-project worker-typescript
46
+ ```
47
+
48
+ Other examples include:
49
+
50
+ ```sh
51
+ $ yarn create cloudflare my-project worker --force
52
+ $ npm init cloudflare my-project worker-router -- --debug
53
+ $ pnpm create cloudflare my-project https://github.com/user/repo.git#branch
54
+ ```
55
+
56
+
57
+ ### Options
58
+
59
+ * `--force` — Allow target directory overwrite
60
+ * `--no-init` — Do not initialize a git repository
61
+ * `--debug` — Print additional error details
62
+ * `--version` or `-v` — Displays current version
63
+ * `--help` or `-h — Displays help text
64
+
65
+ ## Related
66
+
67
+ - [`cloudflare/templates`](https://github.com/cloudflare/templates) - A collection of stater templates and examples for Cloudflare Workers and Pages
68
+
69
+
70
+ ## License
71
+
72
+ MIT © [Luke Edwards](https://lukeed.com)