@turbo/gen 1.13.4-canary.5 → 2.0.0-canary.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. package/LICENSE +4 -370
  2. package/dist/cli.js +1 -1
  3. package/package.json +5 -5
package/LICENSE CHANGED
@@ -1,373 +1,7 @@
1
- Mozilla Public License Version 2.0
2
- ==================================
1
+ Copyright (c) 2024 Vercel, Inc
3
2
 
4
- 1. Definitions
5
- --------------
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
4
 
7
- 1.1. "Contributor"
8
- means each individual or legal entity that creates, contributes to
9
- the creation of, or owns Covered Software.
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10
6
 
11
- 1.2. "Contributor Version"
12
- means the combination of the Contributions of others (if any) used
13
- by a Contributor and that particular Contributor's Contribution.
14
-
15
- 1.3. "Contribution"
16
- means Covered Software of a particular Contributor.
17
-
18
- 1.4. "Covered Software"
19
- means Source Code Form to which the initial Contributor has attached
20
- the notice in Exhibit A, the Executable Form of such Source Code
21
- Form, and Modifications of such Source Code Form, in each case
22
- including portions thereof.
23
-
24
- 1.5. "Incompatible With Secondary Licenses"
25
- means
26
-
27
- (a) that the initial Contributor has attached the notice described
28
- in Exhibit B to the Covered Software; or
29
-
30
- (b) that the Covered Software was made available under the terms of
31
- version 1.1 or earlier of the License, but not also under the
32
- terms of a Secondary License.
33
-
34
- 1.6. "Executable Form"
35
- means any form of the work other than Source Code Form.
36
-
37
- 1.7. "Larger Work"
38
- means a work that combines Covered Software with other material, in
39
- a separate file or files, that is not Covered Software.
40
-
41
- 1.8. "License"
42
- means this document.
43
-
44
- 1.9. "Licensable"
45
- means having the right to grant, to the maximum extent possible,
46
- whether at the time of the initial grant or subsequently, any and
47
- all of the rights conveyed by this License.
48
-
49
- 1.10. "Modifications"
50
- means any of the following:
51
-
52
- (a) any file in Source Code Form that results from an addition to,
53
- deletion from, or modification of the contents of Covered
54
- Software; or
55
-
56
- (b) any new file in Source Code Form that contains any Covered
57
- Software.
58
-
59
- 1.11. "Patent Claims" of a Contributor
60
- means any patent claim(s), including without limitation, method,
61
- process, and apparatus claims, in any patent Licensable by such
62
- Contributor that would be infringed, but for the grant of the
63
- License, by the making, using, selling, offering for sale, having
64
- made, import, or transfer of either its Contributions or its
65
- Contributor Version.
66
-
67
- 1.12. "Secondary License"
68
- means either the GNU General Public License, Version 2.0, the GNU
69
- Lesser General Public License, Version 2.1, the GNU Affero General
70
- Public License, Version 3.0, or any later versions of those
71
- licenses.
72
-
73
- 1.13. "Source Code Form"
74
- means the form of the work preferred for making modifications.
75
-
76
- 1.14. "You" (or "Your")
77
- means an individual or a legal entity exercising rights under this
78
- License. For legal entities, "You" includes any entity that
79
- controls, is controlled by, or is under common control with You. For
80
- purposes of this definition, "control" means (a) the power, direct
81
- or indirect, to cause the direction or management of such entity,
82
- whether by contract or otherwise, or (b) ownership of more than
83
- fifty percent (50%) of the outstanding shares or beneficial
84
- ownership of such entity.
85
-
86
- 2. License Grants and Conditions
87
- --------------------------------
88
-
89
- 2.1. Grants
90
-
91
- Each Contributor hereby grants You a world-wide, royalty-free,
92
- non-exclusive license:
93
-
94
- (a) under intellectual property rights (other than patent or trademark)
95
- Licensable by such Contributor to use, reproduce, make available,
96
- modify, display, perform, distribute, and otherwise exploit its
97
- Contributions, either on an unmodified basis, with Modifications, or
98
- as part of a Larger Work; and
99
-
100
- (b) under Patent Claims of such Contributor to make, use, sell, offer
101
- for sale, have made, import, and otherwise transfer either its
102
- Contributions or its Contributor Version.
103
-
104
- 2.2. Effective Date
105
-
106
- The licenses granted in Section 2.1 with respect to any Contribution
107
- become effective for each Contribution on the date the Contributor first
108
- distributes such Contribution.
109
-
110
- 2.3. Limitations on Grant Scope
111
-
112
- The licenses granted in this Section 2 are the only rights granted under
113
- this License. No additional rights or licenses will be implied from the
114
- distribution or licensing of Covered Software under this License.
115
- Notwithstanding Section 2.1(b) above, no patent license is granted by a
116
- Contributor:
117
-
118
- (a) for any code that a Contributor has removed from Covered Software;
119
- or
120
-
121
- (b) for infringements caused by: (i) Your and any other third party's
122
- modifications of Covered Software, or (ii) the combination of its
123
- Contributions with other software (except as part of its Contributor
124
- Version); or
125
-
126
- (c) under Patent Claims infringed by Covered Software in the absence of
127
- its Contributions.
128
-
129
- This License does not grant any rights in the trademarks, service marks,
130
- or logos of any Contributor (except as may be necessary to comply with
131
- the notice requirements in Section 3.4).
132
-
133
- 2.4. Subsequent Licenses
134
-
135
- No Contributor makes additional grants as a result of Your choice to
136
- distribute the Covered Software under a subsequent version of this
137
- License (see Section 10.2) or under the terms of a Secondary License (if
138
- permitted under the terms of Section 3.3).
139
-
140
- 2.5. Representation
141
-
142
- Each Contributor represents that the Contributor believes its
143
- Contributions are its original creation(s) or it has sufficient rights
144
- to grant the rights to its Contributions conveyed by this License.
145
-
146
- 2.6. Fair Use
147
-
148
- This License is not intended to limit any rights You have under
149
- applicable copyright doctrines of fair use, fair dealing, or other
150
- equivalents.
151
-
152
- 2.7. Conditions
153
-
154
- Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
155
- in Section 2.1.
156
-
157
- 3. Responsibilities
158
- -------------------
159
-
160
- 3.1. Distribution of Source Form
161
-
162
- All distribution of Covered Software in Source Code Form, including any
163
- Modifications that You create or to which You contribute, must be under
164
- the terms of this License. You must inform recipients that the Source
165
- Code Form of the Covered Software is governed by the terms of this
166
- License, and how they can obtain a copy of this License. You may not
167
- attempt to alter or restrict the recipients' rights in the Source Code
168
- Form.
169
-
170
- 3.2. Distribution of Executable Form
171
-
172
- If You distribute Covered Software in Executable Form then:
173
-
174
- (a) such Covered Software must also be made available in Source Code
175
- Form, as described in Section 3.1, and You must inform recipients of
176
- the Executable Form how they can obtain a copy of such Source Code
177
- Form by reasonable means in a timely manner, at a charge no more
178
- than the cost of distribution to the recipient; and
179
-
180
- (b) You may distribute such Executable Form under the terms of this
181
- License, or sublicense it under different terms, provided that the
182
- license for the Executable Form does not attempt to limit or alter
183
- the recipients' rights in the Source Code Form under this License.
184
-
185
- 3.3. Distribution of a Larger Work
186
-
187
- You may create and distribute a Larger Work under terms of Your choice,
188
- provided that You also comply with the requirements of this License for
189
- the Covered Software. If the Larger Work is a combination of Covered
190
- Software with a work governed by one or more Secondary Licenses, and the
191
- Covered Software is not Incompatible With Secondary Licenses, this
192
- License permits You to additionally distribute such Covered Software
193
- under the terms of such Secondary License(s), so that the recipient of
194
- the Larger Work may, at their option, further distribute the Covered
195
- Software under the terms of either this License or such Secondary
196
- License(s).
197
-
198
- 3.4. Notices
199
-
200
- You may not remove or alter the substance of any license notices
201
- (including copyright notices, patent notices, disclaimers of warranty,
202
- or limitations of liability) contained within the Source Code Form of
203
- the Covered Software, except that You may alter any license notices to
204
- the extent required to remedy known factual inaccuracies.
205
-
206
- 3.5. Application of Additional Terms
207
-
208
- You may choose to offer, and to charge a fee for, warranty, support,
209
- indemnity or liability obligations to one or more recipients of Covered
210
- Software. However, You may do so only on Your own behalf, and not on
211
- behalf of any Contributor. You must make it absolutely clear that any
212
- such warranty, support, indemnity, or liability obligation is offered by
213
- You alone, and You hereby agree to indemnify every Contributor for any
214
- liability incurred by such Contributor as a result of warranty, support,
215
- indemnity or liability terms You offer. You may include additional
216
- disclaimers of warranty and limitations of liability specific to any
217
- jurisdiction.
218
-
219
- 4. Inability to Comply Due to Statute or Regulation
220
- ---------------------------------------------------
221
-
222
- If it is impossible for You to comply with any of the terms of this
223
- License with respect to some or all of the Covered Software due to
224
- statute, judicial order, or regulation then You must: (a) comply with
225
- the terms of this License to the maximum extent possible; and (b)
226
- describe the limitations and the code they affect. Such description must
227
- be placed in a text file included with all distributions of the Covered
228
- Software under this License. Except to the extent prohibited by statute
229
- or regulation, such description must be sufficiently detailed for a
230
- recipient of ordinary skill to be able to understand it.
231
-
232
- 5. Termination
233
- --------------
234
-
235
- 5.1. The rights granted under this License will terminate automatically
236
- if You fail to comply with any of its terms. However, if You become
237
- compliant, then the rights granted under this License from a particular
238
- Contributor are reinstated (a) provisionally, unless and until such
239
- Contributor explicitly and finally terminates Your grants, and (b) on an
240
- ongoing basis, if such Contributor fails to notify You of the
241
- non-compliance by some reasonable means prior to 60 days after You have
242
- come back into compliance. Moreover, Your grants from a particular
243
- Contributor are reinstated on an ongoing basis if such Contributor
244
- notifies You of the non-compliance by some reasonable means, this is the
245
- first time You have received notice of non-compliance with this License
246
- from such Contributor, and You become compliant prior to 30 days after
247
- Your receipt of the notice.
248
-
249
- 5.2. If You initiate litigation against any entity by asserting a patent
250
- infringement claim (excluding declaratory judgment actions,
251
- counter-claims, and cross-claims) alleging that a Contributor Version
252
- directly or indirectly infringes any patent, then the rights granted to
253
- You by any and all Contributors for the Covered Software under Section
254
- 2.1 of this License shall terminate.
255
-
256
- 5.3. In the event of termination under Sections 5.1 or 5.2 above, all
257
- end user license agreements (excluding distributors and resellers) which
258
- have been validly granted by You or Your distributors under this License
259
- prior to termination shall survive termination.
260
-
261
- ************************************************************************
262
- * *
263
- * 6. Disclaimer of Warranty *
264
- * ------------------------- *
265
- * *
266
- * Covered Software is provided under this License on an "as is" *
267
- * basis, without warranty of any kind, either expressed, implied, or *
268
- * statutory, including, without limitation, warranties that the *
269
- * Covered Software is free of defects, merchantable, fit for a *
270
- * particular purpose or non-infringing. The entire risk as to the *
271
- * quality and performance of the Covered Software is with You. *
272
- * Should any Covered Software prove defective in any respect, You *
273
- * (not any Contributor) assume the cost of any necessary servicing, *
274
- * repair, or correction. This disclaimer of warranty constitutes an *
275
- * essential part of this License. No use of any Covered Software is *
276
- * authorized under this License except under this disclaimer. *
277
- * *
278
- ************************************************************************
279
-
280
- ************************************************************************
281
- * *
282
- * 7. Limitation of Liability *
283
- * -------------------------- *
284
- * *
285
- * Under no circumstances and under no legal theory, whether tort *
286
- * (including negligence), contract, or otherwise, shall any *
287
- * Contributor, or anyone who distributes Covered Software as *
288
- * permitted above, be liable to You for any direct, indirect, *
289
- * special, incidental, or consequential damages of any character *
290
- * including, without limitation, damages for lost profits, loss of *
291
- * goodwill, work stoppage, computer failure or malfunction, or any *
292
- * and all other commercial damages or losses, even if such party *
293
- * shall have been informed of the possibility of such damages. This *
294
- * limitation of liability shall not apply to liability for death or *
295
- * personal injury resulting from such party's negligence to the *
296
- * extent applicable law prohibits such limitation. Some *
297
- * jurisdictions do not allow the exclusion or limitation of *
298
- * incidental or consequential damages, so this exclusion and *
299
- * limitation may not apply to You. *
300
- * *
301
- ************************************************************************
302
-
303
- 8. Litigation
304
- -------------
305
-
306
- Any litigation relating to this License may be brought only in the
307
- courts of a jurisdiction where the defendant maintains its principal
308
- place of business and such litigation shall be governed by laws of that
309
- jurisdiction, without reference to its conflict-of-law provisions.
310
- Nothing in this Section shall prevent a party's ability to bring
311
- cross-claims or counter-claims.
312
-
313
- 9. Miscellaneous
314
- ----------------
315
-
316
- This License represents the complete agreement concerning the subject
317
- matter hereof. If any provision of this License is held to be
318
- unenforceable, such provision shall be reformed only to the extent
319
- necessary to make it enforceable. Any law or regulation which provides
320
- that the language of a contract shall be construed against the drafter
321
- shall not be used to construe this License against a Contributor.
322
-
323
- 10. Versions of the License
324
- ---------------------------
325
-
326
- 10.1. New Versions
327
-
328
- Mozilla Foundation is the license steward. Except as provided in Section
329
- 10.3, no one other than the license steward has the right to modify or
330
- publish new versions of this License. Each version will be given a
331
- distinguishing version number.
332
-
333
- 10.2. Effect of New Versions
334
-
335
- You may distribute the Covered Software under the terms of the version
336
- of the License under which You originally received the Covered Software,
337
- or under the terms of any subsequent version published by the license
338
- steward.
339
-
340
- 10.3. Modified Versions
341
-
342
- If you create software not governed by this License, and you want to
343
- create a new license for such software, you may create and use a
344
- modified version of this License if you rename the license and remove
345
- any references to the name of the license steward (except to note that
346
- such modified license differs from this License).
347
-
348
- 10.4. Distributing Source Code Form that is Incompatible With Secondary
349
- Licenses
350
-
351
- If You choose to distribute Source Code Form that is Incompatible With
352
- Secondary Licenses under the terms of this version of the License, the
353
- notice described in Exhibit B of this License must be attached.
354
-
355
- Exhibit A - Source Code Form License Notice
356
- -------------------------------------------
357
-
358
- This Source Code Form is subject to the terms of the Mozilla Public
359
- License, v. 2.0. If a copy of the MPL was not distributed with this
360
- file, You can obtain one at http://mozilla.org/MPL/2.0/.
361
-
362
- If it is not possible or desirable to put the notice in a particular
363
- file, then You may include the notice in a location (such as a LICENSE
364
- file in a relevant directory) where a recipient would be likely to look
365
- for such a notice.
366
-
367
- You may add additional accurate notices of copyright ownership.
368
-
369
- Exhibit B - "Incompatible With Secondary Licenses" Notice
370
- ---------------------------------------------------------
371
-
372
- This Source Code Form is "Incompatible With Secondary Licenses", as
373
- defined by the Mozilla Public License, v. 2.0.
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/dist/cli.js CHANGED
@@ -64,7 +64,7 @@ Please report this to https://github.com/szmarczak/http2-wrapper/`);_(y)}return}
64
64
  `,`1. Your spelling of example ${wr.default.red(`"${e}"`)} might be incorrect.
