rxn-ui 0.6.2 → 0.6.4
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 +48 -2
- package/cli/init.js +19 -18
- package/cli/registry.json +15 -0
- package/cli/showHelp.js +2 -1
- package/cli/utils/config.js +1 -1
- package/package.json +3 -2
package/cli/add.js
CHANGED
|
@@ -10,8 +10,10 @@ import { log } from './utils/logger.js'
|
|
|
10
10
|
// Patterns to detect and rewrite import paths
|
|
11
11
|
const IMPORT_PATTERNS = [
|
|
12
12
|
{ type: 'assets', regex: /\.\.\/\.\.\/assets\//g },
|
|
13
|
+
{ type: 'assets', regex: /@\/assets\//g },
|
|
13
14
|
{ type: 'composables', regex: /\.\.\/\.\.\/composables\//g },
|
|
14
15
|
{ type: 'utils', regex: /\.\.\/\.\.\/utils\//g },
|
|
16
|
+
{ type: 'components', regex: /\.\.\/([\w-]+)\//g },
|
|
15
17
|
]
|
|
16
18
|
|
|
17
19
|
export async function add(componentName, cmdOptions = {}) {
|
|
@@ -49,6 +51,18 @@ export async function add(componentName, cmdOptions = {}) {
|
|
|
49
51
|
// Скачиваем зависимости (assets, composables, utils)
|
|
50
52
|
const depDirs = await downloadDependencies(entry, config)
|
|
51
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
|
+
|
|
52
66
|
// Скачиваем файлы компонента
|
|
53
67
|
await downloadItems({
|
|
54
68
|
type: entry.type,
|
|
@@ -61,6 +75,29 @@ export async function add(componentName, cmdOptions = {}) {
|
|
|
61
75
|
rewriteImports(entry.files, destDir, depDirs, isMultipleFiles)
|
|
62
76
|
}
|
|
63
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
|
+
|
|
64
101
|
async function downloadDependencies(entry, config) {
|
|
65
102
|
const deps = entry.dependencies
|
|
66
103
|
if (!deps) return {}
|
|
@@ -91,17 +128,26 @@ function rewriteImports(files, destDir, depDirs, isMultipleFiles) {
|
|
|
91
128
|
|
|
92
129
|
for (const { type, regex } of IMPORT_PATTERNS) {
|
|
93
130
|
if (!depDirs[type]) continue
|
|
94
|
-
if (!regex.test(content)) continue
|
|
95
131
|
|
|
96
132
|
// Reset regex lastIndex
|
|
97
133
|
regex.lastIndex = 0
|
|
98
134
|
|
|
135
|
+
if (!regex.test(content)) continue
|
|
136
|
+
regex.lastIndex = 0
|
|
137
|
+
|
|
99
138
|
// Calculate relative path from component file to dependency dir
|
|
100
139
|
const fileDir = isMultipleFiles ? destDir : path.dirname(filePath)
|
|
101
140
|
const relPath = path.relative(fileDir, depDirs[type]).replace(/\\/g, '/')
|
|
102
141
|
const importPath = relPath.startsWith('.') ? relPath : `./${relPath}`
|
|
103
142
|
|
|
104
|
-
|
|
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
|
+
}
|
|
105
151
|
}
|
|
106
152
|
|
|
107
153
|
fs.writeFileSync(filePath, content)
|
package/cli/init.js
CHANGED
|
@@ -3,7 +3,6 @@ import path from 'node:path'
|
|
|
3
3
|
|
|
4
4
|
import { STYLES_FILES, GITHUB_RAW, cwd } from './constants.js'
|
|
5
5
|
import { detectProject, loadConfig, saveConfig } from './utils/config.js'
|
|
6
|
-
import { downloadItems } from './add.js'
|
|
7
6
|
import { fetchFile } from './utils/fetch.js'
|
|
8
7
|
import { log } from './utils/logger.js'
|
|
9
8
|
|
|
@@ -30,6 +29,18 @@ async function downloadStyles(stylesDir) {
|
|
|
30
29
|
}
|
|
31
30
|
}
|
|
32
31
|
|
|
32
|
+
function getDefaultStylesDir() {
|
|
33
|
+
const hasSrc = fs.existsSync(path.join(cwd, 'src'))
|
|
34
|
+
const base = hasSrc ? 'src/app/styles' : 'styles'
|
|
35
|
+
const stylesPath = path.join(cwd, base)
|
|
36
|
+
|
|
37
|
+
if (fs.existsSync(stylesPath)) {
|
|
38
|
+
const dir = path.dirname(base)
|
|
39
|
+
return path.join(dir, 'rxn-styles')
|
|
40
|
+
}
|
|
41
|
+
return base
|
|
42
|
+
}
|
|
43
|
+
|
|
33
44
|
export async function init(cmdOptions = {}) {
|
|
34
45
|
const configPath = path.join(cwd, 'rxn-ui.json')
|
|
35
46
|
|
|
@@ -38,7 +49,6 @@ export async function init(cmdOptions = {}) {
|
|
|
38
49
|
log.info(`
|
|
39
50
|
Already initialized at ${configPath}
|
|
40
51
|
Components: ${existing.components}
|
|
41
|
-
Styles: ${existing.styles}
|
|
42
52
|
Assets: ${existing.assets}`)
|
|
43
53
|
return
|
|
44
54
|
}
|
|
@@ -48,22 +58,14 @@ Assets: ${existing.assets}`)
|
|
|
48
58
|
if (cmdOptions.components) {
|
|
49
59
|
config.components = cmdOptions.components
|
|
50
60
|
}
|
|
51
|
-
if (cmdOptions.styles) {
|
|
52
|
-
config.styles = cmdOptions.styles
|
|
53
|
-
} else {
|
|
54
|
-
config.styles = 'styles'
|
|
55
|
-
}
|
|
56
61
|
if (cmdOptions.composables) {
|
|
57
62
|
config.composables = cmdOptions.composables
|
|
58
63
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
if (
|
|
63
|
-
|
|
64
|
-
const dir = path.dirname(config.styles)
|
|
65
|
-
config.styles = path.join(dir, `rxn-${base}`)
|
|
66
|
-
log.info(`Styles directory "${config.styles}" (prefixed to avoid conflict)`)
|
|
64
|
+
if (cmdOptions.assets) {
|
|
65
|
+
config.assets = cmdOptions.assets
|
|
66
|
+
}
|
|
67
|
+
if (cmdOptions.utils) {
|
|
68
|
+
config.utils = cmdOptions.utils
|
|
67
69
|
}
|
|
68
70
|
|
|
69
71
|
saveConfig(config)
|
|
@@ -71,13 +73,12 @@ Assets: ${existing.assets}`)
|
|
|
71
73
|
log(`\n
|
|
72
74
|
Configuration saved to ${configPath}
|
|
73
75
|
Components: ${config.components}
|
|
74
|
-
Styles: ${config.styles}
|
|
75
76
|
Composables: ${config.composables}
|
|
76
77
|
Assets: ${config.assets}
|
|
77
78
|
Utils: ${config.utils}`)
|
|
78
79
|
|
|
79
|
-
// Download styles
|
|
80
|
-
const stylesDir = path.join(cwd,
|
|
80
|
+
// Download styles to default location
|
|
81
|
+
const stylesDir = path.join(cwd, getDefaultStylesDir())
|
|
81
82
|
await downloadStyles(stylesDir)
|
|
82
83
|
|
|
83
84
|
log(`\nNow you can add components:
|
package/cli/registry.json
CHANGED
|
@@ -33,6 +33,21 @@
|
|
|
33
33
|
"utils": ["cssParser.ts", "mergeDefaultProps.ts"]
|
|
34
34
|
}
|
|
35
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"]
|
|
50
|
+
},
|
|
36
51
|
"switch-base": {
|
|
37
52
|
"type": "components",
|
|
38
53
|
"files": ["SwitchBase.vue"]
|
package/cli/showHelp.js
CHANGED
|
@@ -15,8 +15,9 @@ ${colors.bold}Commands:${colors.reset}
|
|
|
15
15
|
|
|
16
16
|
${colors.bold}Options:${colors.reset}
|
|
17
17
|
--components <path> Custom components directory
|
|
18
|
-
--styles <path> Custom styles directory
|
|
19
18
|
--composables <path> Custom composables directory
|
|
19
|
+
--assets <path> Custom assets directory
|
|
20
|
+
--utils <path> Custom utils directory
|
|
20
21
|
|
|
21
22
|
${colors.bold}Examples:${colors.reset}
|
|
22
23
|
npx rxn-ui init
|
package/cli/utils/config.js
CHANGED
|
@@ -21,7 +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',
|
|
24
|
+
assets: hasSrc ? 'src/shared/assets' : 'assets',
|
|
25
25
|
utils: hasSrc ? 'src/shared/utils' : 'utils',
|
|
26
26
|
}
|
|
27
27
|
}
|
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.4",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"private": false,
|
|
7
7
|
"type": "module",
|
|
@@ -23,7 +23,8 @@
|
|
|
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
30
|
"vue": "^3.5.0",
|