neo-cmp-cli 1.8.6-beta.6 → 1.8.7

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.
Files changed (158) hide show
  1. package/bin/index.js +2 -2
  2. package/package.json +3 -3
  3. package/src/config/auth.config.js +27 -0
  4. package/src/config/default.config.js +176 -0
  5. package/src/config/index.js +9 -0
  6. package/src/initData/defaultTemplate.html +13 -0
  7. package/src/initData/neo.config.js +138 -0
  8. package/src/main.js +221 -0
  9. package/src/module/inspect.js +41 -0
  10. package/src/module/neoInit.js +55 -0
  11. package/src/module/neoInitByCopy.js +61 -0
  12. package/src/neo/NeoUMDContent.js +30 -0
  13. package/src/neo/neoLogin.js +565 -0
  14. package/src/neo/neoRequire.js +125 -0
  15. package/src/neo/neoService.js +874 -0
  16. package/src/neo/webpack.mf.js +60 -0
  17. package/src/neo/wrapperContent.js +16 -0
  18. package/src/oss/publish2oss.js +348 -0
  19. package/src/plugins/AddNeoRequirePlugin-v1.js +47 -0
  20. package/src/plugins/AddNeoRequirePlugin.js +179 -0
  21. package/src/plugins/README.md +109 -0
  22. package/src/utils/autoEntryRootDir.js +85 -0
  23. package/src/utils/cmpUtils/createCmpByTemplate.js +60 -0
  24. package/src/utils/cmpUtils/createCmpByZip.js +408 -0
  25. package/src/utils/cmpUtils/createCommonModulesCode.js +121 -0
  26. package/src/utils/cmpUtils/deleteCmp.js +63 -0
  27. package/src/utils/cmpUtils/getCmpModelRegisterCode.js +31 -0
  28. package/src/utils/cmpUtils/getCmpPreviewCode.js +43 -0
  29. package/src/utils/cmpUtils/getCmpRegisterCode.js +31 -0
  30. package/src/utils/cmpUtils/getCmpTypeByDir.js +41 -0
  31. package/src/utils/cmpUtils/hasCmpTypeByDir.js +11 -0
  32. package/src/utils/cmpUtils/previewCmp.js +55 -0
  33. package/src/utils/cmpUtils/pullCmp.js +104 -0
  34. package/src/utils/cmpUtils/pushCmp.js +230 -0
  35. package/src/utils/common.js +107 -0
  36. package/src/utils/configureNeoBuild.js +109 -0
  37. package/src/utils/generateEntries.js +63 -0
  38. package/src/utils/neoConfigInit.js +13 -0
  39. package/src/utils/neoParams.js +12 -0
  40. package/src/utils/pathUtils.js +23 -0
  41. package/src/utils/projectNameValidator.js +76 -0
  42. package/src/utils/projectUtils/createCmpProjectByTemplate.js +59 -0
  43. package/src/utils/projectUtils/createCmpProjectZip.js +120 -0
  44. package/src/utils/projectUtils/getEntries.js +80 -0
  45. package/src/utils/projectUtils/getEntriesWithAutoRegister.js +108 -0
  46. package/src/utils/projectUtils/hasNeoProject.js +17 -0
  47. package/src/utils/projectUtils/openProject.js +96 -0
  48. package/src/utils/projectUtils/updatePublishLog.js +30 -0
  49. package/src/utils/replaceInFiles.js +47 -0
  50. package/src/utils/replaceInFilesByMap.js +54 -0
  51. package/src/utils/replaceInPackage.js +134 -0
  52. package/src/utils/resetPackageVersion.js +115 -0
  53. package/test/deprecate-versions.js +1 -1
  54. package/test/neo.config.js +1 -25
  55. package/dist/_virtual/AddNeoRequirePlugin.js +0 -8
  56. package/dist/_virtual/OverloadYield.js +0 -5
  57. package/dist/_virtual/_commonjsHelpers.js +0 -40
  58. package/dist/_virtual/array-set.js +0 -5
  59. package/dist/_virtual/base64-vlq.js +0 -5
  60. package/dist/_virtual/base64.js +0 -5
  61. package/dist/_virtual/binary-search.js +0 -5
  62. package/dist/_virtual/createCmpByZip.js +0 -8
  63. package/dist/_virtual/deleteCmp.js +0 -8
  64. package/dist/_virtual/index.js +0 -9
  65. package/dist/_virtual/mapping-list.js +0 -5
  66. package/dist/_virtual/neoLogin.js +0 -8
  67. package/dist/_virtual/neoService.js +0 -8
  68. package/dist/_virtual/openProject.js +0 -8
  69. package/dist/_virtual/publish2oss.js +0 -8
  70. package/dist/_virtual/pullCmp.js +0 -8
  71. package/dist/_virtual/pushCmp.js +0 -8
  72. package/dist/_virtual/quick-sort.js +0 -5
  73. package/dist/_virtual/regenerator.js +0 -5
  74. package/dist/_virtual/regeneratorAsync.js +0 -5
  75. package/dist/_virtual/regeneratorAsyncGen.js +0 -5
  76. package/dist/_virtual/regeneratorAsyncIterator.js +0 -5
  77. package/dist/_virtual/regeneratorDefine.js +0 -5
  78. package/dist/_virtual/regeneratorKeys.js +0 -5
  79. package/dist/_virtual/regeneratorRuntime.js +0 -5
  80. package/dist/_virtual/regeneratorValues.js +0 -5
  81. package/dist/_virtual/source-map-consumer.js +0 -5
  82. package/dist/_virtual/source-map-generator.js +0 -5
  83. package/dist/_virtual/source-map-support.js +0 -5
  84. package/dist/_virtual/source-map.js +0 -5
  85. package/dist/_virtual/source-node.js +0 -5
  86. package/dist/_virtual/typeof.js +0 -5
  87. package/dist/_virtual/typescript.js +0 -5
  88. package/dist/_virtual/util.js +0 -5
  89. package/dist/config/auth.config.js +0 -50
  90. package/dist/config/default.config.js +0 -225
  91. package/dist/config/index.js +0 -27
  92. package/dist/main.js +0 -9
  93. package/dist/main2.js +0 -261
  94. package/dist/module/inspect.js +0 -64
  95. package/dist/module/neoInit.js +0 -69
  96. package/dist/module/neoInitByCopy.js +0 -81
  97. package/dist/neo/neoLogin.js +0 -663
  98. package/dist/neo/neoRequire.js +0 -118
  99. package/dist/neo/neoService.js +0 -1246
  100. package/dist/node_modules/@babel/runtime/helpers/OverloadYield.js +0 -19
  101. package/dist/node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js +0 -29
  102. package/dist/node_modules/@babel/runtime/helpers/esm/extends.js +0 -13
  103. package/dist/node_modules/@babel/runtime/helpers/regenerator.js +0 -105
  104. package/dist/node_modules/@babel/runtime/helpers/regeneratorAsync.js +0 -24
  105. package/dist/node_modules/@babel/runtime/helpers/regeneratorAsyncGen.js +0 -23
  106. package/dist/node_modules/@babel/runtime/helpers/regeneratorAsyncIterator.js +0 -50
  107. package/dist/node_modules/@babel/runtime/helpers/regeneratorDefine.js +0 -37
  108. package/dist/node_modules/@babel/runtime/helpers/regeneratorKeys.js +0 -25
  109. package/dist/node_modules/@babel/runtime/helpers/regeneratorRuntime.js +0 -98
  110. package/dist/node_modules/@babel/runtime/helpers/regeneratorValues.js +0 -35
  111. package/dist/node_modules/@babel/runtime/helpers/typeof.js +0 -25
  112. package/dist/node_modules/@babel/runtime/regenerator/index.js +0 -29
  113. package/dist/node_modules/buffer-from/index.js +0 -57
  114. package/dist/node_modules/source-map/lib/array-set.js +0 -134
  115. package/dist/node_modules/source-map/lib/base64-vlq.js +0 -144
  116. package/dist/node_modules/source-map/lib/base64.js +0 -81
  117. package/dist/node_modules/source-map/lib/binary-search.js +0 -122
  118. package/dist/node_modules/source-map/lib/mapping-list.js +0 -94
  119. package/dist/node_modules/source-map/lib/quick-sort.js +0 -126
  120. package/dist/node_modules/source-map/lib/source-map-consumer.js +0 -1018
  121. package/dist/node_modules/source-map/lib/source-map-generator.js +0 -385
  122. package/dist/node_modules/source-map/lib/source-node.js +0 -400
  123. package/dist/node_modules/source-map/lib/util.js +0 -449
  124. package/dist/node_modules/source-map/source-map.js +0 -25
  125. package/dist/node_modules/source-map-support/source-map-support.js +0 -610
  126. package/dist/node_modules/typescript/lib/typescript.js +0 -22376
  127. package/dist/oss/publish2oss.js +0 -378
  128. package/dist/plugins/AddNeoRequirePlugin.js +0 -178
  129. package/dist/utils/autoEntryRootDir.js +0 -98
  130. package/dist/utils/cmpUtils/createCmpByTemplate.js +0 -73
  131. package/dist/utils/cmpUtils/createCmpByZip.js +0 -530
  132. package/dist/utils/cmpUtils/createCommonModulesCode.js +0 -84
  133. package/dist/utils/cmpUtils/deleteCmp.js +0 -98
  134. package/dist/utils/cmpUtils/getCmpModelRegisterCode.js +0 -38
  135. package/dist/utils/cmpUtils/getCmpPreviewCode.js +0 -37
  136. package/dist/utils/cmpUtils/getCmpRegisterCode.js +0 -38
  137. package/dist/utils/cmpUtils/getCmpTypeByDir.js +0 -58
  138. package/dist/utils/cmpUtils/hasCmpTypeByDir.js +0 -25
  139. package/dist/utils/cmpUtils/previewCmp.js +0 -74
  140. package/dist/utils/cmpUtils/pullCmp.js +0 -144
  141. package/dist/utils/cmpUtils/pushCmp.js +0 -290
  142. package/dist/utils/common.js +0 -121
  143. package/dist/utils/configureNeoBuild.js +0 -153
  144. package/dist/utils/generateEntries.js +0 -73
  145. package/dist/utils/neoConfigInit.js +0 -25
  146. package/dist/utils/neoParams.js +0 -23
  147. package/dist/utils/pathUtils.js +0 -48
  148. package/dist/utils/projectNameValidator.js +0 -89
  149. package/dist/utils/projectUtils/createCmpProjectByTemplate.js +0 -74
  150. package/dist/utils/projectUtils/createCmpProjectZip.js +0 -135
  151. package/dist/utils/projectUtils/getEntries.js +0 -99
  152. package/dist/utils/projectUtils/getEntriesWithAutoRegister.js +0 -127
  153. package/dist/utils/projectUtils/hasNeoProject.js +0 -31
  154. package/dist/utils/projectUtils/openProject.js +0 -169
  155. package/dist/utils/projectUtils/updatePublishLog.js +0 -45
  156. package/dist/utils/replaceInFilesByMap.js +0 -70
  157. package/dist/utils/replaceInPackage.js +0 -151
  158. package/dist/utils/resetPackageVersion.js +0 -134
