@turbo/gen 2.0.7-canary.1 → 2.0.7
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/cli.js +1 -1
- package/package.json +4 -4
package/dist/cli.js
CHANGED
@@ -73,7 +73,7 @@ Please report this to https://github.com/szmarczak/http2-wrapper/`);b(_)}return}
|
|
73
73
|
`+e.slice(o+1):u+=e.slice(i),u.slice(1)}function E5(e){for(var t="",r=0,n,i=0;i<e.length;r>=65536?i+=2:i++)r=fs(e,i),n=Ge[r],!n&&ms(r)?(t+=e[i],r>=65536&&(t+=e[i+1])):t+=n||f5(r);return t}function w5(e,t,r){var n="",i=e.tag,s,o,a;for(s=0,o=r.length;s<o;s+=1)a=r[s],e.replacer&&(a=e.replacer.call(r,String(s),a)),(lr(e,t,a,!1,!1)||typeof a=="undefined"&&lr(e,t,null,!1,!1))&&(n!==""&&(n+=","+(e.condenseFlow?"":" ")),n+=e.dump);e.tag=i,e.dump="["+n+"]"}function fg(e,t,r,n){var i="",s=e.tag,o,a,u;for(o=0,a=r.length;o<a;o+=1)u=r[o],e.replacer&&(u=e.replacer.call(r,String(o),u)),(lr(e,t+1,u,!0,!0,!1,!0)||typeof u=="undefined"&&lr(e,t+1,null,!0,!0,!1,!0))&&((!n||i!=="")&&(i+=hl(e,t)),e.dump&&ds===e.dump.charCodeAt(0)?i+="-":i+="- ",i+=e.dump);e.tag=s,e.dump=i||"[]"}function v5(e,t,r){var n="",i=e.tag,s=Object.keys(r),o,a,u,c,l;for(o=0,a=s.length;o<a;o+=1)l="",n!==""&&(l+=", "),e.condenseFlow&&(l+='"'),u=s[o],c=r[u],e.replacer&&(c=e.replacer.call(r,u,c)),lr(e,t,u,!1,!1)&&(e.dump.length>1024&&(l+="? "),l+=e.dump+(e.condenseFlow?'"':"")+":"+(e.condenseFlow?"":" "),lr(e,t,c,!1,!1)&&(l+=e.dump,n+=l));e.tag=i,e.dump="{"+n+"}"}function A5(e,t,r,n){var i="",s=e.tag,o=Object.keys(r),a,u,c,l,f,h;if(e.sortKeys===!0)o.sort();else if(typeof e.sortKeys=="function")o.sort(e.sortKeys);else if(e.sortKeys)throw new rt("sortKeys must be a boolean or a function");for(a=0,u=o.length;a<u;a+=1)h="",(!n||i!=="")&&(h+=hl(e,t)),c=o[a],l=r[c],e.replacer&&(l=e.replacer.call(r,c,l)),lr(e,t+1,c,!0,!0,!0)&&(f=e.tag!==null&&e.tag!=="?"||e.dump&&e.dump.length>1024,f&&(e.dump&&ds===e.dump.charCodeAt(0)?h+="?":h+="? "),h+=e.dump,f&&(h+=hl(e,t)),lr(e,t+1,l,!0,f)&&(e.dump&&ds===e.dump.charCodeAt(0)?h+=":":h+=": ",h+=e.dump,i+=h));e.tag=s,e.dump=i||"{}"}function hg(e,t,r){var n,i,s,o,a,u;for(i=r?e.explicitTypes:e.implicitTypes,s=0,o=i.length;s<o;s+=1)if(a=i[s],(a.instanceOf||a.predicate)&&(!a.instanceOf||typeof t=="object"&&t instanceof a.instanceOf)&&(!a.predicate||a.predicate(t))){if(r?a.multi&&a.representName?e.tag=a.representName(t):e.tag=a.tag:e.tag="?",a.represent){if(u=e.styleMap[a.tag]||a.defaultStyle,Ug.call(a.represent)==="[object Function]")n=a.represent(t,u);else if(Gg.call(a.represent,u))n=a.represent[u](t,u);else throw new rt("!<"+a.tag+'> tag resolver accepts not "'+u+'" style');e.dump=n}return!0}return!1}function lr(e,t,r,n,i,s,o){e.tag=null,e.dump=r,hg(e,r,!1)||hg(e,r,!0);var a=Ug.call(e.dump),u=n,c;n&&(n=e.flowLevel<0||e.flowLevel>t);var l=a==="[object Object]"||a==="[object Array]",f,h;if(l&&(f=e.duplicates.indexOf(r),h=f!==-1),(e.tag!==null&&e.tag!=="?"||h||e.indent!==2&&t>0)&&(i=!1),h&&e.usedDuplicates[f])e.dump="*ref_"+f;else{if(l&&h&&!e.usedDuplicates[f]&&(e.usedDuplicates[f]=!0),a==="[object Object]")n&&Object.keys(e.dump).length!==0?(A5(e,t,e.dump,i),h&&(e.dump="&ref_"+f+e.dump)):(v5(e,t,e.dump),h&&(e.dump="&ref_"+f+" "+e.dump));else if(a==="[object Array]")n&&e.dump.length!==0?(e.noArrayIndent&&!o&&t>0?fg(e,t-1,e.dump,i):fg(e,t,e.dump,i),h&&(e.dump="&ref_"+f+e.dump)):(w5(e,t,e.dump),h&&(e.dump="&ref_"+f+" "+e.dump));else if(a==="[object String]")e.tag!=="?"&&_5(e,e.dump,t,s,u);else{if(a==="[object Undefined]")return!1;if(e.skipInvalid)return!1;throw new rt("unacceptable kind of an object to dump "+a)}e.tag!==null&&e.tag!=="?"&&(c=encodeURI(e.tag[0]==="!"?e.tag.slice(1):e.tag).replace(/!/g,"%21"),e.tag[0]==="!"?c="!"+c:c.slice(0,18)==="tag:yaml.org,2002:"?c="!!"+c.slice(18):c="!<"+c+">",e.dump=c+" "+e.dump)}return!0}function D5(e,t){var r=[],n=[],i,s;for(pl(e,r,n),i=0,s=n.length;i<s;i+=1)t.duplicates.push(r[n[i]]);t.usedDuplicates=new Array(s)}function pl(e,t,r){var n,i,s;if(e!==null&&typeof e=="object")if(i=t.indexOf(e),i!==-1)r.indexOf(i)===-1&&r.push(i);else if(t.push(e),Array.isArray(e))for(i=0,s=e.length;i<s;i+=1)pl(e[i],t,r);else for(n=Object.keys(e),i=0,s=n.length;i<s;i+=1)pl(e[n[i]],t,r)}function x5(e,t){t=t||{};var r=new d5(t);r.noRefs||D5(e,r);var n=e;return r.replacer&&(n=r.replacer.call({"":n},"",n)),lr(r,0,n,!0,!0)?r.dump+`
|
74
74
|
`:""}var C5=x5,S5={dump:C5};function El(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 R5=je,F5=mg,T5=bg,O5=Dg,k5=xg,P5=gl,B5=$g.load,I5=$g.loadAll,L5=S5.dump,N5=rt,M5={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},q5=El("safeLoad","load"),j5=El("safeLoadAll","loadAll"),H5=El("safeDump","dump"),$5={Type:R5,Schema:F5,FAILSAFE_SCHEMA:T5,JSON_SCHEMA:O5,CORE_SCHEMA:k5,DEFAULT_SCHEMA:P5,load:B5,loadAll:I5,dump:L5,YAMLException:N5,types:M5,safeLoad:q5,safeLoadAll:j5,safeDump:H5},ey=$5;var ow=re(H_());var L={};KS(L,{bold:()=>FB,dimmed:()=>OB,error:()=>Dt,grey:()=>kB,info:()=>RB,item:()=>PB,log:()=>pr,turboBlue:()=>mi,turboGradient:()=>SB,turboLoader:()=>Hh,turboRed:()=>iw,underline:()=>TB,warn:()=>$h,yellow:()=>sw});var ut=require("picocolors"),ew=re(CE()),tw=re(QE()),rw="#0099F7",nw="#F11712",CB="#FFFF00",jh=e=>{let t=BB(e);return r=>`\x1B[38;5;${t}m${r}${(0,ut.reset)("")}`},SB=(0,tw.default)(rw,nw),mi=jh(rw),iw=jh(nw),sw=jh(CB),Hh=e=>(0,ew.default)({text:e,spinner:{frames:[" ",mi("> "),mi(">> "),mi(">>>")]}}),RB=(...e)=>{pr(mi((0,ut.bold)(">>>")),e.join(" "))},FB=(...e)=>{pr((0,ut.bold)(e.join(" ")))},TB=(...e)=>{pr((0,ut.underline)(e.join(" ")))},OB=(...e)=>{pr((0,ut.dim)(e.join(" ")))},kB=(...e)=>{pr((0,ut.gray)(e.join(" ")))},PB=(...e)=>{pr(mi((0,ut.bold)(" \u2022")),e.join(" "))},pr=(...e)=>{console.log(...e)},$h=(...e)=>{console.error(sw((0,ut.bold)(">>>")),e.join(" "))},Dt=(...e)=>{console.error(iw((0,ut.bold)(">>>")),e.join(" "))};function BB(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 IB="turbo.json";var Uh={};function LB(e){try{if(Ts.default.existsSync(vn.default.join(e,"pnpm-workspace.yaml")))return ey.load(Ts.default.readFileSync(vn.default.join(e,"pnpm-workspace.yaml"),"utf8")).packages||[];let t=JSON.parse(Ts.default.readFileSync(vn.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 Gh(e,t){var s;let r=ls(e,t),n=[],i=(s=t==null?void 0:t.cache)!=null?s:!0;if(i&&e&&e in Uh)return Uh[e];if(r){let a=LB(r).map(c=>`${c}/turbo.json`);(0,ow.sync)([IB,...a],{cwd:r,onlyFiles:!0,followSymbolicLinks:!1,suppressErrors:!0}).map(c=>vn.default.join(r,c)).forEach(c=>{try{let l=Ts.default.readFileSync(c,"utf8"),f=Fo.parse(l),h=vn.default.dirname(c)===r;if(h){if("extends"in f)return}else if(!("extends"in f))return;n.push({config:f,turboConfigPath:c,workspacePath:vn.default.dirname(c),isRootConfig:h})}catch(l){$h(l)}})}return i&&e&&(Uh[e]=n),n}var FL=re(require("os")),TL=re(Pv());var Bv=re(require("fs-extra")),OL=[".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 Is(e){let t=Bv.default.readdirSync(e).filter(r=>!OL.includes(r)).filter(r=>!r.endsWith(".iml"));return{isEmpty:t.length===0,conflicts:t}}var ad=re(require("path")),ud=re(require("fs-extra")),cd=require("picocolors");function Va(e){let t=ad.default.resolve(e),r=ad.default.basename(t),n=ud.default.existsSync(t),i=ud.default.lstatSync(t,{throwIfNoEntry:!1});if(i&&!i.isDirectory())return{valid:!1,root:t,projectName:r,error:`${(0,cd.dim)(r)} is not a directory - please try a different location`};if(n){let{isEmpty:s,conflicts:o}=Is(t);if(!s)return{valid:!1,root:t,projectName:r,error:`${(0,cd.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 rS=require("stream"),nS=require("util"),iS=require("path"),sS=require("os"),ho=require("fs"),nm=re(Ox()),Sc=re(tS()),m9=(0,nS.promisify)(rS.Stream.pipeline);async function Cc(e){try{return(await Sc.default.head(e)).statusCode===200}catch{return!1}}async function im(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,Sc.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 sm({username:e,name:t,branch:r,filePath:n}){let i=`https://api.github.com/repos/${e}/${t}/contents`,s=`${n?`/${n}`:""}/package.json`;return Cc(`${i+s}?ref=${r}`)}function om(e){try{let t=new URL(e);return Cc(t.href)}catch{return Cc(`https://api.github.com/repos/vercel/turbo/contents/examples/${encodeURIComponent(e)}`)}}async function oS(e,t){let r=(0,iS.join)((0,sS.tmpdir)(),`${t}.temp-${Date.now()}`);return await m9(Sc.default.stream(e),(0,ho.createWriteStream)(r)),r}async function am(e,{username:t,name:r,branch:n,filePath:i}){let s=await oS(`https://codeload.github.com/${t}/${r}/tar.gz/${n}`,"turbo-ct-example");await(0,nm.x)({file:s,cwd:e,strip:i?i.split("/").length+1:1,filter:o=>o.startsWith(`${r}-${n.replace(/\//g,"-")}${i?`/${i}/`:"/"}`)}),await ho.promises.unlink(s)}async function um(e,t){let r=await oS("https://codeload.github.com/vercel/turbo/tar.gz/main","turbo-ct-example");await(0,nm.x)({file:r,cwd:e,strip:2+t.split("/").length,filter:n=>n.includes(`turbo-main/examples/${t}/`)}),await ho.promises.unlink(r)}var Rc=require("fs-extra");async function cm(e){try{return await(0,Rc.access)(e,Rc.constants.W_OK),!0}catch{return!1}}var ts=re(require("path")),lm=re(dS()),un=require("picocolors"),rs=require("fs-extra");function b9(e){return typeof e=="object"&&e!==null&&typeof e.message=="string"}var Fc=class extends Error{};async function fm({appPath:e,example:t,isDefaultExample:r,examplePath:n}){let i,s;if(r)i={username:"vercel",name:"turbo",branch:"main",filePath:"examples/basic"};else{try{s=new URL(t)}catch(p){p.code!=="ERR_INVALID_URL"&&(Dt(p),process.exit(1))}s?(s.origin!=="https://github.com"&&(Dt(`Invalid URL: ${(0,un.red)(`"${t}"`)}. Only GitHub repositories are supported. Please use a GitHub URL and try again.`),process.exit(1)),i=await im(s,n),i||(Dt(`Unable to fetch repository information from: ${(0,un.red)(`"${t}"`)}. Please fix the URL and try again.`),process.exit(1)),await sm(i)||(Dt(`Could not locate the repository for ${(0,un.red)(`"${t}"`)}. Please check that the repository exists and try again.`),process.exit(1))):await om(t)||(Dt(`Could not locate an example named ${(0,un.red)(`"${t}"`)}. It could be due to the following:
|
75
75
|
`,`1. Your spelling of example ${(0,un.red)(`"${t}"`)} might be incorrect.
|
76
|
-
`,"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 cm(ts.default.dirname(o))||(Dt("The application path is not writable, please check folder permissions and try again."),Dt("It is likely you do not have write permissions for this folder."),process.exit(1));let a=ts.default.basename(o);try{await(0,rs.mkdir)(o,{recursive:!0})}catch(p){Dt("Unable to create project directory"),Dt(p),process.exit(1)}let{isEmpty:u,conflicts:c}=Is(o);u||(Dt(`${(0,un.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),pr();let f=Hh("Downloading files... (This might take a moment)");try{!r&&i?(f.start(),await(0,lm.default)(()=>am(o,i),{retries:3})):(f.start(),await(0,lm.default)(()=>um(o,t),{retries:3}))}catch(p){throw new Fc(b9(p)?p.message:String(p))}finally{f.stop()}let h=ts.default.join(o,"package.json"),g=(0,rs.existsSync)(h),b=[];if(g){let p;try{p=(0,rs.readJsonSync)(h)}catch{}p&&b.push(...Object.keys(p.scripts||{}))}let _=e;return ts.default.join(l,a)===e&&(_=a),{cdPath:_,hasPackageJson:g,availableScripts:b,repoInfo:i}}function hm(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 $S=require("proxy-agent");var po={name:"@turbo/gen",version:"2.0.7-canary.1",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:*",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.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 Tc=require("picocolors"),pS=re(require("update-check"));var w9=(0,pS.default)(po).catch(()=>null);async function dm(){try{let e=await w9;e!=null&&e.latest&&(L.log(),L.log((0,Tc.yellow)((0,Tc.bold)(`A new version of \`${po.name}\` is available!`))),L.log()),process.exit()}catch{}}var mS=require("@turbo/workspaces");async function Oc({root:e}){let t=e||process.cwd(),r=ls(t);if(!r)L.error("Unable to infer repository root - override with --root");else try{return(0,mS.getWorkspaceDetails)({root:r})}catch{L.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 Or=re(require("path")),Pc=re(require("fs-extra")),kc=re(require("node-plop")),gS=require("ts-node"),yS=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 _S=["ts","js","cjs"],v9=Or.default.join("turbo","generators"),bS=_S.map(e=>Or.default.join(v9,`config.${e}`)),A9=[...bS,..._S.map(e=>Or.default.join(`plopfile.${e}`))];function ES({project:e,configPath:t}){(0,gS.register)({transpileOnly:!0,cwd:e.paths.root,compilerOptions:{module:"nodenext",moduleResolution:"nodenext"}});let r=x9({project:e}),n;if(t){if(!Pc.default.existsSync(t))throw new $e(`No config at "${t}"`,{type:"plop_no_config"});try{n=(0,kc.default)(t,{destBasePath:t,force:!1})}catch(i){L.error(i)}}else{for(let i of A9){let s=Or.default.join(e.paths.root,i);if(Pc.default.existsSync(s))try{n=(0,kc.default)(s,{destBasePath:e.paths.root,force:!1});break}catch(o){L.error(o)}}!n&&r.length>0&&(n=(0,kc.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 pm({project:e,configPath:t}){let r=ES({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(Or.default.sep);return f.pop(),f.pop(),Or.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 yS.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?cs({cwd:t.basePath,target:"package.json"}):void 0},n={};try{n=Gh(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 bS)Pc.default.existsSync(Or.default.join(r.paths.root,n))&&t.push({config:Or.default.join(r.paths.root,n),root:r.paths.root})}),t}async function wS({project:e,generator:t,bypassArgs:r,configPath:n}){let i=ES({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=>{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 $e(`Failed to run "${t}" 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 Mn=require("inquirer");async function vS({generators:e,generator:t}){if(t){if(e.find(n=>!(n instanceof Mn.Separator)&&n.name===t))return{selectedGenerator:t};L.warn(`Generator "${t}" not found`),L.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 AS(){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 DS({message:e}){return(0,Mn.prompt)({type:"confirm",name:"answer",message:e})}var mm=re(require("path")),Bc=require("fs-extra");async function xS({project:e,template:t}){let r=mm.default.join(e.paths.root,"turbo","generators"),n=`simple-${t}`;if(await(0,Bc.pathExists)(r))throw new $e(`Generator config directory already exists at ${r}`,{type:"config_directory_already_exists"});await(0,Bc.copy)(mm.default.join(__dirname,"templates",n),r,{recursive:!0})}async function gm({generator:e,project:t,opts:r}){let n=!1,i=pm({project:t,configPath:r.config});if(!i.length){L.error("No generators found."),L.log();let{answer:o}=await DS({message:`Would you like to add a config with a sample custom generator to ${t.name}?`});if(o){n=!0;let{answer:a}=await AS();try{await xS({project:t,template:a})}catch(u){throw u instanceof $e||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=pm({project:t,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 vS({generators:i,generator:e});try{await wS({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&&(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 Em=re(require("path")),go=require("fs-extra"),LS=require("picocolors");var mo=re(require("path")),FS=require("fs-extra"),Bt=require("inquirer"),TS=require("minimatch"),bm=re(require("validate-npm-package-name"));var ym=re(require("path"));var CS=re(require("path"));function SS({project:e}){let r=e.workspaceData.workspaces.map(i=>CS.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 Ic({project:e}){let t=SS({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 RS=require("inquirer");function Lc({project:e,type:t,showAllDependencies:r}){let n=Ic({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 RS.Separator(u)),o=u,i.push(a)}),i}async function OS({override:e,suggestion:t,workspaceType:r}){let{validForNewPackages:n}=(0,bm.default)(e||"");return e&&n?{answer:e}:(0,Bt.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 kS({override:e,message:t}){return e?{answer:e}:(0,Bt.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 PS({workspaceType:e,workspaceName:t,destination:r,project:n}){let i=t.includes("/")?t.split("/")[1]:t;if(r){let{valid:u,root:c}=Va(r);if(u)return{absolute:c,relative:mo.default.relative(n.paths.root,c)}}let s,o=Ic({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,Bt.prompt)({type:"input",name:"answer",message:`Where should "${t}" be added?`,default:s?mo.default.relative(n.paths.root,s):void 0,validate:u=>{let c=mo.default.join(n.paths.root,u),{valid:l,error:f}=Va(c),h=n.workspaceData.globs.some(g=>(0,TS.minimatch)(u,g));return l&&h?!0:h?f:`${u} is not a valid workspace location`}});return{absolute:mo.default.join(n.paths.root,a),relative:a}}async function BS({override:e,workspaces:t,workspaceName:r}){if(e){let i=t.find(s=>s instanceof Bt.Separator?!1:s.name===e);if(i)return{answer:i};L.warn(`Workspace "${e}" not found`),L.log()}return await(0,Bt.prompt)({type:"list",name:"answer",loop:!1,pageSize:25,message:`Which workspace should "${r}" start from?`,choices:t.map(i=>i instanceof Bt.Separator?i:{name:` ${i.name}`,value:i})})}async function IS({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,Bt.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=Lc({project:t,type:"package",showAllDependencies:n}),u=r?(0,FS.readJsonSync)(r.paths.packageJson):void 0;for(let c of o){let{answer:l}=await(0,Bt.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 Bt.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(g=>{h.has(g)||(f[g]=t.packageManager==="pnpm"?"workspace:*":"*")}),i[c]=f}else i[c]=l.reduce((h,g)=>({...h,[g]:t.packageManager==="pnpm"?"workspace:*":"*"}),{})}return i}async function S9({message:e}){return(0,Bt.prompt)({type:"confirm",name:"answer",message:e})}async function Nc({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 kS({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 OS({override:t.name,workspaceType:i,suggestion:n});if(t.method==="copy"&&t.copy.type==="internal"){let{answer:c}=await BS({override:t.copy.source,workspaces:Lc({project:e,type:i}),workspaceName:s});r=c}let o=await PS({workspaceType:i,workspaceName:s,project:e,destination:t.destination}),a=await IS({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 Nc({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)}),(0,go.mkdirSync)(n.absolute,{recursive:!0}),(0,go.writeFileSync)(Em.default.join(n.absolute,"package.json"),JSON.stringify(s,null,2)),(0,go.writeFileSync)(Em.default.join(n.absolute,"README.md"),`# \`${r}\``),L.log(),L.log(`${(0,LS.bold)(L.turboGradient(">>> Success!"))} Created ${r} at "${n.relative}"`)}var vm=re(require("path")),It=require("fs-extra"),NS=require("picocolors");async function Am({project:e,opts:t}){let{name:r,type:n,location:i,source:s,dependencies:o}=await Nc({project:e,opts:t}),a=vm.default.join(i.absolute,"package.json");if(t.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 fm({appPath:i.absolute,example:t.copy.source,examplePath:t.examplePath});try{if((0,It.existsSync)(a)){if((await(0,It.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,It.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),L.error(l),await(0,It.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,It.copy)(s.paths.root,i.absolute,{filter:c}),l.stop()}let u=await(0,It.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,It.writeJSON)(a,u,{spaces:2}),L.log(),L.log(`${(0,NS.bold)(L.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 yo(e){let t=await Oc(e),r=F9(e);L.log();let n={project:t,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 "${t.name}"`),L.log(),await Am(n)):(L.info(`Add an empty workspace to "${t.name}"`),L.log(),await wm(n))}async function _o(e,t){let r=await Oc(t);L.log(),L.info(`Modify "${r.name}" using custom generators`),L.log(),await gm({generator:e,project:r,opts:t})}function MS(e){try{let t=JSON.parse(e),r={};for(let n in t){let i=hm(n,{to:"camel"});r[i]=t[n]}return r}catch(t){L.error("Error parsing arguments",t),process.exit(1)}}async function Dm(e,t){var r;if(e==="workspace"){let n=MS(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 yo(n)}else if(e==="run"){let n=MS(t.json),{generatorName:i,...s}=n;await _o(i,s)}else L.error(`Received unknown command - "${e}" (must be one of "workspace" | "run")`),process.exit(1)}var US=new $S.ProxyAgent;qS.default.globalAgent=US;jS.default.globalAgent=US;var bo=new Ue.Command;bo.name((0,HS.bold)(L.turboGradient("@turbo/gen"))).description("Extend your Turborepo").version(po.version,"-v, --version","Output the current version").helpOption("-h, --help","Display help for command").showHelpAfterError(!1);bo.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(_o);bo.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
|
76
|
+
`,"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 cm(ts.default.dirname(o))||(Dt("The application path is not writable, please check folder permissions and try again."),Dt("It is likely you do not have write permissions for this folder."),process.exit(1));let a=ts.default.basename(o);try{await(0,rs.mkdir)(o,{recursive:!0})}catch(p){Dt("Unable to create project directory"),Dt(p),process.exit(1)}let{isEmpty:u,conflicts:c}=Is(o);u||(Dt(`${(0,un.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),pr();let f=Hh("Downloading files... (This might take a moment)");try{!r&&i?(f.start(),await(0,lm.default)(()=>am(o,i),{retries:3})):(f.start(),await(0,lm.default)(()=>um(o,t),{retries:3}))}catch(p){throw new Fc(b9(p)?p.message:String(p))}finally{f.stop()}let h=ts.default.join(o,"package.json"),g=(0,rs.existsSync)(h),b=[];if(g){let p;try{p=(0,rs.readJsonSync)(h)}catch{}p&&b.push(...Object.keys(p.scripts||{}))}let _=e;return ts.default.join(l,a)===e&&(_=a),{cdPath:_,hasPackageJson:g,availableScripts:b,repoInfo:i}}function hm(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 $S=require("proxy-agent");var po={name:"@turbo/gen",version:"2.0.7",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:*",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.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 Tc=require("picocolors"),pS=re(require("update-check"));var w9=(0,pS.default)(po).catch(()=>null);async function dm(){try{let e=await w9;e!=null&&e.latest&&(L.log(),L.log((0,Tc.yellow)((0,Tc.bold)(`A new version of \`${po.name}\` is available!`))),L.log()),process.exit()}catch{}}var mS=require("@turbo/workspaces");async function Oc({root:e}){let t=e||process.cwd(),r=ls(t);if(!r)L.error("Unable to infer repository root - override with --root");else try{return(0,mS.getWorkspaceDetails)({root:r})}catch{L.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 Or=re(require("path")),Pc=re(require("fs-extra")),kc=re(require("node-plop")),gS=require("ts-node"),yS=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 _S=["ts","js","cjs"],v9=Or.default.join("turbo","generators"),bS=_S.map(e=>Or.default.join(v9,`config.${e}`)),A9=[...bS,..._S.map(e=>Or.default.join(`plopfile.${e}`))];function ES({project:e,configPath:t}){(0,gS.register)({transpileOnly:!0,cwd:e.paths.root,compilerOptions:{module:"nodenext",moduleResolution:"nodenext"}});let r=x9({project:e}),n;if(t){if(!Pc.default.existsSync(t))throw new $e(`No config at "${t}"`,{type:"plop_no_config"});try{n=(0,kc.default)(t,{destBasePath:t,force:!1})}catch(i){L.error(i)}}else{for(let i of A9){let s=Or.default.join(e.paths.root,i);if(Pc.default.existsSync(s))try{n=(0,kc.default)(s,{destBasePath:e.paths.root,force:!1});break}catch(o){L.error(o)}}!n&&r.length>0&&(n=(0,kc.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 pm({project:e,configPath:t}){let r=ES({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(Or.default.sep);return f.pop(),f.pop(),Or.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 yS.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?cs({cwd:t.basePath,target:"package.json"}):void 0},n={};try{n=Gh(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 bS)Pc.default.existsSync(Or.default.join(r.paths.root,n))&&t.push({config:Or.default.join(r.paths.root,n),root:r.paths.root})}),t}async function wS({project:e,generator:t,bypassArgs:r,configPath:n}){let i=ES({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=>{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 $e(`Failed to run "${t}" 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 Mn=require("inquirer");async function vS({generators:e,generator:t}){if(t){if(e.find(n=>!(n instanceof Mn.Separator)&&n.name===t))return{selectedGenerator:t};L.warn(`Generator "${t}" not found`),L.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 AS(){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 DS({message:e}){return(0,Mn.prompt)({type:"confirm",name:"answer",message:e})}var mm=re(require("path")),Bc=require("fs-extra");async function xS({project:e,template:t}){let r=mm.default.join(e.paths.root,"turbo","generators"),n=`simple-${t}`;if(await(0,Bc.pathExists)(r))throw new $e(`Generator config directory already exists at ${r}`,{type:"config_directory_already_exists"});await(0,Bc.copy)(mm.default.join(__dirname,"templates",n),r,{recursive:!0})}async function gm({generator:e,project:t,opts:r}){let n=!1,i=pm({project:t,configPath:r.config});if(!i.length){L.error("No generators found."),L.log();let{answer:o}=await DS({message:`Would you like to add a config with a sample custom generator to ${t.name}?`});if(o){n=!0;let{answer:a}=await AS();try{await xS({project:t,template:a})}catch(u){throw u instanceof $e||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=pm({project:t,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 vS({generators:i,generator:e});try{await wS({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&&(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 Em=re(require("path")),go=require("fs-extra"),LS=require("picocolors");var mo=re(require("path")),FS=require("fs-extra"),Bt=require("inquirer"),TS=require("minimatch"),bm=re(require("validate-npm-package-name"));var ym=re(require("path"));var CS=re(require("path"));function SS({project:e}){let r=e.workspaceData.workspaces.map(i=>CS.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 Ic({project:e}){let t=SS({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 RS=require("inquirer");function Lc({project:e,type:t,showAllDependencies:r}){let n=Ic({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 RS.Separator(u)),o=u,i.push(a)}),i}async function OS({override:e,suggestion:t,workspaceType:r}){let{validForNewPackages:n}=(0,bm.default)(e||"");return e&&n?{answer:e}:(0,Bt.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 kS({override:e,message:t}){return e?{answer:e}:(0,Bt.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 PS({workspaceType:e,workspaceName:t,destination:r,project:n}){let i=t.includes("/")?t.split("/")[1]:t;if(r){let{valid:u,root:c}=Va(r);if(u)return{absolute:c,relative:mo.default.relative(n.paths.root,c)}}let s,o=Ic({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,Bt.prompt)({type:"input",name:"answer",message:`Where should "${t}" be added?`,default:s?mo.default.relative(n.paths.root,s):void 0,validate:u=>{let c=mo.default.join(n.paths.root,u),{valid:l,error:f}=Va(c),h=n.workspaceData.globs.some(g=>(0,TS.minimatch)(u,g));return l&&h?!0:h?f:`${u} is not a valid workspace location`}});return{absolute:mo.default.join(n.paths.root,a),relative:a}}async function BS({override:e,workspaces:t,workspaceName:r}){if(e){let i=t.find(s=>s instanceof Bt.Separator?!1:s.name===e);if(i)return{answer:i};L.warn(`Workspace "${e}" not found`),L.log()}return await(0,Bt.prompt)({type:"list",name:"answer",loop:!1,pageSize:25,message:`Which workspace should "${r}" start from?`,choices:t.map(i=>i instanceof Bt.Separator?i:{name:` ${i.name}`,value:i})})}async function IS({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,Bt.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=Lc({project:t,type:"package",showAllDependencies:n}),u=r?(0,FS.readJsonSync)(r.paths.packageJson):void 0;for(let c of o){let{answer:l}=await(0,Bt.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 Bt.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(g=>{h.has(g)||(f[g]=t.packageManager==="pnpm"?"workspace:*":"*")}),i[c]=f}else i[c]=l.reduce((h,g)=>({...h,[g]:t.packageManager==="pnpm"?"workspace:*":"*"}),{})}return i}async function S9({message:e}){return(0,Bt.prompt)({type:"confirm",name:"answer",message:e})}async function Nc({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 kS({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 OS({override:t.name,workspaceType:i,suggestion:n});if(t.method==="copy"&&t.copy.type==="internal"){let{answer:c}=await BS({override:t.copy.source,workspaces:Lc({project:e,type:i}),workspaceName:s});r=c}let o=await PS({workspaceType:i,workspaceName:s,project:e,destination:t.destination}),a=await IS({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 Nc({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)}),(0,go.mkdirSync)(n.absolute,{recursive:!0}),(0,go.writeFileSync)(Em.default.join(n.absolute,"package.json"),JSON.stringify(s,null,2)),(0,go.writeFileSync)(Em.default.join(n.absolute,"README.md"),`# \`${r}\``),L.log(),L.log(`${(0,LS.bold)(L.turboGradient(">>> Success!"))} Created ${r} at "${n.relative}"`)}var vm=re(require("path")),It=require("fs-extra"),NS=require("picocolors");async function Am({project:e,opts:t}){let{name:r,type:n,location:i,source:s,dependencies:o}=await Nc({project:e,opts:t}),a=vm.default.join(i.absolute,"package.json");if(t.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 fm({appPath:i.absolute,example:t.copy.source,examplePath:t.examplePath});try{if((0,It.existsSync)(a)){if((await(0,It.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,It.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),L.error(l),await(0,It.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,It.copy)(s.paths.root,i.absolute,{filter:c}),l.stop()}let u=await(0,It.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,It.writeJSON)(a,u,{spaces:2}),L.log(),L.log(`${(0,NS.bold)(L.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 yo(e){let t=await Oc(e),r=F9(e);L.log();let n={project:t,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 "${t.name}"`),L.log(),await Am(n)):(L.info(`Add an empty workspace to "${t.name}"`),L.log(),await wm(n))}async function _o(e,t){let r=await Oc(t);L.log(),L.info(`Modify "${r.name}" using custom generators`),L.log(),await gm({generator:e,project:r,opts:t})}function MS(e){try{let t=JSON.parse(e),r={};for(let n in t){let i=hm(n,{to:"camel"});r[i]=t[n]}return r}catch(t){L.error("Error parsing arguments",t),process.exit(1)}}async function Dm(e,t){var r;if(e==="workspace"){let n=MS(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 yo(n)}else if(e==="run"){let n=MS(t.json),{generatorName:i,...s}=n;await _o(i,s)}else L.error(`Received unknown command - "${e}" (must be one of "workspace" | "run")`),process.exit(1)}var US=new $S.ProxyAgent;qS.default.globalAgent=US;jS.default.globalAgent=US;var bo=new Ue.Command;bo.name((0,HS.bold)(L.turboGradient("@turbo/gen"))).description("Extend your Turborepo").version(po.version,"-v, --version","Output the current version").helpOption("-h, --help","Display help for command").showHelpAfterError(!1);bo.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(_o);bo.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
77
|
within your monorepo, or a fully qualified GitHub URL with any branch and/or subdirectory.
|
78
78
|
`).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
|
79
79
|
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.7
|
3
|
+
"version": "2.0.7",
|
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.7
|
28
|
+
"@turbo/workspaces": "2.0.7"
|
29
29
|
},
|
30
30
|
"devDependencies": {
|
31
31
|
"@types/fs-extra": "^9.0.13",
|
@@ -37,10 +37,10 @@
|
|
37
37
|
"ts-jest": "^27.1.1",
|
38
38
|
"tsup": "^6.7.0",
|
39
39
|
"typescript": "5.3.3",
|
40
|
-
"@turbo/eslint-config": "0.0.0",
|
41
40
|
"@turbo/test-utils": "0.0.0",
|
41
|
+
"@turbo/tsconfig": "0.0.0",
|
42
42
|
"@turbo/utils": "0.0.0",
|
43
|
-
"@turbo/
|
43
|
+
"@turbo/eslint-config": "0.0.0"
|
44
44
|
},
|
45
45
|
"files": [
|
46
46
|
"dist"
|