fleetbo-svro 1.0.10 → 1.0.12
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 +27 -17
- package/package.json +1 -1
package/dist/cli.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var U=(t,
|
|
3
|
-
`),g("\u2192 Created svro.schema.json at project root.")}function $(t){let
|
|
2
|
+
var U=(t,s)=>()=>{try{return s||t((s={exports:{}}).exports,s),s.exports}catch(o){throw s=0,o}};var N=U((oe,R)=>{var c=require("fs"),d=require("path"),j=require("https"),{execSync:D}=require("child_process"),C="\x1B[38;2;231;233;237m",L="\x1B[31m",S="\x1B[0m";function g(t){console.log(` ${C}${t}${S}`)}function u(t){console.error(` ${L}${t}${S}`)}function A(t){let s={};return t.forEach(o=>{if(o.startsWith("--")){let[r,l]=o.slice(2).split("=");r&&l&&(s[r]=l)}}),s}function E(t,s){try{let o=JSON.parse(c.readFileSync(t,"utf8"));return!!(o.dependencies&&o.dependencies[s]||o.devDependencies&&o.devDependencies[s])}catch{return!1}}function M(t,s){if(!E(s,"fleetbo-svro")){g("\u2192 Installing fleetbo-svro into the project...");try{D("npm install fleetbo-svro",{cwd:t,stdio:"inherit"}),g("fleetbo-svro installed successfully!")}catch{u("\u26A0\uFE0F Automatic installation failed. Please run 'npm install fleetbo-svro' manually.")}}}function J(t){let s=d.join(t,"svro.schema.json");if(c.existsSync(s))return;let o=new Date().toISOString(),r={createdAt:o,patchedAt:o,schemaVersion:1,collections:{}};c.writeFileSync(s,JSON.stringify(r,null,2)+`
|
|
3
|
+
`),g("\u2192 Created svro.schema.json at project root.")}function $(t){let s=d.join(t,"src");if(!c.existsSync(s))return;let o=d.join(s,"auto-imports.d.ts");if(c.existsSync(o))return;let r=`/* eslint-disable */
|
|
4
4
|
/* prettier-ignore */
|
|
5
5
|
// @ts-nocheck
|
|
6
6
|
// Generated by fleetbo-svro setup
|
|
@@ -57,7 +57,7 @@ declare module 'react' {
|
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
|
-
`;try{c.writeFileSync(o,r),g("\u2192 Created src/auto-imports.d.ts stub for instant IDE auto-completion.")}catch(l){
|
|
60
|
+
`;try{c.writeFileSync(o,r),g("\u2192 Created src/auto-imports.d.ts stub for instant IDE auto-completion.")}catch(l){u(`\u26A0\uFE0F Unable to create src/auto-imports.d.ts: ${l.message}`)}}function B(t){let s=["tsconfig.json","jsconfig.json"];for(let o of s){let r=d.join(t,o);if(c.existsSync(r)){let l=new Date;c.utimesSync(r,l,l);break}}}function W(t){let s=d.join(t,"index.d.ts");if(c.existsSync(s))return;c.writeFileSync(s,`// File generated/synchronized by fleetbo-svro \u2014 do not edit manually
|
|
61
61
|
|
|
62
62
|
export type FleetboTables = string;
|
|
63
63
|
|
|
@@ -231,14 +231,24 @@ declare global {
|
|
|
231
231
|
FleetboUI: typeof FleetboUI;
|
|
232
232
|
}
|
|
233
233
|
}
|
|
234
|
-
`),g("\u2192 Initialized index.d.ts.")}function
|
|
234
|
+
`),g("\u2192 Initialized index.d.ts.")}function H(t){return new Promise((s,o)=>{let r=JSON.stringify({token:t}),l={hostname:"bootstrapproject-jqycakhlxa-uc.a.run.app",path:"/",method:"POST",headers:{"Content-Type":"application/json","Content-Length":Buffer.byteLength(r)}},b=j.request(l,e=>{let a="";e.on("data",n=>{a+=n}),e.on("end",()=>{if(e.statusCode>=200&&e.statusCode<300)try{s(JSON.parse(a))}catch{o(new Error("Invalid response received from Fleetbo server."))}else try{let n=JSON.parse(a);o(new Error(n.error||`Server error ${e.statusCode}`))}catch{o(new Error(`Server error ${e.statusCode}`))}})});b.on("error",e=>o(e)),b.write(r),b.end()})}async function q(t,s=[]){let o=d.join(t,".env");if(c.existsSync(o)&&c.readFileSync(o,"utf8").includes("VITE_FLEETBO_DB_KEY")){g("\u2192 Fleetbo environment variables already present in .env \u2014 skipping step.");return}let r=A(s),l=r.keyApp,b=r.token||r.bootstrapToken,e=r.email||"";(!l||!b)&&(u("\u26A0\uFE0F Missing required parameters."),u("\u{1F449} Usage: npx fleetbo-svro init --keyApp=YOUR_KEY --token=YOUR_TOKEN"),process.exit(1)),g("\u2192 Exchanging bootstrap token for project keys...");let a;try{a=await H(b)}catch(i){u(`\u26A0\uFE0F Token exchange failed: ${i.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)}(!a.enterpriseId||!a.fleetboDBKey)&&(u("\u26A0\uFE0F Incomplete response from Fleetbo server."),process.exit(1));let n=`
|
|
235
235
|
VITE_FLEETBO_DB_KEY=${a.fleetboDBKey}
|
|
236
236
|
VITE_FLEETBO_ENTERPRISE_ID=${a.enterpriseId}
|
|
237
237
|
VITE_FLEETBO_KEY_APP=${l}
|
|
238
238
|
${e?`VITE_FLEETBO_TESTER_EMAIL=${e}
|
|
239
|
-
`:""}`;c.appendFileSync(o,
|
|
240
|
-
`),g(`\u2192 Updated ${d.basename(l)}.`))}function O(t,
|
|
239
|
+
`:""}`;c.appendFileSync(o,n),g(".env file updated successfully with Fleetbo keys!")}function x(t){let s=d.join(t,"svro.d.ts");if(c.existsSync(s))try{c.unlinkSync(s),g("\u2192 Removed legacy svro.d.ts from project root.")}catch{}}function k(t,s){if(process.env.FLEETBO_SKIP_TYPECHECK_SETUP)return;let o=d.join(t,"tsconfig.json"),r=d.join(t,"jsconfig.json"),l=c.existsSync(o)?o:r,b=!c.existsSync(l),e={};if(!b)try{e=JSON.parse(c.readFileSync(l,"utf8"))}catch{u(`\u26A0\uFE0F Unable to read ${d.basename(l)} (Invalid JSON).`);return}e.compilerOptions=e.compilerOptions||{};let a=!1,n=E(s,"react"),i=E(s,"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"],a=!0):(e.compilerOptions.checkJs===void 0&&(e.compilerOptions.checkJs=!0,a=!0),e.compilerOptions.allowJs===void 0&&(e.compilerOptions.allowJs=!0,a=!0)),n&&e.compilerOptions.jsx===void 0&&(e.compilerOptions.jsx="react-jsx",a=!0),i&&e.compilerOptions.types===void 0&&(e.compilerOptions.types=["vite/client"],a=!0),a&&(c.writeFileSync(l,JSON.stringify(e,null,2)+`
|
|
240
|
+
`),g(`\u2192 Updated ${d.basename(l)}.`))}function O(t,s){if(process.env.FLEETBO_SKIP_AUTOIMPORT_SETUP)return;let r=["vite.config.ts","vite.config.js","vite.config.mjs"].map(n=>d.join(t,n)).find(n=>c.existsSync(n));if(!r)return;let l;try{l=c.readFileSync(r,"utf8")}catch{return}let b="fleetbo-svro",e=l,a=`{
|
|
241
241
|
name: 'fleetbo-schema-sync-middleware',
|
|
242
|
+
transformIndexHtml() {
|
|
243
|
+
return [
|
|
244
|
+
{
|
|
245
|
+
tag: 'script',
|
|
246
|
+
attrs: { type: 'module' },
|
|
247
|
+
children: "import 'fleetbo-svro';",
|
|
248
|
+
injectTo: 'head-prepend'
|
|
249
|
+
}
|
|
250
|
+
];
|
|
251
|
+
},
|
|
242
252
|
configureServer(server) {
|
|
243
253
|
server.middlewares.use('/__fleetbo_sync_schema', (req, res) => {
|
|
244
254
|
if (req.method === 'POST') {
|
|
@@ -280,22 +290,22 @@ ${e?`VITE_FLEETBO_TESTER_EMAIL=${e}
|
|
|
280
290
|
watch: {
|
|
281
291
|
ignored: ['**/svro.schema.json', '**/src/auto-imports.d.ts']
|
|
282
292
|
}
|
|
283
|
-
},`))),e.includes("unplugin-auto-import"))e.includes("fleetbo-svro")&&!e.includes("FleetboUI")&&(e=e.replace(/imports\s*:\s*\[\s*\{\s*['"]fleetbo-svro(?:|\/vue)['"]\s*:\s*\[[^\]]*\]\s*\}\s*\]/g,`imports: [{ '${b}': ['Fleetbo', 'FleetboUI'] }]`));else{let
|
|
293
|
+
},`))),e.includes("unplugin-auto-import"))e.includes("fleetbo-svro")&&!e.includes("FleetboUI")&&(e=e.replace(/imports\s*:\s*\[\s*\{\s*['"]fleetbo-svro(?:|\/vue)['"]\s*:\s*\[[^\]]*\]\s*\}\s*\]/g,`imports: [{ '${b}': ['Fleetbo', 'FleetboUI'] }]`));else{let n=e.match(/plugins\s*:\s*\[/);if(n){let i=n.index+n[0].length,h=`
|
|
284
294
|
AutoImport({
|
|
285
295
|
imports: [{ '${b}': ['Fleetbo', 'FleetboUI'] }],
|
|
286
296
|
dts: 'src/auto-imports.d.ts'
|
|
287
297
|
}),`;if(e=e.slice(0,i)+h+e.slice(i),!e.includes("import AutoImport")){let T=[...e.matchAll(/^import .+;?$/gm)].pop(),v=`import AutoImport from 'unplugin-auto-import/vite';
|
|
288
298
|
`;if(T){let p=T.index+T[0].length;e=e.slice(0,p)+`
|
|
289
|
-
`+v+e.slice(p)}else e=v+e}}}if(e.includes("
|
|
290
|
-
`+a+e.slice(i)}}if(e!==l)try{c.writeFileSync(r,e),g(`\u2192 Updated ${d.basename(r)} with Watcher and AutoImport configuration.`)}catch(
|
|
291
|
-
`),g("\u2192 Added unplugin-auto-import to devDependencies."))}catch(
|
|
292
|
-
`).forEach(l=>{let[b,...e]=l.split("=");b&&e.length>0&&(r[b.trim()]=e.join("=").trim())}),r}function
|
|
293
|
-
[Fleetbo] Initializing and configuring Fleetbo...`),await Y(t,I),K(t,
|
|
299
|
+
`+v+e.slice(p)}else e=v+e}}}if(e.includes("fleetbo-schema-sync-middleware")||e.includes("__fleetbo_sync_schema")){let n=/\{\s*name:\s*['"]fleetbo-schema-sync-middleware['"][\s\S]*?\},/g;!e.includes("transformIndexHtml")&&n.test(e)&&(e=e.replace(n,a),g("\u2192 Updated Fleetbo Vite plugin with universal runtime injection."))}else{let n=e.match(/plugins\s*:\s*\[/);if(n){let i=n.index+n[0].length;e=e.slice(0,i)+`
|
|
300
|
+
`+a+e.slice(i)}}if(e!==l)try{c.writeFileSync(r,e),g(`\u2192 Updated ${d.basename(r)} with Watcher and AutoImport configuration.`)}catch(n){u(`\u26A0\uFE0F Failed to write to ${d.basename(r)}: ${n.message}`)}try{let n=JSON.parse(c.readFileSync(s,"utf8"));n.devDependencies=n.devDependencies||{},n.devDependencies["unplugin-auto-import"]||(n.devDependencies["unplugin-auto-import"]="^0.18.0",c.writeFileSync(s,JSON.stringify(n,null,2)+`
|
|
301
|
+
`),g("\u2192 Added unplugin-auto-import to devDependencies."))}catch(n){u(`\u26A0\uFE0F Failed to update ${d.basename(s)}: ${n.message}`)}}function V(t,s,o={}){let{skipSelfInstall:r=!1}=o,l=d.join(__dirname,"..");r||M(t,s),J(t),W(l),$(t),x(t),k(t,s),O(t,s)}R.exports={touchTsConfig:B,log:g,logError:u,handleAuthAndEnv:q,detectDependency:E,cleanupLegacyRootDts:x,patchJsOrTsConfig:k,attemptViteAutoImportPatch:O,runFullSetup:V}});var m=require("fs"),y=require("path"),w=require("https"),{runFullSetup:K,handleAuthAndEnv:Y,touchTsConfig:X,attemptViteAutoImportPatch:G}=N(),z="\x1B[34m",Q="\x1B[31m",_="\x1B[0m";function f(t){console.log(`${z}${t}${_}`)}function F(t){console.error(`${Q}${t}${_}`)}function Z(t,s){return new Promise((o,r)=>{let l=JSON.stringify({enterpriseID:t,schema:s}),b={hostname:"fleetbo-gatekeeper.fleetbo.workers.dev",path:"/sync-schema",method:"POST",headers:{"Content-Type":"application/json","Content-Length":Buffer.byteLength(l)}},e=w.request(b,a=>{let n="";a.on("data",i=>{n+=i}),a.on("end",()=>{a.statusCode>=200&&a.statusCode<300?o(JSON.parse(n)):r(new Error(`Edge sync failed with HTTP ${a.statusCode}`))})});e.on("error",a=>r(a)),e.write(l),e.end()})}function ee(t){let s=y.join(t,".env");if(!m.existsSync(s))return{};let o=m.readFileSync(s,"utf8"),r={};return o.split(`
|
|
302
|
+
`).forEach(l=>{let[b,...e]=l.split("=");b&&e.length>0&&(r[b.trim()]=e.join("=").trim())}),r}function te(t){return new Promise((s,o)=>{let r=JSON.stringify({projectId:t,moduleName:"svro.schema.json"}),l={hostname:"getmodulecache-jqycakhlxa-uc.a.run.app",path:"/",method:"POST",headers:{"Content-Type":"application/json","Content-Length":Buffer.byteLength(r)}},b=w.request(l,e=>{let a="";e.on("data",n=>{a+=n}),e.on("end",()=>{if(e.statusCode>=200&&e.statusCode<300)try{let n=JSON.parse(a);if(n.success&&n.found&&n.module){let i=n.module.code||n.module.mockCode;s(typeof i=="string"?JSON.parse(i):i)}else o(new Error("Schema not found in Fleetbo Cloud."))}catch{o(new Error("Invalid JSON response received from Fleetbo server."))}else o(new Error(`Server error ${e.statusCode}`))})});b.on("error",e=>o(e)),b.write(r),b.end()})}var I=process.argv.slice(2),P=I[0];async function se(){let t=process.cwd(),s=y.join(t,"package.json");if(P==="init"||P==="doctor")f(`
|
|
303
|
+
[Fleetbo] Initializing and configuring Fleetbo...`),await Y(t,I),K(t,s),f(`
|
|
294
304
|
[Fleetbo] Configuration completed successfully!
|
|
295
|
-
`),
|
|
296
|
-
Next step:`),
|
|
297
|
-
`);else if(P==="sync"){let o=I.includes("--dry-run");
|
|
298
|
-
`),
|
|
305
|
+
`),f(`
|
|
306
|
+
Next step:`),f(` npx fleetbo-svro sync (Sync cloud schema & generate IDE types)
|
|
307
|
+
`);else if(P==="sync"){let o=I.includes("--dry-run");f(`[Fleetbo] Syncing schema...${o?" (dry-run)":""}`);let r=y.join(t,"svro.schema.json"),l=y.join(__dirname,".."),b=y.join(l,"index.d.ts"),e=y.join(t,"src","auto-imports.d.ts"),n=ee(t).VITE_FLEETBO_ENTERPRISE_ID;if(n)try{f("\u2192 Fetching latest svro.schema.json from Fleetbo OS...");let i=await te(n);m.writeFileSync(r,JSON.stringify(i,null,2)+`
|
|
308
|
+
`),f("\u2192 Local svro.schema.json updated from FLeetbo OS.")}catch(i){F(`\u26A0\uFE0F Cloud fetch bypassed: ${i.message}. Using local file fallback.`)}else F("\u26A0\uFE0F VITE_FLEETBO_ENTERPRISE_ID missing in .env. Skipping cloud fetch.");m.existsSync(r)||(F("Error: svro.schema.json not found."),process.exit(1));try{let i=JSON.parse(m.readFileSync(r,"utf8")),h=Object.keys(i.collections||{});if(n)try{await Z(n,i),f("\u2192 Schema successfully sealed at Fleetbo Global Edge (O(1)).")}catch(p){F(`\u26A0\uFE0F Fleetbo Edge Shield sync warning: ${p.message}`)}let T=h.length>0?h.map(p=>`'${p}'`).join(" | "):"string",v=`// Generated by fleetbo-svro \u2014 Updated via fleetbo sql sync
|
|
299
309
|
|
|
300
310
|
export type FleetboTables = ${T};
|
|
301
311
|
|
|
@@ -526,4 +536,4 @@ declare module 'react' {
|
|
|
526
536
|
}
|
|
527
537
|
}
|
|
528
538
|
}
|
|
529
|
-
`;m.writeFileSync(e,p)}X(t),
|
|
539
|
+
`;m.writeFileSync(e,p)}X(t),G(t,s),f(`[Fleetbo] Schema synced successfully (${h.length} collection(s)).`),o&&f("\u2192 [Dry-run] Schema is valid.")}catch(i){F(`Error during synchronization: ${i.message}`),process.exit(1)}}else F('Unknown command. Usage: "npx fleetbo-svro init" or "npx fleetbo-svro sync"'),process.exit(1)}se().catch(t=>{F(`Fleetbo CLI Error: ${t.message}`),process.exit(1)});
|