🌳
pt0/deployF/codeStatsF/deployPathsF.mts
3import * as _ from 'lodash-es'
10import { getEpCfg, type EpScope } from '../dockerF/getEpCfgF.mts'
11import { type EpScopeCfg } from '../dockerF/scopesF.mts'
14export const getDeployEpA = async (): Promise<string[]> => {
15 const {importMetaUrl, deployEp: deployEpArg} = getAppCfg()
16 const deployEp = deployEpArg || (importMetaUrl && absPathToPtPath(getImportMetaUrlPath(importMetaUrl) as any))
17 assertDefined(deployEp)
18 return [deployEp]
21type GetEpsPathsOpts = EpScopeCfg & { onlyPages?: boolean }
22type GetEpsPathsResult = { epA: string[], pathsA: string[] }
24export const getEpsPaths = async ({inclDeploy, inclDocker, onlyPages = false, feOnly = false}: GetEpsPathsOpts): Promise<GetEpsPathsResult> => {
25 const {appPath, usesExplicitEpPtPaths, epPtPathsA: explicitEpPtPathsA} = getAppCfg()
27 // feOnly: client-side detection
28 if (feOnly) {
29 if (usesExplicitEpPtPaths) return { epA: [], pathsA: [] }
30 const pagePathsA = await nextAppPaths()
31 const pagesOnly = _.filter(pagePathsA, p => _.includes(p, '/pages/') || _.includes(p, '/app/'))
32 const apiRoutes = _.filter(pagesOnly, p => _.includes(p, '/api/') || _.endsWith(p, '/route.js'))
33 const clientPages = _.difference(pagesOnly, apiRoutes)
34 const { clientPaths } = await getClientServerPathSets(pagesOnly)
35 const publicPaths = _.filter(pagePathsA, p => _.includes(p, '/public/'))
36 const pathsA = _.uniq([...clientPages, ...Array.from(clientPaths), ...publicPaths])
37 return { epA: clientPages, pathsA }
38 }
40 // Resolve docker entry points (only difference between ep types)
41 const dockerEpPtPathsA = usesExplicitEpPtPaths ? explicitEpPtPathsA : await nextAppPaths()
42 throwIf(() => inclDocker && !dockerEpPtPathsA?.length, {appPath, usesExplicitEpPtPaths, explicitEpPtPathsA})
44 if (onlyPages && inclDocker === undefined) inclDocker = true
46 let epA: string[] = []
47 if (inclDocker) epA = _.union(epA, dockerEpPtPathsA)
48 if (inclDeploy) epA = _.union(epA, await getDeployEpA())
50 if (onlyPages) {
51 throwIf(() => !inclDocker || inclDeploy, {inclDocker, inclDeploy})
52 epA = _.filter(epA, ep => _.includes(ep, '/pages/'))
53 }
55 const pathsA = await epToPathA({epA})
56 return { epA, pathsA }
59export const epToPathA = async ({epA}: {epA: string[]}) => {
60 const madgeResult = await ptMadge(epA) as Record<string, string[]>
61 return _.uniq(_.union(_.flatten(Object.values(madgeResult)), epA)).filter(isPtCodeFileExt)
64export const getRakeEpsPaths = async (epCfgOpts?: {defaultEpScope?: EpScope}): Promise<GetEpsPathsResult> => {
65 return await getEpsPaths(getEpCfg(epCfgOpts))