@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.
package/dist/index.js ADDED
@@ -0,0 +1,408 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ detectFrameworkFromDeps: () => detectFrameworkFromDeps,
34
+ init: () => init,
35
+ loadConfig: () => loadConfig,
36
+ pluginRegistry: () => pluginRegistry
37
+ });
38
+ module.exports = __toCommonJS(index_exports);
39
+
40
+ // ../../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
41
+ 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;
42
+ var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
43
+
44
+ // src/plugin-registry.ts
45
+ var import_node_fs = __toESM(require("fs"));
46
+ var import_node_path = __toESM(require("path"));
47
+ var PluginRegistry = class {
48
+ #frameworkPlugins = /* @__PURE__ */ new Map();
49
+ #customPlugins = /* @__PURE__ */ new Map();
50
+ #api;
51
+ constructor() {
52
+ this.#api = this.#createPluginAPI();
53
+ }
54
+ #createPluginAPI() {
55
+ return {
56
+ registerParser: (extensions, _parser) => {
57
+ console.log(`Registered parser for extensions: ${extensions.join(", ")}`);
58
+ },
59
+ registerFieldType: (typeName, fieldType) => {
60
+ console.log(`Registered field type mapping: ${typeName} -> ${fieldType}`);
61
+ },
62
+ onBeforeGenerate: (_callback) => {
63
+ },
64
+ onAfterGenerate: (_callback) => {
65
+ }
66
+ };
67
+ }
68
+ /** Register a framework plugin */
69
+ registerFrameworkPlugin(plugin) {
70
+ this.#frameworkPlugins.set(plugin.name, plugin);
71
+ }
72
+ /** Register a custom plugin */
73
+ registerCustomPlugin(plugin) {
74
+ this.#customPlugins.set(plugin.name, plugin);
75
+ plugin.setup(this.#api);
76
+ }
77
+ /** Get a framework plugin by name */
78
+ getFrameworkPlugin(name) {
79
+ return this.#frameworkPlugins.get(name);
80
+ }
81
+ /** List all registered framework plugins */
82
+ listFrameworkPlugins() {
83
+ return Array.from(this.#frameworkPlugins.keys());
84
+ }
85
+ /** Auto-detect framework from project dependencies */
86
+ async detectFramework(cwd) {
87
+ for (const [name, plugin] of this.#frameworkPlugins) {
88
+ try {
89
+ const detected = await plugin.detect(cwd);
90
+ if (detected) {
91
+ return name;
92
+ }
93
+ } catch {
94
+ }
95
+ }
96
+ return null;
97
+ }
98
+ /** Load plugins from stormy.config.ts */
99
+ async loadConfigPlugins(cwd) {
100
+ const configPath = import_node_path.default.join(cwd, "stormy.config.ts");
101
+ if (!import_node_fs.default.existsSync(configPath)) {
102
+ return;
103
+ }
104
+ try {
105
+ const configModule = await import(configPath);
106
+ const config = configModule.default || configModule;
107
+ if (config.plugins) {
108
+ for (const pluginPath of config.plugins) {
109
+ const resolvedPath = import_node_path.default.resolve(cwd, pluginPath);
110
+ if (import_node_fs.default.existsSync(resolvedPath)) {
111
+ const pluginModule = await import(resolvedPath);
112
+ const plugin = pluginModule.default || pluginModule;
113
+ if (this.#isValidCustomPlugin(plugin)) {
114
+ this.registerCustomPlugin(plugin);
115
+ }
116
+ }
117
+ }
118
+ }
119
+ } catch (error) {
120
+ console.warn("Failed to load stormy.config.ts:", error);
121
+ }
122
+ }
123
+ #isValidCustomPlugin(plugin) {
124
+ return typeof plugin === "object" && plugin !== null && "name" in plugin && "setup" in plugin && typeof plugin.setup === "function";
125
+ }
126
+ };
127
+ var pluginRegistry = new PluginRegistry();
128
+
129
+ // src/config.ts
130
+ var import_node_fs2 = __toESM(require("fs"));
131
+ var import_node_path2 = __toESM(require("path"));
132
+ var DEFAULT_CONFIG = {
133
+ components: "./src/components",
134
+ output: "./componentschema.ts"
135
+ };
136
+ async function loadConfig(cwd) {
137
+ let config = {};
138
+ const configPath = import_node_path2.default.join(cwd, "stormy.config.ts");
139
+ if (import_node_fs2.default.existsSync(configPath)) {
140
+ try {
141
+ const configModule = await import(configPath);
142
+ config = configModule.default || configModule;
143
+ } catch (error) {
144
+ console.warn("Failed to load stormy.config.ts:", error);
145
+ }
146
+ }
147
+ return {
148
+ ...DEFAULT_CONFIG,
149
+ ...config
150
+ };
151
+ }
152
+ async function detectFrameworkFromDeps(cwd) {
153
+ const packageJsonPath = import_node_path2.default.join(cwd, "package.json");
154
+ if (!import_node_fs2.default.existsSync(packageJsonPath)) {
155
+ return null;
156
+ }
157
+ try {
158
+ const content = import_node_fs2.default.readFileSync(packageJsonPath, "utf-8");
159
+ const pkg = JSON.parse(content);
160
+ const deps = { ...pkg.dependencies, ...pkg.devDependencies };
161
+ if (deps["vue"] || deps["@vue/runtime-core"]) return "vue";
162
+ if (deps["svelte"] || deps["svelte-check"]) return "svelte";
163
+ if (deps["solid-js"]) return "solid";
164
+ if (deps["react"] || deps["react-dom"]) return "react";
165
+ return null;
166
+ } catch {
167
+ return null;
168
+ }
169
+ }
170
+
171
+ // src/init.ts
172
+ var import_node_fs3 = __toESM(require("fs"));
173
+ var import_node_path3 = __toESM(require("path"));
174
+ var import_node_url = require("url");
175
+ var import_node_child_process = require("child_process");
176
+ var import_node_util = require("util");
177
+ var import_adm_zip = __toESM(require("adm-zip"));
178
+ var import_prompts = __toESM(require("prompts"));
179
+ var execFileAsync = (0, import_node_util.promisify)(import_node_child_process.execFile);
180
+ var __filename2 = (0, import_node_url.fileURLToPath)(importMetaUrl);
181
+ var __dirname = import_node_path3.default.dirname(__filename2);
182
+ var DEFAULT_PROJECT_NAME = "my-stormy-site";
183
+ var filesToReplaceProjectName = ["package.json", "package-lock.json", "pnpm-lock.yaml", "README.md"];
184
+ var envFiles = ["apps/admin/.env.example", "apps/site/.env.example"];
185
+ var placeholderPattern = /your-[\w-]+-here/;
186
+ async function init(options) {
187
+ const projectName = await promptProjectName(options.projectName);
188
+ const targetDir = options.target ? import_node_path3.default.resolve(options.target) : await promptTargetDirectory(projectName);
189
+ if (import_node_fs3.default.existsSync(targetDir) && import_node_fs3.default.readdirSync(targetDir).length > 0) {
190
+ throw new Error(`Target directory is not empty: ${targetDir}`);
191
+ }
192
+ import_node_fs3.default.mkdirSync(targetDir, { recursive: true });
193
+ console.log("Extracting boilerplate...");
194
+ extractBoilerplate(targetDir);
195
+ console.log("Applying project name...");
196
+ replaceProjectName(targetDir, projectName);
197
+ const envAnswers = await promptEnvValues(targetDir, options.skipEnv);
198
+ await generateEnvFiles(targetDir, envAnswers);
199
+ console.log("Initializing git repository...");
200
+ await initializeGitRepository(targetDir);
201
+ if (!options.skipInstall) {
202
+ console.log("Installing dependencies...");
203
+ await runPnpmInstall(targetDir);
204
+ }
205
+ console.log("\n\u2705 Project initialized successfully!");
206
+ console.log(`
207
+ Location: ${targetDir}`);
208
+ console.log(`Project name: ${projectName}`);
209
+ console.log("\nNext steps:");
210
+ const relativeTarget = import_node_path3.default.relative(process.cwd(), targetDir);
211
+ const cdTarget = relativeTarget.startsWith("..") || import_node_path3.default.isAbsolute(targetDir) ? targetDir : relativeTarget || ".";
212
+ console.log(` cd ${cdTarget}`);
213
+ if (options.skipInstall) console.log(" pnpm install");
214
+ console.log(" pnpm dev");
215
+ console.log("\nThe public site runs at http://localhost:3000");
216
+ console.log("The admin runs at http://localhost:4000");
217
+ console.log("\nConfigure your Stormy CMS credentials in the generated .env files if you skipped them.");
218
+ }
219
+ function findBoilerplateZip() {
220
+ const candidates = [import_node_path3.default.resolve(__dirname, "../boilerplate.zip"), import_node_path3.default.resolve(__dirname, "../../boilerplate.zip")];
221
+ for (const candidate of candidates) {
222
+ if (import_node_fs3.default.existsSync(candidate)) {
223
+ return candidate;
224
+ }
225
+ }
226
+ throw new Error("Boilerplate package not found.");
227
+ }
228
+ function extractBoilerplate(targetDir) {
229
+ const zipPath = findBoilerplateZip();
230
+ const zip = new import_adm_zip.default(zipPath);
231
+ zip.extractAllTo(targetDir, true);
232
+ }
233
+ function isProjectNameSafe(name) {
234
+ return name.length <= 214 && /^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(name);
235
+ }
236
+ async function promptProjectName(providedName) {
237
+ if (providedName) {
238
+ if (!isProjectNameSafe(providedName)) {
239
+ throw new Error("Project name must be lowercase kebab-case (for example, `my-stormy-site`).");
240
+ }
241
+ return providedName;
242
+ }
243
+ const response = await (0, import_prompts.default)({
244
+ type: "text",
245
+ name: "projectName",
246
+ message: "Project name",
247
+ initial: DEFAULT_PROJECT_NAME,
248
+ validate: (value) => {
249
+ if (!value || value.trim().length === 0) {
250
+ return "Project name is required";
251
+ }
252
+ if (!isProjectNameSafe(value)) {
253
+ return "Use lowercase letters, numbers, and single hyphens";
254
+ }
255
+ return true;
256
+ }
257
+ });
258
+ if (!response.projectName) {
259
+ throw new Error("Project name is required.");
260
+ }
261
+ return response.projectName;
262
+ }
263
+ async function promptTargetDirectory(projectName) {
264
+ const initial = `./${projectName}`;
265
+ const response = await (0, import_prompts.default)({
266
+ type: "text",
267
+ name: "target",
268
+ message: "Project directory",
269
+ initial,
270
+ validate: (value) => value?.trim() ? true : "Project directory is required"
271
+ });
272
+ if (!response.target) throw new Error("Project directory is required.");
273
+ return import_node_path3.default.resolve(response.target);
274
+ }
275
+ function replaceProjectName(targetDir, projectName) {
276
+ for (const relativePath of filesToReplaceProjectName) {
277
+ const filePath = import_node_path3.default.join(targetDir, relativePath);
278
+ if (!import_node_fs3.default.existsSync(filePath)) {
279
+ continue;
280
+ }
281
+ const content = import_node_fs3.default.readFileSync(filePath, "utf-8");
282
+ const updated = content.replaceAll("stormy-cms-nextjs-boilerplate", projectName);
283
+ import_node_fs3.default.writeFileSync(filePath, updated, "utf-8");
284
+ }
285
+ }
286
+ function parseEnvFile(filePath) {
287
+ const content = import_node_fs3.default.readFileSync(filePath, "utf-8");
288
+ const values = {};
289
+ for (const line of content.split("\n")) {
290
+ const trimmed = line.trim();
291
+ if (!trimmed || trimmed.startsWith("#")) {
292
+ continue;
293
+ }
294
+ const separatorIndex = trimmed.indexOf("=");
295
+ if (separatorIndex === -1) {
296
+ continue;
297
+ }
298
+ const key = trimmed.slice(0, separatorIndex).trim();
299
+ const value = trimmed.slice(separatorIndex + 1).trim();
300
+ values[key] = value;
301
+ }
302
+ return values;
303
+ }
304
+ function isPlaceholder(value) {
305
+ return placeholderPattern.test(value) || value === "";
306
+ }
307
+ function isDefaultUrl(value) {
308
+ return value.startsWith("http://localhost");
309
+ }
310
+ function groupMissingKeys(values) {
311
+ return Object.entries(values).filter(([_key, value]) => !isDefaultUrl(value) && isPlaceholder(value)).map(([key]) => key);
312
+ }
313
+ async function promptEnvValues(targetDir, skipEnv) {
314
+ const answers = {};
315
+ if (skipEnv) {
316
+ return answers;
317
+ }
318
+ const skipResponse = await (0, import_prompts.default)({
319
+ type: "confirm",
320
+ name: "skip",
321
+ message: "Skip environment variable prompts and create .env files from examples?",
322
+ initial: false
323
+ });
324
+ if (skipResponse.skip) {
325
+ return answers;
326
+ }
327
+ const missingKeyFiles = /* @__PURE__ */ new Map();
328
+ for (const relativePath of envFiles) {
329
+ const examplePath = import_node_path3.default.join(targetDir, relativePath);
330
+ if (!import_node_fs3.default.existsSync(examplePath)) continue;
331
+ const values = parseEnvFile(examplePath);
332
+ for (const key of groupMissingKeys(values)) {
333
+ missingKeyFiles.set(key, [...missingKeyFiles.get(key) ?? [], relativePath]);
334
+ }
335
+ }
336
+ for (const [key, relativePaths] of missingKeyFiles) {
337
+ const response = await (0, import_prompts.default)({
338
+ type: key.includes("SECRET") ? "password" : "text",
339
+ name: "value",
340
+ message: `${key} (${relativePaths.join(", ")})`
341
+ });
342
+ if (!response.value) continue;
343
+ for (const relativePath of relativePaths) {
344
+ answers[relativePath] ??= {};
345
+ answers[relativePath][key] = response.value;
346
+ }
347
+ }
348
+ return answers;
349
+ }
350
+ async function initializeGitRepository(targetDir) {
351
+ const gitDir = import_node_path3.default.join(targetDir, ".git");
352
+ if (import_node_fs3.default.existsSync(gitDir)) {
353
+ return;
354
+ }
355
+ try {
356
+ await execFileAsync("git", ["init"], { cwd: targetDir });
357
+ await execFileAsync("git", ["add", "."], { cwd: targetDir });
358
+ await execFileAsync("git", ["commit", "-m", "Initial commit"], { cwd: targetDir });
359
+ } catch (error) {
360
+ console.warn(`Warning: could not initialize git repository: ${error}`);
361
+ }
362
+ }
363
+ async function generateEnvFiles(targetDir, answers) {
364
+ for (const relativePath of envFiles) {
365
+ const examplePath = import_node_path3.default.join(targetDir, relativePath);
366
+ if (!import_node_fs3.default.existsSync(examplePath)) {
367
+ continue;
368
+ }
369
+ const values = parseEnvFile(examplePath);
370
+ const fileAnswers = answers[relativePath] ?? {};
371
+ let content = "";
372
+ const lines = import_node_fs3.default.readFileSync(examplePath, "utf-8").split("\n");
373
+ for (const line of lines) {
374
+ const trimmed = line.trim();
375
+ if (!trimmed || trimmed.startsWith("#")) {
376
+ content += line + "\n";
377
+ continue;
378
+ }
379
+ const separatorIndex = trimmed.indexOf("=");
380
+ if (separatorIndex === -1) {
381
+ content += line + "\n";
382
+ continue;
383
+ }
384
+ const key = trimmed.slice(0, separatorIndex).trim();
385
+ const value = fileAnswers[key] ?? values[key];
386
+ content += `${key}=${value}
387
+ `;
388
+ }
389
+ const envPath = import_node_path3.default.join(targetDir, relativePath.replace(".env.example", ".env"));
390
+ import_node_fs3.default.mkdirSync(import_node_path3.default.dirname(envPath), { recursive: true });
391
+ import_node_fs3.default.writeFileSync(envPath, content, "utf-8");
392
+ }
393
+ }
394
+ async function runPnpmInstall(targetDir) {
395
+ try {
396
+ await execFileAsync("pnpm", ["install", "--frozen-lockfile"], { cwd: targetDir, timeout: 3e5 });
397
+ } catch (error) {
398
+ const execError = error;
399
+ throw new Error(`Failed to install dependencies: ${execError.stderr ?? execError.stdout ?? String(error)}`);
400
+ }
401
+ }
402
+ // Annotate the CommonJS export names for ESM import in node:
403
+ 0 && (module.exports = {
404
+ detectFrameworkFromDeps,
405
+ init,
406
+ loadConfig,
407
+ pluginRegistry
408
+ });