UNPKG

everything-dev

Version:

A consolidated product package for building Module Federation apps with oRPC APIs.

1 lines • 3.7 kB
{"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\";\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) => new Error(`glob failed for ${pattern}: ${String(error)}`),\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 Error(`stat failed for ${relativePath}: ${String(error)}`),\n });\n\nexport const readText = (projectDir: string, relativePath: string) =>\n Effect.tryPromise({\n try: () => readFile(`${projectDir}/${relativePath}`, \"utf-8\"),\n catch: (error) => new Error(`read failed for ${relativePath}: ${String(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 Error(`write failed for ${relativePath}: ${String(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 Error(`remove failed for ${relativePath}: ${String(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) => new Error(`command failed: ${command} ${args.join(\" \")}\\n${String(error)}`),\n });\n"],"mappings":";;;;;;;AAMA,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,0BAAU,IAAI,MAAM,mBAAmB,QAAQ,IAAI,OAAO,KAAK,GAAG;AAC5E,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,0BAAU,IAAI,MAAM,mBAAmB,aAAa,IAAI,OAAO,KAAK,GAAG;AACjF,CAAC;AAEH,MAAa,YAAY,YAAoB,iBAC3C,OAAO,WAAW;CAChB,WAAW,SAAS,GAAG,WAAW,GAAG,gBAAgB,OAAO;CAC5D,QAAQ,0BAAU,IAAI,MAAM,mBAAmB,aAAa,IAAI,OAAO,KAAK,GAAG;AACjF,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,OAAO;EAC/B,OAAO;CACT;CACA,QAAQ,0BAAU,IAAI,MAAM,oBAAoB,aAAa,IAAI,OAAO,KAAK,GAAG;AAClF,CAAC;AAEH,MAAa,cAAc,YAAoB,iBAC7C,OAAO,WAAW;CAChB,KAAK,YAAY;EACf,MAAM,GAAG,GAAG,WAAW,GAAG,gBAAgB;GAAE,OAAO;GAAM,WAAW;EAAK,CAAC;EAC1E,OAAO;CACT;CACA,QAAQ,0BAAU,IAAI,MAAM,qBAAqB,aAAa,IAAI,OAAO,KAAK,GAAG;AACnF,CAAC"}