@turbo/gen 2.0.5 → 2.0.6-canary.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. package/dist/cli.js +1 -1
  2. package/package.json +4 -4
package/dist/cli.js CHANGED
@@ -62,7 +62,7 @@ Please report this to https://github.com/szmarczak/http2-wrapper/`);_(y)}return}
62
62
  `+t.slice(o+1):u+=t.slice(i),u.slice(1)}function KR(t){for(var e="",r=0,n,i=0;i<t.length;r>=65536?i+=2:i++)r=zi(t,i),n=He[r],!n&&Ji(r)?(e+=t[i],r>=65536&&(e+=t[i+1])):e+=n||HR(r);return e}function JR(t,e,r){var n="",i=t.tag,s,o,a;for(s=0,o=r.length;s<o;s+=1)a=r[s],t.replacer&&(a=t.replacer.call(r,String(s),a)),(tr(t,e,a,!1,!1)||typeof a=="undefined"&&tr(t,e,null,!1,!1))&&(n!==""&&(n+=","+(t.condenseFlow?"":" ")),n+=t.dump);t.tag=i,t.dump="["+n+"]"}function r0(t,e,r,n){var i="",s=t.tag,o,a,u;for(o=0,a=r.length;o<a;o+=1)u=r[o],t.replacer&&(u=t.replacer.call(r,String(o),u)),(tr(t,e+1,u,!0,!0,!1,!0)||typeof u=="undefined"&&tr(t,e+1,null,!0,!0,!1,!0))&&((!n||i!=="")&&(i+=Cc(t,e)),t.dump&&Yi===t.dump.charCodeAt(0)?i+="-":i+="- ",i+=t.dump);t.tag=s,t.dump=i||"[]"}function XR(t,e,r){var n="",i=t.tag,s=Object.keys(r),o,a,u,c,l;for(o=0,a=s.length;o<a;o+=1)l="",n!==""&&(l+=", "),t.condenseFlow&&(l+='"'),u=s[o],c=r[u],t.replacer&&(c=t.replacer.call(r,u,c)),tr(t,e,u,!1,!1)&&(t.dump.length>1024&&(l+="? "),l+=t.dump+(t.condenseFlow?'"':"")+":"+(t.condenseFlow?"":" "),tr(t,e,c,!1,!1)&&(l+=t.dump,n+=l));t.tag=i,t.dump="{"+n+"}"}function ZR(t,e,r,n){var i="",s=t.tag,o=Object.keys(r),a,u,c,l,f,h;if(t.sortKeys===!0)o.sort();else if(typeof t.sortKeys=="function")o.sort(t.sortKeys);else if(t.sortKeys)throw new Xe("sortKeys must be a boolean or a function");for(a=0,u=o.length;a<u;a+=1)h="",(!n||i!=="")&&(h+=Cc(t,e)),c=o[a],l=r[c],t.replacer&&(l=t.replacer.call(r,c,l)),tr(t,e+1,c,!0,!0,!0)&&(f=t.tag!==null&&t.tag!=="?"||t.dump&&t.dump.length>1024,f&&(t.dump&&Yi===t.dump.charCodeAt(0)?h+="?":h+="? "),h+=t.dump,f&&(h+=Cc(t,e)),tr(t,e+1,l,!0,f)&&(t.dump&&Yi===t.dump.charCodeAt(0)?h+=":":h+=": ",h+=t.dump,i+=h));t.tag=s,t.dump=i||"{}"}function n0(t,e,r){var n,i,s,o,a,u;for(i=r?t.explicitTypes:t.implicitTypes,s=0,o=i.length;s<o;s+=1)if(a=i[s],(a.instanceOf||a.predicate)&&(!a.instanceOf||typeof e=="object"&&e instanceof a.instanceOf)&&(!a.predicate||a.predicate(e))){if(r?a.multi&&a.representName?t.tag=a.representName(e):t.tag=a.tag:t.tag="?",a.represent){if(u=t.styleMap[a.tag]||a.defaultStyle,B0.call(a.represent)==="[object Function]")n=a.represent(e,u);else if(I0.call(a.represent,u))n=a.represent[u](e,u);else throw new Xe("!<"+a.tag+'> tag resolver accepts not "'+u+'" style');t.dump=n}return!0}return!1}function tr(t,e,r,n,i,s,o){t.tag=null,t.dump=r,n0(t,r,!1)||n0(t,r,!0);var a=B0.call(t.dump),u=n,c;n&&(n=t.flowLevel<0||t.flowLevel>e);var l=a==="[object Object]"||a==="[object Array]",f,h;if(l&&(f=t.duplicates.indexOf(r),h=f!==-1),(t.tag!==null&&t.tag!=="?"||h||t.indent!==2&&e>0)&&(i=!1),h&&t.usedDuplicates[f])t.dump="*ref_"+f;else{if(l&&h&&!t.usedDuplicates[f]&&(t.usedDuplicates[f]=!0),a==="[object Object]")n&&Object.keys(t.dump).length!==0?(ZR(t,e,t.dump,i),h&&(t.dump="&ref_"+f+t.dump)):(XR(t,e,t.dump),h&&(t.dump="&ref_"+f+" "+t.dump));else if(a==="[object Array]")n&&t.dump.length!==0?(t.noArrayIndent&&!o&&e>0?r0(t,e-1,t.dump,i):r0(t,e,t.dump,i),h&&(t.dump="&ref_"+f+t.dump)):(JR(t,e,t.dump),h&&(t.dump="&ref_"+f+" "+t.dump));else if(a==="[object String]")t.tag!=="?"&&VR(t,t.dump,e,s,u);else{if(a==="[object Undefined]")return!1;if(t.skipInvalid)return!1;throw new Xe("unacceptable kind of an object to dump "+a)}t.tag!==null&&t.tag!=="?"&&(c=encodeURI(t.tag[0]==="!"?t.tag.slice(1):t.tag).replace(/!/g,"%21"),t.tag[0]==="!"?c="!"+c:c.slice(0,18)==="tag:yaml.org,2002:"?c="!!"+c.slice(18):c="!<"+c+">",t.dump=c+" "+t.dump)}return!0}function QR(t,e){var r=[],n=[],i,s;for(Rc(t,r,n),i=0,s=n.length;i<s;i+=1)e.duplicates.push(r[n[i]]);e.usedDuplicates=new Array(s)}function Rc(t,e,r){var n,i,s;if(t!==null&&typeof t=="object")if(i=e.indexOf(t),i!==-1)r.indexOf(i)===-1&&r.push(i);else if(e.push(t),Array.isArray(t))for(i=0,s=t.length;i<s;i+=1)Rc(t[i],e,r);else for(n=Object.keys(t),i=0,s=n.length;i<s;i+=1)Rc(t[n[i]],e,r)}function eF(t,e){e=e||{};var r=new $R(e);r.noRefs||QR(t,r);var n=t;return r.replacer&&(n=r.replacer.call({"":n},"",n)),tr(r,0,n,!0,!0)?r.dump+`
