@tscircuit/cli 0.0.143 → 0.0.144
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +15 -7
- package/lib/util/get-all-package-files.ts +29 -20
- package/package.json +1 -1
|
@@ -15,20 +15,23 @@ import ignore from "ignore"
|
|
|
15
15
|
export const getAllPackageFiles = async (
|
|
16
16
|
ctx: AppContext
|
|
17
17
|
): Promise<Array<string>> => {
|
|
18
|
-
await ensureNodeModulesIgnored()
|
|
19
|
-
|
|
20
|
-
const gitignore = await fs
|
|
21
|
-
.readFile("./.gitignore")
|
|
22
|
-
.then((b) => b.toString().split("\n").filter(Boolean))
|
|
23
|
-
.catch((e) => null)
|
|
18
|
+
await ensureNodeModulesIgnored()
|
|
24
19
|
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
20
|
+
const [gitIgnore, promptIgnore, npmIgnore] = await Promise.all([
|
|
21
|
+
readIgnoreFile("./.gitignore"),
|
|
22
|
+
readIgnoreFile("./.promptignore"),
|
|
23
|
+
readIgnoreFile("./.npmignore"),
|
|
24
|
+
])
|
|
25
|
+
|
|
26
|
+
const npmAndPromptIgnoreFiles = [
|
|
27
|
+
...(promptIgnore ?? []),
|
|
28
|
+
...(npmIgnore ?? []),
|
|
29
|
+
]
|
|
29
30
|
|
|
30
31
|
const ig = ignore().add([
|
|
31
|
-
...(
|
|
32
|
+
...(npmAndPromptIgnoreFiles.length > 0
|
|
33
|
+
? npmAndPromptIgnoreFiles
|
|
34
|
+
: gitIgnore ?? []),
|
|
32
35
|
".tscircuit",
|
|
33
36
|
"node_modules/*",
|
|
34
37
|
])
|
|
@@ -36,22 +39,28 @@ export const getAllPackageFiles = async (
|
|
|
36
39
|
return Glob.globSync("**/*.{ts,tsx,md}", {}).filter((fp) => !ig.ignores(fp))
|
|
37
40
|
}
|
|
38
41
|
|
|
42
|
+
const readIgnoreFile = async (filePath: string): Promise<string[] | null> =>
|
|
43
|
+
await fs
|
|
44
|
+
.readFile(filePath)
|
|
45
|
+
.then((b) => b.toString().split("\n").filter(Boolean))
|
|
46
|
+
.catch((e) => null)
|
|
47
|
+
|
|
39
48
|
/**
|
|
40
49
|
* Ensure 'node_modules/' is in .gitignore
|
|
41
50
|
*/
|
|
42
51
|
const ensureNodeModulesIgnored = async () => {
|
|
43
|
-
const gitignorePath =
|
|
44
|
-
|
|
52
|
+
const gitignorePath = "./.gitignore"
|
|
53
|
+
|
|
45
54
|
try {
|
|
46
|
-
const gitignore = await fs.readFile(gitignorePath,
|
|
47
|
-
if (!gitignore.includes(
|
|
48
|
-
await fs.appendFile(gitignorePath,
|
|
55
|
+
const gitignore = await fs.readFile(gitignorePath, "utf8")
|
|
56
|
+
if (!gitignore.includes("node_modules/")) {
|
|
57
|
+
await fs.appendFile(gitignorePath, "\nnode_modules/\n")
|
|
49
58
|
}
|
|
50
59
|
} catch (err) {
|
|
51
|
-
if (err.code ===
|
|
52
|
-
await fs.writeFile(gitignorePath,
|
|
60
|
+
if (err.code === "ENOENT") {
|
|
61
|
+
await fs.writeFile(gitignorePath, "node_modules/\n")
|
|
53
62
|
} else {
|
|
54
|
-
console.error(
|
|
63
|
+
console.error("Error while updating .gitignore:", err)
|
|
55
64
|
}
|
|
56
65
|
}
|
|
57
|
-
}
|
|
66
|
+
}
|