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" ;
23import { 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 ( / # p r i v a t e ; / 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+
1766export const preSvelte = async ( ) => await copyDir ( "utils/src" , "svelte/src/lib/utils" ) ;
0 commit comments