create-cloudflare 0.0.2 → 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 -72
- package/index.d.ts +7 -0
- package/index.js +1 -1
- package/package.json +7 -5
package/bin.js
CHANGED
|
@@ -1,73 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
const
|
|
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> <source> -- [options]';
|
|
29
|
-
output += '\n pnpm create cloudflare <directory> <source> [options]';
|
|
30
|
-
output += '\n yarn create cloudflare <directory> <source> [options]';
|
|
31
|
-
output += '\n';
|
|
32
|
-
output += '\n Sources';
|
|
33
|
-
output += '\n • Example — A name or path to an official example subdirectory.';
|
|
34
|
-
output += '\n Visit https://github.com/cloudflare/worker-examples/tree/dev for options'; // TODO: update; get nice-name redirect
|
|
35
|
-
output += '\n • URL — Any valid git repository address.';
|
|
36
|
-
output += '\n [user@]host.xz:path/to/repo.git[#branch]';
|
|
37
|
-
output += '\n git://host.xz[:port]/path/to/repo.git[#branch]';
|
|
38
|
-
output += '\n ssh://[user@]host.xz[:port]/path/to/repo.git[#branch]';
|
|
39
|
-
output += '\n http[s]://host.xz[:port]/path/to/repo.git[#branch]';
|
|
40
|
-
output += '\n ftp[s]://host.xz[:port]/path/to/repo.git[#branch]';
|
|
41
|
-
output += '\n';
|
|
42
|
-
output += '\n Options';
|
|
43
|
-
output += '\n --force Force overwrite target directory';
|
|
44
|
-
output += '\n --no-init Do not initialize a git repository';
|
|
45
|
-
output += '\n --debug Print additional error details';
|
|
46
|
-
output += '\n --version, -v Displays current version';
|
|
47
|
-
output += '\n --help, -h Displays this message';
|
|
48
|
-
output += '\n';
|
|
49
|
-
output += '\n Examples';
|
|
50
|
-
output += '\n $ npm init cloudflare my-project pages/svelte-kit -- --debug';
|
|
51
|
-
output += '\n $ yarn create cloudflare my-project workshops/intro-workers --force';
|
|
52
|
-
output += '\n $ pnpm create cloudflare my-project https://github.com/user/repo.git#branch';
|
|
53
|
-
output += '\n $ npm init cloudflare my-project https://github.com/user/repo.git';
|
|
54
|
-
output += '\n';
|
|
55
|
-
|
|
56
|
-
exit(output, 0);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (argv.version) {
|
|
60
|
-
let pkg = require('./package.json');
|
|
61
|
-
exit(`${pkg.name}, v${pkg.version}`, 0);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
(async function () {
|
|
65
|
-
try {
|
|
66
|
-
let [dir, source] = argv._;
|
|
67
|
-
if (!dir) return exit('Missing <directory> argument', 1);
|
|
68
|
-
if (!source) return exit('Missing <source> argument', 1);
|
|
69
|
-
await require('.').setup(dir, source, argv);
|
|
70
|
-
} catch (err) {
|
|
71
|
-
exit(err && err.stack || err, 1);
|
|
72
|
-
}
|
|
73
|
-
})();
|
|
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
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const t = require('
|
|
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": {
|
|
@@ -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"
|
|
@@ -28,8 +30,8 @@
|
|
|
28
30
|
"semiver": "^1.1.0"
|
|
29
31
|
},
|
|
30
32
|
"devDependencies": {
|
|
31
|
-
"@types/node": "17.0.
|
|
32
|
-
"bundt": "2.0.0-next.
|
|
33
|
-
"typescript": "4.6.
|
|
33
|
+
"@types/node": "17.0.31",
|
|
34
|
+
"bundt": "2.0.0-next.5",
|
|
35
|
+
"typescript": "4.6.4"
|
|
34
36
|
}
|
|
35
37
|
}
|