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.
@@ -3,7 +3,7 @@ import "./ComponentTest.css"
3
3
  const ComponentTest = () => {
4
4
  return (
5
5
  <div>
6
- <h1>Nirmata is here! </h1>
6
+ <h1>NH-Lib is on Git! </h1>
7
7
  </div>
8
8
  )
9
9
  }
@@ -0,0 +1,3 @@
1
+ h1{
2
+ color: cyan;
3
+ }
@@ -0,0 +1,11 @@
1
+ import "./ComponentTest.css"
2
+
3
+ const ComponentTestThree = () => {
4
+ return (
5
+ <div>
6
+ <h1>Nirmata is here 3333! </h1>
7
+ </div>
8
+ )
9
+ }
10
+
11
+ export default ComponentTestThree
@@ -0,0 +1,3 @@
1
+ h1{
2
+ color: cyan;
3
+ }
@@ -0,0 +1,11 @@
1
+ import "./ComponentTest.css"
2
+
3
+ const ComponentTestTwo = () => {
4
+ return (
5
+ <div>
6
+ <h1>Nirmata is here 222! </h1>
7
+ </div>
8
+ )
9
+ }
10
+
11
+ export default ComponentTestTwo
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
- // Get the component name from CLI arguments
7
- const componentName = process.argv[2]
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.log("Please specify a component. Example: NH-Library ComponentTest")
11
- process.exit(1)
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 registry = require("../registry/components.json")
21
+ // 3. Load the registry
22
+ const registryPath = path.join(libraryRoot, "registry", "components.json");
16
23
 
17
- if (!registry[componentName]) {
18
- console.log(`Component "${componentName}" not found in registry.`)
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
- // Destination folder in the target project
23
- const destFolder = path.join(process.cwd(), "src/components/ui", componentName)
29
+ const registry = require(registryPath);
24
30
 
25
- // Ensure destination folder exists
26
- fs.mkdirSync(destFolder, { recursive: true })
31
+ const componentConfig = registry[componentName];
27
32
 
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)
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
- 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}`)
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
- // 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
- })
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(`Component "${componentName}" installed successfully!`)
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.0",
3
+ "version": "1.0.2",
4
4
  "description": "CLI-based React component library",
5
5
  "main": "cli/index.cjs",
6
6
  "bin": {
7
- "NH-Library": "./cli/index.cjs"
7
+ "nh-lib": "./cli/index.cjs"
8
8
  },
9
+ "files": [
10
+ "cli",
11
+ "registry",
12
+ "Components"
13
+ ],
9
14
  "type": "commonjs",
10
- "author": "Nirmata",
15
+ "author": "Your Name",
11
16
  "license": "MIT"
12
- }
17
+ }
@@ -1,7 +1,5 @@
1
1
  {
2
- "ComponentTest": {
3
- "files": [
4
- "Components/ComponentTest"
5
- ]
6
- }
2
+ "ComponentTestOne": { "files": ["Components/ComponentTestOne"] },
3
+ "ComponentTestTwo": { "files": ["Components/ComponentTestTwo"] },
4
+ "ComponentTestTree": { "files": ["Components/ComponentTestTree"] }
7
5
  }