@turbo/gen 2.6.4-canary.6 → 2.7.1-canary.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/cli.js +1 -1
  2. package/package.json +4 -4
package/dist/cli.js CHANGED
@@ -74,7 +74,7 @@ Please report this to https://github.com/szmarczak/http2-wrapper/`);m(g)}return}
74
74
  `:""}var F5=R5,T5={dump:F5};function _l(e,t){return function(){throw new Error("Function yaml."+e+" is removed in js-yaml 4. Use yaml."+t+" instead, which is now safe by default.")}}var O5=je,k5=gg,P5=Eg,B5=xg,I5=Cg,L5=pl,N5=Ug.load,M5=Ug.loadAll,q5=T5.dump,j5=nt,H5={binary:Og,float:Dg,map:bg,null:wg,pairs:Pg,set:Bg,timestamp:Fg,bool:vg,int:Ag,merge:Tg,omap:kg,seq:_g,str:yg},$5=_l("safeLoad","load"),U5=_l("safeLoadAll","loadAll"),G5=_l("safeDump","dump"),W5={Type:O5,Schema:k5,FAILSAFE_SCHEMA:P5,JSON_SCHEMA:B5,CORE_SCHEMA:I5,DEFAULT_SCHEMA:L5,load:N5,loadAll:M5,dump:q5,YAMLException:j5,types:H5,safeLoad:$5,safeLoadAll:U5,safeDump:G5},ty=W5;var uw=X($_());var N={};ZS(N,{bold:()=>kB,dimmed:()=>BB,error:()=>Ye,grey:()=>IB,info:()=>OB,item:()=>LB,log:()=>lt,turboBlue:()=>mi,turboGradient:()=>TB,turboLoader:()=>qh,turboRed:()=>sw,underline:()=>PB,warn:()=>jh,yellow:()=>ow});var ct=require("picocolors"),tw=X(SE()),rw=X(ew()),nw="#0099F7",iw="#F11712",FB="#FFFF00",Mh=e=>{let t=NB(e);return r=>`\x1B[38;5;${t}m${r}${(0,ct.reset)("")}`},TB=(0,rw.default)(nw,iw),mi=Mh(nw),sw=Mh(iw),ow=Mh(FB),qh=e=>(0,tw.default)({text:e,spinner:{frames:[" ",mi("> "),mi(">> "),mi(">>>")]}}),OB=(...e)=>{lt(mi((0,ct.bold)(">>>")),e.join(" "))},kB=(...e)=>{lt((0,ct.bold)(e.join(" ")))},PB=(...e)=>{lt((0,ct.underline)(e.join(" ")))},BB=(...e)=>{lt((0,ct.dim)(e.join(" ")))},IB=(...e)=>{lt((0,ct.gray)(e.join(" ")))},LB=(...e)=>{lt(mi((0,ct.bold)(" \u2022")),e.join(" "))},lt=(...e)=>{console.log(...e)},jh=(...e)=>{console.error(ow((0,ct.bold)(">>>")),e.join(" "))},Ye=(...e)=>{console.error(sw((0,ct.bold)(">>>")),e.join(" "))};function NB(e){let t=parseInt(e.slice(1),16),r=Math.floor(t/(256*256))%256,n=Math.floor(t/256)%256,i=t%256;return 16+36*Math.round(r/255*5)+6*Math.round(n/255*5)+Math.round(i/255*5)}var aw="{turbo.json,turbo.jsonc}";var Hh={};function qB(e){try{if(Fs.default.existsSync(Ur.default.join(e,"pnpm-workspace.yaml")))return ty.load(Fs.default.readFileSync(Ur.default.join(e,"pnpm-workspace.yaml"),"utf8")).packages||[];let t=JSON.parse(Fs.default.readFileSync(Ur.default.join(e,"package.json"),"utf8"));if(t.workspaces){if("packages"in t.workspaces)return t.workspaces.packages||[];if(Array.isArray(t.workspaces))return t.workspaces}return[]}catch{return[]}}function $h(e,t){var s;let r=cs(e,t),n=[],i=(s=t==null?void 0:t.cache)!=null?s:!0;if(i&&e&&e in Hh)return Hh[e];if(r){let a=qB(r).map(l=>`${l}/${aw}`),u=(0,uw.sync)([aw,...a],{cwd:r,onlyFiles:!0,followSymbolicLinks:!1,suppressErrors:!0}).map(l=>Ur.default.join(r,l)),c={};for(let l of u){let f=Ur.default.dirname(l);c[f]||(c[f]=[]),c[f].push(l)}for(let[l,f]of Object.entries(c)){if(f.length>1){let p=`Found both turbo.json and turbo.jsonc in the same directory: ${l}
75
75
  Please use either turbo.json or turbo.jsonc, but not both.`;throw Ye(p),new Error(p)}let h=f[0];try{let p=Fs.default.readFileSync(h,"utf8"),m=Co.parse(p),g=Ur.default.dirname(h)===r;if(g){if("extends"in m)continue}else if(!("extends"in m))continue;n.push({config:m,turboConfigPath:h,workspacePath:Ur.default.dirname(h),isRootConfig:g})}catch(p){jh(p)}}}return i&&e&&(Hh[e]=n),n}var kL=X(require("os")),PL=X(Iv());var Lv=X(require("fs-extra")),BL=[".DS_Store",".git",".gitattributes",".gitignore",".gitlab-ci.yml",".hg",".hgcheck",".hgignore",".idea",".npmignore",".travis.yml","LICENSE","Thumbs.db","docs","mkdocs.yml","npm-debug.log","yarn-debug.log","yarn-error.log","yarnrc.yml",".yarn"];function Bs(e){let t=Lv.default.readdirSync(e).filter(r=>!BL.includes(r)).filter(r=>!r.endsWith(".iml"));return{isEmpty:t.length===0,conflicts:t}}var sd=X(require("path")),od=X(require("fs-extra")),ad=X(require("picocolors"));function Wa(e){let t=sd.default.resolve(e),r=sd.default.basename(t),n=od.default.existsSync(t),i=od.default.lstatSync(t,{throwIfNoEntry:!1});if(i&&!i.isDirectory())return{valid:!1,root:t,projectName:r,error:`${ad.default.dim(r)} is not a directory - please try a different location`};if(n){let{isEmpty:s,conflicts:o}=Bs(t);if(!s)return{valid:!1,root:t,projectName:r,error:`${ad.default.dim(r)} (${t}) has ${o.length} conflicting ${o.length===1?"file":"files"} - please try a different location`}}return{valid:!0,root:t,projectName:r}}var iS=require("stream"),sS=require("util"),oS=require("path"),aS=require("os"),fo=require("fs"),tm=X(Px()),xc=X(nS()),_9=(0,sS.promisify)(iS.Stream.pipeline);async function Dc(e){try{return(await xc.default.head(e)).statusCode===200}catch{return!1}}async function rm(e,t){let[,r,n,i,s,...o]=e.pathname.split("/"),a=t?t.replace(/^\//,""):o.join("/");if(i===void 0||i===""&&s===void 0)try{let c=await(0,xc.default)(`https://api.github.com/repos/${r}/${n}`),l=JSON.parse(c.body);return{username:r,name:n,branch:l.default_branch,filePath:a}}catch{return}let u=t?`${s}/${o.join("/")}`.replace(new RegExp(`/${a}|/$`),""):s;if(r&&n&&u&&i==="tree")return{username:r,name:n,branch:u,filePath:a}}function nm({username:e,name:t,branch:r,filePath:n}){let i=`https://api.github.com/repos/${e}/${t}/contents`,s=`${n?`/${n}`:""}/package.json`;return Dc(`${i+s}?ref=${r}`)}function im(e){try{let t=new URL(e);return Dc(t.href)}catch{return Dc(`https://api.github.com/repos/vercel/turborepo/contents/examples/${encodeURIComponent(e)}`)}}async function uS(e,t){let r=(0,oS.join)((0,aS.tmpdir)(),`${t}.temp-${Date.now()}`);return await _9(xc.default.stream(e),(0,fo.createWriteStream)(r)),r}async function sm(e,{username:t,name:r,branch:n,filePath:i}){let s=await uS(`https://codeload.github.com/${t}/${r}/tar.gz/${n}`,"turbo-ct-example"),o=null;await(0,tm.x)({file:s,cwd:e,strip:i?i.split("/").length+1:1,filter:a=>{if(o===null){let u=a.split("/");o=u.length?u[0]:null}return a.startsWith(`${o}${i?`/${i}/`:"/"}`)}}),await fo.promises.unlink(s)}async function om(e,t){let r=await uS("https://codeload.github.com/vercel/turborepo/tar.gz/main","turbo-ct-example"),n=null;await(0,tm.x)({file:r,cwd:e,strip:2+t.split("/").length,filter:i=>{if(n===null){let s=i.split("/");n=s.length?s[0]:null}return i.includes(`${n}/examples/${t}/`)}}),await fo.promises.unlink(r)}var am=X(require("fs-extra"));async function um(e){try{return await am.default.access(e,am.default.constants.W_OK),!0}catch{return!1}}var ts=X(require("path")),cm=X(mS()),Nn=X(require("picocolors")),Cc=X(require("fs-extra"));function v9(e){return typeof e=="object"&&e!==null&&typeof e.message=="string"}var Sc=class extends Error{};async function lm({appPath:e,example:t,isDefaultExample:r,examplePath:n}){let i,s;if(r)i={username:"vercel",name:"turborepo",branch:"main",filePath:"examples/basic"};else{try{s=new URL(t)}catch(b){b.code!=="ERR_INVALID_URL"&&(Ye(b),process.exit(1))}s?(s.origin!=="https://github.com"&&(Ye(`Invalid URL: ${Nn.default.red(`"${t}"`)}. Only GitHub repositories are supported. Please use a GitHub URL and try again.`),process.exit(1)),i=await rm(s,n),i||(Ye(`Unable to fetch repository information from: ${Nn.default.red(`"${t}"`)}. Please fix the URL and try again.`),process.exit(1)),await nm(i)||(Ye(`Could not locate the repository for ${Nn.default.red(`"${t}"`)}. Please check that the repository exists and try again.`),process.exit(1))):await im(t)||(Ye(`Could not locate an example named ${Nn.default.red(`"${t}"`)}. It could be due to the following:
76
76
  `,`1. Your spelling of example ${Nn.default.red(`"${t}"`)} might be incorrect.
77
- `,"2. You might not be connected to the internet or you are behind a proxy."),process.exit(1))}let o=ts.default.resolve(e);await um(ts.default.dirname(o))||(Ye("The application path is not writable, please check folder permissions and try again."),Ye("It is likely you do not have write permissions for this folder."),process.exit(1));let a=ts.default.basename(o);try{await Cc.default.mkdir(o,{recursive:!0})}catch(b){Ye("Unable to create project directory"),Ye(b),process.exit(1)}let{isEmpty:u,conflicts:c}=Bs(o);u||(Ye(`${Nn.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),lt();let f=qh("Downloading files... (This might take a moment)");try{!r&&i?(f.start(),await(0,cm.default)(()=>sm(o,i),{retries:3})):(f.start(),await(0,cm.default)(()=>om(o,t),{retries:3}))}catch(b){throw new Sc(v9(b)?b.message:String(b))}finally{f.stop()}let h=ts.default.join(o,"package.json"),p=Cc.default.existsSync(h),m=[];if(p){let b;try{b=Cc.default.readJsonSync(h)}catch{}b&&m.push(...Object.keys(b.scripts||{}))}let g=e;return ts.default.join(l,a)===e&&(g=a),{cdPath:g,hasPackageJson:p,availableScripts:m,repoInfo:i}}function fm(e,t={to:"camel"}){switch(t.to){case"camel":return e.replace(/(?:[-_][a-z])/g,r=>r.toUpperCase().replace("-","").replace("_",""));default:throw new Error("Not implemented")}}var Rc=X(require("picocolors")),gS=X(require("update-check"));function hm(e){let{packageInfo:t,upgradeCommand:r}=e,n=(0,gS.default)(t).catch(()=>null);return async function(s=0){try{let o=await n;if(o!=null&&o.latest){lt(),lt(Rc.default.yellow(Rc.default.bold(`A new version of \`${t.name}\` is available!`)));let a=typeof r=="function"?await r():r;a&&lt(`You can update by running: ${Rc.default.cyan(a)}`),lt()}process.exit(s)}catch(o){process.env.DEBUG&&Ye("Update check failed:",o),process.exit(s)}}}var WS=require("proxy-agent");var dm={name:"@turbo/gen",version:"2.6.4-canary.6",description:"Extend a Turborepo",type:"commonjs",homepage:"https://turborepo.com",license:"MIT",repository:{type:"git",url:"git+https://github.com/vercel/turborepo.git",directory:"packages/turbo-gen"},bugs:{url:"https://github.com/vercel/turborepo/issues"},bin:"dist/cli.js",types:"dist/types.d.ts",scripts:{build:"tsup",test:"jest",lint:"eslint src/","check-types":"tsc --noEmit","package:types":"attw --profile node16 --pack"},dependencies:{"@turbo/workspaces":"workspace:*",commander:"10.0.0","fs-extra":"10.1.0",inquirer:"8.2.4",minimatch:"9.0.0","node-plop":"0.26.3",picocolors:"1.0.1","proxy-agent":"6.5.0","ts-node":"10.9.2","update-check":"1.5.4","validate-npm-package-name":"5.0.0"},devDependencies:{"@arethetypeswrong/cli":"0.18.2","@jest/globals":"29.7.0","@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/node":"18.17.4","@types/validate-npm-package-name":"4.0.0",jest:"29.7.0","ts-jest":"29.2.5",tsup:"6.7.0",typescript:"5.5.4"},files:["dist"],publishConfig:{access:"public"}};var yS=require("@turbo/workspaces");async function Fc({root:e}){let t=e||process.cwd(),r=cs(t);if(!r)N.error("Unable to infer repository root - override with --root");else try{return(0,yS.getWorkspaceDetails)({root:r})}catch{N.error(`Unable to determine workspace details. Make sure "${t}" is the root, or add "packageManager" to "package.json" or ensure a lockfile is present.`)}process.exit(1)}var Tr=X(require("path")),Oc=X(require("fs-extra")),Tc=X(require("node-plop")),_S=require("ts-node"),bS=require("inquirer");var $e=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,$e)}};var ES=["ts","js","cjs"],D9=Tr.default.join("turbo","generators"),wS=ES.map(e=>Tr.default.join(D9,`config.${e}`)),x9=[...wS,...ES.map(e=>Tr.default.join(`plopfile.${e}`))];function vS({project:e,configPath:t}){(0,_S.register)({transpileOnly:!0,cwd:e.paths.root,compilerOptions:{module:"nodenext",moduleResolution:"nodenext"}});let r=S9({project:e}),n;if(t){if(!Oc.default.existsSync(t))throw new $e(`No config at "${t}"`,{type:"plop_no_config"});try{n=(0,Tc.default)(t,{destBasePath:t,force:!1})}catch(i){N.error(i)}}else{for(let i of x9){let s=Tr.default.join(e.paths.root,i);if(Oc.default.existsSync(s))try{n=(0,Tc.default)(s,{destBasePath:e.paths.root,force:!1});break}catch(o){N.error(o)}}!n&&r.length>0&&(n=(0,Tc.default)(r[0].config,{destBasePath:r[0].root,force:!1}),r.shift())}return n&&r.forEach(i=>{try{n.load(i.config,{destBasePath:i.root,force:!1})}catch(s){N.error(s)}}),n}function pm({project:e,configPath:t}){let r=vS({project:e,configPath:t});if(!r)return[];let i=r.getGeneratorList().map(a=>r.getGenerator(a.name)),s={};i.forEach(a=>{let u=a,c=e.workspaceData.workspaces.find(l=>{if(u.basePath===e.paths.root)return!1;let f=u.basePath.split(Tr.default.sep);return f.pop(),f.pop(),Tr.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 bS.Separator(a)),o.push(...s[a])}),o}function C9({project:e,generator:t}){let r={cwd:process.cwd(),root:e.paths.root,workspace:t.basePath?us({cwd:t.basePath,target:"package.json"}):void 0},n={};try{n=$h(t.basePath)}catch{}return{turbo:{paths:r,configs:n}}}function S9({project:e}){let t=[];return e.workspaceData.workspaces.forEach(r=>{for(let n of wS)Oc.default.existsSync(Tr.default.join(r.paths.root,n))&&t.push({config:Tr.default.join(r.paths.root,n),root:r.paths.root})}),t}async function AS({project:e,generator:t,bypassArgs:r,configPath:n}){let i=vS({project:e,configPath:n});if(!i)throw new $e("Unable to load generators",{type:"plop_unable_to_load_config"});let s=i.getGenerator(t);if(!s)throw new $e(`Generator ${t} not found`,{type:"plop_generator_not_found"});let o=await s.runPrompts(r),a=await s.runActions({...o,...C9({project:e,generator:s})},{onComment:u=>{N.dimmed(u)}});if(a.failures.length>0)throw a.failures.forEach(u=>{u instanceof Error?N.error(`Error - ${u.message}`):N.error(`Error - ${u.error}. Unable to ${u.type} to "${u.path}"`)}),new $e(`Failed to run "${t}" generator`,{type:"plop_error_running_generator"});a.changes.length>0&&(N.info("Changes made:"),a.changes.forEach(u=>{u.path&&N.item(`${u.path} (${u.type})`)}))}var Mn=require("inquirer");async function DS({generators:e,generator:t}){if(t){if(e.find(n=>!(n instanceof Mn.Separator)&&n.name===t))return{selectedGenerator:t};N.warn(`Generator "${t}" not found`),N.log()}return await(0,Mn.prompt)({type:"list",name:"selectedGenerator",message:"Select generator to run",choices:e.map(n=>n instanceof Mn.Separator?n:{name:n.description?` ${n.name}: ${n.description}`:` ${n.name}`,value:n.name})})}async function xS(){return(0,Mn.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 CS({message:e}){return(0,Mn.prompt)({type:"confirm",name:"answer",message:e})}var mm=X(require("path")),gm=X(require("fs-extra"));async function SS({project:e,template:t}){let r=mm.default.join(e.paths.root,"turbo","generators"),n=`simple-${t}`;if(await gm.default.pathExists(r))throw new $e(`Generator config directory already exists at ${r}`,{type:"config_directory_already_exists"});await gm.default.copy(mm.default.join(__dirname,"templates",n),r,{recursive:!0})}async function ym({generator:e,project:t,opts:r}){let n=!1,i=pm({project:t,configPath:r.config});if(!i.length){N.error("No generators found."),N.log();let{answer:o}=await CS({message:`Would you like to add a config with a sample custom generator to ${t.name}?`});if(o){n=!0;let{answer:a}=await xS();try{await SS({project:t,template:a})}catch(u){throw u instanceof $e||N.error("Failed to create generator config"),u}if(N.log(),N.info("Generator config successfully created!"),N.info("Loading generator config..."),N.log(),i=pm({project:t,configPath:r.config}),!i.length){N.error("Error loading generator");return}}else{N.log(),N.dimmed("Learn more about custom Turborepo generators - https://turborepo.com/docs/guides/generating-code#custom-generators");return}}let{selectedGenerator:s}=await DS({generators:i,generator:e});try{await AS({project:t,generator:s,bypassArgs:r.args,configPath:r.config})}catch(o){if(o instanceof $e)throw o;let a="Failed to run generator";throw o instanceof Error&&(a=o.message),new $e(a,{type:"plop_error_running_generator"})}finally{n&&(N.log(),N.info("Congrats! You just ran your first Turborepo generator"),N.dimmed("Learn more about custom Turborepo generators - https://turborepo.com/docs/guides/generating-code#custom-generators"))}N.log(),N.bold(N.turboGradient(">>> Success!"))}var wm=X(require("path")),Ic=X(require("fs-extra")),MS=X(require("picocolors"));var ho=X(require("path")),OS=X(require("fs-extra")),It=require("inquirer"),kS=require("minimatch"),Em=X(require("validate-npm-package-name"));var _m=X(require("path"));var RS=X(require("path"));function FS({project:e}){let r=e.workspaceData.workspaces.map(i=>RS.default.relative(e.paths.root,i.paths.root)),n=new Set;return e.workspaceData.globs.forEach(i=>{if(!r.includes(i)){if(!i.startsWith("!")){let o=i.split("/")[0];n.add(o)}}}),Array.from(n)}function bm({project:e,workspace:t}){return _m.default.relative(e.paths.root,t.paths.root).split(_m.default.sep)[0]}function kc({project:e}){let t=FS({project:e}),r=t.includes("apps"),n=t.includes("packages"),i={},s=[];return e.workspaceData.workspaces.forEach(o=>{let a=bm({project:e,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 TS=require("inquirer");function Pc({project:e,type:t,showAllDependencies:r}){let n=kc({project:e}),i=[],s=e.workspaceData.workspaces;r||(t==="app"&&n.hasRootApps?s=n.workspacesByGroup.apps:t==="package"&&n.nonAppWorkspaces.length>0&&(s=n.nonAppWorkspaces));let o;return s.forEach(a=>{let u=bm({project:e,workspace:a});u!==o&&i.push(new TS.Separator(u)),o=u,i.push(a)}),i}async function PS({override:e,suggestion:t,workspaceType:r}){let{validForNewPackages:n}=(0,Em.default)(e||"");return e&&n?{answer:e}:(0,It.prompt)({type:"input",name:"answer",default:t,validate:i=>{let{validForNewPackages:s}=(0,Em.default)(i);return s||`Invalid ${r} name`},message:`What is the name of the ${r}?`})}async function BS({override:e,message:t}){return e?{answer:e}:(0,It.prompt)({type:"list",name:"answer",message:t!=null?t:"What type of workspace should be added?",choices:[{name:"app",value:"app"},{name:"package",value:"package"}]})}async function IS({workspaceType:e,workspaceName:t,destination:r,project:n}){let i=t.includes("/")?t.split("/")[1]:t;if(r){let{valid:u,root:c}=Wa(r);if(u)return{absolute:c,relative:ho.default.relative(n.paths.root,c)}}let s,o=kc({project:n});e==="app"&&o.hasRootApps?s=`${n.paths.root}/apps/${i}`:e==="package"&&o.hasRootPackages&&(s=`${n.paths.root}/packages/${i}`);let{answer:a}=await(0,It.prompt)({type:"input",name:"answer",message:`Where should "${t}" be added?`,default:s?ho.default.relative(n.paths.root,s):void 0,validate:u=>{let c=ho.default.join(n.paths.root,u),{valid:l,error:f}=Wa(c),h=n.workspaceData.globs.some(p=>(0,kS.minimatch)(u,p));return l&&h?!0:h?f:`${u} is not a valid workspace location`}});return{absolute:ho.default.join(n.paths.root,a),relative:a}}async function LS({override:e,workspaces:t,workspaceName:r}){if(e){let i=t.find(s=>s instanceof It.Separator?!1:s.name===e);if(i)return{answer:i};N.warn(`Workspace "${e}" not found`),N.log()}return await(0,It.prompt)({type:"list",name:"answer",loop:!1,pageSize:25,message:`Which workspace should "${r}" start from?`,choices:t.map(i=>i instanceof It.Separator?i:{name:` ${i.name}`,value:i})})}async function NS({workspaceName:e,project:t,workspaceSource:r,showAllDependencies:n}){let i={dependencies:{},devDependencies:{},peerDependencies:{},optionalDependencies:{}},{answer:s}=await F9({message:`Add workspace dependencies to "${e}"?`});if(!s)return i;let{answer:o}=await(0,It.prompt)({type:"checkbox",name:"answer",message:`Select all dependencies types to modify for "${e}"`,loop:!1,choices:[{name:"dependencies",value:"dependencies"},{name:"devDependencies",value:"devDependencies"},{name:"peerDependencies",value:"peerDependencies"},{name:"optionalDependencies",value:"optionalDependencies"}]}),a=Pc({project:t,type:"package",showAllDependencies:n}),u=r?OS.default.readJsonSync(r.paths.packageJson):void 0;for(let c of o){let{answer:l}=await(0,It.prompt)({type:"checkbox",name:"answer",default:u&&Object.keys(u[c]||{}),pageSize:15,message:`Which packages should be added as ${c} to "${e}?`,loop:!1,choices:a.map(h=>h instanceof It.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(p=>{h.has(p)||(f[p]=t.packageManager==="pnpm"?"workspace:*":"*")}),i[c]=f}else i[c]=l.reduce((h,p)=>({...h,[p]:t.packageManager==="pnpm"?"workspace:*":"*"}),{})}return i}async function F9({message:e}){return(0,It.prompt)({type:"confirm",name:"answer",message:e})}async function Bc({project:e,opts:t}){var u;let r,n=t.method==="copy"&&t.copy.type==="external"?((u=t.examplePath)==null?void 0:u.split("/").pop())||t.copy.source.split("/").pop():void 0,{answer:i}=await BS({override:t.type,message:t.method==="copy"&&t.copy.source==="external"&&n?`What type of workspace should "${n}" be created as?`:void 0}),{answer:s}=await PS({override:t.name,workspaceType:i,suggestion:n});if(t.method==="copy"&&t.copy.type==="internal"){let{answer:c}=await LS({override:t.copy.source,workspaces:Pc({project:e,type:i}),workspaceName:s});r=c}let o=await IS({workspaceType:i,workspaceName:s,project:e,destination:t.destination}),a=await NS({workspaceName:s,project:e,workspaceSource:r,showAllDependencies:t.showAllDependencies});return{type:i,name:s,location:o,source:r,dependencies:a}}async function vm({project:e,opts:t}){let{name:r,location:n,dependencies:i}=await Bc({project:e,opts:t}),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)}),Ic.default.mkdirSync(n.absolute,{recursive:!0}),Ic.default.writeFileSync(wm.default.join(n.absolute,"package.json"),JSON.stringify(s,null,2)),Ic.default.writeFileSync(wm.default.join(n.absolute,"README.md"),`# \`${r}\``),N.log(),N.log(`${MS.default.bold(N.turboGradient(">>> Success!"))} Created ${r} at "${n.relative}"`)}var Am=X(require("path")),un=X(require("fs-extra")),qS=X(require("picocolors"));async function Dm({project:e,opts:t}){let{name:r,type:n,location:i,source:s,dependencies:o}=await Bc({project:e,opts:t}),a=Am.default.join(i.absolute,"package.json");if(t.copy.type==="external"){N.log(),N.warn("Some manual modifications may be required."),N.dimmed(`This ${n} may require local dependencies or a different package manager than what is available in this repo`),await lm({appPath:i.absolute,example:t.copy.source,examplePath:t.examplePath});try{if(un.default.existsSync(a)){if((await un.default.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(un.default.existsSync(Am.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),N.error(l),await un.default.rm(i.absolute,{recursive:!0,force:!0});return}}else if(s){let c=async f=>Promise.resolve(!f.includes("node_modules")),l=N.turboLoader(`Creating "${r}" from "${s.name}"...`);l.start(),await un.default.copy(s.paths.root,i.absolute,{filter:c}),l.stop()}let u=await un.default.readJSON(a);u.name=r,Object.keys(o).forEach(c=>{let l=o[c];l&&Object.keys(l).length>0&&(u[c]=l)}),await un.default.writeJSON(a,u,{spaces:2}),N.log(),N.log(`${qS.default.bold(N.turboGradient(">>> Success!"))} Created ${r} at "${i.relative}"`)}function O9(e){let{copy:t,...r}=e,n=t===!0||typeof t=="string"?"copy":"empty",i=typeof t=="string"?t:"",s=typeof t=="string"&&t.startsWith("https://")?"external":"internal";return{method:n,copy:{type:s,source:i},...r}}async function po(e){let t=await Fc(e),r=O9(e);N.log();let n={project:t,opts:r};r.method==="copy"?(r.copy.type==="external"?N.info(`Copy a remote workspace from ${r.copy.source}`):N.info(`Copy an existing workspace from "${t.name}"`),N.log(),await Dm(n)):(N.info(`Add an empty workspace to "${t.name}"`),N.log(),await vm(n))}async function mo(e,t){let r=await Fc(t);N.log(),N.info(`Modify "${r.name}" using custom generators`),N.log(),await ym({generator:e,project:r,opts:t})}function jS(e){try{let t=JSON.parse(e),r={};for(let n in t){let i=fm(n,{to:"camel"});r[i]=t[n]}return r}catch(t){N.error("Error parsing arguments",t),process.exit(1)}}async function xm(e,t){var r;if(e==="workspace"){let n=jS(t.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 po(n)}else if(e==="run"){let n=jS(t.json),{generatorName:i,...s}=n;await mo(i,s)}else N.error(`Received unknown command - "${e}" (must be one of "workspace" | "run")`),process.exit(1)}var HS=hm({packageInfo:dm}),zS=new WS.ProxyAgent;$S.default.globalAgent=zS;US.default.globalAgent=zS;var go=new Ue.Command;go.name(GS.default.bold(N.turboGradient("@turbo/gen"))).description("Extend your Turborepo").version(dm.version,"-v, --version","Output the current version").helpOption("-h, --help","Display help for command").showHelpAfterError(!1);go.command("run",{isDefault:!0}).alias("r").description("Run custom generators").addArgument(new Ue.Argument("[generator-name]","The name of the generator to run")).addOption(new Ue.Option("-c, --config <config>","Generator configuration file (default: turbo/generators/config.js")).addOption(new Ue.Option("-r, --root <dir>","The root of your repository (default: directory with root turbo.json)")).addOption(new Ue.Option("-a, --args <args...>","Arguments passed directly to generator").default([])).action(mo);go.command("workspace").aliases(["w"]).description("Add a new package or app to your project").addOption(new Ue.Option("-n, --name <workspace-name>","Name for the new workspace")).addOption(new Ue.Option("-b, --empty","Generate an empty workspace").conflicts("copy").default(!0)).addOption(new Ue.Option("-c, --copy [source]",`Generate a workspace using an existing workspace as a template. Can be the name of a local workspace
77
+ `,"2. You might not be connected to the internet or you are behind a proxy."),process.exit(1))}let o=ts.default.resolve(e);await um(ts.default.dirname(o))||(Ye("The application path is not writable, please check folder permissions and try again."),Ye("It is likely you do not have write permissions for this folder."),process.exit(1));let a=ts.default.basename(o);try{await Cc.default.mkdir(o,{recursive:!0})}catch(b){Ye("Unable to create project directory"),Ye(b),process.exit(1)}let{isEmpty:u,conflicts:c}=Bs(o);u||(Ye(`${Nn.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),lt();let f=qh("Downloading files... (This might take a moment)");try{!r&&i?(f.start(),await(0,cm.default)(()=>sm(o,i),{retries:3})):(f.start(),await(0,cm.default)(()=>om(o,t),{retries:3}))}catch(b){throw new Sc(v9(b)?b.message:String(b))}finally{f.stop()}let h=ts.default.join(o,"package.json"),p=Cc.default.existsSync(h),m=[];if(p){let b;try{b=Cc.default.readJsonSync(h)}catch{}b&&m.push(...Object.keys(b.scripts||{}))}let g=e;return ts.default.join(l,a)===e&&(g=a),{cdPath:g,hasPackageJson:p,availableScripts:m,repoInfo:i}}function fm(e,t={to:"camel"}){switch(t.to){case"camel":return e.replace(/(?:[-_][a-z])/g,r=>r.toUpperCase().replace("-","").replace("_",""));default:throw new Error("Not implemented")}}var Rc=X(require("picocolors")),gS=X(require("update-check"));function hm(e){let{packageInfo:t,upgradeCommand:r}=e,n=(0,gS.default)(t).catch(()=>null);return async function(s=0){try{let o=await n;if(o!=null&&o.latest){lt(),lt(Rc.default.yellow(Rc.default.bold(`A new version of \`${t.name}\` is available!`)));let a=typeof r=="function"?await r():r;a&&lt(`You can update by running: ${Rc.default.cyan(a)}`),lt()}process.exit(s)}catch(o){process.env.DEBUG&&Ye("Update check failed:",o),process.exit(s)}}}var WS=require("proxy-agent");var dm={name:"@turbo/gen",version:"2.7.1-canary.0",description:"Extend a Turborepo",type:"commonjs",homepage:"https://turborepo.com",license:"MIT",repository:{type:"git",url:"git+https://github.com/vercel/turborepo.git",directory:"packages/turbo-gen"},bugs:{url:"https://github.com/vercel/turborepo/issues"},bin:"dist/cli.js",types:"dist/types.d.ts",scripts:{build:"tsup",test:"jest",lint:"eslint src/","check-types":"tsc --noEmit","package:types":"attw --profile node16 --pack"},dependencies:{"@turbo/workspaces":"workspace:*",commander:"10.0.0","fs-extra":"10.1.0",inquirer:"8.2.4",minimatch:"9.0.0","node-plop":"0.26.3",picocolors:"1.0.1","proxy-agent":"6.5.0","ts-node":"10.9.2","update-check":"1.5.4","validate-npm-package-name":"5.0.0"},devDependencies:{"@arethetypeswrong/cli":"0.18.2","@jest/globals":"29.7.0","@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/node":"18.17.4","@types/validate-npm-package-name":"4.0.0",jest:"29.7.0","ts-jest":"29.2.5",tsup:"6.7.0",typescript:"5.5.4"},files:["dist"],publishConfig:{access:"public"}};var yS=require("@turbo/workspaces");async function Fc({root:e}){let t=e||process.cwd(),r=cs(t);if(!r)N.error("Unable to infer repository root - override with --root");else try{return(0,yS.getWorkspaceDetails)({root:r})}catch{N.error(`Unable to determine workspace details. Make sure "${t}" is the root, or add "packageManager" to "package.json" or ensure a lockfile is present.`)}process.exit(1)}var Tr=X(require("path")),Oc=X(require("fs-extra")),Tc=X(require("node-plop")),_S=require("ts-node"),bS=require("inquirer");var $e=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,$e)}};var ES=["ts","js","cjs"],D9=Tr.default.join("turbo","generators"),wS=ES.map(e=>Tr.default.join(D9,`config.${e}`)),x9=[...wS,...ES.map(e=>Tr.default.join(`plopfile.${e}`))];function vS({project:e,configPath:t}){(0,_S.register)({transpileOnly:!0,cwd:e.paths.root,compilerOptions:{module:"nodenext",moduleResolution:"nodenext"}});let r=S9({project:e}),n;if(t){if(!Oc.default.existsSync(t))throw new $e(`No config at "${t}"`,{type:"plop_no_config"});try{n=(0,Tc.default)(t,{destBasePath:t,force:!1})}catch(i){N.error(i)}}else{for(let i of x9){let s=Tr.default.join(e.paths.root,i);if(Oc.default.existsSync(s))try{n=(0,Tc.default)(s,{destBasePath:e.paths.root,force:!1});break}catch(o){N.error(o)}}!n&&r.length>0&&(n=(0,Tc.default)(r[0].config,{destBasePath:r[0].root,force:!1}),r.shift())}return n&&r.forEach(i=>{try{n.load(i.config,{destBasePath:i.root,force:!1})}catch(s){N.error(s)}}),n}function pm({project:e,configPath:t}){let r=vS({project:e,configPath:t});if(!r)return[];let i=r.getGeneratorList().map(a=>r.getGenerator(a.name)),s={};i.forEach(a=>{let u=a,c=e.workspaceData.workspaces.find(l=>{if(u.basePath===e.paths.root)return!1;let f=u.basePath.split(Tr.default.sep);return f.pop(),f.pop(),Tr.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 bS.Separator(a)),o.push(...s[a])}),o}function C9({project:e,generator:t}){let r={cwd:process.cwd(),root:e.paths.root,workspace:t.basePath?us({cwd:t.basePath,target:"package.json"}):void 0},n={};try{n=$h(t.basePath)}catch{}return{turbo:{paths:r,configs:n}}}function S9({project:e}){let t=[];return e.workspaceData.workspaces.forEach(r=>{for(let n of wS)Oc.default.existsSync(Tr.default.join(r.paths.root,n))&&t.push({config:Tr.default.join(r.paths.root,n),root:r.paths.root})}),t}async function AS({project:e,generator:t,bypassArgs:r,configPath:n}){let i=vS({project:e,configPath:n});if(!i)throw new $e("Unable to load generators",{type:"plop_unable_to_load_config"});let s=i.getGenerator(t);if(!s)throw new $e(`Generator ${t} not found`,{type:"plop_generator_not_found"});let o=await s.runPrompts(r),a=await s.runActions({...o,...C9({project:e,generator:s})},{onComment:u=>{N.dimmed(u)}});if(a.failures.length>0)throw a.failures.forEach(u=>{u instanceof Error?N.error(`Error - ${u.message}`):N.error(`Error - ${u.error}. Unable to ${u.type} to "${u.path}"`)}),new $e(`Failed to run "${t}" generator`,{type:"plop_error_running_generator"});a.changes.length>0&&(N.info("Changes made:"),a.changes.forEach(u=>{u.path&&N.item(`${u.path} (${u.type})`)}))}var Mn=require("inquirer");async function DS({generators:e,generator:t}){if(t){if(e.find(n=>!(n instanceof Mn.Separator)&&n.name===t))return{selectedGenerator:t};N.warn(`Generator "${t}" not found`),N.log()}return await(0,Mn.prompt)({type:"list",name:"selectedGenerator",message:"Select generator to run",choices:e.map(n=>n instanceof Mn.Separator?n:{name:n.description?` ${n.name}: ${n.description}`:` ${n.name}`,value:n.name})})}async function xS(){return(0,Mn.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 CS({message:e}){return(0,Mn.prompt)({type:"confirm",name:"answer",message:e})}var mm=X(require("path")),gm=X(require("fs-extra"));async function SS({project:e,template:t}){let r=mm.default.join(e.paths.root,"turbo","generators"),n=`simple-${t}`;if(await gm.default.pathExists(r))throw new $e(`Generator config directory already exists at ${r}`,{type:"config_directory_already_exists"});await gm.default.copy(mm.default.join(__dirname,"templates",n),r,{recursive:!0})}async function ym({generator:e,project:t,opts:r}){let n=!1,i=pm({project:t,configPath:r.config});if(!i.length){N.error("No generators found."),N.log();let{answer:o}=await CS({message:`Would you like to add a config with a sample custom generator to ${t.name}?`});if(o){n=!0;let{answer:a}=await xS();try{await SS({project:t,template:a})}catch(u){throw u instanceof $e||N.error("Failed to create generator config"),u}if(N.log(),N.info("Generator config successfully created!"),N.info("Loading generator config..."),N.log(),i=pm({project:t,configPath:r.config}),!i.length){N.error("Error loading generator");return}}else{N.log(),N.dimmed("Learn more about custom Turborepo generators - https://turborepo.com/docs/guides/generating-code#custom-generators");return}}let{selectedGenerator:s}=await DS({generators:i,generator:e});try{await AS({project:t,generator:s,bypassArgs:r.args,configPath:r.config})}catch(o){if(o instanceof $e)throw o;let a="Failed to run generator";throw o instanceof Error&&(a=o.message),new $e(a,{type:"plop_error_running_generator"})}finally{n&&(N.log(),N.info("Congrats! You just ran your first Turborepo generator"),N.dimmed("Learn more about custom Turborepo generators - https://turborepo.com/docs/guides/generating-code#custom-generators"))}N.log(),N.bold(N.turboGradient(">>> Success!"))}var wm=X(require("path")),Ic=X(require("fs-extra")),MS=X(require("picocolors"));var ho=X(require("path")),OS=X(require("fs-extra")),It=require("inquirer"),kS=require("minimatch"),Em=X(require("validate-npm-package-name"));var _m=X(require("path"));var RS=X(require("path"));function FS({project:e}){let r=e.workspaceData.workspaces.map(i=>RS.default.relative(e.paths.root,i.paths.root)),n=new Set;return e.workspaceData.globs.forEach(i=>{if(!r.includes(i)){if(!i.startsWith("!")){let o=i.split("/")[0];n.add(o)}}}),Array.from(n)}function bm({project:e,workspace:t}){return _m.default.relative(e.paths.root,t.paths.root).split(_m.default.sep)[0]}function kc({project:e}){let t=FS({project:e}),r=t.includes("apps"),n=t.includes("packages"),i={},s=[];return e.workspaceData.workspaces.forEach(o=>{let a=bm({project:e,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 TS=require("inquirer");function Pc({project:e,type:t,showAllDependencies:r}){let n=kc({project:e}),i=[],s=e.workspaceData.workspaces;r||(t==="app"&&n.hasRootApps?s=n.workspacesByGroup.apps:t==="package"&&n.nonAppWorkspaces.length>0&&(s=n.nonAppWorkspaces));let o;return s.forEach(a=>{let u=bm({project:e,workspace:a});u!==o&&i.push(new TS.Separator(u)),o=u,i.push(a)}),i}async function PS({override:e,suggestion:t,workspaceType:r}){let{validForNewPackages:n}=(0,Em.default)(e||"");return e&&n?{answer:e}:(0,It.prompt)({type:"input",name:"answer",default:t,validate:i=>{let{validForNewPackages:s}=(0,Em.default)(i);return s||`Invalid ${r} name`},message:`What is the name of the ${r}?`})}async function BS({override:e,message:t}){return e?{answer:e}:(0,It.prompt)({type:"list",name:"answer",message:t!=null?t:"What type of workspace should be added?",choices:[{name:"app",value:"app"},{name:"package",value:"package"}]})}async function IS({workspaceType:e,workspaceName:t,destination:r,project:n}){let i=t.includes("/")?t.split("/")[1]:t;if(r){let{valid:u,root:c}=Wa(r);if(u)return{absolute:c,relative:ho.default.relative(n.paths.root,c)}}let s,o=kc({project:n});e==="app"&&o.hasRootApps?s=`${n.paths.root}/apps/${i}`:e==="package"&&o.hasRootPackages&&(s=`${n.paths.root}/packages/${i}`);let{answer:a}=await(0,It.prompt)({type:"input",name:"answer",message:`Where should "${t}" be added?`,default:s?ho.default.relative(n.paths.root,s):void 0,validate:u=>{let c=ho.default.join(n.paths.root,u),{valid:l,error:f}=Wa(c),h=n.workspaceData.globs.some(p=>(0,kS.minimatch)(u,p));return l&&h?!0:h?f:`${u} is not a valid workspace location`}});return{absolute:ho.default.join(n.paths.root,a),relative:a}}async function LS({override:e,workspaces:t,workspaceName:r}){if(e){let i=t.find(s=>s instanceof It.Separator?!1:s.name===e);if(i)return{answer:i};N.warn(`Workspace "${e}" not found`),N.log()}return await(0,It.prompt)({type:"list",name:"answer",loop:!1,pageSize:25,message:`Which workspace should "${r}" start from?`,choices:t.map(i=>i instanceof It.Separator?i:{name:` ${i.name}`,value:i})})}async function NS({workspaceName:e,project:t,workspaceSource:r,showAllDependencies:n}){let i={dependencies:{},devDependencies:{},peerDependencies:{},optionalDependencies:{}},{answer:s}=await F9({message:`Add workspace dependencies to "${e}"?`});if(!s)return i;let{answer:o}=await(0,It.prompt)({type:"checkbox",name:"answer",message:`Select all dependencies types to modify for "${e}"`,loop:!1,choices:[{name:"dependencies",value:"dependencies"},{name:"devDependencies",value:"devDependencies"},{name:"peerDependencies",value:"peerDependencies"},{name:"optionalDependencies",value:"optionalDependencies"}]}),a=Pc({project:t,type:"package",showAllDependencies:n}),u=r?OS.default.readJsonSync(r.paths.packageJson):void 0;for(let c of o){let{answer:l}=await(0,It.prompt)({type:"checkbox",name:"answer",default:u&&Object.keys(u[c]||{}),pageSize:15,message:`Which packages should be added as ${c} to "${e}?`,loop:!1,choices:a.map(h=>h instanceof It.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(p=>{h.has(p)||(f[p]=t.packageManager==="pnpm"?"workspace:*":"*")}),i[c]=f}else i[c]=l.reduce((h,p)=>({...h,[p]:t.packageManager==="pnpm"?"workspace:*":"*"}),{})}return i}async function F9({message:e}){return(0,It.prompt)({type:"confirm",name:"answer",message:e})}async function Bc({project:e,opts:t}){var u;let r,n=t.method==="copy"&&t.copy.type==="external"?((u=t.examplePath)==null?void 0:u.split("/").pop())||t.copy.source.split("/").pop():void 0,{answer:i}=await BS({override:t.type,message:t.method==="copy"&&t.copy.source==="external"&&n?`What type of workspace should "${n}" be created as?`:void 0}),{answer:s}=await PS({override:t.name,workspaceType:i,suggestion:n});if(t.method==="copy"&&t.copy.type==="internal"){let{answer:c}=await LS({override:t.copy.source,workspaces:Pc({project:e,type:i}),workspaceName:s});r=c}let o=await IS({workspaceType:i,workspaceName:s,project:e,destination:t.destination}),a=await NS({workspaceName:s,project:e,workspaceSource:r,showAllDependencies:t.showAllDependencies});return{type:i,name:s,location:o,source:r,dependencies:a}}async function vm({project:e,opts:t}){let{name:r,location:n,dependencies:i}=await Bc({project:e,opts:t}),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)}),Ic.default.mkdirSync(n.absolute,{recursive:!0}),Ic.default.writeFileSync(wm.default.join(n.absolute,"package.json"),JSON.stringify(s,null,2)),Ic.default.writeFileSync(wm.default.join(n.absolute,"README.md"),`# \`${r}\``),N.log(),N.log(`${MS.default.bold(N.turboGradient(">>> Success!"))} Created ${r} at "${n.relative}"`)}var Am=X(require("path")),un=X(require("fs-extra")),qS=X(require("picocolors"));async function Dm({project:e,opts:t}){let{name:r,type:n,location:i,source:s,dependencies:o}=await Bc({project:e,opts:t}),a=Am.default.join(i.absolute,"package.json");if(t.copy.type==="external"){N.log(),N.warn("Some manual modifications may be required."),N.dimmed(`This ${n} may require local dependencies or a different package manager than what is available in this repo`),await lm({appPath:i.absolute,example:t.copy.source,examplePath:t.examplePath});try{if(un.default.existsSync(a)){if((await un.default.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(un.default.existsSync(Am.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),N.error(l),await un.default.rm(i.absolute,{recursive:!0,force:!0});return}}else if(s){let c=async f=>Promise.resolve(!f.includes("node_modules")),l=N.turboLoader(`Creating "${r}" from "${s.name}"...`);l.start(),await un.default.copy(s.paths.root,i.absolute,{filter:c}),l.stop()}let u=await un.default.readJSON(a);u.name=r,Object.keys(o).forEach(c=>{let l=o[c];l&&Object.keys(l).length>0&&(u[c]=l)}),await un.default.writeJSON(a,u,{spaces:2}),N.log(),N.log(`${qS.default.bold(N.turboGradient(">>> Success!"))} Created ${r} at "${i.relative}"`)}function O9(e){let{copy:t,...r}=e,n=t===!0||typeof t=="string"?"copy":"empty",i=typeof t=="string"?t:"",s=typeof t=="string"&&t.startsWith("https://")?"external":"internal";return{method:n,copy:{type:s,source:i},...r}}async function po(e){let t=await Fc(e),r=O9(e);N.log();let n={project:t,opts:r};r.method==="copy"?(r.copy.type==="external"?N.info(`Copy a remote workspace from ${r.copy.source}`):N.info(`Copy an existing workspace from "${t.name}"`),N.log(),await Dm(n)):(N.info(`Add an empty workspace to "${t.name}"`),N.log(),await vm(n))}async function mo(e,t){let r=await Fc(t);N.log(),N.info(`Modify "${r.name}" using custom generators`),N.log(),await ym({generator:e,project:r,opts:t})}function jS(e){try{let t=JSON.parse(e),r={};for(let n in t){let i=fm(n,{to:"camel"});r[i]=t[n]}return r}catch(t){N.error("Error parsing arguments",t),process.exit(1)}}async function xm(e,t){var r;if(e==="workspace"){let n=jS(t.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 po(n)}else if(e==="run"){let n=jS(t.json),{generatorName:i,...s}=n;await mo(i,s)}else N.error(`Received unknown command - "${e}" (must be one of "workspace" | "run")`),process.exit(1)}var HS=hm({packageInfo:dm}),zS=new WS.ProxyAgent;$S.default.globalAgent=zS;US.default.globalAgent=zS;var go=new Ue.Command;go.name(GS.default.bold(N.turboGradient("@turbo/gen"))).description("Extend your Turborepo").version(dm.version,"-v, --version","Output the current version").helpOption("-h, --help","Display help for command").showHelpAfterError(!1);go.command("run",{isDefault:!0}).alias("r").description("Run custom generators").addArgument(new Ue.Argument("[generator-name]","The name of the generator to run")).addOption(new Ue.Option("-c, --config <config>","Generator configuration file (default: turbo/generators/config.js")).addOption(new Ue.Option("-r, --root <dir>","The root of your repository (default: directory with root turbo.json)")).addOption(new Ue.Option("-a, --args <args...>","Arguments passed directly to generator").default([])).action(mo);go.command("workspace").aliases(["w"]).description("Add a new package or app to your project").addOption(new Ue.Option("-n, --name <workspace-name>","Name for the new workspace")).addOption(new Ue.Option("-b, --empty","Generate an empty workspace").conflicts("copy").default(!0)).addOption(new Ue.Option("-c, --copy [source]",`Generate a workspace using an existing workspace as a template. Can be the name of a local workspace
78
78
  within your monorepo, or a fully qualified GitHub URL with any branch and/or subdirectory.
79
79
  `).conflicts("empty")).addOption(new Ue.Option("-d, --destination <dir>","Where the new workspace should be created")).addOption(new Ue.Option("-t, --type <type>","The type of workspace to create").choices(["app","package"])).addOption(new Ue.Option("-r, --root <dir>","The root of your repository (default: directory with root turbo.json)")).addOption(new Ue.Option("-p, --example-path <path-to-example>",`In a rare case, your GitHub URL might contain a branch name with
80
80
  a slash (e.g. bug/fix-1) and the path to the example (e.g. foo/bar).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@turbo/gen",
3
- "version": "2.6.4-canary.6",
3
+ "version": "2.7.1-canary.0",
4
4
  "description": "Extend a Turborepo",
5
5
  "type": "commonjs",
6
6
  "homepage": "https://turborepo.com",
@@ -26,7 +26,7 @@
26
26
  "ts-node": "10.9.2",
27
27
  "update-check": "1.5.4",
28
28
  "validate-npm-package-name": "5.0.0",
29
- "@turbo/workspaces": "2.6.4-canary.6"
29
+ "@turbo/workspaces": "2.7.1-canary.0"
30
30
  },
31
31
  "devDependencies": {
32
32
  "@arethetypeswrong/cli": "0.18.2",
@@ -40,9 +40,9 @@
40
40
  "tsup": "6.7.0",
41
41
  "typescript": "5.5.4",
42
42
  "@turbo/eslint-config": "0.0.0",
43
+ "@turbo/test-utils": "0.0.0",
43
44
  "@turbo/tsconfig": "0.0.0",
44
- "@turbo/utils": "0.0.0",
45
- "@turbo/test-utils": "0.0.0"
45
+ "@turbo/utils": "0.0.0"
46
46
  },
47
47
  "files": [
48
48
  "dist"