fleetbo-svro 1.0.27 → 1.0.28
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 +16 -15
- package/package.json +1 -1
package/dist/cli.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var N=(t,o)=>()=>{try{return o||t((o={exports:{}}).exports,o),o.exports}catch(n){throw o=0,n}};var C=N((
|
|
3
|
-
`),f("\u2192 Created svro.schema.json at project root.")}function q(t){let o=p.join(t,"src");if(!
|
|
2
|
+
var N=(t,o)=>()=>{try{return o||t((o={exports:{}}).exports,o),o.exports}catch(n){throw o=0,n}};var C=N((ie,k)=>{var a=require("fs"),p=require("path"),J=require("https"),{execSync:L}=require("child_process"),A="\x1B[38;2;231;233;237m",$="\x1B[31m",T="\x1B[0m";function f(t){console.log(` ${A}${t}${T}`)}function u(t){console.error(` ${$}${t}${T}`)}function D(t){let o={};return t.forEach(n=>{if(n.startsWith("--")){let[s,r]=n.slice(2).split("=");s&&r&&(o[s]=r)}}),o}function S(t,o){try{let n=JSON.parse(a.readFileSync(t,"utf8"));return!!(n.dependencies&&n.dependencies[o]||n.devDependencies&&n.devDependencies[o])}catch{return!1}}function U(t,o){if(!S(o,"fleetbo-svro")){f("\u2192 Installing fleetbo-svro into the project...");try{L("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(a.existsSync(o))return;let n=new Date().toISOString(),s={createdAt:n,patchedAt:n,schemaVersion:1,collections:{}};a.writeFileSync(o,JSON.stringify(s,null,2)+`
|
|
3
|
+
`),f("\u2192 Created svro.schema.json at project root.")}function q(t){let o=p.join(t,"src");if(!a.existsSync(o))return;let n=p.join(o,"fleetbo.d.ts");if(a.existsSync(n))return;let s=`/* eslint-disable */
|
|
4
4
|
/* prettier-ignore */
|
|
5
5
|
// @ts-nocheck
|
|
6
6
|
export {}
|
|
@@ -84,15 +84,15 @@ declare module 'react' {
|
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
|
-
`;try{
|
|
87
|
+
`;try{a.writeFileSync(n,s),f("\u2192 Created src/fleetbo.d.ts stub for instant IDE auto-completion.")}catch(r){u(`\u26A0\uFE0F Unable to create src/fleetbo.d.ts: ${r.message}`)}}function M(t){let o=p.join(t,"index.d.ts");a.existsSync(o)||f("\u2192 Verified index.d.ts presence.")}function V(t){let o=["tsconfig.json","jsconfig.json"];for(let n of o){let s=p.join(t,n);if(a.existsSync(s)){let r=new Date;a.utimesSync(s,r,r);break}}}function H(t){return new Promise((o,n)=>{let s=JSON.stringify({token:t}),r={hostname:"bootstrapproject-jqycakhlxa-uc.a.run.app",path:"/",method:"POST",headers:{"Content-Type":"application/json","Content-Length":Buffer.byteLength(s)}},b=J.request(r,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(s),b.end()})}async function W(t,o=[]){let n=p.join(t,".env");if(a.existsSync(n)&&a.readFileSync(n,"utf8").includes("VITE_FLEETBO_DB_KEY")){f("\u2192 Fleetbo environment variables already present in .env \u2014 skipping step.");return}let s=D(o),r=s.keyApp,b=s.token||s.bootstrapToken,e=s.email||"";(!r||!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(c){u(`\u26A0\uFE0F Token exchange failed: ${c.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=`
|
|
88
88
|
VITE_FLEETBO_DB_KEY=${i.fleetboDBKey}
|
|
89
89
|
VITE_FLEETBO_ENTERPRISE_ID=${i.enterpriseId}
|
|
90
90
|
VITE_FLEETBO_KEY_APP=${r}
|
|
91
91
|
${e?`VITE_FLEETBO_TESTER_EMAIL=${e}
|
|
92
|
-
`:""}`;
|
|
93
|
-
`),f(`\u2192 Updated ${p.basename(r)}.`))}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 s=p.join(t,n);if(
|
|
92
|
+
`:""}`;a.appendFileSync(n,l),f(".env file updated successfully with Fleetbo keys!")}function O(t){let o=p.join(t,"svro.d.ts");if(a.existsSync(o))try{a.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"),s=p.join(t,"jsconfig.json"),r=a.existsSync(n)?n:s,b=!a.existsSync(r),e={};if(!b)try{e=JSON.parse(a.readFileSync(r,"utf8"))}catch{u(`\u26A0\uFE0F Unable to read ${p.basename(r)} (Invalid JSON).`);return}e.compilerOptions=e.compilerOptions||{};let i=!1,l=S(o,"react"),c=S(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),c&&e.compilerOptions.types===void 0&&(e.compilerOptions.types=["vite/client"],i=!0),i&&(a.writeFileSync(r,JSON.stringify(e,null,2)+`
|
|
93
|
+
`),f(`\u2192 Updated ${p.basename(r)}.`))}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 s=p.join(t,n);if(a.existsSync(s)){let r=a.readFileSync(s,"utf8");r.includes("fleetbo-svro")||(r.startsWith('"use client"')||r.startsWith("'use client'")?r=r.replace(/(['"]use client['"];?\r?\n)/,`$1import 'fleetbo-svro';
|
|
94
94
|
`):r=`import 'fleetbo-svro';
|
|
95
|
-
`+r,
|
|
95
|
+
`+r,a.writeFileSync(s,r));return}}}function w(t,o){if(process.env.FLEETBO_SKIP_AUTOIMPORT_SETUP)return;let s=["vite.config.ts","vite.config.js","vite.config.mjs"].map(l=>p.join(t,l)).find(l=>a.existsSync(l));if(!s)return;let r;try{r=a.readFileSync(s,"utf8")}catch{return}let b="fleetbo-svro",e=r,i=`{
|
|
96
96
|
name: 'fleetbo-auto-runtime',
|
|
97
97
|
transform(code, id) {
|
|
98
98
|
if (!id.includes('node_modules') && !code.includes('fleetbo-svro') && /(src[\\\\/](main|index|App|root))\\.(jsx?|tsx?|vue|svelte)/i.test(id)) {
|
|
@@ -144,21 +144,22 @@ ${e?`VITE_FLEETBO_TESTER_EMAIL=${e}
|
|
|
144
144
|
watch: {
|
|
145
145
|
ignored: ['**/svro.schema.json', '**/src/auto-imports.d.ts']
|
|
146
146
|
}
|
|
147
|
-
},`))),!e.includes("unplugin-auto-import")){let l=e.match(/plugins\s*:\s*\[/);if(l){let
|
|
147
|
+
},`))),!e.includes("unplugin-auto-import")){let l=e.match(/plugins\s*:\s*\[/);if(l){let c=l.index+l[0].length,h=`
|
|
148
148
|
AutoImport({
|
|
149
149
|
imports: [{ '${b}': ['Fleetbo', 'FleetboUI'] }],
|
|
150
150
|
dts: 'src/auto-imports.d.ts'
|
|
151
|
-
}),`;if(e=e.slice(0,
|
|
151
|
+
}),`;if(e=e.slice(0,c)+h+e.slice(c),!e.includes("import AutoImport")){let P=[...e.matchAll(/^import .+;?$/gm)].pop(),v=`import AutoImport from 'unplugin-auto-import/vite';
|
|
152
152
|
`;if(P){let m=P.index+P[0].length;e=e.slice(0,m)+`
|
|
153
|
-
`+v+e.slice(m)}else e=v+e}}}if(!e.includes("fleetbo-auto-runtime")){let l=e.match(/plugins\s*:\s*\[/);if(l){let
|
|
154
|
-
`+i+e.slice(
|
|
155
|
-
`).
|
|
156
|
-
[
|
|
153
|
+
`+v+e.slice(m)}else e=v+e}}}if(!e.includes("fleetbo-auto-runtime")){let l=e.match(/plugins\s*:\s*\[/);if(l){let c=l.index+l[0].length;e=e.slice(0,c)+`
|
|
154
|
+
`+i+e.slice(c)}}e!==r&&a.writeFileSync(s,e)}function K(t){let o=p.join(t,".vscode"),n=p.join(o,"settings.json");try{a.existsSync(o)||a.mkdirSync(o,{recursive:!0});let s={};if(a.existsSync(n))try{s=JSON.parse(a.readFileSync(n,"utf8"))}catch{s={}}s["workbench.colorCustomizations"]=s["workbench.colorCustomizations"]||{},s["workbench.colorCustomizations"]["editorInfo.foreground"]="#00feae",s["workbench.colorCustomizations"]["editorHint.foreground"]="#00feae",a.writeFileSync(n,JSON.stringify(s,null,2)+`
|
|
155
|
+
`),f("\u2192 Configured Fleetbo Cyan visual hints in .vscode/settings.json.")}catch{}}function X(t,o,n={}){let{skipSelfInstall:s=!1}=n,r=p.join(__dirname,"..");s||U(t,o),B(t),M(r),q(t),K(t),O(t),I(t,o),w(t,o),j(t)}k.exports={touchTsConfig:V,log:f,logError:u,handleAuthAndEnv:W,detectDependency:S,cleanupLegacyRootDts:O,patchJsOrTsConfig:I,attemptViteAutoImportPatch:w,injectUniversalRuntime:j,runFullSetup:X}});var g=require("fs"),F=require("path"),_=require("https"),{runFullSetup:z,handleAuthAndEnv:Y,touchTsConfig:G,attemptViteAutoImportPatch:Q,injectUniversalRuntime:Z}=C(),ee="\x1B[34m",te="\x1B[31m",R="\x1B[0m";function d(t){console.log(`${ee}${t}${R}`)}function y(t){console.error(`${te}${t}${R}`)}function oe(t,o){return new Promise((n,s)=>{let r=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(r)}},e=_.request(b,i=>{let l="";i.on("data",c=>{l+=c}),i.on("end",()=>{i.statusCode>=200&&i.statusCode<300?n(JSON.parse(l)):s(new Error(`Edge sync failed with HTTP ${i.statusCode}`))})});e.on("error",i=>s(i)),e.write(r),e.end()})}function ne(t){let o=F.join(t,".env");if(!g.existsSync(o))return{};let n=g.readFileSync(o,"utf8"),s={};return n.split(`
|
|
156
|
+
`).forEach(r=>{let[b,...e]=r.split("=");b&&e.length>0&&(s[b.trim()]=e.join("=").trim())}),s}function se(t){return new Promise((o,n)=>{let s=JSON.stringify({projectId:t,moduleName:"svro.schema.json"}),r={hostname:"getmodulecache-jqycakhlxa-uc.a.run.app",path:"/",method:"POST",headers:{"Content-Type":"application/json","Content-Length":Buffer.byteLength(s)}},b=_.request(r,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 c=l.module.code||l.module.mockCode;o(typeof c=="string"?JSON.parse(c):c)}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(s),b.end()})}var E=process.argv.slice(2),x=E[0];async function re(){let t=process.cwd(),o=F.join(t,"package.json");if(x==="init"||x==="doctor")d(`
|
|
157
|
+
[Fleetbo] Initializing and configuring Fleetbo...`),await Y(t,E),z(t,o),d(`
|
|
157
158
|
[Fleetbo] Configuration completed successfully!
|
|
158
159
|
`),d(`
|
|
159
160
|
Next step:`),d(` npx fleetbo-svro sync (Sync cloud schema & generate IDE types)
|
|
160
|
-
`);else if(x==="sync"){let n=E.includes("--dry-run");d(`[Fleetbo] Syncing schema...${n?" (dry-run)":""}`);let s=F.join(t,"svro.schema.json"),r=F.join(__dirname,".."),b=F.join(r,"index.d.ts"),e=F.join(t,"src","fleetbo.d.ts"),l=
|
|
161
|
-
`),d("\u2192 Local svro.schema.json updated from FLeetbo OS.")}catch(
|
|
161
|
+
`);else if(x==="sync"){let n=E.includes("--dry-run");d(`[Fleetbo] Syncing schema...${n?" (dry-run)":""}`);let s=F.join(t,"svro.schema.json"),r=F.join(__dirname,".."),b=F.join(r,"index.d.ts"),e=F.join(t,"src","fleetbo.d.ts"),l=ne(t).VITE_FLEETBO_ENTERPRISE_ID;if(l)try{d("\u2192 Fetching latest svro.schema.json from Fleetbo OS...");let c=await se(l);g.writeFileSync(s,JSON.stringify(c,null,2)+`
|
|
162
|
+
`),d("\u2192 Local svro.schema.json updated from FLeetbo OS.")}catch(c){y(`\u26A0\uFE0F Cloud fetch bypassed: ${c.message}. Using local file fallback.`)}else y("\u26A0\uFE0F VITE_FLEETBO_ENTERPRISE_ID missing in .env. Skipping cloud fetch.");g.existsSync(s)||(y("Error: svro.schema.json not found."),process.exit(1));try{let c=JSON.parse(g.readFileSync(s,"utf8")),h=Object.keys(c.collections||{});if(l)try{await oe(l,c),d("\u2192 Schema successfully sealed at Fleetbo Global Edge (O(1)).")}catch(m){y(`\u26A0\uFE0F Fleetbo Edge Shield sync warning: ${m.message}`)}let P=h.length>0?h.map(m=>`'${m}'`).join(" | "):"string",v=`// Generated by fleetbo-svro \u2014 Updated via fleetbo sync
|
|
162
163
|
|
|
163
164
|
export type KnownFleetboTables = ${P};
|
|
164
165
|
|
|
@@ -508,4 +509,4 @@ declare module 'svelte/elements' {
|
|
|
508
509
|
'fleetbo-reference': FleetboProp;
|
|
509
510
|
}
|
|
510
511
|
}
|
|
511
|
-
`;g.writeFileSync(e,m)}
|
|
512
|
+
`;g.writeFileSync(e,m)}G(t),Q(t,o),Z(t),d(`[Fleetbo] Schema synced successfully (${h.length} collection(s)).`),n&&d("\u2192 [Dry-run] Schema is valid.")}catch(c){y(`Error during synchronization: ${c.message}`),process.exit(1)}}else y('Unknown command. Usage: "npx fleetbo-svro init" or "npx fleetbo-svro sync"'),process.exit(1)}re().catch(t=>{y(`Fleetbo CLI Error: ${t.message}`),process.exit(1)});
|