rxn-ui 0.5.9 → 0.6.1

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,79 +1,72 @@
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
- }
1
+ import fs from 'node:fs'
2
+ import path from 'node:path'
3
+
4
+ import { 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 registryUrl = getRegistryUrl()
18
+
19
+ let registry
20
+ try {
21
+ registry = await fetchJSON(registryUrl)
22
+ } catch (err) {
23
+ log.error(`Failed to fetch registry: ${err.message}`)
24
+ process.exit(1)
25
+ }
26
+
27
+ const entry = registry[componentName]
28
+ if (!entry) {
29
+ log.error(`Component "${componentName}" not found`)
30
+ log.info(`Available components: ${Object.keys(registry).join(', ')}`)
31
+ process.exit(1)
32
+ }
33
+
34
+ // Если файлов больше одного — скачиваем в папку с именем компонента
35
+ const isMultipleFiles = entry.files.length > 1
36
+ const destDir = isMultipleFiles
37
+ ? path.join(cwd, config[entry.type], componentName)
38
+ : path.join(cwd, config[entry.type])
39
+
40
+ log.bold(`\nAdding ${componentName}...`)
41
+
42
+ // Скачиваем файлы компонента
43
+ await downloadItems({
44
+ type: entry.type,
45
+ componentName: isMultipleFiles ? componentName : null,
46
+ files: entry.files,
47
+ destDir,
48
+ })
49
+ }
50
+
51
+ export async function downloadItems({ type, componentName, files, destDir }) {
52
+ log.bold(`\nAdding ${type}...`)
53
+ fs.mkdirSync(destDir, { recursive: true })
54
+
55
+ for (const file of files) {
56
+ const url = getSourceUrl(type, componentName, file)
57
+ const destPath = path.join(destDir, file)
58
+
59
+ if (fs.existsSync(destPath)) {
60
+ log.info(`Skipping ${path.relative(cwd, destPath)} (already exists)`)
61
+ continue
62
+ }
63
+
64
+ try {
65
+ const content = await fetchFile(url)
66
+ fs.writeFileSync(destPath, content)
67
+ log.success(`Added ${path.relative(cwd, destPath)}`)
68
+ } catch (err) {
69
+ log.error(`Failed to download ${file}: ${err.message}`)
70
+ }
71
+ }
72
+ }
package/cli/constants.js CHANGED
@@ -6,6 +6,6 @@ export const GITHUB_RAW = `https://raw.githubusercontent.com/${GITHUB_REPO}/main
6
6
  export const cwd = process.env.INIT_CWD || process.cwd()
7
7
  export const STYLES_FILES = ['style.css', 'variables.css']
8
8
 
9
- export function getRegistryUrl(tag) {
10
- return tag ? `${GITHUB_RAW}/cli/registry.json?ref=${tag}` : `${GITHUB_RAW}/cli/registry.json`
9
+ export function getRegistryUrl() {
10
+ return `${GITHUB_RAW}/cli/registry.json`
11
11
  }
package/cli/init.js CHANGED
@@ -1,20 +1,20 @@
1
1
  import fs from 'node:fs'
2
2
  import path from 'node:path'
3
3
 
4
- import { cwd } from './constants.js'
4
+ import { STYLES_FILES, cwd } from './constants.js'
5
5
  import { detectProject, loadConfig, saveConfig } from './utils/config.js'
6
+ import { downloadItems } from './add.js'
6
7
  import { log } from './utils/logger.js'
7
8
 
8
9
  export async function init(cmdOptions = {}) {
9
10
  const configPath = path.join(cwd, 'rxn-ui.json')
10
11
 
11
- if (fs.existsSync(configPath) && !cmdOptions.overwrite) {
12
+ if (fs.existsSync(configPath)) {
12
13
  const existing = loadConfig()
13
14
  log.info(`
14
15
  Already initialized at ${configPath}
15
16
  Components: ${existing.components}
16
17
  Styles: ${existing.styles}`)
17
- log('\nTo reinitialize, run: npx rxn-ui init --overwrite')
18
18
  return
19
19
  }
20
20
 
@@ -25,18 +25,39 @@ Styles: ${existing.styles}`)
25
25
  }
26
26
  if (cmdOptions.styles) {
27
27
  config.styles = cmdOptions.styles
28
+ } else {
29
+ config.styles = 'styles'
28
30
  }
29
31
  if (cmdOptions.composables) {
30
32
  config.composables = cmdOptions.composables
31
33
  }
32
34
 
35
+ // Check if styles dir exists, use 'rxn-styles' prefix to avoid conflicts
36
+ const stylesPath = path.join(cwd, config.styles)
37
+ if (fs.existsSync(stylesPath)) {
38
+ const base = path.basename(config.styles)
39
+ const dir = path.dirname(config.styles)
40
+ config.styles = path.join(dir, `rxn-${base}`)
41
+ log.info(`Styles directory "${config.styles}" (prefixed to avoid conflict)`)
42
+ }
43
+
33
44
  saveConfig(config)
