uniweb 0.2.12 → 0.2.13

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "uniweb",
3
- "version": "0.2.12",
3
+ "version": "0.2.13",
4
4
  "description": "Create structured Vite + React sites with content/code separation",
5
5
  "type": "module",
6
6
  "bin": {
@@ -34,6 +34,6 @@
34
34
  "handlebars": "^4.7.8",
35
35
  "prompts": "^2.4.2",
36
36
  "tar": "^7.0.0",
37
- "@uniweb/build": "0.1.4"
37
+ "@uniweb/build": "0.1.5"
38
38
  }
39
39
  }
@@ -0,0 +1,143 @@
1
+ /**
2
+ * Docs Command
3
+ *
4
+ * Generates markdown documentation from foundation schema.
5
+ *
6
+ * Usage:
7
+ * uniweb docs # Generate docs for current directory
8
+ * uniweb docs --output README.md # Custom output filename
9
+ * uniweb docs --from-source # Build schema from source (no build required)
10
+ */
11
+
12
+ import { existsSync } from 'node:fs'
13
+ import { resolve, join } from 'node:path'
14
+ import { generateDocs } from '@uniweb/build'
15
+
16
+ // Colors for terminal output
17
+ const colors = {
18
+ reset: '\x1b[0m',
19
+ bright: '\x1b[1m',
20
+ dim: '\x1b[2m',
21
+ cyan: '\x1b[36m',
22
+ green: '\x1b[32m',
23
+ yellow: '\x1b[33m',
24
+ red: '\x1b[31m',
25
+ }
26
+
27
+ function log(message) {
28
+ console.log(message)
29
+ }
30
+
31
+ function success(message) {
32
+ console.log(`${colors.green}✓${colors.reset} ${message}`)
33
+ }
34
+
35
+ function error(message) {
36
+ console.error(`${colors.red}✗${colors.reset} ${message}`)
37
+ }
38
+
39
+ function info(message) {
40
+ console.log(`${colors.cyan}→${colors.reset} ${message}`)
41
+ }
42
+
43
+ /**
44
+ * Parse command line arguments
45
+ */
46
+ function parseArgs(args) {
47
+ const options = {
48
+ output: 'COMPONENTS.md',
49
+ fromSource: false,
50
+ }
51
+
52
+ for (let i = 0; i < args.length; i++) {
53
+ const arg = args[i]
54
+
55
+ if (arg === '--output' || arg === '-o') {
56
+ options.output = args[++i]
57
+ } else if (arg === '--from-source' || arg === '-s') {
58
+ options.fromSource = true
59
+ } else if (arg === '--help' || arg === '-h') {
60
+ options.help = true
61
+ }
62
+ }
63
+
64
+ return options
65
+ }
66
+
67
+ /**
68
+ * Show help message
69
+ */
70
+ function showHelp() {
71
+ log(`
72
+ ${colors.bright}uniweb docs${colors.reset} - Generate component documentation
73
+
74
+ ${colors.dim}Usage:${colors.reset}
75
+ uniweb docs Generate COMPONENTS.md from schema.json
76
+ uniweb docs --output DOCS.md Custom output filename
77
+ uniweb docs --from-source Build schema from source (no build required)
78
+
79
+ ${colors.dim}Options:${colors.reset}
80
+ -o, --output <file> Output filename (default: COMPONENTS.md)
81
+ -s, --from-source Read meta.js files directly instead of schema.json
82
+ -h, --help Show this help message
83
+
84
+ ${colors.dim}Notes:${colors.reset}
85
+ By default, docs are generated from dist/schema.json (requires build).
86
+ Use --from-source to generate without building first.
87
+ `)
88
+ }
89
+
90
+ /**
91
+ * Detect if current directory is a foundation
92
+ */
93
+ function isFoundation(dir) {
94
+ const srcDir = join(dir, 'src')
95
+ const componentsDir = join(srcDir, 'components')
96
+ return existsSync(componentsDir)
97
+ }
98
+
99
+ /**
100
+ * Main docs command
101
+ */
102
+ export async function docs(args) {
103
+ const options = parseArgs(args)
104
+
105
+ if (options.help) {
106
+ showHelp()
107
+ return
108
+ }
109
+
110
+ const projectDir = resolve(process.cwd())
111
+
112
+ // Verify this is a foundation
113
+ if (!isFoundation(projectDir)) {
114
+ error('This directory does not appear to be a foundation.')
115
+ log(`${colors.dim}Foundations have a src/components/ directory with component folders.${colors.reset}`)
116
+ process.exit(1)
117
+ }
118
+
119
+ // Check if schema.json exists (if not using --from-source)
120
+ const schemaPath = join(projectDir, 'dist', 'schema.json')
121
+ if (!options.fromSource && !existsSync(schemaPath)) {
122
+ log(`${colors.yellow}⚠${colors.reset} No dist/schema.json found.`)
123
+ log(`${colors.dim}Run 'uniweb build' first, or use '--from-source' to read meta.js files directly.${colors.reset}`)
124
+ log('')
125
+ info('Falling back to --from-source mode')
126
+ options.fromSource = true
127
+ }
128
+
129
+ try {
130
+ info('Generating documentation...')
131
+
132
+ const result = await generateDocs(projectDir, {
133
+ output: options.output,
134
+ fromSource: options.fromSource,
135
+ })
136
+
137
+ success(`Generated ${result.outputPath}`)
138
+ log(`${colors.dim}Documented ${result.componentCount} components${colors.reset}`)
139
+ } catch (err) {
140
+ error(`Failed to generate docs: ${err.message}`)
141
+ process.exit(1)
142
+ }
143
+ }
package/src/index.js CHANGED
@@ -3,14 +3,13 @@
3
3
  /**
4
4
  * Uniweb CLI
5
5
  *
6
- * Scaffolds new Uniweb sites and foundations, and builds projects.
6
+ * Scaffolds new Uniweb sites and foundations, builds projects, and generates docs.
7
7
  *
8
8
  * Usage:
9
9
  * npx uniweb create [project-name]
10
- * npx uniweb create --template single # site/ + foundation/ (default)
11
- * npx uniweb create --template multi # sites/* + foundations/*
10
+ * npx uniweb create --template marketing
12
11
  * npx uniweb build
13
- * npx uniweb build --target foundation
12
+ * npx uniweb docs # Generate COMPONENTS.md from schema
14
13
  */
