create-cloudflare 0.0.4 → 0.0.5
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/package.json +1 -1
package/bin.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
const
|
|
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: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
|
|
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/package.json
CHANGED