34
45
  log.success('rxn-ui initialized')
35
46
  log(`\n
36
47
  Configuration saved to ${configPath}
37
48
  Components: ${config.components}
38
49
  Styles: ${config.styles}
39
- Composables: ${config.composables}\n
40
- Now you can add components:
50
+ Composables: ${config.composables}`)
51
+
52
+ // Download styles
53
+ const stylesDir = path.join(cwd, config.styles)
54
+ await downloadItems({
55
+ type: 'styles',
56
+ componentName: null,
57
+ files: STYLES_FILES,
58
+ destDir: stylesDir,
59
+ })
60
+
61
+ log(`\nNow you can add components:
41
62
  npx rxn-ui add button-base`)
42
63
  }
package/cli/list.js CHANGED
@@ -3,12 +3,9 @@ import { fetchJSON } from './utils/fetch.js'
3
3
  import { log } from './utils/logger.js'
4
4
 
5
5
  export async function list(cmdOptions = {}) {
6
- const tag = cmdOptions.tag || null
7
- const registryUrl = getRegistryUrl(tag)
8
-
9
6
  let registry
10
7
  try {
11
- registry = await fetchJSON(registryUrl)
8
+ registry = await fetchJSON(getRegistryUrl())
12
9
  } catch (err) {
13
10
  log.error(`Failed to fetch registry: ${err.message}`)
14
11
  process.exit(1)
package/cli/showHelp.js CHANGED
@@ -14,8 +14,6 @@ ${colors.bold}Commands:${colors.reset}
14
14
  help Show this help message
15
15
 
16
16
  ${colors.bold}Options:${colors.reset}
17
- --tag <version> Use a specific version from GitHub
18
- --overwrite Overwrite existing config (for init)
19
17
  --components <path> Custom components directory
20
18
  --styles <path> Custom styles directory
21
19
  --composables <path> Custom composables directory
@@ -23,7 +21,6 @@ ${colors.bold}Options:${colors.reset}
23
21
  ${colors.bold}Examples:${colors.reset}
24
22
  npx rxn-ui init
25
23
  npx rxn-ui add button-base
26
- npx rxn-ui add card-base --tag v0.4.6
27
24
  npx rxn-ui list
28
25
  `)
29
26
  }
@@ -1,7 +1,7 @@
1
1
  import fs from 'node:fs'
2
2
  import path from 'node:path'
3
3
 
4
- const cwd = process.env.INIT_CWD || process.cwd()
4
+ import { cwd } from '../constants.js'
5
5
 
6
6
  export function loadConfig() {
7
7
  const configPath = path.join(cwd, 'rxn-ui.json')
@@ -20,7 +20,6 @@ export function detectProject() {
20
20
  const hasSrc = fs.existsSync(path.join(cwd, 'src'))
21
21
  return {
22
22
  components: hasSrc ? 'src/shared/components' : 'components',
23
- styles: hasSrc ? 'src/app/styles' : 'styles',
24
23
  composables: hasSrc ? 'src/shared/composables' : 'composables',
25
24
  }
26
25
  }
@@ -1,7 +1,6 @@
1
1
  import { GITHUB_RAW } from '../constants.js'
2
2
 
3
- export function getSourceUrl(type, componentName, file, tag) {
4
- const ref = tag ? `?ref=${tag}` : ''
3
+ export function getSourceUrl(type, componentName, file) {
5
4
  const paths = {
6
5
  components: componentName
7
6
  ? `/src/components/${componentName}/${file}`
@@ -11,5 +10,5 @@ export function getSourceUrl(type, componentName, file, tag) {
11
10
  : `/src/composables/${file}`,
12
11
  styles: `/src/styles/${file}`,
13
12
  }
14
- return `${GITHUB_RAW}${paths[type]}${ref}`
13
+ return `${GITHUB_RAW}${paths[type]}`
15
14
  }
package/package.json CHANGED
@@ -1,15 +1,12 @@
1
1
  {
2
2
  "name": "rxn-ui",
3
3
  "description": "Vue 3 UI component library",
4
- "version": "0.5.9",
4
+ "version": "0.6.1",
5
5
  "license": "MIT",
6
6
  "private": false,
7
7
  "type": "module",
8
8
  "author": "Artur Hareksian <artharexian@gmail.com> (https://github.com/r2-h)",
9
- "repository": {
10
- "type": "git",
11
- "url": "git+https://github.com/r2-h/artharexian-ui.git"
12
- },
9
+ "repository": "r2-h/rxn-ui",
13
10
  "bin": {
14
11
  "rxn-ui": "cli/index.mjs"
15
12
  },