Skip to content

Commit 8de1a44

Browse files
committed
move some script helpers around
1 parent 908875e commit 8de1a44

File tree

2 files changed

+32
-18
lines changed

2 files changed

+32
-18
lines changed

prepareVariants.ts

+3-18
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
* This file defines all the different variants of the quickjs WASM library.
55
*/
66

7-
import path from "path"
8-
import fs, { write } from "fs"
9-
import prettier from "prettier"
7+
import path from "node:path"
8+
import fs from "node:fs"
9+
import { writePretty } from "./scripts/helpers"
1010
import { Context, getMatches, buildFFI } from "./generate"
1111
import { TypeDocOptions } from "typedoc"
1212

@@ -374,21 +374,6 @@ async function main() {
374374
await writePretty(path.join(__dirname, "variants.json"), JSON.stringify(variantsJson))
375375
}
376376

377-
async function writePretty(filePath: string, text: string) {
378-
let output = text
379-
380-
const isPrettierUnsupportedType = filePath.endsWith(".mk") || filePath.endsWith("Makefile")
381-
if (!isPrettierUnsupportedType) {
382-
const prettierConfig = (await prettier.resolveConfig(filePath)) ?? {}
383-
output = await prettier.format(text, {
384-
...prettierConfig,
385-
filepath: filePath,
386-
})
387-
}
388-
console.warn(`write`, path.relative(process.cwd(), filePath))
389-
fs.writeFileSync(filePath, output)
390-
}
391-
392377
const describeInclusion = {
393378
[EmscriptenInclusion.SingleFile]: `The WASM runtime is included directly in the JS file. Use if you run into issues with missing .wasm files when building or deploying your app.`,
394379
[EmscriptenInclusion.Separate]: `Has a separate .wasm file. May offer better caching in your browser, and reduces the size of your JS bundle. If you have issues, try a 'singlefile' variant.`,

scripts/helpers.ts

+29
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import path from "node:path"
22
import fs from "node:fs"
33
import p from "node:child_process"
4+
import prettier from "prettier"
45

56
const packagesDir = path.resolve(__dirname, "../packages")
67
const tarDir = path.resolve(__dirname, "../build/tar")
@@ -59,3 +60,31 @@ export function installDependencyGraphFromTar(
5960
export function resolve(...parts: string[]) {
6061
return path.resolve(...parts)
6162
}
63+
64+
export async function writePretty(filePath: string, text: string) {
65+
let output = text
66+
67+
const isPrettierUnsupportedType = filePath.endsWith(".mk") || filePath.endsWith("Makefile")
68+
if (!isPrettierUnsupportedType) {
69+
const prettierConfig = (await prettier.resolveConfig(filePath)) ?? {}
70+
output = await prettier.format(text, {
71+
...prettierConfig,
72+
filepath: filePath,
73+
})
74+
}
75+
console.warn(`write`, path.relative(process.cwd(), filePath))
76+
fs.writeFileSync(filePath, output)
77+
}
78+
79+
interface WorkspaceJson {
80+
location: string
81+
name: string
82+
}
83+
84+
function getYarnWorkspaces(): WorkspaceJson[] {
85+
return p
86+
.execSync("yarn workspaces list --json", { encoding: "utf-8" })
87+
.split("\n")
88+
.filter(Boolean)
89+
.map((line) => JSON.parse(line) as WorkspaceJson)
90+
}

0 commit comments

Comments
 (0)