@turbo/gen 2.6.4-canary.1 → 2.6.4-canary.2

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 +2 -2
package/dist/cli.js CHANGED
@@ -74,7 +74,7 @@ Please report this to https://github.com/szmarczak/http2-wrapper/`);y(_)}return}
74
74
  `:""}var R5=S5,F5={dump:R5};function yl(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 T5=je,O5=mg,k5=bg,P5=Dg,B5=xg,I5=dl,L5=$g.load,N5=$g.loadAll,M5=F5.dump,q5=nt,j5={binary:Tg,float:Ag,map:_g,null:Eg,pairs:kg,set:Pg,timestamp:Rg,bool:wg,int:vg,merge:Fg,omap:Og,seq:yg,str:gg},H5=yl("safeLoad","load"),$5=yl("safeLoadAll","loadAll"),U5=yl("safeDump","dump"),G5={Type:T5,Schema:O5,FAILSAFE_SCHEMA:k5,JSON_SCHEMA:P5,CORE_SCHEMA:B5,DEFAULT_SCHEMA:I5,load:L5,loadAll:N5,dump:M5,YAMLException:q5,types:j5,safeLoad:H5,safeLoadAll:$5,safeDump:U5},ey=G5;var aw=X(H_());var N={};XS(N,{bold:()=>OB,dimmed:()=>PB,error:()=>Ye,grey:()=>BB,info:()=>TB,item:()=>IB,log:()=>lt,turboBlue:()=>mi,turboGradient:()=>FB,turboLoader:()=>Mh,turboRed:()=>iw,underline:()=>kB,warn:()=>qh,yellow:()=>sw});var ct=require("picocolors"),ew=X(CE()),tw=X(QE()),rw="#0099F7",nw="#F11712",RB="#FFFF00",Nh=e=>{let t=LB(e);return r=>`\x1B[38;5;${t}m${r}${(0,ct.reset)("")}`},FB=(0,tw.default)(rw,nw),mi=Nh(rw),iw=Nh(nw),sw=Nh(RB),Mh=e=>(0,ew.default)({text:e,spinner:{frames:[" ",mi("> "),mi(">> "),mi(">>>")]}}),TB=(...e)=>{lt(mi((0,ct.bold)(">>>")),e.join(" "))},OB=(...e)=>{lt((0,ct.bold)(e.join(" ")))},kB=(...e)=>{lt((0,ct.underline)(e.join(" ")))},PB=(...e)=>{lt((0,ct.dim)(e.join(" ")))},BB=(...e)=>{lt((0,ct.gray)(e.join(" ")))},IB=(...e)=>{lt(mi((0,ct.bold)(" \u2022")),e.join(" "))},lt=(...e)=>{console.log(...e)},qh=(...e)=>{console.error(sw((0,ct.bold)(">>>")),e.join(" "))},Ye=(...e)=>{console.error(iw((0,ct.bold)(">>>")),e.join(" "))};function LB(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 ow="{turbo.json,turbo.jsonc}";var jh={};function NB(e){try{if(Fs.default.existsSync(Ur.default.join(e,"pnpm-workspace.yaml")))return ey.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 Hh(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 jh)return jh[e];if(r){let a=NB(r).map(l=>`${l}/${ow}`),u=(0,aw.sync)([ow,...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"),y=Co.parse(p),_=Ur.default.dirname(h)===r;if(_){if("extends"in y)continue}else if(!("extends"in y))continue;n.push({config:y,turboConfigPath:h,workspacePath:Ur.default.dirname(h),isRootConfig:_})}catch(p){qh(p)}}}return i&&e&&(jh[e]=n),n}var TL=X(require("os")),OL=X(Bv());var Iv=X(require("fs-extra")),kL=[".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=Iv.default.readdirSync(e).filter(r=>!kL.includes(r)).filter(r=>!r.endsWith(".iml"));return{isEmpty:t.length===0,conflicts:t}}var id=X(require("path")),sd=X(require("fs-extra")),od=X(require("picocolors"));function Ga(e){let t=id.default.resolve(e),r=id.default.basename(t),n=sd.default.existsSync(t),i=sd.default.lstatSync(t,{throwIfNoEntry:!1});if(i&&!i.isDirectory())return{valid:!1,root:t,projectName:r,error:`${od.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:`${od.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 nS=require("stream"),iS=require("util"),sS=require("path"),oS=require("os"),fo=require("fs"),em=X(kx()),Dc=X(rS()),g9=(0,iS.promisify)(nS.Stream.pipeline);async function Ac(e){try{return(await Dc.default.head(e)).statusCode===200}catch{return!1}}async function tm(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,Dc.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 rm({username:e,name:t,branch:r,filePath:n}){let i=`https://api.github.com/repos/${e}/${t}/contents`,s=`${n?`/${n}`:""}/package.json`;return Ac(`${i+s}?ref=${r}`)}function nm(e){try{let t=new URL(e);return Ac(t.href)}catch{return Ac(`https://api.github.com/repos/vercel/turborepo/contents/examples/${encodeURIComponent(e)}`)}}async function aS(e,t){let r=(0,sS.join)((0,oS.tmpdir)(),`${t}.temp-${Date.now()}`);return await g9(Dc.default.stream(e),(0,fo.createWriteStream)(r)),r}async function im(e,{username:t,name:r,branch:n,filePath:i}){let s=await aS(`https://codeload.github.com/${t}/${r}/tar.gz/${n}`,"turbo-ct-example"),o=null;await(0,em.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 sm(e,t){let r=await aS("https://codeload.github.com/vercel/turborepo/tar.gz/main","turbo-ct-example"),n=null;await(0,em.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 om=X(require("fs-extra"));async function am(e){try{return await om.default.access(e,om.default.constants.W_OK),!0}catch{return!1}}var ts=X(require("path")),um=X(pS()),Nn=X(require("picocolors")),xc=X(require("fs-extra"));function E9(e){return typeof e=="object"&&e!==null&&typeof e.message=="string"}var Cc=class extends Error{};async function cm({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(m){m.code!=="ERR_INVALID_URL"&&(Ye(m),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 tm(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 rm(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 nm(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 am(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 xc.default.mkdir(o,{recursive:!0})}catch(m){Ye("Unable to create project directory"),Ye(m),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=Mh("Downloading files... (This might take a moment)");try{!r&&i?(f.start(),await(0,um.default)(()=>im(o,i),{retries:3})):(f.start(),await(0,um.default)(()=>sm(o,t),{retries:3}))}catch(m){throw new Cc(E9(m)?m.message:String(m))}finally{f.stop()}let h=ts.default.join(o,"package.json"),p=xc.default.existsSync(h),y=[];if(p){let m;try{m=xc.default.readJsonSync(h)}catch{}m&&y.push(...Object.keys(m.scripts||{}))}let _=e;return ts.default.join(l,a)===e&&(_=a),{cdPath:_,hasPackageJson:p,availableScripts:y,repoInfo:i}}function lm(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 Sc=X(require("picocolors")),mS=X(require("update-check"));function fm(e){let{packageInfo:t,upgradeCommand:r}=e,n=(0,mS.default)(t).catch(()=>null);return async function(s=0){try{let o=await n;if(o!=null&&o.latest){lt(),lt(Sc.default.yellow(Sc.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: ${Sc.default.cyan(a)}`),lt()}process.exit(s)}catch(o){process.env.DEBUG&&Ye("Update check failed:",o),process.exit(s)}}}var GS=require("proxy-agent");var hm={name:"@turbo/gen",version:"2.6.4-canary.1",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:lint":"publint --strict","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.2","@types/validate-npm-package-name":"^4.0.0",publint:"^0.3.12",jest:"^29.7.0","ts-jest":"^29.2.5",tsup:"^6.7.0",typescript:"5.5.4"},files:["dist"],publishConfig:{access:"public"}};var gS=require("@turbo/workspaces");async function Rc({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,gS.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")),Tc=X(require("fs-extra")),Fc=X(require("node-plop")),yS=require("ts-node"),_S=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 bS=["ts","js","cjs"],v9=Tr.default.join("turbo","generators"),ES=bS.map(e=>Tr.default.join(v9,`config.${e}`)),A9=[...ES,...bS.map(e=>Tr.default.join(`plopfile.${e}`))];function wS({project:e,configPath:t}){(0,yS.register)({transpileOnly:!0,cwd:e.paths.root,compilerOptions:{module:"nodenext",moduleResolution:"nodenext"}});let r=x9({project:e}),n;if(t){if(!Tc.default.existsSync(t))throw new $e(`No config at "${t}"`,{type:"plop_no_config"});try{n=(0,Fc.default)(t,{destBasePath:t,force:!1})}catch(i){N.error(i)}}else{for(let i of A9){let s=Tr.default.join(e.paths.root,i);if(Tc.default.existsSync(s))try{n=(0,Fc.default)(s,{destBasePath:e.paths.root,force:!1});break}catch(o){N.error(o)}}!n&&r.length>0&&(n=(0,Fc.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 dm({project:e,configPath:t}){let r=wS({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 _S.Separator(a)),o.push(...s[a])}),o}function D9({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=Hh(t.basePath)}catch{}return{turbo:{paths:r,configs:n}}}function x9({project:e}){let t=[];return e.workspaceData.workspaces.forEach(r=>{for(let n of ES)Tc.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 vS({project:e,generator:t,bypassArgs:r,configPath:n}){let i=wS({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,...D9({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 AS({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 DS(){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 xS({message:e}){return(0,Mn.prompt)({type:"confirm",name:"answer",message:e})}var pm=X(require("path")),mm=X(require("fs-extra"));async function CS({project:e,template:t}){let r=pm.default.join(e.paths.root,"turbo","generators"),n=`simple-${t}`;if(await mm.default.pathExists(r))throw new $e(`Generator config directory already exists at ${r}`,{type:"config_directory_already_exists"});await mm.default.copy(pm.default.join(__dirname,"templates",n),r,{recursive:!0})}async function gm({generator:e,project:t,opts:r}){let n=!1,i=dm({project:t,configPath:r.config});if(!i.length){N.error("No generators found."),N.log();let{answer:o}=await xS({message:`Would you like to add a config with a sample custom generator to ${t.name}?`});if(o){n=!0;let{answer:a}=await DS();try{await CS({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=dm({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 AS({generators:i,generator:e});try{await vS({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 Em=X(require("path")),Bc=X(require("fs-extra")),NS=X(require("picocolors"));var ho=X(require("path")),TS=X(require("fs-extra")),It=require("inquirer"),OS=require("minimatch"),bm=X(require("validate-npm-package-name"));var ym=X(require("path"));var SS=X(require("path"));function RS({project:e}){let r=e.workspaceData.workspaces.map(i=>SS.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 _m({project:e,workspace:t}){return ym.default.relative(e.paths.root,t.paths.root).split(ym.default.sep)[0]}function Oc({project:e}){let t=RS({project:e}),r=t.includes("apps"),n=t.includes("packages"),i={},s=[];return e.workspaceData.workspaces.forEach(o=>{let a=_m({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 FS=require("inquirer");function kc({project:e,type:t,showAllDependencies:r}){let n=Oc({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=_m({project:e,workspace:a});u!==o&&i.push(new FS.Separator(u)),o=u,i.push(a)}),i}async function kS({override:e,suggestion:t,workspaceType:r}){let{validForNewPackages:n}=(0,bm.default)(e||"");return e&&n?{answer:e}:(0,It.prompt)({type:"input",name:"answer",default:t,validate:i=>{let{validForNewPackages:s}=(0,bm.default)(i);return s||`Invalid ${r} name`},message:`What is the name of the ${r}?`})}async function PS({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 BS({workspaceType:e,workspaceName:t,destination:r,project:n}){let i=t.includes("/")?t.split("/")[1]:t;if(r){let{valid:u,root:c}=Ga(r);if(u)return{absolute:c,relative:ho.default.relative(n.paths.root,c)}}let s,o=Oc({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}=Ga(c),h=n.workspaceData.globs.some(p=>(0,OS.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 IS({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 LS({workspaceName:e,project:t,workspaceSource:r,showAllDependencies:n}){let i={dependencies:{},devDependencies:{},peerDependencies:{},optionalDependencies:{}},{answer:s}=await S9({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=kc({project:t,type:"package",showAllDependencies:n}),u=r?TS.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 S9({message:e}){return(0,It.prompt)({type:"confirm",name:"answer",message:e})}async function Pc({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 PS({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 kS({override:t.name,workspaceType:i,suggestion:n});if(t.method==="copy"&&t.copy.type==="internal"){let{answer:c}=await IS({override:t.copy.source,workspaces:kc({project:e,type:i}),workspaceName:s});r=c}let o=await BS({workspaceType:i,workspaceName:s,project:e,destination:t.destination}),a=await LS({workspaceName:s,project:e,workspaceSource:r,showAllDependencies:t.showAllDependencies});return{type:i,name:s,location:o,source:r,dependencies:a}}async function wm({project:e,opts:t}){let{name:r,location:n,dependencies:i}=await Pc({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)}),Bc.default.mkdirSync(n.absolute,{recursive:!0}),Bc.default.writeFileSync(Em.default.join(n.absolute,"package.json"),JSON.stringify(s,null,2)),Bc.default.writeFileSync(Em.default.join(n.absolute,"README.md"),`# \`${r}\``),N.log(),N.log(`${NS.default.bold(N.turboGradient(">>> Success!"))} Created ${r} at "${n.relative}"`)}var vm=X(require("path")),un=X(require("fs-extra")),MS=X(require("picocolors"));async function Am({project:e,opts:t}){let{name:r,type:n,location:i,source:s,dependencies:o}=await Pc({project:e,opts:t}),a=vm.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 cm({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(vm.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(`${MS.default.bold(N.turboGradient(">>> Success!"))} Created ${r} at "${i.relative}"`)}function F9(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 Rc(e),r=F9(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 Am(n)):(N.info(`Add an empty workspace to "${t.name}"`),N.log(),await wm(n))}async function mo(e,t){let r=await Rc(t);N.log(),N.info(`Modify "${r.name}" using custom generators`),N.log(),await gm({generator:e,project:r,opts:t})}function qS(e){try{let t=JSON.parse(e),r={};for(let n in t){let i=lm(n,{to:"camel"});r[i]=t[n]}return r}catch(t){N.error("Error parsing arguments",t),process.exit(1)}}async function Dm(e,t){var r;if(e==="workspace"){let n=qS(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=qS(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 jS=fm({packageInfo:hm}),WS=new GS.ProxyAgent;HS.default.globalAgent=WS;$S.default.globalAgent=WS;var go=new Ue.Command;go.name(US.default.bold(N.turboGradient("@turbo/gen"))).description("Extend your Turborepo").version(hm.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 am(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 xc.default.mkdir(o,{recursive:!0})}catch(m){Ye("Unable to create project directory"),Ye(m),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=Mh("Downloading files... (This might take a moment)");try{!r&&i?(f.start(),await(0,um.default)(()=>im(o,i),{retries:3})):(f.start(),await(0,um.default)(()=>sm(o,t),{retries:3}))}catch(m){throw new Cc(E9(m)?m.message:String(m))}finally{f.stop()}let h=ts.default.join(o,"package.json"),p=xc.default.existsSync(h),y=[];if(p){let m;try{m=xc.default.readJsonSync(h)}catch{}m&&y.push(...Object.keys(m.scripts||{}))}let _=e;return ts.default.join(l,a)===e&&(_=a),{cdPath:_,hasPackageJson:p,availableScripts:y,repoInfo:i}}function lm(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 Sc=X(require("picocolors")),mS=X(require("update-check"));function fm(e){let{packageInfo:t,upgradeCommand:r}=e,n=(0,mS.default)(t).catch(()=>null);return async function(s=0){try{let o=await n;if(o!=null&&o.latest){lt(),lt(Sc.default.yellow(Sc.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: ${Sc.default.cyan(a)}`),lt()}process.exit(s)}catch(o){process.env.DEBUG&&Ye("Update check failed:",o),process.exit(s)}}}var GS=require("proxy-agent");var hm={name:"@turbo/gen",version:"2.6.4-canary.2",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:lint":"publint --strict","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.2","@types/validate-npm-package-name":"^4.0.0",publint:"^0.3.12",jest:"^29.7.0","ts-jest":"^29.2.5",tsup:"^6.7.0",typescript:"5.5.4"},files:["dist"],publishConfig:{access:"public"}};var gS=require("@turbo/workspaces");async function Rc({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,gS.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")),Tc=X(require("fs-extra")),Fc=X(require("node-plop")),yS=require("ts-node"),_S=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 bS=["ts","js","cjs"],v9=Tr.default.join("turbo","generators"),ES=bS.map(e=>Tr.default.join(v9,`config.${e}`)),A9=[...ES,...bS.map(e=>Tr.default.join(`plopfile.${e}`))];function wS({project:e,configPath:t}){(0,yS.register)({transpileOnly:!0,cwd:e.paths.root,compilerOptions:{module:"nodenext",moduleResolution:"nodenext"}});let r=x9({project:e}),n;if(t){if(!Tc.default.existsSync(t))throw new $e(`No config at "${t}"`,{type:"plop_no_config"});try{n=(0,Fc.default)(t,{destBasePath:t,force:!1})}catch(i){N.error(i)}}else{for(let i of A9){let s=Tr.default.join(e.paths.root,i);if(Tc.default.existsSync(s))try{n=(0,Fc.default)(s,{destBasePath:e.paths.root,force:!1});break}catch(o){N.error(o)}}!n&&r.length>0&&(n=(0,Fc.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 dm({project:e,configPath:t}){let r=wS({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 _S.Separator(a)),o.push(...s[a])}),o}function D9({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=Hh(t.basePath)}catch{}return{turbo:{paths:r,configs:n}}}function x9({project:e}){let t=[];return e.workspaceData.workspaces.forEach(r=>{for(let n of ES)Tc.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 vS({project:e,generator:t,bypassArgs:r,configPath:n}){let i=wS({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,...D9({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 AS({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 DS(){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 xS({message:e}){return(0,Mn.prompt)({type:"confirm",name:"answer",message:e})}var pm=X(require("path")),mm=X(require("fs-extra"));async function CS({project:e,template:t}){let r=pm.default.join(e.paths.root,"turbo","generators"),n=`simple-${t}`;if(await mm.default.pathExists(r))throw new $e(`Generator config directory already exists at ${r}`,{type:"config_directory_already_exists"});await mm.default.copy(pm.default.join(__dirname,"templates",n),r,{recursive:!0})}async function gm({generator:e,project:t,opts:r}){let n=!1,i=dm({project:t,configPath:r.config});if(!i.length){N.error("No generators found."),N.log();let{answer:o}=await xS({message:`Would you like to add a config with a sample custom generator to ${t.name}?`});if(o){n=!0;let{answer:a}=await DS();try{await CS({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=dm({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 AS({generators:i,generator:e});try{await vS({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 Em=X(require("path")),Bc=X(require("fs-extra")),NS=X(require("picocolors"));var ho=X(require("path")),TS=X(require("fs-extra")),It=require("inquirer"),OS=require("minimatch"),bm=X(require("validate-npm-package-name"));var ym=X(require("path"));var SS=X(require("path"));function RS({project:e}){let r=e.workspaceData.workspaces.map(i=>SS.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 _m({project:e,workspace:t}){return ym.default.relative(e.paths.root,t.paths.root).split(ym.default.sep)[0]}function Oc({project:e}){let t=RS({project:e}),r=t.includes("apps"),n=t.includes("packages"),i={},s=[];return e.workspaceData.workspaces.forEach(o=>{let a=_m({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 FS=require("inquirer");function kc({project:e,type:t,showAllDependencies:r}){let n=Oc({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=_m({project:e,workspace:a});u!==o&&i.push(new FS.Separator(u)),o=u,i.push(a)}),i}async function kS({override:e,suggestion:t,workspaceType:r}){let{validForNewPackages:n}=(0,bm.default)(e||"");return e&&n?{answer:e}:(0,It.prompt)({type:"input",name:"answer",default:t,validate:i=>{let{validForNewPackages:s}=(0,bm.default)(i);return s||`Invalid ${r} name`},message:`What is the name of the ${r}?`})}async function PS({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 BS({workspaceType:e,workspaceName:t,destination:r,project:n}){let i=t.includes("/")?t.split("/")[1]:t;if(r){let{valid:u,root:c}=Ga(r);if(u)return{absolute:c,relative:ho.default.relative(n.paths.root,c)}}let s,o=Oc({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}=Ga(c),h=n.workspaceData.globs.some(p=>(0,OS.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 IS({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 LS({workspaceName:e,project:t,workspaceSource:r,showAllDependencies:n}){let i={dependencies:{},devDependencies:{},peerDependencies:{},optionalDependencies:{}},{answer:s}=await S9({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=kc({project:t,type:"package",showAllDependencies:n}),u=r?TS.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 S9({message:e}){return(0,It.prompt)({type:"confirm",name:"answer",message:e})}async function Pc({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 PS({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 kS({override:t.name,workspaceType:i,suggestion:n});if(t.method==="copy"&&t.copy.type==="internal"){let{answer:c}=await IS({override:t.copy.source,workspaces:kc({project:e,type:i}),workspaceName:s});r=c}let o=await BS({workspaceType:i,workspaceName:s,project:e,destination:t.destination}),a=await LS({workspaceName:s,project:e,workspaceSource:r,showAllDependencies:t.showAllDependencies});return{type:i,name:s,location:o,source:r,dependencies:a}}async function wm({project:e,opts:t}){let{name:r,location:n,dependencies:i}=await Pc({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)}),Bc.default.mkdirSync(n.absolute,{recursive:!0}),Bc.default.writeFileSync(Em.default.join(n.absolute,"package.json"),JSON.stringify(s,null,2)),Bc.default.writeFileSync(Em.default.join(n.absolute,"README.md"),`# \`${r}\``),N.log(),N.log(`${NS.default.bold(N.turboGradient(">>> Success!"))} Created ${r} at "${n.relative}"`)}var vm=X(require("path")),un=X(require("fs-extra")),MS=X(require("picocolors"));async function Am({project:e,opts:t}){let{name:r,type:n,location:i,source:s,dependencies:o}=await Pc({project:e,opts:t}),a=vm.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 cm({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(vm.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(`${MS.default.bold(N.turboGradient(">>> Success!"))} Created ${r} at "${i.relative}"`)}function F9(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 Rc(e),r=F9(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 Am(n)):(N.info(`Add an empty workspace to "${t.name}"`),N.log(),await wm(n))}async function mo(e,t){let r=await Rc(t);N.log(),N.info(`Modify "${r.name}" using custom generators`),N.log(),await gm({generator:e,project:r,opts:t})}function qS(e){try{let t=JSON.parse(e),r={};for(let n in t){let i=lm(n,{to:"camel"});r[i]=t[n]}return r}catch(t){N.error("Error parsing arguments",t),process.exit(1)}}async function Dm(e,t){var r;if(e==="workspace"){let n=qS(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=qS(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 jS=fm({packageInfo:hm}),WS=new GS.ProxyAgent;HS.default.globalAgent=WS;$S.default.globalAgent=WS;var go=new Ue.Command;go.name(US.default.bold(N.turboGradient("@turbo/gen"))).description("Extend your Turborepo").version(hm.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.1",
3
+ "version": "2.6.4-canary.2",
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.1"
29
+ "@turbo/workspaces": "2.6.4-canary.2"
30
30
  },
31
31
  "devDependencies": {
32
32
  "@arethetypeswrong/cli": "^0.18.2",