Skip to content

Commit f3620eb

Browse files
update
1 parent 5a159bf commit f3620eb

File tree

5 files changed

+68
-79
lines changed

5 files changed

+68
-79
lines changed

packages/svelte/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "0.0.1",
44
"scripts": {
55
"dev": "vite dev",
6-
"build": "vite build && npm run prepack",
6+
"build": "npm run prepack",
77
"preview": "vite preview",
88
"prepare": "svelte-kit sync || echo ''",
99
"prepack": "svelte-kit sync && svelte-package && publint",

pnpm-lock.yaml

Lines changed: 6 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/build.ts

Lines changed: 1 addition & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,6 @@
11
import { spawn } from "node:child_process";
2-
import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
3-
import { resolve } from "node:path";
42
import { rollupBuild } from "project-tool/rollup";
5-
import { preSvelte } from "./utils";
6-
7-
const externalCorePackage = (id: string) =>
8-
(id.includes("node_modules") || (id.includes("@git-diff-view/") && !id.endsWith("@git-diff-view/utils"))) &&
9-
!id.includes("tslib");
10-
11-
const external = (id: string) =>
12-
(id.includes("node_modules") || (id.includes("@git-diff-view/") && !id.endsWith("@git-diff-view/utils"))) &&
13-
!id.includes("tslib") &&
14-
!id.endsWith(".css");
15-
16-
// fix css path not found in legacy module bundler
17-
const copyCss = async (packageName: string, file: string) => {
18-
const cssPath = resolve(process.cwd(), "packages", packageName, "dist", "css", file);
19-
const cssContent = await readFile(cssPath, "utf-8");
20-
const legacyCssDirPath = resolve(process.cwd(), "packages", packageName, "styles");
21-
await mkdir(legacyCssDirPath).catch(() => void 0);
22-
const cssDistPath = resolve(legacyCssDirPath, file);
23-
await writeFile(cssDistPath, cssContent);
24-
};
25-
26-
const clean = async (packageName: string) => {
27-
const typePath = resolve(process.cwd(), "packages", packageName, "index.d.ts");
28-
const content = await readFile(typePath, "utf-8");
29-
await writeFile(typePath, content.replace(/#private;/g, ""));
30-
};
31-
32-
const clear = async (packageName: string) => {
33-
const typeDirs = resolve(process.cwd(), "packages", packageName, "dist", "types");
34-
await rm(typeDirs, { recursive: true, force: true });
35-
};
36-
37-
const buildType = async (packageName: string) => {
38-
await new Promise<void>((r, j) => {
39-
const ls = spawn(`cd packages/${packageName} && pnpm run gen:type`, { shell: true, stdio: "inherit" });
40-
ls.on("close", () => r());
41-
ls.on("error", (e) => j(e));
42-
});
43-
await clean(packageName);
44-
await clear(packageName);
45-
};
46-
47-
const buildCss = async (packageName: string) => {
48-
await new Promise<void>((r, j) => {
49-
const ls = spawn(`cd packages/${packageName} && pnpm run gen:css`, { shell: true, stdio: "inherit" });
50-
ls.on("close", () => r());
51-
ls.on("error", (e) => j(e));
52-
});
53-
};
3+
import { buildCss, buildType, copyCss, externalCorePackage, preSvelte, external } from "./utils";
544

555
const buildLowlight = async () => {
566
await rollupBuild({
@@ -130,7 +80,6 @@ const buildSvelte = async () => {
13080
ls.on("error", (e) => j(e));
13181
});
13282
await buildCss("svelte");
133-
// await buildType("solid");
13483
await copyCss("svelte", "diff-view.css");
13584
await copyCss("svelte", "diff-view-pure.css");
13685
};

scripts/pre.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1-
import { preSvelte } from "./utils";
1+
import { buildCss, copyCss, preSvelte } from "./utils";
22

3-
preSvelte();
3+
const buildSvelte = async () => {
4+
await preSvelte();
5+
await buildCss("svelte");
6+
await copyCss("svelte", "diff-view.css");
7+
await copyCss("svelte", "diff-view-pure.css");
8+
};
9+
10+
buildSvelte();

scripts/utils.ts

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { mkdir, readdir, readFile, writeFile } from "fs/promises";
1+
import { spawn } from "child_process";
2+
import { mkdir, readdir, readFile, rm, writeFile } from "fs/promises";
23
import { resolve } from "path";
34

4-
const copyDir = async (srcDir: string, tarDir: string) => {
5+
export const copyDir = async (srcDir: string, tarDir: string) => {
56
const srcPath = resolve(process.cwd(), "packages", srcDir);
67
const tarPath = resolve(process.cwd(), "packages", tarDir);
78
await mkdir(tarPath, { recursive: true }).catch(() => void 0);
@@ -14,4 +15,52 @@ const copyDir = async (srcDir: string, tarDir: string) => {
1415
}
1516
};
1617

18+
export const externalCorePackage = (id: string) =>
19+
(id.includes("node_modules") || (id.includes("@git-diff-view/") && !id.endsWith("@git-diff-view/utils"))) &&
20+
!id.includes("tslib");
21+
22+
export const external = (id: string) =>
23+
(id.includes("node_modules") || (id.includes("@git-diff-view/") && !id.endsWith("@git-diff-view/utils"))) &&
24+
!id.includes("tslib") &&
25+
!id.endsWith(".css");
26+
27+
// fix css path not found in legacy module bundler
28+
export const copyCss = async (packageName: string, file: string) => {
29+
const cssPath = resolve(process.cwd(), "packages", packageName, "dist", "css", file);
30+
const cssContent = await readFile(cssPath, "utf-8");
31+
const legacyCssDirPath = resolve(process.cwd(), "packages", packageName, "styles");
32+
await mkdir(legacyCssDirPath).catch(() => void 0);
33+
const cssDistPath = resolve(legacyCssDirPath, file);
34+
await writeFile(cssDistPath, cssContent);
35+
};
36+
37+
export const clean = async (packageName: string) => {
38+
const typePath = resolve(process.cwd(), "packages", packageName, "index.d.ts");
39+
const content = await readFile(typePath, "utf-8");
40+
await writeFile(typePath, content.replace(/#private;/g, ""));
41+
};
42+
43+
export const clear = async (packageName: string) => {
44+
const typeDirs = resolve(process.cwd(), "packages", packageName, "dist", "types");
45+
await rm(typeDirs, { recursive: true, force: true });
46+
};
47+
48+
export const buildType = async (packageName: string) => {
49+
await new Promise<void>((r, j) => {
50+
const ls = spawn(`cd packages/${packageName} && pnpm run gen:type`, { shell: true, stdio: "inherit" });
51+
ls.on("close", () => r());
52+
ls.on("error", (e) => j(e));
53+
});
54+
await clean(packageName);
55+
await clear(packageName);
56+
};
57+
58+
export const buildCss = async (packageName: string) => {
59+
await new Promise<void>((r, j) => {
60+
const ls = spawn(`cd packages/${packageName} && pnpm run gen:css`, { shell: true, stdio: "inherit" });
61+
ls.on("close", () => r());
62+
ls.on("error", (e) => j(e));
63+
});
64+
};
65+
1766
export const preSvelte = async () => await copyDir("utils/src", "svelte/src/lib/utils");

0 commit comments

Comments
 (0)