🌳
pt0/deployF/ptDeployActions/lscodeActionAI.mts
1import * as _ from 'lodash-es'
5import type { EpScopeSets } from '../dockerF/scopesF.mts'
12import type { EpScope } from '../dockerF/scopesF.mts'
14const colorFns: Record<string, (s: string) => string> = { green: chalkGreen, gray: chalkGray, yellow: chalkYellow, cyan: chalkCyan, magenta: chalkMagenta }
16export const getEpScopeSets = async (): Promise<EpScopeSets> => {
17 const [{pathsA: pubfejsPaths}, {pathsA: dockerjsPaths}, {pathsA: deployjsPaths}] = await Promise.all([
18 getEpsPaths({inclDocker: true, feOnly: true}),
19 getEpsPaths({inclDocker: true}),
20 getEpsPaths({inclDeploy: true}),
21 ])
22 return {
23 pubfejsSet: new Set(pubfejsPaths),
24 dockerjsSet: new Set(dockerjsPaths),
25 deployjsSet: new Set(deployjsPaths),
26 }
29export const colorPathByEpScope = (path: string, sets: EpScopeSets) => {
30 const clr = fileClrFromEpSets(path, sets)
31 return colorFns[clr](path)
34export const epScopeLegend = () => {
35 const {usesExplicitEpPtPaths} = getAppCfg()
36 const scopes = usesExplicitEpPtPaths ? simpleLegendScopes : legendScopes
37 const parts = scopes.map((s) => `${colorFns[epScopeColors[s]](epScopeColors[s])}=${s}`)
38 return parts.join(' ')
41export const lscode: PtAction = async () => {
42 const {appPath, usesExplicitEpPtPaths} = getAppCfg()
44 const {pathsA} = await getRakeEpsPaths({defaultEpScope: epScopes.dockerjs})
45 assertNonEmpty(pathsA, {appPath, usesExplicitEpPtPaths})
47 const pkgJsonPtPathsA: string[] = !usesExplicitEpPtPaths && appPath
48 ? await getPkgJsonPtPathsA({appPath}) as unknown as string[]
49 : []
50 const allPathsA = [...pathsA, ...pkgJsonPtPathsA]
52 const epScopeSets = await getEpScopeSets()
53 const coloredPathsA = allPathsA.map((p) => colorPathByEpScope(p, epScopeSets))
54 console.log(coloredPathsA.join("\n"))
55 console.log('')
56 console.log(epScopeLegend())
57 printEpScopeHint({defaultEpScope: epScopes.dockerjs})
59lscode.needsLazyDocker = true
60lscode.cliSchema = scopeCli
61lscode.cliDescript = {
62 cliDefaultOpt: epScopes.dockerjs,
63 cliOptA: getEpScopeOptA,
64 cliSupportsEpScopes: true,
65 cliExplain: 'list all file paths in scope'