artharexian-ui 0.3.4 → 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.
- package/cli/index.mjs +144 -7
- package/package.json +1 -1
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,13 +25,48 @@ 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
|
-
//
|
|
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')
|
|
@@ -27,6 +80,12 @@ function readRegistry() {
|
|
|
27
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) {
|
|
31
90
|
if (!fs.existsSync(src)) {
|
|
32
91
|
console.error(`Missing file in registry: ${path.basename(src)}`)
|
|
@@ -45,6 +104,9 @@ function copyFileSafe(src, dest) {
|
|
|
45
104
|
|
|
46
105
|
// ---------- commands ----------
|
|
47
106
|
|
|
107
|
+
/**
|
|
108
|
+
* List all available components from registry
|
|
109
|
+
*/
|
|
48
110
|
function listComponents() {
|
|
49
111
|
const registry = readRegistry()
|
|
50
112
|
console.log('Available components:\n')
|
|
@@ -53,7 +115,12 @@ function listComponents() {
|
|
|
53
115
|
})
|
|
54
116
|
}
|
|
55
117
|
|
|
118
|
+
/**
|
|
119
|
+
* Add a component to the user's project
|
|
120
|
+
* @param {string} name - Component name
|
|
121
|
+
*/
|
|
56
122
|
function addComponent(name) {
|
|
123
|
+
const config = loadConfig()
|
|
57
124
|
const registry = readRegistry()
|
|
58
125
|
const entry = registry[name]
|
|
59
126
|
|
|
@@ -64,7 +131,7 @@ function addComponent(name) {
|
|
|
64
131
|
}
|
|
65
132
|
|
|
66
133
|
// Auto-install registry styles if not present
|
|
67
|
-
const stylesPath = path.join(cwd,
|
|
134
|
+
const stylesPath = path.join(cwd, config.styles)
|
|
68
135
|
const registryStyles = path.join(REGISTRY_DIR, 'styles')
|
|
69
136
|
if (!fs.existsSync(stylesPath) && fs.existsSync(registryStyles)) {
|
|
70
137
|
console.log('Styles not found. Installing...\n')
|
|
@@ -76,7 +143,7 @@ function addComponent(name) {
|
|
|
76
143
|
}
|
|
77
144
|
|
|
78
145
|
const srcDir = path.join(REGISTRY_DIR, name)
|
|
79
|
-
const destDir = path.join(cwd,
|
|
146
|
+
const destDir = path.join(cwd, config.components, name)
|
|
80
147
|
|
|
81
148
|
entry.files.forEach((file) => {
|
|
82
149
|
const src = path.join(srcDir, file)
|
|
@@ -87,8 +154,12 @@ function addComponent(name) {
|
|
|
87
154
|
console.log(`\n✔ ${name} installed`)
|
|
88
155
|
}
|
|
89
156
|
|
|
157
|
+
/**
|
|
158
|
+
* Initialize artharexian-ui in the project (install global styles)
|
|
159
|
+
*/
|
|
90
160
|
function init() {
|
|
91
|
-
const
|
|
161
|
+
const config = loadConfig()
|
|
162
|
+
const stylesDest = path.join(cwd, config.styles)
|
|
92
163
|
const registryStyles = path.join(REGISTRY_DIR, 'styles')
|
|
93
164
|
|
|
94
165
|
if (!fs.existsSync(registryStyles)) {
|
|
@@ -105,6 +176,25 @@ function init() {
|
|
|
105
176
|
console.log('\n✔ styles installed')
|
|
106
177
|
}
|
|
107
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
|
+
|
|
108
198
|
// ---------- CLI ----------
|
|
109
199
|
|
|
110
200
|
const args = process.argv.slice(2)
|
|
@@ -113,12 +203,27 @@ const component = args[1]
|
|
|
113
203
|
|
|
114
204
|
if (!command) {
|
|
115
205
|
console.log(`
|
|
116
|
-
artharexian-ui
|
|
206
|
+
artharexian-ui - Component installer
|
|
117
207
|
|
|
118
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
|
|
119
226
|
npx artharexian-ui init
|
|
120
|
-
npx artharexian-ui add <component>
|
|
121
|
-
npx artharexian-ui list
|
|
122
227
|
`)
|
|
123
228
|
process.exit(0)
|
|
124
229
|
}
|
|
@@ -142,5 +247,37 @@ if (command === 'init') {
|
|
|
142
247
|
process.exit(0)
|
|
143
248
|
}
|
|
144
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
|
+
|
|
145
282
|
console.error(`Unknown command: ${command}`)
|
|
146
283
|
process.exit(1)
|