rxn-ui 0.5.6 → 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 CHANGED
@@ -1,73 +1,79 @@
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(name, 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[name]
29
- if (!entry) {
30
- log.error(`Component "${name}" not found`)
31
- log.info(`Available components: ${Object.keys(registry).join(', ')}`)
32
- process.exit(1)
33
- }
34
-
35
- const type = name.startsWith('use-') ? 'composables' : 'components'
36
- const itemsToDownload = [
37
- { type, name, files: entry.files, dir: config[type] },
38
- { type: 'styles', name: null, files: STYLES_FILES, dir: config.styles },
39
- ]
40
-
41
- log.bold(`\nAdding ${name}...`)
42
-
43
- for (const item of itemsToDownload) {
44
- const destDir = path.join(cwd, item.dir)
45
- fs.mkdirSync(destDir, { recursive: true })
46
- await downloadItems({ type: item.type, name: item.name, files: item.files, tag, destDir })
47
- }
48
-
49
- if (entry.imports) {
50
- log.bold(`\nUsage:`)
51
- for (const imp of entry.imports) {
52
- log(` ${imp}`)
53
- }
54
- }
55
- }
56
-
57
- async function downloadItems({ type, name, files, tag, destDir }) {
58
- log.bold(`\nAdding ${type}...`)
59
- for (const file of files) {
60
- const url = getSourceUrl(type, name, file, tag)
61
- const destDirNested = name ? path.join(destDir, name) : destDir
62
- const destPath = path.join(destDirNested, file)
63
-
64
- try {
65
- const content = await fetchFile(url)
66
- fs.mkdirSync(destDirNested, { recursive: true })
67
- fs.writeFileSync(destPath, content)
68
- log.success(`Added ${path.relative(cwd, destPath)}`)
69
- } catch (err) {
70
- log.error(`Failed to download ${file}: ${err.message}`)
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
- "description": "Accessible button primitive",
3
+ "type": "components",
4
4
  "files": ["ButtonBase.vue", "types.ts"],
5
- "dependencies": [],
6
- "imports": ["import { ButtonBase } from '@/components/button-base'"]
5
+ "description": "Accessible button primitive",
6
+ "dependencies": []
7
7
  },
8
8
  "card-base": {
9
- "description": "Card container components",
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
- "dependencies": [],
19
- "imports": [
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
- "description": "Checkbox input primitive",
22
+ "type": "components",
25
23
  "files": ["CheckboxBase.vue"],
26
- "dependencies": [],
27
- "imports": ["import { CheckboxBase } from '@/components/checkbox-base'"]
24
+ "description": "Checkbox input primitive",
25
+ "dependencies": []
28
26
  },
29
27
  "input-base": {
30
- "description": "Text input primitive",
28
+ "type": "components",
31
29
  "files": ["InputBase.vue", "types.ts"],
32
- "dependencies": [],
33
- "imports": ["import { InputBase } from '@/components/input-base'"]
30
+ "description": "Text input primitive",
31
+ "dependencies": []
34
32
  },
35
33
  "range-base": {
36
- "description": "Range slider primitive",
34
+ "type": "components",
37
35
  "files": ["RangeBase.vue", "RangeOutput.vue", "types.ts"],
38
- "dependencies": [],
39
- "imports": ["import { RangeBase, RangeOutput } from '@/components/range-base'"]
36
+ "description": "Range slider primitive",
37
+ "dependencies": []
40
38
  },
41
39
  "switch-base": {
42
- "description": "Toggle switch primitive",
40
+ "type": "components",
43
41
  "files": ["SwitchBase.vue"],
44
- "dependencies": [],
45
- "imports": ["import { SwitchBase } from '@/components/switch-base'"]
42
+ "description": "Toggle switch primitive",
43
+ "dependencies": []
46
44
  },
47
45
  "tabs": {
48
- "description": "Tab navigation components",
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
- "dependencies": [],
59
- "imports": [
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
- "description": "Composable theme switcher",
60
+ "type": "composables",
65
61
  "files": ["useTheme.ts"],
66
- "dependencies": [],
67
- "imports": ["import { useTheme } from '@/composables/useTheme'"]
62
+ "description": "Composable theme switcher",
63
+ "dependencies": []
68
64
  }
69
65
  }
@@ -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, name, file, tag) {
3
+ export function getSourceUrl(type, componentName, file, tag) {
4
4
  const ref = tag ? `?ref=${tag}` : ''
5
5
  const paths = {
6
- components: `/src/components/${name}/${file}`,
7
- composables: `/src/composables/${file}`,
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}`
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "rxn-ui",
3
3
  "description": "Vue 3 UI component library",
4
- "version": "0.5.6",
4
+ "version": "0.5.7",
5
5
  "license": "MIT",
6
6
  "private": false,
7
7
  "type": "module",