create-cloudflare 0.0.3 → 1.0.0
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 +1 -1
- package/index.js +1 -1
- package/license +9 -0
- package/package.json +2 -2
- package/readme.md +72 -0
package/bin.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
const e=require("mri")(process.argv.slice(2),{alias:{v:"version",h:"help"},default:{init:!0,force:!1,debug:!1}});function r(e,r=1){r?
|
|
2
|
+
const e=require("mri")(process.argv.slice(2),{alias:{v:"version",h:"help"},default:{init:!0,force:!1,debug:!1}});function r(e,r=1){r?console.error("\n"+e+"\n"):console.log("\n"+e+"\n"),process.exit(r)}if(e.help){let e="";e+="\n Usage",e+="\n npm init cloudflare <directory> <source> -- [options]",e+="\n pnpm create cloudflare <directory> <source> [options]",e+="\n yarn create cloudflare <directory> <source> [options]",e+="\n",e+="\n Sources",e+="\n • Example — A name or path to an official example subdirectory.",e+="\n Visit https://github.com/cloudflare/templates for options",e+="\n • URL — Any valid git repository address.",e+="\n [user@]host.xz:path/to/repo.git[#branch]",e+="\n git://host.xz[:port]/path/to/repo.git[#branch]",e+="\n ssh://[user@]host.xz[:port]/path/to/repo.git[#branch]",e+="\n http[s]://host.xz[:port]/path/to/repo.git[#branch]",e+="\n ftp[s]://host.xz[:port]/path/to/repo.git[#branch]",e+="\n",e+="\n Options",e+="\n --force Force overwrite target directory",e+="\n --no-init Do not initialize a git repository",e+="\n --debug Print additional error details",e+="\n --version, -v Displays current version",e+="\n --help, -h Displays this message",e+="\n",e+="\n Examples",e+="\n $ npm init cloudflare my-project pages/svelte-kit -- --debug",e+="\n $ yarn create cloudflare my-project workshops/intro-workers --force",e+="\n $ pnpm create cloudflare my-project https://github.com/user/repo.git#branch",e+="\n $ npm init cloudflare my-project https://github.com/user/repo.git",e+="\n",r(e,0)}if(e.version){let e=require("./package.json");r(`${e.name}, v${e.version}`,0)}!async function(){try{let[t,o]=e._;if(!t)return r("Missing <directory> argument",1);if(!o)return r("Missing <source> argument",1);await require(".").setup(t,o,e)}catch(e){r(e instanceof Error?e.stack||e.message:e,1)}}();
|
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const t = require('fs');const { tmpdir:r } = require('os');const { promisify:
|
|
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 u(r){c(r)&&t.promises.rm(r,{recursive:!0})}var f=(...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 u(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 f("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 f(...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 u(g)}if(await u(e(s,".git")),o.init){c=["init"],b=n(y,"2.26.0"),-1!==b&&c.push("-b main");try{await f(...c,s)}catch(t){return d("Error initializing repository",t)}}}({source:d,filter:w},m,h),m=s(g,m),console.log(`\n Success 🎉\n Your "${m}" directory is ready for you~!\n`)}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,8 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.0
|
|
2
|
+
"version": "1.0.0",
|
|
3
3
|
"name": "create-cloudflare",
|
|
4
4
|
"repository": "lukeed/create-cloudflare",
|
|
5
|
-
"description": "
|
|
5
|
+
"description": "Create new Cloudflare projects with one command",
|
|
6
6
|
"types": "index.d.ts",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"bin": "bin.js",
|
package/readme.md
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# create-cloudflare [](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)
|