package/bin/index.js CHANGED
@@ -16,8 +16,8 @@ const {
16
16
  consoleTag,
17
17
  errorLog,
18
18
  successLog
19
- } = require('../dist/main.js');
20
- const mainAction = require('../dist/main.js'); // 构建方法
19
+ } = require('../src/main.js');
20
+ const mainAction = require('../src/main.js'); // 构建方法
21
21
  // neo 的 package 文件
22
22
  const neoPackage = require('../package.json');
23
23
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "neo-cmp-cli",
3
- "version": "1.8.6-beta.6",
3
+ "version": "1.8.7",
4
4
  "description": "Neo 自定义组件开发工具,支持react 和 vue2.0技术栈。",
5
5
  "keywords": [
6
6
  "neo-cli",
@@ -12,7 +12,7 @@
12
12
  "neo": "./bin/neo.js",
13
13
  "build2esm": "neo build2esm"
14
14
  },
15
- "main": "dist/main.js",
15
+ "main": "src/main.js",
16
16
  "scripts": {
17
17
  "neo": "neo",
18
18
  "build2esm": "neo build2esm",
@@ -20,7 +20,7 @@
20
20
  },
21
21
  "files": [
22
22
  "bin/*",
23
- "dist/*",
23
+ "src/*",
24
24
  "template/*",
25
25
  "test/*"
26
26
  ],
