nh-library 1.0.0
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/index.cjs
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require("fs")
|
|
4
|
+
const path = require("path")
|
|
5
|
+
|
|
6
|
+
// Get the component name from CLI arguments
|
|
7
|
+
const componentName = process.argv[2]
|
|
8
|
+
|
|
9
|
+
if (!componentName) {
|
|
10
|
+
console.log("Please specify a component. Example: NH-Library ComponentTest")
|
|
11
|
+
process.exit(1)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// Load the registry
|
|
15
|
+
const registry = require("../registry/components.json")
|
|
16
|
+
|
|
17
|
+
if (!registry[componentName]) {
|
|
18
|
+
console.log(`Component "${componentName}" not found in registry.`)
|
|
19
|
+
process.exit(1)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Destination folder in the target project
|
|
23
|
+
const destFolder = path.join(process.cwd(), "src/components/ui", componentName)
|
|
24
|
+
|
|
25
|
+
// Ensure destination folder exists
|
|
26
|
+
fs.mkdirSync(destFolder, { recursive: true })
|
|
27
|
+
|
|
28
|
+
// Function to copy a folder recursively
|
|
29
|
+
function copyFolderRecursive(src, dest) {
|
|
30
|
+
const entries = fs.readdirSync(src, { withFileTypes: true })
|
|
31
|
+
entries.forEach((entry) => {
|
|
32
|
+
const srcPath = path.join(src, entry.name)
|
|
33
|
+
const destPath = path.join(dest, entry.name)
|
|
34
|
+
|
|
35
|
+
if (entry.isDirectory()) {
|
|
36
|
+
fs.mkdirSync(destPath, { recursive: true })
|
|
37
|
+
copyFolderRecursive(srcPath, destPath)
|
|
38
|
+
} else {
|
|
39
|
+
fs.copyFileSync(srcPath, destPath)
|
|
40
|
+
console.log(`Copied ${entry.name} → ${destPath}`)
|
|
41
|
+
}
|
|
42
|
+
})
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Copy all files/folders listed in the registry
|
|
46
|
+
registry[componentName].files.forEach((file) => {
|
|
47
|
+
const source = path.join(__dirname, "..", file)
|
|
48
|
+
copyFolderRecursive(source, destFolder)
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
console.log(`Component "${componentName}" installed successfully!`)
|
package/package.json
ADDED