rxn-ui 0.6.1 → 0.6.2
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 +61 -1
- package/cli/constants.js +11 -11
- package/cli/init.js +31 -9
- package/cli/registry.json +10 -3
- package/cli/utils/config.js +2 -0
- package/cli/utils/getSourceUrl.js +2 -1
- package/package.json +4 -2
package/cli/add.js
CHANGED
|
@@ -7,6 +7,13 @@ import { fetchFile, fetchJSON } from './utils/fetch.js'
|
|
|
7
7
|
import { getSourceUrl } from './utils/getSourceUrl.js'
|
|
8
8
|
import { log } from './utils/logger.js'
|
|
9
9
|
|
|
10
|
+
// Patterns to detect and rewrite import paths
|
|
11
|
+
const IMPORT_PATTERNS = [
|
|
12
|
+
{ type: 'assets', regex: /\.\.\/\.\.\/assets\//g },
|
|
13
|
+
{ type: 'composables', regex: /\.\.\/\.\.\/composables\//g },
|
|
14
|
+
{ type: 'utils', regex: /\.\.\/\.\.\/utils\//g },
|
|
15
|
+
]
|
|
16
|
+
|
|
10
17
|
export async function add(componentName, cmdOptions = {}) {
|
|
11
18
|
const config = loadConfig()
|
|
12
19
|
if (!config) {
|
|
@@ -39,13 +46,66 @@ export async function add(componentName, cmdOptions = {}) {
|
|
|
39
46
|
|
|
40
47
|
log.bold(`\nAdding ${componentName}...`)
|
|
41
48
|
|
|
49
|
+
// Скачиваем зависимости (assets, composables, utils)
|
|
50
|
+
const depDirs = await downloadDependencies(entry, config)
|
|
51
|
+
|
|
42
52
|
// Скачиваем файлы компонента
|
|
43
53
|
await downloadItems({
|
|
44
54
|
type: entry.type,
|
|
45
|
-
componentName
|
|
55
|
+
componentName,
|
|
46
56
|
files: entry.files,
|
|
47
57
|
destDir,
|
|
48
58
|
})
|
|
59
|
+
|
|
60
|
+
// Переписываем импорты в файлах компонента
|
|
61
|
+
rewriteImports(entry.files, destDir, depDirs, isMultipleFiles)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async function downloadDependencies(entry, config) {
|
|
65
|
+
const deps = entry.dependencies
|
|
66
|
+
if (!deps) return {}
|
|
67
|
+
|
|
68
|
+
const depDirs = {}
|
|
69
|
+
|
|
70
|
+
for (const [type, files] of Object.entries(deps)) {
|
|
71
|
+
const destDir = path.join(cwd, config[type])
|
|
72
|
+
depDirs[type] = destDir
|
|
73
|
+
|
|
74
|
+
await downloadItems({
|
|
75
|
+
type,
|
|
76
|
+
componentName: null,
|
|
77
|
+
files,
|
|
78
|
+
destDir,
|
|
79
|
+
})
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return depDirs
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function rewriteImports(files, destDir, depDirs, isMultipleFiles) {
|
|
86
|
+
for (const file of files) {
|
|
87
|
+
const filePath = path.join(destDir, file)
|
|
88
|
+
if (!fs.existsSync(filePath)) continue
|
|
89
|
+
|
|
90
|
+
let content = fs.readFileSync(filePath, 'utf8')
|
|
91
|
+
|
|
92
|
+
for (const { type, regex } of IMPORT_PATTERNS) {
|
|
93
|
+
if (!depDirs[type]) continue
|
|
94
|
+
if (!regex.test(content)) continue
|
|
95
|
+
|
|
96
|
+
// Reset regex lastIndex
|
|
97
|
+
regex.lastIndex = 0
|
|
98
|
+
|
|
99
|
+
// Calculate relative path from component file to dependency dir
|
|
100
|
+
const fileDir = isMultipleFiles ? destDir : path.dirname(filePath)
|
|
101
|
+
const relPath = path.relative(fileDir, depDirs[type]).replace(/\\/g, '/')
|
|
102
|
+
const importPath = relPath.startsWith('.') ? relPath : `./${relPath}`
|
|
103
|
+
|
|
104
|
+
content = content.replace(regex, `${importPath}/`)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
fs.writeFileSync(filePath, content)
|
|
108
|
+
}
|
|
49
109
|
}
|
|
50
110
|
|
|
51
111
|
export async function downloadItems({ type, componentName, files, destDir }) {
|
package/cli/constants.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import process from 'node:process'
|
|
2
|
-
|
|
3
|
-
export const GITHUB_REPO = 'r2-h/
|
|
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() {
|
|
10
|
-
return `${GITHUB_RAW}/cli/registry.json`
|
|
11
|
-
}
|
|
1
|
+
import process from 'node:process'
|
|
2
|
+
|
|
3
|
+
export const GITHUB_REPO = 'r2-h/rxn-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() {
|
|
10
|
+
return `${GITHUB_RAW}/cli/registry.json`
|
|
11
|
+
}
|
package/cli/init.js
CHANGED
|
@@ -1,11 +1,35 @@
|
|
|
1
1
|
import fs from 'node:fs'
|
|
2
2
|
import path from 'node:path'
|
|
3
3
|
|
|
4
|
-
import { STYLES_FILES, cwd } from './constants.js'
|
|
4
|
+
import { STYLES_FILES, GITHUB_RAW, cwd } from './constants.js'
|
|
5
5
|
import { detectProject, loadConfig, saveConfig } from './utils/config.js'
|
|
6
6
|
import { downloadItems } from './add.js'
|
|
7
|
+
import { fetchFile } from './utils/fetch.js'
|
|
7
8
|
import { log } from './utils/logger.js'
|
|
8
9
|
|
|
10
|
+
async function downloadStyles(stylesDir) {
|
|
11
|
+
log.bold('\nAdding styles...')
|
|
12
|
+
fs.mkdirSync(stylesDir, { recursive: true })
|
|
13
|
+
|
|
14
|
+
for (const file of STYLES_FILES) {
|
|
15
|
+
const url = `${GITHUB_RAW}/src/styles/${file}`
|
|
16
|
+
const destPath = path.join(stylesDir, file)
|
|
17
|
+
|
|
18
|
+
if (fs.existsSync(destPath)) {
|
|
19
|
+
log.info(`Skipping ${path.relative(cwd, destPath)} (already exists)`)
|
|
20
|
+
continue
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
try {
|
|
24
|
+
const content = await fetchFile(url)
|
|
25
|
+
fs.writeFileSync(destPath, content)
|
|
26
|
+
log.success(`Added ${path.relative(cwd, destPath)}`)
|
|
27
|
+
} catch (err) {
|
|
28
|
+
log.error(`Failed to download ${file}: ${err.message}`)
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
9
33
|
export async function init(cmdOptions = {}) {
|
|
10
34
|
const configPath = path.join(cwd, 'rxn-ui.json')
|
|
11
35
|
|
|
@@ -14,7 +38,8 @@ export async function init(cmdOptions = {}) {
|
|
|
14
38
|
log.info(`
|
|
15
39
|
Already initialized at ${configPath}
|
|
16
40
|
Components: ${existing.components}
|
|
17
|
-
Styles: ${existing.styles}
|
|
41
|
+
Styles: ${existing.styles}
|
|
42
|
+
Assets: ${existing.assets}`)
|
|
18
43
|
return
|
|
19
44
|
}
|
|
20
45
|
|
|
@@ -47,16 +72,13 @@ Styles: ${existing.styles}`)
|
|
|
47
72
|
Configuration saved to ${configPath}
|
|
48
73
|
Components: ${config.components}
|
|
49
74
|
Styles: ${config.styles}
|
|
50
|
-
Composables: ${config.composables}
|
|
75
|
+
Composables: ${config.composables}
|
|
76
|
+
Assets: ${config.assets}
|
|
77
|
+
Utils: ${config.utils}`)
|
|
51
78
|
|
|
52
79
|
// Download styles
|
|
53
80
|
const stylesDir = path.join(cwd, config.styles)
|
|
54
|
-
await
|
|
55
|
-
type: 'styles',
|
|
56
|
-
componentName: null,
|
|
57
|
-
files: STYLES_FILES,
|
|
58
|
-
destDir: stylesDir,
|
|
59
|
-
})
|
|
81
|
+
await downloadStyles(stylesDir)
|
|
60
82
|
|
|
61
83
|
log(`\nNow you can add components:
|
|
62
84
|
npx rxn-ui add button-base`)
|
package/cli/registry.json
CHANGED
|
@@ -16,7 +16,10 @@
|
|
|
16
16
|
},
|
|
17
17
|
"checkbox-base": {
|
|
18
18
|
"type": "components",
|
|
19
|
-
"files": ["CheckboxBase.vue"]
|
|
19
|
+
"files": ["CheckboxBase.vue"],
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"assets": ["CheckIcon.vue"]
|
|
22
|
+
}
|
|
20
23
|
},
|
|
21
24
|
"input-base": {
|
|
22
25
|
"type": "components",
|
|
@@ -24,7 +27,11 @@
|
|
|
24
27
|
},
|
|
25
28
|
"range-base": {
|
|
26
29
|
"type": "components",
|
|
27
|
-
"files": ["RangeBase.vue", "RangeOutput.vue", "types.ts"]
|
|
30
|
+
"files": ["RangeBase.vue", "RangeOutput.vue", "types.ts"],
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"composables": ["useVars.ts"],
|
|
33
|
+
"utils": ["cssParser.ts", "mergeDefaultProps.ts"]
|
|
34
|
+
}
|
|
28
35
|
},
|
|
29
36
|
"switch-base": {
|
|
30
37
|
"type": "components",
|
|
@@ -44,7 +51,7 @@
|
|
|
44
51
|
},
|
|
45
52
|
"popover-base": {
|
|
46
53
|
"type": "components",
|
|
47
|
-
"files": ["context.ts", "
|
|
54
|
+
"files": ["context.ts", "PopoverMenu.vue", "PopoverTrigger.vue", "types.ts"]
|
|
48
55
|
},
|
|
49
56
|
"use-theme": {
|
|
50
57
|
"type": "composables",
|
package/cli/utils/config.js
CHANGED
|
@@ -21,5 +21,7 @@ export function detectProject() {
|
|
|
21
21
|
return {
|
|
22
22
|
components: hasSrc ? 'src/shared/components' : 'components',
|
|
23
23
|
composables: hasSrc ? 'src/shared/composables' : 'composables',
|
|
24
|
+
assets: hasSrc ? 'src/assets' : 'assets',
|
|
25
|
+
utils: hasSrc ? 'src/shared/utils' : 'utils',
|
|
24
26
|
}
|
|
25
27
|
}
|
|
@@ -8,7 +8,8 @@ export function getSourceUrl(type, componentName, file) {
|
|
|
8
8
|
composables: componentName
|
|
9
9
|
? `/src/composables/${componentName}/${file}`
|
|
10
10
|
: `/src/composables/${file}`,
|
|
11
|
-
|
|
11
|
+
assets: `/src/assets/${file}`,
|
|
12
|
+
utils: `/src/utils/${file}`,
|
|
12
13
|
}
|
|
13
14
|
return `${GITHUB_RAW}${paths[type]}`
|
|
14
15
|
}
|
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.6.
|
|
4
|
+
"version": "0.6.2",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"private": false,
|
|
7
7
|
"type": "module",
|
|
@@ -26,7 +26,8 @@
|
|
|
26
26
|
"build-storybook": "storybook build"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
|
-
"vue": "^3.5.0"
|
|
29
|
+
"vue": "^3.5.0",
|
|
30
|
+
"vue-router": "^4.0.0"
|
|
30
31
|
},
|
|
31
32
|
"devDependencies": {
|
|
32
33
|
"@chromatic-com/storybook": "^5.0.1",
|
|
@@ -49,6 +50,7 @@
|
|
|
49
50
|
"vite": "^7.3.1",
|
|
50
51
|
"vitest": "^4.0.18",
|
|
51
52
|
"vue": "^3.5.25",
|
|
53
|
+
"vue-router": "^4.6.4",
|
|
52
54
|
"vue-tsc": "^3.1.5"
|
|
53
55
|
},
|
|
54
56
|
"eslintConfig": {
|