@lm_fe/scripts 0.1.201

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # yargs-parser
2
+
3
+
4
+
5
+ The mighty option parser used by.
6
+
7
+
8
+
9
+
10
+ ## Example
11
+
12
+ ```sh
13
+ npm i yargs-parser --save
14
+ ```
15
+
16
+
17
+ **Node.js:**
18
+
19
+ ```js
20
+ import parser from 'yargs-parser'
21
+
22
+ const argv = parser('--foo=99 --bar=9987930', {
23
+ string: ['bar']
24
+ })
25
+ console.log(argv)
26
+ ```
27
+
28
+
29
+ ## License
30
+
31
+ ISC
@@ -0,0 +1,6 @@
1
+ import { FormInstance } from "antd";
2
+ interface IProps {
3
+ form?: FormInstance;
4
+ }
5
+ declare const _default: (props: IProps) => any;
6
+ export default _default;
@@ -0,0 +1,40 @@
1
+
2
+ import { mchcEnv } from '@lm_fe/env'
3
+ import { MyFormSectionForm, MyFormSection } from "@lm_fe/components_m";
4
+ import { mchcEvent } from "@lm_fe/env";
5
+ import { Form, FormInstance } from "antd";
6
+ import React, { useEffect, useState } from "react";
7
+ /*[import1]*/
8
+ interface IProps {
9
+ form?: FormInstance
10
+ }
11
+ interface IDataShape {
12
+ name: string
13
+ }
14
+
15
+ /*[lazy]*/
16
+
17
+
18
+ export default (props: IProps) => {
19
+ /*[import2]*/
20
+ const [_form] = Form.useForm()
21
+ const form = props.form ?? _form
22
+
23
+ useEffect(() => {
24
+ const rm = mchcEvent.on_rm('my_form', e => {
25
+ // mchcEnv.logger.log('event receive', { e })
26
+ if (e.type === 'onChange') {
27
+
28
+ }
29
+ else if (e.type === 'onClick') {
30
+
31
+ }
32
+ })
33
+ return rm
34
+ }, [])
35
+
36
+ //@ts-ignore
37
+ return <MyFormSectionForm<IDataShape> formDescriptions={load_form_config} form={form} onValuesChange={(changedValues, values) => { }} />
38
+ // return <Form form={form}><MyFormSection formDescriptions={load_form_config} form={form} /></Form>
39
+
40
+ }
@@ -0,0 +1,3 @@
1
+ export declare function resolvePagesWithRoutes(names: string[]): {
2
+ [x: string]: any;
3
+ };
@@ -0,0 +1,10 @@
1
+ import { FC, lazy, LazyExoticComponent, ComponentType } from 'react';
2
+ type TC = LazyExoticComponent<ComponentType> | FC
3
+ export function resolvePagesWithRoutes(names: string[]) {
4
+ return names.reduce((a, b) => {
5
+ const isLazy = b.includes('index.ts')
6
+ const routePath = b.replace(/\/index(.nl)??.tsx/, '')
7
+ const C = isLazy ? lazy(() => import(`#@/pages-with-routes#${b}`)) : require(`#@/pages-with-routes#${b}`).default as FC
8
+ return ({ ...a, [routePath.toLocaleLowerCase()]: C })
9
+ }, {} as { [x: string]: TC })
10
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ export declare function warnLogImpl(txt: string): void;
2
+ export declare function successLogImpl(txt: string): void;
3
+ export declare function findEntries(base_path: string, create?: boolean): string[] | undefined;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ export declare function getArgs(): {
2
+ rm: string;
3
+ target: string;
4
+ names: string;
5
+ nolazy: string;
6
+ } | null;
7
+ export declare function warnLogImpl(txt: string): void;
8
+ export declare function successLogImpl(txt: string): void;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,18 @@
1
+ export declare const ANNOTATION = "// \u8FD9\u4E2A\u6587\u4EF6\u662F\u751F\u6210\u7684\uFF0C\u8BF7\u4E0D\u8981\u624B\u52A8\u4FEE\u6539";
2
+ export declare const USAGE = "usage: gen-routes --source=/src/pages --target=/src/routes/meta.ts [--withmd] [--underline] [--help]";
3
+ export declare function getArgs(): {
4
+ source: any;
5
+ target: any;
6
+ withmd: any;
7
+ underline: any;
8
+ };
9
+ export declare function convertUnderlineType(item: string): string;
10
+ export declare function warnLogImpl(txt: string): void;
11
+ export declare function successLogImpl(txt: string): void;
12
+ export declare function findRouteEntry({ sourcePath, prefix, maxLevel, entryPath, excludePath }: {
13
+ sourcePath?: string | undefined;
14
+ prefix?: string | undefined;
15
+ maxLevel?: number | undefined;
16
+ entryPath?: string[] | undefined;
17
+ excludePath?: string[] | undefined;
18
+ }): string[];
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
5
+ var argsParse = require('yargs-parser');
6
+ var index = require('./index-1deed0e0.js');
7
+ require('fs');
8
+ require('json2md');
9
+ require('path');
10
+ require('dayjs');
11
+ require('chalk');
12
+ function _interopDefaultLegacy(e) {
13
+ return e && _typeof(e) === 'object' && 'default' in e ? e : {
14
+ 'default': e
15
+ };
16
+ }
17
+ var argsParse__default = /*#__PURE__*/_interopDefaultLegacy(argsParse);
18
+ var argv = argsParse__default["default"](process.argv.slice(2));
19
+ var _ = argv._,
20
+ color = argv.color,
21
+ who = argv.who;
22
+ function main() {
23
+ index.colorLog(_.join(' '), who, color);
24
+ }
25
+ main();
@@ -0,0 +1,76 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
5
+ var fs = require('fs');
6
+ var path = require('path');
7
+ var argsParse = require('yargs-parser');
8
+ var index = require('./index-1deed0e0.js');
9
+ require('json2md');
10
+ require('dayjs');
11
+ require('chalk');
12
+ function _interopDefaultLegacy(e) {
13
+ return e && _typeof(e) === 'object' && 'default' in e ? e : {
14
+ 'default': e
15
+ };
16
+ }
17
+ var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
18
+ var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
19
+ var argsParse__default = /*#__PURE__*/_interopDefaultLegacy(argsParse);
20
+ var who = 'copy-static';
21
+ function warnLogImpl(txt) {
22
+ index.warnLog(txt, who);
23
+ }
24
+ function successLogImpl(txt) {
25
+ index.successLog(txt, who);
26
+ }
27
+ function findEntries(base_path) {
28
+ var create = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
29
+ var exists = fs__default["default"].existsSync(base_path);
30
+ if (!exists) {
31
+ if (create) {
32
+ fs__default["default"].mkdirSync(base_path);
33
+ return [];
34
+ }
35
+ index.colorLog("".concat(base_path, " \u4E0D\u5B58\u5728\uFF01"), 'bgRed');
36
+ return;
37
+ }
38
+ var stat = fs__default["default"].statSync(base_path);
39
+ if (!stat.isDirectory()) {
40
+ index.colorLog("".concat(base_path, " \u4E0D\u662F\u6587\u4EF6\u5939\uFF01"), 'bgRed');
41
+ return;
42
+ }
43
+ var assertNames = fs__default["default"].readdirSync(base_path);
44
+ return assertNames;
45
+ }
46
+ var argv = argsParse__default["default"](process.argv.slice(2));
47
+ var _argv$target = argv.target,
48
+ target = _argv$target === void 0 ? '/public' : _argv$target,
49
+ _argv$silent = argv.silent,
50
+ silent = _argv$silent === void 0 ? false : _argv$silent;
51
+ var static_path = path__default["default"].resolve(process.cwd() + '/node_modules/@lm_fe/static/asserts');
52
+ var public_path = path__default["default"].resolve(process.cwd() + target);
53
+ function doit() {
54
+ var staticAssertNames = findEntries(static_path);
55
+ if (!staticAssertNames) return warnLogImpl("\u89E3\u6790".concat(static_path, " \u51FA\u9519\uFF01"));
56
+ var publicAssertNames = findEntries(public_path, true);
57
+ if (!publicAssertNames) return warnLogImpl("\u89E3\u6790".concat(public_path, " \u51FA\u9519\uFF01"));
58
+ staticAssertNames.forEach(function (n) {
59
+ var srcDirPath = path__default["default"].resolve(static_path, n);
60
+ var dstDirPath = path__default["default"].resolve(public_path, n);
61
+ if (publicAssertNames.includes(n)) return warnLogImpl("".concat(dstDirPath, " \u5DF2\u5B58\u5728\uFF01"));
62
+ fs__default["default"].cp(srcDirPath, dstDirPath, {
63
+ recursive: true
64
+ }, function (err) {
65
+ if (err) {
66
+ warnLogImpl("cp \u51FA\u9519: ".concat(err));
67
+ } else {
68
+ successLogImpl("\u590D\u5236 ".concat(dstDirPath, " \u6210\u529F\uFF01"));
69
+ }
70
+ });
71
+ });
72
+ }
73
+ function main() {
74
+ doit();
75
+ }
76
+ main();
@@ -0,0 +1,102 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
5
+ var fs = require('fs');
6
+ var path = require('path');
7
+ var index = require('./index-1deed0e0.js');
8
+ var argsParse = require('yargs-parser');
9
+ require('json2md');
10
+ require('dayjs');
11
+ require('chalk');
12
+ function _interopDefaultLegacy(e) {
13
+ return e && _typeof(e) === 'object' && 'default' in e ? e : {
14
+ 'default': e
15
+ };
16
+ }
17
+ var argsParse__default = /*#__PURE__*/_interopDefaultLegacy(argsParse);
18
+ var who = 'gen-form-config';
19
+ var argv = argsParse__default["default"](process.argv.slice(2));
20
+ var USAGE = "usage: [--rm] [--nolazy] [--help] [--target=\u76EE\u6807\u6587\u4EF6\u5939] [--names=\u5E7F\u4E09,\u534E\u533B]";
21
+ function getArgs() {
22
+ var rm = argv.rm,
23
+ help = argv.help,
24
+ target = argv.target,
25
+ names = argv.names,
26
+ nolazy = argv.nolazy;
27
+ if (help) {
28
+ successLogImpl(USAGE);
29
+ successLogImpl(JSON.stringify({
30
+ cwd: process.cwd(),
31
+ argv: process.argv,
32
+ names: names
33
+ }, null, 2));
34
+ return null;
35
+ }
36
+ return {
37
+ rm: rm,
38
+ target: target,
39
+ names: names,
40
+ nolazy: nolazy
41
+ };
42
+ }
43
+ function warnLogImpl(txt) {
44
+ index.warnLog(txt, who);
45
+ }
46
+ function successLogImpl(txt) {
47
+ index.successLog(txt, who);
48
+ }
49
+ var args = getArgs();
50
+ var DIR_NAME = 'form_config';
51
+ var ENV_LIST = ['华医', '南医增城', '广三', '越秀妇幼', '建瓯'];
52
+ var FOMR_CONFIG_TEMPLATE = function FOMR_CONFIG_TEMPLATE() {
53
+ return "\nimport { defineFormConfig } from \"@lm_fe/service\";\n\nexport default defineFormConfig([])\n";
54
+ };
55
+ var LOAD_FORM_TEMPLATE = function LOAD_FORM_TEMPLATE(env_list) {
56
+ return "\nexport function load_form_config() {\n".concat(env_list.map(function (e) {
57
+ return " if (mchcEnv.is('".concat(e, "')) return import('./").concat(e, "')");
58
+ }).join('\r\n'), "\n return import('./default')\n}\n");
59
+ };
60
+ var LOAD_FORM_IMPORT = function LOAD_FORM_IMPORT(env_list) {
61
+ return "\n".concat(env_list.map(function (e) {
62
+ return "import { default as ".concat(e, "_config } from './").concat(e, "'");
63
+ }).join('\r\n'), "\nimport { default as default_config } from './default'\n");
64
+ };
65
+ function main() {
66
+ var _ref;
67
+ var _names$split;
68
+ if (!args) return;
69
+ var rm = args.rm,
70
+ target = args.target,
71
+ names = args.names,
72
+ nolazy = args.nolazy;
73
+ var target_dir_name = target || DIR_NAME;
74
+ var target_dir_path = path.resolve(process.cwd(), target_dir_name);
75
+ var is_exists = fs.existsSync(target_dir_path);
76
+ var _env_list = names ? (_ref = names === null || names === void 0 || (_names$split = names.split) === null || _names$split === void 0 ? void 0 : _names$split.call(names, ',')) !== null && _ref !== void 0 ? _ref : ENV_LIST : ENV_LIST;
77
+ var env_list = _env_list.filter(function (_) {
78
+ return _;
79
+ }).map(function (_) {
80
+ return _.trim();
81
+ });
82
+ if (rm) {
83
+ if (!is_exists) return warnLogImpl("".concat(target_dir_path, " \u4E0D\u5B58\u5728!!"));
84
+ fs.rmSync(target_dir_path, {
85
+ recursive: true
86
+ });
87
+ return successLogImpl("".concat(target_dir_path, " \u5220\u9664\u6210\u529F!! \u2705"));
88
+ }
89
+ if (is_exists) return warnLogImpl("".concat(target_dir_path, " \u5DF2\u5B58\u5728!!"));
90
+ fs.mkdirSync(target_dir_path);
91
+ env_list.forEach(function (_) {
92
+ var r_path = path.resolve(target_dir_path, "".concat(_, ".tsx"));
93
+ fs.appendFileSync(r_path, FOMR_CONFIG_TEMPLATE());
94
+ });
95
+ fs.appendFileSync(path.resolve(target_dir_path, "default.tsx"), FOMR_CONFIG_TEMPLATE());
96
+ // copyFileSync(resolve(__dirname, `asserts/form_config_tpl.tsx`), resolve(target_dir_path, `default.tsx`))
97
+ var tplStr = fs.readFileSync(path.resolve(__dirname, "asserts/form_config_tpl.tsx")).toString().replace('/*[lazy]*/', nolazy ? '' : LOAD_FORM_TEMPLATE(env_list)).replace('/*[import1]*/', nolazy ? LOAD_FORM_IMPORT(env_list) : '').replace('/*[import2]*/', nolazy ? ' const [load_form_config, set_load_form_config] = useState(default_config)' : '');
98
+ // appendFileSync(resolve(target_dir_path, `index.tsx`), LOAD_FORM_TEMPLATE(env_list))
99
+ fs.appendFileSync(path.resolve(target_dir_path, "Form.tsx"), tplStr);
100
+ successLogImpl("".concat(target_dir_path, " \u751F\u6210\u6210\u529F!! \u2705"));
101
+ }
102
+ main();
@@ -0,0 +1,176 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
5
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
6
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
7
+ function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
8
+ function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
9
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
10
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
11
+ var fs = require('fs');
12
+ var path = require('path');
13
+ var index = require('./index-1deed0e0.js');
14
+ var argsParse = require('yargs-parser');
15
+ require('json2md');
16
+ require('dayjs');
17
+ require('chalk');
18
+ function _interopDefaultLegacy(e) {
19
+ return e && _typeof(e) === 'object' && 'default' in e ? e : {
20
+ 'default': e
21
+ };
22
+ }
23
+ var argsParse__default = /*#__PURE__*/_interopDefaultLegacy(argsParse);
24
+ var MAX_LEVEL = 999;
25
+ var EXCLUDE_PATH = ['components', 'copy'];
26
+ var PREFIX = '';
27
+ var ENTRYPATH = ['index.tsx', 'index.nl.tsx'];
28
+ var who = 'gen-routes';
29
+ var argv = argsParse__default["default"](process.argv.slice(2));
30
+ var ANNOTATION = '// 这个文件是生成的,请不要手动修改';
31
+ var USAGE = "usage: gen-routes --source=/src/pages --target=/src/routes/meta.ts [--withmd] [--underline] [--help]";
32
+ function getArgs() {
33
+ var source = argv.source,
34
+ target = argv.target,
35
+ withmd = argv.withmd,
36
+ underline = argv.underline,
37
+ help = argv.help;
38
+ if (!source || !target) {
39
+ source = source !== null && source !== void 0 ? source : './src/pages-with-routes';
40
+ target = target !== null && target !== void 0 ? target : './src/routes/meta.ts';
41
+ warnLogImpl("default: source =====> ".concat(source, " , target =====> ").concat(target));
42
+ }
43
+ if (help) {
44
+ successLogImpl(USAGE);
45
+ }
46
+ return {
47
+ source: source,
48
+ target: target,
49
+ withmd: withmd,
50
+ underline: underline
51
+ };
52
+ }
53
+ function convertUnderlineType(item) {
54
+ return item.split('/').filter(function (_) {
55
+ return !['', '.'].includes(_);
56
+ }).join('_');
57
+ }
58
+ function warnLogImpl(txt) {
59
+ index.warnLog(txt, who);
60
+ }
61
+ function successLogImpl(txt) {
62
+ index.successLog(txt, who);
63
+ }
64
+ function findRouteEntry(_ref) {
65
+ var _ref$sourcePath = _ref.sourcePath,
66
+ sourcePath = _ref$sourcePath === void 0 ? "" : _ref$sourcePath,
67
+ _ref$prefix = _ref.prefix,
68
+ prefix = _ref$prefix === void 0 ? PREFIX : _ref$prefix,
69
+ _ref$maxLevel = _ref.maxLevel,
70
+ maxLevel = _ref$maxLevel === void 0 ? MAX_LEVEL : _ref$maxLevel,
71
+ _ref$entryPath = _ref.entryPath,
72
+ entryPath = _ref$entryPath === void 0 ? ENTRYPATH : _ref$entryPath,
73
+ _ref$excludePath = _ref.excludePath,
74
+ excludePath = _ref$excludePath === void 0 ? EXCLUDE_PATH : _ref$excludePath;
75
+ if (!sourcePath) return [];
76
+ var rawData = [];
77
+ function finds() {
78
+ var dir = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
79
+ var parentPath = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
80
+ var dirs = fs.readdirSync(dir);
81
+ dirs.forEach(function (dirEntry) {
82
+ var _path = path.resolve(dir, dirEntry);
83
+ var structStat = fs.statSync(_path);
84
+ if (!structStat) return;
85
+ if (structStat.isDirectory()) {
86
+ if (dirEntry.startsWith('.') || excludePath.includes(dirEntry)) return;
87
+ finds(_path, parentPath.concat(dirEntry));
88
+ } else {
89
+ entryPath.includes(dirEntry) && rawData.push([].concat(_toConsumableArray(parentPath), [dirEntry]));
90
+ }
91
+ });
92
+ }
93
+ finds(sourcePath, [prefix]);
94
+ var data = rawData.filter(function (_) {
95
+ return _.length < maxLevel;
96
+ }).sort(function (a, b) {
97
+ return a[0].localeCompare(b[0]);
98
+ }).map(function (_) {
99
+ return _.join('/');
100
+ }).filter(function (routePath) {
101
+ return !!routePath;
102
+ });
103
+ return data;
104
+ }
105
+ var args = getArgs();
106
+ function main() {
107
+ var source = args.source,
108
+ withmd = args.withmd;
109
+ var sourcePath = path.resolve(process.cwd(), source);
110
+ if (!fs.existsSync(sourcePath)) return warnLogImpl("".concat(sourcePath, " \u4E0D\u5B58\u5728"));
111
+ var data = findRouteEntry({
112
+ sourcePath: sourcePath
113
+ });
114
+ writeMeta(data);
115
+ if (withmd) {
116
+ writeMd(data);
117
+ }
118
+ successLogImpl('路由生成✅');
119
+ }
120
+ function rawTemplate() {
121
+ var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
122
+ JSON.stringify(data, null, 2);
123
+ var source = args.source,
124
+ target = args.target,
125
+ underline = args.underline;
126
+ var relativePath = path.relative(path.dirname(target), source).replace('\\', '/');
127
+ relativePath = relativePath.startsWith('.') ? relativePath : "./".concat(relativePath);
128
+ var staticImport = [];
129
+ var _data = data.reduce(function (a, b) {
130
+ var isLazy = b.includes('index.ts');
131
+ var routePath = b.replace(/\/index(.nl)??.tsx/, '').toLocaleLowerCase();
132
+ var keyName = underline ? convertUnderlineType(routePath) : routePath;
133
+ var rawPath = "\"".concat(relativePath).concat(b.replace(/\.tsx/, ''), "\"");
134
+ var moduleName = routePath.slice(routePath.lastIndexOf('/') + 1).split('-').map(function (_) {
135
+ return _.toUpperCase();
136
+ }).join('_');
137
+ if (!isLazy) staticImport.push("import ".concat(moduleName, " from ").concat(rawPath, "\n"));
138
+ var C = isLazy ? "lazy(() => import(".concat(rawPath, "))") : "".concat(moduleName);
139
+ var row = " \"".concat(keyName, "\":").concat(C, ",\n");
140
+ return a + row;
141
+ }, '');
142
+ var importStr = staticImport.reduce(function (a, b) {
143
+ return a + b;
144
+ }, '');
145
+ return "\n".concat(ANNOTATION, "\nimport { FC, lazy, LazyExoticComponent, ComponentType } from 'react'; //\n").concat(importStr, "\nexport type TC = LazyExoticComponent<ComponentType> | FC\n\nexport const routesData = {\n").concat(_data, "}");
146
+ }
147
+ function writeMeta() {
148
+ var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
149
+ var target = args.target;
150
+ var targetPath = path.resolve(process.cwd(), target);
151
+ var buf = rawTemplate(data);
152
+ fs.writeFileSync(targetPath, buf);
153
+ }
154
+ function writeMd() {
155
+ var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
156
+ var source = args.source || '';
157
+ var rowsData = data.reduce(function (a, b) {
158
+ var dir = b.slice(0, b.lastIndexOf('/')).toLowerCase();
159
+ var infoPath = path.resolve("".concat(source).concat(dir), 'info.json');
160
+ var info = {
161
+ name: '缺省'
162
+ };
163
+ try {
164
+ info = require(infoPath);
165
+ } catch (error) {}
166
+ return [].concat(_toConsumableArray(a), [[dir, info.name]]);
167
+ }, []);
168
+ var tableData = {
169
+ table: {
170
+ headers: ['路径', '说明'],
171
+ rows: rowsData
172
+ }
173
+ };
174
+ index.tplMd(data.length ? tableData : null);
175
+ }
176
+ main();
@@ -0,0 +1,64 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
5
+ var fs = require('fs');
6
+ var json2md = require('json2md');
7
+ var path = require('path');
8
+ var dayjs = require('dayjs');
9
+ var chalk = require('chalk');
10
+ function _interopDefaultLegacy(e) {
11
+ return e && _typeof(e) === 'object' && 'default' in e ? e : {
12
+ 'default': e
13
+ };
14
+ }
15
+ var json2md__default = /*#__PURE__*/_interopDefaultLegacy(json2md);
16
+ var dayjs__default = /*#__PURE__*/_interopDefaultLegacy(dayjs);
17
+ var chalk__default = /*#__PURE__*/_interopDefaultLegacy(chalk);
18
+ var colorFnMap = {
19
+ green: chalk__default["default"].green,
20
+ bgGreen: chalk__default["default"].bgGreen,
21
+ yellow: chalk__default["default"].yellow,
22
+ bgYellow: chalk__default["default"].bgYellow,
23
+ red: chalk__default["default"].red,
24
+ bgRed: chalk__default["default"].bgRed,
25
+ blue: chalk__default["default"].blue,
26
+ bgBlue: chalk__default["default"].bgBlue,
27
+ cyan: chalk__default["default"].cyan,
28
+ bgCyan: chalk__default["default"].bgCyan
29
+ };
30
+ function colorLog() {
31
+ var str = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
32
+ var who = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
33
+ var color = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'bgCyan';
34
+ var whoPadding = who ? "".concat(who, ": ") : '';
35
+ var fn = colorFnMap[color];
36
+ if (!fn) return console.info(chalk__default["default"].red("color ".concat(color, " \u4E0D\u5B58\u5728\uFF01")));
37
+ var time = dayjs__default["default"]().format('YYYY-MM-DD HH:mm:ss');
38
+ console.info(fn("[".concat(time, "] ").concat(whoPadding).concat(str)));
39
+ }
40
+ function warnLog(txt, who) {
41
+ colorLog(txt, who, 'yellow');
42
+ }
43
+ function successLog(txt, who) {
44
+ colorLog(txt, who, 'green');
45
+ }
46
+ function tplMd(data) {
47
+ var mdName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'README.md';
48
+ var tplName = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'md.json';
49
+ var targetPath = path.resolve(process.cwd(), mdName);
50
+ var tplPath = path.resolve(process.cwd(), tplName);
51
+ var tpl = require(tplPath);
52
+ var index = tpl.findIndex(function (_) {
53
+ return _ === 'slot';
54
+ });
55
+ tpl.splice(index, 1, data);
56
+ var buf = json2md__default["default"](tpl.filter(function (_) {
57
+ return !!_;
58
+ }));
59
+ fs.writeFileSync(targetPath, buf);
60
+ }
61
+ exports.colorLog = colorLog;
62
+ exports.successLog = successLog;
63
+ exports.tplMd = tplMd;
64
+ exports.warnLog = warnLog;
@@ -0,0 +1,2 @@
1
+ export * from './utils';
2
+ export * from './utils/client_helper';
package/dist/index.js ADDED
@@ -0,0 +1,85 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
5
+ var _excluded = ["WITH_THEME", "APP_NAME", "ENVIRONMENT_MODE", "HOST_URL", "PUBLIC_PATH", "API_PREFIX", "check_version"];
6
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
7
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
8
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
9
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
10
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
11
+ function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
12
+ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
13
+ Object.defineProperty(exports, '__esModule', {
14
+ value: true
15
+ });
16
+ var index = require('./index-1deed0e0.js');
17
+ var fs = require('fs');
18
+ var path = require('path');
19
+ var os = require('os');
20
+ var utils = require('@noah-libjs/utils');
21
+ require('json2md');
22
+ require('dayjs');
23
+ require('chalk');
24
+ var cwd = process.cwd();
25
+ function safe_require(m_path) {
26
+ try {
27
+ return require(m_path);
28
+ } catch (_unused) {}
29
+ try {
30
+ var str = fs.readFileSync(path.resolve(cwd, m_path)).toString();
31
+ return JSON.parse(str);
32
+ } catch (_unused2) {}
33
+ return {};
34
+ }
35
+ function client_macro_record() {
36
+ var x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
37
+ var raw = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
38
+ var _process$env = process.env,
39
+ WITH_THEME = _process$env.WITH_THEME,
40
+ APP_NAME = _process$env.APP_NAME,
41
+ ENVIRONMENT_MODE = _process$env.ENVIRONMENT_MODE,
42
+ _process$env$HOST_URL = _process$env.HOST_URL,
43
+ HOST_URL = _process$env$HOST_URL === void 0 ? '' : _process$env$HOST_URL,
44
+ _process$env$PUBLIC_P = _process$env.PUBLIC_PATH,
45
+ PUBLIC_PATH = _process$env$PUBLIC_P === void 0 ? '/' : _process$env$PUBLIC_P,
46
+ _process$env$API_PREF = _process$env.API_PREFIX,
47
+ API_PREFIX = _process$env$API_PREF === void 0 ? '/' : _process$env$API_PREF,
48
+ check_version = _process$env.check_version,
49
+ others = _objectWithoutProperties(_process$env, _excluded);
50
+ var other_record = Object.entries(others).filter(function (_) {
51
+ return _[0].startsWith('LM_');
52
+ }).reduce(function (sum, e) {
53
+ return _objectSpread(_objectSpread({}, sum), {}, _defineProperty({}, e[0], e[1]));
54
+ }, {});
55
+ var devMode = ENVIRONMENT_MODE === 'development';
56
+ var ips = Object.values(os.networkInterfaces()).flat().filter(function (ent) {
57
+ return (ent === null || ent === void 0 ? void 0 : ent.family) === 'IPv4';
58
+ }).map(function (ent) {
59
+ return ent === null || ent === void 0 ? void 0 : ent.address;
60
+ });
61
+ var m = {
62
+ sb: 'http://192.are.you.sb?',
63
+ appName: APP_NAME,
64
+ devMode: devMode,
65
+ check_version: check_version,
66
+ NODE_ENV: ENVIRONMENT_MODE,
67
+ WITH_THEME: WITH_THEME,
68
+ PUBLIC_PATH: PUBLIC_PATH,
69
+ API_PREFIX: API_PREFIX,
70
+ PACKAGE_VERSION: safe_require('package.json').version,
71
+ BUILDINFO: safe_require('build_meta.json'),
72
+ __HOST_URL: utils.simple_encrypt_str(HOST_URL)
73
+ };
74
+ var ret = _objectSpread(_objectSpread(_objectSpread({}, x), other_record), {}, {
75
+ __DEV__: devMode,
76
+ __LOCAL__: "(".concat(JSON.stringify(ips), ".includes(location.hostname))"),
77
+ APP_MACRO: raw ? JSON.stringify(m) : m
78
+ });
79
+ return ret;
80
+ }
81
+ exports.colorLog = index.colorLog;
82
+ exports.successLog = index.successLog;
83
+ exports.tplMd = index.tplMd;
84
+ exports.warnLog = index.warnLog;
85
+ exports.client_macro_record = client_macro_record;
@@ -0,0 +1,19 @@
1
+ export declare function client_macro_record(x?: {
2
+ [x: string]: any;
3
+ }, raw?: boolean): {
4
+ __DEV__: boolean;
5
+ __LOCAL__: string;
6
+ APP_MACRO: string | {
7
+ sb: string;
8
+ appName: string | undefined;
9
+ devMode: boolean;
10
+ check_version: string | undefined;
11
+ NODE_ENV: string | undefined;
12
+ WITH_THEME: string | undefined;
13
+ PUBLIC_PATH: string;
14
+ API_PREFIX: string;
15
+ PACKAGE_VERSION: any;
16
+ BUILDINFO: any;
17
+ __HOST_URL: string | null;
18
+ };
19
+ };
@@ -0,0 +1,18 @@
1
+ import chalk from 'chalk';
2
+ declare const colorFnMap: {
3
+ green: chalk.Chalk;
4
+ bgGreen: chalk.Chalk;
5
+ yellow: chalk.Chalk;
6
+ bgYellow: chalk.Chalk;
7
+ red: chalk.Chalk;
8
+ bgRed: chalk.Chalk;
9
+ blue: chalk.Chalk;
10
+ bgBlue: chalk.Chalk;
11
+ cyan: chalk.Chalk;
12
+ bgCyan: chalk.Chalk;
13
+ };
14
+ export declare function colorLog(str?: string, who?: string, color?: keyof typeof colorFnMap): void;
15
+ export declare function warnLog(txt: string, who: string): void;
16
+ export declare function successLog(txt: string, who: string): void;
17
+ export declare function tplMd(data: any, mdName?: string, tplName?: string): void;
18
+ export {};
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@lm_fe/scripts",
3
+ "version": "0.1.201",
4
+ "description": "",
5
+ "scripts": {
6
+ "test": "echo \"Error: no test specified\" && exit 1",
7
+ "build": "rollup -c rollup.config.js",
8
+ "build:watch": "rollup -c rollup.config.js --watch",
9
+ "clean": "rimraf dist -rf",
10
+ "prebuild": "pnpm clean"
11
+ },
12
+ "bin": {
13
+ "gen-routes": "dist/gen-routes.js",
14
+ "gen-form-config": "dist/gen-form-config.js",
15
+ "copy-static": "dist/copy-static.js",
16
+ "color-log": "dist/color-log.js",
17
+ "lm-cli": "dist/cli.js"
18
+ },
19
+ "main": "dist/index.js",
20
+ "directories": {
21
+ "lib": "dist"
22
+ },
23
+ "files": [
24
+ "dist"
25
+ ],
26
+ "publishConfig": {
27
+ "access": "public"
28
+ },
29
+ "keywords": [],
30
+ "author": "",
31
+ "license": "MIT",
32
+ "devDependencies": {
33
+ "@types/json2md": "^1.5.1",
34
+ "@types/node": "^22.13.11",
35
+ "@types/yargs-parser": "^21.0.0",
36
+ "rollup": "^2.70.2"
37
+ },
38
+ "dependencies": {
39
+ "@lm_fe/static": "^0.1.201",
40
+ "@noah-libjs/utils": "0.0.9",
41
+ "chalk": "^4.1.2",
42
+ "dayjs": "^1.11.13",
43
+ "json2md": "^2.0.2",
44
+ "yargs-parser": "^21.1.1"
45
+ },
46
+ "gitHead": "931c78077ee1fc3df5f0f8ee5a8acc52783460f9"
47
+ }