@baic/yolk-cli 1.0.19 → 2.0.1-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/index.d.ts +2 -0
- package/bin/index.js +664 -1
- package/package.json +6 -6
- package/templates/miniapp/base/package.json.tpl +1 -1
package/bin/index.d.ts
ADDED
package/bin/index.js
CHANGED
|
@@ -1,2 +1,665 @@
|
|
|
1
1
|
#! /usr/bin/env node
|
|
2
|
-
"use strict";function _typeof(e){return _typeof="function"===typeof Symbol&&"symbol"===typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"===typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},_typeof(e)}var _isString2=_interopRequireDefault(require("lodash/isString")),_pick2=_interopRequireDefault(require("lodash/pick")),_chunk2=_interopRequireDefault(require("lodash/chunk")),_fs=_interopRequireDefault(require("fs")),_path=_interopRequireDefault(require("path")),_os=_interopRequireDefault(require("os")),_commander=_interopRequireDefault(require("commander")),_inquirer=_interopRequireDefault(require("inquirer")),_child_process=require("child_process"),_ora=_interopRequireDefault(require("ora")),_glob=_interopRequireDefault(require("glob")),_minimatch=_interopRequireDefault(require("minimatch")),_mustache=_interopRequireDefault(require("mustache")),_mkdirp=_interopRequireDefault(require("mkdirp")),_rimraf=_interopRequireDefault(require("rimraf")),_prettier=require("prettier"),miniProgramCi=_interopRequireWildcard(require("miniprogram-ci")),_package=_interopRequireDefault(require("../package.json"));function _getRequireWildcardCache(e){if("function"!==typeof WeakMap)return null;var t=new WeakMap,r=new WeakMap;return(_getRequireWildcardCache=function(e){return e?r:t})(e)}function _interopRequireWildcard(e,t){if(!t&&e&&e.__esModule)return e;if(null===e||"object"!==_typeof(e)&&"function"!==typeof e)return{default:e};var r=_getRequireWildcardCache(t);if(r&&r.has(e))return r.get(e);var n={},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(n,i,o):n[i]=e[i]}return n["default"]=e,r&&r.set(e,n),n}function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function _toArray(e){return _arrayWithHoles(e)||_iterableToArray(e)||_unsupportedIterableToArray(e)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _arrayWithHoles(e){if(Array.isArray(e))return e}function ownKeys(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function _objectSpread(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?ownKeys(Object(r),!0).forEach((function(t){_defineProperty(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):ownKeys(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function _defineProperty(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function _toConsumableArray(e){return _arrayWithoutHoles(e)||_iterableToArray(e)||_unsupportedIterableToArray(e)||_nonIterableSpread()}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(e,t){if(e){if("string"===typeof e)return _arrayLikeToArray(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?_arrayLikeToArray(e,t):void 0}}function _iterableToArray(e){if("undefined"!==typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function _arrayWithoutHoles(e){if(Array.isArray(e))return _arrayLikeToArray(e)}function _arrayLikeToArray(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}var sgf=require("staged-git-files"),cwd=process.cwd(),HOOK_MARK="##### CREATED BY YOLK #####",PRETTIER_PARSER={ts:"typescript",tsx:"typescript"},ENCODING="utf-8",MAX_FILE_COUNT=60,spinner=(0,_ora["default"])(),warn=function(e){return e&&spinner.warn(Buffer.from(e,ENCODING).toString())},fail=function(e){return e&&spinner.fail(Buffer.from(e,ENCODING).toString())},succeed=function(e){return e&&spinner.succeed(Buffer.from(e,ENCODING).toString())},info=function(e){return e&&spinner.info(Buffer.from(e,ENCODING).toString())},getCommand=function(e){return"win32"===process.platform?"".concat(e,".cmd"):e},completeExit=function(){succeed("yolk complete!"),process.exit(0)},breakExit=function(){warn("yolk break!"),process.exit(0)},execCommand=function(e){var t=e.command,r=e.args,n=e.complete,a=e.close,i=e.exit,o=void 0===i||i,c=(0,_child_process.spawn)(getCommand(t),r||[],{stdio:"inherit"}).on("close",(function(e){e?(a&&a(),fail("yolk close!"),process.exit(e)):(n&&n(),o&&completeExit())}));process.on("SIGINT",(function(){_commander["default"].runningCommand&&_commander["default"].runningCommand.kill("SIGKILL"),c.kill(),breakExit()}))},createTemplate=function(e,t,r){_inquirer["default"].prompt([{type:"list",name:"type",message:"\u9009\u62e9\u5e73\u53f0",default:"web",choices:[{name:"web",value:"web"},{name:"mobile",value:"mobile"},{name:"\u5c0f\u7a0b\u5e8f",value:"miniapp"}]},{type:"input",name:"projectName",message:"\u9879\u76ee\u540d\u79f0",default:_path["default"].basename(_path["default"].basename(process.cwd()))},{type:"list",name:"dependenciesInstallType",message:"\u9009\u62e9\u4f9d\u8d56\u5b89\u88c5\u65b9\u5f0f",default:!1,choices:[{name:"yarn install",value:"yarn"},{name:"npm install",value:"npm"},{name:"\u4e0d\u521d\u59cb\u5316",value:!1}]}]).then((function(n){var a={projectName:n.projectName,mobile:"mobile"===n.type,dependenciesInstallType:n.dependenciesInstallType};t||(t=_path["default"].join(__dirname,"../templates/".concat(n.type,"/").concat(t||"base"))),succeed("\u590d\u5236\u6a21\u7248 ".concat(_path["default"].basename(t)));var i=_glob["default"].sync("**/*",{cwd:t,dot:!0,ignore:["**/node_modules/**","**/.git/**","**/.DS_Store","**/.idea/**"]});if(i.forEach((function(r){if(t){var n=_path["default"].join(t,r);if(!_fs["default"].statSync(n).isDirectory())if(r.endsWith(".tpl")){var i=_fs["default"].readFileSync(n,ENCODING),o=_path["default"].join(e,r.replace(/\.tpl$/,"")),c=_mustache["default"].render(i,a);_mkdirp["default"].sync(_path["default"].dirname(o)),succeed("\u521b\u5efa ".concat(_path["default"].relative(e,o))),_fs["default"].writeFileSync(o,c,ENCODING)}else{succeed("\u521b\u5efa ".concat(r));var s=_path["default"].join(e,r);_mkdirp["default"].sync(_path["default"].dirname(s)),_fs["default"].copyFileSync(n,s)}}})),succeed("\u590d\u5236\u6a21\u7248 success!"),r&&_fs["default"].existsSync(t)&&(0,_rimraf["default"])(t,(function(){succeed("\u7f13\u5b58\u5220\u9664 success! ".concat(_path["default"].basename(t||"")))})),n.dependenciesInstallType)switch(succeed("\u521d\u59cb\u5316\u4f9d\u8d56\u5305"),n.dependenciesInstallType){case"npm":execCommand({command:"npm",args:["install"]});break;case"yarn":default:execCommand({command:"yarn",args:["install"]});break}succeed("\u53ef\u67e5\u9605<<https://303394539.github.io/yolk-docs/>>\u4e86\u89e3\u76f8\u5173\u6587\u6863")}))},createGitTemplate=function(e,t){return createTemplate(e,t,!0)},getYolkConfig=function(){var e=_glob["default"].sync("*.yolkrc*",{cwd:cwd,dot:!0});if(!e.length)return{};var t=_path["default"].join(cwd,e[0]);if(!_fs["default"].existsSync(t))return{};try{return JSON.parse(_fs["default"].readFileSync(t,ENCODING))||{}}catch(r){return fail(r.message||".yolkrc\u8f6c\u6362\u9519\u8bef"),{}}},getPrettierConfig=function(){var e=_path["default"].join(cwd,".prettierrc");if(!_fs["default"].existsSync(e)){if(_fs["default"].existsSync(require.resolve("@umijs/fabric/dist/prettier"))){var t=require("@umijs/fabric/dist/prettier");return t}return{}}try{return JSON.parse(_fs["default"].readFileSync(e,ENCODING))||{}}catch(r){return fail(r.message||".prettierrc\u8f6c\u6362\u9519\u8bef"),{}}},getProjectConfigJSON=function(){var e=_path["default"].join(cwd,"project.config.json");if(!_fs["default"].existsSync(e))return{};try{return JSON.parse(_fs["default"].readFileSync(e,ENCODING))||{}}catch(t){return fail(t.message||"project.config.json\u8f6c\u6362\u9519\u8bef"),{}}},getPackageJSON=function(){var e=_path["default"].join(cwd,"package.json");if(!_fs["default"].existsSync(e))return{};try{return JSON.parse(_fs["default"].readFileSync(e,ENCODING))||{}}catch(t){return fail(t.message||"package.json\u8f6c\u6362\u9519\u8bef"),{}}},isMiniapp=function(){return _fs["default"].existsSync(_path["default"].join(cwd,"project.config.json"))},getAppid=function(){var e=_path["default"].join(cwd,"project.config.json");if(_fs["default"].existsSync(e)){var t=require(e);return t.appid}return""},isWX=function(){return 0===getAppid().indexOf("wx")},isTT=function(){return _fs["default"].existsSync(_path["default"].join(cwd,"project.tt.json"))&&0===getAppid().indexOf("tt")},isAlipay=function(){return 0===getAppid().indexOf("20")},getEsLintConfigPath=function(){var e=getYolkConfig(),t=isMiniapp()?require.resolve("@baic/eslint-config-yolk-miniapp"):require.resolve("@baic/eslint-config-yolk"),r=_glob["default"].sync("*.eslintrc*",{cwd:cwd,dot:!0}),n=r[0];return!1===e.strict&&n&&_fs["default"].existsSync(n)?n:t},getStyleLintConfigPath=function(){var e=_glob["default"].sync("*.stylelintrc*",{cwd:cwd,dot:!0}),t=e[0];return t},initPreCommit=function(){var e=_path["default"].join(cwd,".git/"),t=_path["default"].join(cwd,".git/hooks"),r=_path["default"].join(t,"pre-commit"),n=_fs["default"].existsSync(e),a=_fs["default"].existsSync(r),i=a&&_fs["default"].readFileSync(r,"utf8").includes(HOOK_MARK);if(n&&(!a||!i)){_mkdirp["default"].sync(t),_fs["default"].writeFileSync(r,["#!/usr/bin/env bash","npx yolk pre-commit","RESULT=$?","[ $RESULT -ne 0 ] && exit 1","exit 0",HOOK_MARK].join(_os["default"].EOL),"utf8");try{_fs["default"].chmodSync(r,"777")}catch(o){fail("chmod ".concat(r," failed: ").concat(o.message))}succeed("Create pre-commit hook")}},preCommit=function(){var e=getYolkConfig(),t=!1!==e.strict,r=e.eslintIgnore,n=e.stylelintIgnore;sgf().then((function(e){var a=new Promise((function(r,a){var i=getStyleLintConfigPath();if(i){var o=e.map((function(e){return e.filename})).filter((function(e){return/^([s\u017F]rc|te[s\u017F]t[s\u017F])/i.test(e)})).filter((function(e){return/\.(le|[s\u017F]a|[s\u017F]c|c)[s\u017F]{2}$/i.test(e)})).filter((function(e){return"string"===typeof n?!(0,_minimatch["default"])(e,n,{matchBase:!0}):n instanceof RegExp?!n.test(e):!Array.isArray(n)||n.every((function(t){return"string"===typeof t?!(0,_minimatch["default"])(e,t,{matchBase:!0}):t instanceof RegExp&&!t.test(e)}))})).map((function(e){var t=_path["default"].join(cwd,e);return _fs["default"].existsSync(t)?t:null})).filter((function(e){return!!e}));if(o.length>=MAX_FILE_COUNT){var c=[];(0,_chunk2["default"])(o,20).forEach((function(e){c.push(new Promise((function(r,n){execCommand({command:"stylelint",args:[t?"--ignore-disables":"","--allow-empty-input","--config",i].concat(_toConsumableArray(e)),complete:r,close:n,exit:!1})})))}));var s=process.getMaxListeners(),u=(0,_chunk2["default"])(c,s?s/2:2),l=0,f=function e(){l<u.length?Promise.all(u[l]).then((function(){l++,e()}))["catch"](a):r()};f()}else o.length&&execCommand({command:"stylelint",args:[t?"--ignore-disables":"","--allow-empty-input","--config",i].concat(_toConsumableArray(o)),complete:r,close:a,exit:!1})}else r()})),i=function(){var n=e.map((function(e){return e.filename})).filter((function(e){return/^([s\u017F]rc|te[s\u017F]t[s\u017F])/i.test(e)})).filter((function(e){return/\.([jt\|][s\u017F]x?)$/i.test(e)})).map((function(e){var t=_path["default"].join(cwd,e);return _fs["default"].existsSync(t)?t:null})).filter((function(e){return!!e}));if(n.length){n.forEach((function(e){if(e&&_fs["default"].existsSync(e)){var t=_path["default"].extname(e).replace(/^\./,""),r=_fs["default"].readFileSync(e,"utf8"),n=(0,_prettier.format)(r,_objectSpread({parser:PRETTIER_PARSER[t]},getPrettierConfig()));_fs["default"].writeFileSync(e,n,"utf8")}})),succeed("\u683c\u5f0f\u5316 success!");var a=getEsLintConfigPath();if(a){var i=n.filter((function(e){return"string"===typeof r?!(0,_minimatch["default"])(e,r,{matchBase:!0}):r instanceof RegExp?!r.test(e):!Array.isArray(r)||r.every((function(t){return"string"===typeof t?!(0,_minimatch["default"])(e,t,{matchBase:!0}):t instanceof RegExp&&!t.test(e)}))}));if(t&&(warn("git commit\u7981\u6b62eslint\u7684ignore\u65b9\u5f0f(eslint-disable\u3001.eslintrc*\u3001ignore\u7b49)\u3002"),r&&warn("\u901a\u8fc7yolkrc\u914d\u7f6eeslintIgnore\uff1a".concat(r,"\u3002"))),i.length>=MAX_FILE_COUNT){var o=[];(0,_chunk2["default"])(i,20).forEach((function(e){o.push(new Promise((function(r){execCommand({command:"eslint",args:[t?"--no-inline-config --no-ignore":"","--no-error-on-unmatched-pattern","--config",a].concat(_toConsumableArray(e)),complete:r,exit:!1})})))}));var c=process.getMaxListeners(),s=(0,_chunk2["default"])(o,c?c/2:2),u=0,l=function e(){u<s.length?Promise.all(s[u]).then((function(){u++,e()})):completeExit()};l()}else i.length&&execCommand({command:"eslint",args:[t?"--no-inline-config --no-ignore":"","--no-error-on-unmatched-pattern","--config",a].concat(_toConsumableArray(i))})}else warn("\u6ca1\u6709eslint\u914d\u7f6e\u6587\u4ef6")}else completeExit()};warn("\u8981\u6c42\u7edf\u4e00\u4ee3\u7801\u89c4\u8303\uff0c\u8fdb\u884c\u4e25\u683c\u7684\u8bed\u6cd5\u68c0\u67e5\u3002"),a.then(i)}))},getMiniProgramCi=function(e){var t=e.mProject,r=e.mPrivateKeyPath,n=e.mVersion,a=e.mDesc,i=e.mRobot,o=e.mQrcodeFormat,c=e.mQrcodeOutputDest,s=e.mPagePath,u=e.mSearchQuery,l=_fs["default"].existsSync(_path["default"].join(cwd,".git"))?(0,_child_process.execSync)("git log -1 --pretty=format:%H").toString():"",f=getProjectConfigJSON(),p=f.appid,d=t||_path["default"].join(cwd,"dist"),m=r||_path["default"].join(cwd,"private.".concat(p,".key"));if(_fs["default"].existsSync(d)){if(_fs["default"].existsSync(m)){var y=getPackageJSON(),_=n||y.version||f.version||"1.0.0",g=a||y.description||f.description,h="version: ".concat(_,";").concat(l?" commit: ".concat(l,";"):"").concat(g?" description: ".concat(g,";"):"");l&&info("commit: ".concat(l)),info("dist: ".concat(d)),info("key: ".concat(m)),info("appid: ".concat(p)),info("version: ".concat(_)),info("desc: ".concat(h));var b=new miniProgramCi.Project({appid:p,type:"miniProgram",projectPath:d,privateKeyPath:m,ignores:["node_modules/**/*","**/*.txt","**/*.key","**/*.less","**/*.sass","**/*.scss","**/*.css","**/*.jsx","**/*.ts","**/*.tsx","**/*.md"]});return{miniProgramCi:miniProgramCi,appid:p,options:{project:b,version:_,desc:h,setting:f.setting,robot:i,qrcodeFormat:o,qrcodeOutputDest:c,pagePath:s,searchQuery:u}}}throw Error("\u6ca1\u6709\u627e\u5230\u4e0a\u4f20\u5bc6\u94a5(".concat(m,")"))}throw Error("\u6ca1\u6709\u627e\u5230dist\u76ee\u5f55(".concat(d,")"))},install=function(){info("node version: ".concat(process.version)),initPreCommit(),process.argv.length>2?_commander["default"].version(_package["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((function(e,t){var r=_toArray(t),n=r[0],a=r.slice(1),i=e.clone,o=e.template,c=e.docs;if(n)switch(n){case"init":if(succeed("yolk ".concat(n," \u5f00\u59cb")),i)if(o){var s=".yolk",u=_path["default"].join(cwd,s);_fs["default"].existsSync(u)&&(0,_rimraf["default"])(u,(function(){succeed("\u7f13\u5b58\u5220\u9664 success! ".concat(u))})),execCommand({command:"git",args:["clone","-b","master","--depth","1",o,s].concat(a)}),createGitTemplate(cwd,u)}else fail("--clone \u6a21\u5f0f\u5fc5\u987b\u6709--template");else createTemplate(cwd);break;case"start":isMiniapp()?isTT()?execCommand({command:"taro",args:["build","--type","tt","--watch"].concat(a)}):isAlipay()?execCommand({command:"taro",args:["build","--type","alipay","--watch"].concat(a)}):execCommand({command:"taro",args:["build","--type","weapp","--watch"].concat(a)}):execCommand(c?{command:"dumi",args:["dev"].concat(a)}:{command:"umi",args:["dev"].concat(a)});break;case"build":isMiniapp()?isTT()?execCommand({command:"taro",args:["build","--type","tt"].concat(a)}):isAlipay()?execCommand({command:"taro",args:["build","--type","alipay"].concat(a)}):execCommand({command:"taro",args:["build","--type","weapp"].concat(a)}):execCommand(c?{command:"dumi",args:["build"].concat(a)}:{command:"umi",args:["build"].concat(a)});break;case"pre-commit":preCommit();break;case"test":execCommand({command:"umi-test",args:["--no-cache","--update-snapshot","--runInBand","--detectOpenHandles"].concat(a)});break;case"miniapp-upload":if(isMiniapp())if(isTT());else if(isAlipay());else{var l=getMiniProgramCi(e),f=l.miniProgramCi,p=l.appid,d=l.options;info("".concat(p,"\u4e0a\u4f20\u5f00\u59cb")),f.upload(_objectSpread(_objectSpread({},(0,_pick2["default"])(d,["project","version","desc","setting","robot"])),{},{onProgressUpdate:function(e){if((0,_isString2["default"])(e))info("task: ".concat(e));else{var t=e.status,r=e.message;info("task(".concat(t,"): ").concat(r))}}})).then((function(){succeed("".concat(p,"\u4e0a\u4f20\u5b8c\u6210"))}))}break;case"miniapp-preview":if(isMiniapp())if(isTT());else if(isAlipay());else{var m=getMiniProgramCi(e),y=m.miniProgramCi,_=m.appid,g=m.options;info("".concat(_,"\u4e0a\u4f20\u9884\u89c8\u5f00\u59cb")),y.preview(_objectSpread(_objectSpread({},(0,_pick2["default"])(g,["project","version","desc","setting","robot","qrcodeFormat","qrcodeOutputDest","pagePath","searchQuery"])),{},{onProgressUpdate:function(e){if((0,_isString2["default"])(e))info("task: ".concat(e));else{var t=e.status,r=e.message;info("task(".concat(t,"): ").concat(r))}}})).then((function(){succeed("".concat(_,"\u4e0a\u4f20\u9884\u89c8\u5b8c\u6210"))}))}break;default:breakExit()}})).parse(process.argv):breakExit()};install();
|
|
2
|
+
|
|
3
|
+
"use strict";
|
|
4
|
+
|
|
5
|
+
function _typeof(e) {
|
|
6
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (e) {
|
|
7
|
+
return typeof e
|
|
8
|
+
} : function (e) {
|
|
9
|
+
return e && "function" == typeof Symbol && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : typeof e
|
|
10
|
+
}, _typeof(e)
|
|
11
|
+
}
|
|
12
|
+
var _isString2 = _interopRequireDefault(require("lodash/isString")),
|
|
13
|
+
_pick2 = _interopRequireDefault(require("lodash/pick")),
|
|
14
|
+
_chunk2 = _interopRequireDefault(require("lodash/chunk")),
|
|
15
|
+
_fs = _interopRequireDefault(require("fs")),
|
|
16
|
+
_path = _interopRequireDefault(require("path")),
|
|
17
|
+
_os = _interopRequireDefault(require("os")),
|
|
18
|
+
_commander = _interopRequireDefault(require("commander")),
|
|
19
|
+
_inquirer = _interopRequireDefault(require("inquirer")),
|
|
20
|
+
_child_process = require("child_process"),
|
|
21
|
+
_ora = _interopRequireDefault(require("ora")),
|
|
22
|
+
_glob = _interopRequireDefault(require("glob")),
|
|
23
|
+
_minimatch = _interopRequireDefault(require("minimatch")),
|
|
24
|
+
_mustache = _interopRequireDefault(require("mustache")),
|
|
25
|
+
_mkdirp = _interopRequireDefault(require("mkdirp")),
|
|
26
|
+
_rimraf = _interopRequireDefault(require("rimraf")),
|
|
27
|
+
_prettier = require("prettier"),
|
|
28
|
+
miniProgramCi = _interopRequireWildcard(require("miniprogram-ci")),
|
|
29
|
+
_package = _interopRequireDefault(require("../package.json"));
|
|
30
|
+
|
|
31
|
+
function _getRequireWildcardCache(e) {
|
|
32
|
+
if ("function" !== typeof WeakMap) return null;
|
|
33
|
+
var t = new WeakMap,
|
|
34
|
+
r = new WeakMap;
|
|
35
|
+
return (_getRequireWildcardCache = function (e) {
|
|
36
|
+
return e ? r : t
|
|
37
|
+
})(e)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function _interopRequireWildcard(e, t) {
|
|
41
|
+
if (!t && e && e.__esModule) return e;
|
|
42
|
+
if (null === e || "object" !== _typeof(e) && "function" !== typeof e) return {
|
|
43
|
+
default: e
|
|
44
|
+
};
|
|
45
|
+
var r = _getRequireWildcardCache(t);
|
|
46
|
+
if (r && r.has(e)) return r.get(e);
|
|
47
|
+
var n = {},
|
|
48
|
+
a = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
49
|
+
for (var i in e)
|
|
50
|
+
if ("default" !== i && Object.prototype.hasOwnProperty.call(e, i)) {
|
|
51
|
+
var o = a ? Object.getOwnPropertyDescriptor(e, i) : null;
|
|
52
|
+
o && (o.get || o.set) ? Object.defineProperty(n, i, o) : n[i] = e[i]
|
|
53
|
+
} return n["default"] = e, r && r.set(e, n), n
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function _interopRequireDefault(e) {
|
|
57
|
+
return e && e.__esModule ? e : {
|
|
58
|
+
default: e
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function _toArray(e) {
|
|
63
|
+
return _arrayWithHoles(e) || _iterableToArray(e) || _unsupportedIterableToArray(e) || _nonIterableRest()
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function _nonIterableRest() {
|
|
67
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function _arrayWithHoles(e) {
|
|
71
|
+
if (Array.isArray(e)) return e
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function ownKeys(e, t) {
|
|
75
|
+
var r = Object.keys(e);
|
|
76
|
+
if (Object.getOwnPropertySymbols) {
|
|
77
|
+
var n = Object.getOwnPropertySymbols(e);
|
|
78
|
+
t && (n = n.filter((function (t) {
|
|
79
|
+
return Object.getOwnPropertyDescriptor(e, t).enumerable
|
|
80
|
+
}))), r.push.apply(r, n)
|
|
81
|
+
}
|
|
82
|
+
return r
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function _objectSpread(e) {
|
|
86
|
+
for (var t = 1; t < arguments.length; t++) {
|
|
87
|
+
var r = null != arguments[t] ? arguments[t] : {};
|
|
88
|
+
t % 2 ? ownKeys(Object(r), !0).forEach((function (t) {
|
|
89
|
+
_defineProperty(e, t, r[t])
|
|
90
|
+
})) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(r)) : ownKeys(Object(r)).forEach((function (t) {
|
|
91
|
+
Object.defineProperty(e, t, Object.getOwnPropertyDescriptor(r, t))
|
|
92
|
+
}))
|
|
93
|
+
}
|
|
94
|
+
return e
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function _defineProperty(e, t, r) {
|
|
98
|
+
return t in e ? Object.defineProperty(e, t, {
|
|
99
|
+
value: r,
|
|
100
|
+
enumerable: !0,
|
|
101
|
+
configurable: !0,
|
|
102
|
+
writable: !0
|
|
103
|
+
}) : e[t] = r, e
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function _toConsumableArray(e) {
|
|
107
|
+
return _arrayWithoutHoles(e) || _iterableToArray(e) || _unsupportedIterableToArray(e) || _nonIterableSpread()
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function _nonIterableSpread() {
|
|
111
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function _unsupportedIterableToArray(e, t) {
|
|
115
|
+
if (e) {
|
|
116
|
+
if ("string" === typeof e) return _arrayLikeToArray(e, t);
|
|
117
|
+
var r = Object.prototype.toString.call(e).slice(8, -1);
|
|
118
|
+
return "Object" === r && e.constructor && (r = e.constructor.name), "Map" === r || "Set" === r ? Array.from(e) : "Arguments" === r || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r) ? _arrayLikeToArray(e, t) : void 0
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function _iterableToArray(e) {
|
|
123
|
+
if ("undefined" !== typeof Symbol && null != e[Symbol.iterator] || null != e["@@iterator"]) return Array.from(e)
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function _arrayWithoutHoles(e) {
|
|
127
|
+
if (Array.isArray(e)) return _arrayLikeToArray(e)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function _arrayLikeToArray(e, t) {
|
|
131
|
+
(null == t || t > e.length) && (t = e.length);
|
|
132
|
+
for (var r = 0, n = new Array(t); r < t; r++) n[r] = e[r];
|
|
133
|
+
return n
|
|
134
|
+
}
|
|
135
|
+
var sgf = require("staged-git-files"),
|
|
136
|
+
cwd = process.cwd(),
|
|
137
|
+
HOOK_MARK = "##### CREATED BY YOLK #####",
|
|
138
|
+
PRETTIER_PARSER = {
|
|
139
|
+
ts: "typescript",
|
|
140
|
+
tsx: "typescript"
|
|
141
|
+
},
|
|
142
|
+
ENCODING = "utf-8",
|
|
143
|
+
MAX_FILE_COUNT = 60,
|
|
144
|
+
spinner = (0, _ora["default"])(),
|
|
145
|
+
warn = function (e) {
|
|
146
|
+
return e && spinner.warn(Buffer.from(e, ENCODING).toString())
|
|
147
|
+
},
|
|
148
|
+
fail = function (e) {
|
|
149
|
+
return e && spinner.fail(Buffer.from(e, ENCODING).toString())
|
|
150
|
+
},
|
|
151
|
+
succeed = function (e) {
|
|
152
|
+
return e && spinner.succeed(Buffer.from(e, ENCODING).toString())
|
|
153
|
+
},
|
|
154
|
+
info = function (e) {
|
|
155
|
+
return e && spinner.info(Buffer.from(e, ENCODING).toString())
|
|
156
|
+
},
|
|
157
|
+
getCommand = function (e) {
|
|
158
|
+
return "win32" === process.platform ? "".concat(e, ".cmd") : e
|
|
159
|
+
},
|
|
160
|
+
completeExit = function () {
|
|
161
|
+
succeed("yolk complete!"), process.exit(0)
|
|
162
|
+
},
|
|
163
|
+
breakExit = function () {
|
|
164
|
+
warn("yolk break!"), process.exit(0)
|
|
165
|
+
},
|
|
166
|
+
execCommand = function (e) {
|
|
167
|
+
var t = e.command,
|
|
168
|
+
r = e.args,
|
|
169
|
+
n = e.complete,
|
|
170
|
+
a = e.close,
|
|
171
|
+
i = e.exit,
|
|
172
|
+
o = void 0 === i || i,
|
|
173
|
+
c = (0, _child_process.spawn)(getCommand(t), r || [], {
|
|
174
|
+
stdio: "inherit"
|
|
175
|
+
}).on("close", (function (e) {
|
|
176
|
+
e ? (a && a(), fail("yolk close!"), process.exit(e)) : (n && n(), o && completeExit())
|
|
177
|
+
}));
|
|
178
|
+
process.on("SIGINT", (function () {
|
|
179
|
+
_commander["default"].runningCommand && _commander["default"].runningCommand.kill("SIGKILL"), c.kill(), breakExit()
|
|
180
|
+
}))
|
|
181
|
+
},
|
|
182
|
+
createTemplate = function (e, t, r) {
|
|
183
|
+
_inquirer["default"].prompt([{
|
|
184
|
+
type: "list",
|
|
185
|
+
name: "type",
|
|
186
|
+
message: "\u9009\u62e9\u5e73\u53f0",
|
|
187
|
+
default: "web",
|
|
188
|
+
choices: [{
|
|
189
|
+
name: "web",
|
|
190
|
+
value: "web"
|
|
191
|
+
}, {
|
|
192
|
+
name: "mobile",
|
|
193
|
+
value: "mobile"
|
|
194
|
+
}, {
|
|
195
|
+
name: "\u5c0f\u7a0b\u5e8f",
|
|
196
|
+
value: "miniapp"
|
|
197
|
+
}]
|
|
198
|
+
}, {
|
|
199
|
+
type: "input",
|
|
200
|
+
name: "projectName",
|
|
201
|
+
message: "\u9879\u76ee\u540d\u79f0",
|
|
202
|
+
default: _path["default"].basename(_path["default"].basename(process.cwd()))
|
|
203
|
+
}, {
|
|
204
|
+
type: "list",
|
|
205
|
+
name: "dependenciesInstallType",
|
|
206
|
+
message: "\u9009\u62e9\u4f9d\u8d56\u5b89\u88c5\u65b9\u5f0f",
|
|
207
|
+
default: !1,
|
|
208
|
+
choices: [{
|
|
209
|
+
name: "yarn install",
|
|
210
|
+
value: "yarn"
|
|
211
|
+
}, {
|
|
212
|
+
name: "npm install",
|
|
213
|
+
value: "npm"
|
|
214
|
+
}, {
|
|
215
|
+
name: "\u4e0d\u521d\u59cb\u5316",
|
|
216
|
+
value: !1
|
|
217
|
+
}]
|
|
218
|
+
}]).then((function (n) {
|
|
219
|
+
var a = {
|
|
220
|
+
projectName: n.projectName,
|
|
221
|
+
mobile: "mobile" === n.type,
|
|
222
|
+
dependenciesInstallType: n.dependenciesInstallType
|
|
223
|
+
};
|
|
224
|
+
t || (t = _path["default"].join(__dirname, "../templates/".concat(n.type, "/").concat(t || "base"))), succeed("\u590d\u5236\u6a21\u7248 ".concat(_path["default"].basename(t)));
|
|
225
|
+
var i = _glob["default"].sync("**/*", {
|
|
226
|
+
cwd: t,
|
|
227
|
+
dot: !0,
|
|
228
|
+
ignore: ["**/node_modules/**", "**/.git/**", "**/.DS_Store", "**/.idea/**"]
|
|
229
|
+
});
|
|
230
|
+
if (i.forEach((function (r) {
|
|
231
|
+
if (t) {
|
|
232
|
+
var n = _path["default"].join(t, r);
|
|
233
|
+
if (!_fs["default"].statSync(n).isDirectory())
|
|
234
|
+
if (r.endsWith(".tpl")) {
|
|
235
|
+
var i = _fs["default"].readFileSync(n, ENCODING),
|
|
236
|
+
o = _path["default"].join(e, r.replace(/\.tpl$/, "")),
|
|
237
|
+
c = _mustache["default"].render(i, a);
|
|
238
|
+
_mkdirp["default"].sync(_path["default"].dirname(o)), succeed("\u521b\u5efa ".concat(_path["default"].relative(e, o))), _fs["default"].writeFileSync(o, c, ENCODING)
|
|
239
|
+
} else {
|
|
240
|
+
succeed("\u521b\u5efa ".concat(r));
|
|
241
|
+
var s = _path["default"].join(e, r);
|
|
242
|
+
_mkdirp["default"].sync(_path["default"].dirname(s)), _fs["default"].copyFileSync(n, s)
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
})), succeed("\u590d\u5236\u6a21\u7248 success!"), r && _fs["default"].existsSync(t) && (0, _rimraf["default"])(t, (function () {
|
|
246
|
+
succeed("\u7f13\u5b58\u5220\u9664 success! ".concat(_path["default"].basename(t || "")))
|
|
247
|
+
})), n.dependenciesInstallType) switch (succeed("\u521d\u59cb\u5316\u4f9d\u8d56\u5305"), n.dependenciesInstallType) {
|
|
248
|
+
case "npm":
|
|
249
|
+
execCommand({
|
|
250
|
+
command: "npm",
|
|
251
|
+
args: ["install"]
|
|
252
|
+
});
|
|
253
|
+
break;
|
|
254
|
+
case "yarn":
|
|
255
|
+
default:
|
|
256
|
+
execCommand({
|
|
257
|
+
command: "yarn",
|
|
258
|
+
args: ["install"]
|
|
259
|
+
});
|
|
260
|
+
break
|
|
261
|
+
}
|
|
262
|
+
succeed("\u53ef\u67e5\u9605<<https://303394539.github.io/yolk-docs/>>\u4e86\u89e3\u76f8\u5173\u6587\u6863")
|
|
263
|
+
}))
|
|
264
|
+
},
|
|
265
|
+
createGitTemplate = function (e, t) {
|
|
266
|
+
return createTemplate(e, t, !0)
|
|
267
|
+
},
|
|
268
|
+
getYolkConfig = function () {
|
|
269
|
+
var e = _glob["default"].sync("*.yolkrc*", {
|
|
270
|
+
cwd: cwd,
|
|
271
|
+
dot: !0
|
|
272
|
+
});
|
|
273
|
+
if (!e.length) return {};
|
|
274
|
+
var t = _path["default"].join(cwd, e[0]);
|
|
275
|
+
if (!_fs["default"].existsSync(t)) return {};
|
|
276
|
+
try {
|
|
277
|
+
return JSON.parse(_fs["default"].readFileSync(t, ENCODING)) || {}
|
|
278
|
+
} catch (r) {
|
|
279
|
+
return fail(r.message || ".yolkrc\u8f6c\u6362\u9519\u8bef"), {}
|
|
280
|
+
}
|
|
281
|
+
},
|
|
282
|
+
getPrettierConfig = function () {
|
|
283
|
+
var e = _path["default"].join(cwd, ".prettierrc");
|
|
284
|
+
if (!_fs["default"].existsSync(e)) {
|
|
285
|
+
if (_fs["default"].existsSync(require.resolve("@umijs/fabric/dist/prettier"))) {
|
|
286
|
+
var t = require("@umijs/fabric/dist/prettier");
|
|
287
|
+
return t
|
|
288
|
+
}
|
|
289
|
+
return {}
|
|
290
|
+
}
|
|
291
|
+
try {
|
|
292
|
+
return JSON.parse(_fs["default"].readFileSync(e, ENCODING)) || {}
|
|
293
|
+
} catch (r) {
|
|
294
|
+
return fail(r.message || ".prettierrc\u8f6c\u6362\u9519\u8bef"), {}
|
|
295
|
+
}
|
|
296
|
+
},
|
|
297
|
+
getProjectConfigJSON = function () {
|
|
298
|
+
var e = _path["default"].join(cwd, "project.config.json");
|
|
299
|
+
if (!_fs["default"].existsSync(e)) return {};
|
|
300
|
+
try {
|
|
301
|
+
return JSON.parse(_fs["default"].readFileSync(e, ENCODING)) || {}
|
|
302
|
+
} catch (t) {
|
|
303
|
+
return fail(t.message || "project.config.json\u8f6c\u6362\u9519\u8bef"), {}
|
|
304
|
+
}
|
|
305
|
+
},
|
|
306
|
+
getPackageJSON = function () {
|
|
307
|
+
var e = _path["default"].join(cwd, "package.json");
|
|
308
|
+
if (!_fs["default"].existsSync(e)) return {};
|
|
309
|
+
try {
|
|
310
|
+
return JSON.parse(_fs["default"].readFileSync(e, ENCODING)) || {}
|
|
311
|
+
} catch (t) {
|
|
312
|
+
return fail(t.message || "package.json\u8f6c\u6362\u9519\u8bef"), {}
|
|
313
|
+
}
|
|
314
|
+
},
|
|
315
|
+
isMiniapp = function () {
|
|
316
|
+
return _fs["default"].existsSync(_path["default"].join(cwd, "project.config.json"))
|
|
317
|
+
},
|
|
318
|
+
getAppid = function () {
|
|
319
|
+
var e = _path["default"].join(cwd, "project.config.json");
|
|
320
|
+
if (_fs["default"].existsSync(e)) {
|
|
321
|
+
var t = require(e);
|
|
322
|
+
return t.appid
|
|
323
|
+
}
|
|
324
|
+
return ""
|
|
325
|
+
},
|
|
326
|
+
isWX = function () {
|
|
327
|
+
return 0 === getAppid().indexOf("wx")
|
|
328
|
+
},
|
|
329
|
+
isTT = function () {
|
|
330
|
+
return _fs["default"].existsSync(_path["default"].join(cwd, "project.tt.json")) && 0 === getAppid().indexOf("tt")
|
|
331
|
+
},
|
|
332
|
+
isAlipay = function () {
|
|
333
|
+
return 0 === getAppid().indexOf("20")
|
|
334
|
+
},
|
|
335
|
+
getEsLintConfigPath = function () {
|
|
336
|
+
var e = getYolkConfig(),
|
|
337
|
+
t = isMiniapp() ? require.resolve("@baic/eslint-config-yolk-miniapp") : require.resolve("@baic/eslint-config-yolk"),
|
|
338
|
+
r = _glob["default"].sync("*.eslintrc*", {
|
|
339
|
+
cwd: cwd,
|
|
340
|
+
dot: !0
|
|
341
|
+
}),
|
|
342
|
+
n = r[0];
|
|
343
|
+
return !1 === e.strict && n && _fs["default"].existsSync(n) ? n : t
|
|
344
|
+
},
|
|
345
|
+
getStyleLintConfigPath = function () {
|
|
346
|
+
var e = _glob["default"].sync("*.stylelintrc*", {
|
|
347
|
+
cwd: cwd,
|
|
348
|
+
dot: !0
|
|
349
|
+
}),
|
|
350
|
+
t = e[0];
|
|
351
|
+
return t
|
|
352
|
+
},
|
|
353
|
+
initPreCommit = function () {
|
|
354
|
+
var e = _path["default"].join(cwd, ".git/"),
|
|
355
|
+
t = _path["default"].join(cwd, ".git/hooks"),
|
|
356
|
+
r = _path["default"].join(t, "pre-commit"),
|
|
357
|
+
n = _fs["default"].existsSync(e),
|
|
358
|
+
a = _fs["default"].existsSync(r),
|
|
359
|
+
i = a && _fs["default"].readFileSync(r, "utf8").includes(HOOK_MARK);
|
|
360
|
+
if (n && (!a || !i)) {
|
|
361
|
+
_mkdirp["default"].sync(t), _fs["default"].writeFileSync(r, ["#!/usr/bin/env bash", "npx yolk pre-commit", "RESULT=$?", "[ $RESULT -ne 0 ] && exit 1", "exit 0", HOOK_MARK].join(_os["default"].EOL), "utf8");
|
|
362
|
+
try {
|
|
363
|
+
_fs["default"].chmodSync(r, "777")
|
|
364
|
+
} catch (o) {
|
|
365
|
+
fail("chmod ".concat(r, " failed: ").concat(o.message))
|
|
366
|
+
}
|
|
367
|
+
succeed("Create pre-commit hook")
|
|
368
|
+
}
|
|
369
|
+
},
|
|
370
|
+
preCommit = function () {
|
|
371
|
+
var e = getYolkConfig(),
|
|
372
|
+
t = !1 !== e.strict,
|
|
373
|
+
r = e.eslintIgnore,
|
|
374
|
+
n = e.stylelintIgnore;
|
|
375
|
+
sgf().then((function (e) {
|
|
376
|
+
var a = new Promise((function (r, a) {
|
|
377
|
+
var i = getStyleLintConfigPath();
|
|
378
|
+
if (i) {
|
|
379
|
+
var o = e.map((function (e) {
|
|
380
|
+
return e.filename
|
|
381
|
+
})).filter((function (e) {
|
|
382
|
+
return /^([s\u017F]rc|te[s\u017F]t[s\u017F])/i.test(e)
|
|
383
|
+
})).filter((function (e) {
|
|
384
|
+
return /\.(le|[s\u017F]a|[s\u017F]c|c)[s\u017F]{2}$/i.test(e)
|
|
385
|
+
})).filter((function (e) {
|
|
386
|
+
return "string" === typeof n ? !(0, _minimatch["default"])(e, n, {
|
|
387
|
+
matchBase: !0
|
|
388
|
+
}) : n instanceof RegExp ? !n.test(e) : !Array.isArray(n) || n.every((function (t) {
|
|
389
|
+
return "string" === typeof t ? !(0, _minimatch["default"])(e, t, {
|
|
390
|
+
matchBase: !0
|
|
391
|
+
}) : t instanceof RegExp && !t.test(e)
|
|
392
|
+
}))
|
|
393
|
+
})).map((function (e) {
|
|
394
|
+
var t = _path["default"].join(cwd, e);
|
|
395
|
+
return _fs["default"].existsSync(t) ? t : null
|
|
396
|
+
})).filter((function (e) {
|
|
397
|
+
return !!e
|
|
398
|
+
}));
|
|
399
|
+
if (o.length >= MAX_FILE_COUNT) {
|
|
400
|
+
var c = [];
|
|
401
|
+
(0, _chunk2["default"])(o, 20).forEach((function (e) {
|
|
402
|
+
c.push(new Promise((function (r, n) {
|
|
403
|
+
execCommand({
|
|
404
|
+
command: "stylelint",
|
|
405
|
+
args: [t ? "--ignore-disables" : "", "--allow-empty-input", "--config", i].concat(_toConsumableArray(e)),
|
|
406
|
+
complete: r,
|
|
407
|
+
close: n,
|
|
408
|
+
exit: !1
|
|
409
|
+
})
|
|
410
|
+
})))
|
|
411
|
+
}));
|
|
412
|
+
var s = process.getMaxListeners(),
|
|
413
|
+
u = (0, _chunk2["default"])(c, s ? s / 2 : 2),
|
|
414
|
+
l = 0,
|
|
415
|
+
f = function e() {
|
|
416
|
+
l < u.length ? Promise.all(u[l]).then((function () {
|
|
417
|
+
l++, e()
|
|
418
|
+
}))["catch"](a) : r()
|
|
419
|
+
};
|
|
420
|
+
f()
|
|
421
|
+
} else o.length && execCommand({
|
|
422
|
+
command: "stylelint",
|
|
423
|
+
args: [t ? "--ignore-disables" : "", "--allow-empty-input", "--config", i].concat(_toConsumableArray(o)),
|
|
424
|
+
complete: r,
|
|
425
|
+
close: a,
|
|
426
|
+
exit: !1
|
|
427
|
+
})
|
|
428
|
+
} else r()
|
|
429
|
+
})),
|
|
430
|
+
i = function () {
|
|
431
|
+
var n = e.map((function (e) {
|
|
432
|
+
return e.filename
|
|
433
|
+
})).filter((function (e) {
|
|
434
|
+
return /^([s\u017F]rc|te[s\u017F]t[s\u017F])/i.test(e)
|
|
435
|
+
})).filter((function (e) {
|
|
436
|
+
return /\.([jt\|][s\u017F]x?)$/i.test(e)
|
|
437
|
+
})).map((function (e) {
|
|
438
|
+
var t = _path["default"].join(cwd, e);
|
|
439
|
+
return _fs["default"].existsSync(t) ? t : null
|
|
440
|
+
})).filter((function (e) {
|
|
441
|
+
return !!e
|
|
442
|
+
}));
|
|
443
|
+
if (n.length) {
|
|
444
|
+
n.forEach((function (e) {
|
|
445
|
+
if (e && _fs["default"].existsSync(e)) {
|
|
446
|
+
var t = _path["default"].extname(e).replace(/^\./, ""),
|
|
447
|
+
r = _fs["default"].readFileSync(e, "utf8"),
|
|
448
|
+
n = (0, _prettier.format)(r, _objectSpread({
|
|
449
|
+
parser: PRETTIER_PARSER[t]
|
|
450
|
+
}, getPrettierConfig()));
|
|
451
|
+
_fs["default"].writeFileSync(e, n, "utf8")
|
|
452
|
+
}
|
|
453
|
+
})), succeed("\u683c\u5f0f\u5316 success!");
|
|
454
|
+
var a = getEsLintConfigPath();
|
|
455
|
+
if (a) {
|
|
456
|
+
var i = n.filter((function (e) {
|
|
457
|
+
return "string" === typeof r ? !(0, _minimatch["default"])(e, r, {
|
|
458
|
+
matchBase: !0
|
|
459
|
+
}) : r instanceof RegExp ? !r.test(e) : !Array.isArray(r) || r.every((function (t) {
|
|
460
|
+
return "string" === typeof t ? !(0, _minimatch["default"])(e, t, {
|
|
461
|
+
matchBase: !0
|
|
462
|
+
}) : t instanceof RegExp && !t.test(e)
|
|
463
|
+
}))
|
|
464
|
+
}));
|
|
465
|
+
if (t && (warn("git commit\u7981\u6b62eslint\u7684ignore\u65b9\u5f0f(eslint-disable\u3001.eslintrc*\u3001ignore\u7b49)\u3002"), r && warn("\u901a\u8fc7yolkrc\u914d\u7f6eeslintIgnore\uff1a".concat(r, "\u3002"))), i.length >= MAX_FILE_COUNT) {
|
|
466
|
+
var o = [];
|
|
467
|
+
(0, _chunk2["default"])(i, 20).forEach((function (e) {
|
|
468
|
+
o.push(new Promise((function (r) {
|
|
469
|
+
execCommand({
|
|
470
|
+
command: "eslint",
|
|
471
|
+
args: [t ? "--no-inline-config --no-ignore" : "", "--no-error-on-unmatched-pattern", "--config", a].concat(_toConsumableArray(e)),
|
|
472
|
+
complete: r,
|
|
473
|
+
exit: !1
|
|
474
|
+
})
|
|
475
|
+
})))
|
|
476
|
+
}));
|
|
477
|
+
var c = process.getMaxListeners(),
|
|
478
|
+
s = (0, _chunk2["default"])(o, c ? c / 2 : 2),
|
|
479
|
+
u = 0,
|
|
480
|
+
l = function e() {
|
|
481
|
+
u < s.length ? Promise.all(s[u]).then((function () {
|
|
482
|
+
u++, e()
|
|
483
|
+
})) : completeExit()
|
|
484
|
+
};
|
|
485
|
+
l()
|
|
486
|
+
} else i.length && execCommand({
|
|
487
|
+
command: "eslint",
|
|
488
|
+
args: [t ? "--no-inline-config --no-ignore" : "", "--no-error-on-unmatched-pattern", "--config", a].concat(_toConsumableArray(i))
|
|
489
|
+
})
|
|
490
|
+
} else warn("\u6ca1\u6709eslint\u914d\u7f6e\u6587\u4ef6")
|
|
491
|
+
} else completeExit()
|
|
492
|
+
};
|
|
493
|
+
warn("\u8981\u6c42\u7edf\u4e00\u4ee3\u7801\u89c4\u8303\uff0c\u8fdb\u884c\u4e25\u683c\u7684\u8bed\u6cd5\u68c0\u67e5\u3002"), a.then(i)
|
|
494
|
+
}))
|
|
495
|
+
},
|
|
496
|
+
getMiniProgramCi = function (e) {
|
|
497
|
+
var t = e.mProject,
|
|
498
|
+
r = e.mPrivateKeyPath,
|
|
499
|
+
n = e.mVersion,
|
|
500
|
+
a = e.mDesc,
|
|
501
|
+
i = e.mRobot,
|
|
502
|
+
o = e.mQrcodeFormat,
|
|
503
|
+
c = e.mQrcodeOutputDest,
|
|
504
|
+
s = e.mPagePath,
|
|
505
|
+
u = e.mSearchQuery,
|
|
506
|
+
l = _fs["default"].existsSync(_path["default"].join(cwd, ".git")) ? (0, _child_process.execSync)("git log -1 --pretty=format:%H").toString() : "",
|
|
507
|
+
f = getProjectConfigJSON(),
|
|
508
|
+
p = f.appid,
|
|
509
|
+
d = t || _path["default"].join(cwd, "dist"),
|
|
510
|
+
m = r || _path["default"].join(cwd, "private.".concat(p, ".key"));
|
|
511
|
+
if (_fs["default"].existsSync(d)) {
|
|
512
|
+
if (_fs["default"].existsSync(m)) {
|
|
513
|
+
var y = getPackageJSON(),
|
|
514
|
+
_ = n || y.version || f.version || "1.0.0",
|
|
515
|
+
g = a || y.description || f.description,
|
|
516
|
+
h = "version: ".concat(_, ";").concat(l ? " commit: ".concat(l, ";") : "").concat(g ? " description: ".concat(g, ";") : "");
|
|
517
|
+
l && info("commit: ".concat(l)), info("dist: ".concat(d)), info("key: ".concat(m)), info("appid: ".concat(p)), info("version: ".concat(_)), info("desc: ".concat(h));
|
|
518
|
+
var b = new miniProgramCi.Project({
|
|
519
|
+
appid: p,
|
|
520
|
+
type: "miniProgram",
|
|
521
|
+
projectPath: d,
|
|
522
|
+
privateKeyPath: m,
|
|
523
|
+
ignores: ["node_modules/**/*", "**/*.txt", "**/*.key", "**/*.less", "**/*.sass", "**/*.scss", "**/*.css", "**/*.jsx", "**/*.ts", "**/*.tsx", "**/*.md"]
|
|
524
|
+
});
|
|
525
|
+
return {
|
|
526
|
+
miniProgramCi: miniProgramCi,
|
|
527
|
+
appid: p,
|
|
528
|
+
options: {
|
|
529
|
+
project: b,
|
|
530
|
+
version: _,
|
|
531
|
+
desc: h,
|
|
532
|
+
setting: f.setting,
|
|
533
|
+
robot: i,
|
|
534
|
+
qrcodeFormat: o,
|
|
535
|
+
qrcodeOutputDest: c,
|
|
536
|
+
pagePath: s,
|
|
537
|
+
searchQuery: u
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
throw Error("\u6ca1\u6709\u627e\u5230\u4e0a\u4f20\u5bc6\u94a5(".concat(m, ")"))
|
|
542
|
+
}
|
|
543
|
+
throw Error("\u6ca1\u6709\u627e\u5230dist\u76ee\u5f55(".concat(d, ")"))
|
|
544
|
+
},
|
|
545
|
+
install = function () {
|
|
546
|
+
info("node version: ".concat(process.version)), initPreCommit(), process.argv.length > 2 ? _commander["default"].version(_package["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((function (e, t) {
|
|
547
|
+
console.log(e, t);
|
|
548
|
+
var r = _toArray(t),
|
|
549
|
+
n = r[0],
|
|
550
|
+
a = r.slice(1),
|
|
551
|
+
i = e.clone,
|
|
552
|
+
o = e.template,
|
|
553
|
+
c = e.docs;
|
|
554
|
+
if (n) switch (n) {
|
|
555
|
+
case "init":
|
|
556
|
+
if (succeed("yolk ".concat(n, " \u5f00\u59cb")), i)
|
|
557
|
+
if (o) {
|
|
558
|
+
var s = ".yolk",
|
|
559
|
+
u = _path["default"].join(cwd, s);
|
|
560
|
+
_fs["default"].existsSync(u) && (0, _rimraf["default"])(u, (function () {
|
|
561
|
+
succeed("\u7f13\u5b58\u5220\u9664 success! ".concat(u))
|
|
562
|
+
})), execCommand({
|
|
563
|
+
command: "git",
|
|
564
|
+
args: ["clone", "-b", "master", "--depth", "1", o, s].concat(a)
|
|
565
|
+
}), createGitTemplate(cwd, u)
|
|
566
|
+
} else fail("--clone \u6a21\u5f0f\u5fc5\u987b\u6709--template");
|
|
567
|
+
else createTemplate(cwd);
|
|
568
|
+
break;
|
|
569
|
+
case "start":
|
|
570
|
+
isMiniapp() ? isTT() ? execCommand({
|
|
571
|
+
command: "taro",
|
|
572
|
+
args: ["build", "--type", "tt", "--watch"].concat(a)
|
|
573
|
+
}) : isAlipay() ? execCommand({
|
|
574
|
+
command: "taro",
|
|
575
|
+
args: ["build", "--type", "alipay", "--watch"].concat(a)
|
|
576
|
+
}) : execCommand({
|
|
577
|
+
command: "taro",
|
|
578
|
+
args: ["build", "--type", "weapp", "--watch"].concat(a)
|
|
579
|
+
}) : execCommand(c ? {
|
|
580
|
+
command: "dumi",
|
|
581
|
+
args: ["dev"].concat(a)
|
|
582
|
+
} : {
|
|
583
|
+
command: "umi",
|
|
584
|
+
args: ["dev"].concat(a)
|
|
585
|
+
});
|
|
586
|
+
break;
|
|
587
|
+
case "build":
|
|
588
|
+
isMiniapp() ? isTT() ? execCommand({
|
|
589
|
+
command: "taro",
|
|
590
|
+
args: ["build", "--type", "tt"].concat(a)
|
|
591
|
+
}) : isAlipay() ? execCommand({
|
|
592
|
+
command: "taro",
|
|
593
|
+
args: ["build", "--type", "alipay"].concat(a)
|
|
594
|
+
}) : execCommand({
|
|
595
|
+
command: "taro",
|
|
596
|
+
args: ["build", "--type", "weapp"].concat(a)
|
|
597
|
+
}) : execCommand(c ? {
|
|
598
|
+
command: "dumi",
|
|
599
|
+
args: ["build"].concat(a)
|
|
600
|
+
} : {
|
|
601
|
+
command: "umi",
|
|
602
|
+
args: ["build"].concat(a)
|
|
603
|
+
});
|
|
604
|
+
break;
|
|
605
|
+
case "pre-commit":
|
|
606
|
+
preCommit();
|
|
607
|
+
break;
|
|
608
|
+
case "test":
|
|
609
|
+
execCommand({
|
|
610
|
+
command: "umi-test",
|
|
611
|
+
args: ["--no-cache", "--update-snapshot", "--runInBand", "--detectOpenHandles"].concat(a)
|
|
612
|
+
});
|
|
613
|
+
break;
|
|
614
|
+
case "miniapp-upload":
|
|
615
|
+
if (isMiniapp())
|
|
616
|
+
if (isTT());
|
|
617
|
+
else if (isAlipay());
|
|
618
|
+
else {
|
|
619
|
+
var l = getMiniProgramCi(e),
|
|
620
|
+
f = l.miniProgramCi,
|
|
621
|
+
p = l.appid,
|
|
622
|
+
d = l.options;
|
|
623
|
+
info("".concat(p, "\u4e0a\u4f20\u5f00\u59cb")), f.upload(_objectSpread(_objectSpread({}, (0, _pick2["default"])(d, ["project", "version", "desc", "setting", "robot"])), {}, {
|
|
624
|
+
onProgressUpdate: function (e) {
|
|
625
|
+
if ((0, _isString2["default"])(e)) info("task: ".concat(e));
|
|
626
|
+
else {
|
|
627
|
+
var t = e.status,
|
|
628
|
+
r = e.message;
|
|
629
|
+
info("task(".concat(t, "): ").concat(r))
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
})).then((function () {
|
|
633
|
+
succeed("".concat(p, "\u4e0a\u4f20\u5b8c\u6210"))
|
|
634
|
+
}))
|
|
635
|
+
}
|
|
636
|
+
break;
|
|
637
|
+
case "miniapp-preview":
|
|
638
|
+
if (isMiniapp())
|
|
639
|
+
if (isTT());
|
|
640
|
+
else if (isAlipay());
|
|
641
|
+
else {
|
|
642
|
+
var m = getMiniProgramCi(e),
|
|
643
|
+
y = m.miniProgramCi,
|
|
644
|
+
_ = m.appid,
|
|
645
|
+
g = m.options;
|
|
646
|
+
info("".concat(_, "\u4e0a\u4f20\u9884\u89c8\u5f00\u59cb")), y.preview(_objectSpread(_objectSpread({}, (0, _pick2["default"])(g, ["project", "version", "desc", "setting", "robot", "qrcodeFormat", "qrcodeOutputDest", "pagePath", "searchQuery"])), {}, {
|
|
647
|
+
onProgressUpdate: function (e) {
|
|
648
|
+
if ((0, _isString2["default"])(e)) info("task: ".concat(e));
|
|
649
|
+
else {
|
|
650
|
+
var t = e.status,
|
|
651
|
+
r = e.message;
|
|
652
|
+
info("task(".concat(t, "): ").concat(r))
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
})).then((function () {
|
|
656
|
+
succeed("".concat(_, "\u4e0a\u4f20\u9884\u89c8\u5b8c\u6210"))
|
|
657
|
+
}))
|
|
658
|
+
}
|
|
659
|
+
break;
|
|
660
|
+
default:
|
|
661
|
+
breakExit()
|
|
662
|
+
}
|
|
663
|
+
})).parse(process.argv) : breakExit()
|
|
664
|
+
};
|
|
665
|
+
install();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@baic/yolk-cli",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "2.0.1-alpha.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"pub": "npm publish",
|
|
@@ -22,19 +22,19 @@
|
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@types/glob": "~7.2.0",
|
|
24
24
|
"@types/inquirer": "~8.1.3",
|
|
25
|
-
"@types/lodash": "~4.14.
|
|
25
|
+
"@types/lodash": "~4.14.178",
|
|
26
26
|
"@types/mkdirp": "~1.0.2",
|
|
27
27
|
"@types/mustache": "~4.1.2",
|
|
28
28
|
"@types/rimraf": "~3.0.2",
|
|
29
|
-
"commander": "6.
|
|
29
|
+
"commander": "6.x",
|
|
30
30
|
"glob": "~7.2.0",
|
|
31
31
|
"inquirer": "~8.2.0",
|
|
32
32
|
"lodash": "~4.17.21",
|
|
33
|
-
"miniprogram-ci": "~1.6.
|
|
33
|
+
"miniprogram-ci": "~1.6.10",
|
|
34
34
|
"mkdirp": "~1.0.4",
|
|
35
35
|
"mustache": "~4.2.0",
|
|
36
|
-
"ora": "5.
|
|
37
|
-
"prettier": "~2.
|
|
36
|
+
"ora": "5.x",
|
|
37
|
+
"prettier": "~2.5.1",
|
|
38
38
|
"rimraf": "~3.0.2",
|
|
39
39
|
"staged-git-files": "~1.2.0"
|
|
40
40
|
}
|