fleetbo-svro 1.0.30 → 1.0.32
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 +25 -25
- package/package.json +1 -1
package/dist/cli.cjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var V=(t,
|
|
3
|
-
`),f("\u2192 Created svro.schema.json at project root.")}function
|
|
2
|
+
var V=(t,n)=>()=>{try{return n||t((n={exports:{}}).exports,n),n.exports}catch(o){throw n=0,o}};var $=V((he,N)=>{var i=require("fs"),p=require("path"),q=require("https"),{execSync:W}=require("child_process"),H="\x1B[38;2;231;233;237m",K="\x1B[31m",w="\x1B[0m";function f(t){console.log(` ${H}${t}${w}`)}function d(t){console.error(` ${K}${t}${w}`)}function Y(t){let n={};return t.forEach(o=>{if(o.startsWith("--")){let[s,r]=o.slice(2).split("=");s&&r&&(n[s]=r)}}),n}function O(t,n){try{let o=JSON.parse(i.readFileSync(t,"utf8"));return!!(o.dependencies&&o.dependencies[n]||o.devDependencies&&o.devDependencies[n])}catch{return!1}}function X(t,n){try{return i.existsSync(p.join(t,"node_modules",n,"package.json"))}catch{return!1}}function z(t,n){if(i.existsSync(p.join(t,"pnpm-lock.yaml")))return"pnpm";if(i.existsSync(p.join(t,"yarn.lock")))return"yarn";if(i.existsSync(p.join(t,"bun.lockb")))return"bun";try{let o=JSON.parse(i.readFileSync(n,"utf8"));if(typeof o.packageManager=="string"){if(o.packageManager.startsWith("pnpm"))return"pnpm";if(o.packageManager.startsWith("yarn"))return"yarn";if(o.packageManager.startsWith("bun"))return"bun"}}catch{}return"npm"}function G(t,n){if(!O(n,"fleetbo-svro")||!X(t,"fleetbo-svro")){let o=z(t,n),s={pnpm:"pnpm add fleetbo-svro",yarn:"yarn add fleetbo-svro",bun:"bun add fleetbo-svro",npm:"npm install fleetbo-svro"}[o];f(`\u2192 Installing fleetbo-svro into the project (detected: ${o})...`);try{W(s,{cwd:t,stdio:"inherit"}),f("fleetbo-svro installed successfully!")}catch(r){d(`\u26A0\uFE0F Automatic installation failed: ${r.message}`),d(`\u{1F449} Please run '${s}' manually.`)}}}function Q(t){let n=p.join(t,"svro.schema.json");if(i.existsSync(n))return;let o=new Date().toISOString(),s={createdAt:o,patchedAt:o,schemaVersion:1,collections:{}};i.writeFileSync(n,JSON.stringify(s,null,2)+`
|
|
3
|
+
`),f("\u2192 Created svro.schema.json at project root.")}function Z(t){let n=p.join(t,".env"),o=`
|
|
4
4
|
# Fleetbo Sandbox / Prototype Mode
|
|
5
5
|
# true = BDD verrouill\xE9e, z\xE9ro crash, IDE alerte en Cyan
|
|
6
6
|
# false = Mode strict production (sanction imm\xE9diate HTTP 422 si non scell\xE9, \xE9criture BDD)
|
|
7
7
|
VITE_FLEETBO_PROTOTYPE=true
|
|
8
|
-
`;if(!i.existsSync(
|
|
8
|
+
`;if(!i.existsSync(n))i.writeFileSync(n,o.trimStart()),f("\u2192 Created .env with VITE_FLEETBO_PROTOTYPE=true");else{let s=i.readFileSync(n,"utf8");!s.includes("VITE_FLEETBO_PROTOTYPE")&&!s.includes("FLEETBO_PROTOTYPE")&&(i.appendFileSync(n,o),f("\u2192 Injected VITE_FLEETBO_PROTOTYPE=true into existing .env"))}}function ee(t){let n=p.join(t,"src");if(!i.existsSync(n))return;let o=p.join(n,"fleetbo.d.ts");if(i.existsSync(o))return;let s=`/* eslint-disable */
|
|
9
9
|
/* prettier-ignore */
|
|
10
10
|
// @ts-nocheck
|
|
11
11
|
export {}
|
|
@@ -89,15 +89,15 @@ declare module 'react' {
|
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
|
-
`;try{i.writeFileSync(
|
|
92
|
+
`;try{i.writeFileSync(o,s),f("\u2192 Created src/fleetbo.d.ts stub for instant IDE auto-completion.")}catch(r){d(`\u26A0\uFE0F Unable to create src/fleetbo.d.ts: ${r.message}`)}}function te(t){let n=p.join(t,"index.d.ts");i.existsSync(n)||f("\u2192 Verified index.d.ts presence.")}function oe(t){let n=["tsconfig.json","jsconfig.json"];for(let o of n){let s=p.join(t,o);if(i.existsSync(s)){let r=new Date;i.utimesSync(s,r,r);break}}}function ne(t){return new Promise((n,o)=>{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=q.request(r,e=>{let a="";e.on("data",l=>{a+=l}),e.on("end",()=>{if(e.statusCode>=200&&e.statusCode<300)try{n(JSON.parse(a))}catch{o(new Error("Invalid response received from Fleetbo server."))}else try{let l=JSON.parse(a);o(new Error(l.error||`Server error ${e.statusCode}`))}catch{o(new Error(`Server error ${e.statusCode}`))}})});b.on("error",e=>o(e)),b.write(s),b.end()})}async function se(t,n=[]){let o=p.join(t,".env");if(i.existsSync(o)&&i.readFileSync(o,"utf8").includes("VITE_FLEETBO_DB_KEY")){f("\u2192 Fleetbo environment variables already present in .env \u2014 skipping step.");return}let s=Y(n),r=s.keyApp,b=s.token||s.bootstrapToken,e=s.email||"";(!r||!b)&&(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 a;try{a=await ne(b)}catch(c){d(`\u26A0\uFE0F Token exchange failed: ${c.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)}(!a.enterpriseId||!a.fleetboDBKey)&&(d("\u26A0\uFE0F Incomplete response from Fleetbo server."),process.exit(1));let l=`
|
|
93
93
|
VITE_FLEETBO_DB_KEY=${a.fleetboDBKey}
|
|
94
94
|
VITE_FLEETBO_ENTERPRISE_ID=${a.enterpriseId}
|
|
95
95
|
VITE_FLEETBO_KEY_APP=${r}
|
|
96
96
|
${e?`VITE_FLEETBO_TESTER_EMAIL=${e}
|
|
97
|
-
`:""}`;i.appendFileSync(
|
|
98
|
-
`),f(`\u2192 Updated ${p.basename(r)}.`))}function R(t){let
|
|
97
|
+
`:""}`;i.appendFileSync(o,l),f(".env file updated successfully with Fleetbo keys!")}function _(t){let n=p.join(t,"svro.d.ts");if(i.existsSync(n))try{i.unlinkSync(n),f("\u2192 Removed legacy svro.d.ts from project root.")}catch{}}function C(t,n){if(process.env.FLEETBO_SKIP_TYPECHECK_SETUP)return;let o=p.join(t,"tsconfig.json"),s=p.join(t,"jsconfig.json"),r=i.existsSync(o)?o:s,b=!i.existsSync(r),e={};if(!b)try{e=JSON.parse(i.readFileSync(r,"utf8"))}catch{d(`\u26A0\uFE0F Unable to read ${p.basename(r)} (Invalid JSON).`);return}e.compilerOptions=e.compilerOptions||{};let a=!1,l=O(n,"react");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=["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)),l&&e.compilerOptions.jsx===void 0&&(e.compilerOptions.jsx="react-jsx",a=!0),a&&(i.writeFileSync(r,JSON.stringify(e,null,2)+`
|
|
98
|
+
`),f(`\u2192 Updated ${p.basename(r)}.`))}function R(t){let n=["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 o of n){let s=p.join(t,o);if(i.existsSync(s)){let r=i.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';
|
|
99
99
|
`):r=`import 'fleetbo-svro';
|
|
100
|
-
`+r,i.writeFileSync(s,r));return}}}function L(t,
|
|
100
|
+
`+r,i.writeFileSync(s,r));return}}}function L(t,n){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=>i.existsSync(l));if(!s)return;let r;try{r=i.readFileSync(s,"utf8")}catch{return}let b="fleetbo-svro",e=r,a=`{
|
|
101
101
|
name: 'fleetbo-auto-runtime',
|
|
102
102
|
transform(code, id) {
|
|
103
103
|
if (!id.includes('node_modules') && !code.includes('fleetbo-svro') && /(src[\\\\/](main|index|App|root))\\.(jsx?|tsx?|vue|svelte)/i.test(id)) {
|
|
@@ -153,28 +153,28 @@ ${e?`VITE_FLEETBO_TESTER_EMAIL=${e}
|
|
|
153
153
|
AutoImport({
|
|
154
154
|
imports: [{ '${b}': ['Fleetbo', 'FleetboUI'] }],
|
|
155
155
|
dts: 'src/auto-imports.d.ts'
|
|
156
|
-
}),`;if(e=e.slice(0,c)+P+e.slice(c),!e.includes("import AutoImport")){let T=[...e.matchAll(/^import .+;?$/gm)].pop(),
|
|
157
|
-
`;if(T){let
|
|
158
|
-
`+
|
|
159
|
-
`+a+e.slice(c)}}e!==r&&i.writeFileSync(s,e)}function
|
|
160
|
-
`),f("\u2192 Configured Fleetbo Cyan visual hints in .vscode/settings.json.")}catch{}}function
|
|
161
|
-
`).forEach(r=>{let[b,...e]=r.split("=");b&&e.length>0&&(s[b.trim()]=e.join("=").trim())}),s}function
|
|
162
|
-
[Fleetbo] Initializing and configuring Fleetbo...`),await
|
|
156
|
+
}),`;if(e=e.slice(0,c)+P+e.slice(c),!e.includes("import AutoImport")){let T=[...e.matchAll(/^import .+;?$/gm)].pop(),S=`import AutoImport from 'unplugin-auto-import/vite';
|
|
157
|
+
`;if(T){let E=T.index+T[0].length;e=e.slice(0,E)+`
|
|
158
|
+
`+S+e.slice(E)}else e=S+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)+`
|
|
159
|
+
`+a+e.slice(c)}}e!==r&&i.writeFileSync(s,e)}function re(t){let n=p.join(t,".vscode"),o=p.join(n,"settings.json");try{i.existsSync(n)||i.mkdirSync(n,{recursive:!0});let s={};if(i.existsSync(o))try{s=JSON.parse(i.readFileSync(o,"utf8"))}catch{s={}}s["workbench.colorCustomizations"]=s["workbench.colorCustomizations"]||{},s["workbench.colorCustomizations"]["editorInfo.foreground"]="#00feae",s["workbench.colorCustomizations"]["editorHint.foreground"]="#00feae",i.writeFileSync(o,JSON.stringify(s,null,2)+`
|
|
160
|
+
`),f("\u2192 Configured Fleetbo Cyan visual hints in .vscode/settings.json.")}catch{}}function le(t,n,o={}){let{skipSelfInstall:s=!1}=o,r=p.join(__dirname,"..");s||G(t,n),Q(t),Z(t),te(r),ee(t),re(t),_(t),C(t,n),L(t,n),R(t)}N.exports={touchTsConfig:oe,log:f,logError:d,handleAuthAndEnv:se,detectDependency:O,cleanupLegacyRootDts:_,patchJsOrTsConfig:C,attemptViteAutoImportPatch:L,injectUniversalRuntime:R,runFullSetup:le}});var m=require("fs"),y=require("path"),D=require("https"),{runFullSetup:ie,handleAuthAndEnv:ae,touchTsConfig:ce,attemptViteAutoImportPatch:be,injectUniversalRuntime:pe}=$(),fe="\x1B[34m",de="\x1B[31m",J="\x1B[0m";function u(t){console.log(`${fe}${t}${J}`)}function h(t){console.error(`${de}${t}${J}`)}function ue(t,n){return new Promise((o,s)=>{let r=JSON.stringify({enterpriseID:t,schema:n}),b={hostname:"fleetbo-gatekeeper.fleetbo.workers.dev",path:"/sync-schema",method:"POST",headers:{"Content-Type":"application/json","Content-Length":Buffer.byteLength(r)}},e=D.request(b,a=>{let l="";a.on("data",c=>{l+=c}),a.on("end",()=>{a.statusCode>=200&&a.statusCode<300?o(JSON.parse(l)):s(new Error(`Edge sync failed with HTTP ${a.statusCode}`))})});e.on("error",a=>s(a)),e.write(r),e.end()})}function me(t){let n=y.join(t,".env");if(!m.existsSync(n))return{};let o=m.readFileSync(n,"utf8"),s={};return o.split(`
|
|
161
|
+
`).forEach(r=>{let[b,...e]=r.split("=");b&&e.length>0&&(s[b.trim()]=e.join("=").trim())}),s}function ge(t){return new Promise((n,o)=>{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=D.request(r,e=>{let a="";e.on("data",l=>{a+=l}),e.on("end",()=>{if(e.statusCode>=200&&e.statusCode<300)try{let l=JSON.parse(a);if(l.success&&l.found&&l.module){let c=l.module.code||l.module.mockCode;n(typeof c=="string"?JSON.parse(c):c)}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(s),b.end()})}var k=process.argv.slice(2),I=k[0];async function Fe(){let t=process.cwd(),n=y.join(t,"package.json");if(I==="init"||I==="doctor")u(`
|
|
162
|
+
[Fleetbo] Initializing and configuring Fleetbo...`),await ae(t,k),ie(t,n),u(`
|
|
163
163
|
[Fleetbo] Configuration completed successfully!
|
|
164
|
-
`),
|
|
165
|
-
Next step:`),
|
|
166
|
-
`);else if(I==="sync"){let
|
|
167
|
-
`),
|
|
164
|
+
`),u(`
|
|
165
|
+
Next step:`),u(` npx fleetbo-svro sync (Sync cloud schema & generate IDE types)
|
|
166
|
+
`);else if(I==="sync"){let o=k.includes("--dry-run");u(`[Fleetbo] Syncing schema...${o?" (dry-run)":""}`);let s=y.join(t,"svro.schema.json"),r=y.join(__dirname,".."),b=y.join(r,"index.d.ts"),e=y.join(t,"src","fleetbo.d.ts"),l=me(t).VITE_FLEETBO_ENTERPRISE_ID;if(l)try{u("\u2192 Fetching latest svro.schema.json from Fleetbo OS...");let c=await ge(l);m.writeFileSync(s,JSON.stringify(c,null,2)+`
|
|
167
|
+
`),u("\u2192 Local svro.schema.json updated from FLeetbo OS.")}catch(c){h(`\u26A0\uFE0F Cloud fetch bypassed: ${c.message}. Using local file fallback.`)}else h("\u26A0\uFE0F VITE_FLEETBO_ENTERPRISE_ID missing in .env. Skipping cloud fetch.");m.existsSync(s)||(h("Error: svro.schema.json not found."),process.exit(1));try{let c=JSON.parse(m.readFileSync(s,"utf8")),P=Object.keys(c.collections||{});if(l)try{await ue(l,c),u("\u2192 Schema successfully sealed at Fleetbo Global Edge (O(1)).")}catch(g){h(`\u26A0\uFE0F Fleetbo Edge Shield sync warning: ${g.message}`)}let T=c.collections||{},S=Object.entries(T).map(([g,j])=>{let M=j.fields||j.schema||{},B=Object.entries(M).map(([U,v])=>{let x="any",F=String(typeof v=="string"?v:v.type||"").toLowerCase();return F==="string"||F==="text"||F==="media"?x="string":F==="number"?x="number":F==="boolean"||F==="toggle"?x="boolean":F==="array"&&(x="any[]"),` ${U}?: ${x};`}).join(`
|
|
168
168
|
`);return` ${g}: {
|
|
169
|
-
${
|
|
169
|
+
${B}
|
|
170
170
|
};`}).join(`
|
|
171
|
-
`),
|
|
171
|
+
`),E=P.length>0?P.map(g=>`'${g}'`).join(" | "):"string",A=`// Generated by fleetbo-svro \u2014 Updated via fleetbo sync
|
|
172
172
|
|
|
173
173
|
export interface FleetboSchemaMap {
|
|
174
|
-
${
|
|
174
|
+
${S}
|
|
175
175
|
}
|
|
176
176
|
|
|
177
|
-
export type KnownFleetboTables = ${
|
|
177
|
+
export type KnownFleetboTables = ${E};
|
|
178
178
|
|
|
179
179
|
export type FleetboTables =
|
|
180
180
|
| KnownFleetboTables
|
|
@@ -436,11 +436,11 @@ type FleetboProp = {
|
|
|
436
436
|
};
|
|
437
437
|
|
|
438
438
|
interface FleetboSchemaMap {
|
|
439
|
-
${
|
|
439
|
+
${S}
|
|
440
440
|
}
|
|
441
441
|
|
|
442
442
|
declare global {
|
|
443
|
-
type KnownFleetboTables = ${
|
|
443
|
+
type KnownFleetboTables = ${E};
|
|
444
444
|
type FleetboTables = KnownFleetboTables | (string & { _fleetboPending?: never });
|
|
445
445
|
type FleetboData<T extends string> = T extends KnownFleetboTables
|
|
446
446
|
? Partial<FleetboSchemaMap[T]>
|
|
@@ -530,4 +530,4 @@ declare module 'svelte/elements' {
|
|
|
530
530
|
'fleetbo-reference': FleetboProp;
|
|
531
531
|
}
|
|
532
532
|
}
|
|
533
|
-
`;m.writeFileSync(e,g)}
|
|
533
|
+
`;m.writeFileSync(e,g)}ce(t),be(t,n),pe(t),u(`[Fleetbo] Schema synced successfully (${P.length} collection(s)).`),o&&u("\u2192 [Dry-run] Schema is valid.")}catch(c){h(`Error during synchronization: ${c.message}`),process.exit(1)}}else h('Unknown command. Usage: "npx fleetbo-svro init" or "npx fleetbo-svro sync"'),process.exit(1)}Fe().catch(t=>{h(`Fleetbo CLI Error: ${t.message}`),process.exit(1)});
|