wlmaker 1.7.0 → 1.8.1

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.
@@ -0,0 +1,221 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ findMonorepoRoot
4
+ } from "./chunk-V4S7DQDN.mjs";
5
+
6
+ // src/shared/barrel.ts
7
+ import * as fs from "fs";
8
+ import * as path from "path";
9
+ function updateBarrelFile(parentDir, name) {
10
+ const barrelPath = path.join(parentDir, "bloc.dart");
11
+ const exportLine = `export '${name}/${name}_bloc.dart';`;
12
+ if (fs.existsSync(barrelPath)) {
13
+ const content = fs.readFileSync(barrelPath, "utf8");
14
+ if (content.includes(exportLine)) {
15
+ return;
16
+ }
17
+ fs.writeFileSync(barrelPath, content.trimEnd() + "\n" + exportLine + "\n");
18
+ } else {
19
+ fs.writeFileSync(barrelPath, exportLine + "\n");
20
+ }
21
+ }
22
+ function updateSortedBarrelFile(tierDir, barrelFileName, exportLine) {
23
+ const barrelPath = path.join(tierDir, barrelFileName);
24
+ let lines = [];
25
+ if (fs.existsSync(barrelPath)) {
26
+ const content = fs.readFileSync(barrelPath, "utf8");
27
+ lines = content.split("\n").filter((l) => l.trim().length > 0);
28
+ }
29
+ if (lines.includes(exportLine)) {
30
+ return;
31
+ }
32
+ lines.push(exportLine);
33
+ lines.sort();
34
+ fs.writeFileSync(barrelPath, lines.join("\n") + "\n");
35
+ }
36
+
37
+ // src/dart/builder.ts
38
+ import { spawn, execSync, exec } from "child_process";
39
+ import * as fs2 from "fs";
40
+ import * as path2 from "path";
41
+ function findPubspecDir(startDir) {
42
+ let dir = startDir;
43
+ while (dir !== path2.dirname(dir)) {
44
+ if (fs2.existsSync(path2.join(dir, "pubspec.yaml"))) {
45
+ return dir;
46
+ }
47
+ dir = path2.dirname(dir);
48
+ }
49
+ return void 0;
50
+ }
51
+ function hasBuildRunner(projectRoot) {
52
+ const pubspec = fs2.readFileSync(path2.join(projectRoot, "pubspec.yaml"), "utf8");
53
+ return /build_runner/.test(pubspec);
54
+ }
55
+ function runBuildRunner(projectRoot) {
56
+ return new Promise((resolve) => {
57
+ const child = spawn(
58
+ "dart",
59
+ ["run", "build_runner", "build", "--delete-conflicting-outputs"],
60
+ { cwd: projectRoot, stdio: "inherit" }
61
+ );
62
+ child.on("close", () => {
63
+ resolve();
64
+ });
65
+ child.on("error", () => {
66
+ resolve();
67
+ });
68
+ });
69
+ }
70
+ function dartFormat(filePath) {
71
+ try {
72
+ execSync(`dart format "${filePath}"`, { stdio: "pipe" });
73
+ return true;
74
+ } catch {
75
+ return false;
76
+ }
77
+ }
78
+ function dartFix(filePath) {
79
+ return new Promise((resolve) => {
80
+ exec(`dart fix --apply "${filePath}"`, (error) => {
81
+ resolve(!error);
82
+ });
83
+ });
84
+ }
85
+
86
+ // src/generators/widget/tier.ts
87
+ var VALID_TIERS = ["atom", "molecule", "organism", "template"];
88
+ var TIER_PATTERNS = {
89
+ atom: ["single-public", "single-factory"],
90
+ molecule: ["single", "subdirectory-parts", "subdirectory-widgets"],
91
+ organism: ["subdirectory-show", "single"],
92
+ template: ["simple"]
93
+ };
94
+ var TIER_PLURAL = {
95
+ atom: "atoms",
96
+ molecule: "molecules",
97
+ organism: "organisms",
98
+ template: "templates"
99
+ };
100
+ var TIER_LABELS = {
101
+ atom: "Atom",
102
+ molecule: "Molecule",
103
+ organism: "Organism",
104
+ template: "Template"
105
+ };
106
+ var PATTERN_LABELS = {
107
+ "single-public": "Single file, public constructor",
108
+ "single-factory": "Single file, private constructor + factories",
109
+ "subdirectory-parts": "Subdirectory with part files",
110
+ single: "Single file",
111
+ "subdirectory-widgets": "Subdirectory with widgets/ and utils/",
112
+ "subdirectory-show": "Subdirectory with factories + variant/i18n/skeleton parts",
113
+ simple: "Template simple (i18n + skeleton)"
114
+ };
115
+ function normalizeTier(input) {
116
+ const normalized = input.toLowerCase().replace(/s$/, "");
117
+ if (VALID_TIERS.includes(normalized)) {
118
+ return normalized;
119
+ }
120
+ throw new Error(
121
+ `Invalid tier "${input}". Valid tiers: ${VALID_TIERS.join(", ")}`
122
+ );
123
+ }
124
+ function tierPlural(tier) {
125
+ return TIER_PLURAL[tier];
126
+ }
127
+ function tierLabel(tier) {
128
+ return TIER_LABELS[tier];
129
+ }
130
+ function getValidPatterns(tier) {
131
+ return TIER_PATTERNS[tier];
132
+ }
133
+ function getDefaultPattern(tier) {
134
+ return TIER_PATTERNS[tier][0];
135
+ }
136
+ function patternLabel(pattern) {
137
+ return PATTERN_LABELS[pattern] ?? pattern;
138
+ }
139
+
140
+ // src/analyzer/design-system.ts
141
+ import * as fs3 from "fs";
142
+ import * as path3 from "path";
143
+ function detectDesignSystem(projectRoot) {
144
+ const monorepoRoot = findMonorepoRoot(projectRoot);
145
+ if (monorepoRoot) {
146
+ const dsDir = path3.join(
147
+ monorepoRoot,
148
+ "packages",
149
+ "design_system",
150
+ "lib",
151
+ "wl_design_system"
152
+ );
153
+ if (fs3.existsSync(dsDir)) {
154
+ const widgetbookDir = path3.join(monorepoRoot, "apps", "widgetbook");
155
+ return {
156
+ componentsDir: dsDir,
157
+ widgetbookDir: fs3.existsSync(widgetbookDir) ? widgetbookDir : void 0,
158
+ availableTiers: discoverTiers(dsDir)
159
+ };
160
+ }
161
+ }
162
+ const standaloneDir = path3.join(projectRoot, "lib", "wl_design_system");
163
+ if (fs3.existsSync(standaloneDir)) {
164
+ const widgetbookDir = path3.join(
165
+ path3.dirname(projectRoot),
166
+ "widgetbook"
167
+ );
168
+ return {
169
+ componentsDir: standaloneDir,
170
+ widgetbookDir: fs3.existsSync(widgetbookDir) ? widgetbookDir : void 0,
171
+ availableTiers: discoverTiers(standaloneDir)
172
+ };
173
+ }
174
+ return null;
175
+ }
176
+ function discoverTiers(componentsDir) {
177
+ const tiers = [];
178
+ const tierSet = new Set(VALID_TIERS.map((t) => tierPlural(t)));
179
+ try {
180
+ const entries = fs3.readdirSync(componentsDir, { withFileTypes: true });
181
+ for (const entry of entries) {
182
+ if (entry.isDirectory() && tierSet.has(entry.name)) {
183
+ tiers.push(entry.name);
184
+ }
185
+ }
186
+ } catch {
187
+ }
188
+ return tiers;
189
+ }
190
+ function widgetExists(componentsDir, tierPluralName, widgetName) {
191
+ const tierDir = path3.join(componentsDir, tierPluralName);
192
+ const flatFile = path3.join(tierDir, `${widgetName}.dart`);
193
+ if (fs3.existsSync(flatFile)) return true;
194
+ const subDir = path3.join(tierDir, widgetName);
195
+ if (fs3.existsSync(subDir)) return true;
196
+ const bareName = widgetName.startsWith("wl_") ? widgetName.slice(3) : widgetName;
197
+ if (bareName !== widgetName) {
198
+ const bareSubDir = path3.join(tierDir, bareName);
199
+ if (fs3.existsSync(bareSubDir)) return true;
200
+ }
201
+ return false;
202
+ }
203
+
204
+ export {
205
+ updateBarrelFile,
206
+ updateSortedBarrelFile,
207
+ findPubspecDir,
208
+ hasBuildRunner,
209
+ runBuildRunner,
210
+ dartFormat,
211
+ dartFix,
212
+ VALID_TIERS,
213
+ normalizeTier,
214
+ tierPlural,
215
+ tierLabel,
216
+ getValidPatterns,
217
+ getDefaultPattern,
218
+ patternLabel,
219
+ detectDesignSystem,
220
+ widgetExists
221
+ };