neo-cmp-cli 1.5.1 → 1.5.3

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 (69) hide show
  1. package/README.md +52 -15
  2. package/package.json +1 -1
  3. package/src/cmpUtils/createCmpByTemplate.js +58 -0
  4. package/src/cmpUtils/createCommonModulesCode.js +15 -15
  5. package/src/cmpUtils/{getCmpModelRegister.js → getCmpModelRegisterCode.js} +2 -2
  6. package/src/cmpUtils/{getCmpPreview.js → getCmpPreviewCode.js} +2 -2
  7. package/src/cmpUtils/{getCmpRegister.js → getCmpRegisterCode.js} +2 -2
  8. package/src/cmpUtils/getCmpTypeByDir.js +41 -0
  9. package/src/cmpUtils/hasCmpTypeByDir.js +11 -0
  10. package/src/{module → cmpUtils}/previewCmp.js +2 -2
  11. package/src/cmpUtils/{publishCmp.js → pushCmp.js} +54 -42
  12. package/src/config/default.config.js +14 -2
  13. package/src/module/index.js +144 -21
  14. package/src/module/main.js +17 -13
  15. package/src/module/neoInit.js +3 -0
  16. package/src/module/neoInitByCopy.js +3 -0
  17. package/src/neo/NeoUMDContent.js +29 -0
  18. package/src/neo/neoRequire.js +7 -7
  19. package/src/neo/neoService.js +174 -72
  20. package/src/neo/wrapperContent.js +2 -1
  21. package/src/oss/publish2oss.js +1 -1
  22. package/src/plugins/AddNeoRequirePlugin.js +5 -2
  23. package/src/projectUtils/createCmpProjectByTemplate.js +55 -0
  24. package/src/{cmpUtils → projectUtils}/getEntriesWithAutoRegister.js +4 -4
  25. package/src/projectUtils/hasNeoProject.js +16 -0
  26. package/src/template/antd-custom-cmp-template/README.md +2 -2
  27. package/src/template/antd-custom-cmp-template/neo.config.js +22 -14
  28. package/src/template/antd-custom-cmp-template/package.json +3 -3
  29. package/src/template/develop/neo-custom-cmp-template/neo.config.js +1 -1
  30. package/src/template/echarts-custom-cmp-template/README.md +2 -2
  31. package/src/template/echarts-custom-cmp-template/neo.config.js +19 -13
  32. package/src/template/echarts-custom-cmp-template/package.json +3 -3
  33. package/src/template/empty-cmp/index.tsx +51 -0
  34. package/src/template/empty-cmp/model.ts +77 -0
  35. package/src/template/empty-cmp/style.scss +72 -0
  36. package/src/template/empty-custom-cmp-template/.prettierrc.js +12 -0
  37. package/src/template/empty-custom-cmp-template/README.md +45 -0
  38. package/src/template/empty-custom-cmp-template/commitlint.config.js +59 -0
  39. package/src/template/empty-custom-cmp-template/neo.config.js +126 -0
  40. package/src/template/empty-custom-cmp-template/package.json +57 -0
  41. package/src/template/empty-custom-cmp-template/public/css/base.css +283 -0
  42. package/src/template/empty-custom-cmp-template/public/scripts/app/bluebird.js +6679 -0
  43. package/src/template/empty-custom-cmp-template/public/template.html +13 -0
  44. package/src/template/empty-custom-cmp-template/src/assets/css/common.scss +127 -0
  45. package/src/template/empty-custom-cmp-template/src/assets/css/mixin.scss +47 -0
  46. package/src/template/empty-custom-cmp-template/src/assets/img/NeoCRM.jpg +0 -0
  47. package/src/template/empty-custom-cmp-template/src/assets/img/custom-widget.svg +1 -0
  48. package/src/template/empty-custom-cmp-template/src/assets/img/favicon.png +0 -0
  49. package/src/template/empty-custom-cmp-template/src/assets/img/map.svg +1 -0
  50. package/src/template/empty-custom-cmp-template/src/components/README.md +3 -0
  51. package/src/template/empty-custom-cmp-template/tsconfig.json +68 -0
  52. package/src/template/neo-custom-cmp-template/README.md +2 -2
  53. package/src/template/neo-custom-cmp-template/neo.config.js +6 -26
  54. package/src/template/neo-custom-cmp-template/package.json +3 -4
  55. package/src/template/react-custom-cmp-template/README.md +2 -2
  56. package/src/template/react-custom-cmp-template/neo.config.js +20 -15
  57. package/src/template/react-custom-cmp-template/package.json +3 -3
  58. package/src/template/react-ts-custom-cmp-template/README.md +2 -2
  59. package/src/template/react-ts-custom-cmp-template/neo.config.js +19 -14
  60. package/src/template/react-ts-custom-cmp-template/package.json +3 -3
  61. package/src/template/vue2-custom-cmp-template/README.md +2 -2
  62. package/src/template/vue2-custom-cmp-template/neo.config.js +20 -15
  63. package/src/template/vue2-custom-cmp-template/package.json +3 -3
  64. package/src/utils/autoEntryRootDir.js +75 -0
  65. package/src/utils/replaceInFilesByMap.js +54 -0
  66. package/test/demo.js +2 -2
  67. package/src/template/neo-custom-cmp-template/auth.config.js +0 -12
  68. /package/src/{cmpUtils → projectUtils}/getEntries.js +0 -0
  69. /package/src/{cmpUtils → projectUtils}/updatePublishLog.js +0 -0
