import fs from 'fs'; import {BasicFuncs, ScopeFuncs, appList, createAppId, createFunctionId} from './function.mjs'; import {appMap} from './moduleMap.mjs'; const appIds = appList.map((item, index) => createAppId(item.name)); let content = `export type IFunctionId = string; export type IFunctionIds = IFunctionId[]; export type IFunctionCode = string; export type IFunctionCodes = IFunctionId[]; export interface IPowerItem { id: string; label: string; children: {id: IFunctionId; label: string}[]; } export const appIds = ${JSON.stringify(appIds)}; export const appIdMap = new Set(appIds); export const filterFunctionCodesIsApp = (codeList: string[]) => { return codeList.filter((item) => { return !appIdMap.has(item); }); }; export default [`; appList.forEach((item, index) => { const appId = createAppId(item.name); content += `\n { id: '${appId}', label: '${appMap[item.name].name}', children: ${JSON.stringify( [...BasicFuncs, ...(appMap[item.name].functions || [])].map((itemFunc, indexFunc) => ({ id: createFunctionId(itemFunc, appId), label: `${ScopeFuncs}.${itemFunc}`, })) )}, },`; }) content += `\n]`; try { fs.writeFileSync(`./powerList.ts`, content); console.log(`file written successfully :>> powerList.ts\n`); } catch (err) { console.error(err); }