artharexian-ui 0.3.3 → 0.3.5

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/cli/index.mjs +155 -14
  2. package/package.json +1 -4
package/cli/index.mjs CHANGED
@@ -1,4 +1,22 @@
1
1
  #!/usr/bin/env node
2
+ /**
3
+ * artharexian-ui CLI
4
+ *
5
+ * Component installer for artharexian-ui library.
6
+ * Downloads components from the registry and installs them to the user's project.
7
+ *
8
+ * Commands:
9
+ * init - Install global styles
10
+ * add <component> - Add a component to the project
11
+ * list - List available components
12
+ *
13
+ * Config:
14
+ * Create artharexian-ui.json in project root to customize paths:
15
+ * {
16
+ * "components": "src/components/ui"
17
+ * }
18
+ */
19
+
2
20
  import fs from 'node:fs'
3
21
  import path from 'node:path'
4
22
  import process from 'node:process'
@@ -7,27 +25,72 @@ import { fileURLToPath } from 'node:url'
7
25
  const __filename = fileURLToPath(import.meta.url)
8
26
  const __dirname = path.dirname(__filename)
9
27
 
28
+ // Registry location (inside the npm package)
10
29
  const REGISTRY_DIR = path.join(__dirname, '..', 'registry')
11
30
  const REGISTRY_JSON = path.join(REGISTRY_DIR, 'registry.json')
12
31
 
32
+ // Current working directory (where user runs the command)
13
33
  const cwd = process.env.INIT_CWD || process.cwd()
14
34
 
15
- // ---------- utils ----------
35
+ // Default configuration
36
+ const DEFAULT_CONFIG = {
37
+ components: 'src/components/ui',
38
+ styles: 'src/styles'
39
+ }
40
+
41
+ /**
42
+ * Load user configuration from artharexian-ui.json
43
+ * Falls back to defaults if config doesn't exist
44
+ */
45
+ function loadConfig() {
46
+ const configPath = path.join(cwd, 'artharexian-ui.json')
47
+ if (fs.existsSync(configPath)) {
48
+ try {
49
+ const userConfig = JSON.parse(fs.readFileSync(configPath, 'utf8'))
50
+ return { ...DEFAULT_CONFIG, ...userConfig }
51
+ } catch {
52
+ console.warn('Warning: Invalid artharexian-ui.json, using defaults')
53
+ }
54
+ }
55
+ return DEFAULT_CONFIG
56
+ }
57
+
58
+ /**
59
+ * Save configuration to artharexian-ui.json
60
+ */
61
+ function saveConfig(config) {
62
+ const configPath = path.join(cwd, 'artharexian-ui.json')
63
+ fs.writeFileSync(configPath, JSON.stringify(config, null, 2) + '\n')
64
+ }
16
65
 
66
+ /**
67
+ * Read and validate registry.json
68
+ * @returns {Object} Registry data
69
+ */
17
70
  function readRegistry() {
18
71
  if (!fs.existsSync(REGISTRY_JSON)) {
19
72
  console.error('Registry not found')
20
73
  process.exit(1)
21
74
  }
22
- return JSON.parse(fs.readFileSync(REGISTRY_JSON, 'utf8'))
23
- }
24
-
25
- function ensureVueProject() {
26
- // Optional: could check for package.json or vue dependency
27
- // For now, just ensure cwd is writable
75
+ try {
76
+ return JSON.parse(fs.readFileSync(REGISTRY_JSON, 'utf8'))
77
+ } catch {
78
+ console.error('Invalid registry.json')
79
+ process.exit(1)
80
+ }
28
81
  }
29
82
 
