gbs-add-block 0.0.70 → 0.0.71

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.cjs +173 -0
  2. package/package.json +3 -3
package/index.cjs ADDED
@@ -0,0 +1,173 @@
1
+ #!/usr/bin/env node
2
+
3
+ const fs = require("fs-extra");
4
+ const path = require("path");
5
+ const yargs = require("yargs/yargs");
6
+ const { hideBin } = require("yargs/helpers");
7
+
8
+ // Configuration
9
+ const CONFIG = {
10
+ components: [
11
+ "Select",
12
+ "Grid",
13
+ "MultiSelect",
14
+ "Button",
15
+ "DatePicker",
16
+ "Checkbox",
17
+ "DarkMode",
18
+ "Dialog",
19
+ "Input",
20
+ "Modal",
21
+ "Spinner",
22
+ "Toast",
23
+ "Uploader",
24
+ "FormRenderer",
25
+ "MaterialInput",
26
+ "ContextMenu",
27
+ "Skeleton",
28
+ "Navbar",
29
+ "DataGrid",
30
+ "BreadCrumb",
31
+ ],
32
+ // Define component dependencies
33
+ dependencies: {
34
+ FormRenderer: ["Select", "MultiSelect", "Input", "DatePicker"],
35
+ },
36
+ docs: "https://blackmax-designs.gitbook.io/building-block-v2.0",
37
+ };
38
+
39
+ const SOURCE_PATH = path.join(__dirname, "source", "components");
40
+ const DEFAULT_DEST_PATH = path.join(process.cwd(), "component-lib");
41
+
42
+ const copyCommonFiles = async (destPath) => {
43
+ const commonFiles = [
44
+ { src: ["..", "utils.ts"], dest: "utils.ts" },
45
+ { src: ["..", "globalStyle.ts"], dest: "globalStyle.ts" },
46
+ { src: ["..", "icon"], dest: "icon" },
47
+ ];
48
+
49
+ for (const file of commonFiles) {
50
+ const src = path.join(SOURCE_PATH, ...file.src);
51
+ const dest = path.join(destPath, file.dest);
52
+ await fs.copy(src, dest, { overwrite: true });
53
+ console.log(`✓ ${file.dest} copied successfully`);
54
+ }
55
+ };
56
+
57
+ const checkComponentExists = (component, destPath) => {
58
+ const componentPath = path.join(destPath, component.toLowerCase());
59
+ return fs.existsSync(componentPath);
60
+ };
61
+
62
+ const copyComponent = async (component, destPath) => {
63
+ try {
64
+ const componentSrc = path.join(SOURCE_PATH, component.toLowerCase());
65
+ const componentDest = path.join(destPath, component.toLowerCase());
66
+
67
+ if (!fs.existsSync(componentSrc)) {
68
+ throw new Error(`Component ${component} not found in source directory.`);
69
+ }
70
+
71
+ await fs.copy(componentSrc, componentDest, { overwrite: true });
72
+ console.log(
73
+ `✓ Component ${component} installed successfully ${
74
+ component === "Grid"
75
+ ? "This Version of Grid will be deprecated soon. Please Install The New Data Grid Component"
76
+ : ""
77
+ }`
78
+ );
79
+ } catch (error) {
80
+ console.error(`Error installing component ${component}:`, error.message);
81
+ process.exit(1);
82
+ }
83
+ };
84
+
85
+ const installComponentWithDependencies = async (component, destPath) => {
86
+ // Get dependencies for the component
87
+ const dependencies = CONFIG.dependencies[component] || [];
88
+ const componentsToInstall = new Set([component, ...dependencies]);
89
+
90
+ // Check which components need to be installed
91
+ const pendingInstalls = Array.from(componentsToInstall).filter(
92
+ (comp) => !checkComponentExists(comp, destPath)
93
+ );
94
+
95
+ if (pendingInstalls.length === 0) {
96
+ console.log(
97
+ `✓ ${component} and all its dependencies are already installed.`
98
+ );
99
+ return;
100
+ }
101
+
102
+ // Install all pending components
103
+ for (const comp of pendingInstalls) {
104
+ await copyComponent(comp, destPath);
105
+ }
106
+
107
+ if (dependencies.length > 0) {
108
+ console.log(`\nInstalled dependencies for ${component}:`);
109
+ dependencies.forEach((dep) => {
110
+ console.log(`- ${dep}`);
111
+ });
112
+ }
113
+
114
+ console.log(`\nFor documentation visit: ${CONFIG.docs}`);
115
+ };
116
+
117
+ const main = async () => {
118
+ const argv = yargs(hideBin(process.argv))
119
+ .option("add", {
120
+ alias: "a",
121
+ describe: "Component to install",
122
+ type: "string",
123
+ })
124
+ .option("list", {
125
+ alias: "l",
126
+ describe: "List available components",
127
+ type: "boolean",
128
+ })
129
+ .help().argv;
130
+
131
+ // List components if requested
132
+ if (argv.list) {
133
+ console.log("\nAvailable components:");
134
+ CONFIG.components.forEach((comp) => {
135
+ const deps = CONFIG.dependencies[comp]
136
+ ? ` (requires: ${CONFIG.dependencies[comp].join(", ")})`
137
+ : "";
138
+ console.log(`- ${comp}${deps}`);
139
+ });
140
+ return;
141
+ }
142
+
143
+ if (!argv.add) {
144
+ console.error("Please specify a component to install using -a or --add");
145
+ process.exit(1);
146
+ }
147
+
148
+ // Validate component name
149
+ const component = argv.add;
150
+ if (!CONFIG.components.includes(component)) {
151
+ console.error(`Invalid component: ${component}`);
152
+ console.log("\nAvailable components:");
153
+ CONFIG.components.forEach((comp) => console.log(`- ${comp}`));
154
+ process.exit(1);
155
+ }
156
+
157
+ // Create destination directory in project root
158
+ const destPath = DEFAULT_DEST_PATH;
159
+ await fs.ensureDir(destPath);
160
+
161
+ // Copy common files if they don't exist
162
+ if (!fs.existsSync(path.join(destPath, "utils.ts"))) {
163
+ await copyCommonFiles(destPath);
164
+ }
165
+
166
+ // Install component and its dependencies
167
+ await installComponentWithDependencies(component, destPath);
168
+ };
169
+
170
+ main().catch((error) => {
171
+ console.error("Error:", error.message);
172
+ process.exit(1);
173
+ });
package/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "gbs-add-block",
3
- "version": "0.0.70",
3
+ "version": "0.0.71",
4
4
  "description": "React Component Library",
5
5
  "type": "module",
6
6
  "files": [
7
- "index.js",
7
+ "index.cjs",
8
8
  "source"
9
9
  ],
10
10
  "engines": {
11
11
  "node": ">=17"
12
12
  },
13
13
  "bin": {
14
- "gbs-add-block": "./index.js"
14
+ "gbs-add-block": "./index.cjs"
15
15
  },
16
16
  "scripts": {
17
17
  "test": "echo \"Error: no test specified\" && exit 1"