create-cloudflare 0.0.0 → 0.0.3
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 -68
- package/index.d.ts +7 -0
- package/index.js +1 -0
- package/package.json +16 -3
package/bin.js
CHANGED
|
@@ -1,69 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
const
|
|
3
|
-
alias: {
|
|
4
|
-
C: 'cwd',
|
|
5
|
-
e: 'env',
|
|
6
|
-
f: 'format',
|
|
7
|
-
t: 'typescript',
|
|
8
|
-
// m: 'monorepo',
|
|
9
|
-
v: 'version',
|
|
10
|
-
h: 'help',
|
|
11
|
-
// c: 'cfw',
|
|
12
|
-
},
|
|
13
|
-
default: {
|
|
14
|
-
C: '.',
|
|
15
|
-
force: false,
|
|
16
|
-
e: 'cloudflare',
|
|
17
|
-
f: '', // ~> env-default
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
/** @param {string} msg */
|
|
22
|
-
function exit(msg, code = 1) {
|
|
23
|
-
if (code) process.stderr.write(msg + '\n');
|
|
24
|
-
else process.stdout.write(msg + '\n');
|
|
25
|
-
process.exit(code);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
if (argv.help) {
|
|
29
|
-
let output = '';
|
|
30
|
-
|
|
31
|
-
output += '\n Usage';
|
|
32
|
-
output += '\n npm init worktop <name> [options]';
|
|
33
|
-
output += '\n';
|
|
34
|
-
output += '\n Options';
|
|
35
|
-
output += '\n -C, --cwd Directory to resolve from';
|
|
36
|
-
output += '\n -t, --typescript Setup project for TypeScript usage';
|
|
37
|
-
output += '\n -e, --env Target platform environment (default "cloudflare")';
|
|
38
|
-
output += '\n -f, --format Worker/Script output format (default "module")';
|
|
39
|
-
// output += '\n -m, --monorepo Force directory overwrite';
|
|
40
|
-
// output += '\n -c, --cfw Force directory overwrite';
|
|
41
|
-
output += '\n --force Force overwrite target directory';
|
|
42
|
-
output += '\n -v, --version Displays current version';
|
|
43
|
-
output += '\n -h, --help Displays this message';
|
|
44
|
-
output += '\n';
|
|
45
|
-
output += '\n Examples';
|
|
46
|
-
output += '\n $ npm init worktop my-worker';
|
|
47
|
-
output += '\n $ yarn create worktop my-worker --force';
|
|
48
|
-
output += '\n $ npm init worktop my-worker --env cloudflare';
|
|
49
|
-
output += '\n $ npm init worktop my-worker --env cloudflare';
|
|
50
|
-
output += '\n $ npm init worktop my-worker --env deno';
|
|
51
|
-
output += '\n';
|
|
52
|
-
|
|
53
|
-
exit(output, 0);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if (argv.version) {
|
|
57
|
-
let pkg = require('./package.json');
|
|
58
|
-
return exit(`${pkg.name}, v${pkg.version}`, 0);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
(async function () {
|
|
62
|
-
try {
|
|
63
|
-
let dir = argv._.join('-').trim().replace(/[\s_]+/g, '-');
|
|
64
|
-
if (!dir) return exit('Missing <name> argument', 1);
|
|
65
|
-
await require('.').setup(dir, argv);
|
|
66
|
-
} catch (err) {
|
|
67
|
-
exit(err && err.stack || err, 1);
|
|
68
|
-
}
|
|
69
|
-
})();
|
|
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?process.stderr.write(e+"\n"):process.stdout.write(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/worker-examples/tree/dev 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.d.ts
ADDED
package/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const t = require('fs');const { tmpdir:r } = require('os');const { promisify:e } = require('util');const { join:i, relative:s } = require('path');const { exec:o } = require('child_process');const n = require('semiver');var a=e(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(e,o,h){let m=process.cwd();p(e)&&([e,o]=[o,e]);let g=i(m,e);if(c(g)){if(!h.force){let t=`Refusing to overwrite existing "${s(m,g)}" directory.\n`;throw t+="Please specify a different directory or use the `--force` flag.",t}g.startsWith(m)&&await u(g)}let d="",w="";p(o)?d=o:(d="https://github.com/cloudflare/worker-examples.git",w=o),await async function(e,s,o){let c=["clone --depth 1"],{source:p,filter:h}=e,m=s,g=!1;function d(t,r){if(o.debug&&r&&r instanceof Error){let e=r.stack||r.message;t+="\n"+(e.includes("\n")?e.replace(/(\r?\n)/g,"$1 "):e)}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&&(g=-1!==n(y,"2.26.0"),m=i(r(),l()+"-"+l()),g&&c.push("--filter=blob:none --sparse"));let b=p.lastIndexOf("#");-1===b?(p.includes("worker-examples")&&c.push("-b dev"),c.push(p)):(c.push(`-b ${p.substring(b+1)}`),c.push(p.substring(0,b)));try{c.push(m),await f(...c)}catch(t){return d(`Error cloning "${p}" repository`,t)}if(h){if(g)try{await a(`git sparse-checkout set "${h}"`,{cwd:m})}catch(t){return d(`Error with "${h}" checkout`,t)}await t.promises.rename(i(m,h),s),await u(m)}if(await u(i(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},g,h),console.log("Done~!")}exports.setup=h;
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.0.
|
|
2
|
+
"version": "0.0.3",
|
|
3
3
|
"name": "create-cloudflare",
|
|
4
4
|
"repository": "lukeed/create-cloudflare",
|
|
5
5
|
"description": "TODO",
|
|
6
|
+
"types": "index.d.ts",
|
|
6
7
|
"license": "MIT",
|
|
7
8
|
"bin": "bin.js",
|
|
8
9
|
"author": {
|
|
@@ -12,13 +13,25 @@
|
|
|
12
13
|
},
|
|
13
14
|
"exports": "./index.js",
|
|
14
15
|
"files": [
|
|
15
|
-
"bin.js"
|
|
16
|
+
"bin.js",
|
|
17
|
+
"index.js",
|
|
18
|
+
"index.d.ts"
|
|
16
19
|
],
|
|
17
20
|
"engines": {
|
|
18
21
|
"node": ">=12"
|
|
19
22
|
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "bundt -m",
|
|
25
|
+
"types": "tsc"
|
|
26
|
+
},
|
|
20
27
|
"dependencies": {
|
|
21
28
|
"kleur": "^4.0.0",
|
|
22
|
-
"mri": "^1.2.0"
|
|
29
|
+
"mri": "^1.2.0",
|
|
30
|
+
"semiver": "^1.1.0"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@types/node": "17.0.31",
|
|
34
|
+
"bundt": "2.0.0-next.5",
|
|
35
|
+
"typescript": "4.6.4"
|
|
23
36
|
}
|
|
24
37
|
}
|