momo-ai 1.0.0 → 1.0.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.
Files changed (107) hide show
  1. package/README.md +117 -0
  2. package/package.json +1 -1
  3. package/src/_template/LAIN/.momo/advanced/actor.md +42 -0
  4. package/src/_template/LAIN/.momo/scripts/submodule-clean.sh +56 -0
  5. package/src/_template/LAIN/AGENTS.md +103 -0
  6. package/src/_template/LAIN/changes/proposal.md +39 -0
  7. package/src/_template/LAIN/changes/tasks/task-detail.md +45 -0
  8. package/src/_template/LAIN/changes/tasks.md +49 -0
  9. package/src/_template/LAIN/execute/admin-n-f-dashboard.md +53 -0
  10. package/src/_template/LAIN/execute/admin-n-f-form.md +51 -0
  11. package/src/_template/LAIN/execute/admin-n-f-home.md +49 -0
  12. package/src/_template/LAIN/execute/admin-n-f-list.md +52 -0
  13. package/src/_template/LAIN/execute/admin-n-f-login.md +56 -0
  14. package/src/_template/LAIN/specification/project-model.md +13 -0
  15. package/src/_template/LAIN/specification/project.md +73 -0
  16. package/src/_template/LAIN/specification/requirement.md +25 -0
  17. package/src/_template/PROMPT/add.md.ejs +5 -0
  18. package/src/_template/PROMPT/plan.md.ejs +5 -0
  19. package/src/_template/PROMPT/run.md.ejs +9 -0
  20. package/src/_template/PROMPT/tasks.md.ejs +5 -0
  21. package/src/commander/actor.json +12 -0
  22. package/src/commander/actors.json +6 -0
  23. package/src/commander/add.json +12 -0
  24. package/src/commander/archive.json +12 -0
  25. package/src/commander/env.json +7 -0
  26. package/src/commander/help.json +7 -0
  27. package/src/commander/init.json +13 -0
  28. package/src/commander/list.json +7 -0
  29. package/src/commander/open.json +7 -0
  30. package/src/commander/plan.json +12 -0
  31. package/src/commander/repo.json +18 -0
  32. package/src/commander/run.json +18 -0
  33. package/src/commander/show.json +12 -0
  34. package/src/commander/tasks.json +18 -0
  35. package/src/commander/unlock.json +6 -0
  36. package/src/commander/validate.json +12 -0
  37. package/src/epic/history/ai.economy.impl.fn.excel.js +148 -0
  38. package/src/epic/history/ai.economy.impl.fn.execute.js +117 -0
  39. package/src/epic/history/ai.economy.impl.fn.java.js +140 -0
  40. package/src/epic/history/ai.economy.impl.fn.json.js +23 -0
  41. package/src/epic/history/ai.economy.impl.fn.plugin.js +160 -0
  42. package/src/epic/history/ai.economy.impl.fn.react.js +219 -0
  43. package/src/epic/history/ai.export.impl.fn.parse.js +345 -0
  44. package/src/epic/history/ai.export.impl.fn.seek.js +42 -0
  45. package/src/epic/history/ai.export.interface.fn.string.js +5 -0
  46. package/src/epic/history/ai.export.interface.io.js +69 -0
  47. package/src/epic/history/ai.export.interface.util.js +17 -0
  48. package/src/epic/history/ai.parse.metadata.js +94 -0
  49. package/src/epic/history/ai.path.fn.dir.operation.js +87 -0
  50. package/src/epic/history/ai.path.fn.io.command.js +43 -0
  51. package/src/epic/history/ai.path.fn.io.specification.js +59 -0
  52. package/src/epic/history/ai.path.fn.io.typed.js +63 -0
  53. package/src/epic/history/ai.path.fn.out.content.js +47 -0
  54. package/src/epic/history/ai.string.fn.str.util.js +63 -0
  55. package/src/epic/history/ai.uncork.fn.element.feature.js +52 -0
  56. package/src/epic/history/ai.uncork.fn.it.feature.js +118 -0
  57. package/src/epic/history/ai.uncork.fn.to.typed.js +74 -0
  58. package/src/epic/history/ai.under.fn.cx.evaluate.js +81 -0
  59. package/src/epic/history/ai.under.fn.fx.terminal.js +143 -0
  60. package/src/epic/history/ai.unified.fn.fn.error.code.js +108 -0
  61. package/src/epic/history/ai.unified.fn.is.decision.js +20 -0
  62. package/src/epic/history/ai.unified.fn.sorter.element.js +26 -0
  63. package/src/epic/history/zero.__.fn.find.util.js +37 -0
  64. package/src/epic/history/zero.__.v.constant.js +5 -0
  65. package/src/epic/index.js +50 -0
  66. package/src/epic/lain.fn.execute.js +116 -0
  67. package/src/epic/lain.fn.parse.js +94 -0
  68. package/src/epic/momo.fn.cx.js +81 -0
  69. package/src/epic/momo.fn.dir.js +87 -0
  70. package/src/epic/momo.fn.element.js +52 -0
  71. package/src/epic/momo.fn.find.js +37 -0
  72. package/src/epic/momo.fn.fx.js +143 -0
  73. package/src/epic/momo.fn.io.js +157 -0
  74. package/src/epic/momo.fn.is.js +20 -0
  75. package/src/epic/momo.fn.it.js +118 -0
  76. package/src/epic/momo.fn.log.js +50 -0
  77. package/src/epic/momo.fn.out.js +47 -0
  78. package/src/epic/momo.fn.sorter.js +26 -0
  79. package/src/epic/momo.fn.str.js +63 -0
  80. package/src/epic/momo.fn.to.js +74 -0
  81. package/src/epic/momo.v.constant.js +5 -0
  82. package/src/epic/momo.v.errorcode.js +108 -0
  83. package/src/executor/executeActor.js +113 -0
  84. package/src/executor/executeActors.js +58 -0
  85. package/src/executor/executeAdd.js +248 -0
  86. package/src/executor/executeArchive.js +124 -0
  87. package/src/executor/executeEnv.js +158 -0
  88. package/src/executor/executeHelp.js +23 -0
  89. package/src/executor/executeInit.js +321 -0
  90. package/src/executor/executeList.js +111 -0
  91. package/src/executor/executeOpen.js +150 -0
  92. package/src/executor/executePlan.js +134 -0
  93. package/src/executor/executeRepo.js +234 -0
  94. package/src/executor/executeRun.js +527 -0
  95. package/src/executor/executeShow.js +164 -0
  96. package/src/executor/executeTasks.js +323 -0
  97. package/src/executor/executeUnlock.js +110 -0
  98. package/src/executor/executeValidate.js +210 -0
  99. package/src/executor/index.js +35 -0
  100. package/src/momo.js +39 -1
  101. package/.idea/copilot.data.migration.agent.xml +0 -6
  102. package/.idea/copilot.data.migration.ask.xml +0 -6
  103. package/.idea/copilot.data.migration.ask2agent.xml +0 -6
  104. package/.idea/copilot.data.migration.edit.xml +0 -6
  105. package/.idea/modules.xml +0 -8
  106. package/.idea/r2mo-lain.iml +0 -12
  107. package/.idea/vcs.xml +0 -6
