@turbo/gen 2.8.2-canary.0 → 2.8.2-canary.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +1 -1
- package/package.json +4 -4
package/dist/cli.js
CHANGED
|
@@ -114,7 +114,7 @@ ${s}`;break;case"retry":eO(s)&&(n[i]=s);break;case"id":tO(s)&&(n[i]=s);break;cas
|
|
|
114
114
|
Please use either turbo.json or turbo.jsonc, but not both.`;throw mt(d),new Error(d)}let h=l[0];try{let d=Lu.default.readFileSync(h,"utf8"),f=Tl.parse(d),g=WA.default.dirname(h)===r;if(g){if("extends"in f)continue}else if(!("extends"in f))continue;n.push({config:f,turboConfigPath:h,workspacePath:WA.default.dirname(h),isRootConfig:g})}catch(d){po(d)}}}return A&&e&&(xQ[e]=n),n}var K6=ue(require("os")),X6=ue(U2());var _2=ue(require("fs-extra")),$6=[".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 Ou(e){let t=_2.default.readdirSync(e).filter(r=>!$6.includes(r)).filter(r=>!r.endsWith(".iml"));return{isEmpty:t.length===0,conflicts:t}}var zQ=ue(require("path")),ZQ=ue(require("fs-extra")),Hu=ue(require("picocolors"));function eg(e){if(!e||typeof e!="string"||e.trim()===""||e.includes("\0")){let o=typeof e=="string"?e:"";return{valid:!1,root:"",projectName:"",error:`${Hu.default.dim(o||"<empty>")} is not a valid directory name - please try a different location`}}let t=zQ.default.resolve(e),r=zQ.default.basename(t),n=!t||t.startsWith("-")||t.includes("\0"),A=!r||!/^[a-zA-Z0-9._-]+$/.test(r);if(n||A)return{valid:!1,root:t,projectName:r,error:`${Hu.default.dim(r||t||"<unknown>")} is not a valid directory - please try a different location`};let i=ZQ.default.existsSync(t),s=ZQ.default.lstatSync(t,{throwIfNoEntry:!1});if(s&&!s.isDirectory())return{valid:!1,root:t,projectName:r,error:`${Hu.default.dim(r)} is not a directory - please try a different location`};if(i){let{isEmpty:o,conflicts:a}=Ou(t);if(!o)return{valid:!1,root:t,projectName:r,error:`${Hu.default.dim(r)} (${t}) has ${a.length} conflicting ${a.length===1?"file":"files"} - please try a different location`}}return{valid:!0,root:t,projectName:r}}var QO=require("stream"),IO=require("stream/promises"),pO=require("zlib"),Wn=require("fs"),CC=require("fs/promises"),$t=require("path"),mO=require("os"),fC=require("child_process"),dC=ue(Tv()),yO=ue(CO());var fue=1e4,wO=12e4;function DO(e){return new URL(e).protocol==="https:"?process.env.https_proxy||process.env.HTTPS_PROXY||process.env.http_proxy||process.env.HTTP_PROXY:process.env.http_proxy||process.env.HTTP_PROXY}var gC,dO;function bO(e){return gC&&dO===e||(dO=e,gC=new yO.ProxyAgent(e)),gC}async function rw(e,t={},r=fue){let n=new AbortController,A=setTimeout(()=>{n.abort()},r);try{let i=DO(e),s=i?bO(i):void 0;return await fetch(e,{...t,signal:n.signal,dispatcher:s})}finally{clearTimeout(A)}}async function EC(e){try{return(await rw(e,{method:"HEAD"})).ok}catch{return!1}}async function nw(e,t){let[,r,n,A,i,...s]=e.pathname.split("/"),o=t?t.replace(/^\//,""):s.join("/");if(A===void 0||A===""&&i===void 0)try{let u=await rw(`https://api.github.com/repos/${r}/${n}`);if(!u.ok)return;let c=await u.json();return{username:r,name:n,branch:c.default_branch,filePath:o}}catch{return}let a=t?`${i}/${s.join("/")}`.replace(new RegExp(`/${o}|/$`),""):i;if(r&&n&&a&&A==="tree")return{username:r,name:n,branch:a,filePath:o}}function Aw({username:e,name:t,branch:r,filePath:n}){let A=`https://api.github.com/repos/${e}/${t}/contents`,i=`${n?`/${n}`:""}/package.json`;return EC(`${A+i}?ref=${r}`)}function iw(e){try{let t=new URL(e);return EC(t.href)}catch{return EC(`https://api.github.com/repos/vercel/turborepo/contents/examples/${encodeURIComponent(e)}`)}}function Eue(e,t,r){if(t.includes("\0"))return!1;let A=t.replace(/\\/g,"/").normalize("NFC"),i=r!=null?r:(0,$t.resolve)(e),s=(0,$t.resolve)(i,A);return!(0,$t.relative)(i,s).startsWith("..")&&(0,$t.resolve)(s)===s}function Cue(e){return e==="SymbolicLink"||e==="Link"}async function due({url:e,root:t,strip:r,filter:n}){let A=new AbortController,i=setTimeout(()=>{A.abort()},wO),s=[],o=(0,$t.resolve)(t),a=new Set;try{let u=DO(e),c=u?bO(u):void 0,l=await fetch(e,{signal:A.signal,dispatcher:c});if(!l.ok||!l.body)throw new Error(`Failed to download: ${l.status}`);let h=QO.Readable.fromWeb(l.body),d=null,f=[],g=new dC.Parse({filter:p=>{if(d===null){let Q=p.split("/");d=Q.length?Q[0]:null}return n(p,d)},onentry:p=>{let w=p.path.split("/").slice(r).join("/");if(!w){p.resume();return}if(!Eue(t,w,o)){mt(`Blocked path traversal attempt: ${p.path}`),p.resume();return}if(p.type&&Cue(p.type)){po(`Blocked symlink: ${p.path}`),p.resume();return}let S=(0,$t.resolve)(o,w);if(p.type==="Directory")a.has(S)||((0,Wn.mkdirSync)(S,{recursive:!0}),a.add(S)),p.resume();else if(p.type==="File"){let D=(0,$t.dirname)(S);a.has(D)||((0,Wn.mkdirSync)(D,{recursive:!0}),a.add(D));let b=(0,Wn.createWriteStream)(S);s.push(b),f.push(new Promise((H,U)=>{b.on("finish",H),b.on("error",U)})),p.pipe(b)}else p.resume()}});await(0,IO.pipeline)(h,(0,pO.createGunzip)(),g),await Promise.all(f)}finally{clearTimeout(i);for(let u of s)u.destroy()}}async function sw(e,{username:t,name:r,branch:n,filePath:A}){let i=`https://codeload.github.com/${t}/${r}/tar.gz/${n}`,s=(0,$t.join)((0,mO.tmpdir)(),`turbo-download-${Date.now()}.tar.gz`),o=await rw(i,{},wO);if(!o.ok||!o.body)throw new Error(`Failed to download: ${o.status}`);let a=Buffer.from(await o.arrayBuffer());await(0,CC.writeFile)(s,a);let u=null;try{await(0,dC.extract)({file:s,cwd:e,strip:A?A.split("/").length+1:1,filter:c=>{if(u===null){let l=c.split("/");u=l.length?l[0]:null}return c.startsWith(`${u}${A?`/${A}/`:"/"}`)}})}finally{await(0,CC.unlink)(s)}}function BO(e,t){if(!e||typeof e!="string"||e.includes("\0")||e.startsWith("-"))throw new Error(`Invalid ${t}: path must be a non-empty string without NUL bytes and cannot start with "-"`)}async function ow(e,t){if(!t||!/^[a-zA-Z0-9_-]+$/.test(t))throw new Error(`Invalid example name: ${t}`);let r=(0,$t.resolve)(e);BO(r,"project root");let n=(0,$t.join)(r,".turbo-clone-temp");BO(n,"temporary directory");try{(0,fC.execFileSync)("git",["clone","--filter=blob:none","--no-checkout","--depth","1","--sparse","https://github.com/vercel/turborepo.git",n],{stdio:"pipe"}),(0,fC.execFileSync)("git",["sparse-checkout","set",`examples/${t}`],{cwd:n,stdio:"pipe"}),(0,fC.execFileSync)("git",["checkout"],{cwd:n,stdio:"pipe"});let A=(0,$t.join)(n,"examples",t);(0,Wn.cpSync)(A,r,{recursive:!0})}catch{(0,Wn.rmSync)(n,{recursive:!0,force:!0}),po(`Git is not available. Downloading example via tarball (slower).
|
|
115
115
|
For faster downloads, install git: https://git-scm.com/downloads`),await due({url:"https://codeload.github.com/vercel/turborepo/tar.gz/main",root:r,strip:3,filter:(i,s)=>i.startsWith(`${s}/examples/${t}/`)});return}(0,Wn.rmSync)(n,{recursive:!0,force:!0})}var aw=ue(require("fs-extra"));async function uw(e){try{return await aw.default.access(e,aw.default.constants.W_OK),!0}catch{return!1}}var au=ue(require("path")),cw=ue(vO()),Os=ue(require("picocolors")),BC=ue(require("fs-extra"));function pue(e){return typeof e=="object"&&e!==null&&typeof e.message=="string"}var QC=class extends Error{};function mue(e){return e.hostname==="github.com"}async function lw({appPath:e,example:t,isDefaultExample:r,examplePath:n}){let A,i;nr();let s=kQ("Downloading files...");s.start();try{if(!r){try{i=new URL(t)}catch(p){p.code!=="ERR_INVALID_URL"&&(s.stop(),mt(p),process.exit(1))}i?(mue(i)||(s.stop(),mt(`Invalid URL: ${Os.default.red(`"${t}"`)}. Only GitHub repositories are supported. Please use a GitHub URL and try again.`),process.exit(1)),A=await nw(i,n),A||(s.stop(),mt(`Unable to fetch repository information from: ${Os.default.red(`"${t}"`)}. Please fix the URL and try again.`),process.exit(1)),await Aw(A)||(s.stop(),mt(`Could not locate the repository for ${Os.default.red(`"${t}"`)}. Please check that the repository exists and try again.`),process.exit(1))):(await iw(t)||(s.stop(),mt(`Could not locate an example named ${Os.default.red(`"${t}"`)}. It could be due to the following:
|
|
116
116
|
`,`1. Your spelling of example ${Os.default.red(`"${t}"`)} might be incorrect.
|
|
117
|
-
`,"2. You might not be connected to the internet or you are behind a proxy."),process.exit(1)),A={username:"vercel",name:"turborepo",branch:"main",filePath:`examples/${t}`})}let o=au.default.resolve(e);await uw(au.default.dirname(o))||(s.stop(),mt("The application path is not writable, please check folder permissions and try again."),mt("It is likely you do not have write permissions for this folder."),process.exit(1));let a=au.default.basename(o);try{await BC.default.mkdir(o,{recursive:!0})}catch(p){s.stop(),mt("Unable to create project directory"),mt(p),process.exit(1)}let{isEmpty:u,conflicts:c}=Ou(o);u||(s.stop(),mt(`${Os.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),r||A?await(0,cw.default)(()=>sw(o,A!=null?A:{username:"vercel",name:"turborepo",branch:"main",filePath:"examples/basic"}),{retries:3}):await(0,cw.default)(()=>ow(o,t),{retries:3}),s.stop();let h=au.default.join(o,"package.json"),d=BC.default.existsSync(h),f=[];if(d){let p;try{p=BC.default.readJsonSync(h)}catch{}p&&f.push(...Object.keys(p.scripts||{}))}let g=e;return au.default.join(l,a)===e&&(g=a),{cdPath:g,hasPackageJson:d,availableScripts:f,repoInfo:A}}catch(o){throw s.stop(),new QC(pue(o)?o.message:String(o))}}function hw(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 IC=ue(require("picocolors")),MO=ue(require("update-check"));function gw(e){let{packageInfo:t,upgradeCommand:r}=e,n=(0,MO.default)(t).catch(()=>null);return async function(i=0){try{let s=await n;if(s!=null&&s.latest){nr(),nr(IC.default.yellow(IC.default.bold(`A new version of \`${t.name}\` is available!`)));let o=typeof r=="function"?await r():r;o&&nr(`You can update by running: ${IC.default.cyan(o)}`),nr()}process.exit(i)}catch(s){process.env.DEBUG&&mt("Update check failed:",s),process.exit(i)}}}var uH=require("proxy-agent");var fw={name:"@turbo/gen",version:"2.8.2-canary.0",description:"Extend a Turborepo",type:"commonjs",homepage:"https://turborepo.dev",license:"MIT",repository:{type:"git",url:"git+https://github.com/vercel/turborepo.git",directory:"packages/turbo-gen"},bugs:{url:"https://github.com/vercel/turborepo/issues"},bin:"dist/cli.js",types:"dist/types.d.ts",scripts:{build:"tsup",test:"jest","check-types":"tsc --noEmit","package:types":"attw --profile node16 --pack"},dependencies:{"@turbo/workspaces":"workspace:*",commander:"10.0.0","fs-extra":"10.1.0",inquirer:"8.2.4",minimatch:"9.0.0","node-plop":"0.26.3",picocolors:"1.0.1","proxy-agent":"6.5.0","ts-node":"10.9.2","update-check":"1.5.4","validate-npm-package-name":"5.0.0"},devDependencies:{"@arethetypeswrong/cli":"0.18.2","@jest/globals":"29.7.0","@turbo/test-utils":"workspace:*","@turbo/tsconfig":"workspace:*","@turbo/utils":"workspace:*","@types/fs-extra":"9.0.13","@types/inquirer":"8.2.5","@types/node":"18.17.4","@types/validate-npm-package-name":"4.0.0",jest:"29.7.0","ts-jest":"29.2.5",tsup:"6.7.0",typescript:"5.5.4"},files:["dist"],publishConfig:{access:"public"}};var TO=require("@turbo/workspaces");async function pC({root:e}){let t=e||process.cwd(),r=Cu(t);if(!r)P.error("Unable to infer repository root - override with --root");else try{return(0,TO.getWorkspaceDetails)({root:r})}catch{P.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 MA=ue(require("path")),yC=ue(require("fs-extra")),mC=ue(require("node-plop")),LO=require("ts-node"),UO=require("inquirer");var Nt=class extends Error{constructor(r,n){var A;super(r);this.name="GenerateError",this.type=(A=n==null?void 0:n.type)!=null?A:"unknown",Error.captureStackTrace(this,Nt)}};var _O=["ts","js","cjs"],wue=MA.default.join("turbo","generators"),GO=_O.map(e=>MA.default.join(wue,`config.${e}`)),Due=[...GO,..._O.map(e=>MA.default.join(`plopfile.${e}`))];function YO({project:e,configPath:t}){(0,LO.register)({transpileOnly:!0,cwd:e.paths.root,compilerOptions:{module:"nodenext",moduleResolution:"nodenext"}});let r=Fue({project:e}),n;if(t){if(!yC.default.existsSync(t))throw new Nt(`No config at "${t}"`,{type:"plop_no_config"});try{n=(0,mC.default)(t,{destBasePath:t,force:!1})}catch(A){P.error(A)}}else{for(let A of Due){let i=MA.default.join(e.paths.root,A);if(yC.default.existsSync(i))try{n=(0,mC.default)(i,{destBasePath:e.paths.root,force:!1});break}catch(s){P.error(s)}}!n&&r.length>0&&(n=(0,mC.default)(r[0].config,{destBasePath:r[0].root,force:!1}),r.shift())}return n&&r.forEach(A=>{try{n.load(A.config,{destBasePath:A.root,force:!1})}catch(i){P.error(i)}}),n}function Ew({project:e,configPath:t}){let r=YO({project:e,configPath:t});if(!r)return[];let A=r.getGeneratorList().map(o=>r.getGenerator(o.name)),i={};A.forEach(o=>{let a=o,u=e.workspaceData.workspaces.find(c=>{if(a.basePath===e.paths.root)return!1;let l=a.basePath.split(MA.default.sep);return l.pop(),l.pop(),MA.default.join("/",...l)===c.paths.root});u?(u.name in i||(i[u.name]=[]),i[u.name].push(a)):("root"in i||(i.root=[]),i.root.push(a))});let s=[];return Object.keys(i).forEach(o=>{s.push(new UO.Separator(o)),s.push(...i[o])}),s}function bue({project:e,generator:t}){let r={cwd:process.cwd(),root:e.paths.root,workspace:t.basePath?Eu({cwd:t.basePath,target:"package.json"}):void 0},n={};try{n=NQ(t.basePath)}catch{}return{turbo:{paths:r,configs:n}}}function Fue({project:e}){let t=[];return e.workspaceData.workspaces.forEach(r=>{for(let n of GO)yC.default.existsSync(MA.default.join(r.paths.root,n))&&t.push({config:MA.default.join(r.paths.root,n),root:r.paths.root})}),t}async function OO({project:e,generator:t,bypassArgs:r,configPath:n}){let A=YO({project:e,configPath:n});if(!A)throw new Nt("Unable to load generators",{type:"plop_unable_to_load_config"});let i=A.getGenerator(t);if(!i)throw new Nt(`Generator ${t} not found`,{type:"plop_generator_not_found"});let s=await i.runPrompts(r),o=await i.runActions({...s,...bue({project:e,generator:i})},{onComment:a=>{P.dimmed(a)}});if(o.failures.length>0)throw o.failures.forEach(a=>{a instanceof Error?P.error(`Error - ${a.message}`):P.error(`Error - ${a.error}. Unable to ${a.type} to "${a.path}"`)}),new Nt(`Failed to run "${t}" generator`,{type:"plop_error_running_generator"});o.changes.length>0&&(P.info("Changes made:"),o.changes.forEach(a=>{a.path&&P.item(`${a.path} (${a.type})`)}))}var Hs=require("inquirer");async function HO({generators:e,generator:t}){if(t){if(e.find(n=>!(n instanceof Hs.Separator)&&n.name===t))return{selectedGenerator:t};P.warn(`Generator "${t}" not found`),P.log()}return await(0,Hs.prompt)({type:"list",name:"selectedGenerator",message:"Select generator to run",choices:e.map(n=>n instanceof Hs.Separator?n:{name:n.description?` ${n.name}: ${n.description}`:` ${n.name}`,value:n.name})})}async function PO(){return(0,Hs.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 JO({message:e}){return(0,Hs.prompt)({type:"confirm",name:"answer",message:e})}var Cw=ue(require("path")),dw=ue(require("fs-extra"));async function qO({project:e,template:t}){let r=Cw.default.join(e.paths.root,"turbo","generators"),n=`simple-${t}`;if(await dw.default.pathExists(r))throw new Nt(`Generator config directory already exists at ${r}`,{type:"config_directory_already_exists"});await dw.default.copy(Cw.default.join(__dirname,"templates",n),r,{recursive:!0})}async function Bw({generator:e,project:t,opts:r}){let n=!1,A=Ew({project:t,configPath:r.config});if(!A.length){P.error("No generators found."),P.log();let{answer:s}=await JO({message:`Would you like to add a config with a sample custom generator to ${t.name}?`});if(s){n=!0;let{answer:o}=await PO();try{await qO({project:t,template:o})}catch(a){throw a instanceof Nt||P.error("Failed to create generator config"),a}if(P.log(),P.info("Generator config successfully created!"),P.info("Loading generator config..."),P.log(),A=Ew({project:t,configPath:r.config}),!A.length){P.error("Error loading generator");return}}else{P.log(),P.dimmed("Learn more about custom Turborepo generators - https://turborepo.dev/docs/guides/generating-code#custom-generators");return}}let{selectedGenerator:i}=await HO({generators:A,generator:e});try{await OO({project:t,generator:i,bypassArgs:r.args,configPath:r.config})}catch(s){if(s instanceof Nt)throw s;let o="Failed to run generator";throw s instanceof Error&&(o=s.message),new Nt(o,{type:"plop_error_running_generator"})}finally{n&&(P.log(),P.info("Congrats! You just ran your first Turborepo generator"),P.dimmed("Learn more about custom Turborepo generators - https://turborepo.dev/docs/guides/generating-code#custom-generators"))}P.log(),P.bold(P.turboGradient(">>> Success!"))}var mw=ue(require("path")),FC=ue(require("fs-extra")),rH=ue(require("picocolors"));var pl=ue(require("path")),zO=ue(require("fs-extra")),$r=require("inquirer"),ZO=require("minimatch"),pw=ue(require("validate-npm-package-name"));var Qw=ue(require("path"));var VO=ue(require("path"));function WO({project:e}){let r=e.workspaceData.workspaces.map(A=>VO.default.relative(e.paths.root,A.paths.root)),n=new Set;return e.workspaceData.globs.forEach(A=>{if(!r.includes(A)){if(!A.startsWith("!")){let s=A.split("/")[0];n.add(s)}}}),Array.from(n)}function Iw({project:e,workspace:t}){return Qw.default.relative(e.paths.root,t.paths.root).split(Qw.default.sep)[0]}function wC({project:e}){let t=WO({project:e}),r=t.includes("apps"),n=t.includes("packages"),A={},i=[];return e.workspaceData.workspaces.forEach(s=>{let o=Iw({project:e,workspace:s});o!=="apps"&&i.push(s),o in A||(A[o]=[]),A[o].push(s)}),{hasRootApps:r,hasRootPackages:n,workspacesByGroup:A,nonAppWorkspaces:i}}var jO=require("inquirer");function DC({project:e,type:t,showAllDependencies:r}){let n=wC({project:e}),A=[],i=e.workspaceData.workspaces;r||(t==="app"&&n.hasRootApps?i=n.workspacesByGroup.apps:t==="package"&&n.nonAppWorkspaces.length>0&&(i=n.nonAppWorkspaces));let s;return i.forEach(o=>{let a=Iw({project:e,workspace:o});a!==s&&A.push(new jO.Separator(a)),s=a,A.push(o)}),A}async function KO({override:e,suggestion:t,workspaceType:r}){let{validForNewPackages:n}=(0,pw.default)(e||"");return e&&n?{answer:e}:(0,$r.prompt)({type:"input",name:"answer",default:t,validate:A=>{let{validForNewPackages:i}=(0,pw.default)(A);return i||`Invalid ${r} name`},message:`What is the name of the ${r}?`})}async function XO({override:e,message:t}){return e?{answer:e}:(0,$r.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 $O({workspaceType:e,workspaceName:t,destination:r,project:n}){let A=t.includes("/")?t.split("/")[1]:t;if(r){let{valid:a,root:u}=eg(r);if(a)return{absolute:u,relative:pl.default.relative(n.paths.root,u)}}let i,s=wC({project:n});e==="app"&&s.hasRootApps?i=`${n.paths.root}/apps/${A}`:e==="package"&&s.hasRootPackages&&(i=`${n.paths.root}/packages/${A}`);let{answer:o}=await(0,$r.prompt)({type:"input",name:"answer",message:`Where should "${t}" be added?`,default:i?pl.default.relative(n.paths.root,i):void 0,validate:a=>{let u=pl.default.join(n.paths.root,a),{valid:c,error:l}=eg(u),h=n.workspaceData.globs.some(d=>(0,ZO.minimatch)(a,d));return c&&h?!0:h?l:`${a} is not a valid workspace location`}});return{absolute:pl.default.join(n.paths.root,o),relative:o}}async function eH({override:e,workspaces:t,workspaceName:r}){if(e){let A=t.find(i=>i instanceof $r.Separator?!1:i.name===e);if(A)return{answer:A};P.warn(`Workspace "${e}" not found`),P.log()}return await(0,$r.prompt)({type:"list",name:"answer",loop:!1,pageSize:25,message:`Which workspace should "${r}" start from?`,choices:t.map(A=>A instanceof $r.Separator?A:{name:` ${A.name}`,value:A})})}async function tH({workspaceName:e,project:t,workspaceSource:r,showAllDependencies:n}){let A={dependencies:{},devDependencies:{},peerDependencies:{},optionalDependencies:{}},{answer:i}=await Rue({message:`Add workspace dependencies to "${e}"?`});if(!i)return A;let{answer:s}=await(0,$r.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"}]}),o=DC({project:t,type:"package",showAllDependencies:n}),a=r?zO.default.readJsonSync(r.paths.packageJson):void 0;for(let u of s){let{answer:c}=await(0,$r.prompt)({type:"checkbox",name:"answer",default:a&&Object.keys(a[u]||{}),pageSize:15,message:`Which packages should be added as ${u} to "${e}?`,loop:!1,choices:o.map(h=>h instanceof $r.Separator?h:{name:` ${h.name}`,value:h.name})}),l=(a==null?void 0:a[u])||{};if(Object.keys(l).length){let h=new Set(Object.keys(l));c.forEach(d=>{h.has(d)||(l[d]=t.packageManager==="pnpm"?"workspace:*":"*")}),A[u]=l}else A[u]=c.reduce((h,d)=>({...h,[d]:t.packageManager==="pnpm"?"workspace:*":"*"}),{})}return A}async function Rue({message:e}){return(0,$r.prompt)({type:"confirm",name:"answer",message:e})}async function bC({project:e,opts:t}){var a;let r,n=t.method==="copy"&&t.copy.type==="external"?((a=t.examplePath)==null?void 0:a.split("/").pop())||t.copy.source.split("/").pop():void 0,{answer:A}=await XO({override:t.type,message:t.method==="copy"&&t.copy.source==="external"&&n?`What type of workspace should "${n}" be created as?`:void 0}),{answer:i}=await KO({override:t.name,workspaceType:A,suggestion:n});if(t.method==="copy"&&t.copy.type==="internal"){let{answer:u}=await eH({override:t.copy.source,workspaces:DC({project:e,type:A}),workspaceName:i});r=u}let s=await $O({workspaceType:A,workspaceName:i,project:e,destination:t.destination}),o=await tH({workspaceName:i,project:e,workspaceSource:r,showAllDependencies:t.showAllDependencies});return{type:A,name:i,location:s,source:r,dependencies:o}}async function yw({project:e,opts:t}){let{name:r,location:n,dependencies:A}=await bC({project:e,opts:t}),i={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(A).forEach(s=>{let o=A[s];o&&Object.keys(o).length>0&&(i[s]=o)}),FC.default.mkdirSync(n.absolute,{recursive:!0}),FC.default.writeFileSync(mw.default.join(n.absolute,"package.json"),JSON.stringify(i,null,2)),FC.default.writeFileSync(mw.default.join(n.absolute,"README.md"),`# \`${r}\``),P.log(),P.log(`${rH.default.bold(P.turboGradient(">>> Success!"))} Created ${r} at "${n.relative}"`)}var ww=ue(require("path")),Mi=ue(require("fs-extra")),nH=ue(require("picocolors"));async function Dw({project:e,opts:t}){let{name:r,type:n,location:A,source:i,dependencies:s}=await bC({project:e,opts:t}),o=ww.default.join(A.absolute,"package.json");if(t.copy.type==="external"){P.log(),P.warn("Some manual modifications may be required."),P.dimmed(`This ${n} may require local dependencies or a different package manager than what is available in this repo`),await lw({appPath:A.absolute,example:t.copy.source,examplePath:t.examplePath});try{if(Mi.default.existsSync(o)){if((await Mi.default.readJSON(o)).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(Mi.default.existsSync(ww.default.join(A.absolute,"pnpm-workspace.yaml")))throw new Error("New workspace root detected - unexpected pnpm-workspace.yaml")}catch(u){let c="UNKNOWN_ERROR";u instanceof Error&&(c=u.message),P.error(c),await Mi.default.rm(A.absolute,{recursive:!0,force:!0});return}}else if(i){let u=async l=>Promise.resolve(!l.includes("node_modules")),c=P.turboLoader(`Creating "${r}" from "${i.name}"...`);c.start(),await Mi.default.copy(i.paths.root,A.absolute,{filter:u}),c.stop()}let a=await Mi.default.readJSON(o);a.name=r,Object.keys(s).forEach(u=>{let c=s[u];c&&Object.keys(c).length>0&&(a[u]=c)}),await Mi.default.writeJSON(o,a,{spaces:2}),P.log(),P.log(`${nH.default.bold(P.turboGradient(">>> Success!"))} Created ${r} at "${A.relative}"`)}function xue(e){let{copy:t,...r}=e,n=t===!0||typeof t=="string"?"copy":"empty",A=typeof t=="string"?t:"",i=typeof t=="string"&&t.startsWith("https://")?"external":"internal";return{method:n,copy:{type:i,source:A},...r}}async function ml(e){let t=await pC(e),r=xue(e);P.log();let n={project:t,opts:r};r.method==="copy"?(r.copy.type==="external"?P.info(`Copy a remote workspace from ${r.copy.source}`):P.info(`Copy an existing workspace from "${t.name}"`),P.log(),await Dw(n)):(P.info(`Add an empty workspace to "${t.name}"`),P.log(),await yw(n))}async function yl(e,t){let r=await pC(t);P.log(),P.info(`Modify "${r.name}" using custom generators`),P.log(),await Bw({generator:e,project:r,opts:t})}function AH(e){try{let t=JSON.parse(e),r={};for(let n in t){let A=hw(n,{to:"camel"});r[A]=t[n]}return r}catch(t){P.error("Error parsing arguments",t),process.exit(1)}}async function bw(e,t){var r;if(e==="workspace"){let n=AH(t.json);n.showAllDependencies=(r=n.showAllDependencies)!=null?r:!1;let A=!1,i=n.empty||!0;n.copy===""||n.copy===!0?(A=!0,i=!1):n.copy&&n.copy.length>0&&(A=n.copy,i=!1),n.copy=A,n.empty=i,await ml(n)}else if(e==="run"){let n=AH(t.json),{generatorName:A,...i}=n;await yl(A,i)}else P.error(`Received unknown command - "${e}" (must be one of "workspace" | "run")`),process.exit(1)}var iH=gw({packageInfo:fw}),cH=new uH.ProxyAgent;sH.default.globalAgent=cH;oH.default.globalAgent=cH;var wl=new vt.Command;wl.name(aH.default.bold(P.turboGradient("@turbo/gen"))).description("Extend your Turborepo").version(fw.version,"-v, --version","Output the current version").helpOption("-h, --help","Display help for command").showHelpAfterError(!1);wl.command("run",{isDefault:!0}).alias("r").description("Run custom generators").addArgument(new vt.Argument("[generator-name]","The name of the generator to run")).addOption(new vt.Option("-c, --config <config>","Generator configuration file (default: turbo/generators/config.js")).addOption(new vt.Option("-r, --root <dir>","The root of your repository (default: directory with root turbo.json)")).addOption(new vt.Option("-a, --args <args...>","Arguments passed directly to generator").default([])).action(yl);wl.command("workspace").aliases(["w"]).description("Add a new package or app to your project").addOption(new vt.Option("-n, --name <workspace-name>","Name for the new workspace")).addOption(new vt.Option("-b, --empty","Generate an empty workspace").conflicts("copy").default(!0)).addOption(new vt.Option("-c, --copy [source]",`Generate a workspace using an existing workspace as a template. Can be the name of a local workspace
|
|
117
|
+
`,"2. You might not be connected to the internet or you are behind a proxy."),process.exit(1)),A={username:"vercel",name:"turborepo",branch:"main",filePath:`examples/${t}`})}let o=au.default.resolve(e);await uw(au.default.dirname(o))||(s.stop(),mt("The application path is not writable, please check folder permissions and try again."),mt("It is likely you do not have write permissions for this folder."),process.exit(1));let a=au.default.basename(o);try{await BC.default.mkdir(o,{recursive:!0})}catch(p){s.stop(),mt("Unable to create project directory"),mt(p),process.exit(1)}let{isEmpty:u,conflicts:c}=Ou(o);u||(s.stop(),mt(`${Os.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),r||A?await(0,cw.default)(()=>sw(o,A!=null?A:{username:"vercel",name:"turborepo",branch:"main",filePath:"examples/basic"}),{retries:3}):await(0,cw.default)(()=>ow(o,t),{retries:3}),s.stop();let h=au.default.join(o,"package.json"),d=BC.default.existsSync(h),f=[];if(d){let p;try{p=BC.default.readJsonSync(h)}catch{}p&&f.push(...Object.keys(p.scripts||{}))}let g=e;return au.default.join(l,a)===e&&(g=a),{cdPath:g,hasPackageJson:d,availableScripts:f,repoInfo:A}}catch(o){throw s.stop(),new QC(pue(o)?o.message:String(o))}}function hw(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 IC=ue(require("picocolors")),MO=ue(require("update-check"));function gw(e){let{packageInfo:t,upgradeCommand:r}=e,n=(0,MO.default)(t).catch(()=>null);return async function(i=0){try{let s=await n;if(s!=null&&s.latest){nr(),nr(IC.default.yellow(IC.default.bold(`A new version of \`${t.name}\` is available!`)));let o=typeof r=="function"?await r():r;o&&nr(`You can update by running: ${IC.default.cyan(o)}`),nr()}process.exit(i)}catch(s){process.env.DEBUG&&mt("Update check failed:",s),process.exit(i)}}}var uH=require("proxy-agent");var fw={name:"@turbo/gen",version:"2.8.2-canary.2",description:"Extend a Turborepo",type:"commonjs",homepage:"https://turborepo.dev",license:"MIT",repository:{type:"git",url:"git+https://github.com/vercel/turborepo.git",directory:"packages/turbo-gen"},bugs:{url:"https://github.com/vercel/turborepo/issues"},bin:"dist/cli.js",types:"dist/types.d.ts",scripts:{build:"tsup",test:"jest","check-types":"tsc --noEmit","package:types":"attw --profile node16 --pack"},dependencies:{"@turbo/workspaces":"workspace:*",commander:"10.0.0","fs-extra":"10.1.0",inquirer:"8.2.4",minimatch:"9.0.0","node-plop":"0.26.3",picocolors:"1.0.1","proxy-agent":"6.5.0","ts-node":"10.9.2","update-check":"1.5.4","validate-npm-package-name":"5.0.0"},devDependencies:{"@arethetypeswrong/cli":"0.18.2","@jest/globals":"29.7.0","@turbo/test-utils":"workspace:*","@turbo/tsconfig":"workspace:*","@turbo/utils":"workspace:*","@types/fs-extra":"9.0.13","@types/inquirer":"8.2.5","@types/node":"18.17.4","@types/validate-npm-package-name":"4.0.0",jest:"29.7.0","ts-jest":"29.2.5",tsup:"6.7.0",typescript:"5.5.4"},files:["dist"],publishConfig:{access:"public"}};var TO=require("@turbo/workspaces");async function pC({root:e}){let t=e||process.cwd(),r=Cu(t);if(!r)P.error("Unable to infer repository root - override with --root");else try{return(0,TO.getWorkspaceDetails)({root:r})}catch{P.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 MA=ue(require("path")),yC=ue(require("fs-extra")),mC=ue(require("node-plop")),LO=require("ts-node"),UO=require("inquirer");var Nt=class extends Error{constructor(r,n){var A;super(r);this.name="GenerateError",this.type=(A=n==null?void 0:n.type)!=null?A:"unknown",Error.captureStackTrace(this,Nt)}};var _O=["ts","js","cjs"],wue=MA.default.join("turbo","generators"),GO=_O.map(e=>MA.default.join(wue,`config.${e}`)),Due=[...GO,..._O.map(e=>MA.default.join(`plopfile.${e}`))];function YO({project:e,configPath:t}){(0,LO.register)({transpileOnly:!0,cwd:e.paths.root,compilerOptions:{module:"nodenext",moduleResolution:"nodenext"}});let r=Fue({project:e}),n;if(t){if(!yC.default.existsSync(t))throw new Nt(`No config at "${t}"`,{type:"plop_no_config"});try{n=(0,mC.default)(t,{destBasePath:t,force:!1})}catch(A){P.error(A)}}else{for(let A of Due){let i=MA.default.join(e.paths.root,A);if(yC.default.existsSync(i))try{n=(0,mC.default)(i,{destBasePath:e.paths.root,force:!1});break}catch(s){P.error(s)}}!n&&r.length>0&&(n=(0,mC.default)(r[0].config,{destBasePath:r[0].root,force:!1}),r.shift())}return n&&r.forEach(A=>{try{n.load(A.config,{destBasePath:A.root,force:!1})}catch(i){P.error(i)}}),n}function Ew({project:e,configPath:t}){let r=YO({project:e,configPath:t});if(!r)return[];let A=r.getGeneratorList().map(o=>r.getGenerator(o.name)),i={};A.forEach(o=>{let a=o,u=e.workspaceData.workspaces.find(c=>{if(a.basePath===e.paths.root)return!1;let l=a.basePath.split(MA.default.sep);return l.pop(),l.pop(),MA.default.join("/",...l)===c.paths.root});u?(u.name in i||(i[u.name]=[]),i[u.name].push(a)):("root"in i||(i.root=[]),i.root.push(a))});let s=[];return Object.keys(i).forEach(o=>{s.push(new UO.Separator(o)),s.push(...i[o])}),s}function bue({project:e,generator:t}){let r={cwd:process.cwd(),root:e.paths.root,workspace:t.basePath?Eu({cwd:t.basePath,target:"package.json"}):void 0},n={};try{n=NQ(t.basePath)}catch{}return{turbo:{paths:r,configs:n}}}function Fue({project:e}){let t=[];return e.workspaceData.workspaces.forEach(r=>{for(let n of GO)yC.default.existsSync(MA.default.join(r.paths.root,n))&&t.push({config:MA.default.join(r.paths.root,n),root:r.paths.root})}),t}async function OO({project:e,generator:t,bypassArgs:r,configPath:n}){let A=YO({project:e,configPath:n});if(!A)throw new Nt("Unable to load generators",{type:"plop_unable_to_load_config"});let i=A.getGenerator(t);if(!i)throw new Nt(`Generator ${t} not found`,{type:"plop_generator_not_found"});let s=await i.runPrompts(r),o=await i.runActions({...s,...bue({project:e,generator:i})},{onComment:a=>{P.dimmed(a)}});if(o.failures.length>0)throw o.failures.forEach(a=>{a instanceof Error?P.error(`Error - ${a.message}`):P.error(`Error - ${a.error}. Unable to ${a.type} to "${a.path}"`)}),new Nt(`Failed to run "${t}" generator`,{type:"plop_error_running_generator"});o.changes.length>0&&(P.info("Changes made:"),o.changes.forEach(a=>{a.path&&P.item(`${a.path} (${a.type})`)}))}var Hs=require("inquirer");async function HO({generators:e,generator:t}){if(t){if(e.find(n=>!(n instanceof Hs.Separator)&&n.name===t))return{selectedGenerator:t};P.warn(`Generator "${t}" not found`),P.log()}return await(0,Hs.prompt)({type:"list",name:"selectedGenerator",message:"Select generator to run",choices:e.map(n=>n instanceof Hs.Separator?n:{name:n.description?` ${n.name}: ${n.description}`:` ${n.name}`,value:n.name})})}async function PO(){return(0,Hs.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 JO({message:e}){return(0,Hs.prompt)({type:"confirm",name:"answer",message:e})}var Cw=ue(require("path")),dw=ue(require("fs-extra"));async function qO({project:e,template:t}){let r=Cw.default.join(e.paths.root,"turbo","generators"),n=`simple-${t}`;if(await dw.default.pathExists(r))throw new Nt(`Generator config directory already exists at ${r}`,{type:"config_directory_already_exists"});await dw.default.copy(Cw.default.join(__dirname,"templates",n),r,{recursive:!0})}async function Bw({generator:e,project:t,opts:r}){let n=!1,A=Ew({project:t,configPath:r.config});if(!A.length){P.error("No generators found."),P.log();let{answer:s}=await JO({message:`Would you like to add a config with a sample custom generator to ${t.name}?`});if(s){n=!0;let{answer:o}=await PO();try{await qO({project:t,template:o})}catch(a){throw a instanceof Nt||P.error("Failed to create generator config"),a}if(P.log(),P.info("Generator config successfully created!"),P.info("Loading generator config..."),P.log(),A=Ew({project:t,configPath:r.config}),!A.length){P.error("Error loading generator");return}}else{P.log(),P.dimmed("Learn more about custom Turborepo generators - https://turborepo.dev/docs/guides/generating-code#custom-generators");return}}let{selectedGenerator:i}=await HO({generators:A,generator:e});try{await OO({project:t,generator:i,bypassArgs:r.args,configPath:r.config})}catch(s){if(s instanceof Nt)throw s;let o="Failed to run generator";throw s instanceof Error&&(o=s.message),new Nt(o,{type:"plop_error_running_generator"})}finally{n&&(P.log(),P.info("Congrats! You just ran your first Turborepo generator"),P.dimmed("Learn more about custom Turborepo generators - https://turborepo.dev/docs/guides/generating-code#custom-generators"))}P.log(),P.bold(P.turboGradient(">>> Success!"))}var mw=ue(require("path")),FC=ue(require("fs-extra")),rH=ue(require("picocolors"));var pl=ue(require("path")),zO=ue(require("fs-extra")),$r=require("inquirer"),ZO=require("minimatch"),pw=ue(require("validate-npm-package-name"));var Qw=ue(require("path"));var VO=ue(require("path"));function WO({project:e}){let r=e.workspaceData.workspaces.map(A=>VO.default.relative(e.paths.root,A.paths.root)),n=new Set;return e.workspaceData.globs.forEach(A=>{if(!r.includes(A)){if(!A.startsWith("!")){let s=A.split("/")[0];n.add(s)}}}),Array.from(n)}function Iw({project:e,workspace:t}){return Qw.default.relative(e.paths.root,t.paths.root).split(Qw.default.sep)[0]}function wC({project:e}){let t=WO({project:e}),r=t.includes("apps"),n=t.includes("packages"),A={},i=[];return e.workspaceData.workspaces.forEach(s=>{let o=Iw({project:e,workspace:s});o!=="apps"&&i.push(s),o in A||(A[o]=[]),A[o].push(s)}),{hasRootApps:r,hasRootPackages:n,workspacesByGroup:A,nonAppWorkspaces:i}}var jO=require("inquirer");function DC({project:e,type:t,showAllDependencies:r}){let n=wC({project:e}),A=[],i=e.workspaceData.workspaces;r||(t==="app"&&n.hasRootApps?i=n.workspacesByGroup.apps:t==="package"&&n.nonAppWorkspaces.length>0&&(i=n.nonAppWorkspaces));let s;return i.forEach(o=>{let a=Iw({project:e,workspace:o});a!==s&&A.push(new jO.Separator(a)),s=a,A.push(o)}),A}async function KO({override:e,suggestion:t,workspaceType:r}){let{validForNewPackages:n}=(0,pw.default)(e||"");return e&&n?{answer:e}:(0,$r.prompt)({type:"input",name:"answer",default:t,validate:A=>{let{validForNewPackages:i}=(0,pw.default)(A);return i||`Invalid ${r} name`},message:`What is the name of the ${r}?`})}async function XO({override:e,message:t}){return e?{answer:e}:(0,$r.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 $O({workspaceType:e,workspaceName:t,destination:r,project:n}){let A=t.includes("/")?t.split("/")[1]:t;if(r){let{valid:a,root:u}=eg(r);if(a)return{absolute:u,relative:pl.default.relative(n.paths.root,u)}}let i,s=wC({project:n});e==="app"&&s.hasRootApps?i=`${n.paths.root}/apps/${A}`:e==="package"&&s.hasRootPackages&&(i=`${n.paths.root}/packages/${A}`);let{answer:o}=await(0,$r.prompt)({type:"input",name:"answer",message:`Where should "${t}" be added?`,default:i?pl.default.relative(n.paths.root,i):void 0,validate:a=>{let u=pl.default.join(n.paths.root,a),{valid:c,error:l}=eg(u),h=n.workspaceData.globs.some(d=>(0,ZO.minimatch)(a,d));return c&&h?!0:h?l:`${a} is not a valid workspace location`}});return{absolute:pl.default.join(n.paths.root,o),relative:o}}async function eH({override:e,workspaces:t,workspaceName:r}){if(e){let A=t.find(i=>i instanceof $r.Separator?!1:i.name===e);if(A)return{answer:A};P.warn(`Workspace "${e}" not found`),P.log()}return await(0,$r.prompt)({type:"list",name:"answer",loop:!1,pageSize:25,message:`Which workspace should "${r}" start from?`,choices:t.map(A=>A instanceof $r.Separator?A:{name:` ${A.name}`,value:A})})}async function tH({workspaceName:e,project:t,workspaceSource:r,showAllDependencies:n}){let A={dependencies:{},devDependencies:{},peerDependencies:{},optionalDependencies:{}},{answer:i}=await Rue({message:`Add workspace dependencies to "${e}"?`});if(!i)return A;let{answer:s}=await(0,$r.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"}]}),o=DC({project:t,type:"package",showAllDependencies:n}),a=r?zO.default.readJsonSync(r.paths.packageJson):void 0;for(let u of s){let{answer:c}=await(0,$r.prompt)({type:"checkbox",name:"answer",default:a&&Object.keys(a[u]||{}),pageSize:15,message:`Which packages should be added as ${u} to "${e}?`,loop:!1,choices:o.map(h=>h instanceof $r.Separator?h:{name:` ${h.name}`,value:h.name})}),l=(a==null?void 0:a[u])||{};if(Object.keys(l).length){let h=new Set(Object.keys(l));c.forEach(d=>{h.has(d)||(l[d]=t.packageManager==="pnpm"?"workspace:*":"*")}),A[u]=l}else A[u]=c.reduce((h,d)=>({...h,[d]:t.packageManager==="pnpm"?"workspace:*":"*"}),{})}return A}async function Rue({message:e}){return(0,$r.prompt)({type:"confirm",name:"answer",message:e})}async function bC({project:e,opts:t}){var a;let r,n=t.method==="copy"&&t.copy.type==="external"?((a=t.examplePath)==null?void 0:a.split("/").pop())||t.copy.source.split("/").pop():void 0,{answer:A}=await XO({override:t.type,message:t.method==="copy"&&t.copy.source==="external"&&n?`What type of workspace should "${n}" be created as?`:void 0}),{answer:i}=await KO({override:t.name,workspaceType:A,suggestion:n});if(t.method==="copy"&&t.copy.type==="internal"){let{answer:u}=await eH({override:t.copy.source,workspaces:DC({project:e,type:A}),workspaceName:i});r=u}let s=await $O({workspaceType:A,workspaceName:i,project:e,destination:t.destination}),o=await tH({workspaceName:i,project:e,workspaceSource:r,showAllDependencies:t.showAllDependencies});return{type:A,name:i,location:s,source:r,dependencies:o}}async function yw({project:e,opts:t}){let{name:r,location:n,dependencies:A}=await bC({project:e,opts:t}),i={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(A).forEach(s=>{let o=A[s];o&&Object.keys(o).length>0&&(i[s]=o)}),FC.default.mkdirSync(n.absolute,{recursive:!0}),FC.default.writeFileSync(mw.default.join(n.absolute,"package.json"),JSON.stringify(i,null,2)),FC.default.writeFileSync(mw.default.join(n.absolute,"README.md"),`# \`${r}\``),P.log(),P.log(`${rH.default.bold(P.turboGradient(">>> Success!"))} Created ${r} at "${n.relative}"`)}var ww=ue(require("path")),Mi=ue(require("fs-extra")),nH=ue(require("picocolors"));async function Dw({project:e,opts:t}){let{name:r,type:n,location:A,source:i,dependencies:s}=await bC({project:e,opts:t}),o=ww.default.join(A.absolute,"package.json");if(t.copy.type==="external"){P.log(),P.warn("Some manual modifications may be required."),P.dimmed(`This ${n} may require local dependencies or a different package manager than what is available in this repo`),await lw({appPath:A.absolute,example:t.copy.source,examplePath:t.examplePath});try{if(Mi.default.existsSync(o)){if((await Mi.default.readJSON(o)).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(Mi.default.existsSync(ww.default.join(A.absolute,"pnpm-workspace.yaml")))throw new Error("New workspace root detected - unexpected pnpm-workspace.yaml")}catch(u){let c="UNKNOWN_ERROR";u instanceof Error&&(c=u.message),P.error(c),await Mi.default.rm(A.absolute,{recursive:!0,force:!0});return}}else if(i){let u=async l=>Promise.resolve(!l.includes("node_modules")),c=P.turboLoader(`Creating "${r}" from "${i.name}"...`);c.start(),await Mi.default.copy(i.paths.root,A.absolute,{filter:u}),c.stop()}let a=await Mi.default.readJSON(o);a.name=r,Object.keys(s).forEach(u=>{let c=s[u];c&&Object.keys(c).length>0&&(a[u]=c)}),await Mi.default.writeJSON(o,a,{spaces:2}),P.log(),P.log(`${nH.default.bold(P.turboGradient(">>> Success!"))} Created ${r} at "${A.relative}"`)}function xue(e){let{copy:t,...r}=e,n=t===!0||typeof t=="string"?"copy":"empty",A=typeof t=="string"?t:"",i=typeof t=="string"&&t.startsWith("https://")?"external":"internal";return{method:n,copy:{type:i,source:A},...r}}async function ml(e){let t=await pC(e),r=xue(e);P.log();let n={project:t,opts:r};r.method==="copy"?(r.copy.type==="external"?P.info(`Copy a remote workspace from ${r.copy.source}`):P.info(`Copy an existing workspace from "${t.name}"`),P.log(),await Dw(n)):(P.info(`Add an empty workspace to "${t.name}"`),P.log(),await yw(n))}async function yl(e,t){let r=await pC(t);P.log(),P.info(`Modify "${r.name}" using custom generators`),P.log(),await Bw({generator:e,project:r,opts:t})}function AH(e){try{let t=JSON.parse(e),r={};for(let n in t){let A=hw(n,{to:"camel"});r[A]=t[n]}return r}catch(t){P.error("Error parsing arguments",t),process.exit(1)}}async function bw(e,t){var r;if(e==="workspace"){let n=AH(t.json);n.showAllDependencies=(r=n.showAllDependencies)!=null?r:!1;let A=!1,i=n.empty||!0;n.copy===""||n.copy===!0?(A=!0,i=!1):n.copy&&n.copy.length>0&&(A=n.copy,i=!1),n.copy=A,n.empty=i,await ml(n)}else if(e==="run"){let n=AH(t.json),{generatorName:A,...i}=n;await yl(A,i)}else P.error(`Received unknown command - "${e}" (must be one of "workspace" | "run")`),process.exit(1)}var iH=gw({packageInfo:fw}),cH=new uH.ProxyAgent;sH.default.globalAgent=cH;oH.default.globalAgent=cH;var wl=new vt.Command;wl.name(aH.default.bold(P.turboGradient("@turbo/gen"))).description("Extend your Turborepo").version(fw.version,"-v, --version","Output the current version").helpOption("-h, --help","Display help for command").showHelpAfterError(!1);wl.command("run",{isDefault:!0}).alias("r").description("Run custom generators").addArgument(new vt.Argument("[generator-name]","The name of the generator to run")).addOption(new vt.Option("-c, --config <config>","Generator configuration file (default: turbo/generators/config.js")).addOption(new vt.Option("-r, --root <dir>","The root of your repository (default: directory with root turbo.json)")).addOption(new vt.Option("-a, --args <args...>","Arguments passed directly to generator").default([])).action(yl);wl.command("workspace").aliases(["w"]).description("Add a new package or app to your project").addOption(new vt.Option("-n, --name <workspace-name>","Name for the new workspace")).addOption(new vt.Option("-b, --empty","Generate an empty workspace").conflicts("copy").default(!0)).addOption(new vt.Option("-c, --copy [source]",`Generate a workspace using an existing workspace as a template. Can be the name of a local workspace
|
|
118
118
|
within your monorepo, or a fully qualified GitHub URL with any branch and/or subdirectory.
|
|
119
119
|
`).conflicts("empty")).addOption(new vt.Option("-d, --destination <dir>","Where the new workspace should be created")).addOption(new vt.Option("-t, --type <type>","The type of workspace to create").choices(["app","package"])).addOption(new vt.Option("-r, --root <dir>","The root of your repository (default: directory with root turbo.json)")).addOption(new vt.Option("-p, --example-path <path-to-example>",`In a rare case, your GitHub URL might contain a branch name with
|
|
120
120
|
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.8.2-canary.
|
|
3
|
+
"version": "2.8.2-canary.2",
|
|
4
4
|
"description": "Extend a Turborepo",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"homepage": "https://turborepo.dev",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"ts-node": "10.9.2",
|
|
27
27
|
"update-check": "1.5.4",
|
|
28
28
|
"validate-npm-package-name": "5.0.0",
|
|
29
|
-
"@turbo/workspaces": "2.8.2-canary.
|
|
29
|
+
"@turbo/workspaces": "2.8.2-canary.2"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@arethetypeswrong/cli": "0.18.2",
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
"tsup": "6.7.0",
|
|
41
41
|
"typescript": "5.5.4",
|
|
42
42
|
"@turbo/test-utils": "0.0.0",
|
|
43
|
-
"@turbo/
|
|
44
|
-
"@turbo/
|
|
43
|
+
"@turbo/utils": "0.0.0",
|
|
44
|
+
"@turbo/tsconfig": "0.0.0"
|
|
45
45
|
},
|
|
46
46
|
"files": [
|
|
47
47
|
"dist"
|