neonblade 0.0.2 → 0.0.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/index.js +70 -125
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -3,116 +3,81 @@
|
|
|
3
3
|
const fs = require("fs")
|
|
4
4
|
const path = require("path")
|
|
5
5
|
const axios = require("axios")
|
|
6
|
+
const { execSync } = require("child_process")
|
|
6
7
|
|
|
7
8
|
const BASE_URL = "https://neonbladeui-registry.vercel.app"
|
|
8
9
|
|
|
10
|
+
async function main() {
|
|
11
|
+
const projectRoot = process.cwd()
|
|
12
|
+
const targetAppPath = findAppPath(projectRoot)
|
|
9
13
|
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
const args = process.argv.slice(2)
|
|
14
|
-
|
|
15
|
-
const command = args[0]
|
|
16
|
-
const component = args[1]
|
|
17
|
-
|
|
18
|
-
if (command !== "add") {
|
|
19
|
-
console.log("Usage: neonblade add <component>")
|
|
20
|
-
process.exit(1)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
if (!component) {
|
|
24
|
-
console.log("Please provide a component name")
|
|
25
|
-
process.exit(1)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const componentDir = path.join(
|
|
29
|
-
__dirname,
|
|
30
|
-
"../registry/components",
|
|
31
|
-
component
|
|
32
|
-
)
|
|
33
|
-
|
|
34
|
-
//log if component is not found
|
|
35
|
-
if (!fs.existsSync(componentDir)) {
|
|
36
|
-
logError(`${component} not found`)
|
|
37
|
-
process.exit(1)
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// Read metadata
|
|
41
|
-
// const metaPath = path.join(componentDir, "meta.json")
|
|
42
|
-
|
|
43
|
-
// if (!fs.existsSync(metaPath)) {
|
|
44
|
-
// console.log("Component metadata not found")
|
|
45
|
-
// process.exit(1)
|
|
46
|
-
// }
|
|
47
|
-
|
|
48
|
-
// const meta = JSON.parse(fs.readFileSync(metaPath, "utf-8"))
|
|
14
|
+
const args = process.argv.slice(2)
|
|
15
|
+
const command = args[0]
|
|
16
|
+
const component = args[1]
|
|
49
17
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
// Copy files
|
|
55
|
-
logStep(`Adding ${component}...`)
|
|
56
|
-
logStep("Copying files...")
|
|
18
|
+
if (command !== "add") {
|
|
19
|
+
console.log("Usage: neonblade add <component>")
|
|
20
|
+
process.exit(1)
|
|
21
|
+
}
|
|
57
22
|
|
|
58
|
-
|
|
59
|
-
|
|
23
|
+
if (!component) {
|
|
24
|
+
console.log("Please provide a component name")
|
|
25
|
+
process.exit(1)
|
|
26
|
+
}
|
|
60
27
|
|
|
61
|
-
|
|
62
|
-
// targetAppPath,
|
|
63
|
-
// "components/ui",
|
|
64
|
-
// toKebabCase(file)
|
|
65
|
-
// )
|
|
28
|
+
console.log("\n⚡ NeonBlade UI\n")
|
|
66
29
|
|
|
67
|
-
|
|
68
|
-
// fs.copyFileSync(sourcePath, targetPath)
|
|
69
|
-
// })
|
|
30
|
+
logStep(`Adding ${component}...`)
|
|
70
31
|
|
|
71
|
-
|
|
72
|
-
const fileRes = await axios.get(file.url)
|
|
32
|
+
const data = await fetchComponent(component)
|
|
73
33
|
|
|
74
|
-
|
|
75
|
-
targetAppPath,
|
|
76
|
-
file.path
|
|
77
|
-
)
|
|
34
|
+
logStep("Copying files...")
|
|
78
35
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
36
|
+
for (const file of data.files) {
|
|
37
|
+
const fileRes = await axios.get(file.url)
|
|
82
38
|
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
// logStep("Installing dependencies...")
|
|
39
|
+
const targetPath = path.join(
|
|
40
|
+
targetAppPath,
|
|
41
|
+
file.path
|
|
42
|
+
)
|
|
88
43
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
44
|
+
fs.mkdirSync(path.dirname(targetPath), { recursive: true })
|
|
45
|
+
fs.writeFileSync(targetPath, fileRes.data)
|
|
46
|
+
}
|
|
47
|
+
const packageManager = detectPackageManager(targetAppPath)
|
|
48
|
+
|
|
49
|
+
if (data.dependencies && data.dependencies.length > 0) {
|
|
50
|
+
logStep(`Installing dependencies using ${packageManager}...`)
|
|
51
|
+
let installCmd = ""
|
|
52
|
+
|
|
53
|
+
if (packageManager === "pnpm") {
|
|
54
|
+
installCmd = `pnpm add ${data.dependencies.join(" ")}`
|
|
55
|
+
} else if (packageManager === "yarn") {
|
|
56
|
+
installCmd = `yarn add ${data.dependencies.join(" ")}`
|
|
57
|
+
} else if (packageManager === "npm") {
|
|
58
|
+
installCmd = `npm install ${data.dependencies.join(" ")}`
|
|
59
|
+
}
|
|
94
60
|
|
|
95
|
-
|
|
96
|
-
|
|
61
|
+
execSync(
|
|
62
|
+
installCmd,
|
|
63
|
+
{
|
|
64
|
+
stdio: "inherit",
|
|
65
|
+
cwd: targetAppPath,
|
|
66
|
+
}
|
|
67
|
+
)
|
|
68
|
+
}
|
|
97
69
|
|
|
98
|
-
|
|
99
|
-
`pnpm add ${data.dependencies.join(" ")}`,
|
|
100
|
-
{
|
|
101
|
-
stdio: "inherit",
|
|
102
|
-
cwd: targetAppPath,
|
|
103
|
-
}
|
|
104
|
-
)
|
|
70
|
+
logSuccess(`${component} added successfully`)
|
|
105
71
|
}
|
|
106
72
|
|
|
107
|
-
|
|
73
|
+
main()
|
|
108
74
|
|
|
75
|
+
// ---------------- HELPERS ----------------
|
|
109
76
|
|
|
110
77
|
function findAppPath(root) {
|
|
111
78
|
const appsDir = path.join(root, "apps")
|
|
112
79
|
|
|
113
|
-
if (!fs.existsSync(appsDir))
|
|
114
|
-
return root
|
|
115
|
-
}
|
|
80
|
+
if (!fs.existsSync(appsDir)) return root
|
|
116
81
|
|
|
117
82
|
const apps = fs.readdirSync(appsDir)
|
|
118
83
|
|
|
@@ -132,10 +97,6 @@ function findAppPath(root) {
|
|
|
132
97
|
return root
|
|
133
98
|
}
|
|
134
99
|
|
|
135
|
-
function toKebabCase(str) {
|
|
136
|
-
return str.toLowerCase()
|
|
137
|
-
}
|
|
138
|
-
|
|
139
100
|
function logStep(message) {
|
|
140
101
|
console.log(`📦 ${message}`)
|
|
141
102
|
}
|
|
@@ -148,39 +109,6 @@ function logError(message) {
|
|
|
148
109
|
console.log(`❌ ${message}`)
|
|
149
110
|
}
|
|
150
111
|
|
|
151
|
-
function gradientLog(text) {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
//yellow and blue gradient
|
|
155
|
-
const colors = [
|
|
156
|
-
"#ffff00",
|
|
157
|
-
"#00ffff",
|
|
158
|
-
"#0000ff",
|
|
159
|
-
"#0080ff",
|
|
160
|
-
"#00ff80",
|
|
161
|
-
"#00ff00",
|
|
162
|
-
"#80ff00",
|
|
163
|
-
"#ffbf00",
|
|
164
|
-
"#ff8000",
|
|
165
|
-
"#ff4000",
|
|
166
|
-
"#ff0000",
|
|
167
|
-
];
|
|
168
|
-
|
|
169
|
-
const args = [];
|
|
170
|
-
let format = '';
|
|
171
|
-
|
|
172
|
-
[...text].forEach((char, i) => {
|
|
173
|
-
const color = colors[i % colors.length];
|
|
174
|
-
format += `%c${char}`;
|
|
175
|
-
args.push(`color: ${color}; font-size: 16px; font-weight: bold;`);
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
console.log(format, ...args);
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
|
|
184
112
|
async function fetchComponent(component) {
|
|
185
113
|
try {
|
|
186
114
|
const res = await axios.get(
|
|
@@ -191,4 +119,21 @@ async function fetchComponent(component) {
|
|
|
191
119
|
logError(`Component "${component}" not found`)
|
|
192
120
|
process.exit(1)
|
|
193
121
|
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
function detectPackageManager(projectPath) {
|
|
126
|
+
if (fs.existsSync(path.join(projectPath, "pnpm-lock.yaml"))) {
|
|
127
|
+
return "pnpm"
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (fs.existsSync(path.join(projectPath, "yarn.lock"))) {
|
|
131
|
+
return "yarn"
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (fs.existsSync(path.join(projectPath, "package-lock.json"))) {
|
|
135
|
+
return "npm"
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return "npm" // fallback
|
|
194
139
|
}
|