wlmaker 1.0.1 → 1.1.0

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/dist/cli.mjs +118 -9
  2. package/package.json +1 -1
package/dist/cli.mjs CHANGED
@@ -144,6 +144,8 @@ async function createBloc(name, options) {
144
144
  }
145
145
 
146
146
  // src/interactive.ts
147
+ import * as fs5 from "fs";
148
+ import * as os from "os";
147
149
  import * as path5 from "path";
148
150
  import * as clack from "@clack/prompts";
149
151
  import chalk2 from "chalk";
@@ -187,20 +189,124 @@ function discoverFeatures(projectRoot) {
187
189
  if (!fs4.existsSync(featuresDir)) return [];
188
190
  return fs4.readdirSync(featuresDir, { withFileTypes: true }).filter((d) => d.isDirectory()).map((d) => d.name).sort();
189
191
  }
192
+ function findMonorepoRoot(startDir) {
193
+ let dir = startDir;
194
+ while (dir !== path4.dirname(dir)) {
195
+ if (fs4.existsSync(path4.join(dir, "melos.yaml"))) {
196
+ return dir;
197
+ }
198
+ dir = path4.dirname(dir);
199
+ }
200
+ return void 0;
201
+ }
202
+ function discoverPackages(monorepoRoot) {
203
+ const packageDirs = ["packages", "packages/features"];
204
+ const projects = [];
205
+ for (const base of packageDirs) {
206
+ const baseDir = path4.join(monorepoRoot, base);
207
+ if (!fs4.existsSync(baseDir)) continue;
208
+ const entries = fs4.readdirSync(baseDir, { withFileTypes: true });
209
+ for (const entry of entries) {
210
+ if (!entry.isDirectory()) continue;
211
+ const candidate = path4.join(baseDir, entry.name);
212
+ if (!fs4.existsSync(path4.join(candidate, "pubspec.yaml"))) continue;
213
+ const project = analyzeProject(candidate);
214
+ if (project && (project.hasFreezed || project.hasBloc)) {
215
+ projects.push(project);
216
+ }
217
+ }
218
+ }
219
+ return projects.sort((a, b) => a.projectName.localeCompare(b.projectName));
220
+ }
221
+ var IGNORED_DIRS = /* @__PURE__ */ new Set([
222
+ "node_modules",
223
+ ".dart_tool",
224
+ "build",
225
+ ".git",
226
+ ".idea",
227
+ ".fvm",
228
+ "coverage"
229
+ ]);
230
+ function discoverProjects(searchDir, maxDepth = 2) {
231
+ const projects = [];
232
+ function walk(dir, depth) {
233
+ if (depth > maxDepth) return;
234
+ const project = analyzeProject(dir);
235
+ if (project && (project.hasFreezed || project.hasBloc)) {
236
+ projects.push(project);
237
+ return;
238
+ }
239
+ if (!fs4.existsSync(dir)) return;
240
+ let entries;
241
+ try {
242
+ entries = fs4.readdirSync(dir, { withFileTypes: true });
243
+ } catch {
244
+ return;
245
+ }
246
+ for (const entry of entries) {
247
+ if (!entry.isDirectory() || IGNORED_DIRS.has(entry.name)) continue;
248
+ walk(path4.join(dir, entry.name), depth + 1);
249
+ }
250
+ }
251
+ walk(searchDir, 0);
252
+ return projects.sort((a, b) => a.projectName.localeCompare(b.projectName));
253
+ }
190
254
 
191
255
  // src/interactive.ts
192
256
  var SNAKE_CASE_REGEX2 = /^[a-z][a-z0-9_]*$/;
193
- async function interactiveMode() {
194
- clack.intro(chalk2.bgCyan(chalk2.black(" wlmaker ")));
257
+ async function resolveProject() {
195
258
  const s = clack.spinner();
196
- s.start("Analyzing Flutter project...");
197
- const project = analyzeProject(process.cwd());
198
- if (!project) {
199
- s.stop("No Flutter project found");
200
- clack.outro(chalk2.red("Could not find a pubspec.yaml in the current directory or any parent."));
201
- return;
259
+ s.start("Analyzing current directory...");
260
+ const cwdProject = analyzeProject(process.cwd());
261
+ if (cwdProject && (cwdProject.hasFreezed || cwdProject.hasBloc)) {
262
+ s.stop(`Found ${chalk2.green(cwdProject.projectName)}`);
263
+ return cwdProject;
264
+ }
265
+ s.message("Looking for Melos monorepo...");
266
+ const monorepoRoot = findMonorepoRoot(process.cwd());
267
+ if (monorepoRoot) {
268
+ const packages = discoverPackages(monorepoRoot);
269
+ if (packages.length > 0) {
270
+ s.stop(`Found monorepo with ${packages.length} feature package(s)`);
271
+ return selectPackage(packages);
272
+ }
273
+ }
274
+ s.message("Scanning for Flutter projects...");
275
+ const homeDev = path5.join(os.homedir(), "Development");
276
+ if (fs5.existsSync(homeDev)) {
277
+ const projects = discoverProjects(homeDev, 2);
278
+ if (projects.length > 0) {
279
+ s.stop(`Found ${projects.length} Flutter project(s)`);
280
+ return selectPackage(projects);
281
+ }
202
282
  }
203
- s.stop(`Found ${chalk2.green(project.projectName)} \u2014 ${project.features.length} feature(s) detected`);
283
+ s.stop("No Flutter projects found");
284
+ clack.outro(chalk2.red("Could not find any Flutter project with freezed or flutter_bloc."));
285
+ return null;
286
+ }
287
+ async function selectPackage(projects) {
288
+ if (projects.length === 1) {
289
+ clack.log.info(`Using ${chalk2.green(projects[0].projectName)}`);
290
+ return projects[0];
291
+ }
292
+ const selected = await clack.select({
293
+ message: "Select a package",
294
+ options: projects.map((p) => ({
295
+ value: p,
296
+ label: p.projectName,
297
+ hint: path5.relative(os.homedir(), p.projectRoot)
298
+ }))
299
+ });
300
+ if (clack.isCancel(selected)) {
301
+ clack.cancel("Cancelled");
302
+ return null;
303
+ }
304
+ return selected;
305
+ }
306
+ async function interactiveMode() {
307
+ clack.intro(chalk2.bgCyan(chalk2.black(" wlmaker ")));
308
+ const project = await resolveProject();
309
+ if (!project) return;
204
310
  const name = await clack.text({
205
311
  message: "BLoC name (snake_case)",
206
312
  placeholder: "e.g. user_login",
@@ -242,6 +348,9 @@ async function interactiveMode() {
242
348
  } else {
243
349
  targetDir = path5.join(project.projectRoot, "lib", "features", feature);
244
350
  }
351
+ } else if (fs5.existsSync(path5.join(project.projectRoot, "lib", "bloc"))) {
352
+ targetDir = path5.join(project.projectRoot, "lib", "bloc");
353
+ clack.log.info(`Target: ${chalk2.cyan("lib/bloc/")}`);
245
354
  } else {
246
355
  clack.note("No lib/features/ directory found. Provide a target path manually.", "Info");
247
356
  const customPath = await clack.text({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wlmaker",
3
- "version": "1.0.1",
3
+ "version": "1.1.0",
4
4
  "description": "Create Flutter BLoCs with Freezed sealed classes from the terminal",
5
5
  "keywords": [
6
6
  "flutter",