83
+ /**
84
+ * Copy file from registry to destination
85
+ * Skips if file already exists
86
+ * @param {string} src - Source path in registry
87
+ * @param {string} dest - Destination path in user project
88
+ */
30
89
  function copyFileSafe(src, dest) {
90
+ if (!fs.existsSync(src)) {
91
+ console.error(`Missing file in registry: ${path.basename(src)}`)
92
+ process.exit(1)
93
+ }
31
94
  if (fs.existsSync(dest)) {
32
95
  const rel = path.relative(cwd, dest)
33
96
  console.log(`skip ${rel} (exists)`)
@@ -41,6 +104,9 @@ function copyFileSafe(src, dest) {
41
104
 
42
105
  // ---------- commands ----------
43
106
 
107
+ /**
108
+ * List all available components from registry
109
+ */
44
110
  function listComponents() {
45
111
  const registry = readRegistry()
46
112
  console.log('Available components:\n')
@@ -49,7 +115,12 @@ function listComponents() {
49
115
  })
50
116
  }
51
117
 
118
+ /**
119
+ * Add a component to the user's project
120
+ * @param {string} name - Component name
121
+ */
52
122
  function addComponent(name) {
123
+ const config = loadConfig()
53
124
  const registry = readRegistry()
54
125
  const entry = registry[name]
55
126
 
@@ -59,8 +130,8 @@ function addComponent(name) {
59
130
  process.exit(1)
60
131
  }
61
132
 
62
- // Auto-install styles if not present
63
- const stylesPath = path.join(cwd, 'src', 'styles')
133
+ // Auto-install registry styles if not present
134
+ const stylesPath = path.join(cwd, config.styles)
64
135
  const registryStyles = path.join(REGISTRY_DIR, 'styles')
65
136
  if (!fs.existsSync(stylesPath) && fs.existsSync(registryStyles)) {
66
137
  console.log('Styles not found. Installing...\n')
@@ -72,7 +143,7 @@ function addComponent(name) {
72
143
  }
73
144
 
74
145
  const srcDir = path.join(REGISTRY_DIR, name)
75
- const destDir = path.join(cwd, 'src/components/ui', name)
146
+ const destDir = path.join(cwd, config.components, name)
76
147
 
77
148
  entry.files.forEach((file) => {
78
149
  const src = path.join(srcDir, file)
@@ -83,8 +154,12 @@ function addComponent(name) {
83
154
  console.log(`\n✔ ${name} installed`)
84
155
  }
85
156
 
157
+ /**
158
+ * Initialize artharexian-ui in the project (install global styles)
159
+ */
86
160
  function init() {
87
- const stylesDest = path.join(cwd, 'src', 'styles')
161
+ const config = loadConfig()
162
+ const stylesDest = path.join(cwd, config.styles)
88
163
  const registryStyles = path.join(REGISTRY_DIR, 'styles')
89
164
 
90
165
  if (!fs.existsSync(registryStyles)) {
@@ -101,6 +176,25 @@ function init() {
101
176
  console.log('\n✔ styles installed')
102
177
  }
103
178
 
179
+ /**
180
+ * Initialize configuration file
181
+ */
182
+ function initConfig() {
183
+ const configPath = path.join(cwd, 'artharexian-ui.json')
184
+
185
+ if (fs.existsSync(configPath)) {
186
+ console.log('Config already exists:')
187
+ console.log(fs.readFileSync(configPath, 'utf8'))
188
+ return
189
+ }
190
+
191
+ const config = DEFAULT_CONFIG
192
+ saveConfig(config)
193
+ console.log('Created artharexian-ui.json:')
194
+ console.log(JSON.stringify(config, null, 2))
195
+ console.log('\nEdit this file to customize component installation paths')
196
+ }
197
+
104
198
  // ---------- CLI ----------
105
199
 
106
200
  const args = process.argv.slice(2)
@@ -109,12 +203,27 @@ const component = args[1]
109
203
 
110
204
  if (!command) {
111
205
  console.log(`
112
- artharexian-ui
206
+ artharexian-ui - Component installer
113
207
 
114
208
  Usage:
209
+ npx artharexian-ui init Install global styles
210
+ npx artharexian-ui init-config Create configuration file
211
+ npx artharexian-ui add <component> Add a component
212
+ npx artharexian-ui list List available components
213
+
214
+ Options:
215
+ --help, -h Show this help message
216
+
217
+ Config:
218
+ Create artharexian-ui.json in project root:
219
+ {
220
+ "components": "src/components/ui",
221
+ "styles": "src/styles"
222
+ }
223
+
224
+ Examples:
225
+ npx artharexian-ui add button-base
115
226
  npx artharexian-ui init
116
- npx artharexian-ui add <component>
117
- npx artharexian-ui list
118
227
  `)
119
228
  process.exit(0)
120
229
  }
@@ -138,5 +247,37 @@ if (command === 'init') {
138
247
  process.exit(0)
139
248
  }
140
249
 
250
+ if (command === 'init-config') {
251
+ initConfig()
252
+ process.exit(0)
253
+ }
254
+
255
+ if (command === '--help' || command === '-h') {
256
+ console.log(`
257
+ artharexian-ui - Component installer
258
+
259
+ Usage:
260
+ npx artharexian-ui init Install global styles
261
+ npx artharexian-ui init-config Create configuration file
262
+ npx artharexian-ui add <component> Add a component
263
+ npx artharexian-ui list List available components
264
+
265
+ Options:
266
+ --help, -h Show this help message
267
+
268
+ Config:
269
+ Create artharexian-ui.json in project root:
270
+ {
271
+ "components": "src/components/ui",
272
+ "styles": "src/styles"
273
+ }
274
+
275
+ Examples:
276
+ npx artharexian-ui add button-base
277
+ npx artharexian-ui init
278
+ `)
279
+ process.exit(0)
280
+ }
281
+
141
282
  console.error(`Unknown command: ${command}`)
142
283
  process.exit(1)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "artharexian-ui",
3
3
  "description": "Vue 3 UI component library",
4
- "version": "0.3.3",
4
+ "version": "0.3.5",
5
5
  "license": "MIT",
6
6
  "private": false,
7
7
  "type": "module",
@@ -20,9 +20,6 @@
20
20
  "engines": {
21
21
  "node": ">=18"
22
22
  },
23
- "exports": {
24
- "./styles": "./src/styles/style.css"
25
- },
26
23
  "scripts": {
27
24
  "dev": "vite",
28
25
  "format": "prettier --write .",