@@ -0,0 +1,75 @@
1
+ const path = require('path');
2
+ const fs = require('fs');
3
+
4
+ /**
5
+ * 自动进入指定项目的根目录
6
+ *
7
+ * ⚠️ 重要说明:子进程无法直接改变父 shell 的工作目录
8
+ *
9
+ * 原因:
10
+ * 1. 进程隔离:每个进程都有独立的工作目录,子进程无法修改父进程的工作目录
11
+ * 2. Shell 限制:cd 是 shell 的内置命令,必须在父 shell 进程中执行
12
+ * 3. 安全机制:操作系统禁止子进程修改父进程的工作目录,防止安全问题
13
+ *
14
+ * 解决方案:
15
+ * 1. 使用 process.chdir() 改变 Node.js 进程的工作目录(仅对后续 Node.js 操作有效)
16
+ * 2. 输出 shell 命令让用户执行以改变 shell 的工作目录
17
+ *
18
+ * @param {string} projectPath 项目路径(可以是相对路径或绝对路径)
19
+ * @param {object} options 配置选项
20
+ * @param {boolean} options.outputShellCommand 是否输出 shell 命令让用户执行(默认:true)
21
+ * @returns {boolean} 是否成功切换目录
22
+ */
23
+ module.exports = function (projectPath, options = {}) {
24
+ const { outputShellCommand = true } = options;
25
+
26
+ if (!projectPath) {
27
+ console.error('运行异常:未找到可用的项目路径。');
28
+ return false;
29
+ }
30
+
31
+ // 将路径解析为绝对路径
32
+ const absolutePath = path.isAbsolute(projectPath)
33
+ ? projectPath
34
+ : path.resolve(process.cwd(), projectPath);
35
+
36
+ // 检查目录是否存在
37
+ if (!fs.existsSync(absolutePath)) {
38
+ console.error(`运行异常:${projectPath} 目录不存在。`);
39
+ return false;
40
+ }
41
+
42
+ // 检查是否为目录
43
+ const stats = fs.statSync(absolutePath);
44
+ if (!stats.isDirectory()) {
45
+ console.error(`运行异常:${projectPath} 不是目录。`);
46
+ return false;
47
+ }
48
+
49
+ const projectName = path.relative(process.cwd(), absolutePath);
50
+
51
+ let success = false;
52
+
53
+ // 改变 Node.js 进程的工作目录(仅对后续 Node.js 操作有效)
54
+ try {
55
+ process.chdir(absolutePath);
56
+ success = true;
57
+ } catch (error) {
58
+ console.error(`错误:无法切换到目录 ${projectName}: ${error.message}`);
59
+ return false;
60
+ }
61
+
62
+ // 输出 shell 命令让用户执行(这样可以真正改变 shell 的工作目录)
63
+ if (outputShellCommand) {
64
+ const command = `cd ${projectName}`;
65
+ // 输出提示信息
66
+ console.log('\n' + '='.repeat(60));
67
+ console.log('💡 提示:要切换到项目目录,请执行以下命令:');
68
+ console.log(`\n ${command}\n`);
69
+ console.log('='.repeat(60));
70
+ console.log('\n📝 说明:组件开发工具(neo-cmp-cli)无法直接改变当前命令窗口工作目录,');
71
+ console.log(` 您需要手动执行上述命令才能进入刚创建的自定义组件项目(${projectName})。\n`);
72
+ }
73
+
74
+ return success;
75
+ };
@@ -0,0 +1,54 @@
1
+ const fs = require('fs-extra');
2
+ const path = require('path');
3
+
4
+ /**
5
+ * 全局替换项目中的指定字符串
6
+ * @param dir 项目目录
7
+ * @param needReplaceStrMap {
8
+ * [oldStr]: newStr
9
+ * }
10
+ * @param fileExtensions 文件扩展名
11
+ */
12
+ function replaceInFilesByMap(
13
+ dir,
14
+ needReplaceStrMap = {},
15
+ fileExtensions = ['.js', '.jsx', '.ts', '.tsx', '.vue', '.html', '.css', '.scss', '.json']
16
+ ) {
17
+ try {
18
+ // 读取指定目录下的所有文件
19
+ const files = fs.readdirSync(dir);
20
+
21
+ // 遍历所有文件
22
+ files.forEach((file) => {
23
+ const filePath = path.join(dir, file);
24
+ // 获取文件状态
25
+ const stat = fs.statSync(filePath);
26
+ // 如果文件是目录,则递归处理子目录
27
+ if (stat.isDirectory() && !file.startsWith('.') && file !== 'node_modules') {
28
+ // 递归处理子目录
29
+ replaceInFilesByMap(filePath, needReplaceStrMap, fileExtensions);
30
+ } else if (stat.isFile()) {
31
+ // 检查文件扩展名
32
+ const ext = path.extname(file);
33
+ if (fileExtensions.includes(ext)) {
34
+ if (needReplaceStrMap &&Object.keys(needReplaceStrMap).length > 0) {
35
+ let content = fs.readFileSync(filePath, 'utf8');
36
+ Object.keys(needReplaceStrMap).forEach((key) => {
37
+ const oldStr = key;
38
+ const newStr = needReplaceStrMap[key];
39
+ if (content.includes(oldStr)) {
40
+ content = content.replace(new RegExp(oldStr, 'g'), newStr); // 全局替换
41
+ }
42
+ });
43
+ // 写入文件(更新文件内容)
44
+ fs.writeFileSync(filePath, content, 'utf8');
45
+ }
46
+ }
47
+ }
48
+ });
49
+ } catch (error) {
50
+ console.error('replaceInFiles 运行失败:', error);
51
+ }
52
+ }
53
+
54
+ module.exports = replaceInFilesByMap;
package/test/demo.js CHANGED
@@ -1,6 +1,6 @@
1
1
  const {neoInit, neoConfigInit, inspect, preview, debug, build2lib, build2esm, neoInitByCopy, previewCmp, } = require('../src/module/main');
2
- const getEntries = require('../src/cmpUtils/getEntries');
3
- const getEntriesWithAutoRegister = require('../src/cmpUtils/getEntriesWithAutoRegister');
2
+ const getEntries = require('../src/projectUtils/getEntries');
3
+ const getEntriesWithAutoRegister = require('../src/projectUtils/getEntriesWithAutoRegister');
4
4
  // inspect('dev');
5
5
  // neoInitByCopy('react-ts', 'test123');
6
6
 
@@ -1,12 +0,0 @@
1
- 'use strict';
2
- // NeoCRM 授权配置
3
- module.exports = {
4
- client_id: 'xx', // 客户端 ID,从创建连接器的客户端信息中获取(Client_Id)
5
- client_secret: 'xxx', // 客户端秘钥,从创建连接器的客户端信息中获取(Client_Secret)
6
- username: 'xx', // 用户在销售易系统中的用户名
7
- /**
8
- * password 为 用户在销售易系统中的账号密码加上 8 位安全令牌。
9
- * 例如,用户密码为 123456,安全令牌为 ABCDEFGH,则 password 的值应为 123456ABCDEFGH。
10
- */
11
- password: 'xx xx', // 用户账户密码 + 8 位安全令牌
12
- };
File without changes