gbs-add-block 0.0.3 → 0.0.5

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 +20 -57
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -18,21 +18,7 @@ const COMPONENTS = [
18
18
  "Spinner",
19
19
  "Toast",
20
20
  ];
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");
21
+ const SOURCE_PATH = path.join(__dirname, "source", "components");
36
22
  const DEST_PATH = path.join(process.cwd(), "src", "component-lib");
37
23
 
38
24
  const rl = readline.createInterface({
@@ -51,24 +37,16 @@ function listComponents() {
51
37
 
52
38
  function copyCommonFiles() {
53
39
  // Copy utils.ts
54
- const utilsSrc = path.join(PACKAGE_ROOT, "utils.ts");
40
+ const utilsSrc = path.join(SOURCE_PATH, "..", "utils.ts");
55
41
  const utilsDest = path.join(DEST_PATH, "utils.ts");
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
- }
42
+ fs.copySync(utilsSrc, utilsDest, { overwrite: true });
43
+ console.log(`utils.ts copied successfully to ${utilsDest}`);
62
44
 
63
45
  // Copy icon folder
64
- const iconSrc = path.join(PACKAGE_ROOT, "icon");
46
+ const iconSrc = path.join(SOURCE_PATH, "..", "icon");
65
47
  const iconDest = path.join(DEST_PATH, "icon");
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
- }
48
+ fs.copySync(iconSrc, iconDest, { overwrite: true });
49
+ console.log(`icon folder copied successfully to ${iconDest}`);
72
50
  }
73
51
 
74
52
  function copyComponent(component) {
@@ -76,10 +54,8 @@ function copyComponent(component) {
76
54
  const componentDest = path.join(DEST_PATH, component.toLowerCase());
77
55
 
78
56
  if (!fs.existsSync(componentSrc)) {
79
- console.error(
80
- `Component ${component} not found in source directory: ${componentSrc}`
81
- );
82
- return false;
57
+ console.error(`Component ${component} not found in source directory.`);
58
+ return;
83
59
  }
84
60
 
85
61
  fs.copySync(componentSrc, componentDest, { overwrite: true });
@@ -89,8 +65,6 @@ function copyComponent(component) {
89
65
  copyCommonFiles();
90
66
  isFirstCopy = false;
91
67
  }
92
-
93
- return true;
94
68
  }
95
69
 
96
70
  function promptForComponent() {
@@ -111,33 +85,22 @@ function promptForComponent() {
111
85
  }
112
86
 
113
87
  const selectedComponent = COMPONENTS[index];
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
- }
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();
125
97
  }
126
- );
127
- } else {
128
- promptForComponent();
129
- }
98
+ }
99
+ );
130
100
  }
131
101
  );
132
102
  }
133
103
 
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
-
141
104
  // Ensure the destination directory exists
142
105
  fs.ensureDirSync(DEST_PATH);
143
106
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gbs-add-block",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "React Component Library",
5
5
  "files": [
6
6
  "index.js",