@@ -23,25 +23,14 @@ try {
23
23
) ;
24
24
console . log ( ) ;
25
25
26
- console . log ( chalk . gray `Checking gh auth status...` ) ;
27
- let auth ;
28
- try {
29
- await $ `gh auth status` ;
30
- auth = ( await $ `gh auth token` ) . toString ( ) . trim ( ) ;
31
- } catch ( error ) {
32
- throw new Error ( error . stderr ) ;
33
- }
34
-
35
- console . log ( chalk . gray `✔️ Done.` ) ;
36
- console . log ( ) ;
37
-
38
26
const { values } = parseArgs ( {
39
27
args : process . argv . slice ( 2 ) ,
40
28
options : {
41
29
description : { type : "string" } ,
42
30
owner : { type : "string" } ,
43
31
repository : { type : "string" } ,
44
32
title : { type : "string" } ,
33
+ "skip-api" : { type : "boolean" } ,
45
34
} ,
46
35
tokens : true ,
47
36
strict : false ,
80
69
"How would you describe the new package?"
81
70
) ;
82
71
72
+ const skipApi = await getPrefillOrPromptedValue (
73
+ "skip-api" ,
74
+ "Whether to skip calling the GitHub API (effectively making this a local-only change)."
75
+ ) ;
76
+
83
77
console . log ( ) ;
84
78
console . log ( chalk . gray `Hydrating package metadata locally...` ) ;
85
79
@@ -118,6 +112,7 @@ try {
118
112
[ "JoshuaKGoldberg" , owner ] ,
119
113
[ "template-typescript-node-package" , repository ] ,
120
114
[ / " s e t u p " : " .* " , / , `` , "./package.json" ] ,
115
+ [ / " s e t u p : t e s t " : " .* " , / , `` , "./package.json" ] ,
121
116
[
122
117
`"version": "${ existingPackage . version } "` ,
123
118
`"version": "0.0.0"` ,
@@ -159,87 +154,105 @@ try {
159
154
160
155
console . log ( chalk . gray `✔️ Done.` ) ;
161
156
157
+ console . log ( chalk . gray `✔️ Done.` ) ;
162
158
console . log ( ) ;
163
- console . log ( chalk . gray `Hydrating repository labels...` ) ;
164
159
165
- const existingLabels = JSON . parse (
166
- ( await $ `gh label list --json name` ) . stdout || "[]"
167
- ) ;
160
+ if ( skipApi ) {
161
+ console . log ( chalk . gray `➖ Skipping API hydration.` ) ;
162
+ } else {
163
+ console . log ( chalk . gray `Checking gh auth status...` ) ;
164
+ let auth ;
165
+ try {
166
+ await $ `gh auth status` ;
167
+ auth = ( await $ `gh auth token` ) . toString ( ) . trim ( ) ;
168
+ } catch ( error ) {
169
+ throw new Error ( error . stderr ) ;
170
+ }
168
171
169
- for ( const outcome of outcomeLabels ) {
170
- const action = existingLabels . some (
171
- ( existing ) => existing . name === outcome . name
172
- )
173
- ? "edit"
174
- : "create" ;
175
- await $ `gh label ${ action } ${ outcome . name } --color ${ outcome . color } --description ${ outcome . description } ` ;
176
- }
172
+ console . log ( chalk . gray `✔️ Done.` ) ;
173
+ console . log ( ) ;
177
174
178
- console . log ( chalk . gray `✔️ Done .` ) ;
175
+ console . log ( chalk . gray `Hydrating repository labels.. .` ) ;
179
176
180
- console . log ( ) ;
181
- console . log ( chalk . gray `Hydrating initial repository settings...` ) ;
182
-
183
- const octokit = new Octokit ( { auth } ) ;
184
-
185
- octokit . rest . repos . update ( {
186
- allow_auto_merge : true ,
187
- allow_rebase_merge : false ,
188
- allow_squash_merge : true ,
189
- default_branch : "main" ,
190
- delete_branch_on_merge : true ,
191
- description,
192
- has_wiki : false ,
193
- owner,
194
- repo : repository ,
195
- } ) ;
177
+ const existingLabels = JSON . parse (
178
+ ( await $ `gh label list --json name` ) . stdout || "[]"
179
+ ) ;
196
180
197
- console . log ( ) ;
198
- console . log ( chalk . gray `Hydrating branch protection settings...` ) ;
199
-
200
- // Note: keep this inline script in sync with .github/workflows/release.yml!
201
- // Todo: it would be nice to not have two sources of truth...
202
- // https://github.com/JoshuaKGoldberg/template-typescript-node-package/issues/145
203
- await octokit . request (
204
- `PUT /repos/${ owner } /${ repository } /branches/main/protection` ,
205
- {
206
- allow_deletions : false ,
207
- allow_force_pushes : true ,
208
- allow_fork_pushes : false ,
209
- allow_fork_syncing : true ,
210
- block_creations : false ,
211
- branch : "main" ,
212
- enforce_admins : false ,
213
- owner,
214
- repo : repository ,
215
- required_conversation_resolution : true ,
216
- required_linear_history : false ,
217
- required_pull_request_reviews : null ,
218
- required_status_checks : {
219
- checks : [
220
- { context : "build" } ,
221
- { context : "compliance" } ,
222
- { context : "lint" } ,
223
- { context : "markdown" } ,
224
- { context : "package" } ,
225
- { context : "packages" } ,
226
- { context : "prettier" } ,
227
- { context : "prune" } ,
228
- { context : "spelling" } ,
229
- { context : "test" } ,
230
- ] ,
231
- strict : false ,
232
- } ,
233
- restrictions : null ,
181
+ for ( const outcome of outcomeLabels ) {
182
+ const action = existingLabels . some (
183
+ ( existing ) => existing . name === outcome . name
184
+ )
185
+ ? "edit"
186
+ : "create" ;
187
+ await $ `gh label ${ action } ${ outcome . name } --color ${ outcome . color } --description ${ outcome . description } ` ;
234
188
}
235
- ) ;
189
+ console . log ( chalk . gray `✔️ Done.` ) ;
236
190
237
- console . log ( chalk . gray `✔️ Done.` ) ;
191
+ console . log ( ) ;
192
+ console . log ( chalk . gray `Hydrating initial repository settings...` ) ;
193
+
194
+ const octokit = new Octokit ( { auth } ) ;
195
+
196
+ octokit . rest . repos . update ( {
197
+ allow_auto_merge : true ,
198
+ allow_rebase_merge : false ,
199
+ allow_squash_merge : true ,
200
+ default_branch : "main" ,
201
+ delete_branch_on_merge : true ,
202
+ description,
203
+ has_wiki : false ,
204
+ owner,
205
+ repo : repository ,
206
+ } ) ;
207
+
208
+ console . log ( ) ;
209
+ console . log ( chalk . gray `Hydrating branch protection settings...` ) ;
210
+
211
+ // Note: keep this inline script in sync with .github/workflows/release.yml!
212
+ // Todo: it would be nice to not have two sources of truth...
213
+ // https://github.com/JoshuaKGoldberg/template-typescript-node-package/issues/145
214
+ await octokit . request (
215
+ `PUT /repos/${ owner } /${ repository } /branches/main/protection` ,
216
+ {
217
+ allow_deletions : false ,
218
+ allow_force_pushes : true ,
219
+ allow_fork_pushes : false ,
220
+ allow_fork_syncing : true ,
221
+ block_creations : false ,
222
+ branch : "main" ,
223
+ enforce_admins : false ,
224
+ owner,
225
+ repo : repository ,
226
+ required_conversation_resolution : true ,
227
+ required_linear_history : false ,
228
+ required_pull_request_reviews : null ,
229
+ required_status_checks : {
230
+ checks : [
231
+ { context : "build" } ,
232
+ { context : "compliance" } ,
233
+ { context : "lint" } ,
234
+ { context : "markdown" } ,
235
+ { context : "package" } ,
236
+ { context : "packages" } ,
237
+ { context : "prettier" } ,
238
+ { context : "prune" } ,
239
+ { context : "spelling" } ,
240
+ { context : "test" } ,
241
+ ] ,
242
+ strict : false ,
243
+ } ,
244
+ restrictions : null ,
245
+ }
246
+ ) ;
247
+
248
+ console . log ( chalk . gray `✔️ Done.` ) ;
249
+ }
238
250
239
251
console . log ( ) ;
240
252
console . log ( chalk . gray `Removing setup script...` ) ;
241
253
242
254
await fs . rm ( "./script" , { force : true , recursive : true } ) ;
255
+ await fs . rm ( ".github/workflows/setup.yml" ) ;
243
256
244
257
console . log ( chalk . gray `✔️ Done.` ) ;
245
258
} catch ( error ) {
0 commit comments