create-done-coding 0.2.11 → 0.2.12-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/dist/index.js CHANGED
@@ -1,6 +1,34 @@
1
- "use strict";var S=Object.create;var m=Object.defineProperty;var $=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames;var b=Object.getPrototypeOf,k=Object.prototype.hasOwnProperty;var C=(e,n,i,s)=>{if(n&&typeof n=="object"||typeof n=="function")for(let t of h(n))!k.call(e,t)&&t!==i&&m(e,t,{get:()=>n[t],enumerable:!(s=$(n,t))||s.enumerable});return e};var u=(e,n,i)=>(i=e!=null?S(b(e)):{},C(n||!e||!e.__esModule?m(i,"default",{value:e,enumerable:!0}):i,e));const a=require("prompts"),g=require("node:child_process"),o=require("node:fs"),p=require("node:path"),d="template-node-cli",f="CUSTOM",E=[{title:"typescript",value:"template-ts"},{title:"node-cli",value:d},{title:"web-mobile-vue3",value:"template-web-m-vue3"},{title:"web-mobile-react",value:"template-web-m-react"},{title:"uni-vue3",value:"template-uni-m-vue3"},{title:"monorepo",value:"template-monorepo"},{title:"自定义模板路径",value:f}],x=process.cwd();async function R(){const e=p.resolve(__dirname,"../package.json"),n=o.readFileSync(e,"utf-8"),{version:i}=JSON.parse(n),s=(await import("chalk")).default;return console.log(s.green(`v${i}`)),await a([{type:"text",name:"projectName",message:"Project name:"},{type:"select",name:"template",message:"请选择模板",choices:E},{type:"confirm",name:"saveGitHistory",message:"保留git历史"}])}R().then(async({projectName:e,template:n,saveGitHistory:i})=>{const s=(await import("chalk")).default;if(!e.trim()){console.log(s.red("项目名称不能为空"));return}if(e.includes(" ")||e.includes("\\")||e.includes("/")){console.log(s.red("项目名称不能包含空格或者\\或者/"));return}const t=p.resolve(x,e);if(o.existsSync(t)){const{isRemove:c}=await a({type:"confirm",name:"isRemove",message:"项目已存在,是否删除"});if(c===!0)o.rmSync(t,{recursive:!0,force:!0});else throw new Error("项目已存在")}let l="";if(n===f){const{customUrl:c}=await a({type:"text",name:"customUrl",message:"请输入自定义模板路径"});l=c}else l=`https://gitee.com/justsosu/${n}`;if(console.log(s.green("正在初始化项目,请稍等...")),g.execSync(`git clone ${l} ${e}`),i===!1){const c=`${t}/.git`;if(!o.existsSync(c))throw new Error("git目录不存在");o.rmSync(`${t}/.git`,{recursive:!0,force:!0})}else g.execSync(`cd ${t} && git remote rename origin upstream`);const y=o.readFileSync(`${t}/package.json`,"utf-8"),r=JSON.parse(y),{name:v}=r;if(r.name=e,o.rmSync(`${t}/package.json`),n===d){const c=r.bin;r.bin={[e]:Object.values(c)[0]}}o.writeFileSync(`${t}/package.json`,JSON.stringify(r,null,2));const w=o.readFileSync(`${t}/README.md`,"utf-8").replace(v,e);o.rmSync(`${t}/README.md`),o.writeFileSync(`${t}/README.md`,w),console.log(s.green("项目初始化完成")),console.log(s.blue(`
2
- 使用步骤:
3
- 1. cd ${e}
4
- 2. pnpm install
5
- 3. pnpm run dev
6
- `))});
1
+ "use strict";var Ge=Object.create;var Ee=Object.defineProperty;var Ve=Object.getOwnPropertyDescriptor;var He=Object.getOwnPropertyNames;var Ke=Object.getPrototypeOf,Ze=Object.prototype.hasOwnProperty;var Xe=(i,t,r,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let c of He(t))!Ze.call(i,c)&&c!==r&&Ee(i,c,{get:()=>t[c],enumerable:!(a=Ve(t,c))||a.enumerable});return i};var oe=(i,t,r)=>(r=i!=null?Ge(Ke(i)):{},Xe(t||!i||!i.__esModule?Ee(r,"default",{value:i,enumerable:!0}):r,i));const ke=require("yargs"),de=require("util"),S=require("path"),I=require("fs"),we=require("assert"),et=require("url"),x=require("node:fs"),q=require("node:path"),Oe=require("chalk"),tt=require("node:url"),ee=require("prompts"),ue=require("node:child_process");var te=typeof document<"u"?document.currentScript:null;class M extends Error{constructor(t){super(t||"yargs error"),this.name="YError",Error.captureStackTrace&&Error.captureStackTrace(this,M)}}function $e(){return nt()?0:1}function nt(){return st()&&!process.defaultApp}function st(){return!!process.versions.electron}function it(i){return i.slice($e()+1)}function rt(){return process.argv[$e()]}/**
2
+ * @license
3
+ * Copyright (c) 2016, Contributors
4
+ * SPDX-License-Identifier: ISC
5
+ */function z(i){if(i!==i.toLowerCase()&&i!==i.toUpperCase()||(i=i.toLowerCase()),i.indexOf("-")===-1&&i.indexOf("_")===-1)return i;{let r="",a=!1;const c=i.match(/^-+/);for(let u=c?c[0].length:0;u<i.length;u++){let p=i.charAt(u);a&&(a=!1,p=p.toUpperCase()),u!==0&&(p==="-"||p==="_")?a=!0:p!=="-"&&p!=="_"&&(r+=p)}return r}}function Fe(i,t){const r=i.toLowerCase();t=t||"-";let a="";for(let c=0;c<i.length;c++){const u=r.charAt(c),p=i.charAt(c);u!==p&&c>0?a+=`${t}${r.charAt(c)}`:a+=p}return a}function Ce(i){return i==null?!1:typeof i=="number"||/^0x[0-9a-f]+$/i.test(i)?!0:/^0[^.]/.test(i)?!1:/^[-]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(i)}/**
6
+ * @license
7
+ * Copyright (c) 2016, Contributors
8
+ * SPDX-License-Identifier: ISC
9
+ */function ot(i){if(Array.isArray(i))return i.map(p=>typeof p!="string"?p+"":p);i=i.trim();let t=0,r=null,a=null,c=null;const u=[];for(let p=0;p<i.length;p++){if(r=a,a=i.charAt(p),a===" "&&!c){r!==" "&&t++;continue}a===c?c=null:(a==="'"||a==='"')&&!c&&(c=a),u[t]||(u[t]=""),u[t]+=a}return u}/**
10
+ * @license
11
+ * Copyright (c) 2016, Contributors
12
+ * SPDX-License-Identifier: ISC
13
+ */var R;(function(i){i.BOOLEAN="boolean",i.STRING="string",i.NUMBER="number",i.ARRAY="array"})(R||(R={}));/**
14
+ * @license
15
+ * Copyright (c) 2016, Contributors
16
+ * SPDX-License-Identifier: ISC
17
+ */let W;class at{constructor(t){W=t}parse(t,r){const a=Object.assign({alias:void 0,array:void 0,boolean:void 0,config:void 0,configObjects:void 0,configuration:void 0,coerce:void 0,count:void 0,default:void 0,envPrefix:void 0,narg:void 0,normalize:void 0,string:void 0,number:void 0,__:void 0,key:void 0},r),c=ot(t),u=typeof t=="string",p=ct(Object.assign(Object.create(null),a.alias)),m=Object.assign({"boolean-negation":!0,"camel-case-expansion":!0,"combine-arrays":!1,"dot-notation":!0,"duplicate-arguments-array":!0,"flatten-duplicate-arrays":!0,"greedy-arrays":!0,"halt-at-non-option":!1,"nargs-eats-options":!1,"negation-prefix":"no-","parse-numbers":!0,"parse-positional-numbers":!0,"populate--":!1,"set-placeholder-key":!1,"short-option-groups":!0,"strip-aliased":!1,"strip-dashed":!1,"unknown-options-as-args":!1},a.configuration),E=Object.assign(Object.create(null),a.default),$=a.configObjects||[],w=a.envPrefix,A=m["populate--"],J=A?"--":"_",Y=Object.create(null),he=Object.create(null),P=a.__||W.format,l={aliases:Object.create(null),arrays:Object.create(null),bools:Object.create(null),strings:Object.create(null),numbers:Object.create(null),counts:Object.create(null),normalize:Object.create(null),configs:Object.create(null),nargs:Object.create(null),coercions:Object.create(null),keys:[]},L=/^-([0-9]+(\.[0-9]+)?|\.[0-9]+)$/,ne=new RegExp("^--"+m["negation-prefix"]+"(.+)");[].concat(a.array||[]).filter(Boolean).forEach(function(e){const s=typeof e=="object"?e.key:e,f=Object.keys(e).map(function(o){return{boolean:"bools",string:"strings",number:"numbers"}[o]}).filter(Boolean).pop();f&&(l[f][s]=!0),l.arrays[s]=!0,l.keys.push(s)}),[].concat(a.boolean||[]).filter(Boolean).forEach(function(e){l.bools[e]=!0,l.keys.push(e)}),[].concat(a.string||[]).filter(Boolean).forEach(function(e){l.strings[e]=!0,l.keys.push(e)}),[].concat(a.number||[]).filter(Boolean).forEach(function(e){l.numbers[e]=!0,l.keys.push(e)}),[].concat(a.count||[]).filter(Boolean).forEach(function(e){l.counts[e]=!0,l.keys.push(e)}),[].concat(a.normalize||[]).filter(Boolean).forEach(function(e){l.normalize[e]=!0,l.keys.push(e)}),typeof a.narg=="object"&&Object.entries(a.narg).forEach(([e,s])=>{typeof s=="number"&&(l.nargs[e]=s,l.keys.push(e))}),typeof a.coerce=="object"&&Object.entries(a.coerce).forEach(([e,s])=>{typeof s=="function"&&(l.coercions[e]=s,l.keys.push(e))}),typeof a.config<"u"&&(Array.isArray(a.config)||typeof a.config=="string"?[].concat(a.config).filter(Boolean).forEach(function(e){l.configs[e]=!0}):typeof a.config=="object"&&Object.entries(a.config).forEach(([e,s])=>{(typeof s=="boolean"||typeof s=="function")&&(l.configs[e]=s)})),Te(a.key,p,a.default,l.arrays),Object.keys(E).forEach(function(e){(l.aliases[e]||[]).forEach(function(s){E[s]=E[e]})});let F=null;Ye();let G=[];const O=Object.assign(Object.create(null),{_:[]}),pe={};for(let e=0;e<c.length;e++){const s=c[e],f=s.replace(/^-{3,}/,"---");let o,n,h,d,g,_;if(s!=="--"&&/^-/.test(s)&&Z(s))se(s);else if(f.match(/^---+(=|$)/)){se(s);continue}else if(s.match(/^--.+=/)||!m["short-option-groups"]&&s.match(/^-.+=/))d=s.match(/^--?([^=]+)=([\s\S]*)$/),d!==null&&Array.isArray(d)&&d.length>=3&&(b(d[1],l.arrays)?e=H(e,d[1],c,d[2]):b(d[1],l.nargs)!==!1?e=V(e,d[1],c,d[2]):y(d[1],d[2],!0));else if(s.match(ne)&&m["boolean-negation"])d=s.match(ne),d!==null&&Array.isArray(d)&&d.length>=2&&(n=d[1],y(n,b(n,l.arrays)?[!1]:!1));else if(s.match(/^--.+/)||!m["short-option-groups"]&&s.match(/^-[^-]+/))d=s.match(/^--?(.+)/),d!==null&&Array.isArray(d)&&d.length>=2&&(n=d[1],b(n,l.arrays)?e=H(e,n,c):b(n,l.nargs)!==!1?e=V(e,n,c):(g=c[e+1],g!==void 0&&(!g.match(/^-/)||g.match(L))&&!b(n,l.bools)&&!b(n,l.counts)||/^(true|false)$/.test(g)?(y(n,g),e++):y(n,U(n))));else if(s.match(/^-.\..+=/))d=s.match(/^-([^=]+)=([\s\S]*)$/),d!==null&&Array.isArray(d)&&d.length>=3&&y(d[1],d[2]);else if(s.match(/^-.\..+/)&&!s.match(L))g=c[e+1],d=s.match(/^-(.\..+)/),d!==null&&Array.isArray(d)&&d.length>=2&&(n=d[1],g!==void 0&&!g.match(/^-/)&&!b(n,l.bools)&&!b(n,l.counts)?(y(n,g),e++):y(n,U(n)));else if(s.match(/^-[^-]+/)&&!s.match(L)){h=s.slice(1,-1).split(""),o=!1;for(let j=0;j<h.length;j++){if(g=s.slice(j+2),h[j+1]&&h[j+1]==="="){_=s.slice(j+3),n=h[j],b(n,l.arrays)?e=H(e,n,c,_):b(n,l.nargs)!==!1?e=V(e,n,c,_):y(n,_),o=!0;break}if(g==="-"){y(h[j],g);continue}if(/[A-Za-z]/.test(h[j])&&/^-?\d+(\.\d*)?(e-?\d+)?$/.test(g)&&b(g,l.bools)===!1){y(h[j],g),o=!0;break}if(h[j+1]&&h[j+1].match(/\W/)){y(h[j],g),o=!0;break}else y(h[j],U(h[j]))}n=s.slice(-1)[0],!o&&n!=="-"&&(b(n,l.arrays)?e=H(e,n,c):b(n,l.nargs)!==!1?e=V(e,n,c):(g=c[e+1],g!==void 0&&(!/^(-|--)[^-]/.test(g)||g.match(L))&&!b(n,l.bools)&&!b(n,l.counts)||/^(true|false)$/.test(g)?(y(n,g),e++):y(n,U(n))))}else if(s.match(/^-[0-9]$/)&&s.match(L)&&b(s.slice(1),l.bools))n=s.slice(1),y(n,U(n));else if(s==="--"){G=c.slice(e+1);break}else if(m["halt-at-non-option"]){G=c.slice(e);break}else se(s)}me(O,!0),me(O,!1),Ie(O),Ue(),be(O,l.aliases,E,!0),qe(O),m["set-placeholder-key"]&&Be(O),Object.keys(l.counts).forEach(function(e){B(O,e.split("."))||y(e,0)}),A&&G.length&&(O[J]=[]),G.forEach(function(e){O[J].push(e)}),m["camel-case-expansion"]&&m["strip-dashed"]&&Object.keys(O).filter(e=>e!=="--"&&e.includes("-")).forEach(e=>{delete O[e]}),m["strip-aliased"]&&[].concat(...Object.keys(p).map(e=>p[e])).forEach(e=>{m["camel-case-expansion"]&&e.includes("-")&&delete O[e.split(".").map(s=>z(s)).join(".")],delete O[e]});function se(e){const s=K("_",e);(typeof s=="string"||typeof s=="number")&&O._.push(s)}function V(e,s,f,o){let n,h=b(s,l.nargs);if(h=typeof h!="number"||isNaN(h)?1:h,h===0)return N(o)||(F=Error(P("Argument unexpected for: %s",s))),y(s,U(s)),e;let d=N(o)?0:1;if(m["nargs-eats-options"])f.length-(e+1)+d<h&&(F=Error(P("Not enough arguments following: %s",s))),d=h;else{for(n=e+1;n<f.length&&(!f[n].match(/^-[^0-9]/)||f[n].match(L)||Z(f[n]));n++)d++;d<h&&(F=Error(P("Not enough arguments following: %s",s)))}let g=Math.min(d,h);for(!N(o)&&g>0&&(y(s,o),g--),n=e+1;n<g+e+1;n++)y(s,f[n]);return e+g}function H(e,s,f,o){let n=[],h=o||f[e+1];const d=b(s,l.nargs);if(b(s,l.bools)&&!/^(true|false)$/.test(h))n.push(!0);else if(N(h)||N(o)&&/^-/.test(h)&&!L.test(h)&&!Z(h)){if(E[s]!==void 0){const g=E[s];n=Array.isArray(g)?g:[g]}}else{N(o)||n.push(ie(s,o,!0));for(let g=e+1;g<f.length&&!(!m["greedy-arrays"]&&n.length>0||d&&typeof d=="number"&&n.length>=d||(h=f[g],/^-/.test(h)&&!L.test(h)&&!Z(h)));g++)e=g,n.push(ie(s,h,u))}return typeof d=="number"&&(d&&n.length<d||isNaN(d)&&n.length===0)&&(F=Error(P("Not enough arguments following: %s",s))),y(s,n),e}function y(e,s,f=u){if(/-/.test(e)&&m["camel-case-expansion"]){const h=e.split(".").map(function(d){return z(d)}).join(".");ge(e,h)}const o=ie(e,s,f),n=e.split(".");T(O,n,o),l.aliases[e]&&l.aliases[e].forEach(function(h){const d=h.split(".");T(O,d,o)}),n.length>1&&m["dot-notation"]&&(l.aliases[n[0]]||[]).forEach(function(h){let d=h.split(".");const g=[].concat(n);g.shift(),d=d.concat(g),(l.aliases[e]||[]).includes(d.join("."))||T(O,d,o)}),b(e,l.normalize)&&!b(e,l.arrays)&&[e].concat(l.aliases[e]||[]).forEach(function(d){Object.defineProperty(pe,d,{enumerable:!0,get(){return s},set(g){s=typeof g=="string"?W.normalize(g):g}})})}function ge(e,s){l.aliases[e]&&l.aliases[e].length||(l.aliases[e]=[s],Y[s]=!0),l.aliases[s]&&l.aliases[s].length||ge(s,e)}function ie(e,s,f){f&&(s=lt(s)),(b(e,l.bools)||b(e,l.counts))&&typeof s=="string"&&(s=s==="true");let o=Array.isArray(s)?s.map(function(n){return K(e,n)}):K(e,s);return b(e,l.counts)&&(N(o)||typeof o=="boolean")&&(o=ae()),b(e,l.normalize)&&b(e,l.arrays)&&(Array.isArray(s)?o=s.map(n=>W.normalize(n)):o=W.normalize(s)),o}function K(e,s){return!m["parse-positional-numbers"]&&e==="_"||!b(e,l.strings)&&!b(e,l.bools)&&!Array.isArray(s)&&(Ce(s)&&m["parse-numbers"]&&Number.isSafeInteger(Math.floor(parseFloat(`${s}`)))||!N(s)&&b(e,l.numbers))&&(s=Number(s)),s}function Ie(e){const s=Object.create(null);be(s,l.aliases,E),Object.keys(l.configs).forEach(function(f){const o=e[f]||s[f];if(o)try{let n=null;const h=W.resolve(W.cwd(),o),d=l.configs[f];if(typeof d=="function"){try{n=d(h)}catch(g){n=g}if(n instanceof Error){F=n;return}}else n=W.require(h);re(n)}catch(n){n.name==="PermissionDenied"?F=n:e[f]&&(F=Error(P("Invalid JSON config file: %s",o)))}})}function re(e,s){Object.keys(e).forEach(function(f){const o=e[f],n=s?s+"."+f:f;typeof o=="object"&&o!==null&&!Array.isArray(o)&&m["dot-notation"]?re(o,n):(!B(O,n.split("."))||b(n,l.arrays)&&m["combine-arrays"])&&y(n,o)})}function Ue(){typeof $<"u"&&$.forEach(function(e){re(e)})}function me(e,s){if(typeof w>"u")return;const f=typeof w=="string"?w:"",o=W.env();Object.keys(o).forEach(function(n){if(f===""||n.lastIndexOf(f,0)===0){const h=n.split("__").map(function(d,g){return g===0&&(d=d.substring(f.length)),z(d)});(s&&l.configs[h.join(".")]||!s)&&!B(e,h)&&y(h.join("."),o[n])}})}function qe(e){let s;const f=new Set;Object.keys(e).forEach(function(o){if(!f.has(o)&&(s=b(o,l.coercions),typeof s=="function"))try{const n=K(o,s(e[o]));[].concat(l.aliases[o]||[],o).forEach(h=>{f.add(h),e[h]=n})}catch(n){F=n}})}function Be(e){return l.keys.forEach(s=>{~s.indexOf(".")||typeof e[s]>"u"&&(e[s]=void 0)}),e}function be(e,s,f,o=!1){Object.keys(f).forEach(function(n){B(e,n.split("."))||(T(e,n.split("."),f[n]),o&&(he[n]=!0),(s[n]||[]).forEach(function(h){B(e,h.split("."))||T(e,h.split("."),f[n])}))})}function B(e,s){let f=e;m["dot-notation"]||(s=[s.join(".")]),s.slice(0,-1).forEach(function(n){f=f[n]||{}});const o=s[s.length-1];return typeof f!="object"?!1:o in f}function T(e,s,f){let o=e;m["dot-notation"]||(s=[s.join(".")]),s.slice(0,-1).forEach(function(_){_=_e(_),typeof o=="object"&&o[_]===void 0&&(o[_]={}),typeof o[_]!="object"||Array.isArray(o[_])?(Array.isArray(o[_])?o[_].push({}):o[_]=[o[_],{}],o=o[_][o[_].length-1]):o=o[_]});const n=_e(s[s.length-1]),h=b(s.join("."),l.arrays),d=Array.isArray(f);let g=m["duplicate-arguments-array"];!g&&b(n,l.nargs)&&(g=!0,(!N(o[n])&&l.nargs[n]===1||Array.isArray(o[n])&&o[n].length===l.nargs[n])&&(o[n]=void 0)),f===ae()?o[n]=ae(o[n]):Array.isArray(o[n])?g&&h&&d?o[n]=m["flatten-duplicate-arrays"]?o[n].concat(f):(Array.isArray(o[n][0])?o[n]:[o[n]]).concat([f]):!g&&!!h==!!d?o[n]=f:o[n]=o[n].concat([f]):o[n]===void 0&&h?o[n]=d?f:[f]:g&&!(o[n]===void 0||b(n,l.counts)||b(n,l.bools))?o[n]=[o[n],f]:o[n]=f}function Te(...e){e.forEach(function(s){Object.keys(s||{}).forEach(function(f){l.aliases[f]||(l.aliases[f]=[].concat(p[f]||[]),l.aliases[f].concat(f).forEach(function(o){if(/-/.test(o)&&m["camel-case-expansion"]){const n=z(o);n!==f&&l.aliases[f].indexOf(n)===-1&&(l.aliases[f].push(n),Y[n]=!0)}}),l.aliases[f].concat(f).forEach(function(o){if(o.length>1&&/[A-Z]/.test(o)&&m["camel-case-expansion"]){const n=Fe(o,"-");n!==f&&l.aliases[f].indexOf(n)===-1&&(l.aliases[f].push(n),Y[n]=!0)}}),l.aliases[f].forEach(function(o){l.aliases[o]=[f].concat(l.aliases[f].filter(function(n){return o!==n}))}))})})}function b(e,s){const f=[].concat(l.aliases[e]||[],e),o=Object.keys(s),n=f.find(h=>o.includes(h));return n?s[n]:!1}function ye(e){const s=Object.keys(l);return[].concat(s.map(o=>l[o])).some(function(o){return Array.isArray(o)?o.includes(e):o[e]})}function ze(e,...s){return[].concat(...s).some(function(o){const n=e.match(o);return n&&ye(n[1])})}function Me(e){if(e.match(L)||!e.match(/^-[^-]+/))return!1;let s=!0,f;const o=e.slice(1).split("");for(let n=0;n<o.length;n++){if(f=e.slice(n+2),!ye(o[n])){s=!1;break}if(o[n+1]&&o[n+1]==="="||f==="-"||/[A-Za-z]/.test(o[n])&&/^-?\d+(\.\d*)?(e-?\d+)?$/.test(f)||o[n+1]&&o[n+1].match(/\W/))break}return s}function Z(e){return m["unknown-options-as-args"]&&De(e)}function De(e){return e=e.replace(/^-{3,}/,"--"),e.match(L)||Me(e)?!1:!ze(e,/^-+([^=]+?)=[\s\S]*$/,ne,/^-+([^=]+?)$/,/^-+([^=]+?)-$/,/^-+([^=]+?\d+)$/,/^-+([^=]+?)\W+.*$/)}function U(e){return!b(e,l.bools)&&!b(e,l.counts)&&`${e}`in E?E[e]:Qe(Je(e))}function Qe(e){return{[R.BOOLEAN]:!0,[R.STRING]:"",[R.NUMBER]:void 0,[R.ARRAY]:[]}[e]}function Je(e){let s=R.BOOLEAN;return b(e,l.strings)?s=R.STRING:b(e,l.numbers)?s=R.NUMBER:b(e,l.bools)?s=R.BOOLEAN:b(e,l.arrays)&&(s=R.ARRAY),s}function N(e){return e===void 0}function Ye(){Object.keys(l.counts).find(e=>b(e,l.arrays)?(F=Error(P("Invalid configuration: %s, opts.count excludes opts.array.",e)),!0):b(e,l.nargs)?(F=Error(P("Invalid configuration: %s, opts.count excludes opts.narg.",e)),!0):!1)}return{aliases:Object.assign({},l.aliases),argv:Object.assign(pe,O),configuration:m,defaulted:Object.assign({},he),error:F,newAliases:Object.assign({},Y)}}}function ct(i){const t=[],r=Object.create(null);let a=!0;for(Object.keys(i).forEach(function(c){t.push([].concat(i[c],c))});a;){a=!1;for(let c=0;c<t.length;c++)for(let u=c+1;u<t.length;u++)if(t[c].filter(function(m){return t[u].indexOf(m)!==-1}).length){t[c]=t[c].concat(t[u]),t.splice(u,1),a=!0;break}}return t.forEach(function(c){c=c.filter(function(p,m,E){return E.indexOf(p)===m});const u=c.pop();u!==void 0&&typeof u=="string"&&(r[u]=c)}),r}function ae(i){return i!==void 0?i+1:1}function _e(i){return i==="__proto__"?"___proto___":i}function lt(i){return typeof i=="string"&&(i[0]==="'"||i[0]==='"')&&i[i.length-1]===i[0]?i.substring(1,i.length-1):i}/**
18
+ * @fileoverview Main entrypoint for libraries using yargs-parser in Node.js
19
+ * CJS and ESM environments.
20
+ *
21
+ * @license
22
+ * Copyright (c) 2016, Contributors
23
+ * SPDX-License-Identifier: ISC
24
+ */var ce,le,fe;const Ae=process&&process.env&&process.env.YARGS_MIN_NODE_VERSION?Number(process.env.YARGS_MIN_NODE_VERSION):12,je=(le=(ce=process==null?void 0:process.versions)===null||ce===void 0?void 0:ce.node)!==null&&le!==void 0?le:(fe=process==null?void 0:process.version)===null||fe===void 0?void 0:fe.slice(1);if(je&&Number(je.match(/^([^.]+)/)[1])<Ae)throw Error(`yargs parser supports a minimum Node.js version of ${Ae}. Read our version support policy: https://github.com/yargs/yargs-parser#supported-nodejs-versions`);const ft=process?process.env:{},Re=new at({cwd:process.cwd,env:()=>ft,format:de.format,normalize:S.normalize,resolve:S.resolve,require:i=>{if(typeof require<"u")return require(i);if(i.match(/\.json$/))return JSON.parse(I.readFileSync(i,"utf8"));throw Error("only .json config files are supported in ESM")}}),Q=function(t,r){return Re.parse(t.slice(),r).argv};Q.detailed=function(i,t){return Re.parse(i.slice(),t)};Q.camelCase=z;Q.decamelize=Fe;Q.looksLikeNumber=Ce;const ut={right:bt,center:yt},dt=0,X=1,ht=2,k=3;class pt{constructor(t){var r;this.width=t.width,this.wrap=(r=t.wrap)!==null&&r!==void 0?r:!0,this.rows=[]}span(...t){const r=this.div(...t);r.span=!0}resetOutput(){this.rows=[]}div(...t){if(t.length===0&&this.div(""),this.wrap&&this.shouldApplyLayoutDSL(...t)&&typeof t[0]=="string")return this.applyLayoutDSL(t[0]);const r=t.map(a=>typeof a=="string"?this.colFromString(a):a);return this.rows.push(r),r}shouldApplyLayoutDSL(...t){return t.length===1&&typeof t[0]=="string"&&/[\t\n]/.test(t[0])}applyLayoutDSL(t){const r=t.split(`
25
+ `).map(c=>c.split(" "));let a=0;return r.forEach(c=>{c.length>1&&v.stringWidth(c[0])>a&&(a=Math.min(Math.floor(this.width*.5),v.stringWidth(c[0])))}),r.forEach(c=>{this.div(...c.map((u,p)=>({text:u.trim(),padding:this.measurePadding(u),width:p===0&&c.length>1?a:void 0})))}),this.rows[this.rows.length-1]}colFromString(t){return{text:t,padding:this.measurePadding(t)}}measurePadding(t){const r=v.stripAnsi(t);return[0,r.match(/\s*$/)[0].length,0,r.match(/^\s*/)[0].length]}toString(){const t=[];return this.rows.forEach(r=>{this.rowToString(r,t)}),t.filter(r=>!r.hidden).map(r=>r.text).join(`
26
+ `)}rowToString(t,r){return this.rasterize(t).forEach((a,c)=>{let u="";a.forEach((p,m)=>{const{width:E}=t[m],$=this.negatePadding(t[m]);let w=p;if($>v.stringWidth(p)&&(w+=" ".repeat($-v.stringWidth(p))),t[m].align&&t[m].align!=="left"&&this.wrap){const J=ut[t[m].align];w=J(w,$),v.stringWidth(w)<$&&(w+=" ".repeat((E||0)-v.stringWidth(w)-1))}const A=t[m].padding||[0,0,0,0];A[k]&&(u+=" ".repeat(A[k])),u+=xe(t[m],w,"| "),u+=w,u+=xe(t[m],w," |"),A[X]&&(u+=" ".repeat(A[X])),c===0&&r.length>0&&(u=this.renderInline(u,r[r.length-1]))}),r.push({text:u.replace(/ +$/,""),span:t.span})}),r}renderInline(t,r){const a=t.match(/^ */),c=a?a[0].length:0,u=r.text,p=v.stringWidth(u.trimRight());return r.span?this.wrap?c<p?t:(r.hidden=!0,u.trimRight()+" ".repeat(c-p)+t.trimLeft()):(r.hidden=!0,u+t):t}rasterize(t){const r=[],a=this.columnWidths(t);let c;return t.forEach((u,p)=>{u.width=a[p],this.wrap?c=v.wrap(u.text,this.negatePadding(u),{hard:!0}).split(`
27
+ `):c=u.text.split(`
28
+ `),u.border&&(c.unshift("."+"-".repeat(this.negatePadding(u)+2)+"."),c.push("'"+"-".repeat(this.negatePadding(u)+2)+"'")),u.padding&&(c.unshift(...new Array(u.padding[dt]||0).fill("")),c.push(...new Array(u.padding[ht]||0).fill(""))),c.forEach((m,E)=>{r[E]||r.push([]);const $=r[E];for(let w=0;w<p;w++)$[w]===void 0&&$.push("");$.push(m)})}),r}negatePadding(t){let r=t.width||0;return t.padding&&(r-=(t.padding[k]||0)+(t.padding[X]||0)),t.border&&(r-=4),r}columnWidths(t){if(!this.wrap)return t.map(p=>p.width||v.stringWidth(p.text));let r=t.length,a=this.width;const c=t.map(p=>{if(p.width)return r--,a-=p.width,p.width}),u=r?Math.floor(a/r):0;return c.map((p,m)=>p===void 0?Math.max(u,gt(t[m])):p)}}function xe(i,t,r){return i.border?/[.']-+[.']/.test(t)?"":t.trim().length!==0?r:" ":""}function gt(i){const t=i.padding||[],r=1+(t[k]||0)+(t[X]||0);return i.border?r+4:r}function mt(){return typeof process=="object"&&process.stdout&&process.stdout.columns?process.stdout.columns:80}function bt(i,t){i=i.trim();const r=v.stringWidth(i);return r<t?" ".repeat(t-r)+i:i}function yt(i,t){i=i.trim();const r=v.stringWidth(i);return r>=t?i:" ".repeat(t-r>>1)+i}let v;function Et(i,t){return v=t,new pt({width:(i==null?void 0:i.width)||mt(),wrap:i==null?void 0:i.wrap})}const Le=new RegExp("\x1B(?:\\[(?:\\d+[ABCDEFGJKSTm]|\\d+;\\d+[Hfm]|\\d+;\\d+;\\d+m|6n|s|u|\\?25[lh])|\\w)","g");function Ne(i){return i.replace(Le,"")}function wt(i,t){const[r,a]=i.match(Le)||["",""];i=Ne(i);let c="";for(let u=0;u<i.length;u++)u!==0&&u%t===0&&(c+=`
29
+ `),c+=i.charAt(u);return r&&a&&(c=`${r}${c}${a}`),c}function Ot(i){return Et(i,{stringWidth:t=>[...t].length,stripAnsi:Ne,wrap:wt})}function _t(i,t){let r=S.resolve(".",i),a;for(I.statSync(r).isDirectory()||(r=S.dirname(r));;){if(a=t(r,I.readdirSync(r)),a)return S.resolve(r,a);if(r=S.dirname(a=r),a===r)break}}const At={fs:{readFileSync:I.readFileSync,writeFile:I.writeFile},format:de.format,resolve:S.resolve,exists:i=>{try{return I.statSync(i).isFile()}catch{return!1}}};let C;class jt{constructor(t){t=t||{},this.directory=t.directory||"./locales",this.updateFiles=typeof t.updateFiles=="boolean"?t.updateFiles:!0,this.locale=t.locale||"en",this.fallbackToLanguage=typeof t.fallbackToLanguage=="boolean"?t.fallbackToLanguage:!0,this.cache=Object.create(null),this.writeQueue=[]}__(...t){if(typeof arguments[0]!="string")return this._taggedLiteral(arguments[0],...arguments);const r=t.shift();let a=function(){};return typeof t[t.length-1]=="function"&&(a=t.pop()),a=a||function(){},this.cache[this.locale]||this._readLocaleFile(),!this.cache[this.locale][r]&&this.updateFiles?(this.cache[this.locale][r]=r,this._enqueueWrite({directory:this.directory,locale:this.locale,cb:a})):a(),C.format.apply(C.format,[this.cache[this.locale][r]||r].concat(t))}__n(){const t=Array.prototype.slice.call(arguments),r=t.shift(),a=t.shift(),c=t.shift();let u=function(){};typeof t[t.length-1]=="function"&&(u=t.pop()),this.cache[this.locale]||this._readLocaleFile();let p=c===1?r:a;this.cache[this.locale][r]&&(p=this.cache[this.locale][r][c===1?"one":"other"]),!this.cache[this.locale][r]&&this.updateFiles?(this.cache[this.locale][r]={one:r,other:a},this._enqueueWrite({directory:this.directory,locale:this.locale,cb:u})):u();const m=[p];return~p.indexOf("%d")&&m.push(c),C.format.apply(C.format,m.concat(t))}setLocale(t){this.locale=t}getLocale(){return this.locale}updateLocale(t){this.cache[this.locale]||this._readLocaleFile();for(const r in t)Object.prototype.hasOwnProperty.call(t,r)&&(this.cache[this.locale][r]=t[r])}_taggedLiteral(t,...r){let a="";return t.forEach(function(c,u){const p=r[u+1];a+=c,typeof p<"u"&&(a+="%s")}),this.__.apply(this,[a].concat([].slice.call(r,1)))}_enqueueWrite(t){this.writeQueue.push(t),this.writeQueue.length===1&&this._processWriteQueue()}_processWriteQueue(){const t=this,r=this.writeQueue[0],a=r.directory,c=r.locale,u=r.cb,p=this._resolveLocaleFile(a,c),m=JSON.stringify(this.cache[c],null,2);C.fs.writeFile(p,m,"utf-8",function(E){t.writeQueue.shift(),t.writeQueue.length>0&&t._processWriteQueue(),u(E)})}_readLocaleFile(){let t={};const r=this._resolveLocaleFile(this.directory,this.locale);try{C.fs.readFileSync&&(t=JSON.parse(C.fs.readFileSync(r,"utf-8")))}catch(a){if(a instanceof SyntaxError&&(a.message="syntax error in "+r),a.code==="ENOENT")t={};else throw a}this.cache[this.locale]=t}_resolveLocaleFile(t,r){let a=C.resolve(t,"./",r+".json");if(this.fallbackToLanguage&&!this._fileExistsSync(a)&&~r.lastIndexOf("_")){const c=C.resolve(t,"./",r.split("_")[0]+".json");this._fileExistsSync(c)&&(a=c)}return a}_fileExistsSync(t){return C.exists(t)}}function xt(i,t){C=t;const r=new jt(i);return{__:r.__.bind(r),__n:r.__n.bind(r),setLocale:r.setLocale.bind(r),getLocale:r.getLocale.bind(r),updateLocale:r.updateLocale.bind(r),locale:r.locale}}const vt=i=>xt(i,At),St="require is not supported by ESM",ve="loading a directory of commands is not supported yet for ESM";let D;try{D=et.fileURLToPath(typeof document>"u"?require("url").pathToFileURL(__filename).href:te&&te.src||new URL("index.js",document.baseURI).href)}catch{D=process.cwd()}const $t=D.substring(0,D.lastIndexOf("node_modules"));we.notStrictEqual,we.strictEqual,de.inspect,$t||process.cwd(),S.basename,S.dirname,S.extname,S.relative,S.resolve,process.cwd,process.exit,process.nextTick,typeof process.stdout.columns<"u"&&process.stdout.columns,I.readFileSync,vt({directory:S.resolve(D,"../../../locales"),updateFiles:!1});const Ft=tt.fileURLToPath(typeof document>"u"?require("url").pathToFileURL(__filename).href:te&&te.src||new URL("index.js",document.baseURI).href),Ct=q.dirname(Ft),Rt=(i,t)=>{console.log(Oe.red(i)),console.log(Oe.red(t==null?void 0:t.message)),process.exit(1)},Lt=()=>{const i=x.readFileSync(q.join(Ct,"../package.json"),"utf-8");return JSON.parse(i)},We="template-node-cli",Pe="CUSTOM",Nt=[{title:"typescript",value:"template-ts"},{title:"node-cli",value:We},{title:"web-mobile-vue3",value:"template-web-m-vue3"},{title:"web-mobile-react",value:"template-web-m-react"},{title:"uni-vue3",value:"template-uni-m-vue3"},{title:"monorepo",value:"template-monorepo"},{title:"自定义模板路径",value:Pe}],Wt=process.cwd();async function Pt(){const i=q.resolve(__dirname,"../package.json"),t=x.readFileSync(i,"utf-8"),{version:r}=JSON.parse(t),a=(await import("chalk")).default;return console.log(a.green(`v${r}`)),await ee([{type:"text",name:"projectName",message:"Project name:"},{type:"select",name:"template",message:"请选择模板",choices:Nt},{type:"confirm",name:"saveGitHistory",message:"保留git历史"}])}const It=()=>{Pt().then(async({projectName:i,template:t,saveGitHistory:r})=>{const a=(await import("chalk")).default;if(!i.trim()){console.log(a.red("项目名称不能为空"));return}if(i.includes(" ")||i.includes("\\")||i.includes("/")){console.log(a.red("项目名称不能包含空格或者\\或者/"));return}const c=q.resolve(Wt,i);if(x.existsSync(c)){const{isRemove:A}=await ee({type:"confirm",name:"isRemove",message:"项目已存在,是否删除"});if(A===!0)x.rmSync(c,{recursive:!0,force:!0});else throw new Error("项目已存在")}let u="";if(t===Pe){const{customUrl:A}=await ee({type:"text",name:"customUrl",message:"请输入自定义模板路径"});u=A}else u=`https://gitee.com/justsosu/${t}`;if(console.log(a.green("正在初始化项目,请稍等...")),ue.execSync(`git clone ${u} ${i}`),r===!1){const A=`${c}/.git`;if(!x.existsSync(A))throw new Error("git目录不存在");x.rmSync(`${c}/.git`,{recursive:!0,force:!0})}else ue.execSync(`cd ${c} && git remote rename origin upstream`);const p=x.readFileSync(`${c}/package.json`,"utf-8"),m=JSON.parse(p),{name:E}=m;if(m.name=i,x.rmSync(`${c}/package.json`),t===We){const A=m.bin;m.bin={[i]:Object.values(A)[0]}}x.writeFileSync(`${c}/package.json`,JSON.stringify(m,null,2));const w=x.readFileSync(`${c}/README.md`,"utf-8").replace(E,i);x.rmSync(`${c}/README.md`),x.writeFileSync(`${c}/README.md`,w),console.log(a.green("项目初始化完成")),console.log(a.blue(`
30
+ 使用步骤:
31
+ 1. cd ${i}
32
+ 2. pnpm install
33
+ 3. pnpm run dev
34
+ `))})},Se=process.cwd();async function Ut(){const i=q.resolve(__dirname,"../package.json"),t=x.readFileSync(i,"utf-8"),{version:r}=JSON.parse(t),a=(await import("chalk")).default;return console.log(a.green(`v${r}`)),await ee([{type:"text",name:"npmName",message:"请选择npm包名"},{type:"select",name:"type",message:"请选择片段输出类型",choices:[{title:"ts",value:"ts"},{title:"js(es6)",value:"es6"},{title:"js(es7)",value:"es7"},{title:"js(esnext)",value:"esnext"},{title:"js(esnext)",value:"esnext"}]},{type:"text",name:"output",message:"请输入结果输出路径"}])}const qt=()=>{Ut().then(async({npmName:i,type:t,output:r})=>{const a=q.resolve(Se,r);console.log(i,t,r,a,Se,__dirname),ue.execSync(`pnpm add ${i} 1>&2`)})},Bt=ke(it(process.argv)),{version:Tt}=Lt(),zt=async()=>await Bt.strict().version(Tt).alias("h","help").alias("v","version").options({mode:{type:"string",choices:["project","fragment"],default:"project",describe:"创建项目还是代码片段",alias:"m",demandOption:!0}}).usage("Usage: $0 [options]").help("help").fail(Rt).argv;zt().then(i=>{i.mode==="project"?It():i.mode==="fragment"&&qt()});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-done-coding",
3
- "version": "0.2.11",
3
+ "version": "0.2.12-0",
4
4
  "main": "dist/index.js",
