clefbase 1.2.1 → 1.2.2
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-src/cli/commands/init.js +125 -18
- package/dist/cli.js +105 -15
- package/package.json +1 -1
|
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.runInit = runInit;
|
|
7
|
+
exports.scaffoldLib = scaffoldLib;
|
|
7
8
|
const path_1 = __importDefault(require("path"));
|
|
8
9
|
const fs_1 = __importDefault(require("fs"));
|
|
9
10
|
const chalk_1 = __importDefault(require("chalk"));
|
|
@@ -93,25 +94,129 @@ async function runInit(cwd = process.cwd()) {
|
|
|
93
94
|
if (cfg.services.hosting) {
|
|
94
95
|
await setupHosting(cfg, cwd);
|
|
95
96
|
}
|
|
96
|
-
// ── Step 5: Write config files
|
|
97
|
+
// ── Step 5: Write root config files ──────────────────────────────────────
|
|
97
98
|
const configPath = (0, config_1.saveConfig)(cfg, cwd);
|
|
98
99
|
(0, config_1.ensureGitignore)(cwd);
|
|
99
100
|
(0, config_1.writeEnvExample)(cfg, cwd);
|
|
101
|
+
// ── Step 6: Scaffold src/lib ──────────────────────────────────────────────
|
|
102
|
+
const libResult = scaffoldLib(cfg, cwd);
|
|
103
|
+
// ── Done ──────────────────────────────────────────────────────────────────
|
|
100
104
|
console.log();
|
|
101
105
|
console.log(chalk_1.default.green.bold(" ✓ Project initialised!"));
|
|
102
106
|
console.log();
|
|
103
|
-
console.log(chalk_1.default.dim(` Config:
|
|
104
|
-
console.log(chalk_1.default.dim(" Secrets:
|
|
105
|
-
console.log(chalk_1.default.dim(" Env example:
|
|
107
|
+
console.log(chalk_1.default.dim(` Config: ${path_1.default.relative(cwd, configPath)}`));
|
|
108
|
+
console.log(chalk_1.default.dim(" Secrets: clefbase.json has been added to .gitignore"));
|
|
109
|
+
console.log(chalk_1.default.dim(" Env example: .env.example created"));
|
|
110
|
+
if (libResult) {
|
|
111
|
+
console.log(chalk_1.default.dim(` Lib config: ${libResult.configCopy}`));
|
|
112
|
+
console.log(chalk_1.default.dim(` Lib entry: ${libResult.libFile}`));
|
|
113
|
+
}
|
|
106
114
|
console.log();
|
|
107
115
|
printUsageHint(cfg);
|
|
108
116
|
}
|
|
117
|
+
/**
|
|
118
|
+
* Writes two files into `<cwd>/src/lib/`:
|
|
119
|
+
* • clefbase.json — a copy of the project config (secrets stripped for safety)
|
|
120
|
+
* • clefBase.ts — ready-to-import service exports
|
|
121
|
+
*
|
|
122
|
+
* Safe to call multiple times — the TS file is regenerated on every call so it
|
|
123
|
+
* stays in sync with the enabled services.
|
|
124
|
+
*/
|
|
125
|
+
function scaffoldLib(cfg, cwd = process.cwd()) {
|
|
126
|
+
const libDir = path_1.default.join(cwd, "src", "lib");
|
|
127
|
+
fs_1.default.mkdirSync(libDir, { recursive: true });
|
|
128
|
+
// ── 1. Config copy (strip adminSecret for safety) ─────────────────────────
|
|
129
|
+
const publicCfg = {
|
|
130
|
+
serverUrl: cfg.serverUrl,
|
|
131
|
+
projectId: cfg.projectId,
|
|
132
|
+
apiKey: cfg.apiKey,
|
|
133
|
+
// adminSecret intentionally omitted — not needed in client code
|
|
134
|
+
services: cfg.services,
|
|
135
|
+
...(cfg.hosting ? { hosting: cfg.hosting } : {}),
|
|
136
|
+
};
|
|
137
|
+
const configCopyAbs = path_1.default.join(libDir, "clefbase.json");
|
|
138
|
+
fs_1.default.writeFileSync(configCopyAbs, JSON.stringify(publicCfg, null, 2) + "\n");
|
|
139
|
+
// ── 2. clefBase.ts ────────────────────────────────────────────────────────
|
|
140
|
+
const libFileAbs = path_1.default.join(libDir, "clefBase.ts");
|
|
141
|
+
fs_1.default.writeFileSync(libFileAbs, buildLibTs(cfg));
|
|
142
|
+
return {
|
|
143
|
+
configCopy: path_1.default.relative(cwd, configCopyAbs),
|
|
144
|
+
libFile: path_1.default.relative(cwd, libFileAbs),
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
/** Build the content of src/lib/clefBase.ts based on enabled services. */
|
|
148
|
+
function buildLibTs(cfg) {
|
|
149
|
+
const { database, auth, storage } = cfg.services;
|
|
150
|
+
// Collect SDK imports
|
|
151
|
+
const sdkImports = ["initClefbase"];
|
|
152
|
+
if (database)
|
|
153
|
+
sdkImports.push("getDatabase");
|
|
154
|
+
if (auth)
|
|
155
|
+
sdkImports.push("getAuth");
|
|
156
|
+
if (storage)
|
|
157
|
+
sdkImports.push("getStorage");
|
|
158
|
+
// Collect type imports
|
|
159
|
+
const typeImports = [];
|
|
160
|
+
if (database)
|
|
161
|
+
typeImports.push("Database");
|
|
162
|
+
if (auth)
|
|
163
|
+
typeImports.push("Auth");
|
|
164
|
+
if (storage)
|
|
165
|
+
typeImports.push("ClefbaseStorage");
|
|
166
|
+
const lines = [
|
|
167
|
+
`/**`,
|
|
168
|
+
` * Clefbase — pre-initialised service exports`,
|
|
169
|
+
` *`,
|
|
170
|
+
` * Usage:`,
|
|
171
|
+
` * import { db, auth, storage } from "@lib/clefBase";`,
|
|
172
|
+
` * import db from "@lib/clefBase";`,
|
|
173
|
+
` */`,
|
|
174
|
+
``,
|
|
175
|
+
`import { ${sdkImports.join(", ")} } from "clefbase";`,
|
|
176
|
+
...(typeImports.length > 0
|
|
177
|
+
? [`import type { ${typeImports.join(", ")} } from "clefbase";`]
|
|
178
|
+
: []),
|
|
179
|
+
`import config from "./clefbase.json";`,
|
|
180
|
+
``,
|
|
181
|
+
`// ─── App ─────────────────────────────────────────────────────────────────────`,
|
|
182
|
+
``,
|
|
183
|
+
`const app = initClefbase({`,
|
|
184
|
+
` serverUrl: config.serverUrl,`,
|
|
185
|
+
` projectId: config.projectId,`,
|
|
186
|
+
` apiKey: config.apiKey,`,
|
|
187
|
+
`});`,
|
|
188
|
+
``,
|
|
189
|
+
];
|
|
190
|
+
// ── Service instances ──────────────────────────────────────────────────────
|
|
191
|
+
if (database || auth || storage) {
|
|
192
|
+
lines.push("// ─── Services ───────────────────────────────────────────────────────────────");
|
|
193
|
+
lines.push("");
|
|
194
|
+
}
|
|
195
|
+
if (database) {
|
|
196
|
+
lines.push(`/** Clefbase Database — query and mutate documents. */`);
|
|
197
|
+
lines.push(`export const db: Database = getDatabase(app);`);
|
|
198
|
+
lines.push("");
|
|
199
|
+
}
|
|
200
|
+
if (auth) {
|
|
201
|
+
lines.push(`/** Clefbase Auth — sign up, sign in, manage sessions. */`);
|
|
202
|
+
lines.push(`export const auth: Auth = getAuth(app);`);
|
|
203
|
+
lines.push("");
|
|
204
|
+
}
|
|
205
|
+
if (storage) {
|
|
206
|
+
lines.push(`/** Clefbase Storage — upload and manage files. */`);
|
|
207
|
+
lines.push(`export const storage: ClefbaseStorage = getStorage(app);`);
|
|
208
|
+
lines.push("");
|
|
209
|
+
}
|
|
210
|
+
// ── Re-export app for advanced use ────────────────────────────────────────
|
|
211
|
+
lines.push(`// ─── Advanced ────────────────────────────────────────────────────────────────`, ``, `/** The underlying ClefbaseApp instance (for advanced use). */`, `export { app };`, ``);
|
|
212
|
+
lines.push("");
|
|
213
|
+
return lines.join("\n");
|
|
214
|
+
}
|
|
109
215
|
// ─── Hosting sub-flow ─────────────────────────────────────────────────────────
|
|
110
216
|
async function setupHosting(cfg, cwd) {
|
|
111
217
|
console.log();
|
|
112
218
|
console.log(chalk_1.default.bold(" Hosting"));
|
|
113
219
|
console.log();
|
|
114
|
-
// Fetch existing sites
|
|
115
220
|
let existing = [];
|
|
116
221
|
const siteSpinner = (0, ora_1.default)("Fetching existing sites…").start();
|
|
117
222
|
try {
|
|
@@ -191,35 +296,37 @@ function guessDistDir(cwd) {
|
|
|
191
296
|
return "dist";
|
|
192
297
|
}
|
|
193
298
|
function printUsageHint(cfg) {
|
|
194
|
-
const
|
|
299
|
+
const namedImports = [];
|
|
195
300
|
if (cfg.services.database)
|
|
196
|
-
|
|
301
|
+
namedImports.push("db");
|
|
197
302
|
if (cfg.services.auth)
|
|
198
|
-
|
|
303
|
+
namedImports.push("auth");
|
|
199
304
|
if (cfg.services.storage)
|
|
200
|
-
|
|
201
|
-
if (cfg.services.hosting)
|
|
202
|
-
imports.push("getHosting");
|
|
305
|
+
namedImports.push("storage");
|
|
203
306
|
console.log(chalk_1.default.bold(" Quick start:"));
|
|
204
307
|
console.log();
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
308
|
+
if (namedImports.length > 0) {
|
|
309
|
+
console.log(chalk_1.default.cyan(` import { ${namedImports.join(", ")} } from "@lib/clefBase";`));
|
|
310
|
+
}
|
|
311
|
+
else {
|
|
312
|
+
console.log(chalk_1.default.cyan(` import app from "@lib/clefBase";`));
|
|
313
|
+
}
|
|
209
314
|
if (cfg.services.database) {
|
|
210
315
|
console.log();
|
|
211
|
-
console.log(chalk_1.default.cyan(` const db = getDatabase(app);`));
|
|
212
316
|
console.log(chalk_1.default.cyan(` const docs = await db.collection("items").getDocs();`));
|
|
213
317
|
}
|
|
214
318
|
if (cfg.services.auth) {
|
|
215
319
|
console.log();
|
|
216
|
-
console.log(chalk_1.default.cyan(` const auth = getAuth(app);`));
|
|
217
320
|
console.log(chalk_1.default.cyan(` const { user } = await auth.signIn("email", "pass");`));
|
|
218
321
|
}
|
|
322
|
+
if (cfg.services.storage) {
|
|
323
|
+
console.log();
|
|
324
|
+
console.log(chalk_1.default.cyan(` await storage.ref("uploads/photo.jpg").upload(file);`));
|
|
325
|
+
}
|
|
219
326
|
if (cfg.services.hosting && cfg.hosting) {
|
|
220
327
|
console.log();
|
|
221
328
|
console.log(chalk_1.default.bold(" Deploy:"));
|
|
222
|
-
console.log(chalk_1.default.cyan(` $ npm run build && clefbase deploy`));
|
|
329
|
+
console.log(chalk_1.default.cyan(` $ npm run build && npx clefbase deploy`));
|
|
223
330
|
console.log(chalk_1.default.dim(` Site: ${cfg.serverUrl}/hosted/${cfg.projectId}/${cfg.hosting.siteId}`));
|
|
224
331
|
}
|
|
225
332
|
console.log();
|
package/dist/cli.js
CHANGED
|
@@ -33903,15 +33903,101 @@ async function runInit(cwd = process.cwd()) {
|
|
|
33903
33903
|
const configPath = saveConfig(cfg, cwd);
|
|
33904
33904
|
ensureGitignore(cwd);
|
|
33905
33905
|
writeEnvExample(cfg, cwd);
|
|
33906
|
+
const libResult = scaffoldLib(cfg, cwd);
|
|
33906
33907
|
console.log();
|
|
33907
33908
|
console.log(source_default.green.bold(" \u2713 Project initialised!"));
|
|
33908
33909
|
console.log();
|
|
33909
|
-
console.log(source_default.dim(` Config:
|
|
33910
|
-
console.log(source_default.dim(" Secrets:
|
|
33911
|
-
console.log(source_default.dim(" Env example:
|
|
33910
|
+
console.log(source_default.dim(` Config: ${import_path2.default.relative(cwd, configPath)}`));
|
|
33911
|
+
console.log(source_default.dim(" Secrets: clefbase.json has been added to .gitignore"));
|
|
33912
|
+
console.log(source_default.dim(" Env example: .env.example created"));
|
|
33913
|
+
if (libResult) {
|
|
33914
|
+
console.log(source_default.dim(` Lib config: ${libResult.configCopy}`));
|
|
33915
|
+
console.log(source_default.dim(` Lib entry: ${libResult.libFile}`));
|
|
33916
|
+
}
|
|
33912
33917
|
console.log();
|
|
33913
33918
|
printUsageHint(cfg);
|
|
33914
33919
|
}
|
|
33920
|
+
function scaffoldLib(cfg, cwd = process.cwd()) {
|
|
33921
|
+
const libDir = import_path2.default.join(cwd, "src", "lib");
|
|
33922
|
+
import_fs3.default.mkdirSync(libDir, { recursive: true });
|
|
33923
|
+
const publicCfg = {
|
|
33924
|
+
serverUrl: cfg.serverUrl,
|
|
33925
|
+
projectId: cfg.projectId,
|
|
33926
|
+
apiKey: cfg.apiKey,
|
|
33927
|
+
// adminSecret intentionally omitted — not needed in client code
|
|
33928
|
+
services: cfg.services,
|
|
33929
|
+
...cfg.hosting ? { hosting: cfg.hosting } : {}
|
|
33930
|
+
};
|
|
33931
|
+
const configCopyAbs = import_path2.default.join(libDir, "clefbase.json");
|
|
33932
|
+
import_fs3.default.writeFileSync(configCopyAbs, JSON.stringify(publicCfg, null, 2) + "\n");
|
|
33933
|
+
const libFileAbs = import_path2.default.join(libDir, "clefBase.ts");
|
|
33934
|
+
import_fs3.default.writeFileSync(libFileAbs, buildLibTs(cfg));
|
|
33935
|
+
return {
|
|
33936
|
+
configCopy: import_path2.default.relative(cwd, configCopyAbs),
|
|
33937
|
+
libFile: import_path2.default.relative(cwd, libFileAbs)
|
|
33938
|
+
};
|
|
33939
|
+
}
|
|
33940
|
+
function buildLibTs(cfg) {
|
|
33941
|
+
const { database, auth, storage } = cfg.services;
|
|
33942
|
+
const sdkImports = ["initClefbase"];
|
|
33943
|
+
if (database) sdkImports.push("getDatabase");
|
|
33944
|
+
if (auth) sdkImports.push("getAuth");
|
|
33945
|
+
if (storage) sdkImports.push("getStorage");
|
|
33946
|
+
const typeImports = [];
|
|
33947
|
+
if (database) typeImports.push("Database");
|
|
33948
|
+
if (auth) typeImports.push("Auth");
|
|
33949
|
+
if (storage) typeImports.push("ClefbaseStorage");
|
|
33950
|
+
const lines = [
|
|
33951
|
+
`/**`,
|
|
33952
|
+
` * Clefbase \u2014 pre-initialised service exports`,
|
|
33953
|
+
` *`,
|
|
33954
|
+
` * Usage:`,
|
|
33955
|
+
` * import { db, auth, storage } from "@lib/clefBase";`,
|
|
33956
|
+
` * import db from "@lib/clefBase";`,
|
|
33957
|
+
` */`,
|
|
33958
|
+
``,
|
|
33959
|
+
`import { ${sdkImports.join(", ")} } from "clefbase";`,
|
|
33960
|
+
...typeImports.length > 0 ? [`import type { ${typeImports.join(", ")} } from "clefbase";`] : [],
|
|
33961
|
+
`import config from "./clefbase.json";`,
|
|
33962
|
+
``,
|
|
33963
|
+
`// \u2500\u2500\u2500 App \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500`,
|
|
33964
|
+
``,
|
|
33965
|
+
`const app = initClefbase({`,
|
|
33966
|
+
` serverUrl: config.serverUrl,`,
|
|
33967
|
+
` projectId: config.projectId,`,
|
|
33968
|
+
` apiKey: config.apiKey,`,
|
|
33969
|
+
`});`,
|
|
33970
|
+
``
|
|
33971
|
+
];
|
|
33972
|
+
if (database || auth || storage) {
|
|
33973
|
+
lines.push("// \u2500\u2500\u2500 Services \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
|
|
33974
|
+
lines.push("");
|
|
33975
|
+
}
|
|
33976
|
+
if (database) {
|
|
33977
|
+
lines.push(`/** Clefbase Database \u2014 query and mutate documents. */`);
|
|
33978
|
+
lines.push(`export const db: Database = getDatabase(app);`);
|
|
33979
|
+
lines.push("");
|
|
33980
|
+
}
|
|
33981
|
+
if (auth) {
|
|
33982
|
+
lines.push(`/** Clefbase Auth \u2014 sign up, sign in, manage sessions. */`);
|
|
33983
|
+
lines.push(`export const auth: Auth = getAuth(app);`);
|
|
33984
|
+
lines.push("");
|
|
33985
|
+
}
|
|
33986
|
+
if (storage) {
|
|
33987
|
+
lines.push(`/** Clefbase Storage \u2014 upload and manage files. */`);
|
|
33988
|
+
lines.push(`export const storage: ClefbaseStorage = getStorage(app);`);
|
|
33989
|
+
lines.push("");
|
|
33990
|
+
}
|
|
33991
|
+
lines.push(
|
|
33992
|
+
`// \u2500\u2500\u2500 Advanced \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500`,
|
|
33993
|
+
``,
|
|
33994
|
+
`/** The underlying ClefbaseApp instance (for advanced use). */`,
|
|
33995
|
+
`export { app };`,
|
|
33996
|
+
``
|
|
33997
|
+
);
|
|
33998
|
+
lines.push("");
|
|
33999
|
+
return lines.join("\n");
|
|
34000
|
+
}
|
|
33915
34001
|
async function setupHosting(cfg, cwd) {
|
|
33916
34002
|
var _a;
|
|
33917
34003
|
console.log();
|
|
@@ -33992,31 +34078,35 @@ function guessDistDir(cwd) {
|
|
|
33992
34078
|
return "dist";
|
|
33993
34079
|
}
|
|
33994
34080
|
function printUsageHint(cfg) {
|
|
33995
|
-
const
|
|
33996
|
-
if (cfg.services.database)
|
|
33997
|
-
if (cfg.services.auth)
|
|
33998
|
-
if (cfg.services.storage)
|
|
33999
|
-
if (cfg.services.hosting) imports.push("getHosting");
|
|
34081
|
+
const namedImports = [];
|
|
34082
|
+
if (cfg.services.database) namedImports.push("db");
|
|
34083
|
+
if (cfg.services.auth) namedImports.push("auth");
|
|
34084
|
+
if (cfg.services.storage) namedImports.push("storage");
|
|
34000
34085
|
console.log(source_default.bold(" Quick start:"));
|
|
34001
34086
|
console.log();
|
|
34002
|
-
|
|
34003
|
-
|
|
34004
|
-
|
|
34005
|
-
|
|
34087
|
+
if (namedImports.length > 0) {
|
|
34088
|
+
console.log(
|
|
34089
|
+
source_default.cyan(` import { ${namedImports.join(", ")} } from "@lib/clefBase";`)
|
|
34090
|
+
);
|
|
34091
|
+
} else {
|
|
34092
|
+
console.log(source_default.cyan(` import app from "@lib/clefBase";`));
|
|
34093
|
+
}
|
|
34006
34094
|
if (cfg.services.database) {
|
|
34007
34095
|
console.log();
|
|
34008
|
-
console.log(source_default.cyan(` const db = getDatabase(app);`));
|
|
34009
34096
|
console.log(source_default.cyan(` const docs = await db.collection("items").getDocs();`));
|
|
34010
34097
|
}
|
|
34011
34098
|
if (cfg.services.auth) {
|
|
34012
34099
|
console.log();
|
|
34013
|
-
console.log(source_default.cyan(` const auth = getAuth(app);`));
|
|
34014
34100
|
console.log(source_default.cyan(` const { user } = await auth.signIn("email", "pass");`));
|
|
34015
34101
|
}
|
|
34102
|
+
if (cfg.services.storage) {
|
|
34103
|
+
console.log();
|
|
34104
|
+
console.log(source_default.cyan(` await storage.ref("uploads/photo.jpg").upload(file);`));
|
|
34105
|
+
}
|
|
34016
34106
|
if (cfg.services.hosting && cfg.hosting) {
|
|
34017
34107
|
console.log();
|
|
34018
34108
|
console.log(source_default.bold(" Deploy:"));
|
|
34019
|
-
console.log(source_default.cyan(` $ npm run build && clefbase deploy`));
|
|
34109
|
+
console.log(source_default.cyan(` $ npm run build && npx clefbase deploy`));
|
|
34020
34110
|
console.log(source_default.dim(` Site: ${cfg.serverUrl}/hosted/${cfg.projectId}/${cfg.hosting.siteId}`));
|
|
34021
34111
|
}
|
|
34022
34112
|
console.log();
|