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.
Files changed (2) hide show
  1. package/index.js +70 -125
  2. 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 projectRoot = process.cwd()
11
- const targetAppPath = findAppPath(projectRoot)
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
- const data = await fetchComponent(component)
51
-
52
- console.log("\n⚡ NeonBlade UI\n")
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
- // meta.files.forEach((file) => {
59
- // const sourcePath = path.join(componentDir, file)
23
+ if (!component) {
24
+ console.log("Please provide a component name")
25
+ process.exit(1)
26
+ }
60
27
 
61
- // const targetPath = path.join(
62
- // targetAppPath,
63
- // "components/ui",
64
- // toKebabCase(file)
65
- // )
28
+ console.log("\n⚡ NeonBlade UI\n")
66
29
 
67
- // fs.mkdirSync(path.dirname(targetPath), { recursive: true })
68
- // fs.copyFileSync(sourcePath, targetPath)
69
- // })
30
+ logStep(`Adding ${component}...`)
70
31
 
71
- for (const file of data.files) {
72
- const fileRes = await axios.get(file.url)
32
+ const data = await fetchComponent(component)
73
33
 
74
- const targetPath = path.join(
75
- targetAppPath,
76
- file.path
77
- )
34
+ logStep("Copying files...")
78
35
 
79
- fs.mkdirSync(path.dirname(targetPath), { recursive: true })
80
- fs.writeFileSync(targetPath, fileRes.data)
81
- }
36
+ for (const file of data.files) {
37
+ const fileRes = await axios.get(file.url)
82
38
 
83
- const { execSync } = require("child_process")
84
-
85
- // Install dependencies if any
86
- // if (meta.dependencies && meta.dependencies.length > 0) {
87
- // logStep("Installing dependencies...")
39
+ const targetPath = path.join(
40
+ targetAppPath,
41
+ file.path
42
+ )
88
43
 
89
- // execSync(
90
- // `pnpm add ${meta.dependencies.join(" ")}`,
91
- // { stdio: "inherit", cwd: targetAppPath }
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
- if (data.dependencies && data.dependencies.length > 0) {
96
- logStep("Installing dependencies...")
61
+ execSync(
62
+ installCmd,
63
+ {
64
+ stdio: "inherit",
65
+ cwd: targetAppPath,
66
+ }
67
+ )
68
+ }
97
69
 
98
- execSync(
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
- logSuccess(`${component} added successfully`)
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "neonblade",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "NeonBlade UI CLI",
5
5
  "bin": {
6
6
  "neonblade": "index.js"