rxn-ui 0.5.5 → 0.5.7
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/add.js +79 -73
- package/cli/constants.js +11 -11
- package/cli/registry.json +24 -28
- package/cli/utils/fetch.js +25 -25
- package/cli/utils/getSourceUrl.js +7 -3
- package/package.json +1 -1
package/cli/add.js
CHANGED
|
@@ -1,73 +1,79 @@
|
|
|
1
|
-
import fs from 'node:fs'
|
|
2
|
-
import path from 'node:path'
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
import { loadConfig } from './utils/config.js'
|
|
6
|
-
import { fetchFile, fetchJSON } from './utils/fetch.js'
|
|
7
|
-
import { getSourceUrl } from './utils/getSourceUrl.js'
|
|
8
|
-
import { log } from './utils/logger.js'
|
|
9
|
-
|
|
10
|
-
export async function add(
|
|
11
|
-
const config = loadConfig()
|
|
12
|
-
if (!config) {
|
|
13
|
-
log.error('Not initialized. Run: npx rxn-ui init')
|
|
14
|
-
process.exit(1)
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const tag = cmdOptions.tag || null
|
|
18
|
-
const registryUrl = getRegistryUrl(tag)
|
|
19
|
-
|
|
20
|
-
let registry
|
|
21
|
-
try {
|
|
22
|
-
registry = await fetchJSON(registryUrl)
|
|
23
|
-
} catch (err) {
|
|
24
|
-
log.error(`Failed to fetch registry: ${err.message}`)
|
|
25
|
-
process.exit(1)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const entry = registry[
|
|
29
|
-
if (!entry) {
|
|
30
|
-
log.error(`Component "${
|
|
31
|
-
log.info(`Available components: ${Object.keys(registry).join(', ')}`)
|
|
32
|
-
process.exit(1)
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
log.bold(`\nAdding ${
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
1
|
+
import fs from 'node:fs'
|
|
2
|
+
import path from 'node:path'
|
|
3
|
+
|
|
4
|
+
import { STYLES_FILES, cwd, getRegistryUrl } from './constants.js'
|
|
5
|
+
import { loadConfig } from './utils/config.js'
|
|
6
|
+
import { fetchFile, fetchJSON } from './utils/fetch.js'
|
|
7
|
+
import { getSourceUrl } from './utils/getSourceUrl.js'
|
|
8
|
+
import { log } from './utils/logger.js'
|
|
9
|
+
|
|
10
|
+
export async function add(componentName, cmdOptions = {}) {
|
|
11
|
+
const config = loadConfig()
|
|
12
|
+
if (!config) {
|
|
13
|
+
log.error('Not initialized. Run: npx rxn-ui init')
|
|
14
|
+
process.exit(1)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const tag = cmdOptions.tag || null
|
|
18
|
+
const registryUrl = getRegistryUrl(tag)
|
|
19
|
+
|
|
20
|
+
let registry
|
|
21
|
+
try {
|
|
22
|
+
registry = await fetchJSON(registryUrl)
|
|
23
|
+
} catch (err) {
|
|
24
|
+
log.error(`Failed to fetch registry: ${err.message}`)
|
|
25
|
+
process.exit(1)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const entry = registry[componentName]
|
|
29
|
+
if (!entry) {
|
|
30
|
+
log.error(`Component "${componentName}" not found`)
|
|
31
|
+
log.info(`Available components: ${Object.keys(registry).join(', ')}`)
|
|
32
|
+
process.exit(1)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Если файлов больше одного — скачиваем в папку с именем компонента
|
|
36
|
+
const isMultipleFiles = entry.files.length > 1
|
|
37
|
+
const destDir = isMultipleFiles
|
|
38
|
+
? path.join(cwd, config[entry.type], componentName)
|
|
39
|
+
: path.join(cwd, config[entry.type])
|
|
40
|
+
|
|
41
|
+
log.bold(`\nAdding ${componentName}...`)
|
|
42
|
+
|
|
43
|
+
// Скачиваем файлы компонента
|
|
44
|
+
await downloadItems({
|
|
45
|
+
type: entry.type,
|
|
46
|
+
componentName: isMultipleFiles ? componentName : null,
|
|
47
|
+
files: entry.files,
|
|
48
|
+
tag,
|
|
49
|
+
destDir,
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
// Скачиваем стили
|
|
53
|
+
const stylesDir = path.join(cwd, config.styles)
|
|
54
|
+
await downloadItems({
|
|
55
|
+
type: 'styles',
|
|
56
|
+
componentName: null,
|
|
57
|
+
files: STYLES_FILES,
|
|
58
|
+
tag,
|
|
59
|
+
destDir: stylesDir,
|
|
60
|
+
})
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async function downloadItems({ type, componentName, files, tag, destDir }) {
|
|
64
|
+
log.bold(`\nAdding ${type}...`)
|
|
65
|
+
fs.mkdirSync(destDir, { recursive: true })
|
|
66
|
+
|
|
67
|
+
for (const file of files) {
|
|
68
|
+
const url = getSourceUrl(type, componentName, file, tag)
|
|
69
|
+
const destPath = path.join(destDir, file)
|
|
70
|
+
|
|
71
|
+
try {
|
|
72
|
+
const content = await fetchFile(url)
|
|
73
|
+
fs.writeFileSync(destPath, content)
|
|
74
|
+
log.success(`Added ${path.relative(cwd, destPath)}`)
|
|
75
|
+
} catch (err) {
|
|
76
|
+
log.error(`Failed to download ${file}: ${err.message}`)
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
package/cli/constants.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import process from 'node:process'
|
|
2
|
-
|
|
3
|
-
export const GITHUB_REPO = 'r2-h/artharexian-ui'
|
|
4
|
-
export const GITHUB_RAW = `https://raw.githubusercontent.com/${GITHUB_REPO}/main`
|
|
5
|
-
|
|
6
|
-
export const cwd = process.env.INIT_CWD || process.cwd()
|
|
7
|
-
export const STYLES_FILES = ['style.css', 'variables.css']
|
|
8
|
-
|
|
9
|
-
export function getRegistryUrl(tag) {
|
|
10
|
-
return tag ? `${GITHUB_RAW}/cli/registry.json?ref=${tag}` : `${GITHUB_RAW}/cli/registry.json`
|
|
11
|
-
}
|
|
1
|
+
import process from 'node:process'
|
|
2
|
+
|
|
3
|
+
export const GITHUB_REPO = 'r2-h/artharexian-ui'
|
|
4
|
+
export const GITHUB_RAW = `https://raw.githubusercontent.com/${GITHUB_REPO}/main`
|
|
5
|
+
|
|
6
|
+
export const cwd = process.env.INIT_CWD || process.cwd()
|
|
7
|
+
export const STYLES_FILES = ['style.css', 'variables.css']
|
|
8
|
+
|
|
9
|
+
export function getRegistryUrl(tag) {
|
|
10
|
+
return tag ? `${GITHUB_RAW}/cli/registry.json?ref=${tag}` : `${GITHUB_RAW}/cli/registry.json`
|
|
11
|
+
}
|
package/cli/registry.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"button-base": {
|
|
3
|
-
"
|
|
3
|
+
"type": "components",
|
|
4
4
|
"files": ["ButtonBase.vue", "types.ts"],
|
|
5
|
-
"
|
|
6
|
-
"
|
|
5
|
+
"description": "Accessible button primitive",
|
|
6
|
+
"dependencies": []
|
|
7
7
|
},
|
|
8
8
|
"card-base": {
|
|
9
|
-
"
|
|
9
|
+
"type": "components",
|
|
10
10
|
"files": [
|
|
11
11
|
"CardBase.vue",
|
|
12
12
|
"CardContent.vue",
|
|
@@ -15,37 +15,35 @@
|
|
|
15
15
|
"CardHeader.vue",
|
|
16
16
|
"CardTitle.vue"
|
|
17
17
|
],
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"import { CardBase, CardHeader, CardTitle, CardDescription, CardContent, CardFooter } from '@/components/card-base'"
|
|
21
|
-
]
|
|
18
|
+
"description": "Card container components",
|
|
19
|
+
"dependencies": []
|
|
22
20
|
},
|
|
23
21
|
"checkbox-base": {
|
|
24
|
-
"
|
|
22
|
+
"type": "components",
|
|
25
23
|
"files": ["CheckboxBase.vue"],
|
|
26
|
-
"
|
|
27
|
-
"
|
|
24
|
+
"description": "Checkbox input primitive",
|
|
25
|
+
"dependencies": []
|
|
28
26
|
},
|
|
29
27
|
"input-base": {
|
|
30
|
-
"
|
|
28
|
+
"type": "components",
|
|
31
29
|
"files": ["InputBase.vue", "types.ts"],
|
|
32
|
-
"
|
|
33
|
-
"
|
|
30
|
+
"description": "Text input primitive",
|
|
31
|
+
"dependencies": []
|
|
34
32
|
},
|
|
35
33
|
"range-base": {
|
|
36
|
-
"
|
|
34
|
+
"type": "components",
|
|
37
35
|
"files": ["RangeBase.vue", "RangeOutput.vue", "types.ts"],
|
|
38
|
-
"
|
|
39
|
-
"
|
|
36
|
+
"description": "Range slider primitive",
|
|
37
|
+
"dependencies": []
|
|
40
38
|
},
|
|
41
39
|
"switch-base": {
|
|
42
|
-
"
|
|
40
|
+
"type": "components",
|
|
43
41
|
"files": ["SwitchBase.vue"],
|
|
44
|
-
"
|
|
45
|
-
"
|
|
42
|
+
"description": "Toggle switch primitive",
|
|
43
|
+
"dependencies": []
|
|
46
44
|
},
|
|
47
45
|
"tabs": {
|
|
48
|
-
"
|
|
46
|
+
"type": "components",
|
|
49
47
|
"files": [
|
|
50
48
|
"context.ts",
|
|
51
49
|
"TabsBase.vue",
|
|
@@ -55,15 +53,13 @@
|
|
|
55
53
|
"TabsTab.vue",
|
|
56
54
|
"types.ts"
|
|
57
55
|
],
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"import { TabsBase, TabsList, TabsTab, TabsIndicator, TabsPanel } from '@/components/tabs'"
|
|
61
|
-
]
|
|
56
|
+
"description": "Tab navigation components",
|
|
57
|
+
"dependencies": []
|
|
62
58
|
},
|
|
63
59
|
"use-theme": {
|
|
64
|
-
"
|
|
60
|
+
"type": "composables",
|
|
65
61
|
"files": ["useTheme.ts"],
|
|
66
|
-
"
|
|
67
|
-
"
|
|
62
|
+
"description": "Composable theme switcher",
|
|
63
|
+
"dependencies": []
|
|
68
64
|
}
|
|
69
65
|
}
|
package/cli/utils/fetch.js
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Fetch file content from URL
|
|
3
|
-
* @param {string} url - URL to fetch
|
|
4
|
-
* @returns {Promise<string>}
|
|
5
|
-
*/
|
|
6
|
-
export async function fetchFile(url) {
|
|
7
|
-
const res = await fetch(url)
|
|
8
|
-
if (!res.ok) {
|
|
9
|
-
if (res.status === 404) {
|
|
10
|
-
throw new Error(`File not found: ${url}`)
|
|
11
|
-
}
|
|
12
|
-
throw new Error(`Failed to fetch: ${url} (${res.status})`)
|
|
13
|
-
}
|
|
14
|
-
return res.text()
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Fetch and parse JSON from URL
|
|
19
|
-
* @param {string} url - URL to fetch
|
|
20
|
-
* @returns {Promise<object>}
|
|
21
|
-
*/
|
|
22
|
-
export async function fetchJSON(url) {
|
|
23
|
-
const content = await fetchFile(url)
|
|
24
|
-
return JSON.parse(content)
|
|
25
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Fetch file content from URL
|
|
3
|
+
* @param {string} url - URL to fetch
|
|
4
|
+
* @returns {Promise<string>}
|
|
5
|
+
*/
|
|
6
|
+
export async function fetchFile(url) {
|
|
7
|
+
const res = await fetch(url)
|
|
8
|
+
if (!res.ok) {
|
|
9
|
+
if (res.status === 404) {
|
|
10
|
+
throw new Error(`File not found: ${url}`)
|
|
11
|
+
}
|
|
12
|
+
throw new Error(`Failed to fetch: ${url} (${res.status})`)
|
|
13
|
+
}
|
|
14
|
+
return res.text()
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Fetch and parse JSON from URL
|
|
19
|
+
* @param {string} url - URL to fetch
|
|
20
|
+
* @returns {Promise<object>}
|
|
21
|
+
*/
|
|
22
|
+
export async function fetchJSON(url) {
|
|
23
|
+
const content = await fetchFile(url)
|
|
24
|
+
return JSON.parse(content)
|
|
25
|
+
}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { GITHUB_RAW } from '../constants.js'
|
|
2
2
|
|
|
3
|
-
export function getSourceUrl(type,
|
|
3
|
+
export function getSourceUrl(type, componentName, file, tag) {
|
|
4
4
|
const ref = tag ? `?ref=${tag}` : ''
|
|
5
5
|
const paths = {
|
|
6
|
-
components:
|
|
7
|
-
|
|
6
|
+
components: componentName
|
|
7
|
+
? `/src/components/${componentName}/${file}`
|
|
8
|
+
: `/src/components/${file}`,
|
|
9
|
+
composables: componentName
|
|
10
|
+
? `/src/composables/${componentName}/${file}`
|
|
11
|
+
: `/src/composables/${file}`,
|
|
8
12
|
styles: `/src/styles/${file}`,
|
|
9
13
|
}
|
|
10
14
|
return `${GITHUB_RAW}${paths[type]}${ref}`
|