63
63
  `:""}var tF=eF,rF={dump:tF};function Bc(t,e){return function(){throw new Error("Function yaml."+t+" is removed in js-yaml 4. Use yaml."+e+" instead, which is now safe by default.")}}var nF=Le,iF=o0,sF=l0,oF=m0,aF=g0,uF=Tc,cF=P0.load,lF=P0.loadAll,fF=rF.dump,hF=Xe,dF={binary:D0,float:p0,map:c0,null:f0,pairs:A0,set:x0,timestamp:E0,bool:h0,int:d0,merge:b0,omap:w0,seq:u0,str:a0},pF=Bc("safeLoad","load"),mF=Bc("safeLoadAll","loadAll"),gF=Bc("safeDump","dump"),yF={Type:nF,Schema:iF,FAILSAFE_SCHEMA:sF,JSON_SCHEMA:oF,CORE_SCHEMA:aF,DEFAULT_SCHEMA:uF,load:cF,loadAll:lF,dump:fF,YAMLException:hF,types:dF,safeLoad:pF,safeLoadAll:mF,safeDump:gF},W0=yF;var BE=X(k_());var L={};xv(L,{bold:()=>JP,dimmed:()=>ZP,error:()=>gt,grey:()=>QP,info:()=>KP,item:()=>e2,log:()=>sr,turboBlue:()=>Jn,turboGradient:()=>YP,turboLoader:()=>kf,turboRed:()=>kE,underline:()=>XP,warn:()=>Pf,yellow:()=>PE});var Br=X(require("chalk")),RE=X(pE()),FE=X(vE()),TE="#0099F7",OE="#F11712",VP="#FFFF00",YP=(0,FE.default)(TE,OE),Jn=Br.default.hex(TE),kE=Br.default.hex(OE),PE=Br.default.hex(VP),kf=t=>(0,RE.default)({text:t,spinner:{frames:[" ",Jn("> "),Jn(">> "),Jn(">>>")]}}),KP=(...t)=>{sr(Jn.bold(">>>"),...t)},JP=(...t)=>{sr(Br.default.bold(...t))},XP=(...t)=>{sr(Br.default.underline(...t))},ZP=(...t)=>{sr(Br.default.dim(...t))},QP=(...t)=>{sr(Br.default.grey(...t))},e2=(...t)=>{sr(Jn.bold(" \u2022"),...t)},sr=(...t)=>{console.log(...t)},Pf=(...t)=>{console.error(PE.bold(">>>"),...t)},gt=(...t)=>{console.error(kE.bold(">>>"),...t)};var t2="turbo.json";var Bf={};function r2(t){try{if(ss.default.existsSync(fn.default.join(t,"pnpm-workspace.yaml")))return W0.load(ss.default.readFileSync(fn.default.join(t,"pnpm-workspace.yaml"),"utf8")).packages||[];let e=JSON.parse(ss.default.readFileSync(fn.default.join(t,"package.json"),"utf8"));if(e.workspaces){if("packages"in e.workspaces)return e.workspaces.packages||[];if(Array.isArray(e.workspaces))return e.workspaces}return[]}catch{return[]}}function If(t,e){var s;let r=Wi(t,e),n=[],i=(s=e==null?void 0:e.cache)!=null?s:!0;if(i&&t&&t in Bf)return Bf[t];if(r){let a=r2(r).map(c=>`${c}/turbo.json`);(0,BE.sync)([t2,...a],{cwd:r,onlyFiles:!0,followSymbolicLinks:!1,suppressErrors:!0}).map(c=>fn.default.join(r,c)).forEach(c=>{try{let l=ss.default.readFileSync(c,"utf8"),f=no.parse(l),h=fn.default.dirname(c)===r;if(h){if("extends"in f)return}else if(!("extends"in f))return;n.push({config:f,turboConfigPath:c,workspacePath:fn.default.dirname(c),isRootConfig:h})}catch(l){Pf(l)}})}return i&&t&&(Bf[t]=n),n}var KB=X(require("os")),JB=X(aD());var uD=X(require("fs-extra")),XB=[".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 ls(t){let e=uD.default.readdirSync(t).filter(r=>!XB.includes(r)).filter(r=>!r.endsWith(".iml"));return{isEmpty:e.length===0,conflicts:e}}var Zf=X(require("path")),Qf=X(require("fs-extra")),eh=X(require("chalk"));function ua(t){let e=Zf.default.resolve(t),r=Zf.default.basename(e),n=Qf.default.existsSync(e),i=Qf.default.lstatSync(e,{throwIfNoEntry:!1});if(i&&!i.isDirectory())return{valid:!1,root:e,projectName:r,error:`${eh.default.dim(r)} is not a directory - please try a different location`};if(n){let{isEmpty:s,conflicts:o}=ls(e);if(!s)return{valid:!1,root:e,projectName:r,error:`${eh.default.dim(r)} (${e}) has ${o.length} conflicting ${o.length===1?"file":"files"} - please try a different location`}}return{valid:!0,root:e,projectName:r}}var TC=require("stream"),OC=require("util"),kC=require("path"),PC=require("os"),js=require("fs"),Yp=X(sx()),$u=X(FC()),IM=(0,OC.promisify)(TC.Stream.pipeline);async function ju(t){try{return(await $u.default.head(t)).statusCode===200}catch{return!1}}async function Kp(t,e){let[,r,n,i,s,...o]=t.pathname.split("/"),a=e?e.replace(/^\//,""):o.join("/");if(i===void 0||i===""&&s===void 0)try{let c=await(0,$u.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=e?`${s}/${o.join("/")}`.replace(new RegExp(`/${a}|/$`),""):s;if(r&&n&&u&&i==="tree")return{username:r,name:n,branch:u,filePath:a}}function Jp({username:t,name:e,branch:r,filePath:n}){let i=`https://api.github.com/repos/${t}/${e}/contents`,s=`${n?`/${n}`:""}/package.json`;return ju(`${i+s}?ref=${r}`)}function Xp(t){try{let e=new URL(t);return ju(e.href)}catch{return ju(`https://api.github.com/repos/vercel/turbo/contents/examples/${encodeURIComponent(t)}`)}}async function BC(t,e){let r=(0,kC.join)((0,PC.tmpdir)(),`${e}.temp-${Date.now()}`);return await IM($u.default.stream(t),(0,js.createWriteStream)(r)),r}async function Zp(t,{username:e,name:r,branch:n,filePath:i}){let s=await BC(`https://codeload.github.com/${e}/${r}/tar.gz/${n}`,"turbo-ct-example");await(0,Yp.x)({file:s,cwd:t,strip:i?i.split("/").length+1:1,filter:o=>o.startsWith(`${r}-${n.replace(/\//g,"-")}${i?`/${i}/`:"/"}`)}),await js.promises.unlink(s)}async function Qp(t,e){let r=await BC("https://codeload.github.com/vercel/turbo/tar.gz/main","turbo-ct-example");await(0,Yp.x)({file:r,cwd:t,strip:2+e.split("/").length,filter:n=>n.includes(`turbo-main/examples/${e}/`)}),await js.promises.unlink(r)}var Uu=require("fs-extra");async function em(t){try{return await(0,Uu.access)(t,Uu.constants.W_OK),!0}catch{return!1}}var Li=X(require("path")),tm=X(jC()),vn=X(require("chalk")),Ni=require("fs-extra");function qM(t){return typeof t=="object"&&t!==null&&typeof t.message=="string"}var Gu=class extends Error{};async function rm({appPath:t,example:e,isDefaultExample:r,examplePath:n}){let i,s;if(r)i={username:"vercel",name:"turbo",branch:"main",filePath:"examples/basic"};else{try{s=new URL(e)}catch(p){p.code!=="ERR_INVALID_URL"&&(gt(p),process.exit(1))}s?(s.origin!=="https://github.com"&&(gt(`Invalid URL: ${vn.default.red(`"${e}"`)}. Only GitHub repositories are supported. Please use a GitHub URL and try again.`),process.exit(1)),i=await Kp(s,n),i||(gt(`Unable to fetch repository information from: ${vn.default.red(`"${e}"`)}. Please fix the URL and try again.`),process.exit(1)),await Jp(i)||(gt(`Could not locate the repository for ${vn.default.red(`"${e}"`)}. Please check that the repository exists and try again.`),process.exit(1))):await Xp(e)||(gt(`Could not locate an example named ${vn.default.red(`"${e}"`)}. It could be due to the following:
