1
1
import { preprocess } from '@sveltejs/site-kit/markdown/preprocess' ;
2
2
import path from 'node:path' ;
3
3
import fs from 'node:fs' ;
4
+ import { parseArgs } from 'node:util' ;
4
5
import ts from 'typescript' ;
5
6
import glob from 'tiny-glob/sync' ;
6
7
import chokidar from 'chokidar' ;
@@ -19,6 +20,22 @@ interface Package {
19
20
process_modules ?: ( modules : Modules , pkg : Package ) => Promise < Modules > ;
20
21
}
21
22
23
+ const parsed = parseArgs ( {
24
+ args : process . argv . slice ( 2 ) ,
25
+ options : {
26
+ watch : {
27
+ type : 'boolean' ,
28
+ short : 'w'
29
+ } ,
30
+ pull : {
31
+ type : 'boolean' ,
32
+ short : 'p'
33
+ }
34
+ } ,
35
+ strict : true ,
36
+ allowPositionals : true
37
+ } ) ;
38
+
22
39
const dirname = fileURLToPath ( new URL ( '.' , import . meta. url ) ) ;
23
40
const REPOS = path . join ( dirname , '../../repos' ) ;
24
41
const DOCS = path . join ( dirname , '../../content/docs' ) ;
@@ -111,29 +128,42 @@ const packages: Package[] = [
111
128
{
112
129
name : 'cli' ,
113
130
repo : 'sveltejs/cli' ,
114
- branch : 'chore/add-docs ' ,
131
+ branch : 'main ' ,
115
132
pkg : 'packages/cli' ,
116
133
docs : 'documentation/docs' ,
117
134
types : null
118
135
}
119
136
] ;
120
137
138
+ const unknown = parsed . positionals . filter ( ( name ) => ! packages . some ( ( pkg ) => pkg . name === name ) ) ;
139
+
140
+ if ( unknown . length > 0 ) {
141
+ throw new Error (
142
+ `Valid repos are ${ packages . map ( ( pkg ) => pkg . name ) . join ( ', ' ) } (saw ${ unknown . join ( ', ' ) } )`
143
+ ) ;
144
+ }
145
+
146
+ const filtered =
147
+ parsed . positionals . length === 0
148
+ ? packages
149
+ : packages . filter ( ( pkg ) => parsed . positionals . includes ( pkg . name ) ) ;
150
+
121
151
/**
122
152
* Depending on your setup, this will either clone the Svelte and SvelteKit repositories
123
153
* or use the local paths you provided above to read the documentation files.
124
154
* It will then copy them into the `content/docs` directory and process them to replace
125
155
* placeholders for types with content from the generated types.
126
156
*/
127
- if ( process . env . USE_GIT === 'true' ) {
157
+ if ( parsed . values . pull ) {
128
158
try {
129
159
fs . mkdirSync ( REPOS ) ;
130
160
} catch {
131
161
// ignore if it already exists
132
162
}
133
163
134
- await Promise . all (
135
- packages . map ( ( pkg ) => clone_repo ( `https://github.com/${ pkg . repo } .git` , pkg . branch , REPOS ) )
136
- ) ;
164
+ for ( const pkg of filtered ) {
165
+ await clone_repo ( `https://github.com/${ pkg . repo } .git` , pkg . name , pkg . branch , REPOS ) ;
166
+ }
137
167
}
138
168
139
169
async function sync ( pkg : Package ) {
@@ -157,16 +187,18 @@ async function sync(pkg: Package) {
157
187
}
158
188
}
159
189
160
- for ( const pkg of packages ) {
190
+ for ( const pkg of filtered ) {
161
191
await sync ( pkg ) ;
162
192
}
163
193
164
- if ( process . argv . includes ( '-w' ) || process . argv . includes ( '-- watch' ) ) {
165
- for ( const pkg of packages ) {
194
+ if ( parsed . values . watch ) {
195
+ for ( const pkg of filtered ) {
166
196
chokidar
167
197
. watch ( `${ REPOS } /${ pkg . name } /${ pkg . docs } ` , { ignoreInitial : true } )
168
198
. on ( 'all' , ( event ) => {
169
199
sync ( pkg ) ;
170
200
} ) ;
171
201
}
202
+
203
+ console . log ( `\nwatching for changes in ${ parsed . positionals . join ( ', ' ) } ` ) ;
172
204
}
0 commit comments