create-uniapp-pages-json
Version:
Dynamic generation of uniapp pages.json
38 lines (37 loc) • 1.23 kB
JavaScript
;
/*
* @Author: shen
* @Date: 2020-12-23 14:01:13
* @LastEditors: shen
* @LastEditTime: 2020-12-24 16:54:42
* @Description:
*/
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var path_1 = tslib_1.__importDefault(require("path"));
var fs = tslib_1.__importStar(require("fs"));
var deepFindRoutes = function (modulePath, routeFileName) {
var routesPath = [];
var fn = function (modulePath) {
var modules = fs.readdirSync(modulePath);
modules.forEach(function (module) {
var moduleDir = path_1.default.join(modulePath, module);
var statInfo = fs.statSync(moduleDir);
var isDir = statInfo.isDirectory();
if (isDir) {
fn(moduleDir);
}
else {
module === routeFileName && routesPath.push(moduleDir);
}
});
};
fn(modulePath);
return routesPath;
};
exports.default = (function (_a) {
var modulePath = _a.modulePath, routeFileName = _a.routeFileName;
var moduleFullPath = path_1.default.resolve(modulePath);
var routesPath = deepFindRoutes(moduleFullPath, routeFileName);
return routesPath;
});