64
64
  `,`1. Your spelling of example ${vn.default.red(`"${e}"`)} might be incorrect.
65
- `,"2. You might not be connected to the internet or you are behind a proxy."),process.exit(1))}let o=Li.default.resolve(t);await em(Li.default.dirname(o))||(gt("The application path is not writable, please check folder permissions and try again."),gt("It is likely you do not have write permissions for this folder."),process.exit(1));let a=Li.default.basename(o);try{await(0,Ni.mkdir)(o,{recursive:!0})}catch(p){gt("Unable to create project directory"),gt(p),process.exit(1)}let{isEmpty:u,conflicts:c}=ls(o);u||(gt(`${vn.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),sr();let f=kf("Downloading files... (This might take a moment)");try{!r&&i?(f.start(),await(0,tm.default)(()=>Zp(o,i),{retries:3})):(f.start(),await(0,tm.default)(()=>Qp(o,e),{retries:3}))}catch(p){throw new Gu(qM(p)?p.message:String(p))}finally{f.stop()}let h=Li.default.join(o,"package.json"),m=(0,Ni.existsSync)(h),_=[];if(m){let p;try{p=(0,Ni.readJsonSync)(h)}catch{}p&&_.push(...Object.keys(p.scripts||{}))}let y=t;return Li.default.join(l,a)===t&&(y=a),{cdPath:y,hasPackageJson:m,availableScripts:_,repoInfo:i}}function nm(t,e={to:"camel"}){switch(e.to){case"camel":return t.replace(/(?:[-_][a-z])/g,r=>r.toUpperCase().replace("-","").replace("_",""));default:throw new Error("Not implemented")}}var yv=require("proxy-agent");var $s={name:"@turbo/gen",version:"2.0.5",description:"Extend a Turborepo",homepage:"https://turbo.build/repo",license:"MIT",repository:{type:"git",url:"https://github.com/vercel/turbo",directory:"packages/turbo-gen"},bugs:{url:"https://github.com/vercel/turbo/issues"},bin:"dist/cli.js",types:"dist/types.d.ts",scripts:{build:"tsup",test:"jest",lint:"eslint src/","check-types":"tsc --noEmit"},dependencies:{"@turbo/workspaces":"workspace:*",chalk:"2.4.2",commander:"^10.0.0","fs-extra":"^10.1.0",inquirer:"^8.2.4",minimatch:"^9.0.0","node-plop":"^0.26.3","proxy-agent":"^6.2.2","ts-node":"^10.9.1","update-check":"^1.5.4","validate-npm-package-name":"^5.0.0"},devDependencies:{"@turbo/eslint-config":"workspace:*","@turbo/test-utils":"workspace:*","@turbo/tsconfig":"workspace:*","@turbo/utils":"workspace:*","@types/fs-extra":"^9.0.13","@types/inquirer":"^8.2.5","@types/jest":"^27.4.0","@types/node":"^18.17.2","@types/validate-npm-package-name":"^4.0.0",jest:"^27.4.3","ts-jest":"^27.1.1",tsup:"^6.7.0",typescript:"5.3.3"},files:["dist"],publishConfig:{access:"public"}};var $C=X(require("chalk")),UC=X(require("update-check"));var jM=(0,UC.default)($s).catch(()=>null);async function im(){try{let t=await jM;t!=null&&t.latest&&(L.log(),L.log($C.default.yellow.bold(`A new version of \`${$s.name}\` is available!`)),L.log()),process.exit()}catch{}}var GC=require("@turbo/workspaces");async function Wu({root:t}){let e=t||process.cwd(),r=Wi(e);if(!r)L.error("Unable to infer repository root - override with --root");else try{return(0,GC.getWorkspaceDetails)({root:r})}catch{L.error(`Unable to determine workspace details. Make sure "${e}" is the root, or add "packageManager" to "package.json" or ensure a lockfile is present.`)}process.exit(1)}var wr=X(require("path")),Vu=X(require("fs-extra")),zu=X(require("node-plop")),WC=require("ts-node"),zC=require("inquirer");var Me=class extends Error{constructor(r,n){var i;super(r);this.name="GenerateError",this.type=(i=n==null?void 0:n.type)!=null?i:"unknown",Error.captureStackTrace(this,Me)}};var VC=["ts","js","cjs"],$M=wr.default.join("turbo","generators"),YC=VC.map(t=>wr.default.join($M,`config.${t}`)),UM=[...YC,...VC.map(t=>wr.default.join(`plopfile.${t}`))];function KC({project:t,configPath:e}){(0,WC.register)({transpileOnly:!0,cwd:t.paths.root,compilerOptions:{module:"nodenext",moduleResolution:"nodenext"}});let r=WM({project:t}),n;if(e){if(!Vu.default.existsSync(e))throw new Me(`No config at "${e}"`,{type:"plop_no_config"});try{n=(0,zu.default)(e,{destBasePath:e,force:!1})}catch(i){L.error(i)}}else{for(let i of UM){let s=wr.default.join(t.paths.root,i);if(Vu.default.existsSync(s))try{n=(0,zu.default)(s,{destBasePath:t.paths.root,force:!1});break}catch(o){L.error(o)}}!n&&r.length>0&&(n=(0,zu.default)(r[0].config,{destBasePath:r[0].root,force:!1}),r.shift())}return n&&r.forEach(i=>{try{n==null||n.load(i.config,{destBasePath:i.root,force:!1})}catch(s){L.error(s)}}),n}function sm({project:t,configPath:e}){let r=KC({project:t,configPath:e});if(!r)return[];let i=r.getGeneratorList().map(a=>r.getGenerator(a.name)),s={};i.forEach(a=>{let u=a,c=t.workspaceData.workspaces.find(l=>{if(u.basePath===t.paths.root)return!1;let f=u.basePath.split(wr.default.sep);return f.pop(),f.pop(),wr.default.join("/",...f)===l.paths.root});c?(c.name in s||(s[c.name]=[]),s[c.name].push(u)):("root"in s||(s.root=[]),s.root.push(u))});let o=[];return Object.keys(s).forEach(a=>{o.push(new zC.Separator(a)),o.push(...s[a])}),o}function GM({project:t,generator:e}){let r={cwd:process.cwd(),root:t.paths.root,workspace:e.basePath?Gi({cwd:e.basePath,target:"package.json"}):void 0},n={};try{n=If(e.basePath)}catch{}return{turbo:{paths:r,configs:n}}}function WM({project:t}){let e=[];return t.workspaceData.workspaces.forEach(r=>{for(let n of YC)Vu.default.existsSync(wr.default.join(r.paths.root,n))&&e.push({config:wr.default.join(r.paths.root,n),root:r.paths.root})}),e}async function JC({project:t,generator:e,bypassArgs:r,configPath:n}){let i=KC({project:t,configPath:n});if(!i)throw new Me("Unable to load generators",{type:"plop_unable_to_load_config"});let s=i.getGenerator(e);if(!s)throw new Me(`Generator ${e} not found`,{type:"plop_generator_not_found"});let o=await s.runPrompts(r),a=await s.runActions({...o,...GM({project:t,generator:s})},{onComment:u=>{L.dimmed(u)}});if(a.failures.length>0)throw a.failures.forEach(u=>{u instanceof Error?L.error(`Error - ${u.message}`):L.error(`Error - ${u.error}. Unable to ${u.type} to "${u.path}"`)}),new Me(`Failed to run "${e}" generator`,{type:"plop_error_running_generator"});a.changes.length>0&&(L.info("Changes made:"),a.changes.forEach(u=>{u.path&&L.item(`${u.path} (${u.type})`)}))}var Rn=require("inquirer");async function XC({generators:t,generator:e}){if(e){if(t.find(n=>!(n instanceof Rn.Separator)&&n.name===e))return{selectedGenerator:e};L.warn(`Generator "${e}" not found`),L.log()}return await(0,Rn.prompt)({type:"list",name:"selectedGenerator",message:"Select generator to run",choices:t.map(n=>n instanceof Rn.Separator?n:{name:n.description?` ${n.name}: ${n.description}`:` ${n.name}`,value:n.name})})}async function ZC(){return(0,Rn.prompt)({type:"list",name:"answer",message:"Should the generator config be created with TS or JS?",default:"ts",choices:[{name:"JavaScript",value:"js"},{name:"TypeScript",value:"ts"}]})}async function QC({message:t}){return(0,Rn.prompt)({type:"confirm",name:"answer",message:t})}var om=X(require("path")),Yu=require("fs-extra");async function ev({project:t,template:e}){let r=om.default.join(t.paths.root,"turbo","generators"),n=`simple-${e}`;if(await(0,Yu.pathExists)(r))throw new Me(`Generator config directory already exists at ${r}`,{type:"config_directory_already_exists"});await(0,Yu.copy)(om.default.join(__dirname,"templates",n),r,{recursive:!0})}async function am({generator:t,project:e,opts:r}){let n=!1,i=sm({project:e,configPath:r.config});if(!i.length){L.error("No generators found."),L.log();let{answer:o}=await QC({message:`Would you like to add a config with a sample custom generator to ${e.name}?`});if(o){n=!0;let{answer:a}=await ZC();try{await ev({project:e,template:a})}catch(u){throw u instanceof Me||L.error("Failed to create generator config"),u}if(L.log(),L.info("Generator config successfully created!"),L.info("Loading generator config..."),L.log(),i=sm({project:e,configPath:r.config}),!i.length){L.error("Error loading generator");return}}else{L.log(),L.dimmed("Learn more about custom Turborepo generators - https://turbo.build/repo/docs/core-concepts/monorepos/code-generation#custom-generators");return}}let{selectedGenerator:s}=await XC({generators:i,generator:t});try{await JC({project:e,generator:s,bypassArgs:r.args,configPath:r.config})}catch(o){if(o instanceof Me)throw o;let a="Failed to run generator";throw o instanceof Error&&(a=o.message),new Me(a,{type:"plop_error_running_generator"})}finally{n&&(L.log(),L.info("Congrats! You just ran your first Turborepo generator"),L.dimmed("Learn more about custom Turborepo generators - https://turbo.build/repo/docs/core-concepts/monorepos/code-generation#custom-generators"))}L.log(),L.bold(L.turboGradient(">>> Success!"))}var fm=X(require("path")),Gs=require("fs-extra"),fv=X(require("chalk"));var Us=X(require("path")),iv=require("fs-extra"),Ct=require("inquirer"),sv=require("minimatch"),lm=X(require("validate-npm-package-name"));var um=X(require("path"));var tv=X(require("path"));function rv({project:t}){let r=t.workspaceData.workspaces.map(i=>tv.default.relative(t.paths.root,i.paths.root)),n=new Set;return t.workspaceData.globs.forEach(i=>{if(!r.includes(i)){if(!i.startsWith("!")){let o=i.split("/")[0];n.add(o)}}}),Array.from(n)}function cm({project:t,workspace:e}){return um.default.relative(t.paths.root,e.paths.root).split(um.default.sep)[0]}function Ku({project:t}){let e=rv({project:t}),r=e.includes("apps"),n=e.includes("packages"),i={},s=[];return t.workspaceData.workspaces.forEach(o=>{let a=cm({project:t,workspace:o});a!=="apps"&&s.push(o),a in i||(i[a]=[]),i[a].push(o)}),{hasRootApps:r,hasRootPackages:n,workspacesByGroup:i,nonAppWorkspaces:s}}var nv=require("inquirer");function Ju({project:t,type:e,showAllDependencies:r}){let n=Ku({project:t}),i=[],s=t.workspaceData.workspaces;r||(e==="app"&&n.hasRootApps?s=n.workspacesByGroup.apps:e==="package"&&n.nonAppWorkspaces.length>0&&(s=n.nonAppWorkspaces));let o;return s.forEach(a=>{let u=cm({project:t,workspace:a});u!==o&&i.push(new nv.Separator(u)),o=u,i.push(a)}),i}async function ov({override:t,suggestion:e,workspaceType:r}){let{validForNewPackages:n}=(0,lm.default)(t||"");return t&&n?{answer:t}:(0,Ct.prompt)({type:"input",name:"answer",default:e,validate:i=>{let{validForNewPackages:s}=(0,lm.default)(i);return s||`Invalid ${r} name`},message:`What is the name of the ${r}?`})}async function av({override:t,message:e}){return t?{answer:t}:(0,Ct.prompt)({type:"list",name:"answer",message:e!=null?e:"What type of workspace should be added?",choices:[{name:"app",value:"app"},{name:"package",value:"package"}]})}async function uv({workspaceType:t,workspaceName:e,destination:r,project:n}){let i=e.includes("/")?e.split("/")[1]:e;if(r){let{valid:u,root:c}=ua(r);if(u)return{absolute:c,relative:Us.default.relative(n.paths.root,c)}}let s,o=Ku({project:n});t==="app"&&o.hasRootApps?s=`${n.paths.root}/apps/${i}`:t==="package"&&o.hasRootPackages&&(s=`${n.paths.root}/packages/${i}`);let{answer:a}=await(0,Ct.prompt)({type:"input",name:"answer",message:`Where should "${e}" be added?`,default:s?Us.default.relative(n.paths.root,s):void 0,validate:u=>{let c=Us.default.join(n.paths.root,u),{valid:l,error:f}=ua(c),h=n.workspaceData.globs.some(m=>(0,sv.minimatch)(u,m));return l&&h?!0:h?f:`${u} is not a valid workspace location`}});return{absolute:Us.default.join(n.paths.root,a),relative:a}}async function cv({override:t,workspaces:e,workspaceName:r}){if(t){let i=e.find(s=>s instanceof Ct.Separator?!1:s.name===t);if(i)return{answer:i};L.warn(`Workspace "${t}" not found`),L.log()}return await(0,Ct.prompt)({type:"list",name:"answer",loop:!1,pageSize:25,message:`Which workspace should "${r}" start from?`,choices:e.map(i=>i instanceof Ct.Separator?i:{name:` ${i.name}`,value:i})})}async function lv({workspaceName:t,project:e,workspaceSource:r,showAllDependencies:n}){let i={dependencies:{},devDependencies:{},peerDependencies:{},optionalDependencies:{}},{answer:s}=await VM({message:`Add workspace dependencies to "${t}"?`});if(!s)return i;let{answer:o}=await(0,Ct.prompt)({type:"checkbox",name:"answer",message:`Select all dependencies types to modify for "${t}"`,loop:!1,choices:[{name:"dependencies",value:"dependencies"},{name:"devDependencies",value:"devDependencies"},{name:"peerDependencies",value:"peerDependencies"},{name:"optionalDependencies",value:"optionalDependencies"}]}),a=Ju({project:e,type:"package",showAllDependencies:n}),u=r?(0,iv.readJsonSync)(r.paths.packageJson):void 0;for(let c of o){let{answer:l}=await(0,Ct.prompt)({type:"checkbox",name:"answer",default:u&&Object.keys(u[c]||{}),pageSize:15,message:`Which packages should be added as ${c} to "${t}?`,loop:!1,choices:a.map(h=>h instanceof Ct.Separator?h:{name:` ${h.name}`,value:h.name})}),f=(u==null?void 0:u[c])||{};if(Object.keys(f).length){let h=new Set(Object.keys(f));l.forEach(m=>{h.has(m)||(f[m]=e.packageManager==="pnpm"?"workspace:*":"*")}),i[c]=f}else i[c]=l.reduce((h,m)=>({...h,[m]:e.packageManager==="pnpm"?"workspace:*":"*"}),{})}return i}async function VM({message:t}){return(0,Ct.prompt)({type:"confirm",name:"answer",message:t})}async function Xu({project:t,opts:e}){var u;let r,n=e.method==="copy"&&e.copy.type==="external"?((u=e.examplePath)==null?void 0:u.split("/").pop())||e.copy.source.split("/").pop():void 0,{answer:i}=await av({override:e.type,message:e.method==="copy"&&e.copy.source==="external"&&n?`What type of workspace should "${n}" be created as?`:void 0}),{answer:s}=await ov({override:e.name,workspaceType:i,suggestion:n});if(e.method==="copy"&&e.copy.type==="internal"){let{answer:c}=await cv({override:e.copy.source,workspaces:Ju({project:t,type:i}),workspaceName:s});r=c}let o=await uv({workspaceType:i,workspaceName:s,project:t,destination:e.destination}),a=await lv({workspaceName:s,project:t,workspaceSource:r,showAllDependencies:e.showAllDependencies});return{type:i,name:s,location:o,source:r,dependencies:a}}async function hm({project:t,opts:e}){let{name:r,location:n,dependencies:i}=await Xu({project:t,opts:e}),s={name:r,version:"0.0.0",private:!0,scripts:{dev:"echo 'Add dev script here'",build:"echo 'Add build script here'",test:"echo 'Add test script here'",lint:"echo 'Add lint script here'"}};Object.keys(i).forEach(o=>{let a=i[o];a&&Object.keys(a).length>0&&(s[o]=a)}),(0,Gs.mkdirSync)(n.absolute,{recursive:!0}),(0,Gs.writeFileSync)(fm.default.join(n.absolute,"package.json"),JSON.stringify(s,null,2)),(0,Gs.writeFileSync)(fm.default.join(n.absolute,"README.md"),`# \`${r}\``),L.log(),L.log(`${fv.default.bold(L.turboGradient(">>> Success!"))} Created ${r} at "${n.relative}"`)}var dm=X(require("path")),vt=require("fs-extra"),hv=X(require("chalk"));async function pm({project:t,opts:e}){let{name:r,type:n,location:i,source:s,dependencies:o}=await Xu({project:t,opts:e}),a=dm.default.join(i.absolute,"package.json");if(e.copy.type==="external"){L.log(),L.warn("Some manual modifications may be required."),L.dimmed(`This ${n} may require local dependencies or a different package manager than what is available in this repo`),await rm({appPath:i.absolute,example:e.copy.source,examplePath:e.examplePath});try{if((0,vt.existsSync)(a)){if((await(0,vt.readJSON)(a)).workspaces)throw new Error("New workspace root detected - unexpected 'workspaces' field in package.json")}else throw new Error("New workspace is missing a package.json file");if((0,vt.existsSync)(dm.default.join(i.absolute,"pnpm-workspace.yaml")))throw new Error("New workspace root detected - unexpected pnpm-workspace.yaml")}catch(c){let l="UNKNOWN_ERROR";c instanceof Error&&(l=c.message),L.error(l),await(0,vt.rm)(i.absolute,{recursive:!0,force:!0});return}}else if(s){let c=async f=>Promise.resolve(!f.includes("node_modules")),l=L.turboLoader(`Creating "${r}" from "${s.name}"...`);l.start(),await(0,vt.copy)(s.paths.root,i.absolute,{filter:c}),l.stop()}let u=await(0,vt.readJSON)(a);u.name=r,Object.keys(o).forEach(c=>{let l=o[c];l&&Object.keys(l).length>0&&(u[c]=l)}),await(0,vt.writeJSON)(a,u,{spaces:2}),L.log(),L.log(`${hv.default.bold(L.turboGradient(">>> Success!"))} Created ${r} at "${i.relative}"`)}function KM(t){let{copy:e,...r}=t,n=e===!0||typeof e=="string"?"copy":"empty",i=typeof e=="string"?e:"",s=typeof e=="string"&&e.startsWith("https://")?"external":"internal";return{method:n,copy:{type:s,source:i},...r}}async function Ws(t){let e=await Wu(t),r=KM(t);L.log();let n={project:e,opts:r};r.method==="copy"?(r.copy.type==="external"?L.info(`Copy a remote workspace from ${r.copy.source}`):L.info(`Copy an existing workspace from "${e.name}"`),L.log(),await pm(n)):(L.info(`Add an empty workspace to "${e.name}"`),L.log(),await hm(n))}async function zs(t,e){let r=await Wu(e);L.log(),L.info(`Modify "${r.name}" using custom generators`),L.log(),await am({generator:t,project:r,opts:e})}function dv(t){try{let e=JSON.parse(t),r={};for(let n in e){let i=nm(n,{to:"camel"});r[i]=e[n]}return r}catch(e){L.error("Error parsing arguments",e),process.exit(1)}}async function mm(t,e){var r;if(t==="workspace"){let n=dv(e.json);n.showAllDependencies=(r=n.showAllDependencies)!=null?r:!1;let i=!1,s=n.empty||!0;n.copy===""||n.copy===!0?(i=!0,s=!1):n.copy&&n.copy.length>0&&(i=n.copy,s=!1),n.copy=i,n.empty=s,await Ws(n)}else if(t==="run"){let n=dv(e.json),{generatorName:i,...s}=n;await zs(i,s)}else L.error(`Received unknown command - "${t}" (must be one of "workspace" | "run")`),process.exit(1)}var _v=new yv.ProxyAgent;pv.default.globalAgent=_v;mv.default.globalAgent=_v;var Vs=new qe.Command;Vs.name(gv.default.bold(L.turboGradient("@turbo/gen"))).description("Extend your Turborepo").version($s.version,"-v, --version","Output the current version").helpOption("-h, --help","Display help for command").showHelpAfterError(!1);Vs.command("run",{isDefault:!0}).alias("r").description("Run custom generators").addArgument(new qe.Argument("[generator-name]","The name of the generator to run")).addOption(new qe.Option("-c, --config <config>","Generator configuration file (default: turbo/generators/config.js")).addOption(new qe.Option("-r, --root <dir>","The root of your repository (default: directory with root turbo.json)")).addOption(new qe.Option("-a, --args <args...>","Arguments passed directly to generator").default([])).action(zs);Vs.command("workspace").aliases(["w"]).description("Add a new package or app to your project").addOption(new qe.Option("-n, --name <workspace-name>","Name for the new workspace")).addOption(new qe.Option("-b, --empty","Generate an empty workspace").conflicts("copy").default(!0)).addOption(new qe.Option("-c, --copy [source]",`Generate a workspace using an existing workspace as a template. Can be the name of a local workspace
65
+ `,"2. You might not be connected to the internet or you are behind a proxy."),process.exit(1))}let o=Li.default.resolve(t);await em(Li.default.dirname(o))||(gt("The application path is not writable, please check folder permissions and try again."),gt("It is likely you do not have write permissions for this folder."),process.exit(1));let a=Li.default.basename(o);try{await(0,Ni.mkdir)(o,{recursive:!0})}catch(p){gt("Unable to create project directory"),gt(p),process.exit(1)}let{isEmpty:u,conflicts:c}=ls(o);u||(gt(`${vn.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),sr();let f=kf("Downloading files... (This might take a moment)");try{!r&&i?(f.start(),await(0,tm.default)(()=>Zp(o,i),{retries:3})):(f.start(),await(0,tm.default)(()=>Qp(o,e),{retries:3}))}catch(p){throw new Gu(qM(p)?p.message:String(p))}finally{f.stop()}let h=Li.default.join(o,"package.json"),m=(0,Ni.existsSync)(h),_=[];if(m){let p;try{p=(0,Ni.readJsonSync)(h)}catch{}p&&_.push(...Object.keys(p.scripts||{}))}let y=t;return Li.default.join(l,a)===t&&(y=a),{cdPath:y,hasPackageJson:m,availableScripts:_,repoInfo:i}}function nm(t,e={to:"camel"}){switch(e.to){case"camel":return t.replace(/(?:[-_][a-z])/g,r=>r.toUpperCase().replace("-","").replace("_",""));default:throw new Error("Not implemented")}}var yv=require("proxy-agent");var $s={name:"@turbo/gen",version:"2.0.6-canary.0",description:"Extend a Turborepo",homepage:"https://turbo.build/repo",license:"MIT",repository:{type:"git",url:"https://github.com/vercel/turbo",directory:"packages/turbo-gen"},bugs:{url:"https://github.com/vercel/turbo/issues"},bin:"dist/cli.js",types:"dist/types.d.ts",scripts:{build:"tsup",test:"jest",lint:"eslint src/","check-types":"tsc --noEmit"},dependencies:{"@turbo/workspaces":"workspace:*",chalk:"2.4.2",commander:"^10.0.0","fs-extra":"^10.1.0",inquirer:"^8.2.4",minimatch:"^9.0.0","node-plop":"^0.26.3","proxy-agent":"^6.2.2","ts-node":"^10.9.1","update-check":"^1.5.4","validate-npm-package-name":"^5.0.0"},devDependencies:{"@turbo/eslint-config":"workspace:*","@turbo/test-utils":"workspace:*","@turbo/tsconfig":"workspace:*","@turbo/utils":"workspace:*","@types/fs-extra":"^9.0.13","@types/inquirer":"^8.2.5","@types/jest":"^27.4.0","@types/node":"^18.17.2","@types/validate-npm-package-name":"^4.0.0",jest:"^27.4.3","ts-jest":"^27.1.1",tsup:"^6.7.0",typescript:"5.3.3"},files:["dist"],publishConfig:{access:"public"}};var $C=X(require("chalk")),UC=X(require("update-check"));var jM=(0,UC.default)($s).catch(()=>null);async function im(){try{let t=await jM;t!=null&&t.latest&&(L.log(),L.log($C.default.yellow.bold(`A new version of \`${$s.name}\` is available!`)),L.log()),process.exit()}catch{}}var GC=require("@turbo/workspaces");async function Wu({root:t}){let e=t||process.cwd(),r=Wi(e);if(!r)L.error("Unable to infer repository root - override with --root");else try{return(0,GC.getWorkspaceDetails)({root:r})}catch{L.error(`Unable to determine workspace details. Make sure "${e}" is the root, or add "packageManager" to "package.json" or ensure a lockfile is present.`)}process.exit(1)}var wr=X(require("path")),Vu=X(require("fs-extra")),zu=X(require("node-plop")),WC=require("ts-node"),zC=require("inquirer");var Me=class extends Error{constructor(r,n){var i;super(r);this.name="GenerateError",this.type=(i=n==null?void 0:n.type)!=null?i:"unknown",Error.captureStackTrace(this,Me)}};var VC=["ts","js","cjs"],$M=wr.default.join("turbo","generators"),YC=VC.map(t=>wr.default.join($M,`config.${t}`)),UM=[...YC,...VC.map(t=>wr.default.join(`plopfile.${t}`))];function KC({project:t,configPath:e}){(0,WC.register)({transpileOnly:!0,cwd:t.paths.root,compilerOptions:{module:"nodenext",moduleResolution:"nodenext"}});let r=WM({project:t}),n;if(e){if(!Vu.default.existsSync(e))throw new Me(`No config at "${e}"`,{type:"plop_no_config"});try{n=(0,zu.default)(e,{destBasePath:e,force:!1})}catch(i){L.error(i)}}else{for(let i of UM){let s=wr.default.join(t.paths.root,i);if(Vu.default.existsSync(s))try{n=(0,zu.default)(s,{destBasePath:t.paths.root,force:!1});break}catch(o){L.error(o)}}!n&&r.length>0&&(n=(0,zu.default)(r[0].config,{destBasePath:r[0].root,force:!1}),r.shift())}return n&&r.forEach(i=>{try{n==null||n.load(i.config,{destBasePath:i.root,force:!1})}catch(s){L.error(s)}}),n}function sm({project:t,configPath:e}){let r=KC({project:t,configPath:e});if(!r)return[];let i=r.getGeneratorList().map(a=>r.getGenerator(a.name)),s={};i.forEach(a=>{let u=a,c=t.workspaceData.workspaces.find(l=>{if(u.basePath===t.paths.root)return!1;let f=u.basePath.split(wr.default.sep);return f.pop(),f.pop(),wr.default.join("/",...f)===l.paths.root});c?(c.name in s||(s[c.name]=[]),s[c.name].push(u)):("root"in s||(s.root=[]),s.root.push(u))});let o=[];return Object.keys(s).forEach(a=>{o.push(new zC.Separator(a)),o.push(...s[a])}),o}function GM({project:t,generator:e}){let r={cwd:process.cwd(),root:t.paths.root,workspace:e.basePath?Gi({cwd:e.basePath,target:"package.json"}):void 0},n={};try{n=If(e.basePath)}catch{}return{turbo:{paths:r,configs:n}}}function WM({project:t}){let e=[];return t.workspaceData.workspaces.forEach(r=>{for(let n of YC)Vu.default.existsSync(wr.default.join(r.paths.root,n))&&e.push({config:wr.default.join(r.paths.root,n),root:r.paths.root})}),e}async function JC({project:t,generator:e,bypassArgs:r,configPath:n}){let i=KC({project:t,configPath:n});if(!i)throw new Me("Unable to load generators",{type:"plop_unable_to_load_config"});let s=i.getGenerator(e);if(!s)throw new Me(`Generator ${e} not found`,{type:"plop_generator_not_found"});let o=await s.runPrompts(r),a=await s.runActions({...o,...GM({project:t,generator:s})},{onComment:u=>{L.dimmed(u)}});if(a.failures.length>0)throw a.failures.forEach(u=>{u instanceof Error?L.error(`Error - ${u.message}`):L.error(`Error - ${u.error}. Unable to ${u.type} to "${u.path}"`)}),new Me(`Failed to run "${e}" generator`,{type:"plop_error_running_generator"});a.changes.length>0&&(L.info("Changes made:"),a.changes.forEach(u=>{u.path&&L.item(`${u.path} (${u.type})`)}))}var Rn=require("inquirer");async function XC({generators:t,generator:e}){if(e){if(t.find(n=>!(n instanceof Rn.Separator)&&n.name===e))return{selectedGenerator:e};L.warn(`Generator "${e}" not found`),L.log()}return await(0,Rn.prompt)({type:"list",name:"selectedGenerator",message:"Select generator to run",choices:t.map(n=>n instanceof Rn.Separator?n:{name:n.description?` ${n.name}: ${n.description}`:` ${n.name}`,value:n.name})})}async function ZC(){return(0,Rn.prompt)({type:"list",name:"answer",message:"Should the generator config be created with TS or JS?",default:"ts",choices:[{name:"JavaScript",value:"js"},{name:"TypeScript",value:"ts"}]})}async function QC({message:t}){return(0,Rn.prompt)({type:"confirm",name:"answer",message:t})}var om=X(require("path")),Yu=require("fs-extra");async function ev({project:t,template:e}){let r=om.default.join(t.paths.root,"turbo","generators"),n=`simple-${e}`;if(await(0,Yu.pathExists)(r))throw new Me(`Generator config directory already exists at ${r}`,{type:"config_directory_already_exists"});await(0,Yu.copy)(om.default.join(__dirname,"templates",n),r,{recursive:!0})}async function am({generator:t,project:e,opts:r}){let n=!1,i=sm({project:e,configPath:r.config});if(!i.length){L.error("No generators found."),L.log();let{answer:o}=await QC({message:`Would you like to add a config with a sample custom generator to ${e.name}?`});if(o){n=!0;let{answer:a}=await ZC();try{await ev({project:e,template:a})}catch(u){throw u instanceof Me||L.error("Failed to create generator config"),u}if(L.log(),L.info("Generator config successfully created!"),L.info("Loading generator config..."),L.log(),i=sm({project:e,configPath:r.config}),!i.length){L.error("Error loading generator");return}}else{L.log(),L.dimmed("Learn more about custom Turborepo generators - https://turbo.build/repo/docs/core-concepts/monorepos/code-generation#custom-generators");return}}let{selectedGenerator:s}=await XC({generators:i,generator:t});try{await JC({project:e,generator:s,bypassArgs:r.args,configPath:r.config})}catch(o){if(o instanceof Me)throw o;let a="Failed to run generator";throw o instanceof Error&&(a=o.message),new Me(a,{type:"plop_error_running_generator"})}finally{n&&(L.log(),L.info("Congrats! You just ran your first Turborepo generator"),L.dimmed("Learn more about custom Turborepo generators - https://turbo.build/repo/docs/core-concepts/monorepos/code-generation#custom-generators"))}L.log(),L.bold(L.turboGradient(">>> Success!"))}var fm=X(require("path")),Gs=require("fs-extra"),fv=X(require("chalk"));var Us=X(require("path")),iv=require("fs-extra"),Ct=require("inquirer"),sv=require("minimatch"),lm=X(require("validate-npm-package-name"));var um=X(require("path"));var tv=X(require("path"));function rv({project:t}){let r=t.workspaceData.workspaces.map(i=>tv.default.relative(t.paths.root,i.paths.root)),n=new Set;return t.workspaceData.globs.forEach(i=>{if(!r.includes(i)){if(!i.startsWith("!")){let o=i.split("/")[0];n.add(o)}}}),Array.from(n)}function cm({project:t,workspace:e}){return um.default.relative(t.paths.root,e.paths.root).split(um.default.sep)[0]}function Ku({project:t}){let e=rv({project:t}),r=e.includes("apps"),n=e.includes("packages"),i={},s=[];return t.workspaceData.workspaces.forEach(o=>{let a=cm({project:t,workspace:o});a!=="apps"&&s.push(o),a in i||(i[a]=[]),i[a].push(o)}),{hasRootApps:r,hasRootPackages:n,workspacesByGroup:i,nonAppWorkspaces:s}}var nv=require("inquirer");function Ju({project:t,type:e,showAllDependencies:r}){let n=Ku({project:t}),i=[],s=t.workspaceData.workspaces;r||(e==="app"&&n.hasRootApps?s=n.workspacesByGroup.apps:e==="package"&&n.nonAppWorkspaces.length>0&&(s=n.nonAppWorkspaces));let o;return s.forEach(a=>{let u=cm({project:t,workspace:a});u!==o&&i.push(new nv.Separator(u)),o=u,i.push(a)}),i}async function ov({override:t,suggestion:e,workspaceType:r}){let{validForNewPackages:n}=(0,lm.default)(t||"");return t&&n?{answer:t}:(0,Ct.prompt)({type:"input",name:"answer",default:e,validate:i=>{let{validForNewPackages:s}=(0,lm.default)(i);return s||`Invalid ${r} name`},message:`What is the name of the ${r}?`})}async function av({override:t,message:e}){return t?{answer:t}:(0,Ct.prompt)({type:"list",name:"answer",message:e!=null?e:"What type of workspace should be added?",choices:[{name:"app",value:"app"},{name:"package",value:"package"}]})}async function uv({workspaceType:t,workspaceName:e,destination:r,project:n}){let i=e.includes("/")?e.split("/")[1]:e;if(r){let{valid:u,root:c}=ua(r);if(u)return{absolute:c,relative:Us.default.relative(n.paths.root,c)}}let s,o=Ku({project:n});t==="app"&&o.hasRootApps?s=`${n.paths.root}/apps/${i}`:t==="package"&&o.hasRootPackages&&(s=`${n.paths.root}/packages/${i}`);let{answer:a}=await(0,Ct.prompt)({type:"input",name:"answer",message:`Where should "${e}" be added?`,default:s?Us.default.relative(n.paths.root,s):void 0,validate:u=>{let c=Us.default.join(n.paths.root,u),{valid:l,error:f}=ua(c),h=n.workspaceData.globs.some(m=>(0,sv.minimatch)(u,m));return l&&h?!0:h?f:`${u} is not a valid workspace location`}});return{absolute:Us.default.join(n.paths.root,a),relative:a}}async function cv({override:t,workspaces:e,workspaceName:r}){if(t){let i=e.find(s=>s instanceof Ct.Separator?!1:s.name===t);if(i)return{answer:i};L.warn(`Workspace "${t}" not found`),L.log()}return await(0,Ct.prompt)({type:"list",name:"answer",loop:!1,pageSize:25,message:`Which workspace should "${r}" start from?`,choices:e.map(i=>i instanceof Ct.Separator?i:{name:` ${i.name}`,value:i})})}async function lv({workspaceName:t,project:e,workspaceSource:r,showAllDependencies:n}){let i={dependencies:{},devDependencies:{},peerDependencies:{},optionalDependencies:{}},{answer:s}=await VM({message:`Add workspace dependencies to "${t}"?`});if(!s)return i;let{answer:o}=await(0,Ct.prompt)({type:"checkbox",name:"answer",message:`Select all dependencies types to modify for "${t}"`,loop:!1,choices:[{name:"dependencies",value:"dependencies"},{name:"devDependencies",value:"devDependencies"},{name:"peerDependencies",value:"peerDependencies"},{name:"optionalDependencies",value:"optionalDependencies"}]}),a=Ju({project:e,type:"package",showAllDependencies:n}),u=r?(0,iv.readJsonSync)(r.paths.packageJson):void 0;for(let c of o){let{answer:l}=await(0,Ct.prompt)({type:"checkbox",name:"answer",default:u&&Object.keys(u[c]||{}),pageSize:15,message:`Which packages should be added as ${c} to "${t}?`,loop:!1,choices:a.map(h=>h instanceof Ct.Separator?h:{name:` ${h.name}`,value:h.name})}),f=(u==null?void 0:u[c])||{};if(Object.keys(f).length){let h=new Set(Object.keys(f));l.forEach(m=>{h.has(m)||(f[m]=e.packageManager==="pnpm"?"workspace:*":"*")}),i[c]=f}else i[c]=l.reduce((h,m)=>({...h,[m]:e.packageManager==="pnpm"?"workspace:*":"*"}),{})}return i}async function VM({message:t}){return(0,Ct.prompt)({type:"confirm",name:"answer",message:t})}async function Xu({project:t,opts:e}){var u;let r,n=e.method==="copy"&&e.copy.type==="external"?((u=e.examplePath)==null?void 0:u.split("/").pop())||e.copy.source.split("/").pop():void 0,{answer:i}=await av({override:e.type,message:e.method==="copy"&&e.copy.source==="external"&&n?`What type of workspace should "${n}" be created as?`:void 0}),{answer:s}=await ov({override:e.name,workspaceType:i,suggestion:n});if(e.method==="copy"&&e.copy.type==="internal"){let{answer:c}=await cv({override:e.copy.source,workspaces:Ju({project:t,type:i}),workspaceName:s});r=c}let o=await uv({workspaceType:i,workspaceName:s,project:t,destination:e.destination}),a=await lv({workspaceName:s,project:t,workspaceSource:r,showAllDependencies:e.showAllDependencies});return{type:i,name:s,location:o,source:r,dependencies:a}}async function hm({project:t,opts:e}){let{name:r,location:n,dependencies:i}=await Xu({project:t,opts:e}),s={name:r,version:"0.0.0",private:!0,scripts:{dev:"echo 'Add dev script here'",build:"echo 'Add build script here'",test:"echo 'Add test script here'",lint:"echo 'Add lint script here'"}};Object.keys(i).forEach(o=>{let a=i[o];a&&Object.keys(a).length>0&&(s[o]=a)}),(0,Gs.mkdirSync)(n.absolute,{recursive:!0}),(0,Gs.writeFileSync)(fm.default.join(n.absolute,"package.json"),JSON.stringify(s,null,2)),(0,Gs.writeFileSync)(fm.default.join(n.absolute,"README.md"),`# \`${r}\``),L.log(),L.log(`${fv.default.bold(L.turboGradient(">>> Success!"))} Created ${r} at "${n.relative}"`)}var dm=X(require("path")),vt=require("fs-extra"),hv=X(require("chalk"));async function pm({project:t,opts:e}){let{name:r,type:n,location:i,source:s,dependencies:o}=await Xu({project:t,opts:e}),a=dm.default.join(i.absolute,"package.json");if(e.copy.type==="external"){L.log(),L.warn("Some manual modifications may be required."),L.dimmed(`This ${n} may require local dependencies or a different package manager than what is available in this repo`),await rm({appPath:i.absolute,example:e.copy.source,examplePath:e.examplePath});try{if((0,vt.existsSync)(a)){if((await(0,vt.readJSON)(a)).workspaces)throw new Error("New workspace root detected - unexpected 'workspaces' field in package.json")}else throw new Error("New workspace is missing a package.json file");if((0,vt.existsSync)(dm.default.join(i.absolute,"pnpm-workspace.yaml")))throw new Error("New workspace root detected - unexpected pnpm-workspace.yaml")}catch(c){let l="UNKNOWN_ERROR";c instanceof Error&&(l=c.message),L.error(l),await(0,vt.rm)(i.absolute,{recursive:!0,force:!0});return}}else if(s){let c=async f=>Promise.resolve(!f.includes("node_modules")),l=L.turboLoader(`Creating "${r}" from "${s.name}"...`);l.start(),await(0,vt.copy)(s.paths.root,i.absolute,{filter:c}),l.stop()}let u=await(0,vt.readJSON)(a);u.name=r,Object.keys(o).forEach(c=>{let l=o[c];l&&Object.keys(l).length>0&&(u[c]=l)}),await(0,vt.writeJSON)(a,u,{spaces:2}),L.log(),L.log(`${hv.default.bold(L.turboGradient(">>> Success!"))} Created ${r} at "${i.relative}"`)}function KM(t){let{copy:e,...r}=t,n=e===!0||typeof e=="string"?"copy":"empty",i=typeof e=="string"?e:"",s=typeof e=="string"&&e.startsWith("https://")?"external":"internal";return{method:n,copy:{type:s,source:i},...r}}async function Ws(t){let e=await Wu(t),r=KM(t);L.log();let n={project:e,opts:r};r.method==="copy"?(r.copy.type==="external"?L.info(`Copy a remote workspace from ${r.copy.source}`):L.info(`Copy an existing workspace from "${e.name}"`),L.log(),await pm(n)):(L.info(`Add an empty workspace to "${e.name}"`),L.log(),await hm(n))}async function zs(t,e){let r=await Wu(e);L.log(),L.info(`Modify "${r.name}" using custom generators`),L.log(),await am({generator:t,project:r,opts:e})}function dv(t){try{let e=JSON.parse(t),r={};for(let n in e){let i=nm(n,{to:"camel"});r[i]=e[n]}return r}catch(e){L.error("Error parsing arguments",e),process.exit(1)}}async function mm(t,e){var r;if(t==="workspace"){let n=dv(e.json);n.showAllDependencies=(r=n.showAllDependencies)!=null?r:!1;let i=!1,s=n.empty||!0;n.copy===""||n.copy===!0?(i=!0,s=!1):n.copy&&n.copy.length>0&&(i=n.copy,s=!1),n.copy=i,n.empty=s,await Ws(n)}else if(t==="run"){let n=dv(e.json),{generatorName:i,...s}=n;await zs(i,s)}else L.error(`Received unknown command - "${t}" (must be one of "workspace" | "run")`),process.exit(1)}var _v=new yv.ProxyAgent;pv.default.globalAgent=_v;mv.default.globalAgent=_v;var Vs=new qe.Command;Vs.name(gv.default.bold(L.turboGradient("@turbo/gen"))).description("Extend your Turborepo").version($s.version,"-v, --version","Output the current version").helpOption("-h, --help","Display help for command").showHelpAfterError(!1);Vs.command("run",{isDefault:!0}).alias("r").description("Run custom generators").addArgument(new qe.Argument("[generator-name]","The name of the generator to run")).addOption(new qe.Option("-c, --config <config>","Generator configuration file (default: turbo/generators/config.js")).addOption(new qe.Option("-r, --root <dir>","The root of your repository (default: directory with root turbo.json)")).addOption(new qe.Option("-a, --args <args...>","Arguments passed directly to generator").default([])).action(zs);Vs.command("workspace").aliases(["w"]).description("Add a new package or app to your project").addOption(new qe.Option("-n, --name <workspace-name>","Name for the new workspace")).addOption(new qe.Option("-b, --empty","Generate an empty workspace").conflicts("copy").default(!0)).addOption(new qe.Option("-c, --copy [source]",`Generate a workspace using an existing workspace as a template. Can be the name of a local workspace
66
66
  within your monorepo, or a fully qualified GitHub URL with any branch and/or subdirectory.
67
67
  `).conflicts("empty")).addOption(new qe.Option("-d, --destination <dir>","Where the new workspace should be created")).addOption(new qe.Option("-t, --type <type>","The type of workspace to create").choices(["app","package"])).addOption(new qe.Option("-r, --root <dir>","The root of your repository (default: directory with root turbo.json)")).addOption(new qe.Option("-p, --example-path <path-to-example>",`In a rare case, your GitHub URL might contain a branch name with
68
68
  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.0.5",
3
+ "version": "2.0.6-canary.0",
4
4
  "description": "Extend a Turborepo",
5
5
  "homepage": "https://turbo.build/repo",
6
6
  "license": "MIT",
@@ -25,7 +25,7 @@
25
25
  "ts-node": "^10.9.1",
26
26
  "update-check": "^1.5.4",
27
27
  "validate-npm-package-name": "^5.0.0",
28
- "@turbo/workspaces": "2.0.5"
28
+ "@turbo/workspaces": "2.0.6-canary.0"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@types/fs-extra": "^9.0.13",
@@ -39,8 +39,8 @@
39
39
  "typescript": "5.3.3",
40
40
  "@turbo/test-utils": "0.0.0",
41
41
  "@turbo/eslint-config": "0.0.0",
42
- "@turbo/utils": "0.0.0",
43
- "@turbo/tsconfig": "0.0.0"
42
+ "@turbo/tsconfig": "0.0.0",
43
+ "@turbo/utils": "0.0.0"
44
44
  },
45
45
  "files": [
46
46
  "dist"