@mpilk/mp-route 1.0.1
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/bin/cli.js +3 -0
- package/dist/chunk-6MZ3UWKK.js +238 -0
- package/dist/cli.cjs +260 -0
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +18 -0
- package/dist/index.cjs +256 -0
- package/dist/index.d.cts +357 -0
- package/dist/index.d.ts +357 -0
- package/dist/index.js +11 -0
- package/package.json +52 -0
package/bin/cli.js
ADDED
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import pino from 'pino';
|
|
4
|
+
import { loadFileContent, loadJson, outputFile } from '@vsilk/mp-shared';
|
|
5
|
+
import { isEmpty, isArray, isPlainObject } from 'lodash-es';
|
|
6
|
+
import chokidar from 'chokidar';
|
|
7
|
+
|
|
8
|
+
// src/builder.ts
|
|
9
|
+
var _indexPath = "";
|
|
10
|
+
var logger = pino({
|
|
11
|
+
transport: {
|
|
12
|
+
target: "pino-pretty",
|
|
13
|
+
options: {
|
|
14
|
+
colorize: true
|
|
15
|
+
// ignore: 'hostname,pid',
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
var verboseLogger = logger.child({ verbose: true });
|
|
20
|
+
function builderWithWatch(options) {
|
|
21
|
+
let timer = null;
|
|
22
|
+
function run() {
|
|
23
|
+
if (timer)
|
|
24
|
+
clearTimeout(timer);
|
|
25
|
+
timer = setTimeout(() => {
|
|
26
|
+
timer = null;
|
|
27
|
+
return builder(options);
|
|
28
|
+
}, options?.delay || 200);
|
|
29
|
+
}
|
|
30
|
+
return chokidar.watch([
|
|
31
|
+
`src/**/${options?.routeName || "route"}.{ts,js}`,
|
|
32
|
+
`src/${options?.tabbarName || "tabbar"}.{ts,js}`
|
|
33
|
+
]).on("all", (eventName) => {
|
|
34
|
+
switch (eventName) {
|
|
35
|
+
case "add":
|
|
36
|
+
case "change":
|
|
37
|
+
case "unlink":
|
|
38
|
+
run();
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
async function builder(options = {}) {
|
|
44
|
+
const { input = "./src", routeName = "route", tabbarName = "tabbar", pagesPath = "./src/pages.json", verbose } = options;
|
|
45
|
+
logger.info("\u5F00\u59CB\u751F\u6210\u8DEF\u7531\u6587\u4EF6...");
|
|
46
|
+
const filePaths = loadDirFiles(input, routeName);
|
|
47
|
+
logger.info(`\u6839\u636E ${routeName} \u627E\u5230 ${filePaths.length} \u4E2A\u6587\u4EF6`);
|
|
48
|
+
const routeConfigs = [];
|
|
49
|
+
for (const filePath of filePaths) {
|
|
50
|
+
verbose && verboseLogger.info(`\u5F00\u59CB\u89E3\u6790\u6587\u4EF6 ${filePath}`);
|
|
51
|
+
let content = await loadFileContent(filePath);
|
|
52
|
+
if (!content || typeof content !== "object" || isEmpty(content)) {
|
|
53
|
+
verbose && verboseLogger.info(`\u6587\u4EF6 ${filePath} \u4E3A\u7A7A\uFF0C\u8DF3\u8FC7`);
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
if (!isArray(content))
|
|
57
|
+
content = [content];
|
|
58
|
+
verbose && verboseLogger.info(`\u6587\u4EF6 ${filePath} \u89E3\u6790\u5B8C\u6210\uFF1A${JSON.stringify(content)}`);
|
|
59
|
+
routeConfigs.push(...content);
|
|
60
|
+
}
|
|
61
|
+
const rs = buildRoute(routeConfigs);
|
|
62
|
+
if (_indexPath) {
|
|
63
|
+
const idx2 = rs.pages.findIndex((page) => page.path === _indexPath);
|
|
64
|
+
if (idx2 !== -1)
|
|
65
|
+
rs.pages.unshift(...rs.pages.splice(idx2, 1));
|
|
66
|
+
}
|
|
67
|
+
logger.info("\u8DEF\u7531\u6587\u4EF6\u89E3\u6790\u5B8C\u6210");
|
|
68
|
+
if (!rs.condition.list.length)
|
|
69
|
+
rs.condition = void 0;
|
|
70
|
+
else if (rs.condition.list.length && rs.condition.current === -1)
|
|
71
|
+
rs.condition.current = 0;
|
|
72
|
+
const idx = rs.pages.findIndex((page) => page["_index"]);
|
|
73
|
+
if (idx !== -1)
|
|
74
|
+
rs.pages.unshift(...rs.pages.splice(idx, 1));
|
|
75
|
+
let tabbarObj;
|
|
76
|
+
const [tabbarPath] = loadDirFiles("./src", tabbarName);
|
|
77
|
+
if (tabbarPath && !isEmpty(tabbarPath)) {
|
|
78
|
+
logger.info(`\u6839\u636E ${tabbarName} \u627E\u52301\u4E2A\u6587\u4EF6`);
|
|
79
|
+
tabbarObj = await loadFileContent(tabbarPath);
|
|
80
|
+
if (tabbarObj && !isEmpty(tabbarObj))
|
|
81
|
+
rs.tabBar = tabbarObj;
|
|
82
|
+
}
|
|
83
|
+
const {
|
|
84
|
+
debug: _debug = false,
|
|
85
|
+
pages,
|
|
86
|
+
subPackages,
|
|
87
|
+
preloadRule,
|
|
88
|
+
condition,
|
|
89
|
+
tabBar,
|
|
90
|
+
...otherProps
|
|
91
|
+
} = await loadJson(pagesPath);
|
|
92
|
+
const writeContent = {
|
|
93
|
+
debug: _debug,
|
|
94
|
+
pages: rs.pages || pages,
|
|
95
|
+
subPackages: rs.subPackages || subPackages,
|
|
96
|
+
preloadRule: rs.preloadRule || preloadRule,
|
|
97
|
+
condition: rs.condition || condition,
|
|
98
|
+
tabBar: tabbarObj || tabBar,
|
|
99
|
+
...otherProps
|
|
100
|
+
};
|
|
101
|
+
await outputFile(pagesPath, JSON.stringify(writeContent, null, 2));
|
|
102
|
+
logger.info("\u8DEF\u7531\u6587\u4EF6\u751F\u6210\u5B8C\u6210\uFF01");
|
|
103
|
+
}
|
|
104
|
+
function buildRoute(content, ext = {}) {
|
|
105
|
+
const result = {
|
|
106
|
+
pages: [],
|
|
107
|
+
subPackages: [],
|
|
108
|
+
preloadRule: {},
|
|
109
|
+
condition: {
|
|
110
|
+
current: -1,
|
|
111
|
+
list: []
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
const { parentName = "", parentPath = "", subpackageRoot = "" } = ext;
|
|
115
|
+
for (const route of content) {
|
|
116
|
+
const { subPackages = false, isSubpackage = subPackages, path: path2, title, name, children } = route;
|
|
117
|
+
const style = {
|
|
118
|
+
navigationBarTitleText: title || name || parentName,
|
|
119
|
+
...route.style
|
|
120
|
+
};
|
|
121
|
+
const _path = pathJoin(parentPath, path2);
|
|
122
|
+
if (isSubpackage && !subpackageRoot) {
|
|
123
|
+
let { preLoadPath, preLoadNetwork } = route;
|
|
124
|
+
const { pages, preloadRule, condition } = buildRoute(children ?? [], {
|
|
125
|
+
parentName: style.navigationBarTitleText,
|
|
126
|
+
subpackageRoot: _path
|
|
127
|
+
});
|
|
128
|
+
const subPackage = {
|
|
129
|
+
root: _path,
|
|
130
|
+
pages
|
|
131
|
+
};
|
|
132
|
+
result.preloadRule = deepMerge(result.preloadRule, preloadRule);
|
|
133
|
+
result.condition = deepMerge(result.condition, condition);
|
|
134
|
+
if (condition.current > -1)
|
|
135
|
+
result.condition.current = result.condition?.list?.indexOf(condition.list[condition.current]);
|
|
136
|
+
result.subPackages.push(subPackage);
|
|
137
|
+
if (preLoadPath) {
|
|
138
|
+
if (!isArray(preLoadPath))
|
|
139
|
+
preLoadPath = [preLoadPath];
|
|
140
|
+
const preLoadRule = preLoadPath.reduce((acc, cur) => {
|
|
141
|
+
acc[pathJoin(cur)] = {
|
|
142
|
+
network: preLoadNetwork,
|
|
143
|
+
packages: [_path]
|
|
144
|
+
};
|
|
145
|
+
return acc;
|
|
146
|
+
}, {});
|
|
147
|
+
result.preloadRule = deepMerge(result.preloadRule, preLoadRule);
|
|
148
|
+
}
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
if (children?.length) {
|
|
152
|
+
const { pages, subPackages: subPackages2, preloadRule, condition } = buildRoute(
|
|
153
|
+
children,
|
|
154
|
+
{
|
|
155
|
+
parentName: style.navigationBarTitleText,
|
|
156
|
+
parentPath: _path,
|
|
157
|
+
subpackageRoot
|
|
158
|
+
}
|
|
159
|
+
);
|
|
160
|
+
result.pages = deepMerge(result.pages, pages);
|
|
161
|
+
result.subPackages = deepMerge(result.subPackages, subPackages2);
|
|
162
|
+
result.preloadRule = deepMerge(result.preloadRule, preloadRule);
|
|
163
|
+
result.condition = deepMerge(result.condition, condition);
|
|
164
|
+
if (condition.current > -1)
|
|
165
|
+
result.condition.current = result.condition?.list?.indexOf(condition.list[condition.current]);
|
|
166
|
+
} else {
|
|
167
|
+
const { conditionActive, conditionQuery } = route;
|
|
168
|
+
const item = {
|
|
169
|
+
path: _path,
|
|
170
|
+
style
|
|
171
|
+
};
|
|
172
|
+
route.isIndex && (_indexPath = _path);
|
|
173
|
+
result.pages.push(item);
|
|
174
|
+
if (conditionQuery || conditionActive) {
|
|
175
|
+
const conditionItem = {
|
|
176
|
+
name: style.navigationBarTitleText,
|
|
177
|
+
path: _path,
|
|
178
|
+
query: conditionQuery
|
|
179
|
+
};
|
|
180
|
+
result.condition.list.push(conditionItem);
|
|
181
|
+
if (conditionActive)
|
|
182
|
+
result.condition.current = result.condition.list?.indexOf(conditionItem);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return result;
|
|
187
|
+
}
|
|
188
|
+
var extension = [".ts", ".js", ".mjs", ".json"];
|
|
189
|
+
function loadDirFiles(roots, name, exitByFirst = false) {
|
|
190
|
+
if (!Array.isArray(roots))
|
|
191
|
+
roots = [roots];
|
|
192
|
+
const files = [];
|
|
193
|
+
for (let root of roots) {
|
|
194
|
+
root = path.resolve(root);
|
|
195
|
+
if (!fs.existsSync(root))
|
|
196
|
+
continue;
|
|
197
|
+
const stat = fs.statSync(root);
|
|
198
|
+
const regex = new RegExp(`${name}(${extension.join("|")})$`);
|
|
199
|
+
if (stat.isFile() && regex.test(root)) {
|
|
200
|
+
files.push(root);
|
|
201
|
+
if (exitByFirst)
|
|
202
|
+
break;
|
|
203
|
+
}
|
|
204
|
+
if (stat.isDirectory()) {
|
|
205
|
+
const dirents = fs.readdirSync(root).map((o) => path.resolve(root, o));
|
|
206
|
+
files.push(...loadDirFiles(dirents, name));
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
return files;
|
|
210
|
+
}
|
|
211
|
+
function pathJoin(...paths) {
|
|
212
|
+
return paths.join("/").split("/").filter(Boolean).join("/");
|
|
213
|
+
}
|
|
214
|
+
function deepMerge(target, ...sources) {
|
|
215
|
+
if (typeof target !== "object" || target === null)
|
|
216
|
+
target = {};
|
|
217
|
+
if (!sources.length)
|
|
218
|
+
return target;
|
|
219
|
+
for (const source of sources) {
|
|
220
|
+
if (typeof source !== "object" || source === null)
|
|
221
|
+
continue;
|
|
222
|
+
if (isArray(target) && isArray(source)) {
|
|
223
|
+
const set = /* @__PURE__ */ new Set([...target, ...source]);
|
|
224
|
+
return [...set];
|
|
225
|
+
} else if (isPlainObject(target) && isPlainObject(source)) {
|
|
226
|
+
for (const key in source) {
|
|
227
|
+
if (key in target && typeof target[key] === "object" && typeof source[key] === "object") {
|
|
228
|
+
target[key] = deepMerge(target[key], source[key]);
|
|
229
|
+
} else {
|
|
230
|
+
target[key] = source[key] || target[key];
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
return target;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
export { builder, builderWithWatch };
|
package/dist/cli.cjs
ADDED
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var commander = require('commander');
|
|
5
|
+
var path = require('path');
|
|
6
|
+
var fs = require('fs');
|
|
7
|
+
var pino = require('pino');
|
|
8
|
+
var mpShared = require('@vsilk/mp-shared');
|
|
9
|
+
var lodashEs = require('lodash-es');
|
|
10
|
+
var chokidar = require('chokidar');
|
|
11
|
+
|
|
12
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
|
+
|
|
14
|
+
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
15
|
+
var fs__default = /*#__PURE__*/_interopDefault(fs);
|
|
16
|
+
var pino__default = /*#__PURE__*/_interopDefault(pino);
|
|
17
|
+
var chokidar__default = /*#__PURE__*/_interopDefault(chokidar);
|
|
18
|
+
|
|
19
|
+
// package.json
|
|
20
|
+
var version = "1.1.3";
|
|
21
|
+
var _indexPath = "";
|
|
22
|
+
var logger = pino__default.default({
|
|
23
|
+
transport: {
|
|
24
|
+
target: "pino-pretty",
|
|
25
|
+
options: {
|
|
26
|
+
colorize: true
|
|
27
|
+
// ignore: 'hostname,pid',
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
var verboseLogger = logger.child({ verbose: true });
|
|
32
|
+
function builderWithWatch(options) {
|
|
33
|
+
let timer = null;
|
|
34
|
+
function run() {
|
|
35
|
+
if (timer)
|
|
36
|
+
clearTimeout(timer);
|
|
37
|
+
timer = setTimeout(() => {
|
|
38
|
+
timer = null;
|
|
39
|
+
return builder(options);
|
|
40
|
+
}, options?.delay || 200);
|
|
41
|
+
}
|
|
42
|
+
return chokidar__default.default.watch([
|
|
43
|
+
`src/**/${options?.routeName || "route"}.{ts,js}`,
|
|
44
|
+
`src/${options?.tabbarName || "tabbar"}.{ts,js}`
|
|
45
|
+
]).on("all", (eventName) => {
|
|
46
|
+
switch (eventName) {
|
|
47
|
+
case "add":
|
|
48
|
+
case "change":
|
|
49
|
+
case "unlink":
|
|
50
|
+
run();
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
async function builder(options = {}) {
|
|
56
|
+
const { input = "./src", routeName = "route", tabbarName = "tabbar", pagesPath = "./src/pages.json", verbose } = options;
|
|
57
|
+
logger.info("\u5F00\u59CB\u751F\u6210\u8DEF\u7531\u6587\u4EF6...");
|
|
58
|
+
const filePaths = loadDirFiles(input, routeName);
|
|
59
|
+
logger.info(`\u6839\u636E ${routeName} \u627E\u5230 ${filePaths.length} \u4E2A\u6587\u4EF6`);
|
|
60
|
+
const routeConfigs = [];
|
|
61
|
+
for (const filePath of filePaths) {
|
|
62
|
+
verbose && verboseLogger.info(`\u5F00\u59CB\u89E3\u6790\u6587\u4EF6 ${filePath}`);
|
|
63
|
+
let content = await mpShared.loadFileContent(filePath);
|
|
64
|
+
if (!content || typeof content !== "object" || lodashEs.isEmpty(content)) {
|
|
65
|
+
verbose && verboseLogger.info(`\u6587\u4EF6 ${filePath} \u4E3A\u7A7A\uFF0C\u8DF3\u8FC7`);
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
if (!lodashEs.isArray(content))
|
|
69
|
+
content = [content];
|
|
70
|
+
verbose && verboseLogger.info(`\u6587\u4EF6 ${filePath} \u89E3\u6790\u5B8C\u6210\uFF1A${JSON.stringify(content)}`);
|
|
71
|
+
routeConfigs.push(...content);
|
|
72
|
+
}
|
|
73
|
+
const rs = buildRoute(routeConfigs);
|
|
74
|
+
if (_indexPath) {
|
|
75
|
+
const idx2 = rs.pages.findIndex((page) => page.path === _indexPath);
|
|
76
|
+
if (idx2 !== -1)
|
|
77
|
+
rs.pages.unshift(...rs.pages.splice(idx2, 1));
|
|
78
|
+
}
|
|
79
|
+
logger.info("\u8DEF\u7531\u6587\u4EF6\u89E3\u6790\u5B8C\u6210");
|
|
80
|
+
if (!rs.condition.list.length)
|
|
81
|
+
rs.condition = void 0;
|
|
82
|
+
else if (rs.condition.list.length && rs.condition.current === -1)
|
|
83
|
+
rs.condition.current = 0;
|
|
84
|
+
const idx = rs.pages.findIndex((page) => page["_index"]);
|
|
85
|
+
if (idx !== -1)
|
|
86
|
+
rs.pages.unshift(...rs.pages.splice(idx, 1));
|
|
87
|
+
let tabbarObj;
|
|
88
|
+
const [tabbarPath] = loadDirFiles("./src", tabbarName);
|
|
89
|
+
if (tabbarPath && !lodashEs.isEmpty(tabbarPath)) {
|
|
90
|
+
logger.info(`\u6839\u636E ${tabbarName} \u627E\u52301\u4E2A\u6587\u4EF6`);
|
|
91
|
+
tabbarObj = await mpShared.loadFileContent(tabbarPath);
|
|
92
|
+
if (tabbarObj && !lodashEs.isEmpty(tabbarObj))
|
|
93
|
+
rs.tabBar = tabbarObj;
|
|
94
|
+
}
|
|
95
|
+
const {
|
|
96
|
+
debug: _debug = false,
|
|
97
|
+
pages,
|
|
98
|
+
subPackages,
|
|
99
|
+
preloadRule,
|
|
100
|
+
condition,
|
|
101
|
+
tabBar,
|
|
102
|
+
...otherProps
|
|
103
|
+
} = await mpShared.loadJson(pagesPath);
|
|
104
|
+
const writeContent = {
|
|
105
|
+
debug: _debug,
|
|
106
|
+
pages: rs.pages || pages,
|
|
107
|
+
subPackages: rs.subPackages || subPackages,
|
|
108
|
+
preloadRule: rs.preloadRule || preloadRule,
|
|
109
|
+
condition: rs.condition || condition,
|
|
110
|
+
tabBar: tabbarObj || tabBar,
|
|
111
|
+
...otherProps
|
|
112
|
+
};
|
|
113
|
+
await mpShared.outputFile(pagesPath, JSON.stringify(writeContent, null, 2));
|
|
114
|
+
logger.info("\u8DEF\u7531\u6587\u4EF6\u751F\u6210\u5B8C\u6210\uFF01");
|
|
115
|
+
}
|
|
116
|
+
function buildRoute(content, ext = {}) {
|
|
117
|
+
const result = {
|
|
118
|
+
pages: [],
|
|
119
|
+
subPackages: [],
|
|
120
|
+
preloadRule: {},
|
|
121
|
+
condition: {
|
|
122
|
+
current: -1,
|
|
123
|
+
list: []
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
const { parentName = "", parentPath = "", subpackageRoot = "" } = ext;
|
|
127
|
+
for (const route of content) {
|
|
128
|
+
const { subPackages = false, isSubpackage = subPackages, path: path2, title, name, children } = route;
|
|
129
|
+
const style = {
|
|
130
|
+
navigationBarTitleText: title || name || parentName,
|
|
131
|
+
...route.style
|
|
132
|
+
};
|
|
133
|
+
const _path = pathJoin(parentPath, path2);
|
|
134
|
+
if (isSubpackage && !subpackageRoot) {
|
|
135
|
+
let { preLoadPath, preLoadNetwork } = route;
|
|
136
|
+
const { pages, preloadRule, condition } = buildRoute(children ?? [], {
|
|
137
|
+
parentName: style.navigationBarTitleText,
|
|
138
|
+
subpackageRoot: _path
|
|
139
|
+
});
|
|
140
|
+
const subPackage = {
|
|
141
|
+
root: _path,
|
|
142
|
+
pages
|
|
143
|
+
};
|
|
144
|
+
result.preloadRule = deepMerge(result.preloadRule, preloadRule);
|
|
145
|
+
result.condition = deepMerge(result.condition, condition);
|
|
146
|
+
if (condition.current > -1)
|
|
147
|
+
result.condition.current = result.condition?.list?.indexOf(condition.list[condition.current]);
|
|
148
|
+
result.subPackages.push(subPackage);
|
|
149
|
+
if (preLoadPath) {
|
|
150
|
+
if (!lodashEs.isArray(preLoadPath))
|
|
151
|
+
preLoadPath = [preLoadPath];
|
|
152
|
+
const preLoadRule = preLoadPath.reduce((acc, cur) => {
|
|
153
|
+
acc[pathJoin(cur)] = {
|
|
154
|
+
network: preLoadNetwork,
|
|
155
|
+
packages: [_path]
|
|
156
|
+
};
|
|
157
|
+
return acc;
|
|
158
|
+
}, {});
|
|
159
|
+
result.preloadRule = deepMerge(result.preloadRule, preLoadRule);
|
|
160
|
+
}
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
if (children?.length) {
|
|
164
|
+
const { pages, subPackages: subPackages2, preloadRule, condition } = buildRoute(
|
|
165
|
+
children,
|
|
166
|
+
{
|
|
167
|
+
parentName: style.navigationBarTitleText,
|
|
168
|
+
parentPath: _path,
|
|
169
|
+
subpackageRoot
|
|
170
|
+
}
|
|
171
|
+
);
|
|
172
|
+
result.pages = deepMerge(result.pages, pages);
|
|
173
|
+
result.subPackages = deepMerge(result.subPackages, subPackages2);
|
|
174
|
+
result.preloadRule = deepMerge(result.preloadRule, preloadRule);
|
|
175
|
+
result.condition = deepMerge(result.condition, condition);
|
|
176
|
+
if (condition.current > -1)
|
|
177
|
+
result.condition.current = result.condition?.list?.indexOf(condition.list[condition.current]);
|
|
178
|
+
} else {
|
|
179
|
+
const { conditionActive, conditionQuery } = route;
|
|
180
|
+
const item = {
|
|
181
|
+
path: _path,
|
|
182
|
+
style
|
|
183
|
+
};
|
|
184
|
+
route.isIndex && (_indexPath = _path);
|
|
185
|
+
result.pages.push(item);
|
|
186
|
+
if (conditionQuery || conditionActive) {
|
|
187
|
+
const conditionItem = {
|
|
188
|
+
name: style.navigationBarTitleText,
|
|
189
|
+
path: _path,
|
|
190
|
+
query: conditionQuery
|
|
191
|
+
};
|
|
192
|
+
result.condition.list.push(conditionItem);
|
|
193
|
+
if (conditionActive)
|
|
194
|
+
result.condition.current = result.condition.list?.indexOf(conditionItem);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return result;
|
|
199
|
+
}
|
|
200
|
+
var extension = [".ts", ".js", ".mjs", ".json"];
|
|
201
|
+
function loadDirFiles(roots, name, exitByFirst = false) {
|
|
202
|
+
if (!Array.isArray(roots))
|
|
203
|
+
roots = [roots];
|
|
204
|
+
const files = [];
|
|
205
|
+
for (let root of roots) {
|
|
206
|
+
root = path__default.default.resolve(root);
|
|
207
|
+
if (!fs__default.default.existsSync(root))
|
|
208
|
+
continue;
|
|
209
|
+
const stat = fs__default.default.statSync(root);
|
|
210
|
+
const regex = new RegExp(`${name}(${extension.join("|")})$`);
|
|
211
|
+
if (stat.isFile() && regex.test(root)) {
|
|
212
|
+
files.push(root);
|
|
213
|
+
if (exitByFirst)
|
|
214
|
+
break;
|
|
215
|
+
}
|
|
216
|
+
if (stat.isDirectory()) {
|
|
217
|
+
const dirents = fs__default.default.readdirSync(root).map((o) => path__default.default.resolve(root, o));
|
|
218
|
+
files.push(...loadDirFiles(dirents, name));
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
return files;
|
|
222
|
+
}
|
|
223
|
+
function pathJoin(...paths) {
|
|
224
|
+
return paths.join("/").split("/").filter(Boolean).join("/");
|
|
225
|
+
}
|
|
226
|
+
function deepMerge(target, ...sources) {
|
|
227
|
+
if (typeof target !== "object" || target === null)
|
|
228
|
+
target = {};
|
|
229
|
+
if (!sources.length)
|
|
230
|
+
return target;
|
|
231
|
+
for (const source of sources) {
|
|
232
|
+
if (typeof source !== "object" || source === null)
|
|
233
|
+
continue;
|
|
234
|
+
if (lodashEs.isArray(target) && lodashEs.isArray(source)) {
|
|
235
|
+
const set = /* @__PURE__ */ new Set([...target, ...source]);
|
|
236
|
+
return [...set];
|
|
237
|
+
} else if (lodashEs.isPlainObject(target) && lodashEs.isPlainObject(source)) {
|
|
238
|
+
for (const key in source) {
|
|
239
|
+
if (key in target && typeof target[key] === "object" && typeof source[key] === "object") {
|
|
240
|
+
target[key] = deepMerge(target[key], source[key]);
|
|
241
|
+
} else {
|
|
242
|
+
target[key] = source[key] || target[key];
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
return target;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// src/cli.ts
|
|
251
|
+
commander.program.name("uni-route").description(`\u8FD9\u662F\u4E00\u4E2A\u7528\u6765\u751F\u6210 uni-app \u8DEF\u7531\u6587\u4EF6\u7684\u5DE5\u5177
|
|
252
|
+
\u901A\u8FC7\u626B\u63CFsrc\u76EE\u5F55\u4E0B\u7684\u914D\u7F6E\u6587\u4EF6\uFF0C\u751F\u6210 uni-app \u8DEF\u7531\u914D\u7F6E\u6587\u4EF6\u3002`).version(version);
|
|
253
|
+
commander.program.option("-i, --input <input>", "\u626B\u63CF\u914D\u7F6E\u7684\u6587\u4EF6\u5939\u5165\u53E3\u8DEF\u5F84", "src/").option("-rn, --routeName <routeName>", "\u914D\u7F6E\u6587\u4EF6\u8DEF\u5F84", "route").option("-tn, --tabbarName <tabbarName>", "\u914D\u7F6E\u6587\u4EF6\u8DEF\u5F84", "tabbar").option("-pp, --pagesPath <pagesPath>", "\u914D\u7F6E\u6587\u4EF6\u8DEF\u5F84", "src/pages.json").option("-vvv, --verbose", "\u8F93\u51FA\u8BE6\u7EC6\u7684\u8C03\u8BD5\u4FE1\u606F");
|
|
254
|
+
commander.program.command("build", { isDefault: true }).description("\u641C\u7D22\u8DEF\u5F84\u4E0B\u7684\u8DEF\u7531\u6587\u4EF6\uFF0C\u751F\u6210\u8DEF\u7531\u914D\u7F6E").action((_, command) => {
|
|
255
|
+
builder(command.optsWithGlobals());
|
|
256
|
+
});
|
|
257
|
+
commander.program.command("watch").description("\u76D1\u542C\u6587\u4EF6\u53D8\u5316\uFF0C\u5B9E\u65F6\u751F\u6210\u8DEF\u7531\u914D\u7F6E").option("-t --delay [delay]", "\u5EF6\u8FDF\u65F6\u95F4").action((_, command) => {
|
|
258
|
+
builderWithWatch(command.optsWithGlobals());
|
|
259
|
+
});
|
|
260
|
+
commander.program.parse();
|
package/dist/cli.d.cts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { builder, builderWithWatch } from './chunk-6MZ3UWKK.js';
|
|
3
|
+
import { program } from 'commander';
|
|
4
|
+
|
|
5
|
+
// package.json
|
|
6
|
+
var version = "1.1.3";
|
|
7
|
+
|
|
8
|
+
// src/cli.ts
|
|
9
|
+
program.name("uni-route").description(`\u8FD9\u662F\u4E00\u4E2A\u7528\u6765\u751F\u6210 uni-app \u8DEF\u7531\u6587\u4EF6\u7684\u5DE5\u5177
|
|
10
|
+
\u901A\u8FC7\u626B\u63CFsrc\u76EE\u5F55\u4E0B\u7684\u914D\u7F6E\u6587\u4EF6\uFF0C\u751F\u6210 uni-app \u8DEF\u7531\u914D\u7F6E\u6587\u4EF6\u3002`).version(version);
|
|
11
|
+
program.option("-i, --input <input>", "\u626B\u63CF\u914D\u7F6E\u7684\u6587\u4EF6\u5939\u5165\u53E3\u8DEF\u5F84", "src/").option("-rn, --routeName <routeName>", "\u914D\u7F6E\u6587\u4EF6\u8DEF\u5F84", "route").option("-tn, --tabbarName <tabbarName>", "\u914D\u7F6E\u6587\u4EF6\u8DEF\u5F84", "tabbar").option("-pp, --pagesPath <pagesPath>", "\u914D\u7F6E\u6587\u4EF6\u8DEF\u5F84", "src/pages.json").option("-vvv, --verbose", "\u8F93\u51FA\u8BE6\u7EC6\u7684\u8C03\u8BD5\u4FE1\u606F");
|
|
12
|
+
program.command("build", { isDefault: true }).description("\u641C\u7D22\u8DEF\u5F84\u4E0B\u7684\u8DEF\u7531\u6587\u4EF6\uFF0C\u751F\u6210\u8DEF\u7531\u914D\u7F6E").action((_, command) => {
|
|
13
|
+
builder(command.optsWithGlobals());
|
|
14
|
+
});
|
|
15
|
+
program.command("watch").description("\u76D1\u542C\u6587\u4EF6\u53D8\u5316\uFF0C\u5B9E\u65F6\u751F\u6210\u8DEF\u7531\u914D\u7F6E").option("-t --delay [delay]", "\u5EF6\u8FDF\u65F6\u95F4").action((_, command) => {
|
|
16
|
+
builderWithWatch(command.optsWithGlobals());
|
|
17
|
+
});
|
|
18
|
+
program.parse();
|