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