@@ -4,6 +4,7 @@ import path from 'path';
4
4
import fs from 'fs' ;
5
5
import debug from 'debug' ;
6
6
import chalk from 'chalk' ;
7
+ import type { BunFile } from 'bun' ;
7
8
8
9
const log = debug ( 'wd:sync-logos' ) ;
9
10
@@ -27,8 +28,7 @@ async function getMonorepoRoot() {
27
28
function isDirectorySymlink ( dirPath : string ) {
28
29
try {
29
30
const stats = fs . lstatSync ( dirPath ) ;
30
- console . log ( { isSymlink : stats . isSymbolicLink ( ) , isDirectory : stats . isDirectory ( ) } ) ;
31
- return stats . isSymbolicLink ( ) && stats . isDirectory ( ) ;
31
+ return stats . isSymbolicLink ( ) ;
32
32
} catch ( error ) {
33
33
return false ;
34
34
}
@@ -49,7 +49,7 @@ async function copyFiles({
49
49
} ) {
50
50
// if we are in copy mode, remove any existing symlink and copy the files
51
51
if ( isLinked ) {
52
- fs . rmdirSync ( packageLogosDir , { recursive : true } ) ;
52
+ fs . unlinkSync ( packageLogosDir ) ;
53
53
log ( `\t\t\t🗑️ Deleted existing symlink for ${ packageDir } /logos` ) ;
54
54
} else if ( isCopied ) {
55
55
fs . rmSync ( packageLogosDir , { recursive : true , force : true } ) ;
@@ -92,23 +92,37 @@ async function symlinkFiles({
92
92
93
93
const source = packageLogosDir ;
94
94
const target = path . relative ( source , logosDir ) ;
95
- fs . symlinkSync ( target , source , 'dir ' ) ;
95
+ fs . symlinkSync ( target , source , 'junction ' ) ;
96
96
log ( `\t\t\t🔗 Symlinked ${ logosDir } to ${ packageDir } /logos` ) ;
97
97
}
98
98
99
- async function updatePackageJson ( { packageDir, packagesDir } : { packageDir : string ; packagesDir : string } ) {
100
- // ensure "files" field in package.json includes "logos"
99
+ async function getPackageJson ( { packageDir, packagesDir } : { packageDir : string ; packagesDir : string } ) {
101
100
const packageJsonPath = path . join ( packagesDir , packageDir , 'package.json' ) ;
102
101
const packageJsonFile = Bun . file ( packageJsonPath ) ;
103
102
const pkg = await packageJsonFile . json ( ) ;
103
+ return { file : packageJsonFile , pkg, path : packageJsonPath , nicePath : path . join ( packageDir , 'package.json' ) } ;
104
+ }
105
+
106
+ async function updatePackageJson ( {
107
+ pkg,
108
+ file,
109
+ path,
110
+ nicePath,
111
+ } : {
112
+ pkg : any ;
113
+ file : BunFile ;
114
+ path : string ;
115
+ nicePath : string ;
116
+ } ) {
117
+ // ensure "files" field in package.json includes "logos"
104
118
if ( ! pkg . files ) {
105
119
pkg . files = [ 'logos' ] ;
106
- await packageJsonFile . write ( JSON . stringify ( pkg , null , 2 ) ) ;
107
- log ( `\t\t📝 Added "logos" to "files" in ${ packageDir } /package.json ` ) ;
120
+ await file . write ( JSON . stringify ( pkg , null , 2 ) ) ;
121
+ log ( `\t\t📝 Added "logos" to "files" in ${ nicePath } ` ) ;
108
122
} else if ( ! pkg . files . includes ( 'logos' ) ) {
109
123
pkg . files . push ( 'logos' ) ;
110
- await packageJsonFile . write ( JSON . stringify ( pkg , null , 2 ) ) ;
111
- log ( `\t\t📝 Added "logos" to "files" in ${ packageDir } /package.json ` ) ;
124
+ await file . write ( JSON . stringify ( pkg , null , 2 ) ) ;
125
+ log ( `\t\t📝 Added "logos" to "files" in ${ nicePath } ` ) ;
112
126
}
113
127
}
114
128
@@ -130,6 +144,13 @@ async function main() {
130
144
const packageLogosDir = path . join ( packagesDir , packageDir , 'logos' ) ;
131
145
const isLinked = isDirectorySymlink ( packageLogosDir ) ;
132
146
const isCopied = ! isLinked && fs . existsSync ( packageLogosDir ) ;
147
+ const details = await getPackageJson ( { packageDir, packagesDir } ) ;
148
+
149
+ if ( details . pkg . private ) {
150
+ log ( `\t\t🔒 Skipping private package ${ details . nicePath } ` ) ;
151
+ continue ;
152
+ }
153
+
133
154
log ( `\t\t🔁 Syncing logos to ${ packageDir } ` ) ;
134
155
135
156
if ( ! copyLogos ) {
@@ -150,7 +171,7 @@ async function main() {
150
171
} ) ;
151
172
}
152
173
153
- await updatePackageJson ( { packageDir , packagesDir } ) ;
174
+ await updatePackageJson ( details ) ;
154
175
}
155
176
}
156
177
0 commit comments