rxn-ui 0.6.1 → 0.6.3
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 +107 -1
- package/cli/constants.js +11 -11
- package/cli/init.js +31 -9
- package/cli/registry.json +25 -3
- package/cli/utils/config.js +2 -0
- package/cli/utils/getSourceUrl.js +2 -1
- package/package.json +6 -3
package/cli/add.js
CHANGED
|
@@ -7,6 +7,15 @@ 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: 'assets', regex: /@\/assets\//g },
|
|
14
|
+
{ type: 'composables', regex: /\.\.\/\.\.\/composables\//g },
|
|
15
|
+
{ type: 'utils', regex: /\.\.\/\.\.\/utils\//g },
|
|
16
|
+
{ type: 'components', regex: /\.\.\/([\w-]+)\//g },
|
|
17
|
+
]
|
|
18
|
+
|
|
10
19
|
export async function add(componentName, cmdOptions = {}) {
|
|
11
20
|
const config = loadConfig()
|
|
12
21
|
if (!config) {
|
|
@@ -39,13 +48,110 @@ export async function add(componentName, cmdOptions = {}) {
|
|
|
39
48
|
|
|
40
49
|
log.bold(`\nAdding ${componentName}...`)
|
|
41
50
|
|
|
51
|
+
// Скачиваем зависимости (assets, composables, utils)
|
|
52
|
+
const depDirs = await downloadDependencies(entry, config)
|
|
53
|
+
|
|
54
|
+
// Скачиваем компонентные зависимости
|
|
55
|
+
if (entry.components) {
|
|
56
|
+
for (const compName of entry.components) {
|
|
57
|
+
const compEntry = registry[compName]
|
|
58
|
+
if (!compEntry) {
|
|
59
|
+
log.error(`Dependency "${compName}" not found`)
|
|
60
|
+
continue
|
|
61
|
+
}
|
|
62
|
+
await addDependency(compName, compEntry, config)
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
42
66
|
// Скачиваем файлы компонента
|
|
43
67
|
await downloadItems({
|
|
44
68
|
type: entry.type,
|
|
45
|
-
componentName
|
|
69
|
+
componentName,
|
|
46
70
|
files: entry.files,
|
|
47
71
|
destDir,
|
|
48
72
|
})
|
|
73
|
+
|
|
74
|
+
// Переписываем импорты в файлах компонента
|
|
75
|
+
rewriteImports(entry.files, destDir, depDirs, isMultipleFiles)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async function addDependency(compName, compEntry, config) {
|
|
79
|
+
const isMultipleFiles = compEntry.files.length > 1
|
|
80
|
+
const destDir = isMultipleFiles
|
|
81
|
+
? path.join(cwd, config[compEntry.type], compName)
|
|
82
|
+
: path.join(cwd, config[compEntry.type])
|
|
83
|
+
|
|
84
|
+
log.bold(`\nAdding dependency ${compName}...`)
|
|
85
|
+
|
|
86
|
+
// Скачиваем зависимости компонента
|
|
87
|
+
const depDirs = await downloadDependencies(compEntry, config)
|
|
88
|
+
|
|
89
|
+
// Скачиваем файлы
|
|
90
|
+
await downloadItems({
|
|
91
|
+
type: compEntry.type,
|
|
92
|
+
componentName: compName,
|
|
93
|
+
files: compEntry.files,
|
|
94
|
+
destDir,
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
// Переписываем импорты
|
|
98
|
+
rewriteImports(compEntry.files, destDir, depDirs, isMultipleFiles)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
async function downloadDependencies(entry, config) {
|
|
102
|
+
const deps = entry.dependencies
|
|
103
|
+
if (!deps) return {}
|
|
104
|
+
|
|
105
|
+
const depDirs = {}
|
|
106
|
+
|
|
107
|
+
for (const [type, files] of Object.entries(deps)) {
|
|
108
|
+
const destDir = path.join(cwd, config[type])
|
|
109
|
+
depDirs[type] = destDir
|
|
110
|
+
|
|
111
|
+
await downloadItems({
|
|
112
|
+
type,
|
|
113
|
+
componentName: null,
|
|
114
|
+
files,
|
|
115
|
+
destDir,
|
|
116
|
+
})
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return depDirs
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function rewriteImports(files, destDir, depDirs, isMultipleFiles) {
|
|
123
|
+
for (const file of files) {
|
|
124
|
+
const filePath = path.join(destDir, file)
|
|
125
|
+
if (!fs.existsSync(filePath)) continue
|
|
126
|
+
|
|
127
|
+
let content = fs.readFileSync(filePath, 'utf8')
|
|
128
|
+
|
|
129
|
+
for (const { type, regex } of IMPORT_PATTERNS) {
|
|
130
|
+
if (!depDirs[type]) continue
|
|
131
|
+
|
|
132
|
+
// Reset regex lastIndex
|
|
133
|
+
regex.lastIndex = 0
|
|
134
|
+
|
|
135
|
+
if (!regex.test(content)) continue
|
|
136
|
+
regex.lastIndex = 0
|
|
137
|
+
|
|
138
|
+
// Calculate relative path from component file to dependency dir
|
|
139
|
+
const fileDir = isMultipleFiles ? destDir : path.dirname(filePath)
|
|
140
|
+
const relPath = path.relative(fileDir, depDirs[type]).replace(/\\/g, '/')
|
|
141
|
+
const importPath = relPath.startsWith('.') ? relPath : `./${relPath}`
|
|
142
|
+
|
|
143
|
+
if (type === 'components') {
|
|
144
|
+
// For component imports like ../button-base/ -> ./button-base/
|
|
145
|
+
content = content.replace(regex, (match, compName) => {
|
|
146
|
+
return `${importPath}/${compName}/`
|
|
147
|
+
})
|
|
148
|
+
} else {
|
|
149
|
+
content = content.replace(regex, `${importPath}/`)
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
fs.writeFileSync(filePath, content)
|
|
154
|
+
}
|
|
49
155
|
}
|
|
50
156
|
|
|
51
157
|
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,26 @@
|
|
|
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
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"sidebar-base": {
|
|
37
|
+
"type": "components",
|
|
38
|
+
"files": [
|
|
39
|
+
"SidebarBase.vue",
|
|
40
|
+
"SidebarButton.vue",
|
|
41
|
+
"sidebar-context.ts",
|
|
42
|
+
"use-resize.ts",
|
|
43
|
+
"types.ts"
|
|
44
|
+
],
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"assets": ["ChevronDoubleIcon.vue"],
|
|
47
|
+
"composables": ["useRefWithLocalStorage.ts"]
|
|
48
|
+
},
|
|
49
|
+
"components": ["button-base"]
|
|
28
50
|
},
|
|
29
51
|
"switch-base": {
|
|
30
52
|
"type": "components",
|
|
@@ -44,7 +66,7 @@
|
|
|
44
66
|
},
|
|
45
67
|
"popover-base": {
|
|
46
68
|
"type": "components",
|
|
47
|
-
"files": ["context.ts", "
|
|
69
|
+
"files": ["context.ts", "PopoverMenu.vue", "PopoverTrigger.vue", "types.ts"]
|
|
48
70
|
},
|
|
49
71
|
"use-theme": {
|
|
50
72
|
"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.3",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"private": false,
|
|
7
7
|
"type": "module",
|
|
@@ -23,10 +23,12 @@
|
|
|
23
23
|
"dev": "vite",
|
|
24
24
|
"format": "prettier --write .",
|
|
25
25
|
"storybook": "storybook dev -p 6006",
|
|
26
|
-
"build-storybook": "storybook build"
|
|
26
|
+
"build-storybook": "storybook build",
|
|
27
|
+
"build": "vite build"
|
|
27
28
|
},
|
|
28
29
|
"peerDependencies": {
|
|
29
|
-
"vue": "^3.5.0"
|
|
30
|
+
"vue": "^3.5.0",
|
|
31
|
+
"vue-router": "^4.0.0"
|
|
30
32
|
},
|
|
31
33
|
"devDependencies": {
|
|
32
34
|
"@chromatic-com/storybook": "^5.0.1",
|
|
@@ -49,6 +51,7 @@
|
|
|
49
51
|
"vite": "^7.3.1",
|
|
50
52
|
"vitest": "^4.0.18",
|
|
51
53
|
"vue": "^3.5.25",
|
|
54
|
+
"vue-router": "^4.6.4",
|
|
52
55
|
"vue-tsc": "^3.1.5"
|
|
53
56
|
},
|
|
54
57
|
"eslintConfig": {
|