getlotui 0.1.2 → 0.1.4

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.
package/package.json CHANGED
@@ -11,8 +11,11 @@
11
11
  },
12
12
  "packageManager": "pnpm@9.0.0",
13
13
  "dependencies": {
14
+ "chalk": "^5.3.0",
15
+ "commander": "^11.1.0",
14
16
  "debug": "^4.4.3",
17
+ "fs-extra": "^11.2.0",
15
18
  "ms": "^2.1.3"
16
19
  },
17
- "version": "0.1.2"
20
+ "version": "0.1.4"
18
21
  }
@@ -19,7 +19,7 @@ async function addCommand(component) {
19
19
  config = JSON.parse(configContent);
20
20
  }
21
21
  catch {
22
- console.error(chalk_1.default.red("getlotui.config.json not found. Run `getlotui init` first."));
22
+ console.error(chalk_1.default.red("getlotui.config.json not found. Run `getlotui init` first."));
23
23
  return;
24
24
  }
25
25
  const adapter = config.adapter || "expo";
@@ -28,10 +28,21 @@ async function addCommand(component) {
28
28
  (adapter === "flutter" ? "lib/components/ui" : "components/ui"));
29
29
  const componentName = component.charAt(0).toUpperCase() + component.slice(1);
30
30
  const templatePath = path_1.default.resolve(__dirname, "..", "templates", adapter, `${componentName}.${extension}`);
31
+ // Check if template exists
32
+ try {
33
+ await fs_1.promises.access(templatePath);
34
+ }
35
+ catch {
36
+ console.error(chalk_1.default.red(`❌ Component "${componentName}" not found for ${adapter}.`));
37
+ console.log(chalk_1.default.blue(`\n📚 Available components: Button, Input, Card, Badge, Avatar, Alert, AlertDialog, Accordion, Dropdown, Tabs, Toast`));
38
+ return;
39
+ }
31
40
  await (0, fs_2.copyComponent)(templatePath, path_1.default.join(componentsDir, `${componentName}.${extension}`));
32
- console.log(chalk_1.default.green(`Component ${componentName} added to ${componentsDir}`));
41
+ console.log(chalk_1.default.green(`✓ Component ${componentName} added to ${componentsDir}`));
42
+ // Provide usage hint
43
+ console.log(chalk_1.default.blue(`\n💡 Import it with: import { ${componentName} } from '@/components/ui/${componentName}'`));
33
44
  }
34
45
  catch (err) {
35
- console.error(chalk_1.default.red("Failed to add component:"), err);
46
+ console.error(chalk_1.default.red("Failed to add component:"), err);
36
47
  }
37
48
  }
@@ -1,4 +1,37 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
2
35
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
37
  };
@@ -80,12 +113,124 @@ class GetLotUITheme {
80
113
  }