5
5
  "types": "types/index.d.ts",
6
6
  "bin": "dist/index.js",
@@ -32,6 +32,7 @@
32
32
  "@done-coding/publish": "0.0.8",
33
33
  "@types/node": "^16.18.58",
34
34
  "@types/prompts": "^2.4.6",
35
+ "@types/yargs": "^17.0.28",
35
36
  "@typescript-eslint/eslint-plugin": "^6.7.0",
36
37
  "@typescript-eslint/parser": "^6.7.0",
37
38
  "conventional-changelog-cli": "^4.1.0",
@@ -55,7 +56,8 @@
55
56
  "node": ">=16.0.0"
56
57
  },
57
58
  "dependencies": {
58
- "chalk": "^5.3.0",
59
- "prompts": "^2.4.2"
59
+ "chalk": "^4.1.2",
60
+ "prompts": "^2.4.2",
61
+ "yargs": "^17.7.2"
60
62
  }
61
63
  }
@@ -0,0 +1,5 @@
1
+ export declare const failHandler: (msg: string, err: Error) => never;
2
+ export declare const getPkgInfo: () => {
3
+ name: string;
4
+ version: string;
5
+ };
@@ -0,0 +1 @@
1
+ export declare const initFragment: () => void;
@@ -0,0 +1 @@
1
+ export declare const initProject: () => void;