@@ -0,0 +1,37 @@
1
+ const os = require("os");
2
+ const _V = require('./momo.v.constant');
3
+
4
+ const findTrace = (path = "") => {
5
+ const folderTrace = path.split(_V.FILE_DELIMITER).filter(each => '' !== each);
6
+ const folderInfo = [];
7
+ folderTrace.forEach((trace, index) => {
8
+ const formatted = `${_V.FILE_DELIMITER}${trace}`;
9
+ const previous = folderInfo[index - 1];
10
+ let item = null;
11
+ if (previous) {
12
+ item = `${previous}${formatted}`;
13
+ } else {
14
+ if (os.platform() === 'win32') {
15
+ item = `${trace}`
16
+ } else {
17
+ item = `${formatted}`;
18
+ }
19
+ }
20
+ folderInfo.push(item);
21
+ });
22
+ return folderInfo
23
+ };
24
+ const findMaxFields = (array = []) => {
25
+ let keys = {};
26
+ for (let idx = 0; idx < array.length; idx++) {
27
+ const length = Object.keys(array[idx]).length;
28
+ if (length > Object.keys(keys).length) {
29
+ keys = array[idx];
30
+ }
31
+ }
32
+ return Object.keys(keys);
33
+ };
34
+ module.exports = {
35
+ findTrace,
36
+ findMaxFields,
37
+ }
@@ -0,0 +1,143 @@
1
+ const U = require('underscore');
2
+
3
+ // Import
4
+ const __LOG = require('./momo.fn.log');
5
+ const __EC = require('./momo.v.errorcode');
6
+
7
+ const fxCond = (arg) => {
8
+ if (U.isFunction(arg)) {
9
+ arg = arg();
10
+ }
11
+ return arg;
12
+ };
13
+ const sortString = (left = "", right = "", asc = true) => {
14
+ const minLen = Math.max(left.length, right.length);
15
+ let order = 0;
16
+ for (let idx = 0; idx < minLen; idx++) {
17
+ let leftCode = left.charCodeAt(idx);
18
+ let rightCode = right.charCodeAt(idx);
19
+ // 空白的处理
20
+ if (leftCode !== rightCode) {
21
+ // 修正长度不等的时候的基础算法
22
+ if (isNaN(leftCode)) leftCode = 0;
23
+ if (isNaN(rightCode)) rightCode = 0;
24
+ if (asc) {
25
+ order = leftCode - rightCode;
26
+ } else {
27
+ order = rightCode - leftCode;
28
+ }
29
+ break;
30
+ }
31
+ }
32
+ return order;
33
+ };
34
+ /**
35
+ * ## `Ec.fxContinue`
36
+ *
37
+ * ### 1. 基本介绍
38
+ *
39
+ * 专用二分函数,条件满足时执行`executor`函数,示例代码如:
40
+ *
41
+ * ```js
42
+ * Fx.fxContinue(0 < items.length, () => {
43
+ * const prefixes = inflect.pluralize(prefix);
44
+ * result[prefixes] = items;
45
+ * });
46
+ * ```
47
+ *
48
+ * @memberOf module:_debug
49
+ * @param {Boolean/Function} condition 条件或条件函数。
50
+ * @param {Function} executor 满足条件时的执行函数。
51
+ * @returns 如果有executor则返回该函数的执行返回值。
52
+ */
53
+ const fxContinue = (condition, executor) => {
54
+ if (fxCond(condition) && U.isFunction(executor)) {
55
+ return executor();
56
+ }
57
+ };
58
+ /**
59
+ * ## `Ec.fxSorter`
60
+ *
61
+ * 「调试专用」对输入对象按属性执行字典序的排列,生成新的对象,方便打印和查看对象基本信息。
62
+ *
63
+ * @memberOf module:_debug
64
+ * @param {Object} input 输入排序之前的对象
65
+ * @returns {Object} 返回排序后的对象
66
+ */
67
+ const fxSorter = (input = {}) => {
68
+ const normalized = {};
69
+ const keys = Object.keys(input).sort((left, right) => sortString(left, right, true));
70
+ keys.forEach(key => normalized[key] = input[key]);
71
+ return normalized;
72
+ };
73
+ /**
74
+ * ## `Ec.fxError`
75
+ *
76
+ * ### 1. 基本介绍
77
+ *
78
+ * 参考下边调用代码
79
+ *
80
+ * ```js
81
+ * // 第一种调用方法:第一参直接是错误代码
82
+ * Ec.fxError(10001, arg1, arg2);
83
+ *
84
+ * // 第二种调用方法:第一参是Boolean值,true就输出,第二参是错误代码
85
+ * const checked = true;
86
+ * Ec.fxError(checked, 10001, arg1, arg2);
87
+ *
88
+ * // 第三种调用方法:第一参是Function,执行后结果为true就输出,第二参是错误代码
89
+ * const fnChecked = () => true;
90
+ * Ec.fxError(fnChecked, 10001, arg1, arg2);
91
+ * ```
92
+ *
93
+ * ### 2. 注意点
94
+ *
95
+ * * 第一个参数有三种形态,带条件的有两种形态:Boolean/Function,不带条件时直接表示错误代码。
96
+ * * 第二个参数会受到第一个参数的影响,要么错误代码,要么剩余参数的首参。
97
+ *
98
+ * @memberOf module:_debug
99
+ * @param {Boolean/Function/Number} cond 条件,条件函数和错误代码。
100
+ * @param {*} code 错误代码或首参。
101
+ * @param {*} args 返回剩余参数信息。
102
+ */
103
+ const fxError = (cond, code, ...args) => {
104
+ /*
105
+ * 先提取输入参数
106
+ * 1. cond 为 Number
107
+ * 2. cond 为 Boolean, code 为 Number
108
+ */
109
+ let checked = false;
110
+ let fnMessage;
111
+ const inputArgs = [];
112
+ if (U.isFunction(cond)) {
113
+ checked = cond();
114
+ const fnError = `fn${code}`;
115
+ fnMessage = __EC[fnError];
116
+
117
+ } else if (U.isBoolean(cond)) {
118
+ checked = cond;
119
+ const fnError = `fn${code}`;
120
+ fnMessage = __EC[fnError];
121
+ } else if (U.isNumber(cond)) {
122
+ checked = true;
123
+ const fnError = `fn${cond}`;
124
+ fnMessage = __EC[fnError];
125
+ inputArgs.push(code);
126
+ }
127
+ if (U.isFunction(fnMessage)) {
128
+ if (checked) {
129
+ args.forEach(arg => inputArgs.push(arg));
130
+ const errorMessage = fnMessage.apply(this, inputArgs);
131
+ __LOG.error(errorMessage);
132
+ console.error(errorMessage);
133
+ throw new Error(`错误:${errorMessage}`);
134
+ }
135
+ } else {
136
+ throw new Error(`找不到错误代码描述:${code}`);
137
+ }
138
+ }
139
+ module.exports = {
140
+ fxError,
141
+ fxSorter,
142
+ fxContinue,
143
+ };
@@ -0,0 +1,157 @@
1
+ const fs = require('fs');
2
+ const U = require("underscore");
3
+ const path = require("path");
4
+
5
+ // Import
6
+ const __TO = require("./momo.fn.to");
7
+ const __IS = require('./momo.fn.is');
8
+ const __V = require('./momo.v.constant');
9
+ const __ELE = require("./momo.fn.element");
10
+
11
+ const __CX = require('./momo.fn.cx');
12
+ const __FX = require('./momo.fn.fx');
13
+ const __U = require('./momo.fn.find');
14
+ const __OUT = require("./momo.fn.out");
15
+
16
+ const ioJObject = (path) => __IS.isFile(path) ? __TO.toJObject(fs.readFileSync(path, "utf-8")) : {};
17
+ const ioJArray = (path) => __IS.isFile(path) ? __TO.toJArray(fs.readFileSync(path, "utf-8")) : [];
18
+ const ioString = (path) => __IS.isFile(path) ? fs.readFileSync(path, "utf-8") : "";
19
+ const ioStream = (path) => __IS.isFile(path) ? fs.readFileSync(path) : null;
20
+ const ioProp = (path) => {
21
+ if (__IS.isFile(path)) {
22
+ const content = ioString(path);
23
+ const lines = content.split('\n');
24
+ const result = {};
25
+ lines.forEach(line => {
26
+ const kv = line.split('=');
27
+ const key = kv[0] ? kv[0].trim() : undefined;
28
+ const value = kv[1] ? kv[1].trim() : undefined;
29
+ if (key && value) {
30
+ result[key] = value;
31
+ }
32
+ });
33
+ return result;
34
+ } else {
35
+ return {};
36
+ }
37
+ };
38
+ const ioFiles = (folder) => {
39
+ const fileArr = [];
40
+ if (__IS.isDirectory(folder)) {
41
+ const files = fs.readdirSync(folder);
42
+ files.forEach(item => {
43
+ const file = item;
44
+ const path = `${folder}${__V.FILE_DELIMITER}${item}`;
45
+ fileArr.push({file, path})
46
+ });
47
+ }
48
+ return fileArr;
49
+ };
50
+ const ioCsv = (file, separator) => {
51
+ const data = ioString(file).split('\n');
52
+ const header = data.shift();
53
+ const lines = [];
54
+ data.forEach(line => {
55
+ if (line && 0 < line.trim().length) {
56
+ const item = __ELE.elementZip(header.split(separator), line.split(separator), true);
57
+ lines.push(item);
58
+ }
59
+ });
60
+ return lines;
61
+ };
62
+
63
+ const ioName = (path = '.') => {
64
+ const stat = fs.statSync(path);
65
+ if (stat.isDirectory()) {
66
+ return path.substring(path.lastIndexOf(__V.FILE_DELIMITER) + 1);
67
+ }
68
+ };
69
+
70
+ const ioRoot = () => {
71
+ const folderInfo = __U.findTrace(__dirname);
72
+ let root = folderInfo.filter(item => item.endsWith("src"));
73
+ __FX.fxError(1 !== root.length, 10022, __dirname);
74
+ return root[0];
75
+ };
76
+
77
+
78
+ const __ioDeleteDir = (path) => {
79
+ if (fs.existsSync(path)) {
80
+ const etat = fs.statSync(path);
81
+ if (etat.isDirectory()) {
82
+ const children = fs.readdirSync(path);
83
+ if (0 === children.length) {
84
+ fs.rmdirSync(path);
85
+ } else {
86
+ children.forEach(item => {
87
+ const hitted = path + __V.FILE_DELIMITER + item;
88
+ __ioDeleteDir(hitted);
89
+ });
90
+ }
91
+ } else {
92
+ __LOG.info(`删除文件:${path}`);
93
+ fs.unlinkSync(path);
94
+ }
95
+ }
96
+ };
97
+
98
+ const ioCopy = (from, to) => {
99
+ __FX.fxContinue(__IS.isExist(from) && !__IS.isExist(to) && __IS.isFile(from), () => {
100
+ const content = __IO.ioString(from);
101
+ __OUT.outString(to, content);
102
+ });
103
+ };
104
+
105
+ const ioDelete = (path) => {
106
+ __FX.fxError(__V.FILE_DELIMITER === path.trim(), 10024, path);
107
+ __ioDeleteDir(path);
108
+ };
109
+
110
+ const ioDataA = (path) => {
111
+ // 先读取数据信息
112
+ __CX.cxExist(path);
113
+ const content = ioString(path);
114
+ try {
115
+ const parsed = JSON.parse(content);
116
+ if (U.isArray(parsed)) {
117
+ return parsed;
118
+ } else {
119
+ if (parsed.data && U.isArray(parsed.data)) {
120
+ return parsed.data;
121
+ } else {
122
+ return [];
123
+ }
124
+ }
125
+ } catch (error) {
126
+ return [];
127
+ }
128
+ }
129
+ const ioSwitch = (pathDir = ".") => {
130
+ // 截取当前运行目录
131
+ let pathStart;
132
+ if (pathDir.startsWith("/")) {
133
+ pathStart = pathDir;
134
+ } else {
135
+ pathStart = path.resolve(process.cwd(), pathDir);
136
+ }
137
+ return pathStart;
138
+ }
139
+ module.exports = {
140
+ ioJArray,
141
+ ioJObject,
142
+ ioString,
143
+ ioStream,
144
+ ioProp,
145
+ ioFiles,
146
+ ioCsv,
147
+
148
+
149
+ ioName,
150
+ ioRoot,
151
+ ioDataA,
152
+ ioSwitch,
153
+
154
+
155
+ ioCopy,
156
+ ioDelete,
157
+ }
@@ -0,0 +1,20 @@
1
+ const fs = require('fs');
2
+ const U = require("underscore");
3
+ const isFile = (path) => {
4
+ if (fs.existsSync(path)) {
5
+ return fs.statSync(path).isFile();
6
+ }
7
+ };
8
+ const isDirectory = (path) => {
9
+ if (fs.existsSync(path)) {
10
+ return fs.statSync(path).isDirectory();
11
+ }
12
+ };
13
+ const isExist = (path) => fs.existsSync(path);
14
+
15
+ module.exports = {
16
+ isExist,
17
+ isFile,
18
+ isDirectory,
19
+ isFunction: (input) => U.isFunction(input),
20
+ }
@@ -0,0 +1,118 @@
1
+ const U = require('underscore');
2
+ const fs = require('fs');
3
+ const inflect = require('i')();
4
+
5
+ // Import
6
+ const __FX = require('./momo.fn.fx');
7
+ const __LOG = require('./momo.fn.log');
8
+ const __V = require('./momo.v.constant');
9
+
10
+ const _eachFn = (executor, callback, method = "") => {
11
+ if (U.isFunction(executor)) {
12
+ return callback();
13
+ } else {
14
+ __LOG.warn(`[Zero AI] (${method}) The 'executor' argument must be function, but now ${executor}`);
15
+ }
16
+ };
17
+
18
+ const itPair = (first = [], second = [], executor = () => {
19
+ }) => {
20
+ const length = first.length > second.length ? first.length : second.length;
21
+ _eachFn(executor, () => {
22
+ for (let idx = 0; idx < length; idx++) {
23
+ const firstArg = first[idx];
24
+ const secondArg = second[idx];
25
+ executor(firstArg, secondArg, idx);
26
+ }
27
+ }, "itPair")
28
+ };
29
+
30
+ const itObject = (object = {}, executor = () => {
31
+ }) => {
32
+ const target = {};
33
+ _eachFn(executor, () => {
34
+ for (const key in object) {
35
+ if (object.hasOwnProperty(key)) {
36
+ const value = object[key];
37
+ target[key] = executor(key, value)
38
+ }
39
+ }
40
+ }, "itObject");
41
+ return target;
42
+ };
43
+ /**
44
+ * ## `Ec.itArray`
45
+ *
46
+ * ### 1. 基本介绍
47
+ *
48
+ * 迭代输入的数组,然后执行函数`executor`,该函数签名如下,它有两个参数:
49
+ *
50
+ * ```js
51
+ * function(item, index){
52
+ *
53
+ * }
54
+ * ```
55
+ *
56
+ * ### 2. 内置参数
57
+ *
58
+ * |参数|类型|含义|
59
+ * |---|---|:---|
60
+ * |item|`Object/<Any>`|每一个数组中的元素,任意类型。|
61
+ * |index|Number|该元素在数组中的索引值。|
62
+ *
63
+ * @memberOf module:_epic
64
+ * @param {Array} array 被迭代的数组
65
+ * @param {Function} executor 第二参数,必须是一个标准的JavaScript函数
66
+ * @returns {Array} 返回执行完成后的数组
67
+ */
68
+ const itArray = (array = [], executor = () => {
69
+ }) => {
70
+ const target = [];
71
+ _eachFn(executor, () => array.forEach((item, index) => {
72
+ const each = executor(item, index);
73
+ target.push(each);
74
+ }), "itArray");
75
+ return target;
76
+ };
77
+
78
+ const itFileSync = (path = "", callback) => {
79
+ if (fs.existsSync(path)) {
80
+ const etat = fs.statSync(path);
81
+ if (etat.isDirectory()) {
82
+ const dir = fs.readdirSync(path);
83
+ itArray(dir, (item) => __FX.fxContinue(!item.startsWith('_') && !item.startsWith('.'), () => {
84
+ let divider = path.endsWith(__V.FILE_DELIMITER) ? "" : __V.FILE_DELIMITER;
85
+ let hitFile = path + divider + item;
86
+ itFileSync(hitFile, callback);
87
+ }))
88
+ } else {
89
+ callback(path);
90
+ }
91
+ } else {
92
+ __LOG.warn(`路径不存在:${path}`)
93
+ }
94
+ };
95
+
96
+ const itCompress = (object = {}, prefix = "") => {
97
+ const items = [];
98
+ const result = {};
99
+ itObject(object, (key, value) => {
100
+ if (key.startsWith(prefix)) {
101
+ items.push(value);
102
+ } else {
103
+ result[key] = value;
104
+ }
105
+ });
106
+ __FX.fxContinue(0 < items.length, () => {
107
+ const prefixes = inflect.pluralize(prefix);
108
+ result[prefixes] = items;
109
+ });
110
+ return result;
111
+ };
112
+ module.exports = {
113
+ itPair,
114
+ itCompress,
115
+ itFileSync,
116
+ itObject,
117
+ itArray
118
+ };
@@ -0,0 +1,50 @@
1
+ const colors = require("colors");
2
+ const readline = require("readline");
3
+
4
+ colors.setTheme({
5
+ silly: 'rainbow',
6
+ input: 'grey',
7
+ verbose: 'cyan',
8
+ prompt: 'red',
9
+ info: 'green',
10
+ data: 'blue',
11
+ help: 'cyan',
12
+ warn: 'yellow',
13
+ debug: 'magenta',
14
+ error: 'red'
15
+ });
16
+
17
+ // 创建 readline 接口实例
18
+ const _rl = readline.createInterface({
19
+ input: process.stdin,
20
+ output: process.stdout
21
+ });
22
+
23
+ const error = (message = '') => console.error(`[Momo ER] `.red.bold + `${message}`.red);
24
+ const info = (message = '') => console.info(`[Momo AI]`.green.bold + ` ${message ? message : ''}`);
25
+ const execute = (message = '') => console.info(`[Momo AI]`.blue.bold + ` ${message ? message : ''}`);
26
+ const warn = (message = '') => console.warn(`[Momo AI]`.yellow.bold + ` ${message}`.yellow);
27
+
28
+ // 询问用户输入的函数
29
+ const ask = (question) => {
30
+ const askQ = `[Momo AI] `.blue.bold + `${question}`.yellow;
31
+ return new Promise((resolve) => {
32
+ _rl.question(askQ, (answer) => {
33
+ resolve(answer);
34
+ });
35
+ });
36
+ };
37
+
38
+ // 关闭 readline 接口
39
+ const askClose = () => {
40
+ _rl.close();
41
+ };
42
+
43
+ module.exports = {
44
+ execute,
45
+ info,
46
+ warn,
47
+ error,
48
+ ask,
49
+ askClose
50
+ };
@@ -0,0 +1,47 @@
1
+ const fs = require('fs');
2
+ const os = require("os");
3
+
4
+ const __LOG = require("./momo.fn.log");
5
+ const __FX = require("./momo.fn.fx");
6
+
7
+ const __outFile = (paths, content, sync) => {
8
+ if (sync) {
9
+ fs.writeFileSync(paths, content);
10
+ __LOG.info(`(Sync)成功将数据写入到文件:${paths.cyan}!`);
11
+ } else {
12
+ fs.writeFile(paths, content, (res) => {
13
+ __LOG.info(`(Async)成功将数据写入到文件:${paths.cyan}!`);
14
+ });
15
+ }
16
+ };
17
+
18
+ const outJson = (paths, content, sync = false) => __FX.fxContinue(!!content, () => __outFile(paths, JSON.stringify(content, null, 4), sync));
19
+ const outString = (paths, content, sync = false) => __FX.fxContinue(!!content, () => __outFile(paths, content, sync));
20
+
21
+
22
+ const outCopy = (data) => new Promise(function (resolve, reject) {
23
+ const platform = os.platform();
24
+ let cmd = '';
25
+ if (os.platform() === 'win32') {
26
+ cmd = 'clip';
27
+ } else if (os.platform() === 'darwin') {
28
+ cmd = 'pbcopy';
29
+ } else {
30
+ __FX.fxError(10032, platform);
31
+ }
32
+
33
+ const proc = require('child_process').spawn(cmd);
34
+ proc.on('error', function (err) {
35
+ reject(err);
36
+ });
37
+ proc.on('close', function (err) {
38
+ resolve();
39
+ });
40
+ proc.stdin.write(data);
41
+ proc.stdin.end();
42
+ });
43
+ module.exports = {
44
+ outCopy,
45
+ outString,
46
+ outJson,
47
+ }
@@ -0,0 +1,26 @@
1
+ const sortString = (left = "", right = "", asc = true) => {
2
+ const minLen = Math.max(left.length, right.length);
3
+ let order = 0;
4
+ for (let idx = 0; idx < minLen; idx++) {
5
+ let leftCode = left.charCodeAt(idx);
6
+ let rightCode = right.charCodeAt(idx);
7
+ // 空白的处理
8
+ if (leftCode !== rightCode) {
9
+ // 修正长度不等的时候的基础算法
10
+ if (isNaN(leftCode)) leftCode = 0;
11
+ if (isNaN(rightCode)) rightCode = 0;
12
+ if (asc) {
13
+ order = leftCode - rightCode;
14
+ } else {
15
+ order = rightCode - leftCode;
16
+ }
17
+ break;
18
+ }
19
+ }
20
+ return order;
21
+ };
22
+
23
+ module.exports = {
24
+ sorterSAsc: (left, right) => sortString(left, right, true),
25
+ sorterSDesc: (left, right) => sortString(left, right, false),
26
+ }
@@ -0,0 +1,63 @@
1
+ const {v4} = require("uuid");
2
+ const Mock = require('mockjs');
3
+ const CryptoJS = require('crypto-js');
4
+ const __V = require("./momo.v.constant");
5
+ const strFirstUpper = (value = "") =>
6
+ value.substr(0, 1).toUpperCase() + value.substr(1, value.length);
7
+ const strSlashCount = (literal = "") => {
8
+ let counter = 0;
9
+ for (let idx = 0; idx < literal.length; idx++) {
10
+ if (__V.FILE_DELIMITER === literal.charAt(idx)) {
11
+ counter++;
12
+ }
13
+ }
14
+ return counter;
15
+ };
16
+ const strShapeCount = (literal = "") => {
17
+ let counter = 0;
18
+ for (let idx = 0; idx < literal.length; idx++) {
19
+ if ("#" === literal.charAt(idx)) {
20
+ counter++;
21
+ }
22
+ }
23
+ return counter;
24
+ }
25
+ const strUuid = () => v4();
26
+ // 去掉混淆子母
27
+ const strRandom = (length = 64, full = false) => {
28
+ if (full) {
29
+ return Mock.Random.string("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", length);
30
+ } else {
31
+ return Mock.Random.string("ABCDEFGHJKLMNPQRSTUVWXYZ123456789", length);
32
+ }
33
+ }
34
+
35
+ const strWidth = (input = "") => {
36
+ let content = "";
37
+ const space = 16 - input.length;
38
+ for (let i = 0; i < space; i++) {
39
+ content += " ";
40
+ }
41
+ return content + input;
42
+ }
43
+ const strExpr = (content, params = {}) => {
44
+ Object.keys(params).forEach(name => {
45
+ const expression = new RegExp(`#${name}#`, 'g');
46
+ content = content.replace(expression, params[name]);
47
+ });
48
+ return content;
49
+ }
50
+ const strMD5 = (content) => {
51
+ return CryptoJS.MD5(String(content)).toString().toUpperCase();
52
+ }
53
+ module.exports = {
54
+ strFirstUpper,
55
+ strSlashCount,
56
+ strShapeCount,
57
+ strUuid,
58
+ strWidth,
59
+ strExpr,
60
+ strRandom,
61
+ strMD5,
62
+ SEPARATOR: __V.FILE_DELIMITER,
63
+ };