artharexian-ui 0.3.4 → 0.3.6
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 +108 -8
- 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,63 @@ 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
|
+
* Auto-creates config if it doesn't exist
|
|
44
|
+
*/
|
|
45
|
+
function ensureConfig() {
|
|
46
|
+
const configPath = path.join(cwd, 'artharexian-ui.json')
|
|
47
|
+
|
|
48
|
+
if (!fs.existsSync(configPath)) {
|
|
49
|
+
saveConfig(DEFAULT_CONFIG)
|
|
50
|
+
console.log('Created artharexian-ui.json')
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return loadConfig()
|
|
54
|
+
}
|
|
16
55
|
|
|
56
|
+
/**
|
|
57
|
+
* Load user configuration from artharexian-ui.json
|
|
58
|
+
* Returns defaults if config doesn't exist (shouldn't happen after ensureConfig)
|
|
59
|
+
*/
|
|
60
|
+
function loadConfig() {
|
|
61
|
+
const configPath = path.join(cwd, 'artharexian-ui.json')
|
|
62
|
+
if (fs.existsSync(configPath)) {
|
|
63
|
+
try {
|
|
64
|
+
const userConfig = JSON.parse(fs.readFileSync(configPath, 'utf8'))
|
|
65
|
+
return { ...DEFAULT_CONFIG, ...userConfig }
|
|
66
|
+
} catch {
|
|
67
|
+
console.warn('Warning: Invalid artharexian-ui.json, using defaults')
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return DEFAULT_CONFIG
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Save configuration to artharexian-ui.json
|
|
75
|
+
*/
|
|
76
|
+
function saveConfig(config) {
|
|
77
|
+
const configPath = path.join(cwd, 'artharexian-ui.json')
|
|
78
|
+
fs.writeFileSync(configPath, JSON.stringify(config, null, 2) + '\n')
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Read and validate registry.json
|
|
83
|
+
* @returns {Object} Registry data
|
|
84
|
+
*/
|
|
17
85
|
function readRegistry() {
|
|
18
86
|
if (!fs.existsSync(REGISTRY_JSON)) {
|
|
19
87
|
console.error('Registry not found')
|
|
@@ -27,6 +95,12 @@ function readRegistry() {
|
|
|
27
95
|
}
|
|
28
96
|
}
|
|
29
97
|
|
|
98
|
+
/**
|
|
99
|
+
* Copy file from registry to destination
|
|
100
|
+
* Skips if file already exists
|
|
101
|
+
* @param {string} src - Source path in registry
|
|
102
|
+
* @param {string} dest - Destination path in user project
|
|
103
|
+
*/
|
|
30
104
|
function copyFileSafe(src, dest) {
|
|
31
105
|
if (!fs.existsSync(src)) {
|
|
32
106
|
console.error(`Missing file in registry: ${path.basename(src)}`)
|
|
@@ -45,6 +119,9 @@ function copyFileSafe(src, dest) {
|
|
|
45
119
|
|
|
46
120
|
// ---------- commands ----------
|
|
47
121
|
|
|
122
|
+
/**
|
|
123
|
+
* List all available components from registry
|
|
124
|
+
*/
|
|
48
125
|
function listComponents() {
|
|
49
126
|
const registry = readRegistry()
|
|
50
127
|
console.log('Available components:\n')
|
|
@@ -53,7 +130,13 @@ function listComponents() {
|
|
|
53
130
|
})
|
|
54
131
|
}
|
|
55
132
|
|
|
133
|
+
/**
|
|
134
|
+
* Add a component to the user's project
|
|
135
|
+
* Auto-installs styles and config if needed
|
|
136
|
+
* @param {string} name - Component name
|
|
137
|
+
*/
|
|
56
138
|
function addComponent(name) {
|
|
139
|
+
const config = ensureConfig()
|
|
57
140
|
const registry = readRegistry()
|
|
58
141
|
const entry = registry[name]
|
|
59
142
|
|
|
@@ -64,7 +147,7 @@ function addComponent(name) {
|
|
|
64
147
|
}
|
|
65
148
|
|
|
66
149
|
// Auto-install registry styles if not present
|
|
67
|
-
const stylesPath = path.join(cwd,
|
|
150
|
+
const stylesPath = path.join(cwd, config.styles)
|
|
68
151
|
const registryStyles = path.join(REGISTRY_DIR, 'styles')
|
|
69
152
|
if (!fs.existsSync(stylesPath) && fs.existsSync(registryStyles)) {
|
|
70
153
|
console.log('Styles not found. Installing...\n')
|
|
@@ -76,7 +159,7 @@ function addComponent(name) {
|
|
|
76
159
|
}
|
|
77
160
|
|
|
78
161
|
const srcDir = path.join(REGISTRY_DIR, name)
|
|
79
|
-
const destDir = path.join(cwd,
|
|
162
|
+
const destDir = path.join(cwd, config.components, name)
|
|
80
163
|
|
|
81
164
|
entry.files.forEach((file) => {
|
|
82
165
|
const src = path.join(srcDir, file)
|
|
@@ -87,8 +170,13 @@ function addComponent(name) {
|
|
|
87
170
|
console.log(`\n✔ ${name} installed`)
|
|
88
171
|
}
|
|
89
172
|
|
|
173
|
+
/**
|
|
174
|
+
* Initialize artharexian-ui in the project (install global styles)
|
|
175
|
+
* Deprecated: styles are auto-installed with components
|
|
176
|
+
*/
|
|
90
177
|
function init() {
|
|
91
|
-
const
|
|
178
|
+
const config = ensureConfig()
|
|
179
|
+
const stylesDest = path.join(cwd, config.styles)
|
|
92
180
|
const registryStyles = path.join(REGISTRY_DIR, 'styles')
|
|
93
181
|
|
|
94
182
|
if (!fs.existsSync(registryStyles)) {
|
|
@@ -111,13 +199,25 @@ const args = process.argv.slice(2)
|
|
|
111
199
|
const command = args[0]
|
|
112
200
|
const component = args[1]
|
|
113
201
|
|
|
114
|
-
if (!command) {
|
|
202
|
+
if (!command || command === '--help' || command === '-h') {
|
|
115
203
|
console.log(`
|
|
116
|
-
artharexian-ui
|
|
204
|
+
artharexian-ui - Component installer
|
|
117
205
|
|
|
118
206
|
Usage:
|
|
119
|
-
npx artharexian-ui
|
|
120
|
-
npx artharexian-ui
|
|
207
|
+
npx artharexian-ui add <component> Add a component (auto-installs styles)
|
|
208
|
+
npx artharexian-ui list List available components
|
|
209
|
+
npx artharexian-ui init Install styles only (optional)
|
|
210
|
+
|
|
211
|
+
Config:
|
|
212
|
+
artharexian-ui.json is auto-created on first use.
|
|
213
|
+
Customize paths:
|
|
214
|
+
{
|
|
215
|
+
"components": "src/components/ui",
|
|
216
|
+
"styles": "src/styles"
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
Examples:
|
|
220
|
+
npx artharexian-ui add button-base
|
|
121
221
|
npx artharexian-ui list
|
|
122
222
|
`)
|
|
123
223
|
process.exit(0)
|