81
114
  };`;
82
115
  await fs_1.promises.writeFile(themeFilePath, themeContent, "utf8");
83
- console.log(chalk_1.default.green(`Created ${defaultConfig.themeDir}/${themeFileName}`));
116
+ console.log(chalk_1.default.green(`✓ Created ${defaultConfig.themeDir}/${themeFileName}`));
84
117
  }
85
118
  catch (err) {
86
119
  console.warn(chalk_1.default.yellow("Could not create theme directory:"), err);
87
120
  }
88
- console.log(chalk_1.default.green(`Created getlotui.config.json with ${adapter} (${packageManager}) defaults.`));
121
+ // For web projects, create lib/utils.ts
122
+ if (adapter === "web") {
123
+ try {
124
+ const libDir = path_1.default.join(cwd, "lib");
125
+ await fs_1.promises.mkdir(libDir, { recursive: true });
126
+ const utilsPath = path_1.default.join(libDir, "utils.ts");
127
+ const utilsContent = `import { clsx, type ClassValue } from "clsx";
128
+ import { twMerge } from "tailwind-merge";
129
+
130
+ export function cn(...inputs: ClassValue[]) {
131
+ return twMerge(clsx(inputs));
132
+ }
133
+ `;
134
+ await fs_1.promises.writeFile(utilsPath, utilsContent, "utf8");
135
+ console.log(chalk_1.default.green(`✓ Created lib/utils.ts`));
136
+ }
137
+ catch (err) {
138
+ console.warn(chalk_1.default.yellow("Could not create lib/utils.ts:"), err);
139
+ }
140
+ // Install required dependencies
141
+ console.log(chalk_1.default.blue("\n📦 Installing required dependencies..."));
142
+ const { spawn } = await Promise.resolve().then(() => __importStar(require("child_process")));
143
+ const dependencies = [
144
+ "clsx",
145
+ "tailwind-merge",
146
+ "class-variance-authority",
147
+ ];
148
+ const installCmd = packageManager === "yarn"
149
+ ? "yarn"
150
+ : packageManager === "pnpm"
151
+ ? "pnpm"
152
+ : "npm";
153
+ const installArgs = packageManager === "yarn"
154
+ ? ["add", ...dependencies]
155
+ : packageManager === "pnpm"
156
+ ? ["add", ...dependencies]
157
+ : ["install", ...dependencies];
158
+ await new Promise((resolve, reject) => {
159
+ const proc = spawn(installCmd, installArgs, {
160
+ cwd,
161
+ stdio: "inherit",
162
+ shell: true,
163
+ });
164
+ proc.on("close", (code) => {
165
+ if (code === 0) {
166
+ console.log(chalk_1.default.green(`✓ Dependencies installed successfully`));
167
+ resolve();
168
+ }
169
+ else {
170
+ console.warn(chalk_1.default.yellow(`⚠ Failed to install dependencies. Please run: ${installCmd} ${installArgs.join(" ")}`));
171
+ resolve(); // Don't reject, just warn
172
+ }
173
+ });
174
+ proc.on("error", (err) => {
175
+ console.warn(chalk_1.default.yellow(`⚠ Could not install dependencies automatically: ${err.message}`));
176
+ console.log(chalk_1.default.blue(`Please run manually: ${installCmd} ${installArgs.join(" ")}`));
177
+ resolve(); // Don't reject, just warn
178
+ });
179
+ });
180
+ }
181
+ // For Expo projects, create utils/cn.ts
182
+ if (adapter === "expo") {
183
+ try {
184
+ const utilsDir = path_1.default.join(cwd, "utils");
185
+ await fs_1.promises.mkdir(utilsDir, { recursive: true });
186
+ const utilsPath = path_1.default.join(utilsDir, "cn.ts");
187
+ const utilsContent = `import { StyleSheet } from "react-native";
188
+
189
+ /**
190
+ * A utility to merge React Native styles.
191
+ */
192
+ export function cn(...inputs: any[]) {
193
+ return StyleSheet.flatten(inputs.filter(Boolean));
194
+ }
195
+ `;
196
+ await fs_1.promises.writeFile(utilsPath, utilsContent, "utf8");
197
+ console.log(chalk_1.default.green(`✓ Created utils/cn.ts`));
198
+ }
199
+ catch (err) {
200
+ console.warn(chalk_1.default.yellow("Could not create utils/cn.ts:"), err);
201
+ }
202
+ }
203
+ // For Flutter projects, create lib/utils.dart
204
+ if (adapter === "flutter") {
205
+ try {
206
+ const libDir = path_1.default.join(cwd, "lib");
207
+ await fs_1.promises.mkdir(libDir, { recursive: true });
208
+ const utilsPath = path_1.default.join(libDir, "utils.dart");
209
+ const utilsContent = `import 'package:flutter/material.dart';
210
+
211
+ class GetLotUIUtils {
212
+ static TextStyle cnText(List<TextStyle?> styles) {
213
+ TextStyle result = const TextStyle();
214
+ for (var style in styles) {
215
+ if (style != null) {
216
+ result = result.merge(style);
217
+ }
218
+ }
219
+ return result;
220
+ }
221
+ }
222
+ `;
223
+ await fs_1.promises.writeFile(utilsPath, utilsContent, "utf8");
224
+ console.log(chalk_1.default.green(`✓ Created lib/utils.dart`));
225
+ }
226
+ catch (err) {
227
+ console.warn(chalk_1.default.yellow("Could not create lib/utils.dart:"), err);
228
+ }
229
+ }
230
+ console.log(chalk_1.default.green(`\n✨ GetLotUI initialized with ${adapter} (${packageManager}) defaults.`));
231
+ console.log(chalk_1.default.blue(`\n📚 Next steps:`));
232
+ console.log(chalk_1.default.white(` 1. Run: getlotui add <component>`));
233
+ console.log(chalk_1.default.white(` 2. Import and use components in your app`));
89
234
  }
90
235
  catch (err) {
91
236
  console.error(chalk_1.default.red("Failed to initialize GetLotUI config:"), err);
@@ -14,7 +14,9 @@ export async function addCommand(component: string) {
14
14
  config = JSON.parse(configContent);
15
15
  } catch {
16
16
  console.error(
17
- chalk.red("getlotui.config.json not found. Run `getlotui init` first.")
17
+ chalk.red(
18
+ "❌ getlotui.config.json not found. Run `getlotui init` first."
19
+ )
18
20
  );
19
21
  return;
20
22
  }
@@ -37,14 +39,36 @@ export async function addCommand(component: string) {
37
39
  `${componentName}.${extension}`
38
40
  );
39
41
 
42
+ // Check if template exists
43
+ try {
44
+ await fs.access(templatePath);
45
+ } catch {
46
+ console.error(
47
+ chalk.red(`❌ Component "${componentName}" not found for ${adapter}.`)
48
+ );
49
+ console.log(
50
+ chalk.blue(
51
+ `\n📚 Available components: Button, Input, Card, Badge, Avatar, Alert, AlertDialog, Accordion, Dropdown, Tabs, Toast`
52
+ )
53
+ );
54
+ return;
55
+ }
56
+
40
57
  await copyComponent(
41
58
  templatePath,
42
59
  path.join(componentsDir, `${componentName}.${extension}`)
43
60
  );
44
61
  console.log(
45
- chalk.green(`Component ${componentName} added to ${componentsDir}`)
62
+ chalk.green(`✓ Component ${componentName} added to ${componentsDir}`)
63
+ );
64
+
65
+ // Provide usage hint
66
+ console.log(
67
+ chalk.blue(
68
+ `\n💡 Import it with: import { ${componentName} } from '@/components/ui/${componentName}'`
69
+ )
46
70
  );
47
71
  } catch (err) {
48
- console.error(chalk.red("Failed to add component:"), err);
72
+ console.error(chalk.red("Failed to add component:"), err);
49
73
  }
50
74
  }
@@ -91,17 +91,154 @@ class GetLotUITheme {
91
91
 
92
92
  await fs.writeFile(themeFilePath, themeContent, "utf8");
93
93
  console.log(
94
- chalk.green(`Created ${defaultConfig.themeDir}/${themeFileName}`)
94
+ chalk.green(`✓ Created ${defaultConfig.themeDir}/${themeFileName}`)
95
95
  );
96
96
  } catch (err) {
97
97
  console.warn(chalk.yellow("Could not create theme directory:"), err);
98
98
  }
99
99
 
100
+ // For web projects, create lib/utils.ts
101
+ if (adapter === "web") {
102
+ try {
103
+ const libDir = path.join(cwd, "lib");
104
+ await fs.mkdir(libDir, { recursive: true });
105
+
106
+ const utilsPath = path.join(libDir, "utils.ts");
107
+ const utilsContent = `import { clsx, type ClassValue } from "clsx";
108
+ import { twMerge } from "tailwind-merge";
109
+
110
+ export function cn(...inputs: ClassValue[]) {
111
+ return twMerge(clsx(inputs));
112
+ }
113
+ `;
114
+ await fs.writeFile(utilsPath, utilsContent, "utf8");
115
+ console.log(chalk.green(`✓ Created lib/utils.ts`));
116
+ } catch (err) {
117
+ console.warn(chalk.yellow("Could not create lib/utils.ts:"), err);
118
+ }
119
+
120
+ // Install required dependencies
121
+ console.log(chalk.blue("\n📦 Installing required dependencies..."));
122
+ const { spawn } = await import("child_process");
123
+
124
+ const dependencies = [
125
+ "clsx",
126
+ "tailwind-merge",
127
+ "class-variance-authority",
128
+ ];
129
+
130
+ const installCmd =
131
+ packageManager === "yarn"
132
+ ? "yarn"
133
+ : packageManager === "pnpm"
134
+ ? "pnpm"
135
+ : "npm";
136
+
137
+ const installArgs =
138
+ packageManager === "yarn"
139
+ ? ["add", ...dependencies]
140
+ : packageManager === "pnpm"
141
+ ? ["add", ...dependencies]
142
+ : ["install", ...dependencies];
143
+
144
+ await new Promise<void>((resolve, reject) => {
145
+ const proc = spawn(installCmd, installArgs, {
146
+ cwd,
147
+ stdio: "inherit",
148
+ shell: true,
149
+ });
150
+
151
+ proc.on("close", (code) => {
152
+ if (code === 0) {
153
+ console.log(chalk.green(`✓ Dependencies installed successfully`));
154
+ resolve();
155
+ } else {
156
+ console.warn(
157
+ chalk.yellow(
158
+ `⚠ Failed to install dependencies. Please run: ${installCmd} ${installArgs.join(
159
+ " "
160
+ )}`
161
+ )
162
+ );
163
+ resolve(); // Don't reject, just warn
164
+ }
165
+ });
166
+
167
+ proc.on("error", (err) => {
168
+ console.warn(
169
+ chalk.yellow(
170
+ `⚠ Could not install dependencies automatically: ${err.message}`
171
+ )
172
+ );
173
+ console.log(
174
+ chalk.blue(
175
+ `Please run manually: ${installCmd} ${installArgs.join(" ")}`
176
+ )
177
+ );
178
+ resolve(); // Don't reject, just warn
179
+ });
180
+ });
181
+ }
182
+
183
+ // For Expo projects, create utils/cn.ts
184
+ if (adapter === "expo") {
185
+ try {
186
+ const utilsDir = path.join(cwd, "utils");
187
+ await fs.mkdir(utilsDir, { recursive: true });
188
+
189
+ const utilsPath = path.join(utilsDir, "cn.ts");
190
+ const utilsContent = `import { StyleSheet } from "react-native";
191
+
192
+ /**
193
+ * A utility to merge React Native styles.
194
+ */
195
+ export function cn(...inputs: any[]) {
196
+ return StyleSheet.flatten(inputs.filter(Boolean));
197
+ }
198
+ `;
199
+ await fs.writeFile(utilsPath, utilsContent, "utf8");
200
+ console.log(chalk.green(`✓ Created utils/cn.ts`));
201
+ } catch (err) {
202
+ console.warn(chalk.yellow("Could not create utils/cn.ts:"), err);
203
+ }
204
+ }
205
+
206
+ // For Flutter projects, create lib/utils.dart
207
+ if (adapter === "flutter") {
208
+ try {
209
+ const libDir = path.join(cwd, "lib");
210
+ await fs.mkdir(libDir, { recursive: true });
211
+
212
+ const utilsPath = path.join(libDir, "utils.dart");
213
+ const utilsContent = `import 'package:flutter/material.dart';
214
+
215
+ class GetLotUIUtils {
216
+ static TextStyle cnText(List<TextStyle?> styles) {
217
+ TextStyle result = const TextStyle();
218
+ for (var style in styles) {
219
+ if (style != null) {
220
+ result = result.merge(style);
221
+ }
222
+ }
223
+ return result;
224
+ }
225
+ }
226
+ `;
227
+ await fs.writeFile(utilsPath, utilsContent, "utf8");
228
+ console.log(chalk.green(`✓ Created lib/utils.dart`));
229
+ } catch (err) {
230
+ console.warn(chalk.yellow("Could not create lib/utils.dart:"), err);
231
+ }
232
+ }
233
+
100
234
  console.log(
101
235
  chalk.green(
102
- `Created getlotui.config.json with ${adapter} (${packageManager}) defaults.`
236
+ `\n✨ GetLotUI initialized with ${adapter} (${packageManager}) defaults.`
103
237
  )
104
238
  );
239
+ console.log(chalk.blue(`\n📚 Next steps:`));
240
+ console.log(chalk.white(` 1. Run: getlotui add <component>`));
241
+ console.log(chalk.white(` 2. Import and use components in your app`));
105
242
  } catch (err) {
106
243
  console.error(chalk.red("Failed to initialize GetLotUI config:"), err);
107
244
  }
@@ -1 +1 @@
1
- {"version":2,"entries":[{"package":"crossui_flutter","rootUri":"../","packageUri":"lib/"}]}
1
+ {"version":2,"entries":[{"package":"getlotui_flutter","rootUri":"../","packageUri":"lib/"}]}