@baic/yolk-cli 2.1.0-alpha.42 → 2.1.0-alpha.43

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/es/yolk.js CHANGED
@@ -1,2 +1,2 @@
1
1
  #! /usr/bin/env node
2
- import e from"@babel/runtime/helpers/toArray";import t from"@babel/runtime/helpers/defineProperty";import s from"lodash/isString";import o from"lodash/pick";import r from"lodash/floor";import i from"lodash/chunk";function n(e,t){var s=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),s.push.apply(s,o)}return s}function c(e){for(var s=1;s<arguments.length;s++){var o=null!=arguments[s]?arguments[s]:{};s%2?n(Object(o),!0).forEach((function(s){t(e,s,o[s])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(o)):n(Object(o)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(o,t))}))}return e}import{execSync as a,spawn as m}from"child_process";import l from"commander";import p from"fs";import d from"glob";import u from"inquirer";import f from"minimatch";import*as y from"miniprogram-ci";import g from"mkdirp";import h from"mustache";import b from"ora";import j from"os";import S from"path";import{format as v}from"prettier";import x from"rimraf";import k from"../package.json";const w=require("staged-git-files"),$=process.cwd(),P="##### CREATED BY YOLK #####",O={ts:"typescript",tsx:"typescript",less:"less",sass:"scss",scss:"scss",css:"css"},F="utf-8",E=60,B=["**/node_modules/**","**/.umi/**","**/.umi-production/**","**/.ice/**","**/build/**","**/dist/**","**/lib/**","**/es/**","**/public/**","**/assets/**","**/h5+app/**","**/android/**","**/ios/**","**/mock/**","**/yolk*/**"],D=b(),q=e=>e&&D.warn(Buffer.from(e,F).toString()),I=e=>e&&D.fail(Buffer.from(e,F).toString()),N=e=>e&&D.succeed(Buffer.from(e,F).toString()),Q=e=>e&&D.info(Buffer.from(e,F).toString()),R=e=>"win32"===process.platform?`${e}.cmd`:e,T=()=>{N("yolk complete!"),process.exit(0)},_=()=>{q("yolk break!"),process.exit(0)},L=({command:e,args:t,complete:s,close:o,exit:r=!0})=>{const i=m(R(e),t||[],{stdio:"inherit"}).on("close",(e=>{e?(o&&o(),I("yolk close!"),process.exit(e)):(s&&s(),r&&T())}));process.on("SIGINT",(()=>{l.runningCommand&&l.runningCommand.kill("SIGKILL"),i.kill(),_()}))},A=(e,t,s)=>{u.prompt([{type:"list",name:"type",message:"\u9009\u62e9\u6a21\u7248",default:"web",choices:[{name:"web template(umi framework)",value:"umi-web"},{name:"web big screen template(umi framework)",value:"umi-web-screen"},{name:"mobile template(umi framework)",value:"umi-mobile"},{name:"mobile HBuilderX h5+app template(umi framework)",value:"umi-mobile-h5+app"},{name:"mobile native template(umi framework)",value:"umi-mobile-native"},{name:"web template(ice framework)",value:"ice-web"},{name:"web big screen template(ice framework)",value:"ice-web-screen"},{name:"mobile template(ice framework)",value:"ice-mobile"},{name:"mobile HBuilderX h5+app template(ice framework)",value:"ice-mobile-h5+app"},{name:"mobile native template(ice framework)",value:"ice-mobile-native"},{name:"miniprogram template",value:"miniprogram"}]},{type:"input",name:"projectName",message:"\u9879\u76ee\u540d\u79f0",default:S.basename(S.basename(process.cwd()))},{type:"list",name:"dependenciesInstallType",message:"\u9009\u62e9\u4f9d\u8d56\u5b89\u88c5\u65b9\u5f0f",default:"default",choices:[{name:"\u9ed8\u8ba4\u5b89\u88c5",value:"default"},{name:"\u8df3\u8fc7\u5b89\u88c5",value:!1},{name:"pnpm install",value:"pnpm"},{name:"yarn install",value:"yarn"},{name:"npm install",value:"npm"}]}]).then((o=>{const r={projectName:o.projectName,dependenciesInstallType:o.dependenciesInstallType,yolkVersion:k.version};t||(t=S.join(__dirname,`../templates/${o.type}`)),N(`\u590d\u5236\u6a21\u7248 ${S.basename(t)}`);const i=d.sync("**/*",{cwd:t,dot:!0,ignore:["**/node_modules/**","**/.git/**","**/.DS_Store","**/.idea/**"]});if(i.forEach((s=>{if(!t)return;const o=S.join(t,s);if(!p.statSync(o).isDirectory())if(s.endsWith(".tpl")){const t=p.readFileSync(o,F),i=S.join(e,s.replace(/\.tpl$/u,"")),n=h.render(t,r);g.sync(S.dirname(i)),N(`\u521b\u5efa ${S.relative(e,i)}`),p.writeFileSync(i,n,F)}else{N(`\u521b\u5efa ${s}`);const t=S.join(e,s);g.sync(S.dirname(t)),p.copyFileSync(o,t)}})),N("\u590d\u5236\u6a21\u7248 success!"),s&&p.existsSync(t)&&x(t,(()=>{N(`\u7f13\u5b58\u5220\u9664 success! ${S.basename(t||"")}`)})),o.dependenciesInstallType)switch(N("\u521d\u59cb\u5316\u4f9d\u8d56\u5305"),o.dependenciesInstallType){case"default":case"pnpm":L({command:"pnpm",args:["install"]});break;case"yarn":L({command:"yarn",args:["install"]});break;case"npm":L({command:"npm",args:["install"]});break;default:}N("\u53ef\u67e5\u9605<<https://303394539.github.io/yolk-docs/>>\u4e86\u89e3\u76f8\u5173\u6587\u6863")}))},K=(e,t)=>A(e,t,!0),J=()=>{const e=d.sync("*.yolkrc*",{cwd:$,dot:!0});if(!e.length)return{};const t=S.join($,e[0]);if(!p.existsSync(t))return{};try{return JSON.parse(p.readFileSync(t,F))||{}}catch(s){return I(s.message||".yolkrc\u8f6c\u6362\u9519\u8bef"),{}}},C=()=>{const e=S.join($,".prettierrc");if(p.existsSync(e))try{return JSON.parse(p.readFileSync(e,F))||{}}catch(t){return I(t.message||".prettierrc\u8f6c\u6362\u9519\u8bef"),{}}return require("./.prettierrc")},H=()=>{const e=S.join($,"project.config.json");if(!p.existsSync(e))return{};try{return JSON.parse(p.readFileSync(e,F))||{}}catch(t){return I(t.message||"project.config.json\u8f6c\u6362\u9519\u8bef"),{}}},M=()=>{const e=S.join($,"package.json");if(!p.existsSync(e))return{};try{return JSON.parse(p.readFileSync(e,F))||{}}catch(t){return I(t.message||"package.json\u8f6c\u6362\u9519\u8bef"),{}}},U=()=>p.existsSync(S.join($,"project.config.json")),V=()=>p.existsSync(S.join($,".icerc.ts"))||p.existsSync(S.join($,".icerc.js"))||p.existsSync(S.join($,".ice.ts"))||p.existsSync(S.join($,".ice.js")),G=()=>{let e=p.existsSync(S.join($,"node_modules/.bin/max"));if(!e)try{e=p.existsSync(require.resolve("@umijs/max"))}catch(t){}if(!e)try{e=/umi@4\.(\d+)\.(\d+)/u.test(a("umi -v").toString())}catch(t){}if(!e){const s=S.join($,"node_modules","umi","package.json");if(p.existsSync(s))try{const t=JSON.parse(p.readFileSync(s,F))||{};e=t.version&&+t.version.split(".")[0]>3}catch(t){}}return e},X=()=>p.existsSync(S.join($,".icerc.ts"))?".icerc.ts":p.existsSync(S.join($,".icerc.js"))?".icerc.js":p.existsSync(S.join($,".ice.ts"))?".ice.ts":".ice.js",Y=()=>{const e=S.join($,"project.config.json");if(p.existsSync(e)){const t=require(e);return t.appid}return""},W=()=>p.existsSync(S.join($,"project.tt.json"))&&0===Y().indexOf("tt"),z=()=>0===Y().indexOf("20"),Z=()=>{const e=J();let t="";try{t=require.resolve("@baic/eslint-config-yolk")}catch(r){}const s=d.sync("*.eslintrc*",{cwd:$,dot:!0}),o=s[0];return!1===e.strict&&o&&p.existsSync(o)?o:t},ee=()=>{const e=J();let t="";try{t=require.resolve("@baic/stylelint-config-yolk")}catch(r){}const s=d.sync("*.stylelintrc*",{cwd:$,dot:!0}),o=s[0];return!1===e.strict&&o&&p.existsSync(o)?o:t},te=()=>{const e=S.join($,".git/"),t=S.join($,".git/hooks"),s=S.join(t,"pre-commit"),o=p.existsSync(e),r=p.existsSync(s),i=r&&p.readFileSync(s,F).includes(P);if(o&&(!r||!i)){g.sync(t),p.writeFileSync(s,["#!/usr/bin/env bash","npx yolk pre-commit","RESULT=$?","[ $RESULT -ne 0 ] && exit 1","exit 0",P].join(j.EOL),F);try{p.chmodSync(s,"777")}catch(n){I(`chmod ${s} failed: ${n.message}`)}N("Create pre-commit hook")}},se=()=>{const e=J(),t=!1!==e.strict,s=e.eslintIgnore,o=e.stylelintIgnore;w().then((e=>{const r=new Promise(((s,r)=>{const n=ee();if(n){const a=e.map((e=>e.filename)).filter((e=>/^(src|tests)/iu.test(e))).filter((e=>/\.(le|sa|sc|c)s{2}$/iu.test(e))).filter((e=>B.every((t=>!f(e,t,{matchBase:!0}))))).filter((e=>"string"===typeof o?!f(e,o,{matchBase:!0}):o instanceof RegExp?!o.test(e):!Array.isArray(o)||o.every((t=>"string"===typeof t?!f(e,t,{matchBase:!0}):!(t instanceof RegExp)||!t.test(e))))).map((e=>{const t=S.join($,e);return p.existsSync(t)?t:null})).filter((e=>!!e));if(a.forEach((e=>{if(e&&p.existsSync(e)){const t=S.extname(e).replace(/^\./u,""),s=p.readFileSync(e,F),o=v(s,c({parser:O[t]},C()));p.writeFileSync(e,o,F)}})),N("style prettier success!"),a.length>=E){const e=[];i(a,20).forEach((s=>{e.push(new Promise(((e,o)=>{L({command:"stylelint",args:[t?"--ignore-disables":"","--allow-empty-input","--config",n,...s],complete:e,close:o,exit:!1})})))}));const o=process.getMaxListeners(),c=i(e,o?o/2:2);let m=0;const l=()=>{m<c.length?Promise.all(c[m]).then((()=>{m++,l()})).catch(r):s()};l()}else a.length&&L({command:"stylelint",args:[t?"--ignore-disables":"","--allow-empty-input","--config",n,...a],complete:s,close:r,exit:!1})}else s()})),n=()=>{const o=e.map((e=>e.filename)).filter((e=>/^(src|tests)/iu.test(e))).filter((e=>/\.([t|j]sx?)$/iu.test(e))).map((e=>{const t=S.join($,e);return p.existsSync(t)?t:null})).filter((e=>!!e));if(o.length){o.forEach((e=>{if(e&&p.existsSync(e)){const t=S.extname(e).replace(/^\./u,""),s=p.readFileSync(e,F),o=v(s,c({parser:O[t]},C()));p.writeFileSync(e,o,F)}})),N("script prettier success!");const e=Z();if(e){const r=o.filter((e=>B.every((t=>!f(e,t,{matchBase:!0}))))).filter((e=>"string"===typeof s?!f(e,s,{matchBase:!0}):s instanceof RegExp?!s.test(e):!Array.isArray(s)||s.every((t=>"string"===typeof t?!f(e,t,{matchBase:!0}):!(t instanceof RegExp)||!t.test(e)))));if(t&&(q("git commit\u7981\u6b62eslint\u7684ignore\u65b9\u5f0f(eslint-disable\u3001.eslintrc*\u3001ignore\u7b49)\u3002"),s&&q(`\u901a\u8fc7yolkrc\u914d\u7f6eeslintIgnore\uff1a${s}\u3002`)),r.length>=E){const s=[];i(r,20).forEach((o=>{s.push(new Promise((s=>{L({command:"eslint",args:[t?"--no-inline-config --no-ignore":"","--no-error-on-unmatched-pattern","--config",e,...o],complete:s,exit:!1})})))}));const o=process.getMaxListeners(),n=i(s,o?o/2:2);let c=0;const a=()=>{c<n.length?Promise.all(n[c]).then((()=>{c++,a()})):T()};a()}else r.length&&L({command:"eslint",args:[t?"--no-inline-config --no-ignore":"","--no-error-on-unmatched-pattern","--config",e,...r]})}else q("\u6ca1\u6709eslint\u914d\u7f6e\u6587\u4ef6")}else T()};q("\u8981\u6c42\u7edf\u4e00\u4ee3\u7801\u89c4\u8303\uff0c\u8fdb\u884c\u4e25\u683c\u7684\u8bed\u6cd5\u68c0\u67e5\u3002"),r.then(n)}))},oe=({mProject:e,mPrivateKeyPath:t,mVersion:s,mDesc:o,mRobot:r,mQrcodeFormat:i,mQrcodeOutputDest:n,mPagePath:c,mSearchQuery:m})=>{const l=p.existsSync(S.join($,".git"))?a("git log -1 --pretty=format:%H").toString():"",d=H(),u=d.appid,f=e||S.join($,"dist"),g=t||S.join($,`private.${u}.key`);if(p.existsSync(f)){if(p.existsSync(g)){const e=M(),t=s||e.version||d.version||"1.0.0",a=o||e.description||d.description,p=`version: ${t};${l?` commit: ${l};`:""}${a?` description: ${a};`:""}`;l&&Q(`commit: ${l}`),Q(`dist: ${f}`),Q(`key: ${g}`),Q(`appid: ${u}`),Q(`version: ${t}`),Q(`desc: ${p}`);const h=new y.Project({appid:u,type:"miniProgram",projectPath:f,privateKeyPath:g,ignores:["node_modules/**/*","**/*.txt","**/*.key","**/*.less","**/*.sass","**/*.scss","**/*.css","**/*.jsx","**/*.ts","**/*.tsx","**/*.md"]});return{appid:u,options:{project:h,version:t,desc:p,setting:d.setting,robot:r,qrcodeFormat:i,qrcodeOutputDest:n,pagePath:c,searchQuery:m}}}throw Error(`\u6ca1\u6709\u627e\u5230\u4e0a\u4f20\u5bc6\u94a5(${g})`)}throw Error(`\u6ca1\u6709\u627e\u5230dist\u76ee\u5f55(${f})`)},re=()=>{te(),process.argv.length>2?l.version(k.version).usage("[command] [options]").option("--clone","\u901a\u8fc7git clone\u62c9\u53d6\u6a21\u7248").option("--template <template>","\u6a21\u7248\u540d\u79f0\u6216\u8005clone\u6a21\u5f0f\u7684git\u5730\u5740").option("--docs","\u542f\u52a8\u6587\u6863\u6a21\u5f0f").option("--mProject <project>","\u5c0f\u7a0b\u5e8f\u4e0a\u4f20\u5de5\u7a0b\u76ee\u5f55").option("--mPrivateKeyPath <privateKeyPath>","\u5c0f\u7a0b\u5e8f\u4e0a\u4f20key\u6587\u4ef6").option("--mVersion <version>","\u5c0f\u7a0b\u5e8f\u4e0a\u4f20\u7248\u672c\u53f7").option("--mDesc <desc>","\u5c0f\u7a0b\u5e8f\u4e0a\u4f20\u63cf\u8ff0").option("--mRobot <robot>","\u5c0f\u7a0b\u5e8f\u4e0a\u4f20ci\u673a\u5668\u4eba1~30").option("--mQrcodeFormat <qrcodeFormat>",'\u5c0f\u7a0b\u5e8f\u9884\u89c8\u8fd4\u56de\u4e8c\u7ef4\u7801\u6587\u4ef6\u7684\u683c\u5f0f "image" \u6216 "base64"\uff0c \u9ed8\u8ba4\u503c "terminal" \u4f9b\u8c03\u8bd5\u7528').option("--mQrcodeOutputDest <qrcodeOutputDest>","\u5c0f\u7a0b\u5e8f\u9884\u89c8\u4e8c\u7ef4\u7801\u6587\u4ef6\u4fdd\u5b58\u8def\u5f84").option("--mPagePath <pagePath>","\u5c0f\u7a0b\u5e8f\u9884\u89c8\u9884\u89c8\u9875\u9762\u8def\u5f84").option("--mSearchQuery <searchQuery>","\u5c0f\u7a0b\u5e8f\u9884\u89c8\u9884\u89c8\u9875\u9762\u8def\u5f84\u542f\u52a8\u53c2\u6570").action(((t,i)=>{const n=e(i),a=n[0],m=n.slice(1),l=t.clone,d=t.template,u=t.docs;if(a)switch(Q(`yolk version: ${k.version}`),Q(`node version: ${process.version}`),Q(`platform: ${j.platform()}`),Q(`memory: ${r(j.freemem()/1024/1024)} MB(${r(j.totalmem()/1024/1024)} MB)`),a){case"init":if(N(`yolk ${a} \u5f00\u59cb`),l)if(d){const e=".yolk",t=S.join($,e);p.existsSync(t)&&x(t,(()=>{N(`\u7f13\u5b58\u5220\u9664 success! ${t}`)})),L({command:"git",args:["clone","-b","master","--depth","1",d,e].concat(m)}),K($,t)}else I("--clone \u6a21\u5f0f\u5fc5\u987b\u6709--template");else A($);break;case"start":U()?W()?L({command:"taro",args:["build","--type","tt","--watch"].concat(m)}):z()?L({command:"taro",args:["build","--type","alipay","--watch"].concat(m)}):L({command:"taro",args:["build","--type","weapp","--watch"].concat(m)}):u?L({command:"dumi",args:["dev"].concat(m)}):V()?L({command:"icejs",args:["start","--config",X()].concat(m)}):G()?L({command:"max",args:["dev"].concat(m)}):L({command:"umi",args:["dev"].concat(m)});break;case"build":U()?W()?L({command:"taro",args:["build","--type","tt"].concat(m)}):z()?L({command:"taro",args:["build","--type","alipay"].concat(m)}):L({command:"taro",args:["build","--type","weapp"].concat(m)}):u?L({command:"dumi",args:["build"].concat(m)}):V()?L({command:"icejs",args:["build","--config",X()].concat(m)}):G()?L({command:"max",args:["setup"].concat(m),complete:()=>L({command:"max",args:["build"].concat(m)}),exit:!1}):L({command:"umi",args:["build"].concat(m)});break;case"pre-commit":se();break;case"test":L({command:"umi-test",args:["--no-cache","--update-snapshot","--runInBand","--detectOpenHandles"].concat(m)});break;case"miniapp-upload":case"miniprogram-upload":if(U())if(W());else if(z());else{const e=oe(t),r=e.appid,i=e.options;Q(`${r}\u4e0a\u4f20\u5f00\u59cb`),y.upload(c(c({},o(i,["project","version","desc","setting","robot"])),{},{onProgressUpdate:e=>{if(s(e))Q(`task: ${e}`);else{const t=e.status,s=e.message;Q(`task(${t}): ${s}`)}}})).then((()=>{N(`${r}\u4e0a\u4f20\u5b8c\u6210`)}))}break;case"miniapp-preview":case"miniprogram-preview":if(U())if(W());else if(z());else{const e=oe(t),r=e.appid,i=e.options;Q(`${r}\u4e0a\u4f20\u9884\u89c8\u5f00\u59cb`),y.preview(c(c({},o(i,["project","version","desc","setting","robot","qrcodeFormat","qrcodeOutputDest","pagePath","searchQuery"])),{},{onProgressUpdate:e=>{if(s(e))Q(`task: ${e}`);else{const t=e.status,s=e.message;Q(`task(${t}): ${s}`)}}})).then((()=>{N(`${r}\u4e0a\u4f20\u9884\u89c8\u5b8c\u6210`)}))}break;default:_()}})).parse(process.argv):_()};re();
2
+ import e from"@babel/runtime/helpers/toArray";import t from"@babel/runtime/helpers/defineProperty";import s from"lodash/isString";import n from"lodash/pick";import o from"lodash/floor";import i from"lodash/chunk";function r(e,t){var s=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),s.push.apply(s,n)}return s}function c(e){for(var s=1;s<arguments.length;s++){var n=null!=arguments[s]?arguments[s]:{};s%2?r(Object(n),!0).forEach((function(s){t(e,s,n[s])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):r(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}import{execSync as a,spawn as m}from"child_process";import l from"commander";import p from"fs";import u from"glob";import d from"inquirer";import f from"minimatch";import*as y from"miniprogram-ci";import g from"mkdirp";import h from"mustache";import b from"ora";import j from"os";import x from"path";import{format as S}from"prettier";import $ from"rimraf";import v from"../package.json";const k=require("staged-git-files"),w=process.cwd(),P="##### CREATED BY YOLK #####",O={ts:"typescript",tsx:"typescript",less:"less",sass:"scss",scss:"scss",css:"css"},F="utf-8",E=60,B=["**/node_modules/**","**/.umi/**","**/.umi-production/**","**/.ice/**","**/build/**","**/dist/**","**/lib/**","**/es/**","**/public/**","**/assets/**","**/h5+app/**","**/android/**","**/ios/**","**/mock/**","**/yolk*/**"],D=b(),I=e=>e&&D.warn(Buffer.from(e,F).toString()),q=e=>e&&D.fail(Buffer.from(e,F).toString()),N=e=>e&&D.succeed(Buffer.from(e,F).toString()),Q=e=>e&&D.info(Buffer.from(e,F).toString()),R=e=>"win32"===process.platform?`${e}.cmd`:e,T=()=>{N("yolk complete!"),process.exit(0)},_=()=>{I("yolk break!"),process.exit(0)},L=({command:e,args:t,complete:s,close:n,exit:o=!0})=>{const i=m(R(e),t||[],{stdio:"inherit"}).on("close",(e=>{e?(n&&n(),q("yolk close!"),process.exit(e)):(s&&s(),o&&T())}));process.on("SIGINT",(()=>{l.runningCommand&&l.runningCommand.kill("SIGKILL"),i.kill(),_()}))},A=(e,t,s)=>{d.prompt([{type:"list",name:"type",message:"\u9009\u62e9\u6a21\u7248",default:"web",choices:[{name:"web template(umi framework)",value:"umi-web"},{name:"web big screen template(umi framework)",value:"umi-web-screen"},{name:"mobile template(umi framework)",value:"umi-mobile"},{name:"mobile HBuilderX h5+app template(umi framework)",value:"umi-mobile-h5+app"},{name:"mobile native template(umi framework)",value:"umi-mobile-native"},{name:"web template(ice framework)",value:"ice-web"},{name:"web big screen template(ice framework)",value:"ice-web-screen"},{name:"mobile template(ice framework)",value:"ice-mobile"},{name:"mobile HBuilderX h5+app template(ice framework)",value:"ice-mobile-h5+app"},{name:"mobile native template(ice framework)",value:"ice-mobile-native"},{name:"miniprogram template",value:"miniprogram"}]},{type:"input",name:"projectName",message:"\u9879\u76ee\u540d\u79f0",default:x.basename(x.basename(process.cwd()))},{type:"list",name:"dependenciesInstallType",message:"\u9009\u62e9\u4f9d\u8d56\u5b89\u88c5\u65b9\u5f0f",default:"default",choices:[{name:"\u9ed8\u8ba4\u5b89\u88c5",value:"default"},{name:"\u8df3\u8fc7\u5b89\u88c5",value:!1},{name:"pnpm install",value:"pnpm"},{name:"yarn install",value:"yarn"},{name:"npm install",value:"npm"}]}]).then((n=>{const o={projectName:n.projectName,dependenciesInstallType:n.dependenciesInstallType,yolkVersion:v.version};t||(t=x.join(__dirname,`../templates/${n.type}`)),N(`\u590d\u5236\u6a21\u7248 ${x.basename(t)}`);const i=u.sync("**/*",{cwd:t,dot:!0,ignore:["**/node_modules/**","**/.git/**","**/.DS_Store","**/.idea/**"]});if(i.forEach((s=>{if(!t)return;const n=x.join(t,s);if(!p.statSync(n).isDirectory())if(s.endsWith(".tpl")){const t=p.readFileSync(n,F),i=x.join(e,s.replace(/\.tpl$/u,"")),r=h.render(t,o);g.sync(x.dirname(i)),N(`\u521b\u5efa ${x.relative(e,i)}`),p.writeFileSync(i,r,F)}else{N(`\u521b\u5efa ${s}`);const t=x.join(e,s);g.sync(x.dirname(t)),p.copyFileSync(n,t)}})),N("\u590d\u5236\u6a21\u7248 success!"),s&&p.existsSync(t)&&$(t,(()=>{N(`\u7f13\u5b58\u5220\u9664 success! ${x.basename(t||"")}`)})),n.dependenciesInstallType)switch(N("\u521d\u59cb\u5316\u4f9d\u8d56\u5305"),n.dependenciesInstallType){case"default":case"pnpm":L({command:"pnpm",args:["install"]});break;case"yarn":L({command:"yarn",args:["install"]});break;case"npm":L({command:"npm",args:["install"]});break;default:}N("\u53ef\u67e5\u9605<<https://303394539.github.io/yolk-docs/>>\u4e86\u89e3\u76f8\u5173\u6587\u6863")}))},K=(e,t)=>A(e,t,!0),J=()=>{const e=u.sync("*.yolkrc*",{cwd:w,dot:!0});if(!e.length)return{};const t=x.join(w,e[0]);if(!p.existsSync(t))return{};try{return JSON.parse(p.readFileSync(t,F))||{}}catch(s){return q(s.message||".yolkrc\u8f6c\u6362\u9519\u8bef"),{}}},C=()=>{const e=x.join(w,".prettierrc");if(p.existsSync(e))try{return JSON.parse(p.readFileSync(e,F))||{}}catch(t){return q(t.message||".prettierrc\u8f6c\u6362\u9519\u8bef"),{}}return require("./.prettierrc")},H=()=>{const e=x.join(w,"project.config.json");if(!p.existsSync(e))return{};try{return JSON.parse(p.readFileSync(e,F))||{}}catch(t){return q(t.message||"project.config.json\u8f6c\u6362\u9519\u8bef"),{}}},M=()=>{const e=x.join(w,"package.json");if(!p.existsSync(e))return{};try{return JSON.parse(p.readFileSync(e,F))||{}}catch(t){return q(t.message||"package.json\u8f6c\u6362\u9519\u8bef"),{}}},U=()=>p.existsSync(x.join(w,"project.config.json")),V=()=>p.existsSync(x.join(w,".icerc.ts"))||p.existsSync(x.join(w,".icerc.js"))||p.existsSync(x.join(w,".ice.ts"))||p.existsSync(x.join(w,".ice.js")),G=()=>{let e=p.existsSync(x.join(w,"node_modules/.bin/max"));if(!e)try{e=p.existsSync(require.resolve("@umijs/max"))}catch(t){}if(!e)try{e=/umi@4\.(\d+)\.(\d+)/u.test(a("umi -v").toString())}catch(t){}if(!e){const s=x.join(w,"node_modules","umi","package.json");if(p.existsSync(s))try{const t=JSON.parse(p.readFileSync(s,F))||{};e=t.version&&+t.version.split(".")[0]>3}catch(t){}}return e},X=()=>p.existsSync(x.join(w,".icerc.ts"))?".icerc.ts":p.existsSync(x.join(w,".icerc.js"))?".icerc.js":p.existsSync(x.join(w,".ice.ts"))?".ice.ts":".ice.js",Y=()=>{const e=x.join(w,"project.config.json");if(p.existsSync(e)){const t=require(e);return t.appid}return""},W=()=>p.existsSync(x.join(w,"project.tt.json"))&&0===Y().indexOf("tt"),z=()=>0===Y().indexOf("20"),Z=()=>{const e=J();let t="";try{t=require.resolve("@baic/eslint-config-yolk")}catch(o){}const s=u.sync("*.eslintrc*",{cwd:w,dot:!0}),n=s[0];return!1===e.strict&&n&&p.existsSync(n)?n:t},ee=()=>{const e=J();let t="";try{t=require.resolve("@baic/stylelint-config-yolk")}catch(o){}const s=u.sync("*.stylelintrc*",{cwd:w,dot:!0}),n=s[0];return!1===e.strict&&n&&p.existsSync(n)?n:t},te=()=>{const e=x.join(w,".git/"),t=x.join(w,".git/hooks"),s=x.join(t,"pre-commit"),n=p.existsSync(e),o=p.existsSync(s),i=o&&p.readFileSync(s,F).includes(P);if(n&&(!o||!i)){g.sync(t),p.writeFileSync(s,["#!/usr/bin/env bash","npx yolk pre-commit","RESULT=$?","[ $RESULT -ne 0 ] && exit 1","exit 0",P].join(j.EOL),F);try{p.chmodSync(s,"777")}catch(r){q(`chmod ${s} failed: ${r.message}`)}N("Create pre-commit hook")}},se=()=>{const e=J(),t=!1!==e.strict,s=e.eslintIgnore,n=e.stylelintIgnore;k().then((e=>{const o=s=>new Promise(((o,r)=>{const a=ee();if(a){const m=e.map((e=>e.filename)).filter((e=>/^(src|tests)/iu.test(e))).filter((e=>({css:/\.cs{2}$/iu,less:/\.les{2}$/iu,sass:/\.sas{2}$/iu,scss:/\.scs{2}$/iu}[s].test(e)))).filter((e=>B.every((t=>!f(e,t,{matchBase:!0}))))).filter((e=>"string"===typeof n?!f(e,n,{matchBase:!0}):n instanceof RegExp?!n.test(e):!Array.isArray(n)||n.every((t=>"string"===typeof t?!f(e,t,{matchBase:!0}):!(t instanceof RegExp)||!t.test(e))))).map((e=>{const t=x.join(w,e);return p.existsSync(t)?t:null})).filter((e=>!!e));if(m.length)if(m.forEach((e=>{if(e&&p.existsSync(e)){const t=x.extname(e).replace(/^\./u,""),s=p.readFileSync(e,F),n=S(s,c({parser:O[t]},C()));p.writeFileSync(e,n,F)}})),N(`${s} file(count: ${m.length}) prettier success!`),m.length>=E){const e=[];i(m,20).forEach((n=>{e.push(new Promise(((e,o)=>{L({command:"stylelint",args:[t?"--ignore-disables":"","--allow-empty-input","--custom-syntax",`postcss-${s}`,"--config",a,...n],complete:e,close:o,exit:!1})})))}));const n=process.getMaxListeners(),c=i(e,n?n/2:2);let l=0;const p=()=>{l<c.length?Promise.all(c[l]).then((()=>{l++,p()})).catch(r):(N(`${s} file(count: ${m.length}) stylelint success!`),o())};p()}else m.length&&L({command:"stylelint",args:[t?"--ignore-disables":"","--allow-empty-input","--custom-syntax",`postcss-${s}`,"--config",a,...m],complete:()=>{N(`${s} file(count: ${m.length}) stylelint success!`),o()},close:r,exit:!1});else o()}else I("\u6ca1\u6709 stylelintrc \u6587\u4ef6"),o()})),r=n=>new Promise(((o,r)=>{const a=Z();if(a){const m=e.map((e=>e.filename)).filter((e=>/^(src|tests)/iu.test(e))).filter((e=>({js:/\.js$/iu,jsx:/\.jsx$/iu,ts:/\.ts$/iu,tsx:/\.tsx$/iu}[n].test(e)))).map((e=>{const t=x.join(w,e);return p.existsSync(t)?t:null})).filter((e=>!!e)).filter((e=>B.every((t=>!f(e,t,{matchBase:!0}))))).filter((e=>"string"===typeof s?!f(e,s,{matchBase:!0}):s instanceof RegExp?!s.test(e):!Array.isArray(s)||s.every((t=>"string"===typeof t?!f(e,t,{matchBase:!0}):!(t instanceof RegExp)||!t.test(e)))));if(m.length)if(m.forEach((e=>{if(e&&p.existsSync(e)){const t=x.extname(e).replace(/^\./u,""),s=p.readFileSync(e,F),n=S(s,c({parser:O[t]},C()));p.writeFileSync(e,n,F)}})),N(`${n} file(count: ${m.length}) prettier success!`),m.length>=E){const e=[];i(m,20).forEach((s=>{e.push(new Promise(((e,n)=>{L({command:"eslint",args:[t?"--no-inline-config --no-ignore":"","--no-error-on-unmatched-pattern","--config",a,...s],complete:e,close:n,exit:!1})})))}));const s=process.getMaxListeners(),c=i(e,s?s/2:2);let l=0;const p=()=>{l<c.length?Promise.all(c[l]).then((()=>{l++,p()})).catch(r):(N(`${n} file(count: ${m.length}) eslint success!`),o())};p()}else m.length&&L({command:"eslint",args:[t?"--no-inline-config --no-ignore":"","--no-error-on-unmatched-pattern","--config",a,...m],complete:()=>{N(`${n} file(count: ${m.length}) eslint success!`),o()},close:r,exit:!1});else o()}else I("\u6ca1\u6709 eslintrc \u6587\u4ef6"),o()}));I("\u7edf\u4e00\u4ee3\u7801\u89c4\u8303\uff0c\u8fdb\u884c\u4e25\u683c\u7684\u8bed\u6cd5\u68c0\u67e5\u3002"),t&&(I("git commit \u7981\u6b62 lint \u7684 ignore \u884c\u4e3a"),n&&I(`\u901a\u8fc7 .yolkrc \u914d\u7f6e stylelintIgnore: ${n}\u3002`),s&&I(`\u901a\u8fc7 .yolkrc \u914d\u7f6e eslintIgnore: ${s}\u3002`)),o("css").then((()=>o("less"))).then((()=>o("sass"))).then((()=>o("scss"))).then((()=>r("js"))).then((()=>r("jsx"))).then((()=>r("ts"))).then((()=>r("tsx"))).then(T)}))},ne=({mProject:e,mPrivateKeyPath:t,mVersion:s,mDesc:n,mRobot:o,mQrcodeFormat:i,mQrcodeOutputDest:r,mPagePath:c,mSearchQuery:m})=>{const l=p.existsSync(x.join(w,".git"))?a("git log -1 --pretty=format:%H").toString():"",u=H(),d=u.appid,f=e||x.join(w,"dist"),g=t||x.join(w,`private.${d}.key`);if(p.existsSync(f)){if(p.existsSync(g)){const e=M(),t=s||e.version||u.version||"1.0.0",a=n||e.description||u.description,p=`version: ${t};${l?` commit: ${l};`:""}${a?` description: ${a};`:""}`;l&&Q(`commit: ${l}`),Q(`dist: ${f}`),Q(`key: ${g}`),Q(`appid: ${d}`),Q(`version: ${t}`),Q(`desc: ${p}`);const h=new y.Project({appid:d,type:"miniProgram",projectPath:f,privateKeyPath:g,ignores:["node_modules/**/*","**/*.txt","**/*.key","**/*.less","**/*.sass","**/*.scss","**/*.css","**/*.jsx","**/*.ts","**/*.tsx","**/*.md"]});return{appid:d,options:{project:h,version:t,desc:p,setting:u.setting,robot:o,qrcodeFormat:i,qrcodeOutputDest:r,pagePath:c,searchQuery:m}}}throw Error(`\u6ca1\u6709\u627e\u5230\u4e0a\u4f20\u5bc6\u94a5(${g})`)}throw Error(`\u6ca1\u6709\u627e\u5230dist\u76ee\u5f55(${f})`)},oe=()=>{te(),process.argv.length>2?l.version(v.version).usage("[command] [options]").option("--clone","\u901a\u8fc7git clone\u62c9\u53d6\u6a21\u7248").option("--template <template>","\u6a21\u7248\u540d\u79f0\u6216\u8005clone\u6a21\u5f0f\u7684git\u5730\u5740").option("--docs","\u542f\u52a8\u6587\u6863\u6a21\u5f0f").option("--mProject <project>","\u5c0f\u7a0b\u5e8f\u4e0a\u4f20\u5de5\u7a0b\u76ee\u5f55").option("--mPrivateKeyPath <privateKeyPath>","\u5c0f\u7a0b\u5e8f\u4e0a\u4f20key\u6587\u4ef6").option("--mVersion <version>","\u5c0f\u7a0b\u5e8f\u4e0a\u4f20\u7248\u672c\u53f7").option("--mDesc <desc>","\u5c0f\u7a0b\u5e8f\u4e0a\u4f20\u63cf\u8ff0").option("--mRobot <robot>","\u5c0f\u7a0b\u5e8f\u4e0a\u4f20ci\u673a\u5668\u4eba1~30").option("--mQrcodeFormat <qrcodeFormat>",'\u5c0f\u7a0b\u5e8f\u9884\u89c8\u8fd4\u56de\u4e8c\u7ef4\u7801\u6587\u4ef6\u7684\u683c\u5f0f "image" \u6216 "base64"\uff0c \u9ed8\u8ba4\u503c "terminal" \u4f9b\u8c03\u8bd5\u7528').option("--mQrcodeOutputDest <qrcodeOutputDest>","\u5c0f\u7a0b\u5e8f\u9884\u89c8\u4e8c\u7ef4\u7801\u6587\u4ef6\u4fdd\u5b58\u8def\u5f84").option("--mPagePath <pagePath>","\u5c0f\u7a0b\u5e8f\u9884\u89c8\u9884\u89c8\u9875\u9762\u8def\u5f84").option("--mSearchQuery <searchQuery>","\u5c0f\u7a0b\u5e8f\u9884\u89c8\u9884\u89c8\u9875\u9762\u8def\u5f84\u542f\u52a8\u53c2\u6570").action(((t,i)=>{const r=e(i),a=r[0],m=r.slice(1),l=t.clone,u=t.template,d=t.docs;if(a)switch(Q(`yolk version: ${v.version}`),Q(`node version: ${process.version}`),Q(`platform: ${j.platform()}`),Q(`memory: ${o(j.freemem()/1024/1024)} MB(${o(j.totalmem()/1024/1024)} MB)`),a){case"init":if(N(`yolk ${a} \u5f00\u59cb`),l)if(u){const e=".yolk",t=x.join(w,e);p.existsSync(t)&&$(t,(()=>{N(`\u7f13\u5b58\u5220\u9664 success! ${t}`)})),L({command:"git",args:["clone","-b","master","--depth","1",u,e].concat(m)}),K(w,t)}else q("--clone \u6a21\u5f0f\u5fc5\u987b\u6709--template");else A(w);break;case"start":U()?W()?L({command:"taro",args:["build","--type","tt","--watch"].concat(m)}):z()?L({command:"taro",args:["build","--type","alipay","--watch"].concat(m)}):L({command:"taro",args:["build","--type","weapp","--watch"].concat(m)}):d?L({command:"dumi",args:["dev"].concat(m)}):V()?L({command:"icejs",args:["start","--config",X()].concat(m)}):G()?L({command:"max",args:["dev"].concat(m)}):L({command:"umi",args:["dev"].concat(m)});break;case"build":U()?W()?L({command:"taro",args:["build","--type","tt"].concat(m)}):z()?L({command:"taro",args:["build","--type","alipay"].concat(m)}):L({command:"taro",args:["build","--type","weapp"].concat(m)}):d?L({command:"dumi",args:["build"].concat(m)}):V()?L({command:"icejs",args:["build","--config",X()].concat(m)}):G()?L({command:"max",args:["setup"].concat(m),complete:()=>L({command:"max",args:["build"].concat(m)}),exit:!1}):L({command:"umi",args:["build"].concat(m)});break;case"pre-commit":se();break;case"test":L({command:"umi-test",args:["--no-cache","--update-snapshot","--runInBand","--detectOpenHandles"].concat(m)});break;case"miniapp-upload":case"miniprogram-upload":if(U())if(W());else if(z());else{const e=ne(t),o=e.appid,i=e.options;Q(`${o}\u4e0a\u4f20\u5f00\u59cb`),y.upload(c(c({},n(i,["project","version","desc","setting","robot"])),{},{onProgressUpdate:e=>{if(s(e))Q(`task: ${e}`);else{const t=e.status,s=e.message;Q(`task(${t}): ${s}`)}}})).then((()=>{N(`${o}\u4e0a\u4f20\u5b8c\u6210`)}))}break;case"miniapp-preview":case"miniprogram-preview":if(U())if(W());else if(z());else{const e=ne(t),o=e.appid,i=e.options;Q(`${o}\u4e0a\u4f20\u9884\u89c8\u5f00\u59cb`),y.preview(c(c({},n(i,["project","version","desc","setting","robot","qrcodeFormat","qrcodeOutputDest","pagePath","searchQuery"])),{},{onProgressUpdate:e=>{if(s(e))Q(`task: ${e}`);else{const t=e.status,s=e.message;Q(`task(${t}): ${s}`)}}})).then((()=>{N(`${o}\u4e0a\u4f20\u9884\u89c8\u5b8c\u6210`)}))}break;default:_()}})).parse(process.argv):_()};oe();
package/lib/yolk.js CHANGED
@@ -1,2 +1,2 @@
1
1
  #! /usr/bin/env node
2
- "use strict";var e=require("@babel/runtime/helpers/interopRequireDefault");function t(){const n=e(require("@babel/runtime/helpers/toArray"));return t=function(){return n},n}function n(){const t=e(require("@babel/runtime/helpers/defineProperty"));return n=function(){return t},t}function r(){const t=e(require("lodash/isString"));return r=function(){return t},t}function a(){const t=e(require("lodash/pick"));return a=function(){return t},t}function i(){const t=e(require("lodash/floor"));return i=function(){return t},t}function o(){const t=e(require("lodash/chunk"));return o=function(){return t},t}function s(){const e=require("child_process");return s=function(){return e},e}function c(){const t=e(require("commander"));return c=function(){return t},t}function u(){const t=e(require("fs"));return u=function(){return t},t}function l(){const t=e(require("glob"));return l=function(){return t},t}function f(){const t=e(require("inquirer"));return f=function(){return t},t}function d(){const t=e(require("minimatch"));return d=function(){return t},t}function m(){const e=w(require("miniprogram-ci"));return m=function(){return e},e}function p(){const t=e(require("mkdirp"));return p=function(){return t},t}function y(){const t=e(require("mustache"));return y=function(){return t},t}function g(){const t=e(require("ora"));return g=function(){return t},t}function h(){const t=e(require("os"));return h=function(){return t},t}function b(){const t=e(require("path"));return b=function(){return t},t}function j(){const e=require("prettier");return j=function(){return e},e}function v(){const t=e(require("rimraf"));return v=function(){return t},t}var S=e(require("../package.json"));function x(e){if("function"!==typeof WeakMap)return null;var t=new WeakMap,n=new WeakMap;return(x=function(e){return e?n:t})(e)}function w(e,t){if(!t&&e&&e.__esModule)return e;if(null===e||"object"!==typeof e&&"function"!==typeof e)return{default:e};var n=x(t);if(n&&n.has(e))return n.get(e);var r={},a=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var i in e)if("default"!==i&&Object.prototype.hasOwnProperty.call(e,i)){var o=a?Object.getOwnPropertyDescriptor(e,i):null;o&&(o.get||o.set)?Object.defineProperty(r,i,o):r[i]=e[i]}return r.default=e,n&&n.set(e,r),r}function k(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function $(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?k(Object(r),!0).forEach((function(t){(0,n().default)(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):k(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}const O=require("staged-git-files"),P=process.cwd(),q="##### CREATED BY YOLK #####",F={ts:"typescript",tsx:"typescript",less:"less",sass:"scss",scss:"scss",css:"css"},E="utf-8",D=60,B=["**/node_modules/**","**/.umi/**","**/.umi-production/**","**/.ice/**","**/build/**","**/dist/**","**/lib/**","**/es/**","**/public/**","**/assets/**","**/h5+app/**","**/android/**","**/ios/**","**/mock/**","**/yolk*/**"],I=(0,g().default)(),_=e=>e&&I.warn(Buffer.from(e,E).toString()),R=e=>e&&I.fail(Buffer.from(e,E).toString()),N=e=>e&&I.succeed(Buffer.from(e,E).toString()),Q=e=>e&&I.info(Buffer.from(e,E).toString()),T=e=>"win32"===process.platform?`${e}.cmd`:e,L=()=>{N("yolk complete!"),process.exit(0)},M=()=>{_("yolk break!"),process.exit(0)},A=({command:e,args:t,complete:n,close:r,exit:a=!0})=>{const i=(0,s().spawn)(T(e),t||[],{stdio:"inherit"}).on("close",(e=>{e?(r&&r(),R("yolk close!"),process.exit(e)):(n&&n(),a&&L())}));process.on("SIGINT",(()=>{c().default.runningCommand&&c().default.runningCommand.kill("SIGKILL"),i.kill(),M()}))},K=(e,t,n)=>{f().default.prompt([{type:"list",name:"type",message:"\u9009\u62e9\u6a21\u7248",default:"web",choices:[{name:"web template(umi framework)",value:"umi-web"},{name:"web big screen template(umi framework)",value:"umi-web-screen"},{name:"mobile template(umi framework)",value:"umi-mobile"},{name:"mobile HBuilderX h5+app template(umi framework)",value:"umi-mobile-h5+app"},{name:"mobile native template(umi framework)",value:"umi-mobile-native"},{name:"web template(ice framework)",value:"ice-web"},{name:"web big screen template(ice framework)",value:"ice-web-screen"},{name:"mobile template(ice framework)",value:"ice-mobile"},{name:"mobile HBuilderX h5+app template(ice framework)",value:"ice-mobile-h5+app"},{name:"mobile native template(ice framework)",value:"ice-mobile-native"},{name:"miniprogram template",value:"miniprogram"}]},{type:"input",name:"projectName",message:"\u9879\u76ee\u540d\u79f0",default:b().default.basename(b().default.basename(process.cwd()))},{type:"list",name:"dependenciesInstallType",message:"\u9009\u62e9\u4f9d\u8d56\u5b89\u88c5\u65b9\u5f0f",default:"default",choices:[{name:"\u9ed8\u8ba4\u5b89\u88c5",value:"default"},{name:"\u8df3\u8fc7\u5b89\u88c5",value:!1},{name:"pnpm install",value:"pnpm"},{name:"yarn install",value:"yarn"},{name:"npm install",value:"npm"}]}]).then((r=>{const a={projectName:r.projectName,dependenciesInstallType:r.dependenciesInstallType,yolkVersion:S.default.version};t||(t=b().default.join(__dirname,`../templates/${r.type}`)),N(`\u590d\u5236\u6a21\u7248 ${b().default.basename(t)}`);const i=l().default.sync("**/*",{cwd:t,dot:!0,ignore:["**/node_modules/**","**/.git/**","**/.DS_Store","**/.idea/**"]});if(i.forEach((n=>{if(!t)return;const r=b().default.join(t,n);if(!u().default.statSync(r).isDirectory())if(n.endsWith(".tpl")){const t=u().default.readFileSync(r,E),i=b().default.join(e,n.replace(/\.tpl$/u,"")),o=y().default.render(t,a);p().default.sync(b().default.dirname(i)),N(`\u521b\u5efa ${b().default.relative(e,i)}`),u().default.writeFileSync(i,o,E)}else{N(`\u521b\u5efa ${n}`);const t=b().default.join(e,n);p().default.sync(b().default.dirname(t)),u().default.copyFileSync(r,t)}})),N("\u590d\u5236\u6a21\u7248 success!"),n&&u().default.existsSync(t)&&(0,v().default)(t,(()=>{N(`\u7f13\u5b58\u5220\u9664 success! ${b().default.basename(t||"")}`)})),r.dependenciesInstallType)switch(N("\u521d\u59cb\u5316\u4f9d\u8d56\u5305"),r.dependenciesInstallType){case"default":case"pnpm":A({command:"pnpm",args:["install"]});break;case"yarn":A({command:"yarn",args:["install"]});break;case"npm":A({command:"npm",args:["install"]});break;default:}N("\u53ef\u67e5\u9605<<https://303394539.github.io/yolk-docs/>>\u4e86\u89e3\u76f8\u5173\u6587\u6863")}))},J=(e,t)=>K(e,t,!0),C=()=>{const e=l().default.sync("*.yolkrc*",{cwd:P,dot:!0});if(!e.length)return{};const t=b().default.join(P,e[0]);if(!u().default.existsSync(t))return{};try{return JSON.parse(u().default.readFileSync(t,E))||{}}catch(n){return R(n.message||".yolkrc\u8f6c\u6362\u9519\u8bef"),{}}},H=()=>{const e=b().default.join(P,".prettierrc");if(u().default.existsSync(e))try{return JSON.parse(u().default.readFileSync(e,E))||{}}catch(t){return R(t.message||".prettierrc\u8f6c\u6362\u9519\u8bef"),{}}return require("./.prettierrc")},U=()=>{const e=b().default.join(P,"project.config.json");if(!u().default.existsSync(e))return{};try{return JSON.parse(u().default.readFileSync(e,E))||{}}catch(t){return R(t.message||"project.config.json\u8f6c\u6362\u9519\u8bef"),{}}},W=()=>{const e=b().default.join(P,"package.json");if(!u().default.existsSync(e))return{};try{return JSON.parse(u().default.readFileSync(e,E))||{}}catch(t){return R(t.message||"package.json\u8f6c\u6362\u9519\u8bef"),{}}},V=()=>u().default.existsSync(b().default.join(P,"project.config.json")),G=()=>u().default.existsSync(b().default.join(P,".icerc.ts"))||u().default.existsSync(b().default.join(P,".icerc.js"))||u().default.existsSync(b().default.join(P,".ice.ts"))||u().default.existsSync(b().default.join(P,".ice.js")),X=()=>{let e=u().default.existsSync(b().default.join(P,"node_modules/.bin/max"));if(!e)try{e=u().default.existsSync(require.resolve("@umijs/max"))}catch(t){}if(!e)try{e=/umi@4\.(\d+)\.(\d+)/u.test((0,s().execSync)("umi -v").toString())}catch(t){}if(!e){const n=b().default.join(P,"node_modules","umi","package.json");if(u().default.existsSync(n))try{const t=JSON.parse(u().default.readFileSync(n,E))||{};e=t.version&&+t.version.split(".")[0]>3}catch(t){}}return e},Y=()=>u().default.existsSync(b().default.join(P,".icerc.ts"))?".icerc.ts":u().default.existsSync(b().default.join(P,".icerc.js"))?".icerc.js":u().default.existsSync(b().default.join(P,".ice.ts"))?".ice.ts":".ice.js",z=()=>{const e=b().default.join(P,"project.config.json");if(u().default.existsSync(e)){const t=require(e);return t.appid}return""},Z=()=>u().default.existsSync(b().default.join(P,"project.tt.json"))&&0===z().indexOf("tt"),ee=()=>0===z().indexOf("20"),te=()=>{const e=C();let t="";try{t=require.resolve("@baic/eslint-config-yolk")}catch(a){}const n=l().default.sync("*.eslintrc*",{cwd:P,dot:!0}),r=n[0];return!1===e.strict&&r&&u().default.existsSync(r)?r:t},ne=()=>{const e=C();let t="";try{t=require.resolve("@baic/stylelint-config-yolk")}catch(a){}const n=l().default.sync("*.stylelintrc*",{cwd:P,dot:!0}),r=n[0];return!1===e.strict&&r&&u().default.existsSync(r)?r:t},re=()=>{const e=b().default.join(P,".git/"),t=b().default.join(P,".git/hooks"),n=b().default.join(t,"pre-commit"),r=u().default.existsSync(e),a=u().default.existsSync(n),i=a&&u().default.readFileSync(n,E).includes(q);if(r&&(!a||!i)){p().default.sync(t),u().default.writeFileSync(n,["#!/usr/bin/env bash","npx yolk pre-commit","RESULT=$?","[ $RESULT -ne 0 ] && exit 1","exit 0",q].join(h().default.EOL),E);try{u().default.chmodSync(n,"777")}catch(o){R(`chmod ${n} failed: ${o.message}`)}N("Create pre-commit hook")}},ae=()=>{const e=C(),t=!1!==e.strict,n=e.eslintIgnore,r=e.stylelintIgnore;O().then((e=>{const a=new Promise(((n,a)=>{const i=ne();if(i){const s=e.map((e=>e.filename)).filter((e=>/^(src|tests)/iu.test(e))).filter((e=>/\.(le|sa|sc|c)s{2}$/iu.test(e))).filter((e=>B.every((t=>!(0,d().default)(e,t,{matchBase:!0}))))).filter((e=>"string"===typeof r?!(0,d().default)(e,r,{matchBase:!0}):r instanceof RegExp?!r.test(e):!Array.isArray(r)||r.every((t=>"string"===typeof t?!(0,d().default)(e,t,{matchBase:!0}):!(t instanceof RegExp)||!t.test(e))))).map((e=>{const t=b().default.join(P,e);return u().default.existsSync(t)?t:null})).filter((e=>!!e));if(s.forEach((e=>{if(e&&u().default.existsSync(e)){const t=b().default.extname(e).replace(/^\./u,""),n=u().default.readFileSync(e,E),r=(0,j().format)(n,$({parser:F[t]},H()));u().default.writeFileSync(e,r,E)}})),N("style prettier success!"),s.length>=D){const e=[];(0,o().default)(s,20).forEach((n=>{e.push(new Promise(((e,r)=>{A({command:"stylelint",args:[t?"--ignore-disables":"","--allow-empty-input","--config",i,...n],complete:e,close:r,exit:!1})})))}));const r=process.getMaxListeners(),c=(0,o().default)(e,r?r/2:2);let u=0;const l=()=>{u<c.length?Promise.all(c[u]).then((()=>{u++,l()})).catch(a):n()};l()}else s.length&&A({command:"stylelint",args:[t?"--ignore-disables":"","--allow-empty-input","--config",i,...s],complete:n,close:a,exit:!1})}else n()})),i=()=>{const r=e.map((e=>e.filename)).filter((e=>/^(src|tests)/iu.test(e))).filter((e=>/\.([t|j]sx?)$/iu.test(e))).map((e=>{const t=b().default.join(P,e);return u().default.existsSync(t)?t:null})).filter((e=>!!e));if(r.length){r.forEach((e=>{if(e&&u().default.existsSync(e)){const t=b().default.extname(e).replace(/^\./u,""),n=u().default.readFileSync(e,E),r=(0,j().format)(n,$({parser:F[t]},H()));u().default.writeFileSync(e,r,E)}})),N("script prettier success!");const e=te();if(e){const a=r.filter((e=>B.every((t=>!(0,d().default)(e,t,{matchBase:!0}))))).filter((e=>"string"===typeof n?!(0,d().default)(e,n,{matchBase:!0}):n instanceof RegExp?!n.test(e):!Array.isArray(n)||n.every((t=>"string"===typeof t?!(0,d().default)(e,t,{matchBase:!0}):!(t instanceof RegExp)||!t.test(e)))));if(t&&(_("git commit\u7981\u6b62eslint\u7684ignore\u65b9\u5f0f(eslint-disable\u3001.eslintrc*\u3001ignore\u7b49)\u3002"),n&&_(`\u901a\u8fc7yolkrc\u914d\u7f6eeslintIgnore\uff1a${n}\u3002`)),a.length>=D){const n=[];(0,o().default)(a,20).forEach((r=>{n.push(new Promise((n=>{A({command:"eslint",args:[t?"--no-inline-config --no-ignore":"","--no-error-on-unmatched-pattern","--config",e,...r],complete:n,exit:!1})})))}));const r=process.getMaxListeners(),i=(0,o().default)(n,r?r/2:2);let s=0;const c=()=>{s<i.length?Promise.all(i[s]).then((()=>{s++,c()})):L()};c()}else a.length&&A({command:"eslint",args:[t?"--no-inline-config --no-ignore":"","--no-error-on-unmatched-pattern","--config",e,...a]})}else _("\u6ca1\u6709eslint\u914d\u7f6e\u6587\u4ef6")}else L()};_("\u8981\u6c42\u7edf\u4e00\u4ee3\u7801\u89c4\u8303\uff0c\u8fdb\u884c\u4e25\u683c\u7684\u8bed\u6cd5\u68c0\u67e5\u3002"),a.then(i)}))},ie=({mProject:e,mPrivateKeyPath:t,mVersion:n,mDesc:r,mRobot:a,mQrcodeFormat:i,mQrcodeOutputDest:o,mPagePath:c,mSearchQuery:l})=>{const f=u().default.existsSync(b().default.join(P,".git"))?(0,s().execSync)("git log -1 --pretty=format:%H").toString():"",d=U(),p=d.appid,y=e||b().default.join(P,"dist"),g=t||b().default.join(P,`private.${p}.key`);if(u().default.existsSync(y)){if(u().default.existsSync(g)){const e=W(),t=n||e.version||d.version||"1.0.0",s=r||e.description||d.description,u=`version: ${t};${f?` commit: ${f};`:""}${s?` description: ${s};`:""}`;f&&Q(`commit: ${f}`),Q(`dist: ${y}`),Q(`key: ${g}`),Q(`appid: ${p}`),Q(`version: ${t}`),Q(`desc: ${u}`);const h=new(m().Project)({appid:p,type:"miniProgram",projectPath:y,privateKeyPath:g,ignores:["node_modules/**/*","**/*.txt","**/*.key","**/*.less","**/*.sass","**/*.scss","**/*.css","**/*.jsx","**/*.ts","**/*.tsx","**/*.md"]});return{appid:p,options:{project:h,version:t,desc:u,setting:d.setting,robot:a,qrcodeFormat:i,qrcodeOutputDest:o,pagePath:c,searchQuery:l}}}throw Error(`\u6ca1\u6709\u627e\u5230\u4e0a\u4f20\u5bc6\u94a5(${g})`)}throw Error(`\u6ca1\u6709\u627e\u5230dist\u76ee\u5f55(${y})`)},oe=()=>{re(),process.argv.length>2?c().default.version(S.default.version).usage("[command] [options]").option("--clone","\u901a\u8fc7git clone\u62c9\u53d6\u6a21\u7248").option("--template <template>","\u6a21\u7248\u540d\u79f0\u6216\u8005clone\u6a21\u5f0f\u7684git\u5730\u5740").option("--docs","\u542f\u52a8\u6587\u6863\u6a21\u5f0f").option("--mProject <project>","\u5c0f\u7a0b\u5e8f\u4e0a\u4f20\u5de5\u7a0b\u76ee\u5f55").option("--mPrivateKeyPath <privateKeyPath>","\u5c0f\u7a0b\u5e8f\u4e0a\u4f20key\u6587\u4ef6").option("--mVersion <version>","\u5c0f\u7a0b\u5e8f\u4e0a\u4f20\u7248\u672c\u53f7").option("--mDesc <desc>","\u5c0f\u7a0b\u5e8f\u4e0a\u4f20\u63cf\u8ff0").option("--mRobot <robot>","\u5c0f\u7a0b\u5e8f\u4e0a\u4f20ci\u673a\u5668\u4eba1~30").option("--mQrcodeFormat <qrcodeFormat>",'\u5c0f\u7a0b\u5e8f\u9884\u89c8\u8fd4\u56de\u4e8c\u7ef4\u7801\u6587\u4ef6\u7684\u683c\u5f0f "image" \u6216 "base64"\uff0c \u9ed8\u8ba4\u503c "terminal" \u4f9b\u8c03\u8bd5\u7528').option("--mQrcodeOutputDest <qrcodeOutputDest>","\u5c0f\u7a0b\u5e8f\u9884\u89c8\u4e8c\u7ef4\u7801\u6587\u4ef6\u4fdd\u5b58\u8def\u5f84").option("--mPagePath <pagePath>","\u5c0f\u7a0b\u5e8f\u9884\u89c8\u9884\u89c8\u9875\u9762\u8def\u5f84").option("--mSearchQuery <searchQuery>","\u5c0f\u7a0b\u5e8f\u9884\u89c8\u9884\u89c8\u9875\u9762\u8def\u5f84\u542f\u52a8\u53c2\u6570").action(((e,n)=>{const o=(0,t().default)(n),s=o[0],c=o.slice(1),l=e.clone,f=e.template,d=e.docs;if(s)switch(Q(`yolk version: ${S.default.version}`),Q(`node version: ${process.version}`),Q(`platform: ${h().default.platform()}`),Q(`memory: ${(0,i().default)(h().default.freemem()/1024/1024)} MB(${(0,i().default)(h().default.totalmem()/1024/1024)} MB)`),s){case"init":if(N(`yolk ${s} \u5f00\u59cb`),l)if(f){const e=".yolk",t=b().default.join(P,e);u().default.existsSync(t)&&(0,v().default)(t,(()=>{N(`\u7f13\u5b58\u5220\u9664 success! ${t}`)})),A({command:"git",args:["clone","-b","master","--depth","1",f,e].concat(c)}),J(P,t)}else R("--clone \u6a21\u5f0f\u5fc5\u987b\u6709--template");else K(P);break;case"start":V()?Z()?A({command:"taro",args:["build","--type","tt","--watch"].concat(c)}):ee()?A({command:"taro",args:["build","--type","alipay","--watch"].concat(c)}):A({command:"taro",args:["build","--type","weapp","--watch"].concat(c)}):d?A({command:"dumi",args:["dev"].concat(c)}):G()?A({command:"icejs",args:["start","--config",Y()].concat(c)}):X()?A({command:"max",args:["dev"].concat(c)}):A({command:"umi",args:["dev"].concat(c)});break;case"build":V()?Z()?A({command:"taro",args:["build","--type","tt"].concat(c)}):ee()?A({command:"taro",args:["build","--type","alipay"].concat(c)}):A({command:"taro",args:["build","--type","weapp"].concat(c)}):d?A({command:"dumi",args:["build"].concat(c)}):G()?A({command:"icejs",args:["build","--config",Y()].concat(c)}):X()?A({command:"max",args:["setup"].concat(c),complete:()=>A({command:"max",args:["build"].concat(c)}),exit:!1}):A({command:"umi",args:["build"].concat(c)});break;case"pre-commit":ae();break;case"test":A({command:"umi-test",args:["--no-cache","--update-snapshot","--runInBand","--detectOpenHandles"].concat(c)});break;case"miniapp-upload":case"miniprogram-upload":if(V())if(Z());else if(ee());else{const t=ie(e),n=t.appid,i=t.options;Q(`${n}\u4e0a\u4f20\u5f00\u59cb`),m().upload($($({},(0,a().default)(i,["project","version","desc","setting","robot"])),{},{onProgressUpdate:e=>{if((0,r().default)(e))Q(`task: ${e}`);else{const t=e.status,n=e.message;Q(`task(${t}): ${n}`)}}})).then((()=>{N(`${n}\u4e0a\u4f20\u5b8c\u6210`)}))}break;case"miniapp-preview":case"miniprogram-preview":if(V())if(Z());else if(ee());else{const t=ie(e),n=t.appid,i=t.options;Q(`${n}\u4e0a\u4f20\u9884\u89c8\u5f00\u59cb`),m().preview($($({},(0,a().default)(i,["project","version","desc","setting","robot","qrcodeFormat","qrcodeOutputDest","pagePath","searchQuery"])),{},{onProgressUpdate:e=>{if((0,r().default)(e))Q(`task: ${e}`);else{const t=e.status,n=e.message;Q(`task(${t}): ${n}`)}}})).then((()=>{N(`${n}\u4e0a\u4f20\u9884\u89c8\u5b8c\u6210`)}))}break;default:M()}})).parse(process.argv):M()};oe();
2
+ "use strict";var e=require("@babel/runtime/helpers/interopRequireDefault");function t(){const n=e(require("@babel/runtime/helpers/toArray"));return t=function(){return n},n}function n(){const t=e(require("@babel/runtime/helpers/defineProperty"));return n=function(){return t},t}function r(){const t=e(require("lodash/isString"));return r=function(){return t},t}function s(){const t=e(require("lodash/pick"));return s=function(){return t},t}function i(){const t=e(require("lodash/floor"));return i=function(){return t},t}function a(){const t=e(require("lodash/chunk"));return a=function(){return t},t}function o(){const e=require("child_process");return o=function(){return e},e}function c(){const t=e(require("commander"));return c=function(){return t},t}function l(){const t=e(require("fs"));return l=function(){return t},t}function u(){const t=e(require("glob"));return u=function(){return t},t}function f(){const t=e(require("inquirer"));return f=function(){return t},t}function d(){const t=e(require("minimatch"));return d=function(){return t},t}function m(){const e=$(require("miniprogram-ci"));return m=function(){return e},e}function p(){const t=e(require("mkdirp"));return p=function(){return t},t}function y(){const t=e(require("mustache"));return y=function(){return t},t}function g(){const t=e(require("ora"));return g=function(){return t},t}function h(){const t=e(require("os"));return h=function(){return t},t}function b(){const t=e(require("path"));return b=function(){return t},t}function j(){const e=require("prettier");return j=function(){return e},e}function v(){const t=e(require("rimraf"));return v=function(){return t},t}var x=e(require("../package.json"));function S(e){if("function"!==typeof WeakMap)return null;var t=new WeakMap,n=new WeakMap;return(S=function(e){return e?n:t})(e)}function $(e,t){if(!t&&e&&e.__esModule)return e;if(null===e||"object"!==typeof e&&"function"!==typeof e)return{default:e};var n=S(t);if(n&&n.has(e))return n.get(e);var r={},s=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var i in e)if("default"!==i&&Object.prototype.hasOwnProperty.call(e,i)){var a=s?Object.getOwnPropertyDescriptor(e,i):null;a&&(a.get||a.set)?Object.defineProperty(r,i,a):r[i]=e[i]}return r.default=e,n&&n.set(e,r),r}function w(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function k(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?w(Object(r),!0).forEach((function(t){(0,n().default)(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):w(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}const O=require("staged-git-files"),P=process.cwd(),q="##### CREATED BY YOLK #####",F={ts:"typescript",tsx:"typescript",less:"less",sass:"scss",scss:"scss",css:"css"},E="utf-8",D=60,B=["**/node_modules/**","**/.umi/**","**/.umi-production/**","**/.ice/**","**/build/**","**/dist/**","**/lib/**","**/es/**","**/public/**","**/assets/**","**/h5+app/**","**/android/**","**/ios/**","**/mock/**","**/yolk*/**"],I=(0,g().default)(),_=e=>e&&I.warn(Buffer.from(e,E).toString()),R=e=>e&&I.fail(Buffer.from(e,E).toString()),N=e=>e&&I.succeed(Buffer.from(e,E).toString()),Q=e=>e&&I.info(Buffer.from(e,E).toString()),T=e=>"win32"===process.platform?`${e}.cmd`:e,L=()=>{N("yolk complete!"),process.exit(0)},M=()=>{_("yolk break!"),process.exit(0)},A=({command:e,args:t,complete:n,close:r,exit:s=!0})=>{const i=(0,o().spawn)(T(e),t||[],{stdio:"inherit"}).on("close",(e=>{e?(r&&r(),R("yolk close!"),process.exit(e)):(n&&n(),s&&L())}));process.on("SIGINT",(()=>{c().default.runningCommand&&c().default.runningCommand.kill("SIGKILL"),i.kill(),M()}))},K=(e,t,n)=>{f().default.prompt([{type:"list",name:"type",message:"\u9009\u62e9\u6a21\u7248",default:"web",choices:[{name:"web template(umi framework)",value:"umi-web"},{name:"web big screen template(umi framework)",value:"umi-web-screen"},{name:"mobile template(umi framework)",value:"umi-mobile"},{name:"mobile HBuilderX h5+app template(umi framework)",value:"umi-mobile-h5+app"},{name:"mobile native template(umi framework)",value:"umi-mobile-native"},{name:"web template(ice framework)",value:"ice-web"},{name:"web big screen template(ice framework)",value:"ice-web-screen"},{name:"mobile template(ice framework)",value:"ice-mobile"},{name:"mobile HBuilderX h5+app template(ice framework)",value:"ice-mobile-h5+app"},{name:"mobile native template(ice framework)",value:"ice-mobile-native"},{name:"miniprogram template",value:"miniprogram"}]},{type:"input",name:"projectName",message:"\u9879\u76ee\u540d\u79f0",default:b().default.basename(b().default.basename(process.cwd()))},{type:"list",name:"dependenciesInstallType",message:"\u9009\u62e9\u4f9d\u8d56\u5b89\u88c5\u65b9\u5f0f",default:"default",choices:[{name:"\u9ed8\u8ba4\u5b89\u88c5",value:"default"},{name:"\u8df3\u8fc7\u5b89\u88c5",value:!1},{name:"pnpm install",value:"pnpm"},{name:"yarn install",value:"yarn"},{name:"npm install",value:"npm"}]}]).then((r=>{const s={projectName:r.projectName,dependenciesInstallType:r.dependenciesInstallType,yolkVersion:x.default.version};t||(t=b().default.join(__dirname,`../templates/${r.type}`)),N(`\u590d\u5236\u6a21\u7248 ${b().default.basename(t)}`);const i=u().default.sync("**/*",{cwd:t,dot:!0,ignore:["**/node_modules/**","**/.git/**","**/.DS_Store","**/.idea/**"]});if(i.forEach((n=>{if(!t)return;const r=b().default.join(t,n);if(!l().default.statSync(r).isDirectory())if(n.endsWith(".tpl")){const t=l().default.readFileSync(r,E),i=b().default.join(e,n.replace(/\.tpl$/u,"")),a=y().default.render(t,s);p().default.sync(b().default.dirname(i)),N(`\u521b\u5efa ${b().default.relative(e,i)}`),l().default.writeFileSync(i,a,E)}else{N(`\u521b\u5efa ${n}`);const t=b().default.join(e,n);p().default.sync(b().default.dirname(t)),l().default.copyFileSync(r,t)}})),N("\u590d\u5236\u6a21\u7248 success!"),n&&l().default.existsSync(t)&&(0,v().default)(t,(()=>{N(`\u7f13\u5b58\u5220\u9664 success! ${b().default.basename(t||"")}`)})),r.dependenciesInstallType)switch(N("\u521d\u59cb\u5316\u4f9d\u8d56\u5305"),r.dependenciesInstallType){case"default":case"pnpm":A({command:"pnpm",args:["install"]});break;case"yarn":A({command:"yarn",args:["install"]});break;case"npm":A({command:"npm",args:["install"]});break;default:}N("\u53ef\u67e5\u9605<<https://303394539.github.io/yolk-docs/>>\u4e86\u89e3\u76f8\u5173\u6587\u6863")}))},J=(e,t)=>K(e,t,!0),C=()=>{const e=u().default.sync("*.yolkrc*",{cwd:P,dot:!0});if(!e.length)return{};const t=b().default.join(P,e[0]);if(!l().default.existsSync(t))return{};try{return JSON.parse(l().default.readFileSync(t,E))||{}}catch(n){return R(n.message||".yolkrc\u8f6c\u6362\u9519\u8bef"),{}}},H=()=>{const e=b().default.join(P,".prettierrc");if(l().default.existsSync(e))try{return JSON.parse(l().default.readFileSync(e,E))||{}}catch(t){return R(t.message||".prettierrc\u8f6c\u6362\u9519\u8bef"),{}}return require("./.prettierrc")},U=()=>{const e=b().default.join(P,"project.config.json");if(!l().default.existsSync(e))return{};try{return JSON.parse(l().default.readFileSync(e,E))||{}}catch(t){return R(t.message||"project.config.json\u8f6c\u6362\u9519\u8bef"),{}}},W=()=>{const e=b().default.join(P,"package.json");if(!l().default.existsSync(e))return{};try{return JSON.parse(l().default.readFileSync(e,E))||{}}catch(t){return R(t.message||"package.json\u8f6c\u6362\u9519\u8bef"),{}}},V=()=>l().default.existsSync(b().default.join(P,"project.config.json")),G=()=>l().default.existsSync(b().default.join(P,".icerc.ts"))||l().default.existsSync(b().default.join(P,".icerc.js"))||l().default.existsSync(b().default.join(P,".ice.ts"))||l().default.existsSync(b().default.join(P,".ice.js")),X=()=>{let e=l().default.existsSync(b().default.join(P,"node_modules/.bin/max"));if(!e)try{e=l().default.existsSync(require.resolve("@umijs/max"))}catch(t){}if(!e)try{e=/umi@4\.(\d+)\.(\d+)/u.test((0,o().execSync)("umi -v").toString())}catch(t){}if(!e){const n=b().default.join(P,"node_modules","umi","package.json");if(l().default.existsSync(n))try{const t=JSON.parse(l().default.readFileSync(n,E))||{};e=t.version&&+t.version.split(".")[0]>3}catch(t){}}return e},Y=()=>l().default.existsSync(b().default.join(P,".icerc.ts"))?".icerc.ts":l().default.existsSync(b().default.join(P,".icerc.js"))?".icerc.js":l().default.existsSync(b().default.join(P,".ice.ts"))?".ice.ts":".ice.js",z=()=>{const e=b().default.join(P,"project.config.json");if(l().default.existsSync(e)){const t=require(e);return t.appid}return""},Z=()=>l().default.existsSync(b().default.join(P,"project.tt.json"))&&0===z().indexOf("tt"),ee=()=>0===z().indexOf("20"),te=()=>{const e=C();let t="";try{t=require.resolve("@baic/eslint-config-yolk")}catch(s){}const n=u().default.sync("*.eslintrc*",{cwd:P,dot:!0}),r=n[0];return!1===e.strict&&r&&l().default.existsSync(r)?r:t},ne=()=>{const e=C();let t="";try{t=require.resolve("@baic/stylelint-config-yolk")}catch(s){}const n=u().default.sync("*.stylelintrc*",{cwd:P,dot:!0}),r=n[0];return!1===e.strict&&r&&l().default.existsSync(r)?r:t},re=()=>{const e=b().default.join(P,".git/"),t=b().default.join(P,".git/hooks"),n=b().default.join(t,"pre-commit"),r=l().default.existsSync(e),s=l().default.existsSync(n),i=s&&l().default.readFileSync(n,E).includes(q);if(r&&(!s||!i)){p().default.sync(t),l().default.writeFileSync(n,["#!/usr/bin/env bash","npx yolk pre-commit","RESULT=$?","[ $RESULT -ne 0 ] && exit 1","exit 0",q].join(h().default.EOL),E);try{l().default.chmodSync(n,"777")}catch(a){R(`chmod ${n} failed: ${a.message}`)}N("Create pre-commit hook")}},se=()=>{const e=C(),t=!1!==e.strict,n=e.eslintIgnore,r=e.stylelintIgnore;O().then((e=>{const s=n=>new Promise(((s,i)=>{const o=ne();if(o){const c=e.map((e=>e.filename)).filter((e=>/^(src|tests)/iu.test(e))).filter((e=>({css:/\.cs{2}$/iu,less:/\.les{2}$/iu,sass:/\.sas{2}$/iu,scss:/\.scs{2}$/iu}[n].test(e)))).filter((e=>B.every((t=>!(0,d().default)(e,t,{matchBase:!0}))))).filter((e=>"string"===typeof r?!(0,d().default)(e,r,{matchBase:!0}):r instanceof RegExp?!r.test(e):!Array.isArray(r)||r.every((t=>"string"===typeof t?!(0,d().default)(e,t,{matchBase:!0}):!(t instanceof RegExp)||!t.test(e))))).map((e=>{const t=b().default.join(P,e);return l().default.existsSync(t)?t:null})).filter((e=>!!e));if(c.length)if(c.forEach((e=>{if(e&&l().default.existsSync(e)){const t=b().default.extname(e).replace(/^\./u,""),n=l().default.readFileSync(e,E),r=(0,j().format)(n,k({parser:F[t]},H()));l().default.writeFileSync(e,r,E)}})),N(`${n} file(count: ${c.length}) prettier success!`),c.length>=D){const e=[];(0,a().default)(c,20).forEach((r=>{e.push(new Promise(((e,s)=>{A({command:"stylelint",args:[t?"--ignore-disables":"","--allow-empty-input","--custom-syntax",`postcss-${n}`,"--config",o,...r],complete:e,close:s,exit:!1})})))}));const r=process.getMaxListeners(),l=(0,a().default)(e,r?r/2:2);let u=0;const f=()=>{u<l.length?Promise.all(l[u]).then((()=>{u++,f()})).catch(i):(N(`${n} file(count: ${c.length}) stylelint success!`),s())};f()}else c.length&&A({command:"stylelint",args:[t?"--ignore-disables":"","--allow-empty-input","--custom-syntax",`postcss-${n}`,"--config",o,...c],complete:()=>{N(`${n} file(count: ${c.length}) stylelint success!`),s()},close:i,exit:!1});else s()}else _("\u6ca1\u6709 stylelintrc \u6587\u4ef6"),s()})),i=r=>new Promise(((s,i)=>{const o=te();if(o){const c=e.map((e=>e.filename)).filter((e=>/^(src|tests)/iu.test(e))).filter((e=>({js:/\.js$/iu,jsx:/\.jsx$/iu,ts:/\.ts$/iu,tsx:/\.tsx$/iu}[r].test(e)))).map((e=>{const t=b().default.join(P,e);return l().default.existsSync(t)?t:null})).filter((e=>!!e)).filter((e=>B.every((t=>!(0,d().default)(e,t,{matchBase:!0}))))).filter((e=>"string"===typeof n?!(0,d().default)(e,n,{matchBase:!0}):n instanceof RegExp?!n.test(e):!Array.isArray(n)||n.every((t=>"string"===typeof t?!(0,d().default)(e,t,{matchBase:!0}):!(t instanceof RegExp)||!t.test(e)))));if(c.length)if(c.forEach((e=>{if(e&&l().default.existsSync(e)){const t=b().default.extname(e).replace(/^\./u,""),n=l().default.readFileSync(e,E),r=(0,j().format)(n,k({parser:F[t]},H()));l().default.writeFileSync(e,r,E)}})),N(`${r} file(count: ${c.length}) prettier success!`),c.length>=D){const e=[];(0,a().default)(c,20).forEach((n=>{e.push(new Promise(((e,r)=>{A({command:"eslint",args:[t?"--no-inline-config --no-ignore":"","--no-error-on-unmatched-pattern","--config",o,...n],complete:e,close:r,exit:!1})})))}));const n=process.getMaxListeners(),l=(0,a().default)(e,n?n/2:2);let u=0;const f=()=>{u<l.length?Promise.all(l[u]).then((()=>{u++,f()})).catch(i):(N(`${r} file(count: ${c.length}) eslint success!`),s())};f()}else c.length&&A({command:"eslint",args:[t?"--no-inline-config --no-ignore":"","--no-error-on-unmatched-pattern","--config",o,...c],complete:()=>{N(`${r} file(count: ${c.length}) eslint success!`),s()},close:i,exit:!1});else s()}else _("\u6ca1\u6709 eslintrc \u6587\u4ef6"),s()}));_("\u7edf\u4e00\u4ee3\u7801\u89c4\u8303\uff0c\u8fdb\u884c\u4e25\u683c\u7684\u8bed\u6cd5\u68c0\u67e5\u3002"),t&&(_("git commit \u7981\u6b62 lint \u7684 ignore \u884c\u4e3a"),r&&_(`\u901a\u8fc7 .yolkrc \u914d\u7f6e stylelintIgnore: ${r}\u3002`),n&&_(`\u901a\u8fc7 .yolkrc \u914d\u7f6e eslintIgnore: ${n}\u3002`)),s("css").then((()=>s("less"))).then((()=>s("sass"))).then((()=>s("scss"))).then((()=>i("js"))).then((()=>i("jsx"))).then((()=>i("ts"))).then((()=>i("tsx"))).then(L)}))},ie=({mProject:e,mPrivateKeyPath:t,mVersion:n,mDesc:r,mRobot:s,mQrcodeFormat:i,mQrcodeOutputDest:a,mPagePath:c,mSearchQuery:u})=>{const f=l().default.existsSync(b().default.join(P,".git"))?(0,o().execSync)("git log -1 --pretty=format:%H").toString():"",d=U(),p=d.appid,y=e||b().default.join(P,"dist"),g=t||b().default.join(P,`private.${p}.key`);if(l().default.existsSync(y)){if(l().default.existsSync(g)){const e=W(),t=n||e.version||d.version||"1.0.0",o=r||e.description||d.description,l=`version: ${t};${f?` commit: ${f};`:""}${o?` description: ${o};`:""}`;f&&Q(`commit: ${f}`),Q(`dist: ${y}`),Q(`key: ${g}`),Q(`appid: ${p}`),Q(`version: ${t}`),Q(`desc: ${l}`);const h=new(m().Project)({appid:p,type:"miniProgram",projectPath:y,privateKeyPath:g,ignores:["node_modules/**/*","**/*.txt","**/*.key","**/*.less","**/*.sass","**/*.scss","**/*.css","**/*.jsx","**/*.ts","**/*.tsx","**/*.md"]});return{appid:p,options:{project:h,version:t,desc:l,setting:d.setting,robot:s,qrcodeFormat:i,qrcodeOutputDest:a,pagePath:c,searchQuery:u}}}throw Error(`\u6ca1\u6709\u627e\u5230\u4e0a\u4f20\u5bc6\u94a5(${g})`)}throw Error(`\u6ca1\u6709\u627e\u5230dist\u76ee\u5f55(${y})`)},ae=()=>{re(),process.argv.length>2?c().default.version(x.default.version).usage("[command] [options]").option("--clone","\u901a\u8fc7git clone\u62c9\u53d6\u6a21\u7248").option("--template <template>","\u6a21\u7248\u540d\u79f0\u6216\u8005clone\u6a21\u5f0f\u7684git\u5730\u5740").option("--docs","\u542f\u52a8\u6587\u6863\u6a21\u5f0f").option("--mProject <project>","\u5c0f\u7a0b\u5e8f\u4e0a\u4f20\u5de5\u7a0b\u76ee\u5f55").option("--mPrivateKeyPath <privateKeyPath>","\u5c0f\u7a0b\u5e8f\u4e0a\u4f20key\u6587\u4ef6").option("--mVersion <version>","\u5c0f\u7a0b\u5e8f\u4e0a\u4f20\u7248\u672c\u53f7").option("--mDesc <desc>","\u5c0f\u7a0b\u5e8f\u4e0a\u4f20\u63cf\u8ff0").option("--mRobot <robot>","\u5c0f\u7a0b\u5e8f\u4e0a\u4f20ci\u673a\u5668\u4eba1~30").option("--mQrcodeFormat <qrcodeFormat>",'\u5c0f\u7a0b\u5e8f\u9884\u89c8\u8fd4\u56de\u4e8c\u7ef4\u7801\u6587\u4ef6\u7684\u683c\u5f0f "image" \u6216 "base64"\uff0c \u9ed8\u8ba4\u503c "terminal" \u4f9b\u8c03\u8bd5\u7528').option("--mQrcodeOutputDest <qrcodeOutputDest>","\u5c0f\u7a0b\u5e8f\u9884\u89c8\u4e8c\u7ef4\u7801\u6587\u4ef6\u4fdd\u5b58\u8def\u5f84").option("--mPagePath <pagePath>","\u5c0f\u7a0b\u5e8f\u9884\u89c8\u9884\u89c8\u9875\u9762\u8def\u5f84").option("--mSearchQuery <searchQuery>","\u5c0f\u7a0b\u5e8f\u9884\u89c8\u9884\u89c8\u9875\u9762\u8def\u5f84\u542f\u52a8\u53c2\u6570").action(((e,n)=>{const a=(0,t().default)(n),o=a[0],c=a.slice(1),u=e.clone,f=e.template,d=e.docs;if(o)switch(Q(`yolk version: ${x.default.version}`),Q(`node version: ${process.version}`),Q(`platform: ${h().default.platform()}`),Q(`memory: ${(0,i().default)(h().default.freemem()/1024/1024)} MB(${(0,i().default)(h().default.totalmem()/1024/1024)} MB)`),o){case"init":if(N(`yolk ${o} \u5f00\u59cb`),u)if(f){const e=".yolk",t=b().default.join(P,e);l().default.existsSync(t)&&(0,v().default)(t,(()=>{N(`\u7f13\u5b58\u5220\u9664 success! ${t}`)})),A({command:"git",args:["clone","-b","master","--depth","1",f,e].concat(c)}),J(P,t)}else R("--clone \u6a21\u5f0f\u5fc5\u987b\u6709--template");else K(P);break;case"start":V()?Z()?A({command:"taro",args:["build","--type","tt","--watch"].concat(c)}):ee()?A({command:"taro",args:["build","--type","alipay","--watch"].concat(c)}):A({command:"taro",args:["build","--type","weapp","--watch"].concat(c)}):d?A({command:"dumi",args:["dev"].concat(c)}):G()?A({command:"icejs",args:["start","--config",Y()].concat(c)}):X()?A({command:"max",args:["dev"].concat(c)}):A({command:"umi",args:["dev"].concat(c)});break;case"build":V()?Z()?A({command:"taro",args:["build","--type","tt"].concat(c)}):ee()?A({command:"taro",args:["build","--type","alipay"].concat(c)}):A({command:"taro",args:["build","--type","weapp"].concat(c)}):d?A({command:"dumi",args:["build"].concat(c)}):G()?A({command:"icejs",args:["build","--config",Y()].concat(c)}):X()?A({command:"max",args:["setup"].concat(c),complete:()=>A({command:"max",args:["build"].concat(c)}),exit:!1}):A({command:"umi",args:["build"].concat(c)});break;case"pre-commit":se();break;case"test":A({command:"umi-test",args:["--no-cache","--update-snapshot","--runInBand","--detectOpenHandles"].concat(c)});break;case"miniapp-upload":case"miniprogram-upload":if(V())if(Z());else if(ee());else{const t=ie(e),n=t.appid,i=t.options;Q(`${n}\u4e0a\u4f20\u5f00\u59cb`),m().upload(k(k({},(0,s().default)(i,["project","version","desc","setting","robot"])),{},{onProgressUpdate:e=>{if((0,r().default)(e))Q(`task: ${e}`);else{const t=e.status,n=e.message;Q(`task(${t}): ${n}`)}}})).then((()=>{N(`${n}\u4e0a\u4f20\u5b8c\u6210`)}))}break;case"miniapp-preview":case"miniprogram-preview":if(V())if(Z());else if(ee());else{const t=ie(e),n=t.appid,i=t.options;Q(`${n}\u4e0a\u4f20\u9884\u89c8\u5f00\u59cb`),m().preview(k(k({},(0,s().default)(i,["project","version","desc","setting","robot","qrcodeFormat","qrcodeOutputDest","pagePath","searchQuery"])),{},{onProgressUpdate:e=>{if((0,r().default)(e))Q(`task: ${e}`);else{const t=e.status,n=e.message;Q(`task(${t}): ${n}`)}}})).then((()=>{N(`${n}\u4e0a\u4f20\u9884\u89c8\u5b8c\u6210`)}))}break;default:M()}})).parse(process.argv):M()};ae();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@baic/yolk-cli",
3
- "version": "2.1.0-alpha.42",
3
+ "version": "2.1.0-alpha.43",
4
4
  "author": "Baic <303394539@qq.com>",
5
5
  "license": "MIT",
6
6
  "bin": {
@@ -40,5 +40,5 @@
40
40
  "publishConfig": {
41
41
  "access": "public"
42
42
  },
43
- "gitHead": "70cc43d10dbdee7eb688fbc592495144d98e9bb5"
43
+ "gitHead": "c1876d699fde95593197f55151a567e182a9b266"
44
44
  }