UNPKG

t-comm

Version:

专业、稳定、纯粹的工具库

47 lines (44 loc) 1.42 kB
import { readFileSync } from '../fs/fs.mjs'; import { traverseFolder } from '../fs/fs-util.mjs'; import { getFs } from '../nodejs/fs.mjs'; import { getPath } from '../nodejs/path.mjs'; import '../nodejs/crypto.mjs'; import '../nodejs/os.mjs'; import '@babel/runtime/helpers/toConsumableArray'; import '../time/time.mjs'; /** * 统计页面个数 * @example * statisticsPages('dist/build/mp-weixin/app.json') */ function statisticsPages(pagesJsonPath) { var pagesJson = readFileSync(getPath().resolve(process.cwd(), pagesJsonPath), true); var _pagesJson$pages = pagesJson.pages, pages = _pagesJson$pages === void 0 ? [] : _pagesJson$pages, _pagesJson$subPackage = pagesJson.subPackages, subPackages = _pagesJson$subPackage === void 0 ? [] : _pagesJson$subPackage; var res = pages.length + subPackages.reduce(function (acc, item) { return acc + item.pages.length; }, 0); console.log('[statisticsPages] res: ', res); return res; } /** * 统计组件个数 * @example * statisticsComponent('dist/build/mp-weixin'); */ function statisticsComponent(dir) { var fs = getFs(); var array = []; if (fs.existsSync(dir)) { traverseFolder(function (file) { if (file.endsWith('.wxml')) { array.push(file); } }, dir); } console.log('[statisticsComponent] array.length: ', array.length); return array.length; } export { statisticsComponent, statisticsPages };