@@ -0,0 +1,27 @@
1
+ const curConfig = require('../config/index'); // 获取当前项目根目录下的配置文件
2
+
3
+ const neoConfig = curConfig.neoConfig || {};
4
+ // const authConfig = neoConfig.auth || {};
5
+
6
+ // NeoCRM 跨 Pod 授权配置
7
+ module.exports = {
8
+ loginURL: neoConfig.loginURL || 'https://login-cd.xiaoshouyi.com/auc/oauth2/auth', // 登录 URL,从创建连接器的客户端信息中获取(Login_Url)
9
+ tokenAPI: neoConfig.tokenAPI || 'https://login-cd.xiaoshouyi.com/auc/oauth2/token', // Token 获取接口地址(默认:https://login.xiaoshouyi.com/auc/oauth2/token)
10
+ redirectUri: neoConfig.redirectUri || 'http://localhost:1028', // 固定端口号,用于接收授权码
11
+ // 重定向 URI,动态生成
12
+ getRedirectURI: (port) => {
13
+ return `http://localhost:${port}`;
14
+ },
15
+ // 获取 授权码 相关配置
16
+ response_type: 'code', // 认证类型;此参数值必须为 code
17
+ // client_id: authConfig.client_id || '04c8b45c4dbe36426a660bf70d3fe3e7', // 客户端 ID,跨 Pod 级链接器【内置】
18
+ client_id: '04c8b45c4dbe36426a660bf70d3fe3e7', // 客户端 ID,跨 Pod 级链接器【内置】
19
+ scope: 'all', // 固定值:all
20
+ oauthType: 'standard', // 固定值:standard
21
+ access_type: 'offline', // 此参数值为 online 时,不产生 refresh_token ;此参数值为 offline 时,返回refresh_token
22
+
23
+ // 获取 令牌 相关配置
24
+ // client_secret: authConfig.client_secret || '370817d1336a3737f95c671eea39a23b', // 客户端秘钥,跨 Pod 级链接器【内置】
25
+ client_secret: '370817d1336a3737f95c671eea39a23b', // 客户端秘钥,跨 Pod 级链接器【内置】
26
+ grant_type: 'authorization_code' // 授权类型;此参数值必须为 authorization_code
27
+ };
@@ -0,0 +1,176 @@
1
+ 'use strict';
2
+ // 统一路径解析:
3
+ const { resolve } = require('akfun');
4
+ const path = require('path'); // 以命令执行目录为根目录
5
+
6
+ // 当前neo的路径解析(用于获取neo-cmp-cli本身的文件地址)
7
+ function resolveByDirname(dir) {
8
+ return path.resolve(__dirname, dir);
9
+ }
10
+
11
+ /**
12
+ * 脚手架赋予当前项目的默认配置
13
+ */
14
+ const defaultNEOConfig = {
15
+ settings: {
16
+ enableESLint: false, // 是否开启ESLint,默认开启ESLint检测代码格式
17
+ enableESLintFix: false, // 是否ESLint自动修正代码格式
18
+ enableStyleLint: false, // 是否开启StyleLint,默认开启ESLint检测代码格式
19
+ enableStyleLintFix: false // 是否需要StyleLint自动修正代码格式
20
+ },
21
+ webpack: {
22
+ resolve: {
23
+ // webpack的resolve配置
24
+ extensions: ['.js', '.jsx', '.ts', '.tsx', '.vue', '.min.js', '.json'], // 用于配置webpack在尝试过程中用到的后缀列表
25
+ alias: {
26
+ '@': resolve('src')
27
+ }
28
+ },
29
+ createDeclaration: false, // 打包时是否创建ts声明文件
30
+ ignoreNodeModules: false, // 打包时是否忽略 node_modules
31
+ allowList: [], // ignoreNodeModules为true时生效
32
+ externals: {}, // 从输出的 bundle 中排除依赖
33
+ projectDir: ['src'],
34
+ template: resolveByDirname('../initData/defaultTemplate.html'), // 默认使用neo-widget提供的页面模板(会启动页面设计器)
35
+ sassResources: [],
36
+ babelPlugins: [
37
+ ['import', { libraryName: 'antd', style: 'css' }] // 配置 antd 的样式按需引入
38
+ ]
39
+ },
40
+ envParams: {
41
+ // 项目系统环境变量
42
+ common: {
43
+ // 通用参数
44
+ '#version#': '20221229.1'
45
+ },
46
+ local: {
47
+ // 本地开发环境
48
+ '#dataApiBase#': 'http://localhost:1024', // 数据接口根地址
49
+ '#assetsPublicPath#': 'http://localhost:1024', // 静态资源根地址
50
+ '#routeBasePath#': '/' // 路由根地址
51
+ },
52
+ online: {
53
+ // 线上正式环境配置参数
54
+ '#dataApiBase#': '/', // 数据接口根地址 "//xxx.cn/"格式
55
+ '#assetsPublicPath#': '', // 静态资源根地址 "//xxx.cn/_spa/projectName"格式
56
+ '#routeBasePath#': '/' // 路由根地址 "/_spa/projectName/"格式
57
+ }
58
+ },
59
+ dev: {
60
+ // 用于开启本地调试模式的相关配置信息
61
+ NODE_ENV: 'development',
62
+ port: 80, // 设置基础端口,如果被占用则自动寻找可用端口
63
+ autoOpenBrowser: true,
64
+ assetsPublicPath: '/', // 设置静态资源的引用路径(根域名+路径)
65
+ assetsSubDirectory: '',
66
+ hostname: 'localhost',
67
+ proxyTable: {},
68
+ /** CSS Sourcemaps off by default because relative paths are "buggy"
69
+ * with this option, according to the CSS-Loader README
70
+ * (https://github.com/webpack/css-loader#sourcemaps)
71
+ * In our experience, they generally work as expected,
72
+ * just be aware of this issue when enabling this option.
73
+ */
74
+ cssSourceMap: true
75
+ },
76
+ build: {
77
+ // 用于构建生产环境代码的相关配置信息
78
+ NODE_ENV: 'production', // production 模式,会启动UglifyJsPlugin服务
79
+ assetsRoot: resolve('dist'), // 编译完成的文件存放路径
80
+ assetsPublicPath: '/', // 设置静态资源的引用路径(根域名+路径)
81
+ assetsSubDirectory: '', // 资源引用二级路径
82
+ productionSourceMap: false,
83
+ // closeHtmlWebpackPlugin: true, // 可用于控制不生成html文件
84
+ // Gzip off by default as many popular public hosts such as
85
+ // Surge or Netlify already gzip all public assets for you.
86
+ // Before setting to `true`, make sure to:
87
+ // npm install --save-dev compression-webpack-plugin
88
+ productionGzip: false,
89
+ productionGzipExtensions: ['js', 'css', 'json'],
90
+ // Run the build command with an extra argument to
91
+ // View the bundle analyzer report after build finishes:
92
+ // `npm run build --report`
93
+ // Set to `true` or `false` to always turn it on or off
94
+ bundleAnalyzerReport: false
95
+ },
96
+ build2lib: {
97
+ // 用于构建第三方功能包的配置文件
98
+ NODE_ENV: 'production',
99
+ libraryName: '', // 构建第三方功能包时最后导出的引用变量名
100
+ assetsRoot: resolve('dist'), // 编译完成的文件存放路径
101
+ assetsPublicPath: '/', // 设置静态资源的引用路径(根域名+路径)
102
+ assetsSubDirectory: '', // 资源引用二级路径
103
+ productionSourceMap: false,
104
+ productionGzip: false,
105
+ productionGzipExtensions: ['js', 'css', 'json'],
106
+ bundleAnalyzerReport: false
107
+ },
108
+ linkDebug: {
109
+ // 用于开启本地调试模式的相关配置信息
110
+ NODE_ENV: 'development',
111
+ closeHtmlWebpackPlugin: true,
112
+ autoOpenBrowser: false,
113
+ cssExtract: false,
114
+ consoleInfo: '当前自定义组件可用外链地址'
115
+ },
116
+ publish2oss: {
117
+ output: {
118
+ filename: '[name].js',
119
+ library: {
120
+ type: 'var', // webpack 5 中生成 IIFE 格式的 type 配置
121
+ export: 'default'
122
+ },
123
+ globalObject: 'this' // 定义全局变量,兼容node和浏览器运行,避免出现"window is not defined"的情况
124
+ },
125
+ cssExtract: false, // 不额外提取css文件
126
+ ossType: 'ali', // oss类型:ali、baidu
127
+ ossConfig: {
128
+ endpoint: 'https://oss-cn-beijing.aliyuncs.com',
129
+ // 个人阿里云子账户(neo-cmp-cli),有流量限制,请勿滥用
130
+ AccessKeyId: 'LTAI5tS47y9L4fAPLXNoEzxS',
131
+ AccessKeySecret: '8qz2GxxJJe44K5NRmLAAzIVJnbcYAU',
132
+ bucket: 'neo-widgets' // 存储桶名称
133
+ },
134
+ assetsRoot: resolve('dist') // 上传指定目录下的脚本文件
135
+ },
136
+ // 授权码授权模式下的 NeoCRM 平台配置
137
+ neoConfig: {
138
+ authType: 'oauth2', // 授权类型,可选值:oauth2(默认)、password
139
+ neoBaseURL: 'https://crm-cd.xiaoshouyi.com', // 平台根地址(默认:https://crm.xiaoshouyi.com)
140
+ // 当 authType 为 oauth2 时,loginURL 配置项必填
141
+ loginURL: 'https://login-cd.xiaoshouyi.com/auc/oauth2/auth', // 登录授权 URL(默认:https://login.xiaoshouyi.com/auc/oauth2/auth)
142
+ tokenAPI: 'https://login-cd.xiaoshouyi.com/auc/oauth2/token' // Token 获取接口地址(默认:https://login.xiaoshouyi.com/auc/oauth2/token)
143
+ },
144
+ /*
145
+ // 密码授权模式下的 NeoCRM 平台配置
146
+ neoConfig: {
147
+ authType: 'password', // 授权类型,可选值:oauth2(默认)、password
148
+ neoBaseURL: 'https://crm-cd.xiaoshouyi.com', // 平台根地址(默认:https://crm.xiaoshouyi.com)
149
+ tokenAPI: 'https://login-cd.xiaoshouyi.com/auc/oauth2/token', // Token 获取接口地址(默认:https://login.xiaoshouyi.com/auc/oauth2/token)
150
+ // 当 authType 为 password 时,auth 配置项必填
151
+ auth: {
152
+ client_id: auth.client_id || 'xx', // 客户端 ID,从创建连接器的客户端信息中获取(Client_Id)
153
+ client_secret: auth.client_secret || 'xxx', // 客户端秘钥,从创建连接器的客户端信息中获取(Client_Secret)
154
+ username: auth.username || 'xx', // 用户在销售易系统中的用户名
155
+ // password 为 用户在销售易系统中的账号密码加上 8 位安全令牌。
156
+ // 例如,用户密码为 123456,安全令牌为 ABCDEFGH,则 password 的值应为 123456ABCDEFGH。
157
+ password: auth.password || 'xx xx', // 用户账户密码 + 8 位安全令牌
158
+ },
159
+ },
160
+ */
161
+ pushCmp: {
162
+ output: {
163
+ filename: '[name].js',
164
+ library: {
165
+ type: 'var', // webpack 5 中生成 IIFE 格式的 type 配置
166
+ export: 'default'
167
+ },
168
+ globalObject: 'this' // 定义全局变量,兼容node和浏览器运行,避免出现"window is not defined"的情况
169
+ },
170
+ cssExtract: false, // 不额外提取css文件
171
+ assetsRoot: resolve('dist') // 上传指定目录下的脚本文件
172
+ }
173
+ };
174
+
175
+ // 备注:数组类型则直接覆盖
176
+ module.exports = defaultNEOConfig;
@@ -0,0 +1,9 @@
1
+ // 统一路径解析:
2
+ const { resolve, getConfigObj, deepMergeConfig } = require('akfun');
3
+ const defaultNEOConfig = require('./default.config');
4
+
5
+ // 从项目根目录获取当前项目的配置文件
6
+ const curProjectConfig = getConfigObj(resolve('neo.config.js'));
7
+
8
+ // 备注:数组类型则直接覆盖
9
+ module.exports = deepMergeConfig(defaultNEOConfig, curProjectConfig);
@@ -0,0 +1,13 @@
1
+ <html lang="en">
2
+ <head>
3
+ <meta charset="UTF-8">
4
+ <meta http-equiv="X-UA-Compatible" content="IE=edge">
5
+ <meta name="format-detection" content="telephone=no"/>
6
+ <meta name="viewport" content="initial-scale=1.0,user-scalable=no,width=device-width,viewport-fit=cover">
7
+ <meta http-equiv="X-UA-Compatible" content="ie=edge">
8
+ <title>自定义组件预览页</title>
9
+ </head>
10
+ <body>
11
+ <div id="root"></div>
12
+ </body>
13
+ </html>
@@ -0,0 +1,138 @@
1
+ 'use strict';
2
+ const path = require('path');
3
+
4
+ // 统一路径解析
5
+ function resolve(dir) {
6
+ return path.resolve(__dirname, dir);
7
+ }
8
+
9
+ // 包括生产和开发的环境配置信息
10
+ module.exports = {
11
+ settings: {
12
+ enableESLint: true, // 调试模式是否开启ESLint,默认开启ESLint检测代码格式
13
+ enableESLintFix: true, // 是否自动修正代码格式,默认不自动修正
14
+ enableStyleLint: false, // 是否开启StyleLint,默认开启ESLint检测代码格式
15
+ enableStyleLintFix: false // 是否需要StyleLint自动修正代码格式
16
+ },
17
+ webpack: {
18
+ target: ['web', 'es5'], // 指定目标环境为 web 和 es5,确保兼容性
19
+ resolve: {
20
+ // webpack的resolve配置
21
+ extensions: ['.js', '.jsx', '.ts', '.tsx', '.umd.js', '.min.js', '.json'], // 用于配置webpack在尝试过程中用到的后缀列表
22
+ alias: {
23
+ '@': resolve('src'),
24
+ $assets: resolve('src/assets'),
25
+ $public: resolve('public')
26
+ }
27
+ },
28
+ // sassResources 中的 sass 文件会自动注入项目中每一个 sass 文件中
29
+ sassResources: [
30
+ resolve('./src/assets/css/common.scss'),
31
+ resolve('./src/assets/css/mixin.scss')
32
+ ],
33
+ // createDeclaration: true, // 打包时是否创建ts声明文件
34
+ ignoreNodeModules: false // 打包时是否忽略 node_modules
35
+ // allowList: [], // ignoreNodeModules 为 true 时生效
36
+ // projectDir: ['src'],
37
+ // template: resolve('./public/template.html'), // 自定义html模板
38
+ // plugins: [],
39
+ // babelPlugins: [],
40
+ },
41
+ // 用于添加 Neo 共享依赖模块的配置信息
42
+ /*
43
+ neoCommonModule: {
44
+ // exports: ['xxModule'], // 数组写法,用于导出当前自定义组件中的第三方依赖模块
45
+ exports: { // 对象写法,可用于导出自定义组件中的某个内容模块(需要使用绝对路径导出)
46
+ 'xxModule': path.resolve('./src/components/xxModule'), // 导出 xx组件 或 xx模块
47
+ },
48
+ // remoteDeps: ['xxCmpType'], // 远程依赖组件,表示当前自定义组件会用到的依赖组件,需要和 externals 配合使用
49
+ // externals: ['xxModule'], // 自定义组件中需要剔除的模块,仅支持数组写法
50
+ },
51
+ */
52
+ preview: {
53
+ // 用于开启本地预览模式的相关配置信息
54
+ /*
55
+ 【特别说明】以下配置项都自带默认值,非必填。如需自定义请自行配置。
56
+ entry: { // 根据 src/components 目录下的文件自动生成 entry 相关配置
57
+ // 本地预览自定义组件内容
58
+ index: './src/preview.jsx',
59
+ },
60
+ NODE_ENV: 'development',
61
+ port: 80, // 设置基础端口,如果被占用则自动寻找可用端口
62
+ assetsPublicPath: '/', // 设置静态资源的引用路径(根域名+路径)
63
+ assetsSubDirectory: '',
64
+ hostname: 'localhost',
65
+ proxyTable: {
66
+ '/apiTest': {
67
+ target: 'http://api-test.com.cn', // 不支持跨域的接口根地址
68
+ ws: true,
69
+ changeOrigin: true,
70
+ },
71
+ },
72
+ */
73
+ },
74
+ linkDebug: {
75
+ // 用于开启本地调试模式的相关配置信息
76
+ /*
77
+ 【特别说明】以下配置项都自带默认值,非必填。如需自定义请自行配置。
78
+ entry: { // 根据 src/components 目录下的文件自动生成 entry 相关配置
79
+ // 外链调试(在线上页面设计器端预览自定义组件)
80
+ index: [
81
+ './src/components/xxCmp/register.ts',
82
+ './src/components/xxCmp/model.ts',
83
+ ],
84
+ },
85
+ NODE_ENV: 'development',
86
+ port: 80, // 设置基础端口,如果被占用则自动寻找可用端口
87
+ closeHotReload: true, // 是否关闭热更新
88
+ assetsPublicPath: '/', // 设置静态资源的引用路径(根域名+路径)
89
+ assetsSubDirectory: '',
90
+ hostname: 'localhost',
91
+ proxyTable: {
92
+ '/apiTest': {
93
+ target: 'http://api-test.com.cn', // 不支持跨域的接口根地址
94
+ ws: true,
95
+ changeOrigin: true,
96
+ },
97
+ }
98
+ */
99
+ },
100
+ // 授权码授权模式下的 NeoCRM 平台配置
101
+ neoConfig: {
102
+ authType: 'oauth2', // 授权类型,可选值:oauth2(默认)、password
103
+ neoBaseURL: 'https://crm-cd.xiaoshouyi.com', // 平台根地址(默认:https://crm.xiaoshouyi.com)
104
+ // 当 authType 为 oauth2 时,loginURL 配置项必填
105
+ loginURL: 'https://login-cd.xiaoshouyi.com/auc/oauth2/auth', // 登录授权 URL(默认:https://login.xiaoshouyi.com/auc/oauth2/auth)
106
+ tokenAPI: 'https://login-cd.xiaoshouyi.com/auc/oauth2/token' // Token 获取接口地址(默认:https://login.xiaoshouyi.com/auc/oauth2/token)
107
+ },
108
+ /*
109
+ // 密码授权模式下的 NeoCRM 平台配置
110
+ neoConfig: {
111
+ authType: 'password', // 授权类型,可选值:oauth2(默认)、password
112
+ neoBaseURL: 'https://crm-cd.xiaoshouyi.com', // 平台根地址(默认:https://crm.xiaoshouyi.com)
113
+ tokenAPI: 'https://login-cd.xiaoshouyi.com/auc/oauth2/token', // Token 获取接口地址(默认:https://login.xiaoshouyi.com/auc/oauth2/token)
114
+ // 当 authType 为 password 时,auth 配置项必填
115
+ auth: {
116
+ client_id: auth.client_id || 'xx', // 客户端 ID,从创建连接器的客户端信息中获取(Client_Id)
117
+ client_secret: auth.client_secret || 'xxx', // 客户端秘钥,从创建连接器的客户端信息中获取(Client_Secret)
118
+ username: auth.username || 'xx', // 用户在销售易系统中的用户名
119
+ // password 为 用户在销售易系统中的账号密码加上 8 位安全令牌。
120
+ // 例如,用户密码为 123456,安全令牌为 ABCDEFGH,则 password 的值应为 123456ABCDEFGH。
121
+ password: auth.password || 'xx xx', // 用户账户密码 + 8 位安全令牌
122
+ },
123
+ },
124
+ */
125
+ pushCmp: {
126
+ // 用于构建并发布至 NeoCRM 的相关配置
127
+ /*
128
+ 【特别说明】以下配置项都自带默认值,非必填。如需自定义请自行配置。
129
+ NODE_ENV: 'production',
130
+ entry: { // 根据 src/components 目录下的文件自动生成 entry 相关配置
131
+ InfoCardModel: './src/components/xxCmp/model.ts',
132
+ infoCard: './src/components/xxCmp/register.ts'
133
+ },
134
+ cssExtract: false, // 不额外提取css文件
135
+ assetsRoot: resolve('dist') // 上传指定目录下的脚本文件
136
+ */
137
+ }
138
+ };
package/src/main.js ADDED
@@ -0,0 +1,221 @@
1
+ const akfun = require('akfun');
2
+ const _ = require('lodash');
3
+ const neoInit = require('./module/neoInit');
4
+ const neoInitByCopy = require('./module/neoInitByCopy');
5
+ const inspect = require('./module/inspect');
6
+ const neoConfigInit = require('./utils/neoConfigInit.js');
7
+ const { consoleTag } = require('./utils/neoParams');
8
+ const curConfig = require('./config/index'); // 获取当前项目根目录下的配置文件
9
+ const publish2oss = require('./oss/publish2oss');
10
+ const pushCmp = require('./utils/cmpUtils/pushCmp');
11
+ const previewCmp = require('./utils/cmpUtils/previewCmp');
12
+ const generateEntries = require('./utils/generateEntries');
13
+ // const { MFPlugins } = require('./neo/webpack.mf');
14
+ const createCmpByTemplate = require('./utils/cmpUtils/createCmpByTemplate');
15
+ const createCmpProjectByTemplate = require('./utils/projectUtils/createCmpProjectByTemplate');
16
+ const pullCmp = require('./utils/cmpUtils/pullCmp');
17
+ const deleteCmp = require('./utils/cmpUtils/deleteCmp');
18
+ const openProject = require('./utils/projectUtils/openProject');
19
+ const { configureNeoBuild } = require('./utils/configureNeoBuild');
20
+ const { errorLog, successLog } = require('./utils/common');
21
+ // 导出工具函数
22
+ const { validateProjectName } = require('./utils/projectNameValidator.js');
23
+ const getCmpTypeByDir = require('./utils/cmpUtils/getCmpTypeByDir.js');
24
+ const NeoService = require('./neo/neoService.js');
25
+ const NeoLoginService = require('./neo/neoLogin.js');
26
+ const hasNeoProject = require('./utils/projectUtils/hasNeoProject.js');
27
+
28
+ const getValue = (originValue, defaultValue) => {
29
+ return originValue !== undefined ? originValue : defaultValue;
30
+ };
31
+
32
+ /**
33
+ * 生成并设置 entry 配置
34
+ * @param {object} config 配置对象(dev 或 build2lib)
35
+ * @param {object} options 生成选项
36
+ * @param {string} options.entryType entry 类型:'widget' | 'linkDebug'
37
+ * @param {string} [options.cmpType] 可选的组件类型
38
+ * @returns {array} cmpTypes 组件类型列表
39
+ */
40
+ function setupEntries(config, options) {
41
+ const { entryType, cmpType } = options;
42
+
43
+ let cmpTypes = [];
44
+ let defaultExports = {};
45
+ try {
46
+ const { entries, cmpTypes: generatedCmpTypes, defaultExports: generatedDefaultExports } = generateEntries({
47
+ configEntry: config.entry,
48
+ disableAutoRegister: config.disableAutoRegister,
49
+ componentsDir: curConfig.componentsDir,
50
+ entryType,
51
+ cmpType
52
+ });
53
+
54
+ if (entries && Object.keys(entries).length > 0) {
55
+ config.entry = entries;
56
+ cmpTypes = generatedCmpTypes;
57
+ console.info('已自动生成 entry 入口配置:', entries);
58
+ }
59
+
60
+ defaultExports = generatedDefaultExports;
61
+ } catch (error) {
62
+ errorLog(error.message);
63
+ process.exit(1);
64
+ }
65
+
66
+ return {
67
+ cmpTypes,
68
+ defaultExports
69
+ };
70
+ }
71
+
72
+ /**
73
+ * 准备 build2lib 配置(用于 publish2oss 和 pushCmp)
74
+ * @param {object} sourceConfig 源配置对象
75
+ * @returns {object} 合并后的配置对象
76
+ */
77
+ function prepareBuild2LibConfig(sourceConfig) {
78
+ return Object.assign(curConfig.build2lib, sourceConfig);
79
+ }
80
+
81
+ module.exports = {
82
+ neoInit,
83
+ neoInitByCopy,
84
+ inspect,
85
+ neoConfigInit,
86
+ projectConfig: curConfig,
87
+ consoleTag,
88
+ errorLog,
89
+ successLog,
90
+ validateProjectName,
91
+ getCmpTypeByDir,
92
+ NeoService,
93
+ NeoLoginService,
94
+ hasNeoProject,
95
+ createCmpProjectByTemplate,
96
+ createCmpByTemplate,
97
+ dev: () => {
98
+ if (!curConfig.dev) {
99
+ errorLog('未找到 dev 相关配置。');
100
+ process.exit(1);
101
+ }
102
+ akfun.dev(curConfig, consoleTag);
103
+ },
104
+ previewCmp: (cmpName) => {
105
+ // 预览组件本身内容
106
+ if (!cmpName) {
107
+ errorLog('请输入要预览的组件名称。');
108
+ process.exit(1);
109
+ }
110
+ if (!curConfig.preview) {
111
+ errorLog('未找到 preview 相关配置。');
112
+ process.exit(1);
113
+ }
114
+ curConfig.dev = Object.assign(curConfig.dev, curConfig.preview); // 将 preview 设置给 dev
115
+ delete curConfig.preview;
116
+
117
+ previewCmp(curConfig, cmpName);
118
+ },
119
+ linkDebug: () => {
120
+ // 外链调试模式
121
+ if (!curConfig.linkDebug) {
122
+ errorLog('未找到 debug 相关配置。');
123
+ process.exit(1);
124
+ }
125
+ // 将 linkDebug 设置给 dev
126
+ curConfig.dev = Object.assign(curConfig.dev, curConfig.linkDebug);
127
+ delete curConfig.linkDebug;
128
+
129
+ delete curConfig.dev.ignoreNodeModules; // 需要注入依赖
130
+ curConfig.webpack.ignoreNodeModules = false;
131
+
132
+ // 生成并设置 entry 配置
133
+ const {cmpTypes: curCmpTypes, defaultExports} = setupEntries(curConfig.dev, {
134
+ entryType: 'linkDebug'
135
+ });
136
+
137
+ // 配置 webpack 插件、externals 和 commonModulesCode
138
+ configureNeoBuild(curConfig.dev, {
139
+ cmpTypes: curCmpTypes,
140
+ defaultExports,
141
+ verbose: true,
142
+ excludeModel: false // linkDebug 不排除 Model
143
+ });
144
+
145
+ akfun.dev(curConfig, consoleTag);
146
+ },
147
+ build: () => akfun.build('build', curConfig, consoleTag), // 构建脚本:生产环境
148
+ build2lib: () => {
149
+ // 生成并设置 entry 配置
150
+ setupEntries(curConfig.build2lib, {
151
+ entryType: 'widget'
152
+ });
153
+
154
+ akfun.build('lib', curConfig, consoleTag);
155
+ }, // 构建脚本:生产环境
156
+ publish2oss: (cmpType) => {
157
+ // 将 publish2oss 相关配置设置给 build2lib
158
+ const publish2ossConfig = curConfig.publish2oss;
159
+ curConfig.build2lib = prepareBuild2LibConfig(publish2ossConfig);
160
+
161
+ // 生成并设置 entry 配置
162
+ const {cmpTypes: curCmpTypes, defaultExports} = setupEntries(curConfig.build2lib, {
163
+ entryType: 'widget',
164
+ cmpType
165
+ });
166
+
167
+ // 配置 webpack 插件、externals 和 commonModulesCode
168
+ configureNeoBuild(curConfig.build2lib, {
169
+ cmpTypes: curCmpTypes,
170
+ defaultExports,
171
+ verbose: true,
172
+ excludeModel: true // publish2oss 排除 Model 结尾的文件
173
+ });
174
+
175
+ akfun.build('lib', curConfig, consoleTag, () => {
176
+ // 构建完成后,执行 publish2oss
177
+ publish2oss(
178
+ publish2ossConfig.ossType,
179
+ publish2ossConfig.ossConfig,
180
+ publish2ossConfig.assetsRoot
181
+ );
182
+ });
183
+ },
184
+ // 发布组件到 NeoCRM 平台
185
+ pushCmp: (cmpType) => {
186
+ const { neoConfig, pushCmp: _pushCmpConfig } = curConfig;
187
+ const pushCmpConfig = Object.assign({}, _pushCmpConfig, neoConfig);
188
+ // 将 pushCmp 相关配置设置给 build2lib
189
+ curConfig.build2lib = prepareBuild2LibConfig(pushCmpConfig);
190
+
191
+ // 生成并设置 entry 配置
192
+ const {cmpTypes: curCmpTypes, defaultExports} = setupEntries(curConfig.build2lib, {
193
+ entryType: 'widget',
194
+ cmpType
195
+ });
196
+
197
+ // 配置 webpack 插件、externals 和 commonModulesCode
198
+ configureNeoBuild(curConfig.build2lib, {
199
+ cmpTypes: curCmpTypes,
200
+ defaultExports,
201
+ verbose: false,
202
+ excludeModel: true // pushCmp 排除 Model 结尾的文件
203
+ });
204
+
205
+ akfun.build('lib', curConfig, consoleTag, () => {
206
+ // 构建完成后,执行 pushCmp
207
+ pushCmp(pushCmpConfig, cmpType);
208
+ });
209
+ },
210
+ // 从 NeoCRM 平台拉取组件
211
+ pullCmp: (cmpType, neoService) => {
212
+ pullCmp(cmpType, curConfig.neoConfig, neoService);
213
+ },
214
+ // 从 NeoCRM 平台删除组件
215
+ deleteCmp: (cmpType, neoService) => {
216
+ deleteCmp(cmpType, curConfig.neoConfig, neoService);
217
+ },
218
+ build2esm: (fileName) => akfun.build2esm(fileName, curConfig, consoleTag), // 构建esm输出模块
219
+ // 打开编辑器(Cursor 或 VSCode)
220
+ openEditor: openProject
221
+ };
@@ -0,0 +1,41 @@
1
+ const path = require('path');
2
+ const ora = require('ora');
3
+ const fs = require('fs');
4
+ const { getCurWebpackConfig } = require('akfun'); // 用于获取当前webpack配置的方法
5
+ const curConfig = require('../config/index');
6
+ const { consoleTag } = require('../utils/neoParams'); // 输出标记
7
+ const { errorLog, successLog } = require('../utils/common');
8
+
9
+ // 根据当前配置文件内容创建指定名称的文件
10
+ const createConfigJs = function (fileName, fileCont) {
11
+ let filePath = path.resolve(process.cwd(), fileName);
12
+
13
+ fs.writeFile(filePath, JSON.stringify(fileCont, null, 2), (err) => {
14
+ if (err) {
15
+ throw Error(err);
16
+ }
17
+ });
18
+ };
19
+
20
+ /**
21
+ * 用于输出当前项目配置文件
22
+ */
23
+ module.exports = (type) => {
24
+ const spinner = ora(`${consoleTag}正在获取当前环境的配置数据...`).start();
25
+ if (type === 'dev') {
26
+ const devConfig = getCurWebpackConfig(type, curConfig);
27
+ createConfigJs('current-neo-dev-config.js', devConfig);
28
+ successLog(`当前配置数据已输出至 current-neo-dev-config.js中。`, spinner);
29
+ } else if (type === 'lib') {
30
+ const libraryConfig = getCurWebpackConfig(type, curConfig);
31
+ createConfigJs('current-neo-build2lib-config.js', libraryConfig);
32
+ successLog(`当前配置数据已输出至 current-neo-build2lib-config.js中。`, spinner);
33
+ } else if (type === 'build') {
34
+ const prodConfig = getCurWebpackConfig(type, curConfig);
35
+ // 默认输出生产环境的配置文件
36
+ createConfigJs('current-neo-build-config.js', prodConfig);
37
+ successLog(`当前配置数据已输出至 current-neo-build-config.js。`, spinner);
38
+ } else {
39
+ errorLog(`type 不能为空。`, spinner);
40
+ }
41
+ };