domma-js 0.9.8-alpha → 0.9.9-alpha

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.
Files changed (2) hide show
  1. package/bin/domma-cli.js +88 -45
  2. package/package.json +1 -1
package/bin/domma-cli.js CHANGED
@@ -9,6 +9,11 @@ import {stdin as input, stdout as output} from 'process';
9
9
  const __filename = fileURLToPath(import.meta.url);
10
10
  const __dirname = dirname(__filename);
11
11
 
12
+ // Read version from package.json
13
+ const packageJsonPath = join(__dirname, '..', 'package.json');
14
+ const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));
15
+ const VERSION = packageJson.version;
16
+
12
17
  const THEMES = [
13
18
  'charcoal-dark', 'ocean-dark', 'forest-dark', 'sunset-light',
14
19
  'silver-light', 'ocean-light', 'forest-light', 'sunset-dark',
@@ -20,29 +25,33 @@ const args = process.argv.slice(2);
20
25
  const command = args[0];
21
26
 
22
27
  // Command routing
23
- // Check if first arg is a flag (starts with --)
24
- if (command && command.startsWith('--')) {
25
- // Treat flags as init command
26
- handleInit();
27
- } else {
28
- switch (command) {
29
- case 'init':
30
- case undefined:
28
+ switch (command) {
29
+ case 'init':
30
+ case undefined:
31
+ handleInit();
32
+ break;
33
+ case 'add':
34
+ handleAdd();
35
+ break;
36
+ case 'version':
37
+ case '--version':
38
+ case '-v':
39
+ showVersion();
40
+ break;
41
+ case 'help':
42
+ case '--help':
43
+ case '-h':
44
+ showHelp();
45
+ break;
46
+ default:
47
+ // Check if it's a --flag for init
48
+ if (command && command.startsWith('--')) {
31
49
  handleInit();
32
- break;
33
- case 'add':
34
- handleAdd();
35
- break;
36
- case 'help':
37
- case '--help':
38
- case '-h':
39
- showHelp();
40
- break;
41
- default:
50
+ } else {
42
51
  console.error(`Unknown command: ${command}`);
43
52
  showHelp();
44
53
  process.exit(1);
45
- }
54
+ }
46
55
  }
47
56
 
48
57
  /**
@@ -56,6 +65,7 @@ async function handleInit() {
56
65
  ╔═══════════════════════════════════════╗
57
66
  ║ ║
58
67
  ║ Welcome to Domma CLI! ║
68
+ ║ v${VERSION.padEnd(24)}║
59
69
  ║ ║
60
70
  ╚═══════════════════════════════════════╝
61
71
 
@@ -188,7 +198,7 @@ async function handleAdd() {
188
198
  */
189
199
  async function handleAddPage() {
190
200
  const quickMode = args.includes('--quick');
191
- let pageName = args[2];
201
+ let pagePath = args[2];
192
202
 
193
203
  // Check if we're in a Domma project
194
204
  const configPath = join(process.cwd(), 'domma.config.json');
@@ -198,22 +208,23 @@ async function handleAddPage() {
198
208
  process.exit(1);
199
209
  }
200
210
 
201
- if (!pageName && quickMode) {
202
- console.error('Page name required with --quick flag');
203
- console.log('Usage: npx domma-js add page <name> --quick');
211
+ if (!pagePath && quickMode) {
212
+ console.error('Page path required with --quick flag');
213
+ console.log('Usage: npx domma-js add page <path> --quick');
214
+ console.log('Example: npx domma-js add page frontend/pages/dashboard --quick');
204
215
  process.exit(1);
205
216
  }
206
217
 
207
218
  if (!quickMode) {
208
219
  const rl = readline.createInterface({input, output});
209
220
 
210
- if (!pageName) {
211
- const nameAnswer = await rl.question(' Page name: ');
212
- pageName = nameAnswer.trim();
221
+ if (!pagePath) {
222
+ const pathAnswer = await rl.question(' Page path (e.g., frontend/pages/dashboard): ');
223
+ pagePath = pathAnswer.trim();
213
224
  }
214
225
 
215
- if (!pageName) {
216
- console.error(' ✗ Page name is required');
226
+ if (!pagePath) {
227
+ console.error(' ✗ Page path is required');
217
228
  rl.close();
218
229
  process.exit(1);
219
230
  }
@@ -221,26 +232,35 @@ async function handleAddPage() {
221
232
  rl.close();
222
233
  }
223
234
 
224
- // Validate and sanitize page name
225
- pageName = pageName.toLowerCase().replace(/[^a-z0-9-]/g, '-');
235
+ // Parse the path to extract directory and page name
236
+ const pathParts = pagePath.split('/').filter(p => p.length > 0);
237
+ const pageName = pathParts[pathParts.length - 1].toLowerCase().replace(/[^a-z0-9-]/g, '-');
238
+ const pageDir = pathParts.slice(0, -1).join('/');
226
239
 
227
240
  // Create page
228
- createPage(pageName);
241
+ createPage(pageDir, pageName);
229
242
  }
230
243
 
231
244
  /**
232
245
  * Create a new page from template
233
246
  */
234
- function createPage(pageName) {
235
- const pagesDir = join(process.cwd(), 'pages', pageName);
247
+ function createPage(pageDir, pageName) {
248
+ // Build full path
249
+ const fullPath = pageDir ? join(process.cwd(), pageDir, pageName) : join(process.cwd(), pageName);
236
250
 
237
- if (existsSync(pagesDir)) {
238
- console.error(`\n ✗ Page "${pageName}" already exists`);
251
+ if (existsSync(fullPath)) {
252
+ console.error(`\n ✗ Page "${pageName}" already exists at this location`);
239
253
  process.exit(1);
240
254
  }
241
255
 
242
256
  // Create directory
243
- mkdirSync(pagesDir, {recursive: true});
257
+ mkdirSync(fullPath, {recursive: true});
258
+
259
+ // Calculate depth for relative paths
260
+ // Count how many folders deep we are from project root
261
+ const pathSegments = pageDir ? pageDir.split('/').filter(p => p.length > 0) : [];
262
+ const depth = pathSegments.length + 1; // +1 for the page folder itself
263
+ const parentPath = '../'.repeat(depth);
244
264
 
245
265
  // Get templates
246
266
  const pageTemplateDir = join(__dirname, '..', 'templates', 'page-template');
@@ -251,7 +271,7 @@ function createPage(pageName) {
251
271
  }
252
272
 
253
273
  // Read templates
254
- const htmlTemplate = readFileSync(join(pageTemplateDir, 'page.html'), 'utf-8');
274
+ let htmlTemplate = readFileSync(join(pageTemplateDir, 'page.html'), 'utf-8');
255
275
  const jsTemplate = readFileSync(join(pageTemplateDir, 'page.js'), 'utf-8');
256
276
 
257
277
  // Get project config for theme
@@ -266,6 +286,13 @@ function createPage(pageName) {
266
286
  }
267
287
  }
268
288
 
289
+ // Adjust paths in template based on depth
290
+ // Template has ../../ by default (depth 2)
291
+ // We need to replace with the correct depth
292
+ htmlTemplate = htmlTemplate.replaceAll('../../dist/domma/', `${parentPath}dist/domma/`);
293
+ htmlTemplate = htmlTemplate.replaceAll('../../css/', `${parentPath}css/`);
294
+ htmlTemplate = htmlTemplate.replaceAll('../../js/', `${parentPath}js/`);
295
+
269
296
  // Variable substitution
270
297
  const titleCase = pageName.split('-').map(w =>
271
298
  w.charAt(0).toUpperCase() + w.slice(1)
@@ -286,12 +313,14 @@ function createPage(pageName) {
286
313
  }
287
314
 
288
315
  // Write files
289
- writeFileSync(join(pagesDir, 'index.html'), html);
290
- writeFileSync(join(pagesDir, `${pageName}.js`), js);
316
+ writeFileSync(join(fullPath, 'index.html'), html);
317
+ writeFileSync(join(fullPath, `${pageName}.js`), js);
291
318
 
292
- console.log(`\n ✓ Page created: pages/${pageName}/`);
319
+ const displayPath = pageDir ? `${pageDir}/${pageName}` : pageName;
320
+ console.log(`\n ✓ Page created: ${displayPath}/`);
293
321
  console.log(` - index.html`);
294
- console.log(` - ${pageName}.js\n`);
322
+ console.log(` - ${pageName}.js`);
323
+ console.log(` Depth: ${depth} (using ${parentPath})\n`);
295
324
  console.log(` Don't forget to add it to your navbar in domma.config.json!\n`);
296
325
  }
297
326
 
@@ -328,26 +357,40 @@ function copyTemplatesRecursive(srcDir, destDir, vars) {
328
357
  }
329
358
  }
330
359
 
360
+ /**
361
+ * Show version information
362
+ */
363
+ function showVersion() {
364
+ console.log(`domma-js v${VERSION}`);
365
+ }
366
+
331
367
  /**
332
368
  * Show help information
333
369
  */
334
370
  function showHelp() {
335
371
  console.log(`
336
- Domma CLI - Project scaffolding and management
372
+ Domma CLI v${VERSION} - Project scaffolding and management
337
373
 
338
374
  Commands:
339
375
  npx domma-js Initialize a new Domma project
340
376
  npx domma-js init Initialize a new Domma project
341
- npx domma-js add page <name> Add a new page
377
+ npx domma-js add page <path> Add a new page at specified path
342
378
  --quick Skip interactive prompts
343
379
 
344
380
  Options:
345
381
  --help, -h Show this help message
382
+ --version, -v Show version number
346
383
 
347
384
  Examples:
348
385
  npx domma-js # Interactive project setup
349
386
  npx domma-js --quick # Quick project setup with defaults
350
- npx domma-js add page dashboard # Add a dashboard page (interactive)
351
- npx domma-js add page faq --quick # Add FAQ page (non-interactive)
387
+
388
+ # Add pages at different paths:
389
+ npx domma-js add page admin # Root level (admin/)
390
+ npx domma-js add page pages/dashboard # One level deep (pages/dashboard/)
391
+ npx domma-js add page frontend/pages/profile # Two levels deep (frontend/pages/profile/)
392
+ npx domma-js add page src/views/settings --quick # Quick mode (non-interactive)
393
+
394
+ Note: Paths are automatically calculated based on folder depth
352
395
  `);
353
396
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "domma-js",
3
- "version": "0.9.8-alpha",
3
+ "version": "0.9.9-alpha",
4
4
  "description": "Dynamic Object Manipulation & Modeling API - A complete front-end toolkit.",
5
5
  "main": "public/dist/domma.min.js",
6
6
  "module": "public/dist/domma.esm.js",