@frontstackdev/cli 0.0.0-canary-20251029143733 → 0.0.0-canary-20251031085239
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/frontstack.mjs +1 -1
- package/dist/version +1 -1
- package/package.json +3 -2
package/dist/frontstack.mjs
CHANGED
|
@@ -22,7 +22,7 @@ Expecting one of '${n.join("', '")}'`);return this._lifeCycleHooks[e]?this._life
|
|
|
22
22
|
Expecting one of '${n.join("', '")}'`);const r=`${e}Help`;return this.on(r,i=>{let a;typeof t=="function"?a=t({error:i.error,command:i.command}):a=t,a&&i.write(`${a}
|
|
23
23
|
`)}),this}_outputHelpIfRequested(e){const t=this._getHelpOption();t&&e.find(r=>t.is(r))&&(this.outputHelp(),this._exit(0,"commander.helpDisplayed","(outputHelp)"))}},l(T,"Command"),T);function Ae(o){return o.map(e=>{if(!e.startsWith("--inspect"))return e;let t,n="127.0.0.1",r="9229",i;return(i=e.match(/^(--inspect(-brk)?)$/))!==null?t=i[1]:(i=e.match(/^(--inspect(-brk|-port)?)=([^:]+)$/))!==null?(t=i[1],/^\d+$/.test(i[3])?r=i[3]:n=i[3]):(i=e.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/))!==null&&(t=i[1],n=i[3],r=i[4]),t&&r!=="0"?`${t}=${n}:${parseInt(r)+1}`:e})}l(Ae,"incrementNodeInspectorPort"),_e.Command=At;const{Argument:Ce}=D,{Command:X}=_e,{CommanderError:Ct,InvalidArgumentError:Ee}=k,{Help:Et}=z,{Option:$e}=W;A.program=new X,A.createCommand=o=>new X(o),A.createOption=(o,e)=>new $e(o,e),A.createArgument=(o,e)=>new Ce(o,e),A.Command=X,A.Option=$e,A.Argument=Ce,A.Help=Et,A.CommanderError=Ct,A.InvalidArgumentError=Ee,A.InvalidOptionArgumentError=Ee;const{program:lo,createCommand:uo,createArgument:ho,createOption:po,CommanderError:fo,InvalidArgumentError:mo,InvalidOptionArgumentError:go,Command:$t,Argument:_o,Option:yo,Help:Oo}=A,vt=/"(?:_|\\u0{2}5[Ff]){2}(?:p|\\u0{2}70)(?:r|\\u0{2}72)(?:o|\\u0{2}6[Ff])(?:t|\\u0{2}74)(?:o|\\u0{2}6[Ff])(?:_|\\u0{2}5[Ff]){2}"\s*:/,St=/"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/,jt=/^\s*["[{]|^\s*-?\d{1,16}(\.\d{1,17})?([Ee][+-]?\d+)?\s*$/;function Tt(o,e){if(o==="__proto__"||o==="constructor"&&e&&typeof e=="object"&&"prototype"in e){xt(o);return}return e}l(Tt,"jsonParseTransform");function xt(o){console.warn(`[destr] Dropping "${o}" key to prevent prototype pollution.`)}l(xt,"warnKeyDropped");function kt(o,e={}){if(typeof o!="string")return o;const t=o.trim();if(o[0]==='"'&&o.endsWith('"')&&!o.includes("\\"))return t.slice(1,-1);if(t.length<=9){const n=t.toLowerCase();if(n==="true")return!0;if(n==="false")return!1;if(n==="undefined")return;if(n==="null")return null;if(n==="nan")return Number.NaN;if(n==="infinity")return Number.POSITIVE_INFINITY;if(n==="-infinity")return Number.NEGATIVE_INFINITY}if(!jt.test(o)){if(e.strict)throw new SyntaxError("[destr] Invalid JSON");return o}try{if(vt.test(o)||St.test(o)){if(e.strict)throw new Error("[destr] Possible prototype pollution");return JSON.parse(o,Tt)}return JSON.parse(o)}catch(n){if(e.strict)throw n;return o}}l(kt,"destr");const Pt=/#/g,Rt=/&/g,Ht=/\//g,Nt=/=/g,ee=/\+/g,It=/%5e/gi,Ft=/%60/gi,Vt=/%7c/gi,Dt=/%20/gi;function Lt(o){return encodeURI(""+o).replace(Vt,"|")}l(Lt,"encode");function te(o){return Lt(typeof o=="string"?o:JSON.stringify(o)).replace(ee,"%2B").replace(Dt,"+").replace(Pt,"%23").replace(Rt,"%26").replace(Ft,"`").replace(It,"^").replace(Ht,"%2F")}l(te,"encodeQueryValue");function ne(o){return te(o).replace(Nt,"%3D")}l(ne,"encodeQueryKey");function ve(o=""){try{return decodeURIComponent(""+o)}catch{return""+o}}l(ve,"decode");function qt(o){return ve(o.replace(ee," "))}l(qt,"decodeQueryKey");function Mt(o){return ve(o.replace(ee," "))}l(Mt,"decodeQueryValue");function Ut(o=""){const e={};o[0]==="?"&&(o=o.slice(1));for(const t of o.split("&")){const n=t.match(/([^=]+)=?(.*)/)||[];if(n.length<2)continue;const r=qt(n[1]);if(r==="__proto__"||r==="constructor")continue;const i=Mt(n[2]||"");e[r]===void 0?e[r]=i:Array.isArray(e[r])?e[r].push(i):e[r]=[e[r],i]}return e}l(Ut,"parseQuery");function Wt(o,e){return(typeof e=="number"||typeof e=="boolean")&&(e=String(e)),e?Array.isArray(e)?e.map(t=>`${ne(o)}=${te(t)}`).join("&"):`${ne(o)}=${te(e)}`:ne(o)}l(Wt,"encodeQueryItem");function Gt(o){return Object.keys(o).filter(e=>o[e]!==void 0).map(e=>Wt(e,o[e])).filter(Boolean).join("&")}l(Gt,"stringifyQuery");const Jt=/^[\s\w\0+.-]{2,}:([/\\]{1,2})/,Bt=/^[\s\w\0+.-]{2,}:([/\\]{2})?/,Kt=/^([/\\]\s*){2,}[^/\\]/,zt=/^\.?\//;function Se(o,e={}){return typeof e=="boolean"&&(e={acceptRelative:e}),e.strict?Jt.test(o):Bt.test(o)||(e.acceptRelative?Kt.test(o):!1)}l(Se,"hasProtocol");function Qt(o="",e){return o.endsWith("/")}l(Qt,"hasTrailingSlash");function Yt(o="",e){return(Qt(o)?o.slice(0,-1):o)||"/"}l(Yt,"withoutTrailingSlash");function Zt(o="",e){return o.endsWith("/")?o:o+"/"}l(Zt,"withTrailingSlash");function Xt(o,e){if(tn(e)||Se(o))return o;const t=Yt(e);return o.startsWith(t)?o:on(t,o)}l(Xt,"withBase");function en(o,e){const t=rn(o),n={...Ut(t.search),...e};return t.search=Gt(n),sn(t)}l(en,"withQuery");function tn(o){return!o||o==="/"}l(tn,"isEmptyURL");function nn(o){return o&&o!=="/"}l(nn,"isNonEmptyURL");function on(o,...e){let t=o||"";for(const n of e.filter(r=>nn(r)))if(t){const r=n.replace(zt,"");t=Zt(t)+r}else t=n;return t}l(on,"joinURL");const je=Symbol.for("ufo:protocolRelative");function rn(o="",e){const t=o.match(/^[\s\0]*(blob:|data:|javascript:|vbscript:)(.*)/i);if(t){const[,p,d=""]=t;return{protocol:p.toLowerCase(),pathname:d,href:p+d,auth:"",host:"",search:"",hash:""}}if(!Se(o,{acceptRelative:!0}))return Te(o);const[,n="",r,i=""]=o.replace(/\\/g,"/").match(/^[\s\0]*([\w+.-]{2,}:)?\/\/([^/@]+@)?(.*)/)||[];let[,a="",u=""]=i.match(/([^#/?]*)(.*)?/)||[];n==="file:"&&(u=u.replace(/\/(?=[A-Za-z]:)/,""));const{pathname:c,search:h,hash:s}=Te(u);return{protocol:n.toLowerCase(),auth:r?r.slice(0,Math.max(0,r.length-1)):"",host:a,pathname:c,search:h,hash:s,[je]:!n}}l(rn,"parseURL");function Te(o=""){const[e="",t="",n=""]=(o.match(/([^#?]*)(\?[^#]*)?(#.*)?/)||[]).splice(1);return{pathname:e,search:t,hash:n}}l(Te,"parsePath");function sn(o){const e=o.pathname||"",t=o.search?(o.search.startsWith("?")?"":"?")+o.search:"",n=o.hash||"",r=o.auth?o.auth+"@":"",i=o.host||"";return(o.protocol||o[je]?(o.protocol||"")+"//":"")+r+i+e+t+n}l(sn,"stringifyParsedURL");const ae=class ae extends Error{constructor(e,t){super(e,t),this.name="FetchError",t?.cause&&!this.cause&&(this.cause=t.cause)}};l(ae,"FetchError");let oe=ae;function an(o){const e=o.error?.message||o.error?.toString()||"",t=o.request?.method||o.options?.method||"GET",n=o.request?.url||String(o.request)||"/",r=`[${t}] ${JSON.stringify(n)}`,i=o.response?`${o.response.status} ${o.response.statusText}`:"<no response>",a=`${r}: ${i}${e?` ${e}`:""}`,u=new oe(a,o.error?{cause:o.error}:void 0);for(const c of["request","options","response"])Object.defineProperty(u,c,{get(){return o[c]}});for(const[c,h]of[["data","_data"],["status","status"],["statusCode","status"],["statusText","statusText"],["statusMessage","statusText"]])Object.defineProperty(u,c,{get(){return o.response&&o.response[h]}});return u}l(an,"createFetchError");const cn=new Set(Object.freeze(["PATCH","POST","PUT","DELETE"]));function xe(o="GET"){return cn.has(o.toUpperCase())}l(xe,"isPayloadMethod");function ln(o){if(o===void 0)return!1;const e=typeof o;return e==="string"||e==="number"||e==="boolean"||e===null?!0:e!=="object"?!1:Array.isArray(o)?!0:o.buffer?!1:o.constructor&&o.constructor.name==="Object"||typeof o.toJSON=="function"}l(ln,"isJSONSerializable");const un=new Set(["image/svg","application/xml","application/xhtml","application/html"]),hn=/^application\/(?:[\w!#$%&*.^`~-]*\+)?json(;.+)?$/i;function pn(o=""){if(!o)return"json";const e=o.split(";").shift()||"";return hn.test(e)?"json":un.has(e)||e.startsWith("text/")?"text":"blob"}l(pn,"detectResponseType");function fn(o,e,t=globalThis.Headers){const n={...e,...o};if(e?.params&&o?.params&&(n.params={...e?.params,...o?.params}),e?.query&&o?.query&&(n.query={...e?.query,...o?.query}),e?.headers&&o?.headers){n.headers=new t(e?.headers||{});for(const[r,i]of new t(o?.headers||{}))n.headers.set(r,i)}return n}l(fn,"mergeFetchOptions");const dn=new Set([408,409,425,429,500,502,503,504]),mn=new Set([101,204,205,304]);function ke(o={}){const{fetch:e=globalThis.fetch,Headers:t=globalThis.Headers,AbortController:n=globalThis.AbortController}=o;async function r(u){const c=u.error&&u.error.name==="AbortError"&&!u.options.timeout||!1;if(u.options.retry!==!1&&!c){let s;typeof u.options.retry=="number"?s=u.options.retry:s=xe(u.options.method)?0:1;const p=u.response&&u.response.status||500;if(s>0&&(Array.isArray(u.options.retryStatusCodes)?u.options.retryStatusCodes.includes(p):dn.has(p))){const d=u.options.retryDelay||0;return d>0&&await new Promise(y=>setTimeout(y,d)),i(u.request,{...u.options,retry:s-1})}}const h=an(u);throw Error.captureStackTrace&&Error.captureStackTrace(h,i),h}l(r,"onError");const i=l(async function(c,h={}){const s={request:c,options:fn(h,o.defaults,t),response:void 0,error:void 0};s.options.method=s.options.method?.toUpperCase(),s.options.onRequest&&await s.options.onRequest(s),typeof s.request=="string"&&(s.options.baseURL&&(s.request=Xt(s.request,s.options.baseURL)),(s.options.query||s.options.params)&&(s.request=en(s.request,{...s.options.params,...s.options.query}))),s.options.body&&xe(s.options.method)&&(ln(s.options.body)?(s.options.body=typeof s.options.body=="string"?s.options.body:JSON.stringify(s.options.body),s.options.headers=new t(s.options.headers||{}),s.options.headers.has("content-type")||s.options.headers.set("content-type","application/json"),s.options.headers.has("accept")||s.options.headers.set("accept","application/json")):("pipeTo"in s.options.body&&typeof s.options.body.pipeTo=="function"||typeof s.options.body.pipe=="function")&&("duplex"in s.options||(s.options.duplex="half")));let p;if(!s.options.signal&&s.options.timeout){const y=new n;p=setTimeout(()=>y.abort(),s.options.timeout),s.options.signal=y.signal}try{s.response=await e(s.request,s.options)}catch(y){return s.error=y,s.options.onRequestError&&await s.options.onRequestError(s),await r(s)}finally{p&&clearTimeout(p)}if(s.response.body&&!mn.has(s.response.status)&&s.options.method!=="HEAD"){const y=(s.options.parseResponse?"json":s.options.responseType)||pn(s.response.headers.get("content-type")||"");switch(y){case"json":{const m=await s.response.text(),b=s.options.parseResponse||kt;s.response._data=b(m);break}case"stream":{s.response._data=s.response.body;break}default:s.response._data=await s.response[y]()}}return s.options.onResponse&&await s.options.onResponse(s),!s.options.ignoreResponseError&&s.response.status>=400&&s.response.status<600?(s.options.onResponseError&&await s.options.onResponseError(s),await r(s)):s.response},"$fetchRaw2"),a=l(async function(c,h){return(await i(c,h))._data},"$fetch2");return a.raw=i,a.native=(...u)=>e(...u),a.create=(u={})=>ke({...o,defaults:{...o.defaults,...u}}),a}l(ke,"createFetch");const re=function(){if(typeof globalThis<"u")return globalThis;if(typeof self<"u")return self;if(typeof window<"u")return window;if(typeof global<"u")return global;throw new Error("unable to locate global object")}(),gn=re.fetch||(()=>Promise.reject(new Error("[ofetch] global.fetch is not supported!"))),_n=re.Headers,yn=re.AbortController,L=ke({fetch:gn,Headers:_n,AbortController:yn}),On={apiRoot:process.env.FRONTSTACK_CLI_API_ROOT||(process.env.FRONTSTACK_CLI_DEV_MODE=="1"?"https://backend.frontstack.test/":"https://backend.frontstack.dev/")},q=On.apiRoot,bn=`${q}login`,wn=`${q}api/fetch-api/spec.yaml`,Pe=3008,Re=`http://localhost:${Pe}`,He=`${bn}?redirectUrl=${Re}/callback`,An=".frontstack-local/",S=g.join(process.cwd(),An),ie="api_session.jwt",Ne="project.json",P=l(()=>{const o=l(()=>{console.info("Not auth.login implemented yet")},"login"),e=l(async()=>{try{return a(),0}catch(p){console.log(p)}},"logout"),t=l(async(p=!1)=>{try{return process.env.NODE_TLS_REJECT_UNAUTHORIZED=process.env.FRONTSTACK_CLI_DEV_MODE?"0":"1",await L(`${q}profile`,{method:"GET",headers:{"Content-Type":"application/json",Authorization:`Bearer ${r()}`}})}catch(d){return p&&console.log(d),1}},"getProfile"),n=l(async p=>{try{if(p==null)throw new Error(`You have no project selected
|
|
24
24
|
Run ${f.hex("#7c3bed")("frontstack project")} to select a frontstack project`);return process.env.NODE_TLS_REJECT_UNAUTHORIZED=process.env.FRONTSTACK_CLI_DEV_MODE?"0":"1",await L(wn,{method:"GET",headers:{"Content-Type":"application/yaml",Authorization:`Bearer ${r()}`,"FS-Project":p},parseResponse:l(y=>{try{return me.load(y)}catch{throw new Error("Invalid API specification. The API specification must be a valid YAML file.")}},"parseResponse")})}catch(d){throw"data"in d&&"message"in d.data?new Error(`Server error: ${d.data.message}`):d}},"getFetchApiSpec"),r=l(()=>{const p=g.join(S,ie);return _.existsSync(p)?_.readFileSync(p,"utf8"):null},"getToken"),i=l(p=>(_.existsSync(S)||_.mkdirSync(S),_.writeFileSync(g.join(S,ie),p),0),"writeToken"),a=l(()=>{const p=g.join(S,ie);_.existsSync(p)&&_.unlinkSync(p)},"deleteToken"),u=l(async()=>(process.env.NODE_TLS_REJECT_UNAUTHORIZED=process.env.FRONTSTACK_CLI_DEV_MODE?"0":"1",await L(`${q}api/project`,{method:"GET",headers:{"Content-Type":"application/yaml",Authorization:`Bearer ${r()}`},parseResponse:l(p=>JSON.parse(p),"parseResponse")})),"getProjects"),c=l(()=>{const p=g.join(S,Ne);if(!_.existsSync(p))return null;try{return JSON.parse(_.readFileSync(p,"utf8")).projectId}catch{console.error("[Error] Corrupt project file - please run 'frontstack project'")}},"getProjectId");return{login:o,logout:e,getProfile:t,getFetchApiSpec:n,getToken:r,writeToken:i,deleteToken:a,getProjects:u,getProject:l(async(p=void 0)=>{try{return p===void 0&&(p=c()),p===void 0?void 0:(process.env.NODE_TLS_REJECT_UNAUTHORIZED=process.env.FRONTSTACK_CLI_DEV_MODE?"0":"1",await L(`${q}api/project/${p}`,{method:"GET",headers:{"Content-Type":"application/yaml",Authorization:`Bearer ${r()}`},parseResponse:l(d=>JSON.parse(d),"parseResponse")}))}catch(d){return{error:d.message}}},"getProject"),getProjectId:c,writeProject:l(p=>(_.existsSync(S)||_.mkdirSync(S),_.writeFileSync(g.join(S,Ne),JSON.stringify({projectId:p})),0),"writeProject")}},"auth"),Ie=l(()=>{const o=l(t=>{const n=g.join(t,"metadata.json");if(_.existsSync(n)){const r=_.readFileSync(n,"utf8");return JSON.parse(r)}return null},"getMetadata");return{getMetadata:o,projectGuard:l(t=>{o(t)||(console.log(`${f.hex("#FFA500")("[WARNING]")} No \`${t}/metadata.json\` found, run ${f.hex("#7c3bed")("frontstack generate")} to create a metadata file.`),console.log(`${f.hex("#FFA500")("[WARNING]")} Metadata files have been introduced to keep track of your generated code across multiple projects and organizations.`),console.log(`${f.hex("#FFA500")("[WARNING]")} If you only have a single project, you can ignore this message.`))},"projectGuard")}},"useMetadata"),{writeToken:Cn}=P(),En=l(async(o,e,t=!1)=>new Promise(n=>{const r=new Set,i=et.createServer((a,u)=>{const c=Re;if(a.url===void 0)return;const s=new URL(a.url,c).searchParams.get("token");s&&(u.writeHead(200,{"Content-Type":"text/html"}),u.end('<html><head><script>// window.close()<\/script></head><body style="font-family: sans-serif;"><div style="height: 100%; width: 100%; display: flex; justify-content: center; align-items: center;"><div style="text-align: center"><h1 style="color: #7c3bed;">Login Successful</h1><p>You can <a href="#" onClick="window.close()">close</a> this browser window and return to the terminal.<p style="font-size: .8rem; color: #666; text-align: left; margin-top: 20px;">© 2024 frontstack</p></div></div></html>'),u.on("finish",async()=>{for(const d of r)d.destroy();Cn(s)!==0?(console.error("Login failed."),i.close(),n(!1)):(console.log(`${f.hex("#008000")("[SUCCESS]")} Login successful`),i.close(),n(!0)),t&&process.exit(0)}))}).listen(o,()=>{console.log(`Please continue login in your browser at ${f.hex("#7c3bed")(e)}`)});i.on("connection",a=>{r.add(a),a.on("close",()=>r.delete(a))}),setTimeout(()=>{i.close(),n(!1)},6e4)}),"login$1"),$n={processExit:!0,skipProjectGuard:!1},Fe=l(async o=>{const e=Xe(o,$n);await tt(He),await En(Pe,He,!1);let t=".frontstack";if(e.skipProjectGuard){const{projectGuard:n}=Ie();n(t)}e?.processExit&&process.exit(0)},"login"),vn=P(),Sn=l(async o=>{await vn.logout()!==0&&(console.error("Logout failed."),process.exit(1)),console.log("Logout successful."),process.exit(0)},"logout"),{getFetchApiSpec:jn}=P();$.registerHelper("eq",function(o,e){return o===e}),$.registerHelper("uc",function(o){return o.toUpperCase()}),$.registerHelper("and",function(o,e){return o&&e}),$.registerHelper("contains",function(o,e){return o===void 0?!1:o.includes(e)}),$.registerHelper("endsWith",function(o,e){return o===void 0?!1:o.endsWith(e)}),$.registerHelper("blockNameFromOperationId",function(o){return o.replace("get","").replace("Block","")});const se=l(o=>o.$ref?`components['schemas']['${o.$ref.split("/").pop()}']`:o.type==="array"?`Array<${se(o.items)}>`:o.type==="object"?`{ ${Object.keys(o.properties).map(t=>`${t}: ${se(o.properties[t])}`).join("; ")} }`:o.type,"getSchemaType");$.registerHelper("getSchemaType",o=>se(o)),$.registerHelper("stringInArray",function(o,e,t){return e==null||e.length===0?!1:t.fn?e.indexOf(o)>-1?t.fn(this):t.inverse(this):e.indexOf(o)>-1}),$.registerHelper("log",function(o){console.log(o)});var Tn=l(async o=>{const e=g.dirname(new URL(import.meta.url).pathname),t=g.join(e,"src/commands/generate/templates"),n=g.join(t,"types.js.hbs"),r=_.readFileSync(n,"utf8"),i=$.compile(r),a=g.join(t,"client.js.hbs"),u=_.readFileSync(a,"utf8"),c=$.compile(u),h=g.join(t,"query.js.hbs"),s=_.readFileSync(h,"utf8");let p;if(p=await jn(o),p.error)throw new Error(`Issue fetching API specification. Check more information below.
|
|
25
|
-
`+p.error);let d="";try{d=await nt(p)}catch(b){throw new Error(`Invalid API Specification: ${b.message}`)}const y=i({paths:p.paths,components:p.components}),m=c({components:p.components,paths:p.paths,servers:p.servers});return{_schemaTypes:d,_types:y,_client:m,_query:s,_specFile:p}},"generate");const{getProjects:xn,writeProject:Ve}=P(),De=l(async o=>{let e=o.project??void 0,t=[];try{t=await xn()}catch{console.log(`You are not logged in. Please run ${f.hex("#7c3bed")("frontstack login")} to login`);return}if(t.length<1){console.log("No projects found. Please create a new project in your Admin dashboard");return}if(e!==void 0){const i=t.find(a=>a.id===e);if(i){console.log(`Project ${f.hex("#7c3bed")(i.name)} selected`),Ve(i.id);return}else{console.log(`Project with ID "${e}" not found. Please select a valid project ID`);return}}const n={type:"select",name:"projectId",message:"Pick a project (Use arrow keys and Enter)",choices:t.map(i=>({title:(i.id===e?"(\u2714) ":"")+`${i.name}`,value:i.id}))};async function r(){const i=await U(n),a=t.find(u=>u.id===i.projectId);if(a===void 0){console.log(`Project with ID "${i.projectId}" not found. Please select a valid project ID`);return}console.log(`Project ${f.hex("#7c3bed")(a.name)} selected`),Ve(i.projectId)}l(r,"getProject"),await r()},"project"),kn=l(async o=>{const e=o.verbose||!1,t=o.persistOas||!1,{getProject:n,getProfile:r,getProjects:i,writeProject:a}=P(),u=await r(e);if(!u||u===1){console.info("User not logged in"),await Fe({processExit:!1,skipProjectGuard:!0});const w=await r();(!w||w===1)&&(console.info(`${f.hex("#b90404")("[ERROR]")} Login failed`),process.exit(1))}let c=o.output||".frontstack",h=await n();(!h||"error"in h)&&(console.info("No project selected"),console.info("Running project selection..."),await De({}));const{getMetadata:s}=Ie(),p=s(c);if(h=await n(),!h||"error"in h){console.info(`${f.hex("#b90404")("[ERROR]")} frontstack generate`),console.info(`${f.hex("#b90404")("[ERROR]")} Failed to generate Javascript client`);return}if(p&&p.project.id!==h.id){const C=(await i()).find(B=>B.id===p.project.id),E=[];C&&E.push({title:`Switch to project ${f.hex("#7c3bed")(p.project.name)} and generate client`,value:"switch"}),E.push({title:`Overwrite client with project ${f.hex("#7c3bed")(h.name)}`,value:"overwrite"}),E.push({title:"Cancel",value:"cancel"}),console.log(`${f.hex("#FFA500")("[WARNING]")} Client mismatch detected`),console.log(`${f.hex("#FFA500")("[WARNING]")} The client in ${f.hex("#7c3bed")(c)} was generated for project ${f.hex("#7c3bed")(p.project.name)}.`),console.log(`${f.hex("#FFA500")("[WARNING]")} The selected project is ${f.hex("#7c3bed")(h.name)}.
|
|
25
|
+
`+p.error);let d="";try{d=await nt(p)}catch(b){throw new Error(`Invalid API Specification: ${b.message}`)}const y=i({paths:p.paths,components:p.components}),m=c({components:p.components,paths:p.paths,servers:p.servers});return{_schemaTypes:d,_types:y,_client:m,_query:s,_specFile:p}},"generate");const{getProjects:xn,writeProject:Ve}=P(),De=l(async o=>{let e=o.project??void 0,t=[];try{t=await xn()}catch{console.log(`You are not logged in. Please run ${f.hex("#7c3bed")("frontstack login")} to login`);return}if(t.length<1){console.log("No projects found. Please create a new project in your Admin dashboard");return}if(e!==void 0){const i=t.find(a=>a.id===e);if(i){console.log(`Project ${f.hex("#7c3bed")(i.name)} selected`),Ve(i.id);return}else{console.log(`Project with ID "${e}" not found. Please select a valid project ID`);return}}const n={type:"select",name:"projectId",message:"Pick a project (Use arrow keys and Enter)",choices:t.map(i=>({title:(i.id===e?"(\u2714) ":"")+`${i.name}`,value:i.id}))};async function r(){const i=await U(n),a=t.find(u=>u.id===i.projectId);if(a===void 0){console.log(`Project with ID "${i.projectId}" not found. Please select a valid project ID`);return}console.log(`Project ${f.hex("#7c3bed")(a.name)} selected`),Ve(i.projectId)}l(r,"getProject"),await r()},"project"),kn=l(async o=>{const e=o.verbose||!1,t=o.persistOas||!1,{getProject:n,getProfile:r,getProjects:i,writeProject:a}=P(),u=await r(e);if(!u||u===1){console.info("User not logged in"),await Fe({processExit:!1,skipProjectGuard:!0});const w=await r();(!w||w===1)&&(console.info(`${f.hex("#b90404")("[ERROR]")} Login failed`),process.exit(1))}let c=o.output||".frontstack",h=await n();(!h||"error"in h)&&(console.info("No project selected"),console.info("Running project selection..."),await De({}));const{getMetadata:s}=Ie(),p=s(c);if(h=await n(),!h||"error"in h){console.info(`${f.hex("#b90404")("[ERROR]")} frontstack generate`),console.info(`${f.hex("#b90404")("[ERROR]")} Failed to generate Javascript client`);return}if(p&&p.project.id!==h.id&&!h.environments.some(w=>w.id===p.project.id)){const C=(await i()).find(B=>B.id===p.project.id),E=[];C&&E.push({title:`Switch to project ${f.hex("#7c3bed")(p.project.name)} and generate client`,value:"switch"}),E.push({title:`Overwrite client with project ${f.hex("#7c3bed")(h.name)} (${f.hex("#7c3bed")(h.environment)})`,value:"overwrite"}),E.push({title:"Cancel",value:"cancel"}),console.log(`${f.hex("#FFA500")("[WARNING]")} Client mismatch detected`),console.log(`${f.hex("#FFA500")("[WARNING]")} The client in ${f.hex("#7c3bed")(c)} was generated for project ${f.hex("#7c3bed")(p.project.name)}.`),console.log(`${f.hex("#FFA500")("[WARNING]")} The selected project is ${f.hex("#7c3bed")(h.name)} (${f.hex("#7c3bed")(h.environment)}).
|
|
26
26
|
`);const Ue={type:"select",name:"action",message:"How would you like to proceed?",choices:E},{action:M}=await U(Ue);if(M==="cancel"){console.info("Generation cancelled.");return}if(M==="switch"&&C&&(a(C.id),h=C,console.info(`Switched to project ${f.hex("#7c3bed")(h.name)}.`)),M==="overwrite"){const B={type:"text",name:"confirmation",message:'This is a destructive action and will overwrite the existing client. Type "confirm" to proceed.'},{confirmation:We}=await U(B);if(We!=="confirm"){console.info("Generation cancelled.");return}console.info(`Proceeding to generate client for project ${f.hex("#7c3bed")(h.name)}.`)}if(!M){console.info("Generation cancelled.");return}}let d=h;if(!h||"error"in h){console.info(`${f.hex("#b90404")("[ERROR]")} frontstack generate`),console.info(`${f.hex("#b90404")("[ERROR]")} Failed to generate Javascript client`);return}if(o.env&&h.environments.length>0){let w;if(o.env!=="develop"){if(w=h.environments.find(C=>C.environment===o.env),!w){console.info(`${f.hex("#b90404")("[ERROR]")} frontstack generate`),console.info(`${f.hex("#b90404")("[ERROR]")} Environment ${o.env} not found`);return}d=w}}if(!o.env&&h.environments.length>0){const w={type:"select",name:"projectId",message:"Pick an environment (use arrow keys and enter)",choices:[{title:`${h.name} (${h.environment})`,value:h.id},...h.environments.map(E=>({title:(E.id===d?.id?"(\u2714) ":"")+`${E.name} (${E.environment})`,value:E.id}))]},C=await U(w);d=h.environments.find(E=>E.id===C.projectId)??h}let y,m,b,x,ce;try{e&&console.log("Generating Javascript client"),{_schemaTypes:y,_types:m,_client:b,_query:x,_specFile:ce}=await Tn(d.id)}catch(w){console.info(`${f.hex("#b90404")("[ERROR]")} frontstack generate`),console.info(`${f.hex("#b90404")("[ERROR]")} Failed to generate Javascript client`),e?console.info(`${f.hex("#b90404")("[ERROR]")} ${w.message}`):(console.info("Are you..."),console.info(` * logged in using the ${f.hex("#7c3bed")("frontstack login")} command?`),console.info(" * connected to the internet?"),console.info(`Alternatively, run ${f.hex("#7c3bed")("frontstack generate -v")} for additional output.`));return}process.stdout.write("Generating Javascript client"),c.startsWith("/")||(c=g.join(process.cwd(),c)),c.endsWith("/")||(c+="/");const le=g.join(c,"fetch-api.d.ts"),ue=g.join(c,"generated-types.d.ts"),he=g.join(c,"generated-client.ts"),qe=g.join(c,"query-types.ts"),pe=g.join(c,"metadata.json"),Me={project:{id:d.id,name:d.name}};if(e&&(console.log(`
|
|
27
27
|
Schema types path: ${f.dim(le)}`),console.log(`Types path: ${f.dim(ue)}`),console.log(`Client path: ${f.dim(he)}`),console.log(`Target directory: ${f.dim(c)}`),console.log(`Metadata path: ${f.dim(pe)}`)),_.mkdirSync(c,{recursive:!0}),t){const w=me.dump(ce,{indent:2}),C=g.join(c,"fetch-api.spec.yaml");console.log(`
|
|
28
28
|
Persisting OpenAPI Specification file in ${C}`),_.writeFileSync(g.join(C),w)}_.writeFileSync(g.join(le),y),_.writeFileSync(g.join(ue),m),_.writeFileSync(g.join(he),b),_.writeFileSync(g.join(qe),x),_.writeFileSync(g.join(pe),JSON.stringify(Me,null,2)),e?console.log(`Javascript client generated for ${f.hex("#7c3bed")(`${d.name} (${d.environment})`)}`):(process.stdout.clearLine(0),process.stdout.cursorTo(0),process.stdout.write(f.green(`Javascript client generated for ${f.hex("#7c3bed")(`${d.name} (${d.environment})`)}
|
package/dist/version
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.0.0-canary-
|
|
1
|
+
0.0.0-canary-20251031085239
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@frontstackdev/cli",
|
|
3
|
-
"version": "0.0.0-canary-
|
|
3
|
+
"version": "0.0.0-canary-20251031085239",
|
|
4
4
|
"description": "frontstack CLI for managing projects",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "dist/frontstack.mjs",
|
|
@@ -49,5 +49,6 @@
|
|
|
49
49
|
"openapi-typescript": "^6.7.5",
|
|
50
50
|
"prompts": "^2.4.2",
|
|
51
51
|
"semver": "^7.7.3"
|
|
52
|
-
}
|
|
52
|
+
},
|
|
53
|
+
"packageManager": "pnpm@9.12.3+sha512.cce0f9de9c5a7c95bef944169cc5dfe8741abfb145078c0d508b868056848a87c81e626246cb60967cbd7fd29a6c062ef73ff840d96b3c86c40ac92cf4a813ee"
|
|
53
54
|
}
|