65
65
  `,"2. You might not be connected to the internet or you are behind a proxy."),process.exit(1))}let o=Li.default.resolve(t);await em(Li.default.dirname(o))||(yt("The application path is not writable, please check folder permissions and try again."),yt("It is likely you do not have write permissions for this folder."),process.exit(1));let a=Li.default.basename(o);try{await(0,Ni.mkdir)(o,{recursive:!0})}catch(p){yt("Unable to create project directory"),yt(p),process.exit(1)}let{isEmpty:u,conflicts:c}=ls(o);u||(yt(`${wr.default.dim(o)} has ${c.length} conflicting ${c.length===1?"file":"files"} - please try a different location`),process.exit(1));let l=process.cwd();process.chdir(o);let f=kf("Downloading files...");try{!r&&i?(gt(`
66
66
  Downloading files from repo ${wr.default.cyan(e)}. This might take a moment.`),gt(),f.start(),await(0,tm.default)(()=>Zp(o,i),{retries:3})):(gt(`
67
- Downloading files${r?"":` for example ${wr.default.cyan(e)}`}. This might take a moment.`),gt(),f.start(),await(0,tm.default)(()=>Qp(o,e),{retries:3}))}catch(p){throw new Gu(qM(p)?p.message:String(p))}finally{f.stop()}let h=Li.default.join(o,"package.json"),m=(0,Ni.existsSync)(h),_=[];if(m){let p;try{p=(0,Ni.readJsonSync)(h)}catch{}p&&_.push(...Object.keys(p.scripts||{}))}let y=t;return Li.default.join(l,a)===t&&(y=a),{cdPath:y,hasPackageJson:m,availableScripts:_,repoInfo:i}}function nm(t,e={to:"camel"}){switch(e.to){case"camel":return t.replace(/(?:[-_][a-z])/g,r=>r.toUpperCase().replace("-","").replace("_",""));default:throw new Error("Not implemented")}}var yv=require("proxy-agent");var $s={name:"@turbo/gen",version:"1.13.4-canary.5",description:"Extend a Turborepo",homepage:"https://turbo.build/repo",license:"MPL-2.0",repository:{type:"git",url:"https://github.com/vercel/turbo",directory:"packages/turbo-gen"},bugs:{url:"https://github.com/vercel/turbo/issues"},bin:"dist/cli.js",types:"dist/types.d.ts",scripts:{build:"tsup",test:"jest",lint:"eslint src/","check-types":"tsc --noEmit"},dependencies:{"@turbo/workspaces":"workspace:*",chalk:"2.4.2",commander:"^10.0.0","fs-extra":"^10.1.0",inquirer:"^8.2.4",minimatch:"^9.0.0","node-plop":"^0.26.3","proxy-agent":"^6.2.2","ts-node":"^10.9.1","update-check":"^1.5.4","validate-npm-package-name":"^5.0.0"},devDependencies:{"@turbo/eslint-config":"workspace:*","@turbo/test-utils":"workspace:*","@turbo/tsconfig":"workspace:*","@turbo/utils":"workspace:*","@types/fs-extra":"^9.0.13","@types/inquirer":"^8.2.5","@types/jest":"^27.4.0","@types/node":"^18.17.2","@types/validate-npm-package-name":"^4.0.0",jest:"^27.4.3","ts-jest":"^27.1.1",tsup:"^6.7.0",typescript:"5.3.3"},files:["dist"],publishConfig:{access:"public"}};var $C=X(require("chalk")),UC=X(require("update-check"));var jM=(0,UC.default)($s).catch(()=>null);async function im(){try{let t=await jM;t!=null&&t.latest&&(L.log(),L.log($C.default.yellow.bold(`A new version of \`${$s.name}\` is available!`)),L.log()),process.exit()}catch{}}var GC=require("@turbo/workspaces");async function Wu({root:t}){let e=t||process.cwd(),r=Wi(e);if(!r)L.error("Unable to infer repository root - override with --root");else try{return(0,GC.getWorkspaceDetails)({root:r})}catch{L.error(`Unable to determine workspace details. Make sure "${e}" is the root, or add "packageManager" to "package.json" or ensure a lockfile is present.`)}process.exit(1)}var Ar=X(require("path")),Vu=X(require("fs-extra")),zu=X(require("node-plop")),WC=require("ts-node"),zC=require("inquirer");var Me=class extends Error{constructor(r,n){var i;super(r);this.name="GenerateError",this.type=(i=n==null?void 0:n.type)!=null?i:"unknown",Error.captureStackTrace(this,Me)}};var VC=["ts","js","cjs"],$M=Ar.default.join("turbo","generators"),YC=VC.map(t=>Ar.default.join($M,`config.${t}`)),UM=[...YC,...VC.map(t=>Ar.default.join(`plopfile.${t}`))];function KC({project:t,configPath:e}){(0,WC.register)({transpileOnly:!0,cwd:t.paths.root,compilerOptions:{module:"nodenext",moduleResolution:"nodenext"}});let r=WM({project:t}),n;if(e){if(!Vu.default.existsSync(e))throw new Me(`No config at "${e}"`,{type:"plop_no_config"});try{n=(0,zu.default)(e,{destBasePath:e,force:!1})}catch(i){L.error(i)}}else{for(let i of UM){let s=Ar.default.join(t.paths.root,i);if(Vu.default.existsSync(s))try{n=(0,zu.default)(s,{destBasePath:t.paths.root,force:!1});break}catch(o){L.error(o)}}!n&&r.length>0&&(n=(0,zu.default)(r[0].config,{destBasePath:r[0].root,force:!1}),r.shift())}return n&&r.forEach(i=>{try{n==null||n.load(i.config,{destBasePath:i.root,force:!1})}catch(s){L.error(s)}}),n}function sm({project:t,configPath:e}){let r=KC({project:t,configPath:e});if(!r)return[];let i=r.getGeneratorList().map(a=>r.getGenerator(a.name)),s={};i.forEach(a=>{let u=a,c=t.workspaceData.workspaces.find(l=>{if(u.basePath===t.paths.root)return!1;let f=u.basePath.split(Ar.default.sep);return f.pop(),f.pop(),Ar.default.join("/",...f)===l.paths.root});c?(c.name in s||(s[c.name]=[]),s[c.name].push(u)):("root"in s||(s.root=[]),s.root.push(u))});let o=[];return Object.keys(s).forEach(a=>{o.push(new zC.Separator(a)),o.push(...s[a])}),o}function GM({project:t,generator:e}){let r={cwd:process.cwd(),root:t.paths.root,workspace:e.basePath?Gi({cwd:e.basePath,target:"package.json"}):void 0},n={};try{n=If(e.basePath)}catch{}return{turbo:{paths:r,configs:n}}}function WM({project:t}){let e=[];return t.workspaceData.workspaces.forEach(r=>{for(let n of YC)Vu.default.existsSync(Ar.default.join(r.paths.root,n))&&e.push({config:Ar.default.join(r.paths.root,n),root:r.paths.root})}),e}async function JC({project:t,generator:e,bypassArgs:r,configPath:n}){let i=KC({project:t,configPath:n});if(!i)throw new Me("Unable to load generators",{type:"plop_unable_to_load_config"});let s=i.getGenerator(e);if(!s)throw new Me(`Generator ${e} not found`,{type:"plop_generator_not_found"});let o=await s.runPrompts(r),a=await s.runActions({...o,...GM({project:t,generator:s})},{onComment:u=>{L.dimmed(u)}});if(a.failures.length>0)throw a.failures.forEach(u=>{u instanceof Error?L.error(`Error - ${u.message}`):L.error(`Error - ${u.error}. Unable to ${u.type} to "${u.path}"`)}),new Me(`Failed to run "${e}" generator`,{type:"plop_error_running_generator"});a.changes.length>0&&(L.info("Changes made:"),a.changes.forEach(u=>{u.path&&L.item(`${u.path} (${u.type})`)}))}var Rn=require("inquirer");async function XC({generators:t,generator:e}){if(e){if(t.find(n=>!(n instanceof Rn.Separator)&&n.name===e))return{selectedGenerator:e};L.warn(`Generator "${e}" not found`),L.log()}return await(0,Rn.prompt)({type:"list",name:"selectedGenerator",message:"Select generator to run",choices:t.map(n=>n instanceof Rn.Separator?n:{name:n.description?` ${n.name}: ${n.description}`:` ${n.name}`,value:n.name})})}async function ZC(){return(0,Rn.prompt)({type:"list",name:"answer",message:"Should the generator config be created with TS or JS?",default:"ts",choices:[{name:"JavaScript",value:"js"},{name:"TypeScript",value:"ts"}]})}async function QC({message:t}){return(0,Rn.prompt)({type:"confirm",name:"answer",message:t})}var om=X(require("path")),Yu=require("fs-extra");async function ev({project:t,template:e}){let r=om.default.join(t.paths.root,"turbo","generators"),n=`simple-${e}`;if(await(0,Yu.pathExists)(r))throw new Me(`Generator config directory already exists at ${r}`,{type:"config_directory_already_exists"});await(0,Yu.copy)(om.default.join(__dirname,"templates",n),r,{recursive:!0})}async function am({generator:t,project:e,opts:r}){let n=!1,i=sm({project:e,configPath:r.config});if(!i.length){L.error("No generators found."),L.log();let{answer:o}=await QC({message:`Would you like to add a config with a sample custom generator to ${e.name}?`});if(o){n=!0;let{answer:a}=await ZC();try{await ev({project:e,template:a})}catch(u){throw u instanceof Me||L.error("Failed to create generator config"),u}if(L.log(),L.info("Generator config successfully created!"),L.info("Loading generator config..."),L.log(),i=sm({project:e,configPath:r.config}),!i.length){L.error("Error loading generator");return}}else{L.log(),L.dimmed("Learn more about custom Turborepo generators - https://turbo.build/repo/docs/core-concepts/monorepos/code-generation#custom-generators");return}}let{selectedGenerator:s}=await XC({generators:i,generator:t});try{await JC({project:e,generator:s,bypassArgs:r.args,configPath:r.config})}catch(o){if(o instanceof Me)throw o;let a="Failed to run generator";throw o instanceof Error&&(a=o.message),new Me(a,{type:"plop_error_running_generator"})}finally{n&&(L.log(),L.info("Congrats! You just ran your first Turborepo generator"),L.dimmed("Learn more about custom Turborepo generators - https://turbo.build/repo/docs/core-concepts/monorepos/code-generation#custom-generators"))}L.log(),L.bold(L.turboGradient(">>> Success!"))}var fm=X(require("path")),Gs=require("fs-extra"),fv=X(require("chalk"));var Us=X(require("path")),iv=require("fs-extra"),vt=require("inquirer"),sv=require("minimatch"),lm=X(require("validate-npm-package-name"));var um=X(require("path"));var tv=X(require("path"));function rv({project:t}){let r=t.workspaceData.workspaces.map(i=>tv.default.relative(t.paths.root,i.paths.root)),n=new Set;return t.workspaceData.globs.forEach(i=>{if(!r.includes(i)){if(!i.startsWith("!")){let o=i.split("/")[0];n.add(o)}}}),Array.from(n)}function cm({project:t,workspace:e}){return um.default.relative(t.paths.root,e.paths.root).split(um.default.sep)[0]}function Ku({project:t}){let e=rv({project:t}),r=e.includes("apps"),n=e.includes("packages"),i={},s=[];return t.workspaceData.workspaces.forEach(o=>{let a=cm({project:t,workspace:o});a!=="apps"&&s.push(o),a in i||(i[a]=[]),i[a].push(o)}),{hasRootApps:r,hasRootPackages:n,workspacesByGroup:i,nonAppWorkspaces:s}}var nv=require("inquirer");function Ju({project:t,type:e,showAllDependencies:r}){let n=Ku({project:t}),i=[],s=t.workspaceData.workspaces;r||(e==="app"&&n.hasRootApps?s=n.workspacesByGroup.apps:e==="package"&&n.nonAppWorkspaces.length>0&&(s=n.nonAppWorkspaces));let o;return s.forEach(a=>{let u=cm({project:t,workspace:a});u!==o&&i.push(new nv.Separator(u)),o=u,i.push(a)}),i}async function ov({override:t,suggestion:e,workspaceType:r}){let{validForNewPackages:n}=(0,lm.default)(t||"");return t&&n?{answer:t}:(0,vt.prompt)({type:"input",name:"answer",default:e,validate:i=>{let{validForNewPackages:s}=(0,lm.default)(i);return s||`Invalid ${r} name`},message:`What is the name of the ${r}?`})}async function av({override:t,message:e}){return t?{answer:t}:(0,vt.prompt)({type:"list",name:"answer",message:e!=null?e:"What type of workspace should be added?",choices:[{name:"app",value:"app"},{name:"package",value:"package"}]})}async function uv({workspaceType:t,workspaceName:e,destination:r,project:n}){let i=e.includes("/")?e.split("/")[1]:e;if(r){let{valid:u,root:c}=ua(r);if(u)return{absolute:c,relative:Us.default.relative(n.paths.root,c)}}let s,o=Ku({project:n});t==="app"&&o.hasRootApps?s=`${n.paths.root}/apps/${i}`:t==="package"&&o.hasRootPackages&&(s=`${n.paths.root}/packages/${i}`);let{answer:a}=await(0,vt.prompt)({type:"input",name:"answer",message:`Where should "${e}" be added?`,default:s?Us.default.relative(n.paths.root,s):void 0,validate:u=>{let c=Us.default.join(n.paths.root,u),{valid:l,error:f}=ua(c),h=n.workspaceData.globs.some(m=>(0,sv.minimatch)(u,m));return l&&h?!0:h?f:`${u} is not a valid workspace location`}});return{absolute:Us.default.join(n.paths.root,a),relative:a}}async function cv({override:t,workspaces:e,workspaceName:r}){if(t){let i=e.find(s=>s instanceof vt.Separator?!1:s.name===t);if(i)return{answer:i};L.warn(`Workspace "${t}" not found`),L.log()}return await(0,vt.prompt)({type:"list",name:"answer",loop:!1,pageSize:25,message:`Which workspace should "${r}" start from?`,choices:e.map(i=>i instanceof vt.Separator?i:{name:` ${i.name}`,value:i})})}async function lv({workspaceName:t,project:e,workspaceSource:r,showAllDependencies:n}){let i={dependencies:{},devDependencies:{},peerDependencies:{},optionalDependencies:{}},{answer:s}=await VM({message:`Add workspace dependencies to "${t}"?`});if(!s)return i;let{answer:o}=await(0,vt.prompt)({type:"checkbox",name:"answer",message:`Select all dependencies types to modify for "${t}"`,loop:!1,choices:[{name:"dependencies",value:"dependencies"},{name:"devDependencies",value:"devDependencies"},{name:"peerDependencies",value:"peerDependencies"},{name:"optionalDependencies",value:"optionalDependencies"}]}),a=Ju({project:e,type:"package",showAllDependencies:n}),u=r?(0,iv.readJsonSync)(r.paths.packageJson):void 0;for(let c of o){let{answer:l}=await(0,vt.prompt)({type:"checkbox",name:"answer",default:u&&Object.keys(u[c]||{}),pageSize:15,message:`Which packages should be added as ${c} to "${t}?`,loop:!1,choices:a.map(h=>h instanceof vt.Separator?h:{name:` ${h.name}`,value:h.name})}),f=(u==null?void 0:u[c])||{};if(Object.keys(f).length){let h=new Set(Object.keys(f));l.forEach(m=>{h.has(m)||(f[m]=e.packageManager==="pnpm"?"workspace:*":"*")}),i[c]=f}else i[c]=l.reduce((h,m)=>({...h,[m]:e.packageManager==="pnpm"?"workspace:*":"*"}),{})}return i}async function VM({message:t}){return(0,vt.prompt)({type:"confirm",name:"answer",message:t})}async function Xu({project:t,opts:e}){var u;let r,n=e.method==="copy"&&e.copy.type==="external"?((u=e.examplePath)==null?void 0:u.split("/").pop())||e.copy.source.split("/").pop():void 0,{answer:i}=await av({override:e.type,message:e.method==="copy"&&e.copy.source==="external"&&n?`What type of workspace should "${n}" be created as?`:void 0}),{answer:s}=await ov({override:e.name,workspaceType:i,suggestion:n});if(e.method==="copy"&&e.copy.type==="internal"){let{answer:c}=await cv({override:e.copy.source,workspaces:Ju({project:t,type:i}),workspaceName:s});r=c}let o=await uv({workspaceType:i,workspaceName:s,project:t,destination:e.destination}),a=await lv({workspaceName:s,project:t,workspaceSource:r,showAllDependencies:e.showAllDependencies});return{type:i,name:s,location:o,source:r,dependencies:a}}async function hm({project:t,opts:e}){let{name:r,location:n,dependencies:i}=await Xu({project:t,opts:e}),s={name:r,version:"0.0.0",private:!0,scripts:{dev:"echo 'Add dev script here'",build:"echo 'Add build script here'",test:"echo 'Add test script here'",lint:"echo 'Add lint script here'"}};Object.keys(i).forEach(o=>{let a=i[o];a&&Object.keys(a).length>0&&(s[o]=a)}),(0,Gs.mkdirSync)(n.absolute,{recursive:!0}),(0,Gs.writeFileSync)(fm.default.join(n.absolute,"package.json"),JSON.stringify(s,null,2)),(0,Gs.writeFileSync)(fm.default.join(n.absolute,"README.md"),`# \`${r}\``),L.log(),L.log(`${fv.default.bold(L.turboGradient(">>> Success!"))} Created ${r} at "${n.relative}"`)}var dm=X(require("path")),Rt=require("fs-extra"),hv=X(require("chalk"));async function pm({project:t,opts:e}){let{name:r,type:n,location:i,source:s,dependencies:o}=await Xu({project:t,opts:e}),a=dm.default.join(i.absolute,"package.json");if(e.copy.type==="external"){L.log(),L.warn("Some manual modifications may be required."),L.dimmed(`This ${n} may require local dependencies or a different package manager than what is available in this repo`),await rm({appPath:i.absolute,example:e.copy.source,examplePath:e.examplePath});try{if((0,Rt.existsSync)(a)){if((await(0,Rt.readJSON)(a)).workspaces)throw new Error("New workspace root detected - unexpected 'workspaces' field in package.json")}else throw new Error("New workspace is missing a package.json file");if((0,Rt.existsSync)(dm.default.join(i.absolute,"pnpm-workspace.yaml")))throw new Error("New workspace root detected - unexpected pnpm-workspace.yaml")}catch(c){let l="UNKNOWN_ERROR";c instanceof Error&&(l=c.message),L.error(l),await(0,Rt.rm)(i.absolute,{recursive:!0,force:!0});return}}else if(s){let c=async f=>Promise.resolve(!f.includes("node_modules")),l=L.turboLoader(`Creating "${r}" from "${s.name}"...`);l.start(),await(0,Rt.copy)(s.paths.root,i.absolute,{filter:c}),l.stop()}let u=await(0,Rt.readJSON)(a);u.name=r,Object.keys(o).forEach(c=>{let l=o[c];l&&Object.keys(l).length>0&&(u[c]=l)}),await(0,Rt.writeJSON)(a,u,{spaces:2}),L.log(),L.log(`${hv.default.bold(L.turboGradient(">>> Success!"))} Created ${r} at "${i.relative}"`)}function KM(t){let{copy:e,...r}=t,n=e===!0||typeof e=="string"?"copy":"empty",i=typeof e=="string"?e:"",s=typeof e=="string"&&e.startsWith("https://")?"external":"internal";return{method:n,copy:{type:s,source:i},...r}}async function Ws(t){let e=await Wu(t),r=KM(t);L.log();let n={project:e,opts:r};r.method==="copy"?(r.copy.type==="external"?L.info(`Copy a remote workspace from ${r.copy.source}`):L.info(`Copy an existing workspace from "${e.name}"`),L.log(),await pm(n)):(L.info(`Add an empty workspace to "${e.name}"`),L.log(),await hm(n))}async function zs(t,e){let r=await Wu(e);L.log(),L.info(`Modify "${r.name}" using custom generators`),L.log(),await am({generator:t,project:r,opts:e})}function dv(t){try{let e=JSON.parse(t),r={};for(let n in e){let i=nm(n,{to:"camel"});r[i]=e[n]}return r}catch(e){L.error("Error parsing arguments",e),process.exit(1)}}async function mm(t,e){var r;if(t==="workspace"){let n=dv(e.json);n.showAllDependencies=(r=n.showAllDependencies)!=null?r:!1;let i=!1,s=n.empty||!0;n.copy===""||n.copy===!0?(i=!0,s=!1):n.copy&&n.copy.length>0&&(i=n.copy,s=!1),n.copy=i,n.empty=s,await Ws(n)}else if(t==="run"){let n=dv(e.json),{generatorName:i,...s}=n;await zs(i,s)}else L.error(`Received unknown command - "${t}" (must be one of "workspace" | "run")`),process.exit(1)}var _v=new yv.ProxyAgent;pv.default.globalAgent=_v;mv.default.globalAgent=_v;var Vs=new qe.Command;Vs.name(gv.default.bold(L.turboGradient("@turbo/gen"))).description("Extend your Turborepo").version($s.version,"-v, --version","Output the current version").helpOption("-h, --help","Display help for command").showHelpAfterError(!1);Vs.command("run",{isDefault:!0}).alias("r").description("Run custom generators").addArgument(new qe.Argument("[generator-name]","The name of the generator to run")).addOption(new qe.Option("-c, --config <config>","Generator configuration file (default: turbo/generators/config.js")).addOption(new qe.Option("-r, --root <dir>","The root of your repository (default: directory with root turbo.json)")).addOption(new qe.Option("-a, --args <args...>","Arguments passed directly to generator").default([])).action(zs);Vs.command("workspace").aliases(["w"]).description("Add a new package or app to your project").addOption(new qe.Option("-n, --name <workspace-name>","Name for the new workspace")).addOption(new qe.Option("-b, --empty","Generate an empty workspace").conflicts("copy").default(!0)).addOption(new qe.Option("-c, --copy [source]",`Generate a workspace using an existing workspace as a template. Can be the name of a local workspace
67
+ Downloading files${r?"":` for example ${wr.default.cyan(e)}`}. This might take a moment.`),gt(),f.start(),await(0,tm.default)(()=>Qp(o,e),{retries:3}))}catch(p){throw new Gu(qM(p)?p.message:String(p))}finally{f.stop()}let h=Li.default.join(o,"package.json"),m=(0,Ni.existsSync)(h),_=[];if(m){let p;try{p=(0,Ni.readJsonSync)(h)}catch{}p&&_.push(...Object.keys(p.scripts||{}))}let y=t;return Li.default.join(l,a)===t&&(y=a),{cdPath:y,hasPackageJson:m,availableScripts:_,repoInfo:i}}function nm(t,e={to:"camel"}){switch(e.to){case"camel":return t.replace(/(?:[-_][a-z])/g,r=>r.toUpperCase().replace("-","").replace("_",""));default:throw new Error("Not implemented")}}var yv=require("proxy-agent");var $s={name:"@turbo/gen",version:"2.0.0-canary.0",description:"Extend a Turborepo",homepage:"https://turbo.build/repo",license:"MIT",repository:{type:"git",url:"https://github.com/vercel/turbo",directory:"packages/turbo-gen"},bugs:{url:"https://github.com/vercel/turbo/issues"},bin:"dist/cli.js",types:"dist/types.d.ts",scripts:{build:"tsup",test:"jest",lint:"eslint src/","check-types":"tsc --noEmit"},dependencies:{"@turbo/workspaces":"workspace:*",chalk:"2.4.2",commander:"^10.0.0","fs-extra":"^10.1.0",inquirer:"^8.2.4",minimatch:"^9.0.0","node-plop":"^0.26.3","proxy-agent":"^6.2.2","ts-node":"^10.9.1","update-check":"^1.5.4","validate-npm-package-name":"^5.0.0"},devDependencies:{"@turbo/eslint-config":"workspace:*","@turbo/test-utils":"workspace:*","@turbo/tsconfig":"workspace:*","@turbo/utils":"workspace:*","@types/fs-extra":"^9.0.13","@types/inquirer":"^8.2.5","@types/jest":"^27.4.0","@types/node":"^18.17.2","@types/validate-npm-package-name":"^4.0.0",jest:"^27.4.3","ts-jest":"^27.1.1",tsup:"^6.7.0",typescript:"5.3.3"},files:["dist"],publishConfig:{access:"public"}};var $C=X(require("chalk")),UC=X(require("update-check"));var jM=(0,UC.default)($s).catch(()=>null);async function im(){try{let t=await jM;t!=null&&t.latest&&(L.log(),L.log($C.default.yellow.bold(`A new version of \`${$s.name}\` is available!`)),L.log()),process.exit()}catch{}}var GC=require("@turbo/workspaces");async function Wu({root:t}){let e=t||process.cwd(),r=Wi(e);if(!r)L.error("Unable to infer repository root - override with --root");else try{return(0,GC.getWorkspaceDetails)({root:r})}catch{L.error(`Unable to determine workspace details. Make sure "${e}" is the root, or add "packageManager" to "package.json" or ensure a lockfile is present.`)}process.exit(1)}var Ar=X(require("path")),Vu=X(require("fs-extra")),zu=X(require("node-plop")),WC=require("ts-node"),zC=require("inquirer");var Me=class extends Error{constructor(r,n){var i;super(r);this.name="GenerateError",this.type=(i=n==null?void 0:n.type)!=null?i:"unknown",Error.captureStackTrace(this,Me)}};var VC=["ts","js","cjs"],$M=Ar.default.join("turbo","generators"),YC=VC.map(t=>Ar.default.join($M,`config.${t}`)),UM=[...YC,...VC.map(t=>Ar.default.join(`plopfile.${t}`))];function KC({project:t,configPath:e}){(0,WC.register)({transpileOnly:!0,cwd:t.paths.root,compilerOptions:{module:"nodenext",moduleResolution:"nodenext"}});let r=WM({project:t}),n;if(e){if(!Vu.default.existsSync(e))throw new Me(`No config at "${e}"`,{type:"plop_no_config"});try{n=(0,zu.default)(e,{destBasePath:e,force:!1})}catch(i){L.error(i)}}else{for(let i of UM){let s=Ar.default.join(t.paths.root,i);if(Vu.default.existsSync(s))try{n=(0,zu.default)(s,{destBasePath:t.paths.root,force:!1});break}catch(o){L.error(o)}}!n&&r.length>0&&(n=(0,zu.default)(r[0].config,{destBasePath:r[0].root,force:!1}),r.shift())}return n&&r.forEach(i=>{try{n==null||n.load(i.config,{destBasePath:i.root,force:!1})}catch(s){L.error(s)}}),n}function sm({project:t,configPath:e}){let r=KC({project:t,configPath:e});if(!r)return[];let i=r.getGeneratorList().map(a=>r.getGenerator(a.name)),s={};i.forEach(a=>{let u=a,c=t.workspaceData.workspaces.find(l=>{if(u.basePath===t.paths.root)return!1;let f=u.basePath.split(Ar.default.sep);return f.pop(),f.pop(),Ar.default.join("/",...f)===l.paths.root});c?(c.name in s||(s[c.name]=[]),s[c.name].push(u)):("root"in s||(s.root=[]),s.root.push(u))});let o=[];return Object.keys(s).forEach(a=>{o.push(new zC.Separator(a)),o.push(...s[a])}),o}function GM({project:t,generator:e}){let r={cwd:process.cwd(),root:t.paths.root,workspace:e.basePath?Gi({cwd:e.basePath,target:"package.json"}):void 0},n={};try{n=If(e.basePath)}catch{}return{turbo:{paths:r,configs:n}}}function WM({project:t}){let e=[];return t.workspaceData.workspaces.forEach(r=>{for(let n of YC)Vu.default.existsSync(Ar.default.join(r.paths.root,n))&&e.push({config:Ar.default.join(r.paths.root,n),root:r.paths.root})}),e}async function JC({project:t,generator:e,bypassArgs:r,configPath:n}){let i=KC({project:t,configPath:n});if(!i)throw new Me("Unable to load generators",{type:"plop_unable_to_load_config"});let s=i.getGenerator(e);if(!s)throw new Me(`Generator ${e} not found`,{type:"plop_generator_not_found"});let o=await s.runPrompts(r),a=await s.runActions({...o,...GM({project:t,generator:s})},{onComment:u=>{L.dimmed(u)}});if(a.failures.length>0)throw a.failures.forEach(u=>{u instanceof Error?L.error(`Error - ${u.message}`):L.error(`Error - ${u.error}. Unable to ${u.type} to "${u.path}"`)}),new Me(`Failed to run "${e}" generator`,{type:"plop_error_running_generator"});a.changes.length>0&&(L.info("Changes made:"),a.changes.forEach(u=>{u.path&&L.item(`${u.path} (${u.type})`)}))}var Rn=require("inquirer");async function XC({generators:t,generator:e}){if(e){if(t.find(n=>!(n instanceof Rn.Separator)&&n.name===e))return{selectedGenerator:e};L.warn(`Generator "${e}" not found`),L.log()}return await(0,Rn.prompt)({type:"list",name:"selectedGenerator",message:"Select generator to run",choices:t.map(n=>n instanceof Rn.Separator?n:{name:n.description?` ${n.name}: ${n.description}`:` ${n.name}`,value:n.name})})}async function ZC(){return(0,Rn.prompt)({type:"list",name:"answer",message:"Should the generator config be created with TS or JS?",default:"ts",choices:[{name:"JavaScript",value:"js"},{name:"TypeScript",value:"ts"}]})}async function QC({message:t}){return(0,Rn.prompt)({type:"confirm",name:"answer",message:t})}var om=X(require("path")),Yu=require("fs-extra");async function ev({project:t,template:e}){let r=om.default.join(t.paths.root,"turbo","generators"),n=`simple-${e}`;if(await(0,Yu.pathExists)(r))throw new Me(`Generator config directory already exists at ${r}`,{type:"config_directory_already_exists"});await(0,Yu.copy)(om.default.join(__dirname,"templates",n),r,{recursive:!0})}async function am({generator:t,project:e,opts:r}){let n=!1,i=sm({project:e,configPath:r.config});if(!i.length){L.error("No generators found."),L.log();let{answer:o}=await QC({message:`Would you like to add a config with a sample custom generator to ${e.name}?`});if(o){n=!0;let{answer:a}=await ZC();try{await ev({project:e,template:a})}catch(u){throw u instanceof Me||L.error("Failed to create generator config"),u}if(L.log(),L.info("Generator config successfully created!"),L.info("Loading generator config..."),L.log(),i=sm({project:e,configPath:r.config}),!i.length){L.error("Error loading generator");return}}else{L.log(),L.dimmed("Learn more about custom Turborepo generators - https://turbo.build/repo/docs/core-concepts/monorepos/code-generation#custom-generators");return}}let{selectedGenerator:s}=await XC({generators:i,generator:t});try{await JC({project:e,generator:s,bypassArgs:r.args,configPath:r.config})}catch(o){if(o instanceof Me)throw o;let a="Failed to run generator";throw o instanceof Error&&(a=o.message),new Me(a,{type:"plop_error_running_generator"})}finally{n&&(L.log(),L.info("Congrats! You just ran your first Turborepo generator"),L.dimmed("Learn more about custom Turborepo generators - https://turbo.build/repo/docs/core-concepts/monorepos/code-generation#custom-generators"))}L.log(),L.bold(L.turboGradient(">>> Success!"))}var fm=X(require("path")),Gs=require("fs-extra"),fv=X(require("chalk"));var Us=X(require("path")),iv=require("fs-extra"),vt=require("inquirer"),sv=require("minimatch"),lm=X(require("validate-npm-package-name"));var um=X(require("path"));var tv=X(require("path"));function rv({project:t}){let r=t.workspaceData.workspaces.map(i=>tv.default.relative(t.paths.root,i.paths.root)),n=new Set;return t.workspaceData.globs.forEach(i=>{if(!r.includes(i)){if(!i.startsWith("!")){let o=i.split("/")[0];n.add(o)}}}),Array.from(n)}function cm({project:t,workspace:e}){return um.default.relative(t.paths.root,e.paths.root).split(um.default.sep)[0]}function Ku({project:t}){let e=rv({project:t}),r=e.includes("apps"),n=e.includes("packages"),i={},s=[];return t.workspaceData.workspaces.forEach(o=>{let a=cm({project:t,workspace:o});a!=="apps"&&s.push(o),a in i||(i[a]=[]),i[a].push(o)}),{hasRootApps:r,hasRootPackages:n,workspacesByGroup:i,nonAppWorkspaces:s}}var nv=require("inquirer");function Ju({project:t,type:e,showAllDependencies:r}){let n=Ku({project:t}),i=[],s=t.workspaceData.workspaces;r||(e==="app"&&n.hasRootApps?s=n.workspacesByGroup.apps:e==="package"&&n.nonAppWorkspaces.length>0&&(s=n.nonAppWorkspaces));let o;return s.forEach(a=>{let u=cm({project:t,workspace:a});u!==o&&i.push(new nv.Separator(u)),o=u,i.push(a)}),i}async function ov({override:t,suggestion:e,workspaceType:r}){let{validForNewPackages:n}=(0,lm.default)(t||"");return t&&n?{answer:t}:(0,vt.prompt)({type:"input",name:"answer",default:e,validate:i=>{let{validForNewPackages:s}=(0,lm.default)(i);return s||`Invalid ${r} name`},message:`What is the name of the ${r}?`})}async function av({override:t,message:e}){return t?{answer:t}:(0,vt.prompt)({type:"list",name:"answer",message:e!=null?e:"What type of workspace should be added?",choices:[{name:"app",value:"app"},{name:"package",value:"package"}]})}async function uv({workspaceType:t,workspaceName:e,destination:r,project:n}){let i=e.includes("/")?e.split("/")[1]:e;if(r){let{valid:u,root:c}=ua(r);if(u)return{absolute:c,relative:Us.default.relative(n.paths.root,c)}}let s,o=Ku({project:n});t==="app"&&o.hasRootApps?s=`${n.paths.root}/apps/${i}`:t==="package"&&o.hasRootPackages&&(s=`${n.paths.root}/packages/${i}`);let{answer:a}=await(0,vt.prompt)({type:"input",name:"answer",message:`Where should "${e}" be added?`,default:s?Us.default.relative(n.paths.root,s):void 0,validate:u=>{let c=Us.default.join(n.paths.root,u),{valid:l,error:f}=ua(c),h=n.workspaceData.globs.some(m=>(0,sv.minimatch)(u,m));return l&&h?!0:h?f:`${u} is not a valid workspace location`}});return{absolute:Us.default.join(n.paths.root,a),relative:a}}async function cv({override:t,workspaces:e,workspaceName:r}){if(t){let i=e.find(s=>s instanceof vt.Separator?!1:s.name===t);if(i)return{answer:i};L.warn(`Workspace "${t}" not found`),L.log()}return await(0,vt.prompt)({type:"list",name:"answer",loop:!1,pageSize:25,message:`Which workspace should "${r}" start from?`,choices:e.map(i=>i instanceof vt.Separator?i:{name:` ${i.name}`,value:i})})}async function lv({workspaceName:t,project:e,workspaceSource:r,showAllDependencies:n}){let i={dependencies:{},devDependencies:{},peerDependencies:{},optionalDependencies:{}},{answer:s}=await VM({message:`Add workspace dependencies to "${t}"?`});if(!s)return i;let{answer:o}=await(0,vt.prompt)({type:"checkbox",name:"answer",message:`Select all dependencies types to modify for "${t}"`,loop:!1,choices:[{name:"dependencies",value:"dependencies"},{name:"devDependencies",value:"devDependencies"},{name:"peerDependencies",value:"peerDependencies"},{name:"optionalDependencies",value:"optionalDependencies"}]}),a=Ju({project:e,type:"package",showAllDependencies:n}),u=r?(0,iv.readJsonSync)(r.paths.packageJson):void 0;for(let c of o){let{answer:l}=await(0,vt.prompt)({type:"checkbox",name:"answer",default:u&&Object.keys(u[c]||{}),pageSize:15,message:`Which packages should be added as ${c} to "${t}?`,loop:!1,choices:a.map(h=>h instanceof vt.Separator?h:{name:` ${h.name}`,value:h.name})}),f=(u==null?void 0:u[c])||{};if(Object.keys(f).length){let h=new Set(Object.keys(f));l.forEach(m=>{h.has(m)||(f[m]=e.packageManager==="pnpm"?"workspace:*":"*")}),i[c]=f}else i[c]=l.reduce((h,m)=>({...h,[m]:e.packageManager==="pnpm"?"workspace:*":"*"}),{})}return i}async function VM({message:t}){return(0,vt.prompt)({type:"confirm",name:"answer",message:t})}async function Xu({project:t,opts:e}){var u;let r,n=e.method==="copy"&&e.copy.type==="external"?((u=e.examplePath)==null?void 0:u.split("/").pop())||e.copy.source.split("/").pop():void 0,{answer:i}=await av({override:e.type,message:e.method==="copy"&&e.copy.source==="external"&&n?`What type of workspace should "${n}" be created as?`:void 0}),{answer:s}=await ov({override:e.name,workspaceType:i,suggestion:n});if(e.method==="copy"&&e.copy.type==="internal"){let{answer:c}=await cv({override:e.copy.source,workspaces:Ju({project:t,type:i}),workspaceName:s});r=c}let o=await uv({workspaceType:i,workspaceName:s,project:t,destination:e.destination}),a=await lv({workspaceName:s,project:t,workspaceSource:r,showAllDependencies:e.showAllDependencies});return{type:i,name:s,location:o,source:r,dependencies:a}}async function hm({project:t,opts:e}){let{name:r,location:n,dependencies:i}=await Xu({project:t,opts:e}),s={name:r,version:"0.0.0",private:!0,scripts:{dev:"echo 'Add dev script here'",build:"echo 'Add build script here'",test:"echo 'Add test script here'",lint:"echo 'Add lint script here'"}};Object.keys(i).forEach(o=>{let a=i[o];a&&Object.keys(a).length>0&&(s[o]=a)}),(0,Gs.mkdirSync)(n.absolute,{recursive:!0}),(0,Gs.writeFileSync)(fm.default.join(n.absolute,"package.json"),JSON.stringify(s,null,2)),(0,Gs.writeFileSync)(fm.default.join(n.absolute,"README.md"),`# \`${r}\``),L.log(),L.log(`${fv.default.bold(L.turboGradient(">>> Success!"))} Created ${r} at "${n.relative}"`)}var dm=X(require("path")),Rt=require("fs-extra"),hv=X(require("chalk"));async function pm({project:t,opts:e}){let{name:r,type:n,location:i,source:s,dependencies:o}=await Xu({project:t,opts:e}),a=dm.default.join(i.absolute,"package.json");if(e.copy.type==="external"){L.log(),L.warn("Some manual modifications may be required."),L.dimmed(`This ${n} may require local dependencies or a different package manager than what is available in this repo`),await rm({appPath:i.absolute,example:e.copy.source,examplePath:e.examplePath});try{if((0,Rt.existsSync)(a)){if((await(0,Rt.readJSON)(a)).workspaces)throw new Error("New workspace root detected - unexpected 'workspaces' field in package.json")}else throw new Error("New workspace is missing a package.json file");if((0,Rt.existsSync)(dm.default.join(i.absolute,"pnpm-workspace.yaml")))throw new Error("New workspace root detected - unexpected pnpm-workspace.yaml")}catch(c){let l="UNKNOWN_ERROR";c instanceof Error&&(l=c.message),L.error(l),await(0,Rt.rm)(i.absolute,{recursive:!0,force:!0});return}}else if(s){let c=async f=>Promise.resolve(!f.includes("node_modules")),l=L.turboLoader(`Creating "${r}" from "${s.name}"...`);l.start(),await(0,Rt.copy)(s.paths.root,i.absolute,{filter:c}),l.stop()}let u=await(0,Rt.readJSON)(a);u.name=r,Object.keys(o).forEach(c=>{let l=o[c];l&&Object.keys(l).length>0&&(u[c]=l)}),await(0,Rt.writeJSON)(a,u,{spaces:2}),L.log(),L.log(`${hv.default.bold(L.turboGradient(">>> Success!"))} Created ${r} at "${i.relative}"`)}function KM(t){let{copy:e,...r}=t,n=e===!0||typeof e=="string"?"copy":"empty",i=typeof e=="string"?e:"",s=typeof e=="string"&&e.startsWith("https://")?"external":"internal";return{method:n,copy:{type:s,source:i},...r}}async function Ws(t){let e=await Wu(t),r=KM(t);L.log();let n={project:e,opts:r};r.method==="copy"?(r.copy.type==="external"?L.info(`Copy a remote workspace from ${r.copy.source}`):L.info(`Copy an existing workspace from "${e.name}"`),L.log(),await pm(n)):(L.info(`Add an empty workspace to "${e.name}"`),L.log(),await hm(n))}async function zs(t,e){let r=await Wu(e);L.log(),L.info(`Modify "${r.name}" using custom generators`),L.log(),await am({generator:t,project:r,opts:e})}function dv(t){try{let e=JSON.parse(t),r={};for(let n in e){let i=nm(n,{to:"camel"});r[i]=e[n]}return r}catch(e){L.error("Error parsing arguments",e),process.exit(1)}}async function mm(t,e){var r;if(t==="workspace"){let n=dv(e.json);n.showAllDependencies=(r=n.showAllDependencies)!=null?r:!1;let i=!1,s=n.empty||!0;n.copy===""||n.copy===!0?(i=!0,s=!1):n.copy&&n.copy.length>0&&(i=n.copy,s=!1),n.copy=i,n.empty=s,await Ws(n)}else if(t==="run"){let n=dv(e.json),{generatorName:i,...s}=n;await zs(i,s)}else L.error(`Received unknown command - "${t}" (must be one of "workspace" | "run")`),process.exit(1)}var _v=new yv.ProxyAgent;pv.default.globalAgent=_v;mv.default.globalAgent=_v;var Vs=new qe.Command;Vs.name(gv.default.bold(L.turboGradient("@turbo/gen"))).description("Extend your Turborepo").version($s.version,"-v, --version","Output the current version").helpOption("-h, --help","Display help for command").showHelpAfterError(!1);Vs.command("run",{isDefault:!0}).alias("r").description("Run custom generators").addArgument(new qe.Argument("[generator-name]","The name of the generator to run")).addOption(new qe.Option("-c, --config <config>","Generator configuration file (default: turbo/generators/config.js")).addOption(new qe.Option("-r, --root <dir>","The root of your repository (default: directory with root turbo.json)")).addOption(new qe.Option("-a, --args <args...>","Arguments passed directly to generator").default([])).action(zs);Vs.command("workspace").aliases(["w"]).description("Add a new package or app to your project").addOption(new qe.Option("-n, --name <workspace-name>","Name for the new workspace")).addOption(new qe.Option("-b, --empty","Generate an empty workspace").conflicts("copy").default(!0)).addOption(new qe.Option("-c, --copy [source]",`Generate a workspace using an existing workspace as a template. Can be the name of a local workspace
68
68
  within your monorepo, or a fully qualified GitHub URL with any branch and/or subdirectory.
69
69
  `).conflicts("empty")).addOption(new qe.Option("-d, --destination <dir>","Where the new workspace should be created")).addOption(new qe.Option("-t, --type <type>","The type of workspace to create").choices(["app","package"])).addOption(new qe.Option("-r, --root <dir>","The root of your repository (default: directory with root turbo.json)")).addOption(new qe.Option("-p, --example-path <path-to-example>",`In a rare case, your GitHub URL might contain a branch name with
70
70
  a slash (e.g. bug/fix-1) and the path to the example (e.g. foo/bar).
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@turbo/gen",
3
- "version": "1.13.4-canary.5",
3
+ "version": "2.0.0-canary.0",
4
4
  "description": "Extend a Turborepo",
5
5
  "homepage": "https://turbo.build/repo",
6
- "license": "MPL-2.0",
6
+ "license": "MIT",
7
7
  "repository": {
8
8
  "type": "git",
9
9
  "url": "https://github.com/vercel/turbo",
@@ -25,7 +25,7 @@
25
25
  "ts-node": "^10.9.1",
26
26
  "update-check": "^1.5.4",
27
27
  "validate-npm-package-name": "^5.0.0",
28
- "@turbo/workspaces": "1.13.4-canary.5"
28
+ "@turbo/workspaces": "2.0.0-canary.0"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@types/fs-extra": "^9.0.13",
@@ -38,9 +38,9 @@
38
38
  "tsup": "^6.7.0",
39
39
  "typescript": "5.3.3",
40
40
  "@turbo/eslint-config": "0.0.0",
41
+ "@turbo/tsconfig": "0.0.0",
41
42
  "@turbo/test-utils": "0.0.0",
42
- "@turbo/utils": "0.0.0",
43
- "@turbo/tsconfig": "0.0.0"
43
+ "@turbo/utils": "0.0.0"
44
44
  },
45
45
  "files": [
46
46
  "dist"