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 +72 -79
- package/cli/constants.js +2 -2
- package/cli/init.js +26 -5
- package/cli/list.js +1 -4
- package/cli/showHelp.js +0 -3
- package/cli/utils/config.js +1 -2
- package/cli/utils/getSourceUrl.js +2 -3
- package/package.json +2 -5
package/cli/add.js
CHANGED
|
@@ -1,79 +1,72 @@
|
|
|
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(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
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
log.
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
componentName
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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(
|
|
10
|
-
return
|
|
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)
|
|
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}
|
|
40
|
-
|
|
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(
|
|
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
|
}
|
package/cli/utils/config.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import fs from 'node:fs'
|
|
2
2
|
import path from 'node:path'
|
|
3
3
|
|
|
4
|
-
|
|
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
|
|
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]}
|
|
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.
|
|
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
|
},
|