gbs-add-block 0.0.1 → 0.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.
Files changed (2) hide show
  1. package/index.js +39 -20
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -18,7 +18,10 @@ const COMPONENTS = [
18
18
  "Spinner",
19
19
  "Toast",
20
20
  ];
21
- const SOURCE_PATH = path.join(process.cwd(), "source", "components");
21
+
22
+ // Use __dirname to get the directory where the script is located
23
+ const PACKAGE_ROOT = path.join(__dirname, "..");
24
+ const SOURCE_PATH = path.join(PACKAGE_ROOT, "components");
22
25
  const DEST_PATH = path.join(process.cwd(), "src", "component-lib");
23
26
 
24
27
  const rl = readline.createInterface({
@@ -37,16 +40,24 @@ function listComponents() {
37
40
 
38
41
  function copyCommonFiles() {
39
42
  // Copy utils.ts
40
- const utilsSrc = path.join(SOURCE_PATH, "..", "utils.ts");
43
+ const utilsSrc = path.join(PACKAGE_ROOT, "utils.ts");
41
44
  const utilsDest = path.join(DEST_PATH, "utils.ts");
42
- fs.copySync(utilsSrc, utilsDest, { overwrite: true });
43
- console.log(`utils.ts copied successfully to ${utilsDest}`);
45
+ if (fs.existsSync(utilsSrc)) {
46
+ fs.copySync(utilsSrc, utilsDest, { overwrite: true });
47
+ console.log(`utils.ts copied successfully to ${utilsDest}`);
48
+ } else {
49
+ console.warn(`utils.ts not found at ${utilsSrc}`);
50
+ }
44
51
 
45
52
  // Copy icon folder
46
- const iconSrc = path.join(SOURCE_PATH, "..", "icon");
53
+ const iconSrc = path.join(PACKAGE_ROOT, "icon");
47
54
  const iconDest = path.join(DEST_PATH, "icon");
48
- fs.copySync(iconSrc, iconDest, { overwrite: true });
49
- console.log(`icon folder copied successfully to ${iconDest}`);
55
+ if (fs.existsSync(iconSrc)) {
56
+ fs.copySync(iconSrc, iconDest, { overwrite: true });
57
+ console.log(`icon folder copied successfully to ${iconDest}`);
58
+ } else {
59
+ console.warn(`icon folder not found at ${iconSrc}`);
60
+ }
50
61
  }
51
62
 
52
63
  function copyComponent(component) {
@@ -54,8 +65,10 @@ function copyComponent(component) {
54
65
  const componentDest = path.join(DEST_PATH, component.toLowerCase());
55
66
 
56
67
  if (!fs.existsSync(componentSrc)) {
57
- console.error(`Component ${component} not found in source directory.`);
58
- return;
68
+ console.error(
69
+ `Component ${component} not found in source directory: ${componentSrc}`
70
+ );
71
+ return false;
59
72
  }
60
73
 
61
74
  fs.copySync(componentSrc, componentDest, { overwrite: true });
@@ -65,6 +78,8 @@ function copyComponent(component) {
65
78
  copyCommonFiles();
66
79
  isFirstCopy = false;
67
80
  }
81
+
82
+ return true;
68
83
  }
69
84
 
70
85
  function promptForComponent() {
@@ -85,18 +100,22 @@ function promptForComponent() {
85
100
  }
86
101
 
87
102
  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();
103
+ const success = copyComponent(selectedComponent);
104
+
105
+ if (success) {
106
+ rl.question(
107
+ "Do you want to copy another component? (y/n): ",
108
+ (answer) => {
109
+ if (answer.toLowerCase() === "y") {
110
+ promptForComponent();
111
+ } else {
112
+ rl.close();
113
+ }
97
114
  }
98
- }
99
- );
115
+ );
116
+ } else {
117
+ promptForComponent();
118
+ }
100
119
  }
101
120
  );
102
121
  }
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.2",
4
4
  "description": "React Component Library",
5
5
  "files": [
6
6
  "index.js",