Skip to content

Commit d7af8b6

Browse files
wip
1 parent 9b04da7 commit d7af8b6

File tree

4 files changed

+25
-16
lines changed

4 files changed

+25
-16
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
"lint:fix": "pnpm run lint --fix",
2323
"prettier": "prettier --ignore-path .prettierignore --write .",
2424
"clean": "pnpm -p -r -c exec rm -rf dist dev .cache",
25-
"purge": "pnpm -p -r -c exec rm -rf node_modules"
25+
"purge": "pnpm -p -r -c exec rm -rf node_modules",
26+
"prepare": "ts-node ./scripts/pre.ts"
2627
},
2728
"packageManager": "[email protected]",
2829
"devDependencies": {

scripts/build.ts

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { spawn } from "node:child_process";
2-
import { mkdir, readdir, readFile, rm, writeFile } from "node:fs/promises";
2+
import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
33
import { resolve } from "node:path";
44
import { rollupBuild } from "project-tool/rollup";
5+
import { preSvelte } from "./utils";
56

67
const externalCorePackage = (id: string) =>
78
(id.includes("node_modules") || (id.includes("@git-diff-view/") && !id.endsWith("@git-diff-view/utils"))) &&
@@ -22,19 +23,6 @@ const copyCss = async (packageName: string, file: string) => {
2223
await writeFile(cssDistPath, cssContent);
2324
};
2425

25-
const copyDir = async (srcDir: string, tarDir: string) => {
26-
const srcPath = resolve(process.cwd(), "packages", srcDir);
27-
const tarPath = resolve(process.cwd(), "packages", tarDir);
28-
await mkdir(tarPath, { recursive: true }).catch(() => void 0);
29-
const files = await readdir(srcPath);
30-
for (const file of files) {
31-
if (file.endsWith("index.ts")) continue;
32-
const srcFilePath = resolve(srcPath, file);
33-
const tarFilePath = resolve(tarPath, file);
34-
await writeFile(tarFilePath, await readFile(srcFilePath));
35-
}
36-
};
37-
3826
const clean = async (packageName: string) => {
3927
const typePath = resolve(process.cwd(), "packages", packageName, "index.d.ts");
4028
const content = await readFile(typePath, "utf-8");
@@ -135,7 +123,7 @@ const buildSolid = async () => {
135123
};
136124

137125
const buildSvelte = async () => {
138-
await copyDir("utils/src", "svelte/src/lib/utils");
126+
await preSvelte();
139127
await new Promise<void>((r, j) => {
140128
const ls = spawn(`cd packages/svelte && pnpm run build`, { shell: true, stdio: "inherit" });
141129
ls.on("close", () => r());

scripts/pre.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { preSvelte } from "./utils";
2+
3+
preSvelte();

scripts/utils.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { mkdir, readdir, readFile, writeFile } from "fs/promises";
2+
import { resolve } from "path";
3+
4+
const copyDir = async (srcDir: string, tarDir: string) => {
5+
const srcPath = resolve(process.cwd(), "packages", srcDir);
6+
const tarPath = resolve(process.cwd(), "packages", tarDir);
7+
await mkdir(tarPath, { recursive: true }).catch(() => void 0);
8+
const files = await readdir(srcPath);
9+
for (const file of files) {
10+
if (file.endsWith("index.ts")) continue;
11+
const srcFilePath = resolve(srcPath, file);
12+
const tarFilePath = resolve(tarPath, file);
13+
await writeFile(tarFilePath, await readFile(srcFilePath));
14+
}
15+
};
16+
17+
export const preSvelte = async () => await copyDir("utils/src", "svelte/src/lib/utils");

0 commit comments

Comments
 (0)