Skip to content

Commit

Permalink
feat: replace writeFile with outputFile from fs-extra
Browse files Browse the repository at this point in the history
  • Loading branch information
bgenia committed May 22, 2024
1 parent a026b02 commit 18fb33a
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 8 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"@s21toolkit/shared": "^1.2.1",
"@total-typescript/ts-reset": "^0.5.1",
"@types/common-tags": "^1.8.4",
"@types/fs-extra": "^11.0.4",
"@types/har-format": "^1.2.15",
"@types/node": "^20.12.12",
"tsup": "^8.0.2",
Expand All @@ -36,6 +37,7 @@
"acorn-walk": "^8.3.2",
"cmd-ts": "^0.13.0",
"common-tags": "^1.8.2",
"fs-extra": "^11.2.0",
"graphql": "^16.8.1",
"node-html-parser": "^6.1.13",
"ts-pattern": "^5.1.1"
Expand Down
46 changes: 46 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions src/cli/commands/introspect/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { writeFile } from "node:fs/promises"
import { resolve } from "node:path"
import { PLATFORM_TOKEN } from "@/cli/arguments/platform-token"
import { HarFile } from "@/cli/arguments/types/har-file"
Expand All @@ -23,6 +22,7 @@ import {
string,
} from "cmd-ts"
import { source } from "common-tags"
import { outputFile } from "fs-extra"
import { type DocumentNode, print as printAst, printSchema } from "graphql"
import type { Har } from "har-format"
import { OperationRegistry } from "./operation-registry"
Expand Down Expand Up @@ -239,7 +239,7 @@ export const introspectCommand = command({
const schema = printSchema(typeSchema).trim()
const operations = await fetchGqlOperations(har)

await writeFile(schemaFile, schema)
await outputFile(schemaFile, schema)

for (const operation of operations.getValidOperations(
!deduplicateFragments,
Expand All @@ -249,7 +249,7 @@ export const introspectCommand = command({
`${operation.name}.${gqlFileExtension}`,
)

await writeFile(operationFile, printAst(operation.node).trim())
await outputFile(operationFile, printAst(operation.node).trim())
}

return
Expand Down Expand Up @@ -284,8 +284,8 @@ export const introspectCommand = command({
validOperationDocuments.map(({ node }) => node),
)

await writeFile(schemaFile, schema)
await writeFile(operationsFile, operationSchema)
await outputFile(schemaFile, schema)
await outputFile(operationsFile, operationSchema)

return
}
Expand Down Expand Up @@ -318,6 +318,6 @@ export const introspectCommand = command({
`.trim()
}

await writeFile(resolvedOutFile, schema)
await outputFile(resolvedOutFile, schema)
},
})
4 changes: 2 additions & 2 deletions src/cli/commands/sources/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { createHash } from "node:crypto"
import { writeFile } from "node:fs/promises"
import { join } from "node:path"
import { NewFile } from "@/cli/arguments/types/new-file"
import { walkScriptsFromWebpage } from "@/common/walk-scripts"
import { Constants } from "@/constants"
import { command, option, optional, positional, string } from "cmd-ts"
import { outputFile } from "fs-extra"

function createRootScriptFilename(text: string) {
const hash = createHash("md5").update(text).digest("hex")
Expand Down Expand Up @@ -43,7 +43,7 @@ export const sourcesCommand = command({

console.log(`Saving: ${source} -> ${join(".", filename)}`)

const writePromise = writeFile(join(outDir, filename), text)
const writePromise = outputFile(join(outDir, filename), text)

writePromises.push(writePromise)
})
Expand Down

0 comments on commit 18fb33a

Please sign in to comment.