🌳
pt0/deployF/ossHookLoaderF.mts
1import { existsSync } from 'fs'
2import path from 'path'
3import { ptDir } from '../serverF/ptDirF.mts'
5const ossHookPath = path.join(ptDir, 'ptnodeHooks/ossF.mjs')
7export const isOssCheckout = () => !existsSync(ossHookPath)
9let _ossHook: any = undefined
10export const getOssHook = async () => {
11 _ossHook ??= existsSync(ossHookPath) ? await import(ossHookPath) : null
12 return _ossHook
15export const getOssReplaceFn = async (): Promise<((contents: string) => string) | null> => {
16 const hook = await getOssHook()
17 return hook?.ossReplace ?? null
20export const getOssTranscriptRedactFn = async (): Promise<((contents: string) => string) | null> => {
21 const hook = await getOssHook()
22 return hook?.ossTranscriptRedact ?? null
25export const getOssTrackedPaths = async (): Promise<string[] | null> => {
26 const hook = await getOssHook()
27 return hook?.allTrackedPaths ?? null
30export const isOssTrackedPath = (trackedPaths: string[] | null, subPath: string): boolean => {
31 if (!trackedPaths) return true
32 return trackedPaths.some(p => subPath.startsWith(p))
35export const getOssGlobalReplaceH = async (): Promise<Record<string, string> | null> => {
36 const hook = await getOssHook()
37 return hook?.ossGlobalReplaceH ?? null
40export const getOssGitignoreContent = async (): Promise<string | null> => {
41 const hook = await getOssHook()
42 return hook?.ossGitignoreContent ?? null
45export const getOssForbidStrA = async (): Promise<any[] | null> => {
46 const hook = await getOssHook()
47 return hook?.ossForbidStrA ?? null
50export const getDirForbidStrAH = async (): Promise<Record<string, any[]> | null> => {
51 const hook = await getOssHook()
52 return hook?.dirForbidStrAH ?? null
55export const getFilterOssPnpmWorkspace = async (): Promise<((raw: string) => string) | null> => {
56 const hook = await getOssHook()
57 return hook?.filterOssPnpmWorkspace ?? null
60type GeneratePrunedOssPackageJsonFn = (opts: {monorPkg: any, codeDirs: string[]}) => Promise<any>
61export const getGeneratePrunedOssPackageJson = async (): Promise<GeneratePrunedOssPackageJsonFn | null> => {
62 const hook = await getOssHook()
63 return hook?.generatePrunedOssPackageJson ?? null
66export const getTransformOssOpencodeJson = async (): Promise<((raw: string) => string) | null> => {
67 const hook = await getOssHook()
68 return hook?.transformOssOpencodeJson ?? null
71export const getFindDanglingOssDropRefs = async (): Promise<(() => Promise<{path: string, ident: string}[]>) | null> => {
72 const hook = await getOssHook()
73 return hook?.findDanglingOssDropRefs ?? null
76export const getOssReplaceTargets = async (): Promise<string[]> => {
77 const hook = await getOssHook()
78 return hook?.getOssReplaceTargets?.() ?? []
81export const getOssExcludeFn = async (): Promise<((ptPath: string) => boolean) | null> => {
82 const hook = await getOssHook()
83 return hook?.isOssExcludedPath ?? null
86export const getOssPublicClusterA = async (): Promise<string[] | null> => {
87 const hook = await getOssHook()
88 return hook?.ossPublicClusterA ?? null