gbs-add-block 0.0.1 → 0.0.3

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 +57 -20
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -18,7 +18,21 @@ const COMPONENTS = [
18
18
  "Spinner",
19
19
  "Toast",
20
20
  ];
21
- const SOURCE_PATH = path.join(process.cwd(), "source", "components");
21
+
22
+ // Function to find the package root directory
23
+ function findPackageRoot(startDir) {
24
+ let dir = startDir;
25
+ while (dir !== path.parse(dir).root) {
26
+ if (fs.existsSync(path.join(dir, "package.json"))) {
27
+ return dir;
28
+ }
29
+ dir = path.dirname(dir);
30
+ }
31
+ throw new Error("Unable to find package root");
32
+ }
33
+
34
+ const PACKAGE_ROOT = findPackageRoot(__dirname);
35
+ const SOURCE_PATH = path.join(PACKAGE_ROOT, "components");
22
36
  const DEST_PATH = path.join(process.cwd(), "src", "component-lib");
23
37
 
24
38
  const rl = readline.createInterface({
@@ -37,16 +51,24 @@ function listComponents() {
37
51
 
38
52
  function copyCommonFiles() {
39
53
  // Copy utils.ts
40
- const utilsSrc = path.join(SOURCE_PATH, "..", "utils.ts");
54
+ const utilsSrc = path.join(PACKAGE_ROOT, "utils.ts");
41
55
  const utilsDest = path.join(DEST_PATH, "utils.ts");
42
- fs.copySync(utilsSrc, utilsDest, { overwrite: true });
43
- console.log(`utils.ts copied successfully to ${utilsDest}`);
56
+ if (fs.existsSync(utilsSrc)) {
57
+ fs.copySync(utilsSrc, utilsDest, { overwrite: true });
58
+ console.log(`utils.ts copied successfully to ${utilsDest}`);
59
+ } else {
60
+ console.warn(`utils.ts not found at ${utilsSrc}`);
61
+ }
44
62
 
45
63
  // Copy icon folder
46
- const iconSrc = path.join(SOURCE_PATH, "..", "icon");
64
+ const iconSrc = path.join(PACKAGE_ROOT, "icon");
47
65
  const iconDest = path.join(DEST_PATH, "icon");
48
- fs.copySync(iconSrc, iconDest, { overwrite: true });
49
- console.log(`icon folder copied successfully to ${iconDest}`);
66
+ if (fs.existsSync(iconSrc)) {
67
+ fs.copySync(iconSrc, iconDest, { overwrite: true });
68
+ console.log(`icon folder copied successfully to ${iconDest}`);
69
+ } else {
70
+ console.warn(`icon folder not found at ${iconSrc}`);
71
+ }
50
72
  }
51
73
 
52
74
  function copyComponent(component) {
@@ -54,8 +76,10 @@ function copyComponent(component) {
54
76
  const componentDest = path.join(DEST_PATH, component.toLowerCase());
55
77
 
56
78
  if (!fs.existsSync(componentSrc)) {
57
- console.error(`Component ${component} not found in source directory.`);
58
- return;
79
+ console.error(
80
+ `Component ${component} not found in source directory: ${componentSrc}`
81
+ );
82
+ return false;
59
83
  }
60
84
 
61
85
  fs.copySync(componentSrc, componentDest, { overwrite: true });
@@ -65,6 +89,8 @@ function copyComponent(component) {
65
89
  copyCommonFiles();
66
90
  isFirstCopy = false;
67
91
  }
92
+
93
+ return true;
68
94
  }
69
95
 
70
96
  function promptForComponent() {
@@ -85,22 +111,33 @@ function promptForComponent() {
85
111
  }
86
112
 
87
113
  const selectedComponent = COMPONENTS[index];
88
- copyComponent(selectedComponent);
89
-
90
- rl.question(
91
- "Do you want to copy another component? (y/n): ",
92
- (answer) => {
93
- if (answer.toLowerCase() === "y") {
94
- promptForComponent();
95
- } else {
96
- rl.close();
114
+ const success = copyComponent(selectedComponent);
115
+
116
+ if (success) {
117
+ rl.question(
118
+ "Do you want to copy another component? (y/n): ",
119
+ (answer) => {
120
+ if (answer.toLowerCase() === "y") {
121
+ promptForComponent();
122
+ } else {
123
+ rl.close();
124
+ }
97
125
  }
98
- }
99
- );
126
+ );
127
+ } else {
128
+ promptForComponent();
129
+ }
100
130
  }
101
131
  );
102
132
  }
103
133
 
134
+ // Print debug information
135
+ console.log("Debug Info:");
136
+ console.log(`__dirname: ${__dirname}`);
137
+ console.log(`PACKAGE_ROOT: ${PACKAGE_ROOT}`);
138
+ console.log(`SOURCE_PATH: ${SOURCE_PATH}`);
139
+ console.log(`DEST_PATH: ${DEST_PATH}`);
140
+
104
141
  // Ensure the destination directory exists
105
142
  fs.ensureDirSync(DEST_PATH);
106
143
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gbs-add-block",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "React Component Library",
5
5
  "files": [
6
6
  "index.js",