15
14
 
16
15
  import { existsSync, mkdirSync, writeFileSync, readFileSync } from 'node:fs'
@@ -18,6 +17,7 @@ import { resolve, join, dirname } from 'node:path'
18
17
  import { fileURLToPath } from 'node:url'
19
18
  import prompts from 'prompts'
20
19
  import { build } from './commands/build.js'
20
+ import { docs } from './commands/docs.js'
21
21
  import { getVersionsForTemplates, getVersion } from './versions.js'
22
22
  import {
23
23
  resolveTemplate,
@@ -84,6 +84,12 @@ async function main() {
84
84
  return
85
85
  }
86
86
 
87
+ // Handle docs command
88
+ if (command === 'docs') {
89
+ await docs(args.slice(1))
90
+ return
91
+ }
92
+
87
93
  // Handle create command
88
94
  if (command !== 'create') {
89
95
  error(`Unknown command: ${command}`)
@@ -239,6 +245,7 @@ ${colors.bright}Usage:${colors.reset}
239
245
  ${colors.bright}Commands:${colors.reset}
240
246
  create [name] Create a new project
241
247
  build Build the current project
248
+ docs Generate component documentation
242
249
 
243
250
  ${colors.bright}Create Options:${colors.reset}
244
251
  --template <type> Project template
@@ -251,6 +258,10 @@ ${colors.bright}Build Options:${colors.reset}
251
258
  --foundation-dir Path to foundation directory (for prerendering)
252
259
  --platform <name> Deployment platform (e.g., vercel) for platform-specific output
253
260
 
261
+ ${colors.bright}Docs Options:${colors.reset}
262
+ --output <file> Output filename (default: COMPONENTS.md)
263
+ --from-source Read meta.js files directly instead of schema.json
264
+
254
265
  ${colors.bright}Template Types:${colors.reset}
255
266
  single One site + one foundation (default)
256
267
  multi Multiple sites and foundations
@@ -268,6 +279,7 @@ ${colors.bright}Examples:${colors.reset}
268
279
  npx uniweb build
269
280
  npx uniweb build --target foundation
270
281
  npx uniweb build --prerender # Build site + pre-render to static HTML
282
+ cd foundation && npx uniweb docs # Generate COMPONENTS.md
271
283
  `)
272
284
  }
273
285
 
package/src/versions.js CHANGED
@@ -72,6 +72,9 @@ export function getResolvedVersions() {
72
72
  '@uniweb/runtime': '^0.1.0',
73
73
  '@uniweb/core': '^0.1.0',
74
74
 
75
+ // Foundation utility library (used by official templates)
76
+ '@uniweb/kit': '^0.1.0',
77
+
75
78
  // CLI itself (use current version)
76
79
  'uniweb': `^${pkg.version}`,
77
80
  }
@@ -106,6 +109,7 @@ export function getVersionsForTemplates() {
106
109
  build: versions['@uniweb/build'],
107
110
  runtime: versions['@uniweb/runtime'],
108
111
  core: versions['@uniweb/core'],
112
+ kit: versions['@uniweb/kit'],
109
113
  templates: versions['@uniweb/templates'],
110
114
  cli: versions['uniweb'],
111
115
  }