nh-library 1.0.0 → 1.0.2
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/Components/{ComponentTest → ComponentTestOne}/ComponentTest.jsx +1 -1
- package/Components/ComponentTestTree/ComponentTest.css +3 -0
- package/Components/ComponentTestTree/ComponentTestTree.jsx +11 -0
- package/Components/ComponentTestTwo/ComponentTest.css +3 -0
- package/Components/ComponentTestTwo/ComponentTestTwo.jsx +11 -0
- package/cli/index.cjs +67 -34
- package/package.json +9 -4
- package/registry/components.json +3 -5
- /package/Components/{ComponentTest → ComponentTestOne}/ComponentTest.css +0 -0
package/cli/index.cjs
CHANGED
|
@@ -1,51 +1,84 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
const fs = require("fs")
|
|
4
|
-
const path = require("path")
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const path = require("path");
|
|
5
5
|
|
|
6
|
-
//
|
|
7
|
-
|
|
6
|
+
// 1. Setup Paths
|
|
7
|
+
// __dirname is /node_modules/nh-library/cli
|
|
8
|
+
// We need to go up one level to reach /node_modules/nh-library/
|
|
9
|
+
const libraryRoot = path.join(__dirname, "..");
|
|
10
|
+
const projectRoot = process.cwd();
|
|
11
|
+
|
|
12
|
+
// 2. Get the component name from CLI arguments
|
|
13
|
+
const componentName = process.argv[2];
|
|
8
14
|
|
|
9
15
|
if (!componentName) {
|
|
10
|
-
console.
|
|
11
|
-
|
|
16
|
+
console.error("\x1b[31m%s\x1b[0m", "Error: Please specify a component name.");
|
|
17
|
+
console.log("Usage: npx nh-library <ComponentName>");
|
|
18
|
+
process.exit(1);
|
|
12
19
|
}
|
|
13
20
|
|
|
14
|
-
// Load the registry
|
|
15
|
-
const
|
|
21
|
+
// 3. Load the registry
|
|
22
|
+
const registryPath = path.join(libraryRoot, "registry", "components.json");
|
|
16
23
|
|
|
17
|
-
if (!
|
|
18
|
-
console.
|
|
19
|
-
process.exit(1)
|
|
24
|
+
if (!fs.existsSync(registryPath)) {
|
|
25
|
+
console.error("\x1b[31m%s\x1b[0m", "Error: Registry file not found in the library.");
|
|
26
|
+
process.exit(1);
|
|
20
27
|
}
|
|
21
28
|
|
|
22
|
-
|
|
23
|
-
const destFolder = path.join(process.cwd(), "src/components/ui", componentName)
|
|
29
|
+
const registry = require(registryPath);
|
|
24
30
|
|
|
25
|
-
|
|
26
|
-
fs.mkdirSync(destFolder, { recursive: true })
|
|
31
|
+
const componentConfig = registry[componentName];
|
|
27
32
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const destPath = path.join(dest, entry.name)
|
|
33
|
+
if (!componentConfig) {
|
|
34
|
+
console.error("\x1b[31m%s\x1b[0m", `Error: Component "${componentName}" not found in registry.`);
|
|
35
|
+
console.log("Available components:", Object.keys(registry).join(", "));
|
|
36
|
+
process.exit(1);
|
|
37
|
+
}
|
|
34
38
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
// 4. Define Destination (Standardizing on src/components/ui)
|
|
40
|
+
const destFolder = path.join(projectRoot, "src", "components", "ui", componentName);
|
|
41
|
+
|
|
42
|
+
// 5. Recursive Copy Function
|
|
43
|
+
function copyRecursive(src, dest) {
|
|
44
|
+
const exists = fs.existsSync(src);
|
|
45
|
+
const stats = exists && fs.statSync(src);
|
|
46
|
+
const isDirectory = exists && stats.isDirectory();
|
|
47
|
+
|
|
48
|
+
if (isDirectory) {
|
|
49
|
+
if (!fs.existsSync(dest)) {
|
|
50
|
+
fs.mkdirSync(dest, { recursive: true });
|
|
41
51
|
}
|
|
42
|
-
|
|
52
|
+
fs.readdirSync(src).forEach((childItemName) => {
|
|
53
|
+
copyRecursive(
|
|
54
|
+
path.join(src, childItemName),
|
|
55
|
+
path.join(dest, childItemName)
|
|
56
|
+
);
|
|
57
|
+
});
|
|
58
|
+
} else {
|
|
59
|
+
fs.copyFileSync(src, dest);
|
|
60
|
+
console.log(` \x1b[32m%s\x1b[0m`, `ADDED: ${path.relative(projectRoot, dest)}`);
|
|
61
|
+
}
|
|
43
62
|
}
|
|
44
63
|
|
|
45
|
-
//
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
64
|
+
// 6. Execution
|
|
65
|
+
console.log(`\nInstalling ${componentName} into your project...`);
|
|
66
|
+
|
|
67
|
+
try {
|
|
68
|
+
componentConfig.files.forEach((fileRelativePath) => {
|
|
69
|
+
// Construct the absolute path to the source in node_modules
|
|
70
|
+
const sourcePath = path.join(libraryRoot, fileRelativePath);
|
|
71
|
+
|
|
72
|
+
if (fs.existsSync(sourcePath)) {
|
|
73
|
+
copyRecursive(sourcePath, destFolder);
|
|
74
|
+
} else {
|
|
75
|
+
console.warn(`\x1b[33m%s\x1b[0m`, `Warning: Source path not found: ${fileRelativePath}`);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
50
78
|
|
|
51
|
-
console.log(`
|
|
79
|
+
console.log(`\n\x1b[32m%s\x1b[0m`, `Success! ${componentName} is ready to use.`);
|
|
80
|
+
console.log(`Location: /src/components/ui/${componentName}\n`);
|
|
81
|
+
} catch (error) {
|
|
82
|
+
console.error("\x1b[31m%s\x1b[0m", "An error occurred during installation:");
|
|
83
|
+
console.error(error);
|
|
84
|
+
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nh-library",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "CLI-based React component library",
|
|
5
5
|
"main": "cli/index.cjs",
|
|
6
6
|
"bin": {
|
|
7
|
-
"
|
|
7
|
+
"nh-lib": "./cli/index.cjs"
|
|
8
8
|
},
|
|
9
|
+
"files": [
|
|
10
|
+
"cli",
|
|
11
|
+
"registry",
|
|
12
|
+
"Components"
|
|
13
|
+
],
|
|
9
14
|
"type": "commonjs",
|
|
10
|
-
"author": "
|
|
15
|
+
"author": "Your Name",
|
|
11
16
|
"license": "MIT"
|
|
12
|
-
}
|
|
17
|
+
}
|
package/registry/components.json
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
]
|
|
6
|
-
}
|
|
2
|
+
"ComponentTestOne": { "files": ["Components/ComponentTestOne"] },
|
|
3
|
+
"ComponentTestTwo": { "files": ["Components/ComponentTestTwo"] },
|
|
4
|
+
"ComponentTestTree": { "files": ["Components/ComponentTestTree"] }
|
|
7
5
|
}
|
|
File without changes
|