import fs from 'fs-extra' import { globbySync } from 'globby' import { fileURLToPath } from 'node:url' import path from 'path' function resolveApp(...filePath: string[]) { return path.resolve(process.cwd(), ...filePath) } function resolveOwn(...filePath: string[]) { let current = path.dirname(fileURLToPath(import.meta.url)) while (!fs.existsSync(path.join(current, 'package.json'))) { const parent = path.dirname(current) if (parent === current) { throw new Error('package.json not found') } current = parent } return path.resolve(current, ...filePath) } function resolveExistPaths(...paths: string[]) { return paths.filter((p) => fs.existsSync(p)) } function getExistPath(...paths: string[]) { const existPaths = resolveExistPaths(...paths) return existPaths[0] || paths[0] } const paths = { resolveApp, resolveOwn, resolveExistPaths, eduAppEnv: resolveApp('src', 'edu-app-env.d.ts'), dist: resolveApp('dist'), sshSftp: resolveApp('.sftprc.json'), nodeModules: resolveApp('node_modules'), tsconfig: resolveApp('tsconfig.json'), jsconfig: resolveApp('jsconfig.json'), package: resolveApp('package.json'), tailwind: resolveApp('tailwind.config.js'), pages: resolveApp('src', 'pages'), override: getExistPath( resolveApp('edu-scripts.override.js'), resolveApp('edu-scripts.override.ts') ), indexHTML: globbySync('./public/*.html', { absolute: true }), src: resolveApp('src'), public: resolveApp('public'), static: resolveApp('public', 'static'), theme: getExistPath(resolveApp('theme.json'), resolveApp('theme.js')), mock: resolveApp('mock'), } export default paths