create-cloudflare 0.0.1 → 0.0.2
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 +26 -17
- package/index.js +1 -1
- package/package.json +3 -2
package/bin.js
CHANGED
|
@@ -25,23 +25,32 @@ if (argv.help) {
|
|
|
25
25
|
let output = '';
|
|
26
26
|
|
|
27
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]';
|
|
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]';
|
|
31
41
|
output += '\n';
|
|
32
42
|
output += '\n Options';
|
|
33
|
-
output += '\n
|
|
34
|
-
output += '\n
|
|
35
|
-
output += '\n
|
|
36
|
-
output += '\n -v
|
|
37
|
-
output += '\n -h
|
|
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';
|
|
38
48
|
output += '\n';
|
|
39
49
|
output += '\n Examples';
|
|
40
|
-
output += '\n $ npm init cloudflare my-project';
|
|
41
|
-
output += '\n $
|
|
42
|
-
output += '\n $
|
|
43
|
-
output += '\n $ npm init cloudflare my-project
|
|
44
|
-
output += '\n $ npm init cloudflare my-project -- https://github.com/user/repo.git#branch';
|
|
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';
|
|
45
54
|
output += '\n';
|
|
46
55
|
|
|
47
56
|
exit(output, 0);
|
|
@@ -54,10 +63,10 @@ if (argv.version) {
|
|
|
54
63
|
|
|
55
64
|
(async function () {
|
|
56
65
|
try {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
if (!
|
|
60
|
-
await require('.').setup(dir, argv);
|
|
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);
|
|
61
70
|
} catch (err) {
|
|
62
71
|
exit(err && err.stack || err, 1);
|
|
63
72
|
}
|
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const
|
|
1
|
+
const t = require('semiver');const e = require('fs');const { tmpdir:r } = require('os');const { promisify:i } = require('util');const { join:s, relative:o } = require('path');const { exec:a } = require('child_process');var n=i(a),c=e.existsSync;async function f(t){c(t)&&e.promises.rm(t,{recursive:!0})}var p=(...t)=>n(`git ${t.join(" ")}`),l=()=>Math.random().toString(16).substring(2);async function u(i,a,u){let w=process.cwd(),h=s(w,i);if(c(h)){if(!u.force){let t=`Refusing to overwrite existing "${o(w,h)}" directory.\n`;throw t+="Please specify a different directory or use the `--force` flag.",new Error(t)}if(!h.startsWith(w))throw new Error("Refusing to manipulate the file system outside the PWD location.\nPlease specify a different target directory.");await f(h)}let m="",g="";if(/^(https?|ftps?|file|git|ssh):\/\//.test(a)||a.includes(":")?m=a:(m="https://github.com/cloudflare/worker-examples.git",g=a),g){try{var{stdout:d}=await p("version")}catch{throw new Error("Missing `git` executable")}let[e]=/\d+.\d+.\d+/.exec(d)||[];if(!e)throw new Error("Unknown `git` version");if(t(e,"2.19.0")<0)throw new Error("Requires git version 2.19.0 or newer")}try{await async function(t,i,o){let a=["clone --depth 1"],c=i;o&&(a.push("--filter=blob:none --sparse"),c=s(r(),l()+"-"+l()));let u=t.lastIndexOf("#");-1===u?(t.includes("worker-examples")&&a.push("-b dev"),a.push(t)):(a.push(`-b ${t.substring(u+1)}`),a.push(t.substring(0,u))),a.push(c),await p(...a),o&&(await n(`git sparse-checkout set "${o}"`,{cwd:c}),await e.promises.rename(s(c,o),i),await f(c))}(m,h,g)}catch(t){throw u.debug&&console.error(t.toString()),new Error(`Error cloning "${m}" repository`)}await async function(t,e){await f(s(t,".git")),e&&await p("init -b main",t)}(h,!!u.init),console.log("Done~!")}exports.setup=u;
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.0.
|
|
2
|
+
"version": "0.0.2",
|
|
3
3
|
"name": "create-cloudflare",
|
|
4
4
|
"repository": "lukeed/create-cloudflare",
|
|
5
5
|
"description": "TODO",
|
|
@@ -24,7 +24,8 @@
|
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"kleur": "^4.0.0",
|
|
27
|
-
"mri": "^1.2.0"
|
|
27
|
+
"mri": "^1.2.0",
|
|
28
|
+
"semiver": "^1.1.0"
|
|
28
29
|
},
|
|
29
30
|
"devDependencies": {
|
|
30
31
|
"@types/node": "17.0.29",
|