fleetbo-svro 1.0.21 → 1.0.22
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.cjs +20 -21
- package/package.json +1 -1
package/dist/cli.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var J=(t,o)=>()=>{try{return o||t((o={exports:{}}).exports,o),o.exports}catch(n){throw o=0,n}};var _=J((le,
|
|
3
|
-
`),f("\u2192 Created svro.schema.json at project root.")}function M(t){let o=p.join(t,"src");if(!
|
|
2
|
+
var J=(t,o)=>()=>{try{return o||t((o={exports:{}}).exports,o),o.exports}catch(n){throw o=0,n}};var _=J((le,w)=>{var c=require("fs"),p=require("path"),L=require("https"),{execSync:A}=require("child_process"),$="\x1B[38;2;231;233;237m",N="\x1B[31m",T="\x1B[0m";function f(t){console.log(` ${$}${t}${T}`)}function u(t){console.error(` ${N}${t}${T}`)}function D(t){let o={};return t.forEach(n=>{if(n.startsWith("--")){let[r,s]=n.slice(2).split("=");r&&s&&(o[r]=s)}}),o}function E(t,o){try{let n=JSON.parse(c.readFileSync(t,"utf8"));return!!(n.dependencies&&n.dependencies[o]||n.devDependencies&&n.devDependencies[o])}catch{return!1}}function U(t,o){if(!E(o,"fleetbo-svro")){f("\u2192 Installing fleetbo-svro into the project...");try{A("npm install fleetbo-svro",{cwd:t,stdio:"inherit"}),f("fleetbo-svro installed successfully!")}catch{u("\u26A0\uFE0F Automatic installation failed. Please run 'npm install fleetbo-svro' manually.")}}}function B(t){let o=p.join(t,"svro.schema.json");if(c.existsSync(o))return;let n=new Date().toISOString(),r={createdAt:n,patchedAt:n,schemaVersion:1,collections:{}};c.writeFileSync(o,JSON.stringify(r,null,2)+`
|
|
3
|
+
`),f("\u2192 Created svro.schema.json at project root.")}function M(t){let o=p.join(t,"src");if(!c.existsSync(o))return;let n=p.join(o,"auto-imports.d.ts");if(c.existsSync(n))return;let r=`/* eslint-disable */
|
|
4
4
|
/* prettier-ignore */
|
|
5
5
|
// @ts-nocheck
|
|
6
6
|
// Generated by fleetbo-svro setup
|
|
@@ -110,15 +110,15 @@ declare module 'svelte/elements' {
|
|
|
110
110
|
'fleetbo-reference': FleetboProp;
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
|
-
`;try{
|
|
113
|
+
`;try{c.writeFileSync(n,r),f("\u2192 Created src/auto-imports.d.ts stub for instant IDE auto-completion.")}catch(s){u(`\u26A0\uFE0F Unable to create src/auto-imports.d.ts: ${s.message}`)}}function q(t){let o=p.join(t,"index.d.ts");c.existsSync(o)||f("\u2192 Verified index.d.ts presence.")}function V(t){let o=["tsconfig.json","jsconfig.json"];for(let n of o){let r=p.join(t,n);if(c.existsSync(r)){let s=new Date;c.utimesSync(r,s,s);break}}}function H(t){return new Promise((o,n)=>{let r=JSON.stringify({token:t}),s={hostname:"bootstrapproject-jqycakhlxa-uc.a.run.app",path:"/",method:"POST",headers:{"Content-Type":"application/json","Content-Length":Buffer.byteLength(r)}},b=L.request(s,e=>{let i="";e.on("data",l=>{i+=l}),e.on("end",()=>{if(e.statusCode>=200&&e.statusCode<300)try{o(JSON.parse(i))}catch{n(new Error("Invalid response received from Fleetbo server."))}else try{let l=JSON.parse(i);n(new Error(l.error||`Server error ${e.statusCode}`))}catch{n(new Error(`Server error ${e.statusCode}`))}})});b.on("error",e=>n(e)),b.write(r),b.end()})}async function W(t,o=[]){let n=p.join(t,".env");if(c.existsSync(n)&&c.readFileSync(n,"utf8").includes("VITE_FLEETBO_DB_KEY")){f("\u2192 Fleetbo environment variables already present in .env \u2014 skipping step.");return}let r=D(o),s=r.keyApp,b=r.token||r.bootstrapToken,e=r.email||"";(!s||!b)&&(u("\u26A0\uFE0F Missing required parameters."),u("\u{1F449} Usage: npx fleetbo-svro init --keyApp=YOUR_KEY --token=YOUR_TOKEN"),process.exit(1)),f("\u2192 Exchanging bootstrap token for project keys...");let i;try{i=await H(b)}catch(a){u(`\u26A0\uFE0F Token exchange failed: ${a.message}`),u("\u{1F449} The token may have expired (15 min limit) or was already used. Please regenerate one from the Fleetbo dashboard."),process.exit(1)}(!i.enterpriseId||!i.fleetboDBKey)&&(u("\u26A0\uFE0F Incomplete response from Fleetbo server."),process.exit(1));let l=`
|
|
114
114
|
VITE_FLEETBO_DB_KEY=${i.fleetboDBKey}
|
|
115
115
|
VITE_FLEETBO_ENTERPRISE_ID=${i.enterpriseId}
|
|
116
|
-
VITE_FLEETBO_KEY_APP=${
|
|
116
|
+
VITE_FLEETBO_KEY_APP=${s}
|
|
117
117
|
${e?`VITE_FLEETBO_TESTER_EMAIL=${e}
|
|
118
|
-
`:""}`;
|
|
119
|
-
`),f(`\u2192 Updated ${p.basename(
|
|
120
|
-
`):
|
|
121
|
-
`+
|
|
118
|
+
`:""}`;c.appendFileSync(n,l),f(".env file updated successfully with Fleetbo keys!")}function O(t){let o=p.join(t,"svro.d.ts");if(c.existsSync(o))try{c.unlinkSync(o),f("\u2192 Removed legacy svro.d.ts from project root.")}catch{}}function I(t,o){if(process.env.FLEETBO_SKIP_TYPECHECK_SETUP)return;let n=p.join(t,"tsconfig.json"),r=p.join(t,"jsconfig.json"),s=c.existsSync(n)?n:r,b=!c.existsSync(s),e={};if(!b)try{e=JSON.parse(c.readFileSync(s,"utf8"))}catch{u(`\u26A0\uFE0F Unable to read ${p.basename(s)} (Invalid JSON).`);return}e.compilerOptions=e.compilerOptions||{};let i=!1,l=E(o,"react"),a=E(o,"vite");b?(e.compilerOptions.checkJs=!0,e.compilerOptions.allowJs=!0,e.compilerOptions.target=e.compilerOptions.target||"ES2020",e.compilerOptions.module=e.compilerOptions.module||"ESNext",e.compilerOptions.moduleResolution=e.compilerOptions.moduleResolution||"bundler",e.include=e.include||["src"],i=!0):(e.compilerOptions.checkJs===void 0&&(e.compilerOptions.checkJs=!0,i=!0),e.compilerOptions.allowJs===void 0&&(e.compilerOptions.allowJs=!0,i=!0)),l&&e.compilerOptions.jsx===void 0&&(e.compilerOptions.jsx="react-jsx",i=!0),a&&e.compilerOptions.types===void 0&&(e.compilerOptions.types=["vite/client"],i=!0),i&&(c.writeFileSync(s,JSON.stringify(e,null,2)+`
|
|
119
|
+
`),f(`\u2192 Updated ${p.basename(s)}.`))}function j(t){let o=["src/app/layout.tsx","src/app/layout.jsx","app/layout.tsx","app/layout.jsx","src/pages/_app.tsx","src/pages/_app.jsx","pages/_app.tsx","pages/_app.jsx","src/main.tsx","src/main.jsx","src/main.ts","src/main.js","src/index.tsx","src/index.jsx","src/index.ts","src/index.js","src/App.tsx","src/App.jsx","src/App.vue","app.vue","src/routes/+layout.svelte","src/routes/+layout.ts","src/main.singletons.ts"];for(let n of o){let r=p.join(t,n);if(c.existsSync(r)){let s=c.readFileSync(r,"utf8");s.includes("fleetbo-svro")||(s.startsWith('"use client"')||s.startsWith("'use client'")?s=s.replace(/(['"]use client['"];?\r?\n)/,`$1import 'fleetbo-svro';
|
|
120
|
+
`):s=`import 'fleetbo-svro';
|
|
121
|
+
`+s,c.writeFileSync(r,s));return}}}function k(t,o){if(process.env.FLEETBO_SKIP_AUTOIMPORT_SETUP)return;let r=["vite.config.ts","vite.config.js","vite.config.mjs"].map(l=>p.join(t,l)).find(l=>c.existsSync(l));if(!r)return;let s;try{s=c.readFileSync(r,"utf8")}catch{return}let b="fleetbo-svro",e=s,i=`{
|
|
122
122
|
name: 'fleetbo-auto-runtime',
|
|
123
123
|
transform(code, id) {
|
|
124
124
|
if (!id.includes('node_modules') && !code.includes('fleetbo-svro') && /(src[\\\\/](main|index|App|root))\\.(jsx?|tsx?|vue|svelte)/i.test(id)) {
|
|
@@ -170,22 +170,21 @@ ${e?`VITE_FLEETBO_TESTER_EMAIL=${e}
|
|
|
170
170
|
watch: {
|
|
171
171
|
ignored: ['**/svro.schema.json', '**/src/auto-imports.d.ts']
|
|
172
172
|
}
|
|
173
|
-
},`))),!e.includes("unplugin-auto-import")){let
|
|
173
|
+
},`))),!e.includes("unplugin-auto-import")){let l=e.match(/plugins\s*:\s*\[/);if(l){let a=l.index+l[0].length,y=`
|
|
174
174
|
AutoImport({
|
|
175
|
-
imports: [{ '${b}': ['Fleetbo'] }],
|
|
175
|
+
imports: [{ '${b}': ['Fleetbo', 'FleetboUI'] }],
|
|
176
176
|
dts: 'src/auto-imports.d.ts'
|
|
177
|
-
}),`;if(e=e.slice(0,
|
|
177
|
+
}),`;if(e=e.slice(0,a)+y+e.slice(a),!e.includes("import AutoImport")){let h=[...e.matchAll(/^import .+;?$/gm)].pop(),v=`import AutoImport from 'unplugin-auto-import/vite';
|
|
178
178
|
`;if(h){let m=h.index+h[0].length;e=e.slice(0,m)+`
|
|
179
|
-
`+v+e.slice(m)}else e=v+e}}}if(!e.includes("fleetbo-auto-runtime")){let
|
|
180
|
-
`+i+e.slice(
|
|
181
|
-
`)
|
|
182
|
-
|
|
183
|
-
[Fleetbo] Initializing and configuring Fleetbo...`),await G(t,x),K(t,o),u(`
|
|
179
|
+
`+v+e.slice(m)}else e=v+e}}}if(!e.includes("fleetbo-auto-runtime")){let l=e.match(/plugins\s*:\s*\[/);if(l){let a=l.index+l[0].length;e=e.slice(0,a)+`
|
|
180
|
+
`+i+e.slice(a)}}e!==s&&c.writeFileSync(r,e)}function X(t,o,n={}){let{skipSelfInstall:r=!1}=n,s=p.join(__dirname,"..");r||U(t,o),B(t),q(s),M(t),O(t),I(t,o),k(t,o),j(t)}w.exports={touchTsConfig:V,log:f,logError:u,handleAuthAndEnv:W,detectDependency:E,cleanupLegacyRootDts:O,patchJsOrTsConfig:I,attemptViteAutoImportPatch:k,injectUniversalRuntime:j,runFullSetup:X}});var g=require("fs"),F=require("path"),R=require("https"),{runFullSetup:K,handleAuthAndEnv:G,touchTsConfig:Y,attemptViteAutoImportPatch:z,injectUniversalRuntime:Q}=_(),Z="\x1B[34m",ee="\x1B[31m",C="\x1B[0m";function d(t){console.log(`${Z}${t}${C}`)}function P(t){console.error(`${ee}${t}${C}`)}function te(t,o){return new Promise((n,r)=>{let s=JSON.stringify({enterpriseID:t,schema:o}),b={hostname:"fleetbo-gatekeeper.fleetbo.workers.dev",path:"/sync-schema",method:"POST",headers:{"Content-Type":"application/json","Content-Length":Buffer.byteLength(s)}},e=R.request(b,i=>{let l="";i.on("data",a=>{l+=a}),i.on("end",()=>{i.statusCode>=200&&i.statusCode<300?n(JSON.parse(l)):r(new Error(`Edge sync failed with HTTP ${i.statusCode}`))})});e.on("error",i=>r(i)),e.write(s),e.end()})}function oe(t){let o=F.join(t,".env");if(!g.existsSync(o))return{};let n=g.readFileSync(o,"utf8"),r={};return n.split(`
|
|
181
|
+
`).forEach(s=>{let[b,...e]=s.split("=");b&&e.length>0&&(r[b.trim()]=e.join("=").trim())}),r}function ne(t){return new Promise((o,n)=>{let r=JSON.stringify({projectId:t,moduleName:"svro.schema.json"}),s={hostname:"getmodulecache-jqycakhlxa-uc.a.run.app",path:"/",method:"POST",headers:{"Content-Type":"application/json","Content-Length":Buffer.byteLength(r)}},b=R.request(s,e=>{let i="";e.on("data",l=>{i+=l}),e.on("end",()=>{if(e.statusCode>=200&&e.statusCode<300)try{let l=JSON.parse(i);if(l.success&&l.found&&l.module){let a=l.module.code||l.module.mockCode;o(typeof a=="string"?JSON.parse(a):a)}else n(new Error("Schema not found in Fleetbo Cloud."))}catch{n(new Error("Invalid JSON response received from Fleetbo server."))}else n(new Error(`Server error ${e.statusCode}`))})});b.on("error",e=>n(e)),b.write(r),b.end()})}var S=process.argv.slice(2),x=S[0];async function re(){let t=process.cwd(),o=F.join(t,"package.json");if(x==="init"||x==="doctor")d(`
|
|
182
|
+
[Fleetbo] Initializing and configuring Fleetbo...`),await G(t,S),K(t,o),d(`
|
|
184
183
|
[Fleetbo] Configuration completed successfully!
|
|
185
|
-
`),
|
|
186
|
-
Next step:`),
|
|
187
|
-
`);else if(
|
|
188
|
-
`),
|
|
184
|
+
`),d(`
|
|
185
|
+
Next step:`),d(` npx fleetbo-svro sync (Sync cloud schema & generate IDE types)
|
|
186
|
+
`);else if(x==="sync"){let n=S.includes("--dry-run");d(`[Fleetbo] Syncing schema...${n?" (dry-run)":""}`);let r=F.join(t,"svro.schema.json"),s=F.join(__dirname,".."),b=F.join(s,"index.d.ts"),e=F.join(t,"src","auto-imports.d.ts"),l=oe(t).VITE_FLEETBO_ENTERPRISE_ID;if(l)try{d("\u2192 Fetching latest svro.schema.json from Fleetbo OS...");let a=await ne(l);g.writeFileSync(r,JSON.stringify(a,null,2)+`
|
|
187
|
+
`),d("\u2192 Local svro.schema.json updated from FLeetbo OS.")}catch(a){P(`\u26A0\uFE0F Cloud fetch bypassed: ${a.message}. Using local file fallback.`)}else P("\u26A0\uFE0F VITE_FLEETBO_ENTERPRISE_ID missing in .env. Skipping cloud fetch.");g.existsSync(r)||(P("Error: svro.schema.json not found."),process.exit(1));try{let a=JSON.parse(g.readFileSync(r,"utf8")),y=Object.keys(a.collections||{});if(l)try{await te(l,a),d("\u2192 Schema successfully sealed at Fleetbo Global Edge (O(1)).")}catch(m){P(`\u26A0\uFE0F Fleetbo Edge Shield sync warning: ${m.message}`)}let h=y.length>0?y.map(m=>`'${m}'`).join(" | "):"string",v=`// Generated by fleetbo-svro \u2014 Updated via fleetbo sync
|
|
189
188
|
|
|
190
189
|
export type FleetboTables = ${h};
|
|
191
190
|
|
|
@@ -500,4 +499,4 @@ declare module 'svelte/elements' {
|
|
|
500
499
|
'fleetbo-reference': FleetboProp;
|
|
501
500
|
}
|
|
502
501
|
}
|
|
503
|
-
`;g.writeFileSync(e,m)}Y(t),z(t,o),Q(t),
|
|
502
|
+
`;g.writeFileSync(e,m)}Y(t),z(t,o),Q(t),d(`[Fleetbo] Schema synced successfully (${y.length} collection(s)).`),n&&d("\u2192 [Dry-run] Schema is valid.")}catch(a){P(`Error during synchronization: ${a.message}`),process.exit(1)}}else P('Unknown command. Usage: "npx fleetbo-svro init" or "npx fleetbo-svro sync"'),process.exit(1)}re().catch(t=>{P(`Fleetbo CLI Error: ${t.message}`),process.exit(1)});
|