neo-cmp-cli 1.8.11 → 1.8.13
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/README.md +12 -0
- package/bin/neo.js +1 -1
- package/dist/_virtual/index.js +1 -0
- package/dist/index.js +1 -0
- package/dist/index2.js +1 -0
- package/dist/main2.js +1 -1
- package/dist/package.json.js +1 -0
- package/package.json +1 -1
- package/template/antd-custom-cmp-template/package.json +2 -2
- package/template/echarts-custom-cmp-template/package.json +2 -2
- package/template/empty-custom-cmp-template/package.json +2 -2
- package/template/neo-custom-cmp-template/package.json +2 -2
- package/template/react-custom-cmp-template/package.json +2 -2
- package/template/react-ts-custom-cmp-template/package.json +2 -2
- package/template/vue2-custom-cmp-template/package.json +2 -2
- package/test/demo6.js +95 -0
- package/test/deprecate-versions.js +1 -1
- package/bin/index.js +0 -675
package/README.md
CHANGED
|
@@ -120,6 +120,18 @@ neo push cmp
|
|
|
120
120
|
| `neo pull cmp` | 拉取线上自定义组件(NeoCRM 平台)至当前项目 | `--name` 指定组件名称 |
|
|
121
121
|
| `neo delete cmp` | 删除线上自定义组件(NeoCRM 平台) | `--name` 指定组件名称 |
|
|
122
122
|
|
|
123
|
+
## 常见问题
|
|
124
|
+
|
|
125
|
+
**Q1: 在 Windows VSCode 控制台执行 neo 相关命令出现报错**
|
|
126
|
+
A: 如果提示“在此系统上禁止运行脚本”,这个可能是 Windows 客户端的默认安全策略影响,可尝试在控制台输入以下命令解决:
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope CurrentUser
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
说明:以上命令用于设置 允许当前用户在此 Windows 客户端执行所有脚本。[关于 PowerShell 执行策略](https://learn.microsoft.com/zh-cn/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-7.5)
|
|
133
|
+
|
|
134
|
+
|
|
123
135
|
---
|
|
124
136
|
|
|
125
137
|
## 🔐 授权配置
|
package/bin/neo.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
require('./index');
|
|
2
|
+
require('./dist/index');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});exports.__exports={};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const e=require("./_virtual/_commonjsHelpers.js");var r=require("./index2.js").__require();const s=e.getDefaultExportFromCjs(r);module.exports=s;
|
package/dist/index2.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./_virtual/index.js"),s=require("figlet"),o=require("yargs"),a=require("chalk"),t=require("inquirer"),n=require("ora"),p=require("./main2.js"),i=require("./package.json.js");var c;exports.__require=function(){if(c)return e.__exports;c=1;const m=s,r=o,l=a,u=t,d=n,{neoInit:g,neoInitByCopy:h,inspect:y,neoConfigInit:b,validateProjectName:C,getCmpTypeByDir:v,NeoService:f,NeoLoginService:$,hasNeoProject:x,consoleTag:T,errorLog:U,successLog:j}=p.__require(),w=p.__require(),q=i.default,N=w.projectConfig,_=function(e){return l.green(l.bold(e))},M=m.textSync("neo",{font:"Lean"});return console.log(l.green(M)),console.log(l.green(`当前版本:v${q.version}.\n`)),r.command("init [options]","根据模板创建一个自定义组件",e=>{e.reset().usage(_("Usage")+": $0 init [options]").option("type",{alias:"t",describe:"自定义组件类型(react ts 技术栈/ vue2.0 技术栈/ react 技术栈)"}).option("name",{alias:"n",describe:"自定义组件项目名称"}).alias("h","help")},e=>{if(e.type&&e.name)x()&&(U(`${T}创建自定义组件失败,当前目录(${process.cwd()})已经是一个自定义组件项目,请勿重复创建。`),process.exit(1)),"github"===e.mode?g(e.type,e.name):h(e.type,e.name);else{const s=[],o=[{name:"react&ts 自定义组件",value:"react-ts",short:"react-ts"},{name:"Neo 自定义组件(使用平台实体数据源)",value:"neo",short:"neo"},{name:"antd 自定义组件",value:"antd",short:"antd"},{name:"echarts 自定义组件",value:"echarts",short:"echarts"},{name:"vue2 自定义组件",value:"vue2",short:"vue2"}];e.type||s.push({name:"type",type:"list",message:"请选择您要创建的自定义组件类型: ",default:"react-ts",choices:o}),e.name||s.push({name:"name",type:"input",message:"请设置自定义组件项目名称(默认 neoCustomCmp):",default:"neoCustomCmp"}),u.prompt(s).then(s=>{const{isValid:o,errors:a}=C(s.name);o||(U(a.join("\n")),process.exit(1)),"github"===e.mode?g(s.type,s.name):h(s.type,s.name)})}}).command("config init","创建 neo.config.js 配置文件",e=>{e.reset().usage(_("Usage")+": $0 config init").alias("h","help")},()=>{b("neo.config.js")}).command("login","登录 NeoCRM 平台(OAuth2 授权)",e=>{e.reset().usage(_("Usage")+": $0 login").alias("h","help")},async()=>{try{const e=new $(N.neoConfig);await e.login(),process.exit(0)}catch(e){U(`\n登录失败: ${e.message}`),process.exit(1)}}).command("logout","登出 NeoCRM 平台",e=>{e.reset().usage(_("Usage")+": $0 logout").alias("h","help")},async()=>{try{const e=new $(N.neoConfig);await e.logout(),process.exit(0)}catch(e){U(`\n登出失败: ${e.message}`),process.exit(1)}}).command("create","创建项目或者组件",e=>e.command("project [options]","创建自定义组件项目(含工程代码)",e=>{e.reset().usage(_("Usage")+": $0 project [options]").option("name",{alias:"n",describe:"自定义组件项目名称"}).alias("h","help")},e=>{if(e.name)w.createCmpProjectByTemplate(e.name);else{const e=[{name:"name",type:"input",message:"请设置自定义组件项目名称:"}];u.prompt(e).then(e=>{const{isValid:s,errors:o}=C(e.name);s||(U(o.join("\n")),process.exit(1)),e.name?w.createCmpProjectByTemplate(e.name):(U("自定义组件项目名称不能为空。"),process.exit(1))})}}).command("cmp [options]","创建自定义组件",e=>{e.reset().usage(_("Usage")+": $0 cmp [options]").option("name",{alias:"n",describe:"自定义组件名称"}).alias("h","help")},e=>{if(e.name)w.createCmpByTemplate(e.name);else{const e=[{name:"name",type:"input",message:"请设置自定义组件名称:"}];u.prompt(e).then(e=>{e.name?w.createCmpByTemplate(e.name):(U("自定义组件名称不能为空。"),process.exit(1))})}})).command("pull cmp [options]","拉取线上自定义组件",e=>{e.reset().usage(_("Usage")+": $0 pull cmp [options]").option("name",{alias:"n",describe:"自定义组件名称"}).alias("h","help")},async e=>{if(e.name)w.pullCmp(e.name);else{const e=new f(N.neoConfig),s=d("正在拉取线上自定义组件列表...").start(),o=await e.getCustomCmpList();0===o.length&&(U("当前租户暂无任何自定义组件。"),process.exit(1)),s.stop("线上自定义组件列表拉取成功。");const a=[{name:"cmpType",type:"list",message:"请选择要拉取的自定义组件:",choices:o.map(e=>({name:`${e.label}(${e.cmpType})`,value:e.cmpType}))}];u.prompt(a).then(s=>{s.cmpType?w.pullCmp(s.cmpType,e):(U("自定义组件名称不能为空。"),process.exit(1))})}}).command("delete cmp [options]","删除线上自定义组件",e=>{e.reset().usage(_("Usage")+": $0 delete cmp [options]").option("name",{alias:"n",describe:"自定义组件名称"}).alias("h","help")},async e=>{if(e.name)w.deleteCmp(e.name);else{const e=new f(N.neoConfig),s=d("正在获取线上自定义组件列表...").start(),o=await e.getCustomCmpList();0===o.length&&(U("当前租户暂无任何自定义组件。"),process.exit(1)),s.stop("线上自定义组件列表获取成功。");const a=[{name:"cmpType",type:"list",message:"请选择要删除的自定义组件:",choices:o.map(e=>({name:`${e.label}(${e.cmpType})`,value:e.cmpType}))}];u.prompt(a).then(s=>{s.cmpType?w.deleteCmp(s.cmpType,e):(U("自定义组件名称不能为空。"),process.exit(1))})}}).command("preview [options]","预览指定自定义组件(仅预览组件本身内容)",e=>{e.reset().usage(_("Usage")+": $0 preview [options]").option("name",{alias:"n",describe:"自定义组件名称"}).alias("h","help")},e=>{if(e.name)w.previewCmp(e.name);else{const e=v();0===e.length&&(U("当前自定义组件目录中未找到自定义组件。(./src/components 目录下)"),process.exit(1));const s=[{name:"cmpType",type:"list",message:"请选择要预览的自定义组件:",choices:e.map(e=>({name:e,value:e}))}];u.prompt(s).then(e=>{e.cmpType||(U("未选择要预览的自定义组件。"),process.exit(1)),w.previewCmp(e.cmpType)})}}).command("dev","开启本地调试模式",e=>{e.reset().usage(_("Usage")+": $0 dev").alias("h","help")},()=>{w.dev()}).command("linkDebug","开启外链调试模式(在线上页面设计器端调试)",e=>{e.reset().usage(_("Usage")+": $0 linkDebug").alias("h","help")},e=>{w.linkDebug()}).command("build","构建生产环境代码",e=>{e.reset().usage(_("Usage")+": $0 build").alias("h","help")},e=>{w.build()}).command("build2lib","构建 UMD 模块",e=>{e.reset().usage(_("Usage")+": $0 build2lib").alias("h","help")},e=>{w.build2lib()}).command("publish2oss [options]","发布到oss",e=>{e.reset().usage(_("Usage")+": $0 publish2oss [options]").option("name",{alias:"n",describe:"自定义组件名称"}).alias("h","help")},e=>{if(e.name)w.publish2oss(e.name);else{const e=v();0===e.length&&(U("当前自定义组件目录中未找到自定义组件。(./src/components 目录下)"),process.exit(1));const s=[{name:"cmpType",type:"list",message:"请选择要发布的自定义组件:",choices:e.map(e=>({name:e,value:e}))}];u.prompt(s).then(e=>{e.cmpType||(U("未选择要发布的自定义组件。"),process.exit(1)),w.publish2oss(e.cmpType)})}}).command("push cmp [options]","构建并发布自定义组件到 NeoCRM 平台",e=>{e.reset().usage(_("Usage")+": $0 push cmp [options]").option("name",{alias:"n",describe:"自定义组件名称"}).alias("h","help")},e=>{if(e.name)w.pushCmp(e.name);else{const e=v();0===e.length&&(U("当前自定义组件目录中未找到自定义组件。(./src/components 目录下)"),process.exit(1));const s=[{name:"cmpType",type:"list",message:"请选择要发布的自定义组件:",choices:e.map(e=>({name:e,value:e}))}];u.prompt(s).then(e=>{e.cmpType||(U("未选择要发布的自定义组件。"),process.exit(1)),w.pushCmp(e.cmpType)})}}).command("build2esm","构建 ESM 模块",e=>{e.reset().usage(_("Usage")+": $0 build2esm").alias("h","help")},()=>{w.build2esm()}).command("inspect","输出当前配置文件",e=>{e.reset().usage(_("Usage")+": $0 inspect").option("type",{alias:"t",describe:"环境类型(本地调试环境/生产环境/library构建环境)",default:"build"}).alias("h","help")},e=>{y(e.type)}).command("open [options]","使用 Cursor 或 VSCode 打开项目",e=>{e.reset().usage(_("Usage")+": $0 open [options]").option("editor",{alias:"e",describe:"编辑器类型(cursor/vscode/auto),默认为 auto(自动检测)",default:"auto",choices:["cursor","vscode","code","auto"]}).option("name",{alias:"n",describe:"要打开的项目名称,默认为当前目录"}).alias("h","help")},e=>{w.openEditor(e.editor,e.name)}).alias("h","help").alias("v","version").strict().fail((e,s,o)=>{U(`\n运行命令时发生错误: ${e}。\n`),console.log(_("当前可用命令列表:")),console.log("");[{cmd:"init [options]",desc:"根据模板创建一个自定义组件"},{cmd:"create project [options]",desc:"创建自定义组件项目(含工程代码)"},{cmd:"create cmp [options]",desc:"创建自定义组件"},{cmd:"preview [options]",desc:"预览指定自定义组件(仅预览组件本身内容)"},{cmd:"linkDebug",desc:"开启外链调试模式(在线上页面设计器端调试)"},{cmd:"login",desc:"登录 NeoCRM 平台(OAuth2 授权)"},{cmd:"logout",desc:"登出 NeoCRM 平台"},{cmd:"pull cmp [options]",desc:"拉取线上自定义组件"},{cmd:"delete cmp [options]",desc:"删除线上自定义组件"},{cmd:"push cmp [options]",desc:"构建并发布自定义组件到 NeoCRM 平台"},{cmd:"open [options]",desc:"使用 Cursor 或 VSCode 打开项目"}].forEach(({cmd:e,desc:s})=>{console.log(` ${l.cyan(e.padEnd(25))} ${s}`)}),console.log(""),console.log(`使用 ${l.cyan("neo <command> --help")} 查看具体命令的帮助信息。`),console.log(""),process.exit(1)}).help().updateStrings({"Usage:":_("Usage:"),"Commands:":_("Commands:"),"Options:":_("Options:")}).argv,e.__exports};
|
package/dist/main2.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("akfun");require("lodash");const r=require("./module/neoInit.js"),i=require("./module/neoInitByCopy.js"),s=require("./module/inspect.js"),t=require("./utils/neoConfigInit.js"),o=require("./utils/neoParams.js"),u=require("./config/index.js"),l=require("./oss/publish2oss.js"),p=require("./utils/cmpUtils/pushCmp.js"),n=require("./utils/cmpUtils/previewCmp.js"),c=require("./utils/generateEntries.js"),d=require("./utils/cmpUtils/createCmpByTemplate.js"),m=require("./utils/projectUtils/createCmpProjectByTemplate.js"),b=require("./utils/cmpUtils/pullCmp.js"),a=require("./utils/cmpUtils/deleteCmp.js"),q=require("./utils/projectUtils/openProject.js"),_=require("./utils/configureNeoBuild.js"),y=require("./utils/common.js"),g=require("./utils/projectNameValidator.js"),j=require("./utils/cmpUtils/getCmpTypeByDir.js"),v=require("./neo/neoService.js"),T=require("./neo/neoLogin.js"),f=require("./utils/projectUtils/hasNeoProject.js");var C,x;exports.__require=function(){if(x)return C;x=1;const h=e,E=r.__require(),N=i.__require(),w=s.__require(),B=t.__require(),{consoleTag:D}=o.__require(),P=u.__require(),U=l.__require(),k=p.__require(),I=n.__require(),L=c.__require(),M=d.__require(),O=m.__require(),S=b.__require(),R=a.__require(),A=q.__require(),{configureNeoBuild:V}=_.__require(),{errorLog:z,successLog:F}=y.__require(),{validateProjectName:G}=g.__require(),H=j.__require(),J=v.__require(),K=T.__require(),Q=f.__require();function W(e,r){const{entryType:i,cmpType:s}=r;let t=[],o={};try{const{entries:r,cmpTypes:u,defaultExports:l}=L({configEntry:e.entry,disableAutoRegister:e.disableAutoRegister,componentsDir:P.componentsDir,entryType:i,cmpType:s});r&&Object.keys(r).length>0&&(e.entry=r,t=u,console.info("已自动生成 entry 入口配置:",r)),o=l}catch(e){z(e.message),process.exit(1)}return{cmpTypes:t,defaultExports:o}}function X(e){return Object.assign(P.build2lib,e)}return C={neoInit:E,neoInitByCopy:N,inspect:w,neoConfigInit:B,projectConfig:P,consoleTag:D,errorLog:z,successLog:F,validateProjectName:G,getCmpTypeByDir:H,NeoService:J,NeoLoginService:K,hasNeoProject:Q,createCmpProjectByTemplate:O,createCmpByTemplate:M,dev:()=>{P.dev||(z("未找到 dev 相关配置。"),process.exit(1)),h.dev(P,D)},previewCmp:e=>{e||(z("请输入要预览的组件名称。"),process.exit(1)),P.preview||(z("未找到 preview 相关配置。"),process.exit(1)),P.dev=Object.assign(P.dev,P.preview),delete P.preview,I(P,e)},linkDebug:()=>{P.linkDebug||(z("未找到 debug 相关配置。"),process.exit(1)),P.dev=Object.assign(P.dev,P.linkDebug),delete P.linkDebug,delete P.dev.ignoreNodeModules,P.webpack.ignoreNodeModules=!1;const{cmpTypes:e,defaultExports:r}=W(P.dev,{entryType:"linkDebug"});V(P.dev,{cmpTypes:e,defaultExports:r,verbose:!0,excludeModel:!1}),h.dev(P,D)},build:()=>h.build("build",P,D),build2lib:()=>{W(P.build2lib,{entryType:"widget"}),h.build("lib",P,D)},publish2oss:e=>{const r=P.publish2oss;P.build2lib=X(r);const{cmpTypes:i,defaultExports:s}=W(P.build2lib,{entryType:"widget",cmpType:e});V(P.build2lib,{cmpTypes:i,defaultExports:s,verbose:!0,excludeModel:!0}),h.build("lib",P,D,()=>{U(r.ossType,r.ossConfig,r.assetsRoot)})},pushCmp:e=>{const{neoConfig:r,pushCmp:i}=P,s=Object.assign({},i,r);P.build2lib=X(s);const{cmpTypes:t,defaultExports:o}=W(P.build2lib,{entryType:"widget",cmpType:e});V(P.build2lib,{cmpTypes:t,defaultExports:o,verbose:!1,excludeModel:!0}),h.build("lib",P,D,()=>{k(s,e)})},pullCmp:(e,r)=>{S(e,P.neoConfig,r)},deleteCmp:(e,r)=>{R(e,P.neoConfig,r)},build2esm:
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("akfun");require("lodash");const r=require("./module/neoInit.js"),i=require("./module/neoInitByCopy.js"),s=require("./module/inspect.js"),t=require("./utils/neoConfigInit.js"),o=require("./utils/neoParams.js"),u=require("./config/index.js"),l=require("./oss/publish2oss.js"),p=require("./utils/cmpUtils/pushCmp.js"),n=require("./utils/cmpUtils/previewCmp.js"),c=require("./utils/generateEntries.js"),d=require("./utils/cmpUtils/createCmpByTemplate.js"),m=require("./utils/projectUtils/createCmpProjectByTemplate.js"),b=require("./utils/cmpUtils/pullCmp.js"),a=require("./utils/cmpUtils/deleteCmp.js"),q=require("./utils/projectUtils/openProject.js"),_=require("./utils/configureNeoBuild.js"),y=require("./utils/common.js"),g=require("./utils/projectNameValidator.js"),j=require("./utils/cmpUtils/getCmpTypeByDir.js"),v=require("./neo/neoService.js"),T=require("./neo/neoLogin.js"),f=require("./utils/projectUtils/hasNeoProject.js");var C,x;exports.__require=function(){if(x)return C;x=1;const h=e,E=r.__require(),N=i.__require(),w=s.__require(),B=t.__require(),{consoleTag:D}=o.__require(),P=u.__require(),U=l.__require(),k=p.__require(),I=n.__require(),L=c.__require(),M=d.__require(),O=m.__require(),S=b.__require(),R=a.__require(),A=q.__require(),{configureNeoBuild:V}=_.__require(),{errorLog:z,successLog:F}=y.__require(),{validateProjectName:G}=g.__require(),H=j.__require(),J=v.__require(),K=T.__require(),Q=f.__require();function W(e,r){const{entryType:i,cmpType:s}=r;let t=[],o={};try{const{entries:r,cmpTypes:u,defaultExports:l}=L({configEntry:e.entry,disableAutoRegister:e.disableAutoRegister,componentsDir:P.componentsDir,entryType:i,cmpType:s});r&&Object.keys(r).length>0&&(e.entry=r,t=u,console.info("已自动生成 entry 入口配置:",r)),o=l}catch(e){z(e.message),process.exit(1)}return{cmpTypes:t,defaultExports:o}}function X(e){return Object.assign(P.build2lib,e)}return C={neoInit:E,neoInitByCopy:N,inspect:w,neoConfigInit:B,projectConfig:P,consoleTag:D,errorLog:z,successLog:F,validateProjectName:G,getCmpTypeByDir:H,NeoService:J,NeoLoginService:K,hasNeoProject:Q,createCmpProjectByTemplate:O,createCmpByTemplate:M,dev:()=>{P.dev||(z("未找到 dev 相关配置。"),process.exit(1)),h.dev(P,D)},previewCmp:e=>{e||(z("请输入要预览的组件名称。"),process.exit(1)),P.preview||(z("未找到 preview 相关配置。"),process.exit(1)),P.dev=Object.assign(P.dev,P.preview),delete P.preview,I(P,e)},linkDebug:()=>{P.linkDebug||(z("未找到 debug 相关配置。"),process.exit(1)),P.dev=Object.assign(P.dev,P.linkDebug),delete P.linkDebug,delete P.dev.ignoreNodeModules,P.webpack.ignoreNodeModules=!1;const{cmpTypes:e,defaultExports:r}=W(P.dev,{entryType:"linkDebug"});V(P.dev,{cmpTypes:e,defaultExports:r,verbose:!0,excludeModel:!1}),h.dev(P,D)},build:()=>h.build("build",P,D),build2lib:()=>{W(P.build2lib,{entryType:"widget"}),h.build("lib",P,D)},publish2oss:e=>{const r=P.publish2oss;P.build2lib=X(r);const{cmpTypes:i,defaultExports:s}=W(P.build2lib,{entryType:"widget",cmpType:e});V(P.build2lib,{cmpTypes:i,defaultExports:s,verbose:!0,excludeModel:!0}),h.build("lib",P,D,()=>{U(r.ossType,r.ossConfig,r.assetsRoot)})},pushCmp:e=>{const{neoConfig:r,pushCmp:i}=P,s=Object.assign({},i,r);P.build2lib=X(s);const{cmpTypes:t,defaultExports:o}=W(P.build2lib,{entryType:"widget",cmpType:e});V(P.build2lib,{cmpTypes:t,defaultExports:o,verbose:!1,excludeModel:!0}),h.build("lib",P,D,()=>{k(s,e)})},pullCmp:(e,r)=>{S(e,P.neoConfig,r)},deleteCmp:(e,r)=>{R(e,P.neoConfig,r)},build2esm:()=>h.build2esm(P,D),openEditor:A},C};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var e="1.8.13";const o={version:e};exports.default=o,exports.version=e;
|
package/package.json
CHANGED
package/test/demo6.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 基于XMLHttpRequest的通用请求方法
|
|
3
|
+
* @param {string} url - 请求地址
|
|
4
|
+
* @param {object} options - 请求配置
|
|
5
|
+
* @param {string} [options.method='GET'] - 请求方法
|
|
6
|
+
* @param {object} [options.params={}] - URL查询参数(GET/DELETE)
|
|
7
|
+
* @param {object} [options.data={}] - 请求体数据(POST/PUT)
|
|
8
|
+
* @param {object} [options.headers={}] - 请求头
|
|
9
|
+
* @param {number} [options.timeout=5000] - 超时时间(毫秒)
|
|
10
|
+
* @returns {Promise} - 返回Promise对象
|
|
11
|
+
*/
|
|
12
|
+
function requestXHR(url, options) {
|
|
13
|
+
options = options || {};
|
|
14
|
+
var method = options.method || 'GET';
|
|
15
|
+
var data = options.data || {};
|
|
16
|
+
var headers = options.headers || {};
|
|
17
|
+
var timeout = options.timeout || 5000;
|
|
18
|
+
|
|
19
|
+
return new Promise(function(resolve, reject) {
|
|
20
|
+
// 1. 创建XHR对象
|
|
21
|
+
var xhr = new XMLHttpRequest();
|
|
22
|
+
|
|
23
|
+
// 2. 处理GET参数,拼接到URL
|
|
24
|
+
var queryParts = [];
|
|
25
|
+
var queryString = queryParts.join('&');
|
|
26
|
+
var fullUrl = queryString ? url + '?' + queryString : url;
|
|
27
|
+
|
|
28
|
+
// 3. 初始化请求
|
|
29
|
+
xhr.open(method.toUpperCase(), fullUrl, true);
|
|
30
|
+
|
|
31
|
+
// 4. 设置请求头
|
|
32
|
+
// 默认JSON请求头(POST/PUT)
|
|
33
|
+
var methodUpper = method.toUpperCase();
|
|
34
|
+
if (methodUpper === 'POST' || methodUpper === 'PUT') {
|
|
35
|
+
xhr.setRequestHeader('Content-Type', 'application/json;charset=utf-8');
|
|
36
|
+
}
|
|
37
|
+
// 自定义请求头
|
|
38
|
+
var headerKeys = Object.keys(headers);
|
|
39
|
+
for (var j = 0; j < headerKeys.length; j++) {
|
|
40
|
+
var headerKey = headerKeys[j];
|
|
41
|
+
var headerValue = headers[headerKey];
|
|
42
|
+
xhr.setRequestHeader(headerKey, headerValue);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// 5. 设置超时
|
|
46
|
+
xhr.timeout = timeout;
|
|
47
|
+
|
|
48
|
+
// 6. 处理响应
|
|
49
|
+
xhr.onload = function () {
|
|
50
|
+
if (xhr.status >= 200 && xhr.status < 300) {
|
|
51
|
+
// 解析响应数据(优先JSON,其次文本)
|
|
52
|
+
var responseData;
|
|
53
|
+
try {
|
|
54
|
+
responseData = JSON.parse(xhr.responseText);
|
|
55
|
+
} catch (e) {
|
|
56
|
+
responseData = xhr.responseText;
|
|
57
|
+
}
|
|
58
|
+
resolve({
|
|
59
|
+
data: responseData,
|
|
60
|
+
status: xhr.status,
|
|
61
|
+
statusText: xhr.statusText
|
|
62
|
+
});
|
|
63
|
+
} else {
|
|
64
|
+
reject(new Error('请求失败:' + xhr.status + ' ' + xhr.statusText));
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
// 7. 处理网络错误、超时
|
|
69
|
+
xhr.onerror = function () {
|
|
70
|
+
reject(new Error('网络错误,请检查网络连接'));
|
|
71
|
+
};
|
|
72
|
+
xhr.ontimeout = function () {
|
|
73
|
+
reject(new Error('请求超时(' + timeout + 'ms)'));
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
// 8. 发送请求(POST/PUT需传请求体)
|
|
77
|
+
var methodUpperSend = method.toUpperCase();
|
|
78
|
+
if (methodUpperSend === 'POST' || methodUpperSend === 'PUT') {
|
|
79
|
+
xhr.send(JSON.stringify(data));
|
|
80
|
+
} else {
|
|
81
|
+
xhr.send(null);
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// GET请求
|
|
87
|
+
requestXHR('https://jsonplaceholder.typicode.com/posts', {
|
|
88
|
+
timeout: 10000
|
|
89
|
+
})
|
|
90
|
+
.then(function(res) {
|
|
91
|
+
|
|
92
|
+
})
|
|
93
|
+
.catch(function(err) {
|
|
94
|
+
|
|
95
|
+
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const { execSync } = require('child_process');
|
|
2
2
|
|
|
3
3
|
// 所有需要废弃的版本
|
|
4
|
-
const versionsToDeprecate = ["1.8.
|
|
4
|
+
const versionsToDeprecate = ["1.8.10", "1.8.11", "1.8.12"];
|
|
5
5
|
|
|
6
6
|
const packageName = 'neo-cmp-cli';
|
|
7
7
|
const deprecateMessage = '此版本为开发中版本(存在 bug),请升级到最新版本。';
|
package/bin/index.js
DELETED
|
@@ -1,675 +0,0 @@
|
|
|
1
|
-
const figlet = require('figlet'); // 用于输出图形文字
|
|
2
|
-
const yargs = require('yargs'); // 命令行工具
|
|
3
|
-
const chalk = require('chalk'); // 带样式的log输出
|
|
4
|
-
const inquirer = require('inquirer'); // 问答式交互
|
|
5
|
-
const ora = require('ora');
|
|
6
|
-
const {
|
|
7
|
-
neoInit,
|
|
8
|
-
neoInitByCopy,
|
|
9
|
-
inspect,
|
|
10
|
-
neoConfigInit,
|
|
11
|
-
validateProjectName,
|
|
12
|
-
getCmpTypeByDir,
|
|
13
|
-
NeoService,
|
|
14
|
-
NeoLoginService,
|
|
15
|
-
hasNeoProject,
|
|
16
|
-
consoleTag,
|
|
17
|
-
errorLog,
|
|
18
|
-
successLog
|
|
19
|
-
} = require('../dist/main.js');
|
|
20
|
-
const mainAction = require('../dist/main.js'); // 构建方法
|
|
21
|
-
// neo 的 package 文件
|
|
22
|
-
const neoPackage = require('../package.json');
|
|
23
|
-
|
|
24
|
-
// 获取当前项目根目录下的配置文件
|
|
25
|
-
const curConfig = mainAction.projectConfig;
|
|
26
|
-
|
|
27
|
-
const titleTip = function (msg) {
|
|
28
|
-
return chalk.green(chalk.bold(msg));
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
const bigTip = figlet.textSync('neo', {
|
|
32
|
-
font: 'Lean'
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
console.log(chalk.green(bigTip));
|
|
36
|
-
console.log(chalk.green(`当前版本:v${neoPackage.version}.\n`));
|
|
37
|
-
|
|
38
|
-
yargs
|
|
39
|
-
.command(
|
|
40
|
-
'init [options]',
|
|
41
|
-
'根据模板创建一个自定义组件',
|
|
42
|
-
(yargs) => {
|
|
43
|
-
yargs
|
|
44
|
-
.reset()
|
|
45
|
-
.usage(titleTip('Usage') + ': $0 init [options]')
|
|
46
|
-
.option('type', {
|
|
47
|
-
alias: 't',
|
|
48
|
-
describe: '自定义组件类型(react ts 技术栈/ vue2.0 技术栈/ react 技术栈)'
|
|
49
|
-
})
|
|
50
|
-
.option('name', {
|
|
51
|
-
alias: 'n',
|
|
52
|
-
describe: '自定义组件项目名称'
|
|
53
|
-
})
|
|
54
|
-
/*
|
|
55
|
-
// 暂不提供 github 下载模式(网络原因,下载速度慢)
|
|
56
|
-
.option('mode', {
|
|
57
|
-
alias: 'm',
|
|
58
|
-
describe: '自定义组件下载模式(github / copy)',
|
|
59
|
-
default: 'copy'
|
|
60
|
-
})
|
|
61
|
-
*/
|
|
62
|
-
.alias('h', 'help');
|
|
63
|
-
},
|
|
64
|
-
(argv) => {
|
|
65
|
-
if (argv.type && argv.name) {
|
|
66
|
-
if (hasNeoProject()) {
|
|
67
|
-
errorLog(
|
|
68
|
-
`${consoleTag}创建自定义组件失败,当前目录(${process.cwd()})已经是一个自定义组件项目,请勿重复创建。`
|
|
69
|
-
);
|
|
70
|
-
process.exit(1);
|
|
71
|
-
}
|
|
72
|
-
if (argv.mode === 'github') {
|
|
73
|
-
neoInit(argv.type, argv.name);
|
|
74
|
-
} else {
|
|
75
|
-
neoInitByCopy(argv.type, argv.name);
|
|
76
|
-
}
|
|
77
|
-
} else {
|
|
78
|
-
const questions = [];
|
|
79
|
-
// 初始化项目模板时,当用户未设置项目类型type时,以列表形式展示当前可以使用的项目模板
|
|
80
|
-
const neoWidgetTemplates = [
|
|
81
|
-
{
|
|
82
|
-
name: 'react&ts 自定义组件',
|
|
83
|
-
value: 'react-ts',
|
|
84
|
-
short: 'react-ts'
|
|
85
|
-
},
|
|
86
|
-
{
|
|
87
|
-
name: 'Neo 自定义组件(使用平台实体数据源)',
|
|
88
|
-
value: 'neo',
|
|
89
|
-
short: 'neo'
|
|
90
|
-
},
|
|
91
|
-
{
|
|
92
|
-
name: 'antd 自定义组件',
|
|
93
|
-
value: 'antd',
|
|
94
|
-
short: 'antd'
|
|
95
|
-
},
|
|
96
|
-
{
|
|
97
|
-
name: 'echarts 自定义组件',
|
|
98
|
-
value: 'echarts',
|
|
99
|
-
short: 'echarts'
|
|
100
|
-
},
|
|
101
|
-
/*
|
|
102
|
-
// 暂不提供 react js 模板(react js 模板已废弃)
|
|
103
|
-
{
|
|
104
|
-
name: 'react 自定义组件',
|
|
105
|
-
value: 'react',
|
|
106
|
-
short: 'react'
|
|
107
|
-
},
|
|
108
|
-
*/
|
|
109
|
-
{
|
|
110
|
-
name: 'vue2 自定义组件',
|
|
111
|
-
value: 'vue2',
|
|
112
|
-
short: 'vue2'
|
|
113
|
-
}
|
|
114
|
-
/*
|
|
115
|
-
{
|
|
116
|
-
name: 'vue3 自定义组件',
|
|
117
|
-
value: 'vue3',
|
|
118
|
-
short: 'vue3'
|
|
119
|
-
}
|
|
120
|
-
*/
|
|
121
|
-
];
|
|
122
|
-
|
|
123
|
-
if (!argv.type) {
|
|
124
|
-
questions.push({
|
|
125
|
-
name: 'type',
|
|
126
|
-
type: 'list',
|
|
127
|
-
message: '请选择您要创建的自定义组件类型: ',
|
|
128
|
-
default: 'react-ts',
|
|
129
|
-
choices: neoWidgetTemplates
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
// 当用户未设置存放项目的目录地址时,提示用户
|
|
133
|
-
if (!argv.name) {
|
|
134
|
-
questions.push({
|
|
135
|
-
name: 'name',
|
|
136
|
-
type: 'input',
|
|
137
|
-
message: '请设置自定义组件项目名称(默认 neoCustomCmp):',
|
|
138
|
-
default: 'neoCustomCmp'
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
inquirer.prompt(questions).then((ans) => {
|
|
142
|
-
// 验证项目名称是否合法
|
|
143
|
-
const { isValid, errors } = validateProjectName(ans.name);
|
|
144
|
-
if (!isValid) {
|
|
145
|
-
errorLog(errors.join('\n'));
|
|
146
|
-
process.exit(1);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
if (argv.mode === 'github') {
|
|
150
|
-
neoInit(ans.type, ans.name);
|
|
151
|
-
} else {
|
|
152
|
-
neoInitByCopy(ans.type, ans.name);
|
|
153
|
-
}
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
)
|
|
158
|
-
.command(
|
|
159
|
-
'config init',
|
|
160
|
-
'创建 neo.config.js 配置文件',
|
|
161
|
-
(yargs) => {
|
|
162
|
-
yargs
|
|
163
|
-
.reset()
|
|
164
|
-
.usage(titleTip('Usage') + ': $0 config init')
|
|
165
|
-
.alias('h', 'help');
|
|
166
|
-
},
|
|
167
|
-
() => {
|
|
168
|
-
neoConfigInit('neo.config.js');
|
|
169
|
-
}
|
|
170
|
-
)
|
|
171
|
-
.command(
|
|
172
|
-
'login',
|
|
173
|
-
'登录 NeoCRM 平台(OAuth2 授权)',
|
|
174
|
-
(yargs) => {
|
|
175
|
-
yargs
|
|
176
|
-
.reset()
|
|
177
|
-
.usage(titleTip('Usage') + ': $0 login')
|
|
178
|
-
.alias('h', 'help');
|
|
179
|
-
},
|
|
180
|
-
async () => {
|
|
181
|
-
try {
|
|
182
|
-
const loginService = new NeoLoginService(curConfig.neoConfig);
|
|
183
|
-
await loginService.login();
|
|
184
|
-
process.exit(0);
|
|
185
|
-
} catch (error) {
|
|
186
|
-
errorLog(`\n登录失败: ${error.message}`);
|
|
187
|
-
process.exit(1);
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
)
|
|
191
|
-
.command(
|
|
192
|
-
'logout',
|
|
193
|
-
'登出 NeoCRM 平台',
|
|
194
|
-
(yargs) => {
|
|
195
|
-
yargs
|
|
196
|
-
.reset()
|
|
197
|
-
.usage(titleTip('Usage') + ': $0 logout')
|
|
198
|
-
.alias('h', 'help');
|
|
199
|
-
},
|
|
200
|
-
async () => {
|
|
201
|
-
try {
|
|
202
|
-
const loginService = new NeoLoginService(curConfig.neoConfig);
|
|
203
|
-
await loginService.logout();
|
|
204
|
-
process.exit(0);
|
|
205
|
-
} catch (error) {
|
|
206
|
-
errorLog(`\n登出失败: ${error.message}`);
|
|
207
|
-
process.exit(1);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
)
|
|
211
|
-
.command('create', '创建项目或者组件', (yargs) => {
|
|
212
|
-
return yargs
|
|
213
|
-
.command(
|
|
214
|
-
'project [options]',
|
|
215
|
-
'创建自定义组件项目(含工程代码)',
|
|
216
|
-
(yargs) => {
|
|
217
|
-
yargs
|
|
218
|
-
.reset()
|
|
219
|
-
.usage(titleTip('Usage') + ': $0 project [options]')
|
|
220
|
-
.option('name', {
|
|
221
|
-
alias: 'n',
|
|
222
|
-
describe: '自定义组件项目名称'
|
|
223
|
-
})
|
|
224
|
-
.alias('h', 'help');
|
|
225
|
-
},
|
|
226
|
-
(argv) => {
|
|
227
|
-
if (argv.name) {
|
|
228
|
-
mainAction.createCmpProjectByTemplate(argv.name);
|
|
229
|
-
} else {
|
|
230
|
-
const questions = [
|
|
231
|
-
{
|
|
232
|
-
name: 'name',
|
|
233
|
-
type: 'input',
|
|
234
|
-
message: '请设置自定义组件项目名称:'
|
|
235
|
-
}
|
|
236
|
-
];
|
|
237
|
-
|
|
238
|
-
inquirer.prompt(questions).then((ans) => {
|
|
239
|
-
// 验证项目名称是否合法
|
|
240
|
-
const { isValid, errors } = validateProjectName(ans.name);
|
|
241
|
-
if (!isValid) {
|
|
242
|
-
errorLog(errors.join('\n'));
|
|
243
|
-
process.exit(1);
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
if (!ans.name) {
|
|
247
|
-
errorLog('自定义组件项目名称不能为空。');
|
|
248
|
-
process.exit(1);
|
|
249
|
-
} else {
|
|
250
|
-
mainAction.createCmpProjectByTemplate(ans.name);
|
|
251
|
-
}
|
|
252
|
-
});
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
)
|
|
256
|
-
.command(
|
|
257
|
-
'cmp [options]',
|
|
258
|
-
'创建自定义组件',
|
|
259
|
-
(yargs) => {
|
|
260
|
-
yargs
|
|
261
|
-
.reset()
|
|
262
|
-
.usage(titleTip('Usage') + ': $0 cmp [options]')
|
|
263
|
-
.option('name', {
|
|
264
|
-
alias: 'n',
|
|
265
|
-
describe: '自定义组件名称'
|
|
266
|
-
})
|
|
267
|
-
.alias('h', 'help');
|
|
268
|
-
},
|
|
269
|
-
(argv) => {
|
|
270
|
-
if (argv.name) {
|
|
271
|
-
mainAction.createCmpByTemplate(argv.name);
|
|
272
|
-
} else {
|
|
273
|
-
const questions = [
|
|
274
|
-
{
|
|
275
|
-
name: 'name',
|
|
276
|
-
type: 'input',
|
|
277
|
-
message: '请设置自定义组件名称:'
|
|
278
|
-
}
|
|
279
|
-
];
|
|
280
|
-
|
|
281
|
-
inquirer.prompt(questions).then((ans) => {
|
|
282
|
-
if (!ans.name) {
|
|
283
|
-
errorLog('自定义组件名称不能为空。');
|
|
284
|
-
process.exit(1);
|
|
285
|
-
} else {
|
|
286
|
-
mainAction.createCmpByTemplate(ans.name);
|
|
287
|
-
}
|
|
288
|
-
});
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
);
|
|
292
|
-
})
|
|
293
|
-
.command(
|
|
294
|
-
'pull cmp [options]',
|
|
295
|
-
'拉取线上自定义组件',
|
|
296
|
-
(yargs) => {
|
|
297
|
-
yargs
|
|
298
|
-
.reset()
|
|
299
|
-
.usage(titleTip('Usage') + ': $0 pull cmp [options]')
|
|
300
|
-
.option('name', {
|
|
301
|
-
alias: 'n',
|
|
302
|
-
describe: '自定义组件名称'
|
|
303
|
-
})
|
|
304
|
-
.alias('h', 'help');
|
|
305
|
-
},
|
|
306
|
-
async (argv) => {
|
|
307
|
-
if (argv.name) {
|
|
308
|
-
mainAction.pullCmp(argv.name);
|
|
309
|
-
} else {
|
|
310
|
-
// 创建 neoService 实例
|
|
311
|
-
const neoService = new NeoService(curConfig.neoConfig);
|
|
312
|
-
const spinner = ora('正在拉取线上自定义组件列表...').start();
|
|
313
|
-
const cmpList = await neoService.getCustomCmpList();
|
|
314
|
-
if (cmpList.length === 0) {
|
|
315
|
-
errorLog('当前租户暂无任何自定义组件。');
|
|
316
|
-
process.exit(1);
|
|
317
|
-
}
|
|
318
|
-
spinner.stop('线上自定义组件列表拉取成功。');
|
|
319
|
-
const cmpTypeChoices = cmpList.map((cmpItem) => ({
|
|
320
|
-
name: `${cmpItem.label}(${cmpItem.cmpType})`,
|
|
321
|
-
value: cmpItem.cmpType
|
|
322
|
-
}));
|
|
323
|
-
const questions = [
|
|
324
|
-
{
|
|
325
|
-
name: 'cmpType',
|
|
326
|
-
type: 'list',
|
|
327
|
-
message: '请选择要拉取的自定义组件:',
|
|
328
|
-
choices: cmpTypeChoices
|
|
329
|
-
}
|
|
330
|
-
];
|
|
331
|
-
inquirer.prompt(questions).then((ans) => {
|
|
332
|
-
if (!ans.cmpType) {
|
|
333
|
-
errorLog('自定义组件名称不能为空。');
|
|
334
|
-
process.exit(1);
|
|
335
|
-
} else {
|
|
336
|
-
mainAction.pullCmp(ans.cmpType, neoService);
|
|
337
|
-
}
|
|
338
|
-
});
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
)
|
|
342
|
-
.command(
|
|
343
|
-
'delete cmp [options]',
|
|
344
|
-
'删除线上自定义组件',
|
|
345
|
-
(yargs) => {
|
|
346
|
-
yargs
|
|
347
|
-
.reset()
|
|
348
|
-
.usage(titleTip('Usage') + ': $0 delete cmp [options]')
|
|
349
|
-
.option('name', {
|
|
350
|
-
alias: 'n',
|
|
351
|
-
describe: '自定义组件名称'
|
|
352
|
-
})
|
|
353
|
-
.alias('h', 'help');
|
|
354
|
-
},
|
|
355
|
-
async (argv) => {
|
|
356
|
-
if (argv.name) {
|
|
357
|
-
mainAction.deleteCmp(argv.name);
|
|
358
|
-
} else {
|
|
359
|
-
// 创建 neoService 实例
|
|
360
|
-
const neoService = new NeoService(curConfig.neoConfig);
|
|
361
|
-
const spinner = ora('正在获取线上自定义组件列表...').start();
|
|
362
|
-
const cmpList = await neoService.getCustomCmpList();
|
|
363
|
-
if (cmpList.length === 0) {
|
|
364
|
-
errorLog('当前租户暂无任何自定义组件。');
|
|
365
|
-
process.exit(1);
|
|
366
|
-
}
|
|
367
|
-
spinner.stop('线上自定义组件列表获取成功。');
|
|
368
|
-
const cmpTypeChoices = cmpList.map((cmpItem) => ({
|
|
369
|
-
name: `${cmpItem.label}(${cmpItem.cmpType})`,
|
|
370
|
-
value: cmpItem.cmpType
|
|
371
|
-
}));
|
|
372
|
-
const questions = [
|
|
373
|
-
{
|
|
374
|
-
name: 'cmpType',
|
|
375
|
-
type: 'list',
|
|
376
|
-
message: '请选择要删除的自定义组件:',
|
|
377
|
-
choices: cmpTypeChoices
|
|
378
|
-
}
|
|
379
|
-
];
|
|
380
|
-
inquirer.prompt(questions).then((ans) => {
|
|
381
|
-
if (!ans.cmpType) {
|
|
382
|
-
errorLog('自定义组件名称不能为空。');
|
|
383
|
-
process.exit(1);
|
|
384
|
-
} else {
|
|
385
|
-
mainAction.deleteCmp(ans.cmpType, neoService);
|
|
386
|
-
}
|
|
387
|
-
});
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
)
|
|
391
|
-
.command(
|
|
392
|
-
'preview [options]',
|
|
393
|
-
'预览指定自定义组件(仅预览组件本身内容)',
|
|
394
|
-
(yargs) => {
|
|
395
|
-
yargs
|
|
396
|
-
.reset()
|
|
397
|
-
.usage(titleTip('Usage') + ': $0 preview [options]')
|
|
398
|
-
.option('name', {
|
|
399
|
-
alias: 'n',
|
|
400
|
-
describe: '自定义组件名称'
|
|
401
|
-
})
|
|
402
|
-
.alias('h', 'help');
|
|
403
|
-
},
|
|
404
|
-
(argv) => {
|
|
405
|
-
if (argv.name) {
|
|
406
|
-
mainAction.previewCmp(argv.name);
|
|
407
|
-
} else {
|
|
408
|
-
const cmpTypes = getCmpTypeByDir();
|
|
409
|
-
if (cmpTypes.length === 0) {
|
|
410
|
-
errorLog('当前自定义组件目录中未找到自定义组件。(./src/components 目录下)');
|
|
411
|
-
process.exit(1);
|
|
412
|
-
}
|
|
413
|
-
const cmpTypeChoices = cmpTypes.map((cmpType) => ({
|
|
414
|
-
name: cmpType,
|
|
415
|
-
value: cmpType
|
|
416
|
-
}));
|
|
417
|
-
const questions = [
|
|
418
|
-
{
|
|
419
|
-
name: 'cmpType',
|
|
420
|
-
type: 'list',
|
|
421
|
-
message: '请选择要预览的自定义组件:',
|
|
422
|
-
choices: cmpTypeChoices
|
|
423
|
-
}
|
|
424
|
-
];
|
|
425
|
-
inquirer.prompt(questions).then((ans) => {
|
|
426
|
-
if (!ans.cmpType) {
|
|
427
|
-
errorLog('未选择要预览的自定义组件。');
|
|
428
|
-
process.exit(1);
|
|
429
|
-
}
|
|
430
|
-
mainAction.previewCmp(ans.cmpType);
|
|
431
|
-
});
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
)
|
|
435
|
-
.command(
|
|
436
|
-
'dev',
|
|
437
|
-
'开启本地调试模式',
|
|
438
|
-
(yargs) => {
|
|
439
|
-
yargs
|
|
440
|
-
.reset()
|
|
441
|
-
.usage(titleTip('Usage') + ': $0 dev')
|
|
442
|
-
.alias('h', 'help');
|
|
443
|
-
},
|
|
444
|
-
() => {
|
|
445
|
-
mainAction.dev();
|
|
446
|
-
}
|
|
447
|
-
)
|
|
448
|
-
.command(
|
|
449
|
-
'linkDebug',
|
|
450
|
-
'开启外链调试模式(在线上页面设计器端调试)',
|
|
451
|
-
(yargs) => {
|
|
452
|
-
yargs
|
|
453
|
-
.reset()
|
|
454
|
-
.usage(titleTip('Usage') + ': $0 linkDebug')
|
|
455
|
-
.alias('h', 'help');
|
|
456
|
-
},
|
|
457
|
-
(argv) => {
|
|
458
|
-
mainAction.linkDebug();
|
|
459
|
-
}
|
|
460
|
-
)
|
|
461
|
-
.command(
|
|
462
|
-
'build',
|
|
463
|
-
'构建生产环境代码',
|
|
464
|
-
(yargs) => {
|
|
465
|
-
yargs
|
|
466
|
-
.reset()
|
|
467
|
-
.usage(titleTip('Usage') + ': $0 build')
|
|
468
|
-
.alias('h', 'help');
|
|
469
|
-
},
|
|
470
|
-
(argv) => {
|
|
471
|
-
mainAction.build();
|
|
472
|
-
}
|
|
473
|
-
)
|
|
474
|
-
.command(
|
|
475
|
-
'build2lib',
|
|
476
|
-
'构建 UMD 模块',
|
|
477
|
-
(yargs) => {
|
|
478
|
-
yargs
|
|
479
|
-
.reset()
|
|
480
|
-
.usage(titleTip('Usage') + ': $0 build2lib')
|
|
481
|
-
.alias('h', 'help');
|
|
482
|
-
},
|
|
483
|
-
(argv) => {
|
|
484
|
-
mainAction.build2lib(); // 构建library
|
|
485
|
-
}
|
|
486
|
-
)
|
|
487
|
-
.command(
|
|
488
|
-
'publish2oss [options]',
|
|
489
|
-
'发布到oss',
|
|
490
|
-
(yargs) => {
|
|
491
|
-
yargs
|
|
492
|
-
.reset()
|
|
493
|
-
.usage(titleTip('Usage') + ': $0 publish2oss [options]')
|
|
494
|
-
.option('name', {
|
|
495
|
-
alias: 'n',
|
|
496
|
-
describe: '自定义组件名称'
|
|
497
|
-
})
|
|
498
|
-
.alias('h', 'help');
|
|
499
|
-
},
|
|
500
|
-
(argv) => {
|
|
501
|
-
if (argv.name) {
|
|
502
|
-
mainAction.publish2oss(argv.name); // 构建并发布脚本到oss
|
|
503
|
-
} else {
|
|
504
|
-
const cmpTypes = getCmpTypeByDir();
|
|
505
|
-
if (cmpTypes.length === 0) {
|
|
506
|
-
errorLog('当前自定义组件目录中未找到自定义组件。(./src/components 目录下)');
|
|
507
|
-
process.exit(1);
|
|
508
|
-
}
|
|
509
|
-
const cmpTypeChoices = cmpTypes.map((cmpType) => ({
|
|
510
|
-
name: cmpType,
|
|
511
|
-
value: cmpType
|
|
512
|
-
}));
|
|
513
|
-
const questions = [
|
|
514
|
-
{
|
|
515
|
-
name: 'cmpType',
|
|
516
|
-
type: 'list',
|
|
517
|
-
message: '请选择要发布的自定义组件:',
|
|
518
|
-
choices: cmpTypeChoices
|
|
519
|
-
}
|
|
520
|
-
];
|
|
521
|
-
inquirer.prompt(questions).then((ans) => {
|
|
522
|
-
if (!ans.cmpType) {
|
|
523
|
-
errorLog('未选择要发布的自定义组件。');
|
|
524
|
-
process.exit(1);
|
|
525
|
-
}
|
|
526
|
-
mainAction.publish2oss(ans.cmpType);
|
|
527
|
-
});
|
|
528
|
-
}
|
|
529
|
-
}
|
|
530
|
-
)
|
|
531
|
-
.command(
|
|
532
|
-
'push cmp [options]',
|
|
533
|
-
'构建并发布自定义组件到 NeoCRM 平台',
|
|
534
|
-
(yargs) => {
|
|
535
|
-
yargs
|
|
536
|
-
.reset()
|
|
537
|
-
.usage(titleTip('Usage') + ': $0 push cmp [options]')
|
|
538
|
-
.option('name', {
|
|
539
|
-
alias: 'n',
|
|
540
|
-
describe: '自定义组件名称'
|
|
541
|
-
})
|
|
542
|
-
.alias('h', 'help');
|
|
543
|
-
},
|
|
544
|
-
(argv) => {
|
|
545
|
-
if (argv.name) {
|
|
546
|
-
mainAction.pushCmp(argv.name); // 构建并发布组件到 NeoCRM
|
|
547
|
-
} else {
|
|
548
|
-
const cmpTypes = getCmpTypeByDir();
|
|
549
|
-
if (cmpTypes.length === 0) {
|
|
550
|
-
errorLog('当前自定义组件目录中未找到自定义组件。(./src/components 目录下)');
|
|
551
|
-
process.exit(1);
|
|
552
|
-
}
|
|
553
|
-
const cmpTypeChoices = cmpTypes.map((cmpType) => ({
|
|
554
|
-
name: cmpType,
|
|
555
|
-
value: cmpType
|
|
556
|
-
}));
|
|
557
|
-
const questions = [
|
|
558
|
-
{
|
|
559
|
-
name: 'cmpType',
|
|
560
|
-
type: 'list',
|
|
561
|
-
message: '请选择要发布的自定义组件:',
|
|
562
|
-
choices: cmpTypeChoices
|
|
563
|
-
}
|
|
564
|
-
];
|
|
565
|
-
inquirer.prompt(questions).then((ans) => {
|
|
566
|
-
if (!ans.cmpType) {
|
|
567
|
-
errorLog('未选择要发布的自定义组件。');
|
|
568
|
-
process.exit(1);
|
|
569
|
-
}
|
|
570
|
-
mainAction.pushCmp(ans.cmpType);
|
|
571
|
-
});
|
|
572
|
-
}
|
|
573
|
-
}
|
|
574
|
-
)
|
|
575
|
-
.command(
|
|
576
|
-
'build2esm',
|
|
577
|
-
'构建 ESM 模块',
|
|
578
|
-
(yargs) => {
|
|
579
|
-
yargs
|
|
580
|
-
.reset()
|
|
581
|
-
.usage(titleTip('Usage') + ': $0 build2esm')
|
|
582
|
-
.option('fileName', {
|
|
583
|
-
alias: 'n',
|
|
584
|
-
describe: '输出的文件名',
|
|
585
|
-
default: ''
|
|
586
|
-
})
|
|
587
|
-
.alias('h', 'help');
|
|
588
|
-
},
|
|
589
|
-
(argv) => {
|
|
590
|
-
mainAction.build2esm(argv.fileName); // 构建esm
|
|
591
|
-
}
|
|
592
|
-
)
|
|
593
|
-
.command(
|
|
594
|
-
'inspect',
|
|
595
|
-
'输出当前配置文件',
|
|
596
|
-
(yargs) => {
|
|
597
|
-
yargs
|
|
598
|
-
.reset()
|
|
599
|
-
.usage(titleTip('Usage') + ': $0 inspect')
|
|
600
|
-
.option('type', {
|
|
601
|
-
alias: 't',
|
|
602
|
-
describe: '环境类型(本地调试环境/生产环境/library构建环境)',
|
|
603
|
-
default: 'build'
|
|
604
|
-
})
|
|
605
|
-
.alias('h', 'help');
|
|
606
|
-
},
|
|
607
|
-
(argv) => {
|
|
608
|
-
inspect(argv.type);
|
|
609
|
-
}
|
|
610
|
-
)
|
|
611
|
-
.command(
|
|
612
|
-
'open [options]',
|
|
613
|
-
'使用 Cursor 或 VSCode 打开项目',
|
|
614
|
-
(yargs) => {
|
|
615
|
-
yargs
|
|
616
|
-
.reset()
|
|
617
|
-
.usage(titleTip('Usage') + ': $0 open [options]')
|
|
618
|
-
.option('editor', {
|
|
619
|
-
alias: 'e',
|
|
620
|
-
describe: '编辑器类型(cursor/vscode/auto),默认为 auto(自动检测)',
|
|
621
|
-
default: 'auto',
|
|
622
|
-
choices: ['cursor', 'vscode', 'code', 'auto']
|
|
623
|
-
})
|
|
624
|
-
.option('name', {
|
|
625
|
-
alias: 'n',
|
|
626
|
-
describe: '要打开的项目名称,默认为当前目录'
|
|
627
|
-
})
|
|
628
|
-
.alias('h', 'help');
|
|
629
|
-
},
|
|
630
|
-
(argv) => {
|
|
631
|
-
mainAction.openEditor(argv.editor, argv.name);
|
|
632
|
-
}
|
|
633
|
-
)
|
|
634
|
-
.alias('h', 'help')
|
|
635
|
-
.alias('v', 'version')
|
|
636
|
-
.strict()
|
|
637
|
-
.fail((msg, err, yargs) => {
|
|
638
|
-
errorLog(`\n运行命令时发生错误: ${msg}。\n`);
|
|
639
|
-
console.log(titleTip('当前可用命令列表:'));
|
|
640
|
-
console.log('');
|
|
641
|
-
// 定义所有可用命令及其描述
|
|
642
|
-
const commands = [
|
|
643
|
-
{ cmd: 'init [options]', desc: '根据模板创建一个自定义组件' },
|
|
644
|
-
// { cmd: 'config init', desc: '创建 neo.config.js 配置文件' },
|
|
645
|
-
{ cmd: 'create project [options]', desc: '创建自定义组件项目(含工程代码)' },
|
|
646
|
-
{ cmd: 'create cmp [options]', desc: '创建自定义组件' },
|
|
647
|
-
{ cmd: 'preview [options]', desc: '预览指定自定义组件(仅预览组件本身内容)' },
|
|
648
|
-
// { cmd: 'dev', desc: '开启本地调试模式' },
|
|
649
|
-
{ cmd: 'linkDebug', desc: '开启外链调试模式(在线上页面设计器端调试)' },
|
|
650
|
-
// { cmd: 'build', desc: '构建生产环境代码' },
|
|
651
|
-
// { cmd: 'build2lib', desc: '构建 UMD 模块' },
|
|
652
|
-
// { cmd: 'build2esm', desc: '构建 ESM 模块' },
|
|
653
|
-
// { cmd: 'publish2oss [options]', desc: '发布到oss' },
|
|
654
|
-
// { cmd: 'inspect', desc: '输出当前配置文件' },
|
|
655
|
-
{ cmd: 'login', desc: '登录 NeoCRM 平台(OAuth2 授权)' },
|
|
656
|
-
{ cmd: 'logout', desc: '登出 NeoCRM 平台' },
|
|
657
|
-
{ cmd: 'pull cmp [options]', desc: '拉取线上自定义组件' },
|
|
658
|
-
{ cmd: 'delete cmp [options]', desc: '删除线上自定义组件' },
|
|
659
|
-
{ cmd: 'push cmp [options]', desc: '构建并发布自定义组件到 NeoCRM 平台' },
|
|
660
|
-
{ cmd: 'open [options]', desc: '使用 Cursor 或 VSCode 打开项目' }
|
|
661
|
-
];
|
|
662
|
-
commands.forEach(({ cmd, desc }) => {
|
|
663
|
-
console.log(` ${chalk.cyan(cmd.padEnd(25))} ${desc}`);
|
|
664
|
-
});
|
|
665
|
-
console.log('');
|
|
666
|
-
console.log(`使用 ${chalk.cyan('neo <command> --help')} 查看具体命令的帮助信息。`);
|
|
667
|
-
console.log('');
|
|
668
|
-
process.exit(1);
|
|
669
|
-
})
|
|
670
|
-
.help()
|
|
671
|
-
.updateStrings({
|
|
672
|
-
'Usage:': titleTip('Usage:'),
|
|
673
|
-
'Commands:': titleTip('Commands:'),
|
|
674
|
-
'Options:': titleTip('Options:')
|
|
675
|
-
}).argv;
|