neo-cmp-cli 1.11.0 → 1.11.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index2.js +1 -1
- package/dist/main2.js +1 -1
- package/dist/neo/env.js +1 -1
- package/dist/neo/neoService.js +1 -1
- package/dist/package.json.js +1 -1
- package/package.json +1 -1
- package/template/antd-custom-cmp-template/package.json +1 -1
- package/template/echarts-custom-cmp-template/package.json +1 -1
- package/template/neo-bi-cmps/package.json +1 -1
- package/template/neo-custom-cmp-template/package.json +1 -1
- package/template/neo-h5-cmps/package.json +1 -1
- package/template/neo-order-cmps/package.json +1 -1
- package/template/react-custom-cmp-template/package.json +1 -1
- package/template/react-ts-custom-cmp-template/package.json +1 -1
- package/template/vue2-custom-cmp-template/package.json +1 -1
package/dist/index2.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./_virtual/index.js"),s=require("figlet"),o=require("yargs"),n=require("chalk"),a=require("inquirer"),t=require("ora"),p=require("./main2.js"),c=require("./neo/env.js"),i=require("./package.json.js");var m;exports.__require=function(){if(m)return e.__exports;m=1;const l=s,r=o,u=n,g=a,d=t,{neoInit:h,neoInitByCopy:y,inspect:b,neoConfigInit:v,validateProjectName:C,getCmpTypeByDir:$,NeoService:f,NeoLoginService:x,hasNeoProject:T,consoleTag:w,errorLog:U,successLog:j,warningLog:L}=p.__require(),N=p.__require(),{getNeoCrmAPI:_}=c.__require(),M=i.default,q=l.textSync("neo",{font:"Lean"}),S=N.projectConfig,D=function(e){return u.green(u.bold(e))},R={"config init":"初始化配置文件",dev:"开启本地调试模式",build:"构建生产环境代码",build2lib:"构建 UMD 模块",build2esm:"构建 ESM 模块",publish2oss:"发布到 OSS",inspect:"输出配置文件",open:"打开项目"},A={...R,init:"初始化自定义组件项目",login:"登录 NeoCRM 平台",logout:"登出 NeoCRM 平台","create project":"创建自定义组件项目","create cmp":"创建自定义组件",linkDebug:"开启外链调试模式","pull cmp":"拉取线上自定义组件","delete cmp":"删除线上自定义组件",preview:"预览自定义组件","push cmp":"发布自定义组件到平台"};return r.middleware(function(e){if(e.help||e.version)return;const s=function(e){if(!e._||0===e._.length)return"";const s=e._.join(" ");if(A[s])return s;const o=e._[0];return A[o]?o:s||o}(e);if(!s)return;const o=A[s]||s;R[s]&&(console.log(u.green(q)),console.log(u.green(`当前版本:v${M.version}.\n`))),console.log(""),console.log(u.cyan(`执行命令: ${o}`)),console.log("")}).command("init [options]","根据模板创建一个自定义组件",e=>{e.reset().usage(D("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)T()&&(U(`${w}创建自定义组件失败,当前目录(${process.cwd()})已经是一个自定义组件项目,请勿重复创建。`),process.exit(1)),"github"===e.mode?h(e.type,e.name):y(e.type,e.name);else{const s=[],o=[{name:"react&ts 自定义组件",value:"react-ts",short:"react-ts"},{name:"Neo 自定义业务组件",value:"neo",short:"neo"},{name:"Neo H5 自定义业务组件",value:"neo-h5-cmps",short:"neo-h5-cmps"},{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"}),g.prompt(s).then(s=>{const{isValid:o,errors:n}=C(s.name);o||(U(n.join("\n")),process.exit(1)),"github"===e.mode?h(s.type,s.name):y(s.type,s.name)})}}).command("config init","创建 neo.config.js 配置文件",e=>{e.reset().usage(D("Usage")+": $0 config init").alias("h","help")},()=>{v("neo.config.js")}).command("login","登录 NeoCRM 平台(OAuth2 授权)",e=>{e.reset().usage(D("Usage")+": $0 login").alias("h","help")},()=>{const e=[{name:"env",type:"list",message:"请选择您要登录的环境:",default:"cd",choices:[{name:"线上生产环境(crm.xiaoshouyi.com)",value:"production"},{name:"灰度环境(crm-gray.xiaoshouyi.com)",value:"gray"},{name:"沙盒环境(crm-sandbox.xiaoshouyi.com)",value:"sandbox"},{name:"开发环境(crm-cd.xiaoshouyi.com)",value:"cd"},{name:"自定义环境(在neo.config.js / neoConfig 中自行配置)",value:"custom"}]}];g.prompt(e).then(async e=>{const s=_(e.env,S.neoConfig);try{const e=new x(s);await e.login(),process.exit(0)}catch(e){U(`\n登录失败: ${e.message||e.msg}`),process.exit(1)}})}).command("logout","登出 NeoCRM 平台",e=>{e.reset().usage(D("Usage")+": $0 logout").alias("h","help")},async()=>{try{const e=new x;await e.logout(),process.exit(0)}catch(e){U(`\n登出失败: ${e.message||e.msg}`),process.exit(1)}}).command("create","创建项目或者组件",e=>e.command("project [options]","创建自定义组件项目(含工程代码)",e=>{e.reset().usage(D("Usage")+": $0 project [options]").option("name",{alias:"n",describe:"自定义组件项目名称"}).alias("h","help")},e=>{if(e.name)N.createCmpProjectByTemplate(e.name);else{const e=[{name:"name",type:"input",message:"请设置自定义组件项目名称:"}];g.prompt(e).then(e=>{const{isValid:s,errors:o}=C(e.name);s||(U(o.join("\n")),process.exit(1)),e.name?N.createCmpProjectByTemplate(e.name):(U("自定义组件项目名称不能为空。"),process.exit(1))})}}).command("cmp [options]","创建自定义组件",e=>{e.reset().usage(D("Usage")+": $0 cmp [options]").option("name",{alias:"n",describe:"自定义组件名称"}).alias("h","help")},e=>{if(e.name)N.createCmpByTemplate(e.name);else{const e=[{name:"name",type:"input",message:"请设置自定义组件名称:"}];g.prompt(e).then(e=>{e.name?N.createCmpByTemplate(e.name):(U("自定义组件名称不能为空。"),process.exit(1))})}})).command("pull cmp [options]","拉取线上自定义组件",e=>{e.reset().usage(D("Usage")+": $0 pull cmp [options]").option("name",{alias:"n",describe:"自定义组件名称"}).alias("h","help")},async e=>{if(e.name){L(`[neo pull cmp] 即将拉取自定义组件:${e.name},如本地已存在同名组件目录,将可能被覆盖,请提前备份本地修改。`);try{await N.pullCmp(e.name)}catch(e){U(e.message||e.msg||"拉取线上自定义组件失败"),process.exit(1)}}else{const e=new f,s=d("正在拉取线上自定义组件列表...").start(),o=await e.getCustomCmpList();0===o.length&&(U("当前租户暂无任何自定义组件。"),process.exit(1)),s.stop("线上自定义组件列表拉取成功。");const n=[{name:"cmpType",type:"list",message:"请选择要拉取的自定义组件:",choices:[{name:"拉取所有组件(ALL)",value:"ALL"},...o.map(e=>({name:`${e.label}(${e.cmpType})`,value:e.cmpType}))]}];try{const s=await g.prompt(n);if(s.cmpType)if("ALL"===s.cmpType){L(`[neo pull cmp] 即将拉取当前租户下的所有自定义组件(共 ${o.length} 个),如本地存在同名组件目录,将可能被覆盖,请提前备份本地修改。`);for(let s=0,n=o.length;s<n;s++){const a=o[s];console.log(u.gray(`[neo pull cmp] 正在拉取第 ${s+1}/${n} 个组件: ${a.cmpType}`)),await N.pullCmp(a.cmpType,e)}j("[neo pull cmp]拉取所有组件命令已执行完成。")}else L(`[neo pull cmp] 即将拉取自定义组件:${s.cmpType},如本地已存在同名组件目录,将可能被覆盖,请提前备份本地修改。`),await N.pullCmp(s.cmpType,e);else U("请选择要拉取的自定义组件。"),process.exit(1)}catch(e){U(e.message||e.msg||"拉取线上自定义组件失败"),process.exit(1)}}}).command("delete cmp [options]","删除线上自定义组件",e=>{e.reset().usage(D("Usage")+": $0 delete cmp [options]").option("name",{alias:"n",describe:"自定义组件名称"}).alias("h","help")},async e=>{if(e.name)N.deleteCmp(e.name);else{const e=new f,s=d("正在获取线上自定义组件列表...").start(),o=await e.getCustomCmpList();0===o.length&&(U("当前租户暂无任何自定义组件。"),process.exit(1)),s.stop("线上自定义组件列表获取成功。");const n=[{name:"cmpType",type:"list",message:"请选择要删除的自定义组件:",choices:o.map(e=>({name:`${e.label}(${e.cmpType})`,value:e.cmpType}))}];g.prompt(n).then(s=>{s.cmpType?N.deleteCmp(s.cmpType,e):(U("自定义组件名称不能为空。"),process.exit(1))})}}).command("preview [options]","预览指定自定义组件(仅预览组件本身内容)",e=>{e.reset().usage(D("Usage")+": $0 preview [options]").option("name",{alias:"n",describe:"自定义组件名称"}).alias("h","help")},e=>{if(e.name)N.previewCmp(e.name);else{const e=$(S.componentsDir);0===e.length&&(U("当前自定义组件目录中未找到自定义组件。(./src/components 目录下)"),process.exit(1));const s=[{name:"cmpType",type:"list",message:"请选择要预览的自定义组件:",choices:e.map(e=>({name:e,value:e}))}];g.prompt(s).then(e=>{e.cmpType||(U("未选择要预览的自定义组件。"),process.exit(1)),N.previewCmp(e.cmpType)})}}).command("dev","开启本地调试模式",e=>{e.reset().usage(D("Usage")+": $0 dev").alias("h","help")},()=>{N.dev()}).command("linkDebug","开启外链调试模式(在线上页面设计器端调试)",e=>{e.reset().usage(D("Usage")+": $0 linkDebug").alias("h","help")},e=>{N.linkDebug()}).command("build","构建生产环境代码",e=>{e.reset().usage(D("Usage")+": $0 build").alias("h","help")},e=>{N.build()}).command("build2lib","构建 UMD 模块",e=>{e.reset().usage(D("Usage")+": $0 build2lib").alias("h","help")},e=>{N.build2lib()}).command("publish2oss [options]","发布到oss",e=>{e.reset().usage(D("Usage")+": $0 publish2oss [options]").option("name",{alias:"n",describe:"自定义组件名称"}).alias("h","help")},e=>{if(e.name)N.publish2oss(e.name);else{const e=$(S.componentsDir);0===e.length&&(U("当前自定义组件目录中未找到自定义组件。(./src/components 目录下)"),process.exit(1));const s=[{name:"cmpType",type:"list",message:"请选择要发布的自定义组件:",choices:e.map(e=>({name:e,value:e}))}];g.prompt(s).then(e=>{e.cmpType||(U("未选择要发布的自定义组件。"),process.exit(1)),N.publish2oss(e.cmpType)})}}).command("push cmp [options]","构建并发布自定义组件到 NeoCRM 平台",e=>{e.reset().usage(D("Usage")+": $0 push cmp [options]").option("name",{alias:"n",describe:"自定义组件名称"}).alias("h","help")},async e=>{if(e.name){L(`[neo push cmp] 即将构建并发布自定义组件:${e.name} 到 NeoCRM 平台,请确保已经通过 neo login 登录到正确的环境。`);try{await N.pushCmp(e.name)}catch(e){U(e.message||e.msg||"发布自定义组件失败"),process.exit(1)}}else{const e=$(S.componentsDir);0===e.length&&(U("当前自定义组件目录中未找到自定义组件。(./src/components 目录下)"),process.exit(1));const s=[{name:"cmpType",type:"list",message:"请选择要发布的自定义组件:",choices:[{name:"发布所有组件(ALL)",value:"ALL"},...e.map(e=>({name:e,value:e}))]}];g.prompt(s).then(async s=>{s.cmpType||(U("请选择要发布的自定义组件。"),process.exit(1));try{if("ALL"===s.cmpType){L(`[neo push cmp] 即将构建并发布当前目录下的所有自定义组件(共 ${e.length} 个)到 NeoCRM 平台,请确保已经通过 neo login 登录到正确的环境。`);for(let s=0,o=e.length;s<o;s++){const n=e[s];console.log(u.gray(`[neo push cmp] 正在拉取第 ${s+1}/${o} 个组件: ${n}`)),await N.pushCmp(n,!0)}j("[neo push cmp]发布所有组件命令已执行完成。")}else L(`[neo push cmp] 即将构建并发布自定义组件:${s.cmpType} 到 NeoCRM 平台,请确保已经通过 neo login 登录到正确的环境。`),await N.pushCmp(s.cmpType)}catch(e){U(e.message||e.msg||"发布失败"),process.exit(1)}})}}).command("build2esm","构建 ESM 模块",e=>{e.reset().usage(D("Usage")+": $0 build2esm").alias("h","help")},()=>{N.build2esm()}).command("inspect","输出当前配置文件",e=>{e.reset().usage(D("Usage")+": $0 inspect").option("type",{alias:"t",describe:"环境类型(本地调试环境/生产环境/library构建环境)",default:"build"}).alias("h","help")},e=>{b(e.type)}).command("open [options]","使用 Cursor 或 VSCode 打开项目",e=>{e.reset().usage(D("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=>{N.openEditor(e.editor,e.name)}).alias("h","help").alias("v","version").strict().fail((e,s,o)=>{U(`\n运行命令时发生错误: ${e}。\n`),console.log(D("当前可用命令列表:")),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(` ${u.cyan(e.padEnd(25))} ${s}`)}),console.log(""),console.log(`使用 ${u.cyan("neo <command> --help")} 查看具体命令的帮助信息。`),console.log(""),process.exit(1)}).help().updateStrings({"Usage:":D("Usage:"),"Commands:":D("Commands:"),"Options:":D("Options:")}).argv,e.__exports};
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./_virtual/index.js"),s=require("figlet"),o=require("yargs"),n=require("chalk"),a=require("inquirer"),t=require("ora"),p=require("./main2.js"),c=require("./utils/common.js"),i=require("./neo/env.js"),m=require("./package.json.js");var l;exports.__require=function(){if(l)return e.__exports;l=1;const r=s,u=o,g=n,d=a,h=t,{neoInit:y,neoInitByCopy:b,inspect:v,neoConfigInit:C,validateProjectName:$,getCmpTypeByDir:f,NeoService:x,NeoLoginService:T,hasNeoProject:w,consoleTag:j}=p.__require(),{errorLog:U,successLog:L,warningLog:_}=c.__require(),N=p.__require(),{getNeoCrmAPI:q}=i.__require(),M=m.default,S=r.textSync("neo",{font:"Lean"}),D=N.projectConfig,R=function(e){return g.green(g.bold(e))},A={"config init":"初始化配置文件",dev:"开启本地调试模式",build:"构建生产环境代码",build2lib:"构建 UMD 模块",build2esm:"构建 ESM 模块",publish2oss:"发布到 OSS",inspect:"输出配置文件",open:"打开项目"},k={...A,init:"初始化自定义组件项目",login:"登录 NeoCRM 平台",logout:"登出 NeoCRM 平台","create project":"创建自定义组件项目","create cmp":"创建自定义组件",linkDebug:"开启外链调试模式","pull cmp":"拉取线上自定义组件","delete cmp":"删除线上自定义组件",preview:"预览自定义组件","push cmp":"发布自定义组件到平台"};return u.middleware(function(e){if(e.help||e.version)return;const s=function(e){if(!e._||0===e._.length)return"";const s=e._.join(" ");if(k[s])return s;const o=e._[0];return k[o]?o:s||o}(e);if(!s)return;const o=k[s]||s;A[s]&&(console.log(g.green(S)),console.log(g.green(`当前版本:v${M.version}.\n`))),console.log(""),console.log(g.cyan(`执行命令: ${o}`)),console.log("")}).command("init [options]","根据模板创建一个自定义组件",e=>{e.reset().usage(R("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)w()&&(U(`${j}创建自定义组件失败,当前目录(${process.cwd()})已经是一个自定义组件项目,请勿重复创建。`),process.exit(1)),"github"===e.mode?y(e.type,e.name):b(e.type,e.name);else{const s=[],o=[{name:"react&ts 自定义组件",value:"react-ts",short:"react-ts"},{name:"Neo 自定义业务组件",value:"neo",short:"neo"},{name:"Neo H5 自定义业务组件",value:"neo-h5-cmps",short:"neo-h5-cmps"},{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"}),d.prompt(s).then(s=>{const{isValid:o,errors:n}=$(s.name);o||(U(n.join("\n")),process.exit(1)),"github"===e.mode?y(s.type,s.name):b(s.type,s.name)})}}).command("config init","创建 neo.config.js 配置文件",e=>{e.reset().usage(R("Usage")+": $0 config init").alias("h","help")},()=>{C("neo.config.js")}).command("login","登录 NeoCRM 平台(OAuth2 授权)",e=>{e.reset().usage(R("Usage")+": $0 login").alias("h","help")},()=>{const e=[{name:"env",type:"list",message:"请选择您要登录的环境:",default:"cd",choices:[{name:"线上生产环境(crm.xiaoshouyi.com)",value:"production"},{name:"灰度环境(crm-gray.xiaoshouyi.com)",value:"gray"},{name:"沙盒环境(crm-sandbox.xiaoshouyi.com)",value:"sandbox"},{name:"开发环境(crm-cd.xiaoshouyi.com)",value:"cd"},{name:"自定义环境(在neo.config.js / neoConfig 中自行配置)",value:"custom"}]}];d.prompt(e).then(async e=>{const s=q(e.env,D.neoConfig);try{const e=new T(s);await e.login(),process.exit(0)}catch(e){U(`\n登录失败: ${e.message||e.msg}`),process.exit(1)}})}).command("logout","登出 NeoCRM 平台",e=>{e.reset().usage(R("Usage")+": $0 logout").alias("h","help")},async()=>{try{const e=new T;await e.logout(),process.exit(0)}catch(e){U(`\n登出失败: ${e.message||e.msg}`),process.exit(1)}}).command("create","创建项目或者组件",e=>e.command("project [options]","创建自定义组件项目(含工程代码)",e=>{e.reset().usage(R("Usage")+": $0 project [options]").option("name",{alias:"n",describe:"自定义组件项目名称"}).alias("h","help")},e=>{if(e.name)N.createCmpProjectByTemplate(e.name);else{const e=[{name:"name",type:"input",message:"请设置自定义组件项目名称:"}];d.prompt(e).then(e=>{const{isValid:s,errors:o}=$(e.name);s||(U(o.join("\n")),process.exit(1)),e.name?N.createCmpProjectByTemplate(e.name):(U("自定义组件项目名称不能为空。"),process.exit(1))})}}).command("cmp [options]","创建自定义组件",e=>{e.reset().usage(R("Usage")+": $0 cmp [options]").option("name",{alias:"n",describe:"自定义组件名称"}).alias("h","help")},e=>{if(e.name)N.createCmpByTemplate(e.name);else{const e=[{name:"name",type:"input",message:"请设置自定义组件名称:"}];d.prompt(e).then(e=>{e.name?N.createCmpByTemplate(e.name):(U("自定义组件名称不能为空。"),process.exit(1))})}})).command("pull cmp [options]","拉取线上自定义组件",e=>{e.reset().usage(R("Usage")+": $0 pull cmp [options]").option("name",{alias:"n",describe:"自定义组件名称"}).alias("h","help")},async e=>{if(e.name){_(`[neo pull cmp] 即将拉取自定义组件:${e.name},如本地已存在同名组件目录,将可能被覆盖,请提前备份本地修改。`);try{await N.pullCmp(e.name)}catch(e){U(e.message||e.msg||"拉取线上自定义组件失败"),process.exit(1)}}else{const e=new x,s=h("正在拉取线上自定义组件列表...").start(),o=await e.getCustomCmpList();0===o.length&&(U("当前租户暂无任何自定义组件。"),process.exit(1)),s.stop("线上自定义组件列表拉取成功。");const n=[{name:"cmpType",type:"list",message:"请选择要拉取的自定义组件:",choices:[{name:"拉取所有组件(ALL)",value:"ALL"},...o.map(e=>({name:`${e.label}(${e.cmpType})`,value:e.cmpType}))]}];try{const s=await d.prompt(n);if(s.cmpType)if("ALL"===s.cmpType){_(`[neo pull cmp] 即将拉取当前租户下的所有自定义组件(共 ${o.length} 个),如本地存在同名组件目录,将可能被覆盖,请提前备份本地修改。`);for(let s=0,n=o.length;s<n;s++){const a=o[s];console.log(g.gray(`[neo pull cmp] 正在拉取第 ${s+1}/${n} 个组件: ${a.cmpType}`)),await N.pullCmp(a.cmpType,e)}L("[neo pull cmp]拉取所有组件命令已执行完成。")}else _(`[neo pull cmp] 即将拉取自定义组件:${s.cmpType},如本地已存在同名组件目录,将可能被覆盖,请提前备份本地修改。`),await N.pullCmp(s.cmpType,e);else U("请选择要拉取的自定义组件。"),process.exit(1)}catch(e){U(e.message||e.msg||"拉取线上自定义组件失败"),process.exit(1)}}}).command("delete cmp [options]","删除线上自定义组件",e=>{e.reset().usage(R("Usage")+": $0 delete cmp [options]").option("name",{alias:"n",describe:"自定义组件名称"}).alias("h","help")},async e=>{if(e.name)N.deleteCmp(e.name);else{const e=new x,s=h("正在获取线上自定义组件列表...").start(),o=await e.getCustomCmpList();0===o.length&&(U("当前租户暂无任何自定义组件。"),process.exit(1)),s.stop("线上自定义组件列表获取成功。");const n=[{name:"cmpType",type:"list",message:"请选择要删除的自定义组件:",choices:o.map(e=>({name:`${e.label}(${e.cmpType})`,value:e.cmpType}))}];d.prompt(n).then(s=>{s.cmpType?N.deleteCmp(s.cmpType,e):(U("自定义组件名称不能为空。"),process.exit(1))})}}).command("preview [options]","预览指定自定义组件(仅预览组件本身内容)",e=>{e.reset().usage(R("Usage")+": $0 preview [options]").option("name",{alias:"n",describe:"自定义组件名称"}).alias("h","help")},e=>{if(e.name)N.previewCmp(e.name);else{const e=f(D.componentsDir);0===e.length&&(U("当前自定义组件目录中未找到自定义组件。(./src/components 目录下)"),process.exit(1));const s=[{name:"cmpType",type:"list",message:"请选择要预览的自定义组件:",choices:e.map(e=>({name:e,value:e}))}];d.prompt(s).then(e=>{e.cmpType||(U("未选择要预览的自定义组件。"),process.exit(1)),N.previewCmp(e.cmpType)})}}).command("dev","开启本地调试模式",e=>{e.reset().usage(R("Usage")+": $0 dev").alias("h","help")},()=>{N.dev()}).command("linkDebug","开启外链调试模式(在线上页面设计器端调试)",e=>{e.reset().usage(R("Usage")+": $0 linkDebug").alias("h","help")},e=>{N.linkDebug()}).command("build","构建生产环境代码",e=>{e.reset().usage(R("Usage")+": $0 build").alias("h","help")},e=>{N.build()}).command("build2lib","构建 UMD 模块",e=>{e.reset().usage(R("Usage")+": $0 build2lib").alias("h","help")},e=>{N.build2lib()}).command("publish2oss [options]","发布到oss",e=>{e.reset().usage(R("Usage")+": $0 publish2oss [options]").option("name",{alias:"n",describe:"自定义组件名称"}).alias("h","help")},e=>{if(e.name)N.publish2oss(e.name);else{const e=f(D.componentsDir);0===e.length&&(U("当前自定义组件目录中未找到自定义组件。(./src/components 目录下)"),process.exit(1));const s=[{name:"cmpType",type:"list",message:"请选择要发布的自定义组件:",choices:e.map(e=>({name:e,value:e}))}];d.prompt(s).then(e=>{e.cmpType||(U("未选择要发布的自定义组件。"),process.exit(1)),N.publish2oss(e.cmpType)})}}).command("push cmp [options]","构建并发布自定义组件到 NeoCRM 平台",e=>{e.reset().usage(R("Usage")+": $0 push cmp [options]").option("name",{alias:"n",describe:"自定义组件名称"}).alias("h","help")},async e=>{if(e.name){_(`[neo push cmp] 即将构建并发布自定义组件:${e.name} 到 NeoCRM 平台,请确保已经通过 neo login 登录到正确的环境。`);try{await N.pushCmp(e.name)}catch(e){U(e.message||e.msg||"发布自定义组件失败"),process.exit(1)}}else{const e=f(D.componentsDir);0===e.length&&(U("当前自定义组件目录中未找到自定义组件。(./src/components 目录下)"),process.exit(1));const s=[{name:"cmpType",type:"list",message:"请选择要发布的自定义组件:",choices:[{name:"发布所有组件(ALL)",value:"ALL"},...e.map(e=>({name:e,value:e}))]}];d.prompt(s).then(async s=>{s.cmpType||(U("请选择要发布的自定义组件。"),process.exit(1));try{if("ALL"===s.cmpType){_(`[neo push cmp] 即将构建并发布当前目录下的所有自定义组件(共 ${e.length} 个)到 NeoCRM 平台,请确保已经通过 neo login 登录到正确的环境。`);for(let s=0,o=e.length;s<o;s++){const n=e[s];console.log(g.gray(`[neo push cmp] 正在拉取第 ${s+1}/${o} 个组件: ${n}`)),await N.pushCmp(n,!0)}L("[neo push cmp]发布所有组件命令已执行完成。")}else _(`[neo push cmp] 即将构建并发布自定义组件:${s.cmpType} 到 NeoCRM 平台,请确保已经通过 neo login 登录到正确的环境。`),await N.pushCmp(s.cmpType)}catch(e){U(e.message||e.msg||"发布失败"),process.exit(1)}})}}).command("build2esm","构建 ESM 模块",e=>{e.reset().usage(R("Usage")+": $0 build2esm").alias("h","help")},()=>{N.build2esm()}).command("inspect","输出当前配置文件",e=>{e.reset().usage(R("Usage")+": $0 inspect").option("type",{alias:"t",describe:"环境类型(本地调试环境/生产环境/library构建环境)",default:"build"}).alias("h","help")},e=>{v(e.type)}).command("open [options]","使用 Cursor 或 VSCode 打开项目",e=>{e.reset().usage(R("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=>{N.openEditor(e.editor,e.name)}).alias("h","help").alias("v","version").strict().fail((e,s,o)=>{U(`\n运行命令时发生错误: ${e}。\n`),console.log(R("当前可用命令列表:")),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(` ${g.cyan(e.padEnd(25))} ${s}`)}),console.log(""),console.log(`使用 ${g.cyan("neo <command> --help")} 查看具体命令的帮助信息。`),console.log(""),process.exit(1)}).help().updateStrings({"Usage:":R("Usage:"),"Commands:":R("Commands:"),"Options:":R("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("./neo/pushCmp.js"),n=require("./neo/pullCmp.js"),c=require("./neo/deleteCmp.js"),d=require("./utils/cmpUtils/previewCmp.js"),b=require("./utils/generateEntries.js"),m=require("./utils/cmpUtils/createCmpByTemplate.js"),a=require("./utils/projectUtils/createCmpProjectByTemplate.js"),y=require("./utils/projectUtils/openProject.js"),q=require("./utils/configureNeoBuild.js"),_=require("./utils/common.js"),
|
|
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("./neo/pushCmp.js"),n=require("./neo/pullCmp.js"),c=require("./neo/deleteCmp.js"),d=require("./utils/cmpUtils/previewCmp.js"),b=require("./utils/generateEntries.js"),m=require("./utils/cmpUtils/createCmpByTemplate.js"),a=require("./utils/projectUtils/createCmpProjectByTemplate.js"),y=require("./utils/projectUtils/openProject.js"),q=require("./utils/configureNeoBuild.js"),_=require("./utils/common.js"),j=require("./utils/projectNameValidator.js"),g=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,w=r.__require(),E=i.__require(),N=s.__require(),D=t.__require(),{consoleTag:B}=o.__require(),P=u.__require(),k=l.__require(),M=p.__require(),I=n.__require(),U=c.__require(),O=d.__require(),S=b.__require(),L=m.__require(),R=a.__require(),A=y.__require(),{configureNeoBuild:V}=q.__require(),{errorLog:z,successLog:F}=_.__require(),{validateProjectName:G}=j.__require(),H=g.__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}=S({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||e.msg),process.exit(1)}return{cmpTypes:t,defaultExports:o}}function X(e){return Object.assign(P.build2lib,e)}return C={neoInit:w,neoInitByCopy:E,inspect:N,neoConfigInit:D,projectConfig:P,consoleTag:B,validateProjectName:G,getCmpTypeByDir:H,NeoService:J,NeoLoginService:K,hasNeoProject:Q,createCmpProjectByTemplate:R,createCmpByTemplate:L,dev:()=>{P.dev||(z("未找到 dev 相关配置。"),process.exit(1)),h.dev(P,B)},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,O(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,P.dev,{cmpTypes:e,defaultExports:r,verbose:!0,excludeModel:!1}),h.dev(P,B)},build:()=>h.build("build",P,B),build2lib:()=>{W(P.build2lib,{entryType:"widget"}),P.build2lib.removeNeoCommonModules&&V(P,P.build2lib,{cmpTypes:[],defaultExports:[],verbose:!1,excludeModel:!0}),h.build("lib",P,B)},publish2oss:e=>{const r=P.publish2oss;P.build2lib=X(r);const{cmpTypes:i,defaultExports:s}=W(P.build2lib,{entryType:"widget",cmpType:e});V(P,P.build2lib,{cmpTypes:i,defaultExports:s,verbose:!0,excludeModel:!0}),h.build("lib",P,B,()=>{k(r.ossType,r.ossConfig,r.assetsRoot)})},pushCmp:(e,r=!1)=>{const{pushCmp:i}=P;P.build2lib=X(i),r&&(P.build2lib.entry={});const{cmpTypes:s,defaultExports:t}=W(P.build2lib,{entryType:"widget",cmpType:e});return V(P,P.build2lib,{cmpTypes:s,defaultExports:t,verbose:!1,excludeModel:!0}),new Promise((r,s)=>{h.build("lib",P,B,async()=>{try{await M({...i,componentsDir:P.componentsDir},e),r()}catch(e){s(e)}})})},pullCmp:I,deleteCmp:(e,r)=>{U(e,r)},build2esm:()=>h.build2esm(P,B),openEditor:A},C};
|
package/dist/neo/env.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("lodash");var t,e;exports.__require=function(){if(e)return t;e=1;const a=o,s={neoBaseURL:"https://crm.xiaoshouyi.com",loginURL:"https://login.xiaoshouyi.com/auc/oauth2/auth",tokenURL:"https://login.xiaoshouyi.com/auc/oauth2/token"},n={neoBaseURL:"https://crm-gray.xiaoshouyi.com",loginURL:"https://login.xiaoshouyi.com/auc/oauth2/auth",tokenURL:"https://login.xiaoshouyi.com/auc/oauth2/token"},u={neoBaseURL:"https://crm-sandbox.xiaoshouyi.com",loginURL:"https://login-sandbox.xiaoshouyi.com/auc/oauth2/auth",tokenURL:"https://login-sandbox.xiaoshouyi.com/auc/oauth2/token"},i={neoBaseURL:"https://crm-cd.xiaoshouyi.com",loginURL:"https://login-cd.xiaoshouyi.com/auc/oauth2/auth",tokenURL:"https://login-cd.xiaoshouyi.com/auc/oauth2/token"},c={neoBaseURL:"https://crm-cd.xiaoshouyi.com",loginURL:"https://login-cd.xiaoshouyi.com/auc/oauth2/auth",tokenURL:"https://login-cd.xiaoshouyi.com/auc/oauth2/token",delete:"/rest/metadata/v3.0/ui/customComponents",saveAPI:"/rest/metadata/v3.0/ui/customComponents/actions/saveOrUpdateComponent",
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("lodash");var t,e;exports.__require=function(){if(e)return t;e=1;const a=o,s={neoBaseURL:"https://crm.xiaoshouyi.com",loginURL:"https://login.xiaoshouyi.com/auc/oauth2/auth",tokenURL:"https://login.xiaoshouyi.com/auc/oauth2/token"},n={neoBaseURL:"https://crm-gray.xiaoshouyi.com",loginURL:"https://login.xiaoshouyi.com/auc/oauth2/auth",tokenURL:"https://login.xiaoshouyi.com/auc/oauth2/token"},u={neoBaseURL:"https://crm-sandbox.xiaoshouyi.com",loginURL:"https://login-sandbox.xiaoshouyi.com/auc/oauth2/auth",tokenURL:"https://login-sandbox.xiaoshouyi.com/auc/oauth2/token"},i={neoBaseURL:"https://crm-cd.xiaoshouyi.com",loginURL:"https://login-cd.xiaoshouyi.com/auc/oauth2/auth",tokenURL:"https://login-cd.xiaoshouyi.com/auc/oauth2/token"},c={neoBaseURL:"https://crm-cd.xiaoshouyi.com",loginURL:"https://login-cd.xiaoshouyi.com/auc/oauth2/auth",tokenURL:"https://login-cd.xiaoshouyi.com/auc/oauth2/token",delete:"/rest/metadata/v3.0/ui/customComponents",saveAPI:"/rest/metadata/v3.0/ui/customComponents/actions/saveOrUpdateComponent",queryAll_v1:"/rest/metadata/v3.0/ui/components/filter?custom=true",queryAll:"/rest/metadata/v3.0/ui/customComponents/actions/queryCustomComponents",getCodeLibAPI:o=>`/rest/metadata/v3.0/ui/customComponents/${o}/codeLib`,uploadAPI:"/rest/metadata/v3.0/ui/customComponents/actions/upload",getUserInfoAPI:"/rest/auc/v2.0/userInfo"};return t={DefaultNeoCrmAPI:c,getNeoCrmAPI:(o="cd",t={})=>{let e=a.cloneDeep(c),h=i;switch(o){case"production":h=s;break;case"gray":h=n;break;case"sandbox":h=u;break;case"cd":default:h=i;break;case"custom":h={...t,neoBaseURL:t.neoBaseURL,loginURL:t.loginURL||t.loginAPI,tokenURL:t.tokenURL||t.tokenAPI}}return{...e,...h}}}};
|
package/dist/neo/neoService.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("axios"),t=require("form-data"),s=require("node:fs"),o=require("node:path"),i=require("node:crypto"),r=require("ora"),n=require("lodash"),a=require("akfun"),c=require("./neoLogin.js"),l=require("../utils/projectUtils/updatePublishLog.js"),h=require("../utils/common.js"),d=require("./neoEnvManager.js"),u=require("../utils/tableLog.js");var p,m;exports.__require=function(){if(m)return p;m=1;const f=e,y=t,g=s,w=o,k=i,A=r,$=n,{resolve:C}=a,x=c.__require(),T=l.__require(),{getFramework:F,errorLog:L,successLog:P}=h.__require(),b=d.__require(),{tableLog:I}=u.__require(),S=["cmpType","label","componentCategory","description","framework","icon","iconUrl","orderNo","version","propsSchema","defaultProps","previewProps","events","functions","asset","modelAsset","cssAsset","codeLib"];return p=class{constructor(){const e=b.getEnvConfig(),{assetsRoot:t,auth:s,authType:o}=e||{};this.authType=o||"oauth2",this.NeoCrmAPI=e,"password"!==this.authType||s||(L("密码授权模式时,neo.config.js / neoConfig / auth 配置不能为空"),process.exit(1)),"password"===this.authType?s.client_id&&s.client_secret&&s.username&&s.password||(L("neo.config.js / neoConfig / auth 配置不完整(password 模式),需要包含 client_id、client_secret、username、password"),process.exit(1)):"oauth2"!=this.authType&&(L(`不支持的授权类型: ${this.authType},可选值:oauth2、password`),process.exit(1)),this.assetsRoot=t||C("dist"),this.auth=s,this.cmpList=[],this.cmpInfoMap={},this.tokenCache={token:null,expiresAt:null}}buildFullUrl(e){return e.startsWith("http://")||e.startsWith("https://")?e:`${this.NeoCrmAPI.neoBaseURL}${e}`}uploadAPI(){return this.buildFullUrl(this.NeoCrmAPI.uploadAPI)}saveAPI(){return this.buildFullUrl(this.NeoCrmAPI.saveAPI)}isTokenExpired(){return!this.tokenCache.token||!this.tokenCache.expiresAt||Date.now()>=this.tokenCache.expiresAt}async getToken(){return this.isTokenExpired()?"oauth2"===this.authType?await this.getTokenByOAuth2():await this.getTokenByPassword():this.tokenCache.token}async getTokenByPassword(){const e=A("获取 token(密码模式)...").start();if(!this.isTokenExpired())return P("使用缓存的 token。",e),this.tokenCache.token;const t=new URLSearchParams;t.append("grant_type","password"),t.append("client_id",this.auth.client_id),t.append("client_secret",this.auth.client_secret),t.append("username",this.auth.username),t.append("password",this.auth.password);const s=this.buildFullUrl(this.NeoCrmAPI.tokenURL);try{const o=await f.post(s,t.toString(),{headers:{"Content-Type":"application/x-www-form-urlencoded"}}),i=o.data||{},{access_token:r,expires_in:n}=i;r||(L("获取 token 失败(授权配置错误):响应中未包含 access_token,"+JSON.stringify(o.data),e),process.exit(1));const a=parseInt(n)||3600;return this.tokenCache={...i,token:r,expiresAt:Date.now()+1e3*(a-60)},e.clear(),e.stop(),r}catch(o){L("获取 token 失败",e),L(`\n获取 token 失败: ${o.message||o.msg}`),L(`\ntoken 授权地址: ${s}`),L(`\ntoken 请求参数: ${t}`),o.response&&L(`响应数据: ${JSON.stringify(o.response.data)}`),process.exit(1)}}async getTokenByOAuth2(){const e=A("获取 token(OAuth2 模式)...").start();try{const t={neoBaseURL:this.NeoCrmAPI.neoBaseURL,loginURL:this.NeoCrmAPI.loginURL,tokenURL:this.NeoCrmAPI.tokenURL},s=new x(t),o=await s.getAccessToken(),i=o.access_token;return this.tokenCache={...o,token:i,expiresAt:Date.now()+72e5},e.clear(),e.stop(),i}catch(t){L("获取 token 失败(OAuth2 模式)",e),L(`\n获取 token 失败: ${t.message||t.msg}`),t.response&&L(`响应数据: ${JSON.stringify(t.response.data)}`),process.exit(1)}}async refreshToken(){return this.tokenCache={token:null,expiresAt:null},await this.getToken()}async ensureValidToken(){if(!this.tokenCache.token)return await this.getToken();if(this.isTokenExpired()){const e=A("token 已过期,正在刷新...").start();try{const t=await this.refreshToken();return P("token 刷新成功。",e),t}catch(t){throw L("token 刷新失败。",e),t}}return this.tokenCache.token}async uploadFile(e,t={}){const s=await this.ensureValidToken();if(!e||"string"!=typeof e)throw new Error(`文件路径无效: ${e}`);if(!g.existsSync(e))throw new Error(`文件不存在: ${e}`);const o=g.statSync(e);if(!o.isFile())throw new Error(`路径不是文件: ${e}`);const i=t.maxSize||5242880;if(o.size>i){const e=(o.size/1024/1024).toFixed(2),t=(i/1024/1024).toFixed(2);throw new Error(`文件大小超过限制: ${e}MB > ${t}MB`)}if(0===o.size)throw new Error(`文件为空: ${e}`);const r=w.basename(e),n=(o.size/1024).toFixed(2),a=A(`正在上传文件: ${r} (${n}KB)...`).start();try{const o=new y,i=t.fieldName||"customComponentCode",n=g.createReadStream(e);o.append(i,n,r);const c=this.uploadAPI(),l=t.timeout||6e4,h={headers:{Authorization:`Bearer ${s}`,"xsy-inner-source":"bff",...o.getHeaders()},timeout:l,maxContentLength:1/0,maxBodyLength:1/0},d=await f.post(c,o,h);let u;const p=d.data;if(200!==d.status&&201!==d.status)throw new Error(`上传失败: HTTP ${d.status}`);if("string"==typeof p)u=p.trim();else{if(!p||"object"!=typeof p)throw new Error("响应数据格式不正确: "+typeof p);if(void 0!==p.code&&200!==p.code&&0!==p.code){const e=p.message||p.msg||"未知错误";throw new Error(`上传失败: ${e} (code: ${p.code})`)}u=void 0!==p.data?p.data:void 0!==p.url?p.url:void 0!==p.fileUrl?p.fileUrl:p}if(!u)throw new Error("返回的文件地址为空");let m;return"string"==typeof u?m=u:u&&"object"==typeof u&&u.url&&(m=u.url),P(`文件上传成功: ${r} -> ${m}`,a),m}catch(t){if(L(`上传文件失败: ${t.message||t.msg}, 文件路径: ${e}`,a),t.response){const e=t.response.status,s=t.response.statusText,o=t.response.data,i=t.config?.url||this.uploadAPI();if(L("\n========== 上传请求详情 =========="),L(`请求 URL: ${i}`),L(`HTTP 状态码: ${e} ${s}`),L(`响应数据: ${JSON.stringify(o)}`),L("==================================\n"),404===e)throw new Error(`上传 API 不存在 (404): ${i}\n请检查 neo.config.js 中的 neoBaseURL 配置是否正确,或者 API 路径是否存在。\n当前配置的 API 路径: ${this.NeoCrmAPI.uploadAPI}`)}else t.request&&L("请求已发送但未收到响应,请检查网络连接或代理配置。");throw t}}async publish2oss(e,t=[".js",".css",".zip"]){if(!e)return void L(`自定义组件名称不能为空: ${e}`);if(!g.existsSync(this.assetsRoot))return void L(`未找到自定义组件资源目录: ${this.assetsRoot}`);const s={cmpType:e},o=g.readdirSync(this.assetsRoot).map(async o=>{const i=w.join(this.assetsRoot,o),r=g.statSync(i),n=w.parse(i);if(r.isFile()&&t.includes(n.ext)){let t=$.camelCase(e);if(o.indexOf(t)<0)return;try{const e=await this.uploadFile(i);o.indexOf("Model")>-1?s.modelAsset=e:o.endsWith(".css")?s.cssAsset=e:o.endsWith(".zip")?s.codeLib=e:s.asset=e}catch(e){L(`文件上传失败(${o}):\n`),process.exit(1)}}});return await Promise.all(o),s&&s.cmpType&&(console.info("上传至 OSS 的文件信息:\n",s),T(s)),s}async getCmpAssets(e,t=[".js",".css",".zip"]){if(!e)return void L(`自定义组件名称不能为空: ${e}`);if(!g.existsSync(this.assetsRoot))return void L(`未找到自定义组件资源目录: ${this.assetsRoot}`);const s={cmpType:e};return g.readdirSync(this.assetsRoot).forEach(o=>{const i=w.join(this.assetsRoot,o),r=g.statSync(i),n=w.parse(i);if(r.isFile()&&t.includes(n.ext)){let t=$.camelCase(e);if(o.indexOf(t)<0)return;const n=5242880;if(r.size>n){const e=(r.size/1024/1024).toFixed(2),t=(n/1024/1024).toFixed(2);throw new Error(`${o} 文件大小超过限制: ${e}MB > ${t}MB`)}const a=g.readFileSync(i),c=k.createHash("md5").update(a).digest("hex").substring(0,8),l={fileContent:g.createReadStream(i),fileName:`${c}-${o}`,fileSize:r.size};o.indexOf("Model")>-1?s.modelAssetFile=l:o.endsWith(".css")?s.cssAssetFile=l:o.endsWith(".zip")?s.codeLibFile=l:s.assetFile=l}}),s}async updateCustomComponent(e){const t=await this.ensureValidToken();if(!e)throw new Error("componentData 不能为空");const s=A("正在保存自定义组件信息...").start();try{const o=this.saveAPI(),i=new y;e.assetFile&&i.append("assetFile",e.assetFile.fileContent,e.assetFile.fileName),e.modelAssetFile&&i.append("modelAssetFile",e.modelAssetFile.fileContent,e.modelAssetFile.fileName),e.cssAssetFile&&i.append("cssAssetFile",e.cssAssetFile.fileContent,e.cssAssetFile.fileName),e.codeLibFile&&i.append("codeLibFile",e.codeLibFile.fileContent,e.codeLibFile.fileName),i.append("component",JSON.stringify($.omit(e,["assetFile","modelAssetFile","cssAssetFile","codeLibFile"])));const r=await f.post(o,i,{headers:{Authorization:`Bearer ${t}`,"xsy-inner-source":"bff",...i.getHeaders()},timeout:12e4,maxContentLength:1/0,maxBodyLength:1/0}),{code:n,message:a,msg:c}=r.data||{};n&&200!==n&&(L(`保存自定义组件信息失败: ${a||c||"未知错误"}`),process.exit(1)),s.clear(),s.stop()}catch(e){const t=e.message||e.msg;L(t?`保存自定义组件信息失败: ${t}`:`保存自定义组件信息失败: ${JSON.stringify(e)}`,s),process.exit(1)}}async getCustomCmpList(){const e=await this.ensureValidToken();try{let t=this.buildFullUrl(this.NeoCrmAPI.queryAll);t+=`&fields=${S.join(",")}`;const s=await f.get(t,{headers:{Authorization:`Bearer ${e}`,"xsy-inner-source":"bff","Content-Type":"application/json"}}),{code:o,message:i,msg:r}=s.data||{};o&&200!==o&&(L(`获取自定义组件列表失败: ${i||r||"未知错误"}`),process.exit(1)),this.updateCustomCmpList(s.data.data||[])}catch(e){const t=e.message||e.msg;L(t?`获取自定义组件列表失败: ${t}`:`响应数据: ${JSON.stringify(e)}`),process.exit(1)}return this.cmpList||[]}getCodeLibByCmpType(e){return e?this.buildFullUrl(this.NeoCrmAPI.getCodeLibAPI(e)):null}async deleteCmp(e){const t=await this.ensureValidToken();e||(L("自定义组件名称不能为空。"),process.exit(1));let s=this.buildFullUrl(this.NeoCrmAPI.delete);s+=`/${e}`;const o=await f.delete(s,{headers:{Authorization:`Bearer ${t}`,"xsy-inner-source":"bff","Content-Type":"application/json"}}),{code:i,message:r,msg:n,errorInfo:a}=o.data||{};return i&&200!==i&&(a&&a.length>0?I(a,{title:"删除自定义组件失败",columns:["reason","instance"],headers:{reason:"原因",instance:"实例"},align:{reason:"center",instance:"center"},padding:2,showBorder:!0}):L(`删除自定义组件失败: ${r||n||"未知错误"}`),process.exit(1)),o.data}getCmpListByFramework(e){if(!e)return this.cmpList;const t=F(e);return this.cmpList.filter(e=>e.framework===t)}getCmpInfoByCmpType(e){return e&&this.cmpInfoMap[e]||null}updateCustomCmpList(e){e&&Array.isArray(e)&&(this.cmpList=e,e.forEach(e=>{this.cmpInfoMap[e.cmpType]=e}))}async request(e,t,s={}){const o=await this.ensureValidToken(),{data:i,headers:r={},params:n}=s,a=this.buildFullUrl(t);try{const t=await f({method:e,url:a,data:i,params:n,headers:{Authorization:`Bearer ${o}`,"xsy-inner-source":"bff",...r}});if(t.data&&t.data.code&&200!==t.data.code)throw new Error(`请求失败: ${t.data.message||t.data.msg||"未知错误"}`);return t.data}catch(s){throw L(`请求失败 [${e} ${t}]: ${s.message||s.msg}`),s.response&&L(`响应数据: ${JSON.stringify(s.response.data)}`),s}}async get(e,t={}){return await this.request("GET",e,t)}async post(e,t={}){return await this.request("POST",e,t)}async put(e,t={}){return await this.request("PUT",e,t)}async delete(e,t={}){return await this.request("DELETE",e,t)}}};
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("axios"),t=require("form-data"),s=require("node:fs"),i=require("node:path"),o=require("node:crypto"),r=require("ora"),n=require("lodash"),a=require("akfun"),c=require("./neoLogin.js"),h=require("../utils/projectUtils/updatePublishLog.js"),l=require("../utils/common.js"),u=require("./neoEnvManager.js"),d=require("../utils/tableLog.js");var p,m;exports.__require=function(){if(m)return p;m=1;const f=e,y=t,g=s,w=i,k=o,A=r,$=n,{resolve:C}=a,x=c.__require(),T=h.__require(),{getFramework:F,errorLog:L,successLog:P}=l.__require(),b=u.__require(),{tableLog:I}=d.__require();return p=class{constructor(){const e=b.getEnvConfig(),{assetsRoot:t,auth:s,authType:i}=e||{};this.authType=i||"oauth2",this.NeoCrmAPI=e,"password"!==this.authType||s||(L("密码授权模式时,neo.config.js / neoConfig / auth 配置不能为空"),process.exit(1)),"password"===this.authType?s.client_id&&s.client_secret&&s.username&&s.password||(L("neo.config.js / neoConfig / auth 配置不完整(password 模式),需要包含 client_id、client_secret、username、password"),process.exit(1)):"oauth2"!=this.authType&&(L(`不支持的授权类型: ${this.authType},可选值:oauth2、password`),process.exit(1)),this.assetsRoot=t||C("dist"),this.auth=s,this.cmpList=[],this.cmpInfoMap={},this.tokenCache={token:null,expiresAt:null}}buildFullUrl(e){return e.startsWith("http://")||e.startsWith("https://")?e:`${this.NeoCrmAPI.neoBaseURL}${e}`}uploadAPI(){return this.buildFullUrl(this.NeoCrmAPI.uploadAPI)}saveAPI(){return this.buildFullUrl(this.NeoCrmAPI.saveAPI)}isTokenExpired(){return!this.tokenCache.token||!this.tokenCache.expiresAt||Date.now()>=this.tokenCache.expiresAt}async getToken(){return this.isTokenExpired()?"oauth2"===this.authType?await this.getTokenByOAuth2():await this.getTokenByPassword():this.tokenCache.token}async getTokenByPassword(){const e=A("获取 token(密码模式)...").start();if(!this.isTokenExpired())return P("使用缓存的 token。",e),this.tokenCache.token;const t=new URLSearchParams;t.append("grant_type","password"),t.append("client_id",this.auth.client_id),t.append("client_secret",this.auth.client_secret),t.append("username",this.auth.username),t.append("password",this.auth.password);const s=this.buildFullUrl(this.NeoCrmAPI.tokenURL);try{const i=await f.post(s,t.toString(),{headers:{"Content-Type":"application/x-www-form-urlencoded"}}),o=i.data||{},{access_token:r,expires_in:n}=o;r||(L("获取 token 失败(授权配置错误):响应中未包含 access_token,"+JSON.stringify(i.data),e),process.exit(1));const a=parseInt(n)||3600;return this.tokenCache={...o,token:r,expiresAt:Date.now()+1e3*(a-60)},e.clear(),e.stop(),r}catch(i){L("获取 token 失败",e),L(`\n获取 token 失败: ${i.message||i.msg}`),L(`\ntoken 授权地址: ${s}`),L(`\ntoken 请求参数: ${t}`),i.response&&L(`响应数据: ${JSON.stringify(i.response.data)}`),process.exit(1)}}async getTokenByOAuth2(){const e=A("获取 token(OAuth2 模式)...").start();try{const t={neoBaseURL:this.NeoCrmAPI.neoBaseURL,loginURL:this.NeoCrmAPI.loginURL,tokenURL:this.NeoCrmAPI.tokenURL},s=new x(t),i=await s.getAccessToken(),o=i.access_token;return this.tokenCache={...i,token:o,expiresAt:Date.now()+72e5},e.clear(),e.stop(),o}catch(t){L("获取 token 失败(OAuth2 模式)",e),L(`\n获取 token 失败: ${t.message||t.msg}`),t.response&&L(`响应数据: ${JSON.stringify(t.response.data)}`),process.exit(1)}}async refreshToken(){return this.tokenCache={token:null,expiresAt:null},await this.getToken()}async ensureValidToken(){if(!this.tokenCache.token)return await this.getToken();if(this.isTokenExpired()){const e=A("token 已过期,正在刷新...").start();try{const t=await this.refreshToken();return P("token 刷新成功。",e),t}catch(t){throw L("token 刷新失败。",e),t}}return this.tokenCache.token}async uploadFile(e,t={}){const s=await this.ensureValidToken();if(!e||"string"!=typeof e)throw new Error(`文件路径无效: ${e}`);if(!g.existsSync(e))throw new Error(`文件不存在: ${e}`);const i=g.statSync(e);if(!i.isFile())throw new Error(`路径不是文件: ${e}`);const o=t.maxSize||5242880;if(i.size>o){const e=(i.size/1024/1024).toFixed(2),t=(o/1024/1024).toFixed(2);throw new Error(`文件大小超过限制: ${e}MB > ${t}MB`)}if(0===i.size)throw new Error(`文件为空: ${e}`);const r=w.basename(e),n=(i.size/1024).toFixed(2),a=A(`正在上传文件: ${r} (${n}KB)...`).start();try{const i=new y,o=t.fieldName||"customComponentCode",n=g.createReadStream(e);i.append(o,n,r);const c=this.uploadAPI(),h=t.timeout||6e4,l={headers:{Authorization:`Bearer ${s}`,"xsy-inner-source":"bff",...i.getHeaders()},timeout:h,maxContentLength:1/0,maxBodyLength:1/0},u=await f.post(c,i,l);let d;const p=u.data;if(200!==u.status&&201!==u.status)throw new Error(`上传失败: HTTP ${u.status}`);if("string"==typeof p)d=p.trim();else{if(!p||"object"!=typeof p)throw new Error("响应数据格式不正确: "+typeof p);if(void 0!==p.code&&200!==p.code&&0!==p.code){const e=p.message||p.msg||"未知错误";throw new Error(`上传失败: ${e} (code: ${p.code})`)}d=void 0!==p.data?p.data:void 0!==p.url?p.url:void 0!==p.fileUrl?p.fileUrl:p}if(!d)throw new Error("返回的文件地址为空");let m;return"string"==typeof d?m=d:d&&"object"==typeof d&&d.url&&(m=d.url),P(`文件上传成功: ${r} -> ${m}`,a),m}catch(t){if(L(`上传文件失败: ${t.message||t.msg}, 文件路径: ${e}`,a),t.response){const e=t.response.status,s=t.response.statusText,i=t.response.data,o=t.config?.url||this.uploadAPI();if(L("\n========== 上传请求详情 =========="),L(`请求 URL: ${o}`),L(`HTTP 状态码: ${e} ${s}`),L(`响应数据: ${JSON.stringify(i)}`),L("==================================\n"),404===e)throw new Error(`上传 API 不存在 (404): ${o}\n请检查 neo.config.js 中的 neoBaseURL 配置是否正确,或者 API 路径是否存在。\n当前配置的 API 路径: ${this.NeoCrmAPI.uploadAPI}`)}else t.request&&L("请求已发送但未收到响应,请检查网络连接或代理配置。");throw t}}async publish2oss(e,t=[".js",".css",".zip"]){if(!e)return void L(`自定义组件名称不能为空: ${e}`);if(!g.existsSync(this.assetsRoot))return void L(`未找到自定义组件资源目录: ${this.assetsRoot}`);const s={cmpType:e},i=g.readdirSync(this.assetsRoot).map(async i=>{const o=w.join(this.assetsRoot,i),r=g.statSync(o),n=w.parse(o);if(r.isFile()&&t.includes(n.ext)){let t=$.camelCase(e);if(i.indexOf(t)<0)return;try{const e=await this.uploadFile(o);i.indexOf("Model")>-1?s.modelAsset=e:i.endsWith(".css")?s.cssAsset=e:i.endsWith(".zip")?s.codeLib=e:s.asset=e}catch(e){L(`文件上传失败(${i}):\n`),process.exit(1)}}});return await Promise.all(i),s&&s.cmpType&&(console.info("上传至 OSS 的文件信息:\n",s),T(s)),s}async getCmpAssets(e,t=[".js",".css",".zip"]){if(!e)return void L(`自定义组件名称不能为空: ${e}`);if(!g.existsSync(this.assetsRoot))return void L(`未找到自定义组件资源目录: ${this.assetsRoot}`);const s={cmpType:e};return g.readdirSync(this.assetsRoot).forEach(i=>{const o=w.join(this.assetsRoot,i),r=g.statSync(o),n=w.parse(o);if(r.isFile()&&t.includes(n.ext)){let t=$.camelCase(e);if(i.indexOf(t)<0)return;const n=5242880;if(r.size>n){const e=(r.size/1024/1024).toFixed(2),t=(n/1024/1024).toFixed(2);throw new Error(`${i} 文件大小超过限制: ${e}MB > ${t}MB`)}const a=g.readFileSync(o),c=k.createHash("md5").update(a).digest("hex").substring(0,8),h={fileContent:g.createReadStream(o),fileName:`${c}-${i}`,fileSize:r.size};i.indexOf("Model")>-1?s.modelAssetFile=h:i.endsWith(".css")?s.cssAssetFile=h:i.endsWith(".zip")?s.codeLibFile=h:s.assetFile=h}}),s}async updateCustomComponent(e){const t=await this.ensureValidToken();if(!e)throw new Error("componentData 不能为空");const s=A("正在保存自定义组件信息...").start();try{const i=this.saveAPI(),o=new y;e.assetFile&&o.append("assetFile",e.assetFile.fileContent,e.assetFile.fileName),e.modelAssetFile&&o.append("modelAssetFile",e.modelAssetFile.fileContent,e.modelAssetFile.fileName),e.cssAssetFile&&o.append("cssAssetFile",e.cssAssetFile.fileContent,e.cssAssetFile.fileName),e.codeLibFile&&o.append("codeLibFile",e.codeLibFile.fileContent,e.codeLibFile.fileName),o.append("component",JSON.stringify($.omit(e,["assetFile","modelAssetFile","cssAssetFile","codeLibFile"])));const r=await f.post(i,o,{headers:{Authorization:`Bearer ${t}`,"xsy-inner-source":"bff",...o.getHeaders()},timeout:12e4,maxContentLength:1/0,maxBodyLength:1/0}),{code:n,message:a,msg:c}=r.data||{};n&&200!==n&&(L(`保存自定义组件信息失败: ${a||c||"未知错误"}`),process.exit(1)),s.clear(),s.stop()}catch(e){const t=e.message||e.msg;L(t?`保存自定义组件信息失败: ${t}`:`保存自定义组件信息失败: ${JSON.stringify(e)}`,s),process.exit(1)}}async getCustomCmpList(){const e=await this.ensureValidToken();try{let t=this.buildFullUrl(this.NeoCrmAPI.queryAll);const s=await f.post(t,{pageNo:1,pageSize:1e3},{headers:{Authorization:`Bearer ${e}`,"xsy-inner-source":"bff","Content-Type":"application/json"}}),{code:i,message:o,msg:r}=s.data||{};i&&200!==i&&(L(`获取自定义组件列表失败: ${o||r||"未知错误"}`),process.exit(1)),this.updateCustomCmpList(s.data.data||[])}catch(e){const t=e.message||e.msg;L(t?`获取自定义组件列表失败: ${t}`:`响应数据: ${JSON.stringify(e)}`),process.exit(1)}return this.cmpList||[]}getCodeLibByCmpType(e){return e?this.buildFullUrl(this.NeoCrmAPI.getCodeLibAPI(e)):null}async deleteCmp(e){const t=await this.ensureValidToken();e||(L("自定义组件名称不能为空。"),process.exit(1));let s=this.buildFullUrl(this.NeoCrmAPI.delete);s+=`/${e}`;const i=await f.delete(s,{headers:{Authorization:`Bearer ${t}`,"xsy-inner-source":"bff","Content-Type":"application/json"}}),{code:o,message:r,msg:n,errorInfo:a}=i.data||{};return o&&200!==o&&(a&&a.length>0?I(a,{title:"删除自定义组件失败",columns:["reason","instance"],headers:{reason:"原因",instance:"实例"},align:{reason:"center",instance:"center"},padding:2,showBorder:!0}):L(`删除自定义组件失败: ${r||n||"未知错误"}`),process.exit(1)),i.data}getCmpListByFramework(e){if(!e)return this.cmpList;const t=F(e);return this.cmpList.filter(e=>e.framework===t)}getCmpInfoByCmpType(e){return e&&this.cmpInfoMap[e]||null}updateCustomCmpList(e){e&&Array.isArray(e)&&(this.cmpList=e,e.forEach(e=>{this.cmpInfoMap[e.cmpType]=e}))}async request(e,t,s={}){const i=await this.ensureValidToken(),{data:o,headers:r={},params:n}=s,a=this.buildFullUrl(t);try{const t=await f({method:e,url:a,data:o,params:n,headers:{Authorization:`Bearer ${i}`,"xsy-inner-source":"bff",...r}});if(t.data&&t.data.code&&200!==t.data.code)throw new Error(`请求失败: ${t.data.message||t.data.msg||"未知错误"}`);return t.data}catch(s){throw L(`请求失败 [${e} ${t}]: ${s.message||s.msg}`),s.response&&L(`响应数据: ${JSON.stringify(s.response.data)}`),s}}async get(e,t={}){return await this.request("GET",e,t)}async post(e,t={}){return await this.request("POST",e,t)}async put(e,t={}){return await this.request("PUT",e,t)}async delete(e,t={}){return await this.request("DELETE",e,t)}}};
|
package/dist/package.json.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var e="1.11.
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var e="1.11.2";const o={version:e};exports.default=o,exports.version=e;
|
package/package.json
CHANGED