everything-dev
Version:
A consolidated product package for building Module Federation apps with oRPC APIs.
1 lines • 4.02 kB
Source Map (JSON)
{"version":3,"file":"fs.mjs","names":[],"sources":["../../../../src/services/scaffold/upgrade-audit/fs.ts"],"sourcesContent":["import { execFile } from \"node:child_process\";\nimport { mkdir, readFile, rm, stat, writeFile } from \"node:fs/promises\";\nimport { promisify } from \"node:util\";\nimport { Effect } from \"effect\";\nimport { glob } from \"glob\";\nimport { AuditFileError } from \"./domain\";\n\nconst execFileAsync = promisify(execFile);\n\nexport const listFiles = (projectDir: string, pattern: string | string[]) =>\n Effect.tryPromise({\n try: async () =>\n glob(pattern, {\n cwd: projectDir,\n nodir: true,\n dot: false,\n absolute: false,\n }),\n catch: (error) =>\n new AuditFileError({\n op: \"glob\",\n target: Array.isArray(pattern) ? pattern.join(\" \") : pattern,\n cause: error,\n }),\n });\n\nexport const fileExists = (projectDir: string, relativePath: string) =>\n Effect.tryPromise({\n try: async () => {\n try {\n await stat(`${projectDir}/${relativePath}`);\n return true;\n } catch {\n return false;\n }\n },\n catch: (error) => new AuditFileError({ op: \"stat\", target: relativePath, cause: error }),\n });\n\nexport const readText = (projectDir: string, relativePath: string) =>\n Effect.tryPromise({\n try: () => readFile(`${projectDir}/${relativePath}`, \"utf-8\"),\n catch: (error) => new AuditFileError({ op: \"read\", target: relativePath, cause: error }),\n });\n\nexport const writeText = (projectDir: string, relativePath: string, content: string) =>\n Effect.tryPromise({\n try: async () => {\n const target = `${projectDir}/${relativePath}`;\n const dir = target.slice(0, target.lastIndexOf(\"/\"));\n if (dir) await mkdir(dir, { recursive: true });\n await writeFile(target, content);\n return relativePath;\n },\n catch: (error) => new AuditFileError({ op: \"write\", target: relativePath, cause: error }),\n });\n\nexport const removePath = (projectDir: string, relativePath: string) =>\n Effect.tryPromise({\n try: async () => {\n await rm(`${projectDir}/${relativePath}`, { force: true, recursive: true });\n return relativePath;\n },\n catch: (error) => new AuditFileError({ op: \"remove\", target: relativePath, cause: error }),\n });\n\nexport const runCommand = (cwd: string, command: string, args: readonly string[]) =>\n Effect.tryPromise({\n try: async () => {\n const { stdout } = await execFileAsync(command, [...args], {\n cwd,\n maxBuffer: 16 * 1024 * 1024,\n });\n return stdout;\n },\n catch: (error) =>\n new AuditFileError({\n op: \"command\",\n target: `${command} ${args.join(\" \")}`,\n cause: error,\n }),\n });\n"],"mappings":";;;;;;;;AAOA,MAAM,gBAAgB,UAAU,QAAQ;AAExC,MAAa,aAAa,YAAoB,YAC5C,OAAO,WAAW;CAChB,KAAK,YACH,KAAK,SAAS;EACZ,KAAK;EACL,OAAO;EACP,KAAK;EACL,UAAU;CACZ,CAAC;CACH,QAAQ,UACN,IAAI,eAAe;EACjB,IAAI;EACJ,QAAQ,MAAM,QAAQ,OAAO,IAAI,QAAQ,KAAK,GAAG,IAAI;EACrD,OAAO;CACT,CAAC;AACL,CAAC;AAEH,MAAa,cAAc,YAAoB,iBAC7C,OAAO,WAAW;CAChB,KAAK,YAAY;EACf,IAAI;GACF,MAAM,KAAK,GAAG,WAAW,GAAG,cAAc;GAC1C,OAAO;EACT,QAAQ;GACN,OAAO;EACT;CACF;CACA,QAAQ,UAAU,IAAI,eAAe;EAAE,IAAI;EAAQ,QAAQ;EAAc,OAAO;CAAM,CAAC;AACzF,CAAC;AAEH,MAAa,YAAY,YAAoB,iBAC3C,OAAO,WAAW;CAChB,WAAW,SAAS,GAAG,WAAW,GAAG,gBAAgB,OAAO;CAC5D,QAAQ,UAAU,IAAI,eAAe;EAAE,IAAI;EAAQ,QAAQ;EAAc,OAAO;CAAM,CAAC;AACzF,CAAC;AAEH,MAAa,aAAa,YAAoB,cAAsB,YAClE,OAAO,WAAW;CAChB,KAAK,YAAY;EACf,MAAM,SAAS,GAAG,WAAW,GAAG;EAChC,MAAM,MAAM,OAAO,MAAM,GAAG,OAAO,YAAY,GAAG,CAAC;EACnD,IAAI,KAAK,MAAM,MAAM,KAAK,EAAE,WAAW,KAAK,CAAC;EAC7C,MAAM,UAAU,QAAQ,OA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