@baic/yolk-cli 2.1.0-alpha.130 → 2.1.0-alpha.131
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 +1 -1
- package/lib/yolk.js +1 -1
- package/package.json +2 -2
package/es/yolk.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#! /usr/bin/env node
|
|
2
|
-
import e from"@babel/runtime/helpers/esm/toArray";import t from"@babel/runtime/helpers/esm/toConsumableArray";import n from"@babel/runtime/helpers/esm/defineProperty";import o from"lodash/isString";import r from"lodash/pick";import c from"lodash/floor";import i from"lodash/chunk";function s(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,o)}return n}function a(e){for(var t=1;t<arguments.length;t++){var o=null!=arguments[t]?arguments[t]:{};t%2?s(Object(o),!0).forEach((function(t){n(e,t,o[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(o)):s(Object(o)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(o,t))}))}return e}import{execSync as m,spawn as l}from"child_process";import p from"fs";import u from"os";import f from"path";import d from"inquirer";import*as y from"miniprogram-ci";import g from"ora";import h from"../compiled/commander";import v from"../compiled/glob";import b from"../compiled/minimatch";import j from"../compiled/mkdirp";import S from"../compiled/mustache";import{format as x}from"../compiled/prettier";import k from"../compiled/rimraf";import w from"../package.json";var O=require("../compiled/staged-git-files"),P=process.cwd(),D="##### CREATED BY YOLK #####",_={ts:"typescript",tsx:"typescript",less:"less",sass:"scss",scss:"scss",css:"css"},F="utf-8",I=20,E=["**/node_modules/**","**/.umi/**","**/.umi-production/**","**/build/**","**/dist/**","**/lib/**","**/es/**","**/public/**","**/assets/**","**/h5+app/**","**/android/**","**/ios/**","**/mock/**","**/yolk*/**"],N=g(),B=function(e){return e&&N.warn(Buffer.from(e,F).toString())},q=function(e){return e&&N.fail(Buffer.from(e,F).toString())},K=function(e){return e&&N.succeed(Buffer.from(e,F).toString())},$=function(e){return e&&N.info(Buffer.from(e,F).toString())},U=function(e){return"win32"===process.platform?"".concat(e,".cmd"):e},A=function(){K("yolk complete!"),process.exit(0)},Q=function(){B("yolk break!"),process.exit(0)},R=function(e){var t=e.command,n=e.args,o=e.complete,r=e.close,c=e.exit,i=void 0===c||c,s=l(U(t),n||[],{stdio:"inherit"}).on("close",(function(e){e?(r&&r(),q("yolk close!"),process.exit(e)):(o&&o(),i&&A())}));process.on("SIGINT",(function(){h.runningCommand&&h.runningCommand.kill("SIGKILL"),s.kill(),Q()}))},T=function(e,t,n){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:"miniprogram template",value:"miniprogram"}]},{type:"input",name:"projectName",message:"\u9879\u76ee\u540d\u79f0",default:f.basename(f.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((function(o){var r={projectName:o.projectName,dependenciesInstallType:o.dependenciesInstallType,yolkVersion:w.version},c=t||f.join(__dirname,"../templates/".concat(o.type));K("\u590d\u5236\u6a21\u7248 ".concat(f.basename(c)));var i=v.sync("**/*",{cwd:c,dot:!0,ignore:["**/node_modules/**","**/.git/**","**/.DS_Store","**/.idea/**"]});if(i.forEach((function(t){if(c){var n=f.join(c,t);if(!p.statSync(n).isDirectory())if(t.endsWith(".tpl")){var o=p.readFileSync(n,F),i=f.join(e,t.replace(/\.tpl$/,"")),s=S.render(o,r);j.sync(f.dirname(i)),K("\u521b\u5efa ".concat(f.relative(e,i))),p.writeFileSync(i,s,F)}else{K("\u521b\u5efa ".concat(t));var a=f.join(e,t);j.sync(f.dirname(a)),p.copyFileSync(n,a)}}})),K("\u590d\u5236\u6a21\u7248 success!"),n&&p.existsSync(c)&&k(c,(function(){K("\u7f13\u5b58\u5220\u9664 success! ".concat(f.basename(c||"")))})),o.dependenciesInstallType)switch(K("\u521d\u59cb\u5316\u4f9d\u8d56\u5305"),o.dependenciesInstallType){case"default":case"pnpm":R({command:"pnpm",args:["install"]});break;case"yarn":R({command:"yarn",args:["install"]});break;case"npm":R({command:"npm",args:["install"]});break;default:}K("\u53ef\u67e5\u9605<<https://303394539.github.io/yolk-docs/>>\u4e86\u89e3\u76f8\u5173\u6587\u6863")}))},Y=function(e,t){return T(e,t,!0)},W=function(){var e=v.sync("*.yolkrc*",{cwd:P,dot:!0});if(!e.length)return{};var t=f.join(P,e[0]);if(!p.existsSync(t))return{};try{return JSON.parse(p.readFileSync(t,F))||{}}catch(n){return q(n.message||".yolkrc\u8f6c\u6362\u9519\u8bef"),{}}},L=function(){var e=f.join(P,".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")},C=function(){var e=f.join(P,"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"),{}}},J=function(){var e=f.join(P,"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"),{}}},V=function(){return p.existsSync(f.join(P,"project.config.json"))},G=function(){var e=p.existsSync(f.join(P,"node_modules/.bin/max"));if(!e)try{e=p.existsSync(require.resolve("@umijs/max"))}catch(o){}if(!e)try{e=/umi@4\.(\d+)\.(\d+)/.test(m("umi -v").toString())}catch(o){}if(!e){var t=f.join(P,"node_modules","umi","package.json");if(p.existsSync(t))try{var n=JSON.parse(p.readFileSync(t,F))||{};e=n.version&&+n.version.split(".")[0]>3}catch(o){}}return e},H=function(){var e=f.join(P,"project.config.json");if(p.existsSync(e)){var t=require(e);return t.appid}return""},M=function(){return p.existsSync(f.join(P,"project.tt.json"))&&0===H().indexOf("tt")},X=function(){return 0===H().indexOf("20")},z=function(){var e=W(),t="";try{t=require.resolve("@baic/eslint-config-yolk")}catch(r){}var n=v.sync("*.eslintrc*",{cwd:P,dot:!0}),o=n[0];return!1===e.strict&&o&&p.existsSync(o)?o:p.existsSync(t)?t:o},Z=function(){var e=W(),t="";try{t=require.resolve("@baic/stylelint-config-yolk")}catch(r){}var n=v.sync("*.stylelintrc*",{cwd:P,dot:!0}),o=n[0];return!1===e.strict&&o&&p.existsSync(o)?o:p.existsSync(t)?t:o},ee=function(){var e=f.join(P,".git/"),t=f.join(P,".git/hooks"),n=f.join(t,"pre-commit"),o=p.existsSync(e),r=p.existsSync(n),c=r&&p.readFileSync(n,F).includes(D);if(o&&(!r||!c)){j.sync(t),p.writeFileSync(n,["#!/usr/bin/env bash","npx yolk pre-commit","RESULT=$?","[ $RESULT -ne 0 ] && exit 1","exit 0",D].join(u.EOL),F);try{p.chmodSync(n,"777")}catch(i){q("chmod ".concat(n," failed: ").concat(i.message))}K("Create pre-commit hook")}},te=function(){var e=W(),n=!1!==e.strict,o=e.eslintIgnore,r=e.stylelintIgnore;O().then((function(e){var c=function(o){return new Promise((function(c,s){var m=Z();if(m){var l=e.map((function(e){return e.filename})).filter((function(e){return/^(src|tests)/i.test(e)})).filter((function(e){return{css:/\.cs{2}$/i,less:/\.les{2}$/i,sass:/\.sas{2}$/i,scss:/\.scs{2}$/i}[o].test(e)})).filter((function(e){var t=f.join(P,e);return p.existsSync(t)})).filter((function(e){return E.every((function(t){return!b(e,t,{matchBase:!0})}))})).filter((function(e){return"string"===typeof r?!b(e,r,{matchBase:!0}):r instanceof RegExp?!r.test(e):!Array.isArray(r)||r.every((function(t){return"string"===typeof t?!b(e,t,{matchBase:!0}):!(t instanceof RegExp)||!t.test(e)}))}));if(l.length)if(l.forEach((function(e){if(e&&p.existsSync(e)){var t=f.extname(e).replace(/^\./,""),n=p.readFileSync(e,F),o=x(n,a({parser:_[t]},L()));p.writeFileSync(e,o,F)}})),K("".concat(o," - ").concat(l.length," files prettier success!")),l.length>=I){var u=[];i(l,I).forEach((function(e){u.push(new Promise((function(r,c){R({command:"stylelint",args:[n?"--ignore-disables":"","--allow-empty-input","--custom-syntax","postcss-".concat(o),"--config",m].concat(t(e)),complete:r,close:c,exit:!1})})))}));var d=0,y=function e(){d<u.length?u[d].then((function(){d++,e()})).catch(s):(K("".concat(o," - ").concat(l.length," files stylelint success!")),c())};y()}else l.length&&R({command:"stylelint",args:[n?"--ignore-disables":"","--allow-empty-input","--custom-syntax","postcss-".concat(o),"--config",m].concat(t(l)),complete:function(){K("".concat(o," - ").concat(l.length," files stylelint success!")),c()},close:s,exit:!1});else c()}else q("\u6ca1\u6709 stylelintrc \u6587\u4ef6\uff0c".concat(o," files prettier fail!")),c()}))},s=function(r){return new Promise((function(c,s){var m=z();if(m){var l=e.map((function(e){return e.filename})).filter((function(e){return/^(src|tests)/i.test(e)})).filter((function(e){return{js:/\.js$/i,jsx:/\.jsx$/i,ts:/\.ts$/i,tsx:/\.tsx$/i}[r].test(e)})).filter((function(e){var t=f.join(P,e);return p.existsSync(t)})).filter((function(e){return E.every((function(t){return!b(e,t,{matchBase:!0})}))})).filter((function(e){return"string"===typeof o?!b(e,o,{matchBase:!0}):o instanceof RegExp?!o.test(e):!Array.isArray(o)||o.every((function(t){return"string"===typeof t?!b(e,t,{matchBase:!0}):!(t instanceof RegExp)||!t.test(e)}))}));if(l.length)if(l.forEach((function(e){if(e&&p.existsSync(e)){var t=f.extname(e).replace(/^\./,""),n=p.readFileSync(e,F),o=x(n,a({parser:_[t]},L()));p.writeFileSync(e,o,F)}})),K("".concat(r," - ").concat(l.length," files prettier success!")),l.length>=I){var u=[];i(l,I).forEach((function(e){u.push(new Promise((function(o,r){R({command:"eslint",args:[n?"--no-inline-config --no-ignore":"","--no-error-on-unmatched-pattern","--config",m].concat(t(e)),complete:o,close:r,exit:!1})})))}));var d=0,y=function e(){d<u.length?u[d].then((function(){d++,e()})).catch(s):(K("".concat(r," - ").concat(l.length," files eslint success!")),c())};y()}else l.length&&R({command:"eslint",args:[n?"--no-inline-config --no-ignore":"","--no-error-on-unmatched-pattern","--config",m].concat(t(l)),complete:function(){K("".concat(r," - ").concat(l.length," files eslint success!")),c()},close:s,exit:!1});else c()}else q("\u6ca1\u6709 eslintrc \u6587\u4ef6\uff0c".concat(r," files eslint fail!")),c()}))};B("\u7edf\u4e00\u4ee3\u7801\u89c4\u8303\uff0c\u8fdb\u884c\u4e25\u683c\u7684\u8bed\u6cd5\u68c0\u67e5\u3002"),n&&(B("git commit \u7981\u6b62 lint \u7684 ignore \u884c\u4e3a"),r&&B("\u901a\u8fc7 .yolkrc \u914d\u7f6e stylelintIgnore: ".concat(r,"\u3002")),o&&B("\u901a\u8fc7 .yolkrc \u914d\u7f6e eslintIgnore: ".concat(o,"\u3002"))),c("css").then((function(){return c("less")})).then((function(){return c("sass")})).then((function(){return c("scss")})).then((function(){return s("js")})).then((function(){return s("jsx")})).then((function(){return s("ts")})).then((function(){return s("tsx")})).then(A).catch(A)}))},ne=function(e){var t=e.mAppid,n=e.mProject,o=e.mPrivateKeyPath,r=e.mVersion,c=e.mDesc,i=e.mRobot,s=e.mQrcodeFormat,a=e.mQrcodeOutputDest,l=e.mPagePath,u=e.mSearchQuery,d=p.existsSync(f.join(P,".git"))?m("git log -1 --pretty=format:%H").toString():"",g=C(),h=t||g.appid,v=n||f.join(P,"dist"),b=o||f.join(P,"private.".concat(h,".key"));if(p.existsSync(v)){if(p.existsSync(b)){var j=J(),S=r||j.version||g.version||"1.0.0",x=c||j.description||g.description,k="version: ".concat(S,";").concat(d?" commit: ".concat(d,";"):"").concat(x?" description: ".concat(x,";"):"");d&&$("commit: ".concat(d)),$("dist: ".concat(v)),$("key: ".concat(b)),$("appid: ".concat(h)),$("version: ".concat(S)),$("desc: ".concat(k));var w=new y.Project({appid:h,type:"miniProgram",projectPath:v,privateKeyPath:b,ignores:["node_modules/**/*","**/*.txt","**/*.key","**/*.less","**/*.sass","**/*.scss","**/*.css","**/*.jsx","**/*.ts","**/*.tsx","**/*.md"]});return{appid:h,options:{project:w,version:S,desc:k,setting:g.setting,robot:i,qrcodeFormat:s,qrcodeOutputDest:a,pagePath:l,searchQuery:u}}}throw Error("\u6ca1\u6709\u627e\u5230\u4e0a\u4f20\u5bc6\u94a5(".concat(b,")"))}throw Error("\u6ca1\u6709\u627e\u5230dist\u76ee\u5f55(".concat(v,")"))},oe=function(){ee(),process.argv.length>2?h.version(w.version,"-v,--version","\u8f93\u51fa\u7248\u672c\u53f7").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("--mAppid <appid>","\u5c0f\u7a0b\u5e8fappid").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((function(t,n){var i=e(n),s=i[0],m=i.slice(1),l=t.clone,d=t.template,g=t.docs;if(s)switch($("yolk version: ".concat(w.version)),$("node version: ".concat(process.version)),$("platform: ".concat(u.platform())),$("memory: ".concat(c(u.freemem()/1024/1024)," MB(").concat(c(u.totalmem()/1024/1024)," MB)")),s){case"init":if(K("yolk ".concat(s," \u5f00\u59cb")),l)if(d){var h=".yolk",v=f.join(P,h);p.existsSync(v)&&k(v,(function(){K("\u7f13\u5b58\u5220\u9664 success! ".concat(v))})),R({command:"git",args:["clone","-b","master","--depth","1",d,h].concat(m)}),Y(P,v)}else q("--clone \u6a21\u5f0f\u5fc5\u987b\u6709--template");else T(P);break;case"start":V()?M()?R({command:"taro",args:["build","--type","tt","--watch"].concat(m)}):X()?R({command:"taro",args:["build","--type","alipay","--watch"].concat(m)}):R({command:"taro",args:["build","--type","weapp","--watch"].concat(m)}):g?(process.env.DID_YOU_KNOW="none",R({command:"dumi",args:["dev"].concat(m)})):G()?(process.env.DID_YOU_KNOW="none",R({command:"max",args:["dev"].concat(m)})):(process.env.DID_YOU_KNOW="none",R({command:"umi",args:["dev"].concat(m)}));break;case"build":V()?M()?R({command:"taro",args:["build","--type","tt"].concat(m)}):X()?R({command:"taro",args:["build","--type","alipay"].concat(m)}):R({command:"taro",args:["build","--type","weapp"].concat(m)}):g?(process.env.DID_YOU_KNOW="none",R({command:"dumi",args:["build"].concat(m)})):G()?(process.env.DID_YOU_KNOW="none",R({command:"max",args:["setup"].concat(m),complete:function(){return R({command:"max",args:["build"].concat(m)})},exit:!1})):(process.env.DID_YOU_KNOW="none",R({command:"umi",args:["build"].concat(m)}));break;case"pre-commit":te();break;case"miniprogram-upload":if(V())if(M());else if(X());else{var b=ne(t),j=b.appid,S=b.options;$("".concat(j,"\u4e0a\u4f20\u5f00\u59cb")),y.upload(a(a({},r(S,["project","version","desc","setting","robot"])),{},{onProgressUpdate:function(e){if(o(e))$("task: ".concat(e));else{var t=e.status,n=e.message;$("task(".concat(t,"): ").concat(n))}}})).then((function(){K("".concat(j,"\u4e0a\u4f20\u5b8c\u6210"))}))}break;case"miniprogram-preview":if(V())if(M());else if(X());else{var x=ne(t),O=x.appid,D=x.options;$("".concat(O,"\u4e0a\u4f20\u9884\u89c8\u5f00\u59cb")),y.preview(a(a({},r(D,["project","version","desc","setting","robot","qrcodeFormat","qrcodeOutputDest","pagePath","searchQuery"])),{},{onProgressUpdate:function(e){if(o(e))$("task: ".concat(e));else{var t=e.status,n=e.message;$("task(".concat(t,"): ").concat(n))}}})).then((function(){K("".concat(O,"\u4e0a\u4f20\u9884\u89c8\u5b8c\u6210"))}))}break;default:Q()}})).parse(process.argv):Q()};oe();
|
|
2
|
+
import e from"@babel/runtime/helpers/esm/toArray";import t from"@babel/runtime/helpers/esm/toConsumableArray";import n from"@babel/runtime/helpers/esm/defineProperty";import o from"lodash/isString";import r from"lodash/pick";import c from"lodash/floor";import i from"lodash/chunk";function s(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,o)}return n}function a(e){for(var t=1;t<arguments.length;t++){var o=null!=arguments[t]?arguments[t]:{};t%2?s(Object(o),!0).forEach((function(t){n(e,t,o[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(o)):s(Object(o)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(o,t))}))}return e}import{execSync as m,spawn as l}from"child_process";import p from"fs";import u from"os";import f from"path";import d from"inquirer";import*as y from"miniprogram-ci";import g from"ora";import h from"../compiled/commander";import v from"../compiled/glob";import b from"../compiled/minimatch";import j from"../compiled/mkdirp";import S from"../compiled/mustache";import{format as x}from"../compiled/prettier";import k from"../compiled/rimraf";import w from"../package.json";var O=require("../compiled/staged-git-files"),P=process.cwd(),D="##### CREATED BY YOLK #####",_={ts:"typescript",tsx:"typescript",less:"less",sass:"scss",scss:"scss",css:"css"},F="utf-8",I=20,E=["**/node_modules/**","**/.umi/**","**/.umi-production/**","**/build/**","**/dist/**","**/lib/**","**/es/**","**/public/**","**/assets/**","**/h5+app/**","**/android/**","**/ios/**","**/mock/**","**/yolk*/**"],N=g(),B=function(e){return e&&N.warn(Buffer.from(e,F).toString())},q=function(e){return e&&N.fail(Buffer.from(e,F).toString())},K=function(e){return e&&N.succeed(Buffer.from(e,F).toString())},$=function(e){return e&&N.info(Buffer.from(e,F).toString())},U=function(e){return"win32"===process.platform?"".concat(e,".cmd"):e},A=function(){K("yolk complete!"),process.exit(0)},Q=function(){B("yolk break!"),process.exit(0)},R=function(e){var t=e.command,n=e.args,o=e.complete,r=e.close,c=e.exit,i=void 0===c||c,s=l(U(t),n||[],{stdio:"inherit"}).on("close",(function(e){e?(r&&r(),q("yolk close!"),process.exit(e)):(o&&o(),i&&A())}));process.on("SIGINT",(function(){h.runningCommand&&h.runningCommand.kill("SIGKILL"),s.kill(),Q()}))},T=function(e,t,n){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:"miniprogram template",value:"miniprogram"}]},{type:"input",name:"projectName",message:"\u9879\u76ee\u540d\u79f0",default:f.basename(f.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((function(o){var r={projectName:o.projectName,dependenciesInstallType:o.dependenciesInstallType,yolkVersion:w.version},c=t||f.join(__dirname,"../templates/".concat(o.type));K("\u590d\u5236\u6a21\u7248 ".concat(f.basename(c)));var i=v.sync("**/*",{cwd:c,dot:!0,ignore:["**/node_modules/**","**/.git/**","**/.DS_Store","**/.idea/**"]});if(i.forEach((function(t){if(c){var n=f.join(c,t);if(!p.statSync(n).isDirectory())if(t.endsWith(".tpl")){var o=p.readFileSync(n,F),i=f.join(e,t.replace(/\.tpl$/,"")),s=S.render(o,r);j.sync(f.dirname(i)),K("\u521b\u5efa ".concat(f.relative(e,i))),p.writeFileSync(i,s,F)}else{K("\u521b\u5efa ".concat(t));var a=f.join(e,t);j.sync(f.dirname(a)),p.copyFileSync(n,a)}}})),K("\u590d\u5236\u6a21\u7248 success!"),n&&p.existsSync(c)&&k(c,(function(){K("\u7f13\u5b58\u5220\u9664 success! ".concat(f.basename(c||"")))})),o.dependenciesInstallType)switch(K("\u521d\u59cb\u5316\u4f9d\u8d56\u5305"),o.dependenciesInstallType){case"default":case"pnpm":R({command:"pnpm",args:["install"]});break;case"yarn":R({command:"yarn",args:["install"]});break;case"npm":R({command:"npm",args:["install"]});break;default:}K("\u53ef\u67e5\u9605<<https://303394539.github.io/yolk-docs/>>\u4e86\u89e3\u76f8\u5173\u6587\u6863")}))},Y=function(e,t){return T(e,t,!0)},W=function(){var e=v.sync("*.yolkrc*",{cwd:P,dot:!0});if(!e.length)return{};var t=f.join(P,e[0]);if(!p.existsSync(t))return{};try{return JSON.parse(p.readFileSync(t,F))||{}}catch(n){return q(n.message||".yolkrc\u8f6c\u6362\u9519\u8bef"),{}}},L=function(){var e=f.join(P,".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")},C=function(){var e=f.join(P,"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"),{}}},J=function(){var e=f.join(P,"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"),{}}},V=function(){return p.existsSync(f.join(P,"project.config.json"))},G=function(){var e=p.existsSync(f.join(P,"node_modules/.bin/max"));if(!e)try{e=p.existsSync(require.resolve("@umijs/max"))}catch(o){}if(!e)try{e=/umi@4\.(\d+)\.(\d+)/.test(m("umi -v").toString())}catch(o){}if(!e){var t=f.join(P,"node_modules","umi","package.json");if(p.existsSync(t))try{var n=JSON.parse(p.readFileSync(t,F))||{};e=n.version&&+n.version.split(".")[0]>3}catch(o){}}return e},H=function(){var e=f.join(P,"project.config.json");if(p.existsSync(e)){var t=require(e);return t.appid}return""},M=function(){return p.existsSync(f.join(P,"project.tt.json"))&&0===H().indexOf("tt")},X=function(){return 0===H().indexOf("20")},z=function(){var e=W(),t="";try{t=require.resolve("@baic/eslint-config-yolk")}catch(r){}var n=v.sync("*.eslintrc*",{cwd:P,dot:!0}),o=n[0];return!1===e.strict&&o&&p.existsSync(o)?o:p.existsSync(t)?t:o},Z=function(){var e=W(),t="";try{t=require.resolve("@baic/stylelint-config-yolk")}catch(r){}var n=v.sync("*.stylelintrc*",{cwd:P,dot:!0}),o=n[0];return!1===e.strict&&o&&p.existsSync(o)?o:p.existsSync(t)?t:o},ee=function(){var e=f.join(P,".git/"),t=f.join(P,".git/hooks"),n=f.join(t,"pre-commit"),o=p.existsSync(e),r=p.existsSync(n),c=r&&p.readFileSync(n,F).includes(D);if(o&&(!r||!c)){j.sync(t),p.writeFileSync(n,["#!/usr/bin/env bash","npx yolk pre-commit","RESULT=$?","[ $RESULT -ne 0 ] && exit 1","exit 0",D].join(u.EOL),F);try{p.chmodSync(n,"777")}catch(i){q("chmod ".concat(n," failed: ").concat(i.message))}K("Create pre-commit hook")}},te=function(){var e=W(),n=!1!==e.strict,o=e.eslintIgnore,r=e.stylelintIgnore;O().then((function(e){var c=function(o){return new Promise((function(c,s){var m=Z();if(m){var l=e.map((function(e){return e.filename})).filter((function(e){return/^(src|tests)/i.test(e)})).filter((function(e){return{css:/\.cs{2}$/i,less:/\.les{2}$/i,sass:/\.sas{2}$/i,scss:/\.scs{2}$/i}[o].test(e)})).filter((function(e){var t=f.join(P,e);return p.existsSync(t)})).filter((function(e){return E.every((function(t){return!b(e,t,{matchBase:!0})}))})).filter((function(e){return"string"===typeof r?!b(e,r,{matchBase:!0}):r instanceof RegExp?!r.test(e):!Array.isArray(r)||r.every((function(t){return"string"===typeof t?!b(e,t,{matchBase:!0}):!(t instanceof RegExp)||!t.test(e)}))}));if(l.length)if(l.forEach((function(e){if(e&&p.existsSync(e)){var t=f.extname(e).replace(/^\./,""),n=p.readFileSync(e,F),o=x(n,a({parser:_[t]},L()));p.writeFileSync(e,o,F)}})),K("".concat(o," - ").concat(l.length," files prettier success!")),l.length>=I){var u=[];i(l,I).forEach((function(e){u.push(new Promise((function(r,c){R({command:"stylelint",args:[n?"--ignore-disables":"","--allow-empty-input","--custom-syntax","postcss-".concat(o),"--config",m].concat(t(e)),complete:r,close:c,exit:!1})})))}));var d=0,y=function e(){d<u.length?u[d].then((function(){d++,e()})).catch(s):(K("".concat(o," - ").concat(l.length," files stylelint success!")),c())};y()}else l.length&&R({command:"stylelint",args:[n?"--ignore-disables":"","--allow-empty-input","--custom-syntax","postcss-".concat(o),"--config",m].concat(t(l)),complete:function(){K("".concat(o," - ").concat(l.length," files stylelint success!")),c()},close:s,exit:!1});else c()}else q("\u6ca1\u6709 stylelintrc \u6587\u4ef6\uff0c".concat(o," files prettier fail!")),c()}))},s=function(r){return new Promise((function(c,s){var m=z();if(m){var l=e.map((function(e){return e.filename})).filter((function(e){return/^(src|tests)/i.test(e)})).filter((function(e){return{js:/\.js$/i,jsx:/\.jsx$/i,ts:/\.ts$/i,tsx:/\.tsx$/i}[r].test(e)})).filter((function(e){var t=f.join(P,e);return p.existsSync(t)})).filter((function(e){return E.every((function(t){return!b(e,t,{matchBase:!0})}))})).filter((function(e){return"string"===typeof o?!b(e,o,{matchBase:!0}):o instanceof RegExp?!o.test(e):!Array.isArray(o)||o.every((function(t){return"string"===typeof t?!b(e,t,{matchBase:!0}):!(t instanceof RegExp)||!t.test(e)}))}));if(l.length)if(l.forEach((function(e){if(e&&p.existsSync(e)){var t=f.extname(e).replace(/^\./,""),n=p.readFileSync(e,F),o=x(n,a({parser:_[t]},L()));p.writeFileSync(e,o,F)}})),K("".concat(r," - ").concat(l.length," files prettier success!")),l.length>=I){var u=[];i(l,I).forEach((function(e){u.push(new Promise((function(o,r){R({command:"eslint",args:[n?"--no-inline-config --no-ignore":"","--no-error-on-unmatched-pattern","--config",m].concat(t(e)),complete:o,close:r,exit:!1})})))}));var d=0,y=function e(){d<u.length?u[d].then((function(){d++,e()})).catch(s):(K("".concat(r," - ").concat(l.length," files eslint success!")),c())};y()}else l.length&&R({command:"eslint",args:[n?"--no-inline-config --no-ignore":"","--no-error-on-unmatched-pattern","--config",m].concat(t(l)),complete:function(){K("".concat(r," - ").concat(l.length," files eslint success!")),c()},close:s,exit:!1});else c()}else q("\u6ca1\u6709 eslintrc \u6587\u4ef6\uff0c".concat(r," files eslint fail!")),c()}))};B("\u7edf\u4e00\u4ee3\u7801\u89c4\u8303\uff0c\u8fdb\u884c\u4e25\u683c\u7684\u8bed\u6cd5\u68c0\u67e5\u3002"),n&&(B("git commit \u7981\u6b62 lint \u7684 ignore \u884c\u4e3a"),r&&B("\u901a\u8fc7 .yolkrc \u914d\u7f6e stylelintIgnore: ".concat(r,"\u3002")),o&&B("\u901a\u8fc7 .yolkrc \u914d\u7f6e eslintIgnore: ".concat(o,"\u3002"))),c("css").then((function(){return c("less")})).then((function(){return c("sass")})).then((function(){return c("scss")})).then((function(){return s("js")})).then((function(){return s("jsx")})).then((function(){return s("ts")})).then((function(){return s("tsx")})).then(A).catch(A)}))},ne=function(e){var t=e.mAppid,n=e.mProject,o=e.mPrivateKeyPath,r=e.mVersion,c=e.mDesc,i=e.mRobot,s=e.mQrcodeFormat,a=e.mQrcodeOutputDest,l=e.mPagePath,u=e.mSearchQuery,d=p.existsSync(f.join(P,".git"))?m("git log -1 --pretty=format:%H").toString():"",g=C(),h=t||g.appid,v=n||f.join(P,"dist"),b=o||f.join(P,"private.".concat(h,".key"));if(p.existsSync(v)){if(p.existsSync(b)){var j=J(),S=r||j.version||g.version||"1.0.0",x=c||j.description||g.description,k="".concat(d?" commit: ".concat(d,";"):"").concat(x?" description: ".concat(x,";"):"");d&&$("commit: ".concat(d)),$("dist: ".concat(v)),$("key: ".concat(b)),$("appid: ".concat(h)),$("version: ".concat(S)),$("desc: ".concat(k));var w=new y.Project({appid:h,type:"miniProgram",projectPath:v,privateKeyPath:b,ignores:["node_modules/**/*","**/*.txt","**/*.key","**/*.less","**/*.sass","**/*.scss","**/*.css","**/*.jsx","**/*.ts","**/*.tsx","**/*.md"]});return{appid:h,options:{project:w,version:S,desc:k,setting:g.setting,robot:i,qrcodeFormat:s,qrcodeOutputDest:a,pagePath:l,searchQuery:u}}}throw Error("\u6ca1\u6709\u627e\u5230\u4e0a\u4f20\u5bc6\u94a5(".concat(b,")"))}throw Error("\u6ca1\u6709\u627e\u5230dist\u76ee\u5f55(".concat(v,")"))},oe=function(){ee(),process.argv.length>2?h.version(w.version,"-v,--version","\u8f93\u51fa\u7248\u672c\u53f7").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("--mAppid <appid>","\u5c0f\u7a0b\u5e8fappid").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((function(t,n){var i=e(n),s=i[0],m=i.slice(1),l=t.clone,d=t.template,g=t.docs;if(s)switch($("yolk version: ".concat(w.version)),$("node version: ".concat(process.version)),$("platform: ".concat(u.platform())),$("memory: ".concat(c(u.freemem()/1024/1024)," MB(").concat(c(u.totalmem()/1024/1024)," MB)")),s){case"init":if(K("yolk ".concat(s," \u5f00\u59cb")),l)if(d){var h=".yolk",v=f.join(P,h);p.existsSync(v)&&k(v,(function(){K("\u7f13\u5b58\u5220\u9664 success! ".concat(v))})),R({command:"git",args:["clone","-b","master","--depth","1",d,h].concat(m)}),Y(P,v)}else q("--clone \u6a21\u5f0f\u5fc5\u987b\u6709--template");else T(P);break;case"start":V()?M()?R({command:"taro",args:["build","--type","tt","--watch"].concat(m)}):X()?R({command:"taro",args:["build","--type","alipay","--watch"].concat(m)}):R({command:"taro",args:["build","--type","weapp","--watch"].concat(m)}):g?(process.env.DID_YOU_KNOW="none",R({command:"dumi",args:["dev"].concat(m)})):G()?(process.env.DID_YOU_KNOW="none",R({command:"max",args:["dev"].concat(m)})):(process.env.DID_YOU_KNOW="none",R({command:"umi",args:["dev"].concat(m)}));break;case"build":V()?M()?R({command:"taro",args:["build","--type","tt"].concat(m)}):X()?R({command:"taro",args:["build","--type","alipay"].concat(m)}):R({command:"taro",args:["build","--type","weapp"].concat(m)}):g?(process.env.DID_YOU_KNOW="none",R({command:"dumi",args:["build"].concat(m)})):G()?(process.env.DID_YOU_KNOW="none",R({command:"max",args:["setup"].concat(m),complete:function(){return R({command:"max",args:["build"].concat(m)})},exit:!1})):(process.env.DID_YOU_KNOW="none",R({command:"umi",args:["build"].concat(m)}));break;case"pre-commit":te();break;case"miniprogram-upload":if(V())if(M());else if(X());else{var b=ne(t),j=b.appid,S=b.options;$("".concat(j,"\u4e0a\u4f20\u5f00\u59cb")),y.upload(a(a({},r(S,["project","version","desc","setting","robot"])),{},{onProgressUpdate:function(e){if(o(e))$("task: ".concat(e));else{var t=e.status,n=e.message;$("task(".concat(t,"): ").concat(n))}}})).then((function(){K("".concat(j,"\u4e0a\u4f20\u5b8c\u6210"))}))}break;case"miniprogram-preview":if(V())if(M());else if(X());else{var x=ne(t),O=x.appid,D=x.options;$("".concat(O,"\u4e0a\u4f20\u9884\u89c8\u5f00\u59cb")),y.preview(a(a({},r(D,["project","version","desc","setting","robot","qrcodeFormat","qrcodeOutputDest","pagePath","searchQuery"])),{},{onProgressUpdate:function(e){if(o(e))$("task: ".concat(e));else{var t=e.status,n=e.message;$("task(".concat(t,"): ").concat(n))}}})).then((function(){K("".concat(O,"\u4e0a\u4f20\u9884\u89c8\u5b8c\u6210"))}))}break;default:Q()}})).parse(process.argv):Q()};oe();
|
package/lib/yolk.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#! /usr/bin/env node
|
|
2
|
-
var e=Object.create,t=Object.defineProperty,s=Object.getOwnPropertyDescriptor,a=Object.getOwnPropertyNames,n=Object.getPrototypeOf,i=Object.prototype.hasOwnProperty,o=(e,n,o,r)=>{if(n&&"object"===typeof n||"function"===typeof n)for(let c of a(n))i.call(e,c)||c===o||t(e,c,{get:()=>n[c],enumerable:!(r=s(n,c))||r.enumerable});return e},r=(s,a,i)=>(i=null!=s?e(n(s)):{},o(!a&&s&&s.__esModule?i:t(i,"default",{value:s,enumerable:!0}),s)),c=e=>o(t({},"__esModule",{value:!0}),e),l={};module.exports=c(l);var d=require("child_process"),u=r(require("fs")),m=r(require("os")),p=r(require("path")),f=r(require("lodash")),y=r(require("inquirer")),g=r(require("miniprogram-ci")),h=r(require("ora")),$=r(require("../compiled/commander")),b=r(require("../compiled/glob")),x=r(require("../compiled/minimatch")),v=r(require("../compiled/mkdirp")),S=r(require("../compiled/mustache")),j=require("../compiled/prettier"),k=r(require("../compiled/rimraf")),w=r(require("../package.json")),O=require("../compiled/staged-git-files"),q=process.cwd(),P="##### CREATED BY YOLK #####",_={ts:"typescript",tsx:"typescript",less:"less",sass:"scss",scss:"scss",css:"css"},D="utf-8",F=20,I=["**/node_modules/**","**/.umi/**","**/.umi-production/**","**/build/**","**/dist/**","**/lib/**","**/es/**","**/public/**","**/assets/**","**/h5+app/**","**/android/**","**/ios/**","**/mock/**","**/yolk*/**"],E=(0,h.default)(),N=e=>e&&E.warn(Buffer.from(e,D).toString()),B=e=>e&&E.fail(Buffer.from(e,D).toString()),K=e=>e&&E.succeed(Buffer.from(e,D).toString()),U=e=>e&&E.info(Buffer.from(e,D).toString()),Q=e=>"win32"===process.platform?`${e}.cmd`:e,R=()=>{K("yolk complete!"),process.exit(0)},T=()=>{N("yolk break!"),process.exit(0)},Y=({command:e,args:t,complete:s,close:a,exit:n=!0})=>{const i=(0,d.spawn)(Q(e),t||[],{stdio:"inherit"}).on("close",(e=>{e?(a&&a(),B("yolk close!"),process.exit(e)):(s&&s(),n&&R())}));process.on("SIGINT",(()=>{$.default.runningCommand&&$.default.runningCommand.kill("SIGKILL"),i.kill(),T()}))},A=(e,t,s)=>{y.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:"miniprogram template",value:"miniprogram"}]},{type:"input",name:"projectName",message:"\u9879\u76ee\u540d\u79f0",default:p.default.basename(p.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((a=>{const n={projectName:a.projectName,dependenciesInstallType:a.dependenciesInstallType,yolkVersion:w.default.version},i=t||p.default.join(__dirname,`../templates/${a.type}`);K(`\u590d\u5236\u6a21\u7248 ${p.default.basename(i)}`);const o=b.default.sync("**/*",{cwd:i,dot:!0,ignore:["**/node_modules/**","**/.git/**","**/.DS_Store","**/.idea/**"]});if(o.forEach((t=>{if(!i)return;const s=p.default.join(i,t);if(!u.default.statSync(s).isDirectory())if(t.endsWith(".tpl")){const a=u.default.readFileSync(s,D),i=p.default.join(e,t.replace(/\.tpl$/,"")),o=S.default.render(a,n);v.default.sync(p.default.dirname(i)),K(`\u521b\u5efa ${p.default.relative(e,i)}`),u.default.writeFileSync(i,o,D)}else{K(`\u521b\u5efa ${t}`);const a=p.default.join(e,t);v.default.sync(p.default.dirname(a)),u.default.copyFileSync(s,a)}})),K("\u590d\u5236\u6a21\u7248 success!"),s&&u.default.existsSync(i)&&(0,k.default)(i,(()=>{K(`\u7f13\u5b58\u5220\u9664 success! ${p.default.basename(i||"")}`)})),a.dependenciesInstallType)switch(K("\u521d\u59cb\u5316\u4f9d\u8d56\u5305"),a.dependenciesInstallType){case"default":case"pnpm":Y({command:"pnpm",args:["install"]});break;case"yarn":Y({command:"yarn",args:["install"]});break;case"npm":Y({command:"npm",args:["install"]});break;default:}K("\u53ef\u67e5\u9605<<https://303394539.github.io/yolk-docs/>>\u4e86\u89e3\u76f8\u5173\u6587\u6863")}))},W=(e,t)=>A(e,t,!0),L=()=>{const e=b.default.sync("*.yolkrc*",{cwd:q,dot:!0});if(!e.length)return{};const t=p.default.join(q,e[0]);if(!u.default.existsSync(t))return{};try{return JSON.parse(u.default.readFileSync(t,D))||{}}catch(s){return B(s.message||".yolkrc\u8f6c\u6362\u9519\u8bef"),{}}},J=()=>{const e=p.default.join(q,".prettierrc");if(u.default.existsSync(e))try{return JSON.parse(u.default.readFileSync(e,D))||{}}catch(t){return B(t.message||".prettierrc\u8f6c\u6362\u9519\u8bef"),{}}return require("./.prettierrc")},C=()=>{const e=p.default.join(q,"project.config.json");if(!u.default.existsSync(e))return{};try{return JSON.parse(u.default.readFileSync(e,D))||{}}catch(t){return B(t.message||"project.config.json\u8f6c\u6362\u9519\u8bef"),{}}},M=()=>{const e=p.default.join(q,"package.json");if(!u.default.existsSync(e))return{};try{return JSON.parse(u.default.readFileSync(e,D))||{}}catch(t){return B(t.message||"package.json\u8f6c\u6362\u9519\u8bef"),{}}},V=()=>u.default.existsSync(p.default.join(q,"project.config.json")),G=()=>{let e=u.default.existsSync(p.default.join(q,"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+)/.test((0,d.execSync)("umi -v").toString())}catch(t){}if(!e){const s=p.default.join(q,"node_modules","umi","package.json");if(u.default.existsSync(s))try{const t=JSON.parse(u.default.readFileSync(s,D))||{};e=t.version&&+t.version.split(".")[0]>3}catch(t){}}return e},H=()=>{const e=p.default.join(q,"project.config.json");if(u.default.existsSync(e)){const t=require(e);return t.appid}return""},X=()=>u.default.existsSync(p.default.join(q,"project.tt.json"))&&0===H().indexOf("tt"),z=()=>0===H().indexOf("20"),Z=()=>{const e=L();let t="";try{t=require.resolve("@baic/eslint-config-yolk")}catch(n){}const s=b.default.sync("*.eslintrc*",{cwd:q,dot:!0}),a=s[0];return!1===e.strict&&a&&u.default.existsSync(a)?a:u.default.existsSync(t)?t:a},ee=()=>{const e=L();let t="";try{t=require.resolve("@baic/stylelint-config-yolk")}catch(n){}const s=b.default.sync("*.stylelintrc*",{cwd:q,dot:!0}),a=s[0];return!1===e.strict&&a&&u.default.existsSync(a)?a:u.default.existsSync(t)?t:a},te=()=>{const e=p.default.join(q,".git/"),t=p.default.join(q,".git/hooks"),s=p.default.join(t,"pre-commit"),a=u.default.existsSync(e),n=u.default.existsSync(s),i=n&&u.default.readFileSync(s,D).includes(P);if(a&&(!n||!i)){v.default.sync(t),u.default.writeFileSync(s,["#!/usr/bin/env bash","npx yolk pre-commit","RESULT=$?","[ $RESULT -ne 0 ] && exit 1","exit 0",P].join(m.default.EOL),D);try{u.default.chmodSync(s,"777")}catch(o){B(`chmod ${s} failed: ${o.message}`)}K("Create pre-commit hook")}},se=()=>{const e=L(),t=!1!==e.strict,s=e.eslintIgnore,a=e.stylelintIgnore;O().then((e=>{const n=s=>new Promise(((n,i)=>{const o=ee();if(o){const r=e.map((e=>e.filename)).filter((e=>/^(src|tests)/i.test(e))).filter((e=>({css:/\.cs{2}$/i,less:/\.les{2}$/i,sass:/\.sas{2}$/i,scss:/\.scs{2}$/i}[s].test(e)))).filter((e=>{const t=p.default.join(q,e);return u.default.existsSync(t)})).filter((e=>I.every((t=>!(0,x.default)(e,t,{matchBase:!0}))))).filter((e=>"string"===typeof a?!(0,x.default)(e,a,{matchBase:!0}):a instanceof RegExp?!a.test(e):!Array.isArray(a)||a.every((t=>"string"===typeof t?!(0,x.default)(e,t,{matchBase:!0}):!(t instanceof RegExp)||!t.test(e)))));if(r.length)if(r.forEach((e=>{if(e&&u.default.existsSync(e)){const t=p.default.extname(e).replace(/^\./,""),s=u.default.readFileSync(e,D),a=(0,j.format)(s,{parser:_[t],...J()});u.default.writeFileSync(e,a,D)}})),K(`${s} - ${r.length} files prettier success!`),r.length>=F){const e=[];f.default.chunk(r,F).forEach((a=>{e.push(new Promise(((e,n)=>{Y({command:"stylelint",args:[t?"--ignore-disables":"","--allow-empty-input","--custom-syntax",`postcss-${s}`,"--config",o,...a],complete:e,close:n,exit:!1})})))}));let a=0;const c=()=>{a<e.length?e[a].then((()=>{a++,c()})).catch(i):(K(`${s} - ${r.length} files stylelint success!`),n())};c()}else r.length&&Y({command:"stylelint",args:[t?"--ignore-disables":"","--allow-empty-input","--custom-syntax",`postcss-${s}`,"--config",o,...r],complete:()=>{K(`${s} - ${r.length} files stylelint success!`),n()},close:i,exit:!1});else n()}else B(`\u6ca1\u6709 stylelintrc \u6587\u4ef6\uff0c${s} files prettier fail!`),n()})),i=a=>new Promise(((n,i)=>{const o=Z();if(o){const r=e.map((e=>e.filename)).filter((e=>/^(src|tests)/i.test(e))).filter((e=>({js:/\.js$/i,jsx:/\.jsx$/i,ts:/\.ts$/i,tsx:/\.tsx$/i}[a].test(e)))).filter((e=>{const t=p.default.join(q,e);return u.default.existsSync(t)})).filter((e=>I.every((t=>!(0,x.default)(e,t,{matchBase:!0}))))).filter((e=>"string"===typeof s?!(0,x.default)(e,s,{matchBase:!0}):s instanceof RegExp?!s.test(e):!Array.isArray(s)||s.every((t=>"string"===typeof t?!(0,x.default)(e,t,{matchBase:!0}):!(t instanceof RegExp)||!t.test(e)))));if(r.length)if(r.forEach((e=>{if(e&&u.default.existsSync(e)){const t=p.default.extname(e).replace(/^\./,""),s=u.default.readFileSync(e,D),a=(0,j.format)(s,{parser:_[t],...J()});u.default.writeFileSync(e,a,D)}})),K(`${a} - ${r.length} files prettier success!`),r.length>=F){const e=[];f.default.chunk(r,F).forEach((s=>{e.push(new Promise(((e,a)=>{Y({command:"eslint",args:[t?"--no-inline-config --no-ignore":"","--no-error-on-unmatched-pattern","--config",o,...s],complete:e,close:a,exit:!1})})))}));let s=0;const c=()=>{s<e.length?e[s].then((()=>{s++,c()})).catch(i):(K(`${a} - ${r.length} files eslint success!`),n())};c()}else r.length&&Y({command:"eslint",args:[t?"--no-inline-config --no-ignore":"","--no-error-on-unmatched-pattern","--config",o,...r],complete:()=>{K(`${a} - ${r.length} files eslint success!`),n()},close:i,exit:!1});else n()}else B(`\u6ca1\u6709 eslintrc \u6587\u4ef6\uff0c${a} files eslint fail!`),n()}));N("\u7edf\u4e00\u4ee3\u7801\u89c4\u8303\uff0c\u8fdb\u884c\u4e25\u683c\u7684\u8bed\u6cd5\u68c0\u67e5\u3002"),t&&(N("git commit \u7981\u6b62 lint \u7684 ignore \u884c\u4e3a"),a&&N(`\u901a\u8fc7 .yolkrc \u914d\u7f6e stylelintIgnore: ${a}\u3002`),s&&N(`\u901a\u8fc7 .yolkrc \u914d\u7f6e eslintIgnore: ${s}\u3002`)),n("css").then((()=>n("less"))).then((()=>n("sass"))).then((()=>n("scss"))).then((()=>i("js"))).then((()=>i("jsx"))).then((()=>i("ts"))).then((()=>i("tsx"))).then(R).catch(R)}))},ae=({mAppid:e,mProject:t,mPrivateKeyPath:s,mVersion:a,mDesc:n,mRobot:i,mQrcodeFormat:o,mQrcodeOutputDest:r,mPagePath:c,mSearchQuery:l})=>{const m=u.default.existsSync(p.default.join(q,".git"))?(0,d.execSync)("git log -1 --pretty=format:%H").toString():"",f=C(),y=e||f.appid,h=t||p.default.join(q,"dist"),$=s||p.default.join(q,`private.${y}.key`);if(u.default.existsSync(h)){if(u.default.existsSync($)){const e=M(),t=a||e.version||f.version||"1.0.0",s=n||e.description||f.description,d=`version: ${t};${m?` commit: ${m};`:""}${s?` description: ${s};`:""}`;m&&U(`commit: ${m}`),U(`dist: ${h}`),U(`key: ${$}`),U(`appid: ${y}`),U(`version: ${t}`),U(`desc: ${d}`);const u=new g.Project({appid:y,type:"miniProgram",projectPath:h,privateKeyPath:$,ignores:["node_modules/**/*","**/*.txt","**/*.key","**/*.less","**/*.sass","**/*.scss","**/*.css","**/*.jsx","**/*.ts","**/*.tsx","**/*.md"]});return{appid:y,options:{project:u,version:t,desc:d,setting:f.setting,robot:i,qrcodeFormat:o,qrcodeOutputDest:r,pagePath:c,searchQuery:l}}}throw Error(`\u6ca1\u6709\u627e\u5230\u4e0a\u4f20\u5bc6\u94a5(${$})`)}throw Error(`\u6ca1\u6709\u627e\u5230dist\u76ee\u5f55(${h})`)},ne=()=>{te(),process.argv.length>2?$.default.version(w.default.version,"-v,--version","\u8f93\u51fa\u7248\u672c\u53f7").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("--mAppid <appid>","\u5c0f\u7a0b\u5e8fappid").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,t)=>{const[s,...a]=t,{clone:n,template:i,docs:o}=e;if(s)switch(U(`yolk version: ${w.default.version}`),U(`node version: ${process.version}`),U(`platform: ${m.default.platform()}`),U(`memory: ${f.default.floor(m.default.freemem()/1024/1024)} MB(${f.default.floor(m.default.totalmem()/1024/1024)} MB)`),s){case"init":if(K(`yolk ${s} \u5f00\u59cb`),n)if(i){const e=".yolk",t=p.default.join(q,e);u.default.existsSync(t)&&(0,k.default)(t,(()=>{K(`\u7f13\u5b58\u5220\u9664 success! ${t}`)})),Y({command:"git",args:["clone","-b","master","--depth","1",i,e].concat(a)}),W(q,t)}else B("--clone \u6a21\u5f0f\u5fc5\u987b\u6709--template");else A(q);break;case"start":V()?X()?Y({command:"taro",args:["build","--type","tt","--watch"].concat(a)}):z()?Y({command:"taro",args:["build","--type","alipay","--watch"].concat(a)}):Y({command:"taro",args:["build","--type","weapp","--watch"].concat(a)}):o?(process.env.DID_YOU_KNOW="none",Y({command:"dumi",args:["dev"].concat(a)})):G()?(process.env.DID_YOU_KNOW="none",Y({command:"max",args:["dev"].concat(a)})):(process.env.DID_YOU_KNOW="none",Y({command:"umi",args:["dev"].concat(a)}));break;case"build":V()?X()?Y({command:"taro",args:["build","--type","tt"].concat(a)}):z()?Y({command:"taro",args:["build","--type","alipay"].concat(a)}):Y({command:"taro",args:["build","--type","weapp"].concat(a)}):o?(process.env.DID_YOU_KNOW="none",Y({command:"dumi",args:["build"].concat(a)})):G()?(process.env.DID_YOU_KNOW="none",Y({command:"max",args:["setup"].concat(a),complete:()=>Y({command:"max",args:["build"].concat(a)}),exit:!1})):(process.env.DID_YOU_KNOW="none",Y({command:"umi",args:["build"].concat(a)}));break;case"pre-commit":se();break;case"miniprogram-upload":if(V())if(X());else if(z());else{const{appid:t,options:s}=ae(e);U(`${t}\u4e0a\u4f20\u5f00\u59cb`),g.upload({...f.default.pick(s,["project","version","desc","setting","robot"]),onProgressUpdate:e=>{if(f.default.isString(e))U(`task: ${e}`);else{const{status:t,message:s}=e;U(`task(${t}): ${s}`)}}}).then((()=>{K(`${t}\u4e0a\u4f20\u5b8c\u6210`)}))}break;case"miniprogram-preview":if(V())if(X());else if(z());else{const{appid:t,options:s}=ae(e);U(`${t}\u4e0a\u4f20\u9884\u89c8\u5f00\u59cb`),g.preview({...f.default.pick(s,["project","version","desc","setting","robot","qrcodeFormat","qrcodeOutputDest","pagePath","searchQuery"]),onProgressUpdate:e=>{if(f.default.isString(e))U(`task: ${e}`);else{const{status:t,message:s}=e;U(`task(${t}): ${s}`)}}}).then((()=>{K(`${t}\u4e0a\u4f20\u9884\u89c8\u5b8c\u6210`)}))}break;default:T()}})).parse(process.argv):T()};ne();
|
|
2
|
+
var e=Object.create,t=Object.defineProperty,s=Object.getOwnPropertyDescriptor,a=Object.getOwnPropertyNames,n=Object.getPrototypeOf,i=Object.prototype.hasOwnProperty,o=(e,n,o,r)=>{if(n&&"object"===typeof n||"function"===typeof n)for(let c of a(n))i.call(e,c)||c===o||t(e,c,{get:()=>n[c],enumerable:!(r=s(n,c))||r.enumerable});return e},r=(s,a,i)=>(i=null!=s?e(n(s)):{},o(!a&&s&&s.__esModule?i:t(i,"default",{value:s,enumerable:!0}),s)),c=e=>o(t({},"__esModule",{value:!0}),e),l={};module.exports=c(l);var d=require("child_process"),u=r(require("fs")),m=r(require("os")),p=r(require("path")),f=r(require("lodash")),y=r(require("inquirer")),g=r(require("miniprogram-ci")),h=r(require("ora")),$=r(require("../compiled/commander")),b=r(require("../compiled/glob")),x=r(require("../compiled/minimatch")),S=r(require("../compiled/mkdirp")),j=r(require("../compiled/mustache")),v=require("../compiled/prettier"),k=r(require("../compiled/rimraf")),w=r(require("../package.json")),O=require("../compiled/staged-git-files"),q=process.cwd(),P="##### CREATED BY YOLK #####",_={ts:"typescript",tsx:"typescript",less:"less",sass:"scss",scss:"scss",css:"css"},D="utf-8",F=20,I=["**/node_modules/**","**/.umi/**","**/.umi-production/**","**/build/**","**/dist/**","**/lib/**","**/es/**","**/public/**","**/assets/**","**/h5+app/**","**/android/**","**/ios/**","**/mock/**","**/yolk*/**"],E=(0,h.default)(),N=e=>e&&E.warn(Buffer.from(e,D).toString()),B=e=>e&&E.fail(Buffer.from(e,D).toString()),K=e=>e&&E.succeed(Buffer.from(e,D).toString()),U=e=>e&&E.info(Buffer.from(e,D).toString()),Q=e=>"win32"===process.platform?`${e}.cmd`:e,R=()=>{K("yolk complete!"),process.exit(0)},T=()=>{N("yolk break!"),process.exit(0)},Y=({command:e,args:t,complete:s,close:a,exit:n=!0})=>{const i=(0,d.spawn)(Q(e),t||[],{stdio:"inherit"}).on("close",(e=>{e?(a&&a(),B("yolk close!"),process.exit(e)):(s&&s(),n&&R())}));process.on("SIGINT",(()=>{$.default.runningCommand&&$.default.runningCommand.kill("SIGKILL"),i.kill(),T()}))},A=(e,t,s)=>{y.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:"miniprogram template",value:"miniprogram"}]},{type:"input",name:"projectName",message:"\u9879\u76ee\u540d\u79f0",default:p.default.basename(p.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((a=>{const n={projectName:a.projectName,dependenciesInstallType:a.dependenciesInstallType,yolkVersion:w.default.version},i=t||p.default.join(__dirname,`../templates/${a.type}`);K(`\u590d\u5236\u6a21\u7248 ${p.default.basename(i)}`);const o=b.default.sync("**/*",{cwd:i,dot:!0,ignore:["**/node_modules/**","**/.git/**","**/.DS_Store","**/.idea/**"]});if(o.forEach((t=>{if(!i)return;const s=p.default.join(i,t);if(!u.default.statSync(s).isDirectory())if(t.endsWith(".tpl")){const a=u.default.readFileSync(s,D),i=p.default.join(e,t.replace(/\.tpl$/,"")),o=j.default.render(a,n);S.default.sync(p.default.dirname(i)),K(`\u521b\u5efa ${p.default.relative(e,i)}`),u.default.writeFileSync(i,o,D)}else{K(`\u521b\u5efa ${t}`);const a=p.default.join(e,t);S.default.sync(p.default.dirname(a)),u.default.copyFileSync(s,a)}})),K("\u590d\u5236\u6a21\u7248 success!"),s&&u.default.existsSync(i)&&(0,k.default)(i,(()=>{K(`\u7f13\u5b58\u5220\u9664 success! ${p.default.basename(i||"")}`)})),a.dependenciesInstallType)switch(K("\u521d\u59cb\u5316\u4f9d\u8d56\u5305"),a.dependenciesInstallType){case"default":case"pnpm":Y({command:"pnpm",args:["install"]});break;case"yarn":Y({command:"yarn",args:["install"]});break;case"npm":Y({command:"npm",args:["install"]});break;default:}K("\u53ef\u67e5\u9605<<https://303394539.github.io/yolk-docs/>>\u4e86\u89e3\u76f8\u5173\u6587\u6863")}))},W=(e,t)=>A(e,t,!0),L=()=>{const e=b.default.sync("*.yolkrc*",{cwd:q,dot:!0});if(!e.length)return{};const t=p.default.join(q,e[0]);if(!u.default.existsSync(t))return{};try{return JSON.parse(u.default.readFileSync(t,D))||{}}catch(s){return B(s.message||".yolkrc\u8f6c\u6362\u9519\u8bef"),{}}},J=()=>{const e=p.default.join(q,".prettierrc");if(u.default.existsSync(e))try{return JSON.parse(u.default.readFileSync(e,D))||{}}catch(t){return B(t.message||".prettierrc\u8f6c\u6362\u9519\u8bef"),{}}return require("./.prettierrc")},C=()=>{const e=p.default.join(q,"project.config.json");if(!u.default.existsSync(e))return{};try{return JSON.parse(u.default.readFileSync(e,D))||{}}catch(t){return B(t.message||"project.config.json\u8f6c\u6362\u9519\u8bef"),{}}},M=()=>{const e=p.default.join(q,"package.json");if(!u.default.existsSync(e))return{};try{return JSON.parse(u.default.readFileSync(e,D))||{}}catch(t){return B(t.message||"package.json\u8f6c\u6362\u9519\u8bef"),{}}},V=()=>u.default.existsSync(p.default.join(q,"project.config.json")),G=()=>{let e=u.default.existsSync(p.default.join(q,"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+)/.test((0,d.execSync)("umi -v").toString())}catch(t){}if(!e){const s=p.default.join(q,"node_modules","umi","package.json");if(u.default.existsSync(s))try{const t=JSON.parse(u.default.readFileSync(s,D))||{};e=t.version&&+t.version.split(".")[0]>3}catch(t){}}return e},H=()=>{const e=p.default.join(q,"project.config.json");if(u.default.existsSync(e)){const t=require(e);return t.appid}return""},X=()=>u.default.existsSync(p.default.join(q,"project.tt.json"))&&0===H().indexOf("tt"),z=()=>0===H().indexOf("20"),Z=()=>{const e=L();let t="";try{t=require.resolve("@baic/eslint-config-yolk")}catch(n){}const s=b.default.sync("*.eslintrc*",{cwd:q,dot:!0}),a=s[0];return!1===e.strict&&a&&u.default.existsSync(a)?a:u.default.existsSync(t)?t:a},ee=()=>{const e=L();let t="";try{t=require.resolve("@baic/stylelint-config-yolk")}catch(n){}const s=b.default.sync("*.stylelintrc*",{cwd:q,dot:!0}),a=s[0];return!1===e.strict&&a&&u.default.existsSync(a)?a:u.default.existsSync(t)?t:a},te=()=>{const e=p.default.join(q,".git/"),t=p.default.join(q,".git/hooks"),s=p.default.join(t,"pre-commit"),a=u.default.existsSync(e),n=u.default.existsSync(s),i=n&&u.default.readFileSync(s,D).includes(P);if(a&&(!n||!i)){S.default.sync(t),u.default.writeFileSync(s,["#!/usr/bin/env bash","npx yolk pre-commit","RESULT=$?","[ $RESULT -ne 0 ] && exit 1","exit 0",P].join(m.default.EOL),D);try{u.default.chmodSync(s,"777")}catch(o){B(`chmod ${s} failed: ${o.message}`)}K("Create pre-commit hook")}},se=()=>{const e=L(),t=!1!==e.strict,s=e.eslintIgnore,a=e.stylelintIgnore;O().then((e=>{const n=s=>new Promise(((n,i)=>{const o=ee();if(o){const r=e.map((e=>e.filename)).filter((e=>/^(src|tests)/i.test(e))).filter((e=>({css:/\.cs{2}$/i,less:/\.les{2}$/i,sass:/\.sas{2}$/i,scss:/\.scs{2}$/i}[s].test(e)))).filter((e=>{const t=p.default.join(q,e);return u.default.existsSync(t)})).filter((e=>I.every((t=>!(0,x.default)(e,t,{matchBase:!0}))))).filter((e=>"string"===typeof a?!(0,x.default)(e,a,{matchBase:!0}):a instanceof RegExp?!a.test(e):!Array.isArray(a)||a.every((t=>"string"===typeof t?!(0,x.default)(e,t,{matchBase:!0}):!(t instanceof RegExp)||!t.test(e)))));if(r.length)if(r.forEach((e=>{if(e&&u.default.existsSync(e)){const t=p.default.extname(e).replace(/^\./,""),s=u.default.readFileSync(e,D),a=(0,v.format)(s,{parser:_[t],...J()});u.default.writeFileSync(e,a,D)}})),K(`${s} - ${r.length} files prettier success!`),r.length>=F){const e=[];f.default.chunk(r,F).forEach((a=>{e.push(new Promise(((e,n)=>{Y({command:"stylelint",args:[t?"--ignore-disables":"","--allow-empty-input","--custom-syntax",`postcss-${s}`,"--config",o,...a],complete:e,close:n,exit:!1})})))}));let a=0;const c=()=>{a<e.length?e[a].then((()=>{a++,c()})).catch(i):(K(`${s} - ${r.length} files stylelint success!`),n())};c()}else r.length&&Y({command:"stylelint",args:[t?"--ignore-disables":"","--allow-empty-input","--custom-syntax",`postcss-${s}`,"--config",o,...r],complete:()=>{K(`${s} - ${r.length} files stylelint success!`),n()},close:i,exit:!1});else n()}else B(`\u6ca1\u6709 stylelintrc \u6587\u4ef6\uff0c${s} files prettier fail!`),n()})),i=a=>new Promise(((n,i)=>{const o=Z();if(o){const r=e.map((e=>e.filename)).filter((e=>/^(src|tests)/i.test(e))).filter((e=>({js:/\.js$/i,jsx:/\.jsx$/i,ts:/\.ts$/i,tsx:/\.tsx$/i}[a].test(e)))).filter((e=>{const t=p.default.join(q,e);return u.default.existsSync(t)})).filter((e=>I.every((t=>!(0,x.default)(e,t,{matchBase:!0}))))).filter((e=>"string"===typeof s?!(0,x.default)(e,s,{matchBase:!0}):s instanceof RegExp?!s.test(e):!Array.isArray(s)||s.every((t=>"string"===typeof t?!(0,x.default)(e,t,{matchBase:!0}):!(t instanceof RegExp)||!t.test(e)))));if(r.length)if(r.forEach((e=>{if(e&&u.default.existsSync(e)){const t=p.default.extname(e).replace(/^\./,""),s=u.default.readFileSync(e,D),a=(0,v.format)(s,{parser:_[t],...J()});u.default.writeFileSync(e,a,D)}})),K(`${a} - ${r.length} files prettier success!`),r.length>=F){const e=[];f.default.chunk(r,F).forEach((s=>{e.push(new Promise(((e,a)=>{Y({command:"eslint",args:[t?"--no-inline-config --no-ignore":"","--no-error-on-unmatched-pattern","--config",o,...s],complete:e,close:a,exit:!1})})))}));let s=0;const c=()=>{s<e.length?e[s].then((()=>{s++,c()})).catch(i):(K(`${a} - ${r.length} files eslint success!`),n())};c()}else r.length&&Y({command:"eslint",args:[t?"--no-inline-config --no-ignore":"","--no-error-on-unmatched-pattern","--config",o,...r],complete:()=>{K(`${a} - ${r.length} files eslint success!`),n()},close:i,exit:!1});else n()}else B(`\u6ca1\u6709 eslintrc \u6587\u4ef6\uff0c${a} files eslint fail!`),n()}));N("\u7edf\u4e00\u4ee3\u7801\u89c4\u8303\uff0c\u8fdb\u884c\u4e25\u683c\u7684\u8bed\u6cd5\u68c0\u67e5\u3002"),t&&(N("git commit \u7981\u6b62 lint \u7684 ignore \u884c\u4e3a"),a&&N(`\u901a\u8fc7 .yolkrc \u914d\u7f6e stylelintIgnore: ${a}\u3002`),s&&N(`\u901a\u8fc7 .yolkrc \u914d\u7f6e eslintIgnore: ${s}\u3002`)),n("css").then((()=>n("less"))).then((()=>n("sass"))).then((()=>n("scss"))).then((()=>i("js"))).then((()=>i("jsx"))).then((()=>i("ts"))).then((()=>i("tsx"))).then(R).catch(R)}))},ae=({mAppid:e,mProject:t,mPrivateKeyPath:s,mVersion:a,mDesc:n,mRobot:i,mQrcodeFormat:o,mQrcodeOutputDest:r,mPagePath:c,mSearchQuery:l})=>{const m=u.default.existsSync(p.default.join(q,".git"))?(0,d.execSync)("git log -1 --pretty=format:%H").toString():"",f=C(),y=e||f.appid,h=t||p.default.join(q,"dist"),$=s||p.default.join(q,`private.${y}.key`);if(u.default.existsSync(h)){if(u.default.existsSync($)){const e=M(),t=a||e.version||f.version||"1.0.0",s=n||e.description||f.description,d=`${m?` commit: ${m};`:""}${s?` description: ${s};`:""}`;m&&U(`commit: ${m}`),U(`dist: ${h}`),U(`key: ${$}`),U(`appid: ${y}`),U(`version: ${t}`),U(`desc: ${d}`);const u=new g.Project({appid:y,type:"miniProgram",projectPath:h,privateKeyPath:$,ignores:["node_modules/**/*","**/*.txt","**/*.key","**/*.less","**/*.sass","**/*.scss","**/*.css","**/*.jsx","**/*.ts","**/*.tsx","**/*.md"]});return{appid:y,options:{project:u,version:t,desc:d,setting:f.setting,robot:i,qrcodeFormat:o,qrcodeOutputDest:r,pagePath:c,searchQuery:l}}}throw Error(`\u6ca1\u6709\u627e\u5230\u4e0a\u4f20\u5bc6\u94a5(${$})`)}throw Error(`\u6ca1\u6709\u627e\u5230dist\u76ee\u5f55(${h})`)},ne=()=>{te(),process.argv.length>2?$.default.version(w.default.version,"-v,--version","\u8f93\u51fa\u7248\u672c\u53f7").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("--mAppid <appid>","\u5c0f\u7a0b\u5e8fappid").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,t)=>{const[s,...a]=t,{clone:n,template:i,docs:o}=e;if(s)switch(U(`yolk version: ${w.default.version}`),U(`node version: ${process.version}`),U(`platform: ${m.default.platform()}`),U(`memory: ${f.default.floor(m.default.freemem()/1024/1024)} MB(${f.default.floor(m.default.totalmem()/1024/1024)} MB)`),s){case"init":if(K(`yolk ${s} \u5f00\u59cb`),n)if(i){const e=".yolk",t=p.default.join(q,e);u.default.existsSync(t)&&(0,k.default)(t,(()=>{K(`\u7f13\u5b58\u5220\u9664 success! ${t}`)})),Y({command:"git",args:["clone","-b","master","--depth","1",i,e].concat(a)}),W(q,t)}else B("--clone \u6a21\u5f0f\u5fc5\u987b\u6709--template");else A(q);break;case"start":V()?X()?Y({command:"taro",args:["build","--type","tt","--watch"].concat(a)}):z()?Y({command:"taro",args:["build","--type","alipay","--watch"].concat(a)}):Y({command:"taro",args:["build","--type","weapp","--watch"].concat(a)}):o?(process.env.DID_YOU_KNOW="none",Y({command:"dumi",args:["dev"].concat(a)})):G()?(process.env.DID_YOU_KNOW="none",Y({command:"max",args:["dev"].concat(a)})):(process.env.DID_YOU_KNOW="none",Y({command:"umi",args:["dev"].concat(a)}));break;case"build":V()?X()?Y({command:"taro",args:["build","--type","tt"].concat(a)}):z()?Y({command:"taro",args:["build","--type","alipay"].concat(a)}):Y({command:"taro",args:["build","--type","weapp"].concat(a)}):o?(process.env.DID_YOU_KNOW="none",Y({command:"dumi",args:["build"].concat(a)})):G()?(process.env.DID_YOU_KNOW="none",Y({command:"max",args:["setup"].concat(a),complete:()=>Y({command:"max",args:["build"].concat(a)}),exit:!1})):(process.env.DID_YOU_KNOW="none",Y({command:"umi",args:["build"].concat(a)}));break;case"pre-commit":se();break;case"miniprogram-upload":if(V())if(X());else if(z());else{const{appid:t,options:s}=ae(e);U(`${t}\u4e0a\u4f20\u5f00\u59cb`),g.upload({...f.default.pick(s,["project","version","desc","setting","robot"]),onProgressUpdate:e=>{if(f.default.isString(e))U(`task: ${e}`);else{const{status:t,message:s}=e;U(`task(${t}): ${s}`)}}}).then((()=>{K(`${t}\u4e0a\u4f20\u5b8c\u6210`)}))}break;case"miniprogram-preview":if(V())if(X());else if(z());else{const{appid:t,options:s}=ae(e);U(`${t}\u4e0a\u4f20\u9884\u89c8\u5f00\u59cb`),g.preview({...f.default.pick(s,["project","version","desc","setting","robot","qrcodeFormat","qrcodeOutputDest","pagePath","searchQuery"]),onProgressUpdate:e=>{if(f.default.isString(e))U(`task: ${e}`);else{const{status:t,message:s}=e;U(`task(${t}): ${s}`)}}}).then((()=>{K(`${t}\u4e0a\u4f20\u9884\u89c8\u5b8c\u6210`)}))}break;default:T()}})).parse(process.argv):T()};ne();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@baic/yolk-cli",
|
|
3
|
-
"version": "2.1.0-alpha.
|
|
3
|
+
"version": "2.1.0-alpha.131",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/303394539/yolk.git"
|
|
@@ -53,5 +53,5 @@
|
|
|
53
53
|
"publishConfig": {
|
|
54
54
|
"access": "public"
|
|
55
55
|
},
|
|
56
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "4e1b946fc559fc7c969885fe751091d9eb0717f4"
|
|
57
57
|
}
|