neonblade 0.0.1
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 +154 -0
- package/package.json +11 -0
package/index.js
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require("fs")
|
|
4
|
+
const path = require("path")
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
const projectRoot = process.cwd()
|
|
9
|
+
const targetAppPath = findAppPath(projectRoot)
|
|
10
|
+
|
|
11
|
+
const args = process.argv.slice(2)
|
|
12
|
+
|
|
13
|
+
const command = args[0]
|
|
14
|
+
const component = args[1]
|
|
15
|
+
|
|
16
|
+
if (command !== "add") {
|
|
17
|
+
console.log("Usage: neonblade add <component>")
|
|
18
|
+
process.exit(1)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (!component) {
|
|
22
|
+
console.log("Please provide a component name")
|
|
23
|
+
process.exit(1)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const componentDir = path.join(
|
|
27
|
+
__dirname,
|
|
28
|
+
"../registry/components",
|
|
29
|
+
component
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
//log if component is not found
|
|
33
|
+
if (!fs.existsSync(componentDir)) {
|
|
34
|
+
logError(`${component} not found`)
|
|
35
|
+
process.exit(1)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Read metadata
|
|
39
|
+
const metaPath = path.join(componentDir, "meta.json")
|
|
40
|
+
|
|
41
|
+
if (!fs.existsSync(metaPath)) {
|
|
42
|
+
console.log("Component metadata not found")
|
|
43
|
+
process.exit(1)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const meta = JSON.parse(fs.readFileSync(metaPath, "utf-8"))
|
|
47
|
+
|
|
48
|
+
console.log("\nā” NeonBlade UI\n")
|
|
49
|
+
|
|
50
|
+
// Copy files
|
|
51
|
+
logStep(`Adding ${component}...`)
|
|
52
|
+
logStep("Copying files...")
|
|
53
|
+
|
|
54
|
+
meta.files.forEach((file) => {
|
|
55
|
+
const sourcePath = path.join(componentDir, file)
|
|
56
|
+
|
|
57
|
+
const targetPath = path.join(
|
|
58
|
+
targetAppPath,
|
|
59
|
+
"components/ui",
|
|
60
|
+
toKebabCase(file)
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
fs.mkdirSync(path.dirname(targetPath), { recursive: true })
|
|
64
|
+
fs.copyFileSync(sourcePath, targetPath)
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
const { execSync } = require("child_process")
|
|
68
|
+
|
|
69
|
+
// Install dependencies if any
|
|
70
|
+
if (meta.dependencies && meta.dependencies.length > 0) {
|
|
71
|
+
logStep("Installing dependencies...")
|
|
72
|
+
|
|
73
|
+
execSync(
|
|
74
|
+
`pnpm add ${meta.dependencies.join(" ")}`,
|
|
75
|
+
{ stdio: "inherit", cwd: targetAppPath }
|
|
76
|
+
)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
logSuccess(`${component} added successfully`)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
function findAppPath(root) {
|
|
83
|
+
const appsDir = path.join(root, "apps")
|
|
84
|
+
|
|
85
|
+
if (!fs.existsSync(appsDir)) {
|
|
86
|
+
return root
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const apps = fs.readdirSync(appsDir)
|
|
90
|
+
|
|
91
|
+
for (const app of apps) {
|
|
92
|
+
const appPath = path.join(appsDir, app)
|
|
93
|
+
const pkgPath = path.join(appPath, "package.json")
|
|
94
|
+
|
|
95
|
+
if (fs.existsSync(pkgPath)) {
|
|
96
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"))
|
|
97
|
+
|
|
98
|
+
if (pkg.dependencies && pkg.dependencies.next) {
|
|
99
|
+
return appPath
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return root
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function toKebabCase(str) {
|
|
108
|
+
return str.toLowerCase()
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function logStep(message) {
|
|
112
|
+
console.log(`š¦ ${message}`)
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function logSuccess(message) {
|
|
116
|
+
console.log(`ā
${message}`)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function logError(message) {
|
|
120
|
+
console.log(`ā ${message}`)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function gradientLog(text) {
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
//yellow and blue gradient
|
|
127
|
+
const colors = [
|
|
128
|
+
"#ffff00",
|
|
129
|
+
"#00ffff",
|
|
130
|
+
"#0000ff",
|
|
131
|
+
"#0080ff",
|
|
132
|
+
"#00ff80",
|
|
133
|
+
"#00ff00",
|
|
134
|
+
"#80ff00",
|
|
135
|
+
"#ffbf00",
|
|
136
|
+
"#ff8000",
|
|
137
|
+
"#ff4000",
|
|
138
|
+
"#ff0000",
|
|
139
|
+
];
|
|
140
|
+
|
|
141
|
+
const args = [];
|
|
142
|
+
let format = '';
|
|
143
|
+
|
|
144
|
+
[...text].forEach((char, i) => {
|
|
145
|
+
const color = colors[i % colors.length];
|
|
146
|
+
format += `%c${char}`;
|
|
147
|
+
args.push(`color: ${color}; font-size: 16px; font-weight: bold;`);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
console.log(format, ...args);
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
}
|
|
154
|
+
|