@stormycms/cli 0.0.10

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.
Binary file
package/dist/cli.js ADDED
@@ -0,0 +1,482 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
18
+ // If the importer is in node compatibility mode or this is not an ESM
19
+ // file that has been converted to a CommonJS file using a Babel-
20
+ // compatible transform (i.e. "__esModule" has not been set), then set
21
+ // "default" to the CommonJS "module.exports" for node compatibility.
22
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
23
+ mod
24
+ ));
25
+
26
+ // ../../node_modules/.pnpm/tsup@8.5.1_postcss@8.5.16_tsx@4.23.0_typescript@5.9.3/node_modules/tsup/assets/cjs_shims.js
27
+ var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.tagName.toUpperCase() === "SCRIPT" ? document.currentScript.src : new URL("main.js", document.baseURI).href;
28
+ var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
29
+
30
+ // src/cli.ts
31
+ var import_commander = require("commander");
32
+
33
+ // src/plugin-registry.ts
34
+ var import_node_fs = __toESM(require("fs"));
35
+ var import_node_path = __toESM(require("path"));
36
+ var PluginRegistry = class {
37
+ #frameworkPlugins = /* @__PURE__ */ new Map();
38
+ #customPlugins = /* @__PURE__ */ new Map();
39
+ #api;
40
+ constructor() {
41
+ this.#api = this.#createPluginAPI();
42
+ }
43
+ #createPluginAPI() {
44
+ return {
45
+ registerParser: (extensions, _parser) => {
46
+ console.log(`Registered parser for extensions: ${extensions.join(", ")}`);
47
+ },
48
+ registerFieldType: (typeName, fieldType) => {
49
+ console.log(`Registered field type mapping: ${typeName} -> ${fieldType}`);
50
+ },
51
+ onBeforeGenerate: (_callback) => {
52
+ },
53
+ onAfterGenerate: (_callback) => {
54
+ }
55
+ };
56
+ }
57
+ /** Register a framework plugin */
58
+ registerFrameworkPlugin(plugin) {
59
+ this.#frameworkPlugins.set(plugin.name, plugin);
60
+ }
61
+ /** Register a custom plugin */
62
+ registerCustomPlugin(plugin) {
63
+ this.#customPlugins.set(plugin.name, plugin);
64
+ plugin.setup(this.#api);
65
+ }
66
+ /** Get a framework plugin by name */
67
+ getFrameworkPlugin(name) {
68
+ return this.#frameworkPlugins.get(name);
69
+ }
70
+ /** List all registered framework plugins */
71
+ listFrameworkPlugins() {
72
+ return Array.from(this.#frameworkPlugins.keys());
73
+ }
74
+ /** Auto-detect framework from project dependencies */
75
+ async detectFramework(cwd) {
76
+ for (const [name, plugin] of this.#frameworkPlugins) {
77
+ try {
78
+ const detected = await plugin.detect(cwd);
79
+ if (detected) {
80
+ return name;
81
+ }
82
+ } catch {
83
+ }
84
+ }
85
+ return null;
86
+ }
87
+ /** Load plugins from stormy.config.ts */
88
+ async loadConfigPlugins(cwd) {
89
+ const configPath = import_node_path.default.join(cwd, "stormy.config.ts");
90
+ if (!import_node_fs.default.existsSync(configPath)) {
91
+ return;
92
+ }
93
+ try {
94
+ const configModule = await import(configPath);
95
+ const config = configModule.default || configModule;
96
+ if (config.plugins) {
97
+ for (const pluginPath of config.plugins) {
98
+ const resolvedPath = import_node_path.default.resolve(cwd, pluginPath);
99
+ if (import_node_fs.default.existsSync(resolvedPath)) {
100
+ const pluginModule = await import(resolvedPath);
101
+ const plugin = pluginModule.default || pluginModule;
102
+ if (this.#isValidCustomPlugin(plugin)) {
103
+ this.registerCustomPlugin(plugin);
104
+ }
105
+ }
106
+ }
107
+ }
108
+ } catch (error) {
109
+ console.warn("Failed to load stormy.config.ts:", error);
110
+ }
111
+ }
112
+ #isValidCustomPlugin(plugin) {
113
+ return typeof plugin === "object" && plugin !== null && "name" in plugin && "setup" in plugin && typeof plugin.setup === "function";
114
+ }
115
+ };
116
+ var pluginRegistry = new PluginRegistry();
117
+ async function loadBuiltInPlugins() {
118
+ try {
119
+ const reactPlugin = await import("@stormycms/react/plugin");
120
+ if (reactPlugin.default) {
121
+ pluginRegistry.registerFrameworkPlugin(reactPlugin.default);
122
+ }
123
+ } catch {
124
+ }
125
+ }
126
+
127
+ // src/config.ts
128
+ var import_node_fs2 = __toESM(require("fs"));
129
+ var import_node_path2 = __toESM(require("path"));
130
+ var DEFAULT_CONFIG = {
131
+ components: "./src/components",
132
+ output: "./componentschema.ts"
133
+ };
134
+ async function loadConfig(cwd) {
135
+ let config = {};
136
+ const configPath = import_node_path2.default.join(cwd, "stormy.config.ts");
137
+ if (import_node_fs2.default.existsSync(configPath)) {
138
+ try {
139
+ const configModule = await import(configPath);
140
+ config = configModule.default || configModule;
141
+ } catch (error) {
142
+ console.warn("Failed to load stormy.config.ts:", error);
143
+ }
144
+ }
145
+ return {
146
+ ...DEFAULT_CONFIG,
147
+ ...config
148
+ };
149
+ }
150
+ async function detectFrameworkFromDeps(cwd) {
151
+ const packageJsonPath = import_node_path2.default.join(cwd, "package.json");
152
+ if (!import_node_fs2.default.existsSync(packageJsonPath)) {
153
+ return null;
154
+ }
155
+ try {
156
+ const content = import_node_fs2.default.readFileSync(packageJsonPath, "utf-8");
157
+ const pkg = JSON.parse(content);
158
+ const deps = { ...pkg.dependencies, ...pkg.devDependencies };
159
+ if (deps["vue"] || deps["@vue/runtime-core"]) return "vue";
160
+ if (deps["svelte"] || deps["svelte-check"]) return "svelte";
161
+ if (deps["solid-js"]) return "solid";
162
+ if (deps["react"] || deps["react-dom"]) return "react";
163
+ return null;
164
+ } catch {
165
+ return null;
166
+ }
167
+ }
168
+
169
+ // src/generate.ts
170
+ var import_node_fs3 = __toESM(require("fs"));
171
+ var import_node_path3 = __toESM(require("path"));
172
+ async function generate(options) {
173
+ const cwd = process.cwd();
174
+ const config = await loadConfig(cwd);
175
+ await loadBuiltInPlugins();
176
+ await pluginRegistry.loadConfigPlugins(cwd);
177
+ let framework = config.framework;
178
+ if (!framework) {
179
+ framework = await detectFrameworkFromDeps(cwd);
180
+ if (!framework) {
181
+ framework = await pluginRegistry.detectFramework(cwd);
182
+ }
183
+ }
184
+ if (!framework) {
185
+ console.error(
186
+ "Could not detect framework. Please install a Stormy CMS framework package (e.g., @stormycms/react) or specify framework in stormy.config.ts"
187
+ );
188
+ process.exit(1);
189
+ }
190
+ const plugin = pluginRegistry.getFrameworkPlugin(framework);
191
+ if (!plugin) {
192
+ console.error(
193
+ `Framework plugin '${framework}' not found. Please install @stormycms/${framework} or a compatible plugin.`
194
+ );
195
+ console.error(`Available plugins: ${pluginRegistry.listFrameworkPlugins().join(", ") || "none"}`);
196
+ process.exit(1);
197
+ }
198
+ console.log(`Using framework plugin: ${plugin.name}`);
199
+ try {
200
+ runGeneration(plugin, options);
201
+ } catch (error) {
202
+ console.error("Generation failed:", error);
203
+ process.exit(1);
204
+ }
205
+ }
206
+ function runGeneration(plugin, options) {
207
+ const componentsDir = import_node_path3.default.resolve(process.cwd(), options.components);
208
+ const outputPath = import_node_path3.default.resolve(process.cwd(), options.output);
209
+ const outputDir = import_node_path3.default.dirname(outputPath);
210
+ if (!import_node_fs3.default.existsSync(componentsDir)) {
211
+ console.error(`Components directory not found: ${componentsDir}`);
212
+ process.exit(1);
213
+ }
214
+ const components = plugin.parseComponents(options);
215
+ if (components.length === 0) {
216
+ console.warn("No valid components found in component files.");
217
+ return;
218
+ }
219
+ const relativePath = import_node_path3.default.relative(outputDir, componentsDir).replace(/\\/g, "/");
220
+ const importBasePath = relativePath.startsWith(".") ? relativePath : `./${relativePath}`;
221
+ const output = plugin.generateSchema(components, importBasePath);
222
+ import_node_fs3.default.mkdirSync(outputDir, { recursive: true });
223
+ import_node_fs3.default.writeFileSync(outputPath, output, "utf-8");
224
+ const totalFields = components.reduce((sum, c) => sum + c.fields.length, 0);
225
+ console.log(`Generated ${outputPath} with ${components.length} component(s) and ${totalFields} field(s)`);
226
+ }
227
+
228
+ // src/init.ts
229
+ var import_node_fs4 = __toESM(require("fs"));
230
+ var import_node_path4 = __toESM(require("path"));
231
+ var import_node_url = require("url");
232
+ var import_node_child_process = require("child_process");
233
+ var import_node_util = require("util");
234
+ var import_adm_zip = __toESM(require("adm-zip"));
235
+ var import_prompts = __toESM(require("prompts"));
236
+ var execFileAsync = (0, import_node_util.promisify)(import_node_child_process.execFile);
237
+ var __filename2 = (0, import_node_url.fileURLToPath)(importMetaUrl);
238
+ var __dirname = import_node_path4.default.dirname(__filename2);
239
+ var DEFAULT_PROJECT_NAME = "my-stormy-site";
240
+ var filesToReplaceProjectName = ["package.json", "package-lock.json", "pnpm-lock.yaml", "README.md"];
241
+ var envFiles = ["apps/admin/.env.example", "apps/site/.env.example"];
242
+ var placeholderPattern = /your-[\w-]+-here/;
243
+ async function init(options) {
244
+ const projectName = await promptProjectName(options.projectName);
245
+ const targetDir = options.target ? import_node_path4.default.resolve(options.target) : await promptTargetDirectory(projectName);
246
+ if (import_node_fs4.default.existsSync(targetDir) && import_node_fs4.default.readdirSync(targetDir).length > 0) {
247
+ throw new Error(`Target directory is not empty: ${targetDir}`);
248
+ }
249
+ import_node_fs4.default.mkdirSync(targetDir, { recursive: true });
250
+ console.log("Extracting boilerplate...");
251
+ extractBoilerplate(targetDir);
252
+ console.log("Applying project name...");
253
+ replaceProjectName(targetDir, projectName);
254
+ const envAnswers = await promptEnvValues(targetDir, options.skipEnv);
255
+ await generateEnvFiles(targetDir, envAnswers);
256
+ console.log("Initializing git repository...");
257
+ await initializeGitRepository(targetDir);
258
+ if (!options.skipInstall) {
259
+ console.log("Installing dependencies...");
260
+ await runPnpmInstall(targetDir);
261
+ }
262
+ console.log("\n\u2705 Project initialized successfully!");
263
+ console.log(`
264
+ Location: ${targetDir}`);
265
+ console.log(`Project name: ${projectName}`);
266
+ console.log("\nNext steps:");
267
+ const relativeTarget = import_node_path4.default.relative(process.cwd(), targetDir);
268
+ const cdTarget = relativeTarget.startsWith("..") || import_node_path4.default.isAbsolute(targetDir) ? targetDir : relativeTarget || ".";
269
+ console.log(` cd ${cdTarget}`);
270
+ if (options.skipInstall) console.log(" pnpm install");
271
+ console.log(" pnpm dev");
272
+ console.log("\nThe public site runs at http://localhost:3000");
273
+ console.log("The admin runs at http://localhost:4000");
274
+ console.log("\nConfigure your Stormy CMS credentials in the generated .env files if you skipped them.");
275
+ }
276
+ function findBoilerplateZip() {
277
+ const candidates = [import_node_path4.default.resolve(__dirname, "../boilerplate.zip"), import_node_path4.default.resolve(__dirname, "../../boilerplate.zip")];
278
+ for (const candidate of candidates) {
279
+ if (import_node_fs4.default.existsSync(candidate)) {
280
+ return candidate;
281
+ }
282
+ }
283
+ throw new Error("Boilerplate package not found.");
284
+ }
285
+ function extractBoilerplate(targetDir) {
286
+ const zipPath = findBoilerplateZip();
287
+ const zip = new import_adm_zip.default(zipPath);
288
+ zip.extractAllTo(targetDir, true);
289
+ }
290
+ function isProjectNameSafe(name) {
291
+ return name.length <= 214 && /^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(name);
292
+ }
293
+ async function promptProjectName(providedName) {
294
+ if (providedName) {
295
+ if (!isProjectNameSafe(providedName)) {
296
+ throw new Error("Project name must be lowercase kebab-case (for example, `my-stormy-site`).");
297
+ }
298
+ return providedName;
299
+ }
300
+ const response = await (0, import_prompts.default)({
301
+ type: "text",
302
+ name: "projectName",
303
+ message: "Project name",
304
+ initial: DEFAULT_PROJECT_NAME,
305
+ validate: (value) => {
306
+ if (!value || value.trim().length === 0) {
307
+ return "Project name is required";
308
+ }
309
+ if (!isProjectNameSafe(value)) {
310
+ return "Use lowercase letters, numbers, and single hyphens";
311
+ }
312
+ return true;
313
+ }
314
+ });
315
+ if (!response.projectName) {
316
+ throw new Error("Project name is required.");
317
+ }
318
+ return response.projectName;
319
+ }
320
+ async function promptTargetDirectory(projectName) {
321
+ const initial = `./${projectName}`;
322
+ const response = await (0, import_prompts.default)({
323
+ type: "text",
324
+ name: "target",
325
+ message: "Project directory",
326
+ initial,
327
+ validate: (value) => value?.trim() ? true : "Project directory is required"
328
+ });
329
+ if (!response.target) throw new Error("Project directory is required.");
330
+ return import_node_path4.default.resolve(response.target);
331
+ }
332
+ function replaceProjectName(targetDir, projectName) {
333
+ for (const relativePath of filesToReplaceProjectName) {
334
+ const filePath = import_node_path4.default.join(targetDir, relativePath);
335
+ if (!import_node_fs4.default.existsSync(filePath)) {
336
+ continue;
337
+ }
338
+ const content = import_node_fs4.default.readFileSync(filePath, "utf-8");
339
+ const updated = content.replaceAll("stormy-cms-nextjs-boilerplate", projectName);
340
+ import_node_fs4.default.writeFileSync(filePath, updated, "utf-8");
341
+ }
342
+ }
343
+ function parseEnvFile(filePath) {
344
+ const content = import_node_fs4.default.readFileSync(filePath, "utf-8");
345
+ const values = {};
346
+ for (const line of content.split("\n")) {
347
+ const trimmed = line.trim();
348
+ if (!trimmed || trimmed.startsWith("#")) {
349
+ continue;
350
+ }
351
+ const separatorIndex = trimmed.indexOf("=");
352
+ if (separatorIndex === -1) {
353
+ continue;
354
+ }
355
+ const key = trimmed.slice(0, separatorIndex).trim();
356
+ const value = trimmed.slice(separatorIndex + 1).trim();
357
+ values[key] = value;
358
+ }
359
+ return values;
360
+ }
361
+ function isPlaceholder(value) {
362
+ return placeholderPattern.test(value) || value === "";
363
+ }
364
+ function isDefaultUrl(value) {
365
+ return value.startsWith("http://localhost");
366
+ }
367
+ function groupMissingKeys(values) {
368
+ return Object.entries(values).filter(([_key, value]) => !isDefaultUrl(value) && isPlaceholder(value)).map(([key]) => key);
369
+ }
370
+ async function promptEnvValues(targetDir, skipEnv) {
371
+ const answers = {};
372
+ if (skipEnv) {
373
+ return answers;
374
+ }
375
+ const skipResponse = await (0, import_prompts.default)({
376
+ type: "confirm",
377
+ name: "skip",
378
+ message: "Skip environment variable prompts and create .env files from examples?",
379
+ initial: false
380
+ });
381
+ if (skipResponse.skip) {
382
+ return answers;
383
+ }
384
+ const missingKeyFiles = /* @__PURE__ */ new Map();
385
+ for (const relativePath of envFiles) {
386
+ const examplePath = import_node_path4.default.join(targetDir, relativePath);
387
+ if (!import_node_fs4.default.existsSync(examplePath)) continue;
388
+ const values = parseEnvFile(examplePath);
389
+ for (const key of groupMissingKeys(values)) {
390
+ missingKeyFiles.set(key, [...missingKeyFiles.get(key) ?? [], relativePath]);
391
+ }
392
+ }
393
+ for (const [key, relativePaths] of missingKeyFiles) {
394
+ const response = await (0, import_prompts.default)({
395
+ type: key.includes("SECRET") ? "password" : "text",
396
+ name: "value",
397
+ message: `${key} (${relativePaths.join(", ")})`
398
+ });
399
+ if (!response.value) continue;
400
+ for (const relativePath of relativePaths) {
401
+ answers[relativePath] ??= {};
402
+ answers[relativePath][key] = response.value;
403
+ }
404
+ }
405
+ return answers;
406
+ }
407
+ async function initializeGitRepository(targetDir) {
408
+ const gitDir = import_node_path4.default.join(targetDir, ".git");
409
+ if (import_node_fs4.default.existsSync(gitDir)) {
410
+ return;
411
+ }
412
+ try {
413
+ await execFileAsync("git", ["init"], { cwd: targetDir });
414
+ await execFileAsync("git", ["add", "."], { cwd: targetDir });
415
+ await execFileAsync("git", ["commit", "-m", "Initial commit"], { cwd: targetDir });
416
+ } catch (error) {
417
+ console.warn(`Warning: could not initialize git repository: ${error}`);
418
+ }
419
+ }
420
+ async function generateEnvFiles(targetDir, answers) {
421
+ for (const relativePath of envFiles) {
422
+ const examplePath = import_node_path4.default.join(targetDir, relativePath);
423
+ if (!import_node_fs4.default.existsSync(examplePath)) {
424
+ continue;
425
+ }
426
+ const values = parseEnvFile(examplePath);
427
+ const fileAnswers = answers[relativePath] ?? {};
428
+ let content = "";
429
+ const lines = import_node_fs4.default.readFileSync(examplePath, "utf-8").split("\n");
430
+ for (const line of lines) {
431
+ const trimmed = line.trim();
432
+ if (!trimmed || trimmed.startsWith("#")) {
433
+ content += line + "\n";
434
+ continue;
435
+ }
436
+ const separatorIndex = trimmed.indexOf("=");
437
+ if (separatorIndex === -1) {
438
+ content += line + "\n";
439
+ continue;
440
+ }
441
+ const key = trimmed.slice(0, separatorIndex).trim();
442
+ const value = fileAnswers[key] ?? values[key];
443
+ content += `${key}=${value}
444
+ `;
445
+ }
446
+ const envPath = import_node_path4.default.join(targetDir, relativePath.replace(".env.example", ".env"));
447
+ import_node_fs4.default.mkdirSync(import_node_path4.default.dirname(envPath), { recursive: true });
448
+ import_node_fs4.default.writeFileSync(envPath, content, "utf-8");
449
+ }
450
+ }
451
+ async function runPnpmInstall(targetDir) {
452
+ try {
453
+ await execFileAsync("pnpm", ["install", "--frozen-lockfile"], { cwd: targetDir, timeout: 3e5 });
454
+ } catch (error) {
455
+ const execError = error;
456
+ throw new Error(`Failed to install dependencies: ${execError.stderr ?? execError.stdout ?? String(error)}`);
457
+ }
458
+ }
459
+
460
+ // src/cli.ts
461
+ var program = new import_commander.Command();
462
+ program.name("stormy").description("Stormy CMS CLI tools").version("0.1.0");
463
+ program.command("generate").description("Generate CMS-wrapped components from component files").option("-c, --components <path>", "Path to the components directory", "./src/components").option("-o, --output <path>", "Output file path", "./componentschema.ts").option("-f, --framework <name>", "Framework to use (auto-detected if not specified)").action(async (options) => {
464
+ await generate({
465
+ components: options.components,
466
+ output: options.output
467
+ });
468
+ });
469
+ program.command("init").description("Initialize a new Stormy CMS project from the boilerplate").option("-n, --name <name>", "Project name").option("-t, --target <path>", "Target directory (defaults to ./{project name})").option("--skip-env", "Skip environment variable prompts and use example values").option("--skip-install", "Create the project without installing dependencies").action(async (options) => {
470
+ try {
471
+ await init({
472
+ projectName: options.name,
473
+ target: options.target,
474
+ skipEnv: options.skipEnv,
475
+ skipInstall: options.skipInstall
476
+ });
477
+ } catch (error) {
478
+ console.error(error instanceof Error ? error.message : error);
479
+ process.exitCode = 1;
480
+ }
481
+ });
482
+ program.parse();
@@ -0,0 +1,100 @@
1
+ /**
2
+ * Stormy CMS Plugin Interface
3
+ *
4
+ * Frameworks implement this interface to provide component parsing
5
+ * and schema generation capabilities.
6
+ */
7
+ type PropField = {
8
+ label: string;
9
+ prop: string;
10
+ field: string;
11
+ fn?: string;
12
+ options?: string[];
13
+ fieldTypes?: string[];
14
+ subFields?: PropField[];
15
+ };
16
+ type ComponentInfo = {
17
+ name: string;
18
+ fileName: string;
19
+ export: string;
20
+ componentId: string;
21
+ label: string;
22
+ fields: PropField[];
23
+ };
24
+ type GenerateOptions = {
25
+ components: string;
26
+ output: string;
27
+ };
28
+ type InitOptions = {
29
+ projectName?: string;
30
+ target?: string;
31
+ skipEnv?: boolean;
32
+ skipInstall?: boolean;
33
+ };
34
+ type StormyConfig = {
35
+ framework?: string;
36
+ components: string;
37
+ output: string;
38
+ plugins?: string[];
39
+ };
40
+ /**
41
+ * A Stormy CMS plugin for a specific framework
42
+ */
43
+ interface StormyPlugin {
44
+ /** Plugin name (e.g., 'react', 'vue', 'svelte') */
45
+ name: string;
46
+ /** Detect if this framework is used in the project */
47
+ detect: (cwd: string) => boolean | Promise<boolean>;
48
+ /** Parse component files and extract metadata */
49
+ parseComponents: (options: GenerateOptions) => ComponentInfo[];
50
+ /** Generate the schema file content */
51
+ generateSchema: (components: ComponentInfo[], importBasePath: string) => string;
52
+ }
53
+ /**
54
+ * Custom plugin interface for consumers
55
+ */
56
+ interface CustomPlugin {
57
+ name: string;
58
+ setup: (api: PluginAPI) => void;
59
+ }
60
+ interface PluginAPI {
61
+ /** Register a parser for specific file extensions */
62
+ registerParser: (extensions: string[], parser: FileParser) => void;
63
+ /** Register a field type mapping */
64
+ registerFieldType: (typeName: string, fieldType: string) => void;
65
+ /** Hook into the generate lifecycle */
66
+ onBeforeGenerate: (callback: (options: GenerateOptions) => void | Promise<void>) => void;
67
+ onAfterGenerate: (callback: (options: GenerateOptions, output: string) => void | Promise<void>) => void;
68
+ }
69
+ type FileParser = (filePath: string, content: string) => ComponentInfo | null;
70
+
71
+ declare class PluginRegistry {
72
+ #private;
73
+ constructor();
74
+ /** Register a framework plugin */
75
+ registerFrameworkPlugin(plugin: StormyPlugin): void;
76
+ /** Register a custom plugin */
77
+ registerCustomPlugin(plugin: CustomPlugin): void;
78
+ /** Get a framework plugin by name */
79
+ getFrameworkPlugin(name: string): StormyPlugin | undefined;
80
+ /** List all registered framework plugins */
81
+ listFrameworkPlugins(): string[];
82
+ /** Auto-detect framework from project dependencies */
83
+ detectFramework(cwd: string): Promise<string | null>;
84
+ /** Load plugins from stormy.config.ts */
85
+ loadConfigPlugins(cwd: string): Promise<void>;
86
+ }
87
+ declare const pluginRegistry: PluginRegistry;
88
+
89
+ /**
90
+ * Load Stormy configuration from stormy.config.ts or package.json
91
+ */
92
+ declare function loadConfig(cwd: string): Promise<StormyConfig>;
93
+ /**
94
+ * Detect framework from package.json dependencies
95
+ */
96
+ declare function detectFrameworkFromDeps(cwd: string): Promise<string | null>;
97
+
98
+ declare function init(options: InitOptions): Promise<void>;
99
+
100
+ export { type ComponentInfo, type CustomPlugin, type FileParser, type GenerateOptions, type InitOptions, type PluginAPI, type PropField, type StormyConfig, type StormyPlugin, detectFrameworkFromDeps, init, loadConfig, pluginRegistry };
@@ -0,0 +1,100 @@
1
+ /**
2
+ * Stormy CMS Plugin Interface
3
+ *
4
+ * Frameworks implement this interface to provide component parsing
5
+ * and schema generation capabilities.
6
+ */
7
+ type PropField = {
8
+ label: string;
9
+ prop: string;
10
+ field: string;
11
+ fn?: string;
12
+ options?: string[];
13
+ fieldTypes?: string[];
14
+ subFields?: PropField[];
15
+ };
16
+ type ComponentInfo = {
17
+ name: string;
18
+ fileName: string;
19
+ export: string;
20
+ componentId: string;
21
+ label: string;
22
+ fields: PropField[];
23
+ };
24
+ type GenerateOptions = {
25
+ components: string;
26
+ output: string;
27
+ };
28
+ type InitOptions = {
29
+ projectName?: string;
30
+ target?: string;
31
+ skipEnv?: boolean;
32
+ skipInstall?: boolean;
33
+ };
34
+ type StormyConfig = {
35
+ framework?: string;
36
+ components: string;
37
+ output: string;
38
+ plugins?: string[];
39
+ };
40
+ /**
41
+ * A Stormy CMS plugin for a specific framework
42
+ */
43
+ interface StormyPlugin {
44
+ /** Plugin name (e.g., 'react', 'vue', 'svelte') */
45
+ name: string;
46
+ /** Detect if this framework is used in the project */
47
+ detect: (cwd: string) => boolean | Promise<boolean>;
48
+ /** Parse component files and extract metadata */
49
+ parseComponents: (options: GenerateOptions) => ComponentInfo[];
50
+ /** Generate the schema file content */
51
+ generateSchema: (components: ComponentInfo[], importBasePath: string) => string;
52
+ }
53
+ /**
54
+ * Custom plugin interface for consumers
55
+ */
56
+ interface CustomPlugin {
57
+ name: string;
58
+ setup: (api: PluginAPI) => void;
59
+ }
60
+ interface PluginAPI {
61
+ /** Register a parser for specific file extensions */
62
+ registerParser: (extensions: string[], parser: FileParser) => void;
63
+ /** Register a field type mapping */
64
+ registerFieldType: (typeName: string, fieldType: string) => void;
65
+ /** Hook into the generate lifecycle */
66
+ onBeforeGenerate: (callback: (options: GenerateOptions) => void | Promise<void>) => void;
67
+ onAfterGenerate: (callback: (options: GenerateOptions, output: string) => void | Promise<void>) => void;
68
+ }
69
+ type FileParser = (filePath: string, content: string) => ComponentInfo | null;
70
+
71
+ declare class PluginRegistry {
72
+ #private;
73
+ constructor();
74
+ /** Register a framework plugin */
75
+ registerFrameworkPlugin(plugin: StormyPlugin): void;
76
+ /** Register a custom plugin */
77
+ registerCustomPlugin(plugin: CustomPlugin): void;
78
+ /** Get a framework plugin by name */
79
+ getFrameworkPlugin(name: string): StormyPlugin | undefined;
80
+ /** List all registered framework plugins */
81
+ listFrameworkPlugins(): string[];
82
+ /** Auto-detect framework from project dependencies */
83
+ detectFramework(cwd: string): Promise<string | null>;
84
+ /** Load plugins from stormy.config.ts */
85
+ loadConfigPlugins(cwd: string): Promise<void>;
86
+ }
87
+ declare const pluginRegistry: PluginRegistry;
88
+
89
+ /**
90
+ * Load Stormy configuration from stormy.config.ts or package.json
91
+ */
92
+ declare function loadConfig(cwd: string): Promise<StormyConfig>;
93
+ /**
94
+ * Detect framework from package.json dependencies
95
+ */
96
+ declare function detectFrameworkFromDeps(cwd: string): Promise<string | null>;
97
+
98
+ declare function init(options: InitOptions): Promise<void>;
99
+
100
+ export { type ComponentInfo, type CustomPlugin, type FileParser, type GenerateOptions, type InitOptions, type PluginAPI, type PropField, type StormyConfig, type StormyPlugin, detectFrameworkFromDeps, init, loadConfig, pluginRegistry };