@snap/valdi 1.0.11 → 1.1.7

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 (74) hide show
  1. package/.metadata/.bazelrc.template +7 -6
  2. package/.metadata/MODULE.bazel.template +154 -0
  3. package/bundled-skills/registry.json +13 -2
  4. package/bundled-skills/skills/valdi-animations/skill.md +197 -0
  5. package/bundled-skills/skills/valdi-async/tests/src/reference.tsx +1 -1
  6. package/bundled-skills/skills/valdi-compiler/skill.md +4 -4
  7. package/bundled-skills/skills/valdi-component-dedup/skill.md +263 -0
  8. package/bundled-skills/skills/valdi-component-tests/tests/test/ProfileCardTest.spec.tsx +1 -1
  9. package/bundled-skills/skills/valdi-custom-view/skill.md +43 -1
  10. package/bundled-skills/skills/valdi-error-handling/skill.md +238 -0
  11. package/bundled-skills/skills/valdi-gestures/skill.md +198 -0
  12. package/bundled-skills/skills/valdi-inspect/skill.md +19 -1
  13. package/bundled-skills/skills/valdi-localization/skill.md +142 -0
  14. package/bundled-skills/skills/valdi-mock-breakdown/skill.md +327 -0
  15. package/bundled-skills/skills/valdi-mock-iterate/skill.md +216 -0
  16. package/bundled-skills/skills/valdi-mock-to-module/scripts/diff.py +392 -0
  17. package/bundled-skills/skills/valdi-mock-to-module/scripts/extract_colors.py +277 -0
  18. package/bundled-skills/skills/valdi-mock-to-module/scripts/find_icon.py +303 -0
  19. package/bundled-skills/skills/valdi-mock-to-module/scripts/snapshot-and-diff.sh +53 -0
  20. package/bundled-skills/skills/valdi-mock-to-module/scripts/test_diff.py +207 -0
  21. package/bundled-skills/skills/valdi-mock-to-module/scripts/test_extract_colors.py +167 -0
  22. package/bundled-skills/skills/valdi-mock-to-module/scripts/test_find_icon.py +188 -0
  23. package/bundled-skills/skills/valdi-mock-to-module/scripts/watch-and-diff.sh +181 -0
  24. package/bundled-skills/skills/valdi-mock-to-module/skill.md +451 -0
  25. package/bundled-skills/skills/valdi-navigation/skill.md +187 -0
  26. package/bundled-skills/skills/valdi-overview/skill.md +7 -4
  27. package/bundled-skills/skills/valdi-perf/skill.md +223 -0
  28. package/bundled-skills/skills/valdi-polyglot-module/skill.md +80 -0
  29. package/bundled-skills/skills/valdi-preview/skill.md +303 -0
  30. package/bundled-skills/skills/valdi-setup/skill.md +55 -5
  31. package/bundled-skills/skills/valdi-testing/skill.md +23 -7
  32. package/bundled-skills/skills/valdi-tsx/skill.md +69 -5
  33. package/bundled-skills/skills/valdi-tsx/tests/src/reference.tsx +29 -5
  34. package/dist/commands/agentCheck.js +184 -0
  35. package/dist/commands/analyze.js +16 -0
  36. package/dist/commands/analyze_commands/duplicates.js +134 -0
  37. package/dist/commands/bootstrap.js +57 -73
  38. package/dist/commands/build.js +6 -0
  39. package/dist/commands/doctor.js +42 -266
  40. package/dist/commands/hotreload.js +15 -0
  41. package/dist/commands/inspect_commands/snapshot.js +71 -6
  42. package/dist/commands/inspect_commands/snapshot.spec.js +105 -0
  43. package/dist/commands/install.js +6 -0
  44. package/dist/commands/preview.js +81 -0
  45. package/dist/commands/projectsync.js +9 -7
  46. package/dist/commands/skills_commands/install.js +6 -1
  47. package/dist/commands/skills_commands/update.js +2 -1
  48. package/dist/core/analyze/clusterer.js +150 -0
  49. package/dist/core/analyze/fingerprint.js +2 -0
  50. package/dist/core/analyze/knownPatterns.js +76 -0
  51. package/dist/core/analyze/parser.js +177 -0
  52. package/dist/core/analyze/reporter.js +83 -0
  53. package/dist/core/analyze/scanner.js +172 -0
  54. package/dist/core/analyze/similarity.js +56 -0
  55. package/dist/core/constants.js +6 -3
  56. package/dist/core/packageFiles.spec.js +1 -1
  57. package/dist/preview/previewGenerator.js +240 -0
  58. package/dist/preview/previewGenerator.spec.js +203 -0
  59. package/dist/preview/viewModelParser.js +86 -0
  60. package/dist/preview/viewModelParser.spec.js +171 -0
  61. package/dist/setup/DevSetupHelper.js +0 -54
  62. package/dist/setup/linuxSetup.js +0 -16
  63. package/dist/setup/macOSSetup.js +1 -5
  64. package/dist/utils/BazelClient.js +15 -0
  65. package/dist/utils/applicationUtils.js +15 -0
  66. package/dist/utils/daemonClient.js +3 -1
  67. package/dist/utils/linuxDistro.js +0 -21
  68. package/dist/utils/linuxDistro.spec.js +0 -48
  69. package/dist/utils/skillsAdapters.js +126 -19
  70. package/dist/utils/skillsAdapters.spec.js +141 -0
  71. package/dist/utils/skillsRegistry.js +8 -0
  72. package/package.json +16 -8
  73. package/.metadata/WORKSPACE.template +0 -57
  74. package/dist/setup/versions.js +0 -8
@@ -0,0 +1,203 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ require("jasmine");
5
+ const fs = tslib_1.__importStar(require("fs"));
6
+ const os = tslib_1.__importStar(require("os"));
7
+ const path = tslib_1.__importStar(require("path"));
8
+ const previewGenerator_1 = require("./previewGenerator");
9
+ describe('previewGenerator', () => {
10
+ let tmpDir;
11
+ beforeEach(() => {
12
+ tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'pg-test-'));
13
+ });
14
+ afterEach(() => {
15
+ fs.rmSync(tmpDir, { recursive: true, force: true });
16
+ });
17
+ describe('getPreviewDir', () => {
18
+ it('returns apps/preview under workspace root', () => {
19
+ expect((0, previewGenerator_1.getPreviewDir)('/workspace')).toBe('/workspace/apps/preview');
20
+ });
21
+ });
22
+ describe('getModuleNameFromImport', () => {
23
+ it('extracts the first path segment', () => {
24
+ expect((0, previewGenerator_1.getModuleNameFromImport)('widgets/src/components/Button')).toBe('widgets');
25
+ expect((0, previewGenerator_1.getModuleNameFromImport)('coreui/src/Cell')).toBe('coreui');
26
+ expect((0, previewGenerator_1.getModuleNameFromImport)('mymod')).toBe('mymod');
27
+ });
28
+ });
29
+ describe('findModuleDir', () => {
30
+ it('walks up to find BUILD.bazel with valdi_module()', () => {
31
+ const modDir = path.join(tmpDir, 'mod');
32
+ const srcDir = path.join(modDir, 'src', 'components');
33
+ fs.mkdirSync(srcDir, { recursive: true });
34
+ fs.writeFileSync(path.join(modDir, 'BUILD.bazel'), `
35
+ valdi_module(
36
+ name = "mymod",
37
+ srcs = glob(["**/*.tsx"]),
38
+ )
39
+ `, 'utf8');
40
+ const componentFile = path.join(srcDir, 'Button.tsx');
41
+ fs.writeFileSync(componentFile, 'export class Button {}', 'utf8');
42
+ expect((0, previewGenerator_1.findModuleDir)(componentFile)).toBe(modDir);
43
+ });
44
+ it('skips BUILD.bazel files without valdi_module()', () => {
45
+ const parentDir = path.join(tmpDir, 'parent');
46
+ const childDir = path.join(parentDir, 'child');
47
+ fs.mkdirSync(childDir, { recursive: true });
48
+ fs.writeFileSync(path.join(childDir, 'BUILD.bazel'), 'cc_library(name = "lib")', 'utf8');
49
+ fs.writeFileSync(path.join(parentDir, 'BUILD.bazel'), 'valdi_module(name = "mod")', 'utf8');
50
+ const componentFile = path.join(childDir, 'Comp.tsx');
51
+ fs.writeFileSync(componentFile, '', 'utf8');
52
+ expect((0, previewGenerator_1.findModuleDir)(componentFile)).toBe(parentDir);
53
+ });
54
+ it('throws when no valdi_module BUILD is found', () => {
55
+ const isolatedDir = path.join(tmpDir, 'isolated');
56
+ fs.mkdirSync(isolatedDir, { recursive: true });
57
+ const componentFile = path.join(isolatedDir, 'Comp.tsx');
58
+ fs.writeFileSync(componentFile, '', 'utf8');
59
+ expect(() => (0, previewGenerator_1.findModuleDir)(componentFile)).toThrowError(/Could not find a BUILD.bazel/);
60
+ });
61
+ });
62
+ describe('readModuleName', () => {
63
+ it('extracts module name from BUILD.bazel', () => {
64
+ const modDir = path.join(tmpDir, 'mymod');
65
+ fs.mkdirSync(modDir, { recursive: true });
66
+ fs.writeFileSync(path.join(modDir, 'BUILD.bazel'), `
67
+ load("@valdi//bzl:valdi.bzl", "valdi_module")
68
+ valdi_module(
69
+ name = "widgets",
70
+ srcs = glob(["**/*.tsx"]),
71
+ )
72
+ `, 'utf8');
73
+ expect((0, previewGenerator_1.readModuleName)(modDir)).toBe('widgets');
74
+ });
75
+ it('throws when no valdi_module name found', () => {
76
+ const modDir = path.join(tmpDir, 'bad');
77
+ fs.mkdirSync(modDir, { recursive: true });
78
+ fs.writeFileSync(path.join(modDir, 'BUILD.bazel'), 'cc_library(name = "lib")', 'utf8');
79
+ expect(() => (0, previewGenerator_1.readModuleName)(modDir)).toThrowError(/Could not find valdi_module name/);
80
+ });
81
+ });
82
+ describe('isValdiWorkspace', () => {
83
+ it('returns true for workspace named "valdi"', () => {
84
+ fs.writeFileSync(path.join(tmpDir, 'WORKSPACE'), 'workspace(name = "valdi")\n', 'utf8');
85
+ expect((0, previewGenerator_1.isValdiWorkspace)(tmpDir)).toBe(true);
86
+ });
87
+ it('returns false for other workspace names', () => {
88
+ fs.writeFileSync(path.join(tmpDir, 'WORKSPACE'), 'workspace(name = "my_app")\n', 'utf8');
89
+ expect((0, previewGenerator_1.isValdiWorkspace)(tmpDir)).toBe(false);
90
+ });
91
+ it('returns false when no WORKSPACE file exists', () => {
92
+ expect((0, previewGenerator_1.isValdiWorkspace)(tmpDir)).toBe(false);
93
+ });
94
+ });
95
+ describe('computeModuleLabel', () => {
96
+ it('computes a Bazel label from module dir', () => {
97
+ const modDir = path.join(tmpDir, 'src', 'widgets');
98
+ fs.mkdirSync(modDir, { recursive: true });
99
+ fs.writeFileSync(path.join(modDir, 'BUILD.bazel'), 'valdi_module(name = "widgets")', 'utf8');
100
+ expect((0, previewGenerator_1.computeModuleLabel)(modDir, tmpDir)).toBe('//src/widgets:widgets');
101
+ });
102
+ });
103
+ describe('generatePreviewFiles', () => {
104
+ it('generates PreviewRoot.tsx, BUILD.bazel, and tsconfig.json', () => {
105
+ const modDir = path.join(tmpDir, 'src', 'widgets');
106
+ fs.mkdirSync(modDir, { recursive: true });
107
+ fs.writeFileSync(path.join(modDir, 'BUILD.bazel'), 'valdi_module(name = "widgets")', 'utf8');
108
+ fs.writeFileSync(path.join(tmpDir, 'WORKSPACE'), 'workspace(name = "my_app")', 'utf8');
109
+ const configDir = path.join(tmpDir, 'valdi_modules', '_configs');
110
+ fs.mkdirSync(configDir, { recursive: true });
111
+ fs.writeFileSync(path.join(configDir, 'base.tsconfig.json'), '{}', 'utf8');
112
+ const config = {
113
+ componentFilePath: path.join(modDir, 'src', 'Button.tsx'),
114
+ importPath: 'widgets/src/Button',
115
+ moduleLabel: '//src/widgets:widgets',
116
+ workspaceRoot: tmpDir,
117
+ isValdiRepo: false,
118
+ viewModel: {
119
+ componentName: 'Button',
120
+ viewModelName: 'ButtonViewModel',
121
+ props: [
122
+ { name: 'label', typeString: 'string', optional: false, isBoolean: false, isCallback: false, callbackParamType: undefined },
123
+ { name: 'onTap', typeString: '() => void', optional: false, isBoolean: false, isCallback: true, callbackParamType: undefined },
124
+ ],
125
+ extraImports: [],
126
+ },
127
+ };
128
+ (0, previewGenerator_1.generatePreviewFiles)(config);
129
+ const previewDir = (0, previewGenerator_1.getPreviewDir)(tmpDir);
130
+ expect(fs.existsSync(path.join(previewDir, 'PreviewRoot.tsx'))).toBe(true);
131
+ expect(fs.existsSync(path.join(previewDir, 'BUILD.bazel'))).toBe(true);
132
+ expect(fs.existsSync(path.join(previewDir, 'tsconfig.json'))).toBe(true);
133
+ const previewTsx = fs.readFileSync(path.join(previewDir, 'PreviewRoot.tsx'), 'utf8');
134
+ expect(previewTsx).toContain("import { Button } from 'widgets/src/Button'");
135
+ expect(previewTsx).toContain('<Button');
136
+ expect(previewTsx).toContain("label={'Sample'}");
137
+ expect(previewTsx).toContain('onTap={() => {}}');
138
+ const buildBazel = fs.readFileSync(path.join(previewDir, 'BUILD.bazel'), 'utf8');
139
+ expect(buildBazel).toContain('@valdi//bzl/valdi:valdi_application.bzl');
140
+ expect(buildBazel).toContain('//src/widgets:widgets');
141
+ expect(buildBazel).toContain('root_component_path = "PreviewRoot@preview/PreviewRoot"');
142
+ const tsconfig = JSON.parse(fs.readFileSync(path.join(previewDir, 'tsconfig.json'), 'utf8'));
143
+ expect(tsconfig.compilerOptions.paths['preview/*']).toEqual(['./*']);
144
+ });
145
+ it('generates StatefulComponent when interactive state is detected', () => {
146
+ const modDir = path.join(tmpDir, 'src', 'widgets');
147
+ fs.mkdirSync(modDir, { recursive: true });
148
+ fs.writeFileSync(path.join(modDir, 'BUILD.bazel'), 'valdi_module(name = "widgets")', 'utf8');
149
+ fs.writeFileSync(path.join(tmpDir, 'WORKSPACE'), 'workspace(name = "other")', 'utf8');
150
+ const configDir = path.join(tmpDir, 'valdi_modules', '_configs');
151
+ fs.mkdirSync(configDir, { recursive: true });
152
+ fs.writeFileSync(path.join(configDir, 'base.tsconfig.json'), '{}', 'utf8');
153
+ const config = {
154
+ componentFilePath: path.join(modDir, 'src', 'Toggle.tsx'),
155
+ importPath: 'widgets/src/Toggle',
156
+ moduleLabel: '//src/widgets:widgets',
157
+ workspaceRoot: tmpDir,
158
+ isValdiRepo: false,
159
+ viewModel: {
160
+ componentName: 'Toggle',
161
+ viewModelName: 'ToggleVM',
162
+ props: [
163
+ { name: 'checked', typeString: 'boolean', optional: false, isBoolean: true, isCallback: false, callbackParamType: undefined },
164
+ { name: 'onToggle', typeString: '(val: boolean) => void', optional: false, isBoolean: false, isCallback: true, callbackParamType: 'boolean' },
165
+ ],
166
+ extraImports: [],
167
+ },
168
+ };
169
+ (0, previewGenerator_1.generatePreviewFiles)(config);
170
+ const previewTsx = fs.readFileSync(path.join((0, previewGenerator_1.getPreviewDir)(tmpDir), 'PreviewRoot.tsx'), 'utf8');
171
+ expect(previewTsx).toContain('StatefulComponent');
172
+ expect(previewTsx).toContain('state: PreviewState');
173
+ expect(previewTsx).toContain('this.state.checked');
174
+ expect(previewTsx).toContain('this.setState');
175
+ });
176
+ it('uses // prefix for Valdi repo BUILD.bazel', () => {
177
+ const modDir = path.join(tmpDir, 'src', 'widgets');
178
+ fs.mkdirSync(modDir, { recursive: true });
179
+ fs.writeFileSync(path.join(modDir, 'BUILD.bazel'), 'valdi_module(name = "widgets")', 'utf8');
180
+ fs.writeFileSync(path.join(tmpDir, 'WORKSPACE'), 'workspace(name = "valdi")', 'utf8');
181
+ const configDir = path.join(tmpDir, 'modules', '_configs');
182
+ fs.mkdirSync(configDir, { recursive: true });
183
+ fs.writeFileSync(path.join(configDir, 'base.tsconfig.json'), '{}', 'utf8');
184
+ const config = {
185
+ componentFilePath: path.join(modDir, 'src', 'Button.tsx'),
186
+ importPath: 'widgets/src/Button',
187
+ moduleLabel: '//src/widgets:widgets',
188
+ workspaceRoot: tmpDir,
189
+ isValdiRepo: true,
190
+ viewModel: {
191
+ componentName: 'Button',
192
+ viewModelName: 'ButtonVM',
193
+ props: [],
194
+ extraImports: [],
195
+ },
196
+ };
197
+ (0, previewGenerator_1.generatePreviewFiles)(config);
198
+ const buildBazel = fs.readFileSync(path.join((0, previewGenerator_1.getPreviewDir)(tmpDir), 'BUILD.bazel'), 'utf8');
199
+ expect(buildBazel).toContain('load("//bzl/valdi:valdi_application.bzl"');
200
+ expect(buildBazel).not.toContain('@valdi');
201
+ });
202
+ });
203
+ });
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseComponentFile = parseComponentFile;
4
+ exports.detectInteractiveState = detectInteractiveState;
5
+ exports.sampleValueForType = sampleValueForType;
6
+ const tslib_1 = require("tslib");
7
+ const fs_1 = tslib_1.__importDefault(require("fs"));
8
+ function parseComponentFile(filePath) {
9
+ const source = fs_1.default.readFileSync(filePath, 'utf8');
10
+ const classMatch = source.match(/export\s+class\s+(\w+)\s+extends\s+(?:Stateful)?Component<(\w+)/);
11
+ if (!classMatch) {
12
+ throw new Error(`Could not find an exported Component class in ${filePath}`);
13
+ }
14
+ const componentName = classMatch[1];
15
+ const viewModelName = classMatch[2];
16
+ const ifaceRegex = new RegExp(`(?:export\\s+)?interface\\s+${escapeRegex(viewModelName)}\\s*\\{([^}]*)\\}`, 's');
17
+ const ifaceMatch = source.match(ifaceRegex);
18
+ if (!ifaceMatch) {
19
+ throw new Error(`Could not find interface ${viewModelName} in ${filePath}`);
20
+ }
21
+ const body = ifaceMatch[1];
22
+ const props = [];
23
+ const propRegex = /^\s*(\w+)(\??):\s*(.+?)\s*;/gm;
24
+ let m;
25
+ while ((m = propRegex.exec(body)) !== null) {
26
+ const name = m[1];
27
+ const optional = m[2] === '?';
28
+ const typeString = m[3].trim();
29
+ const isBoolean = typeString === 'boolean';
30
+ const isCallback = /=>/.test(typeString);
31
+ let callbackParamType;
32
+ if (isCallback) {
33
+ const cbMatch = typeString.match(/\(\s*\w+\s*:\s*(\w+)\s*\)\s*=>/);
34
+ if (cbMatch) {
35
+ callbackParamType = cbMatch[1];
36
+ }
37
+ }
38
+ props.push({ name: name, typeString: typeString, optional, isBoolean, isCallback, callbackParamType });
39
+ }
40
+ return { componentName: componentName, viewModelName: viewModelName, props, extraImports: [] };
41
+ }
42
+ function detectInteractiveState(props) {
43
+ const boolProps = props.filter(p => p.isBoolean && !p.optional);
44
+ const callbackProps = props.filter(p => p.isCallback && p.callbackParamType === 'boolean');
45
+ const pairs = [];
46
+ for (const bp of boolProps) {
47
+ const candidate = callbackProps.find(cp => {
48
+ const cpLower = cp.name.toLowerCase();
49
+ const bpLower = bp.name.toLowerCase();
50
+ if (['ontap', 'onpress', 'onchange', 'ontoggle'].includes(cpLower))
51
+ return true;
52
+ if (cpLower === `on${bpLower}`)
53
+ return true;
54
+ return false;
55
+ });
56
+ if (candidate) {
57
+ pairs.push({
58
+ stateName: bp.name,
59
+ boolPropName: bp.name,
60
+ callbackPropName: candidate.name,
61
+ });
62
+ }
63
+ }
64
+ return pairs;
65
+ }
66
+ function sampleValueForType(typeString) {
67
+ const t = typeString.trim();
68
+ if (t === 'boolean')
69
+ return 'false';
70
+ if (t === 'string')
71
+ return "'Sample'";
72
+ if (t === 'number')
73
+ return '42';
74
+ if (t === 'Date')
75
+ return 'new Date()';
76
+ if (/^\(\s*\)\s*=>/.test(t))
77
+ return '() => {}';
78
+ if (/=>/.test(t))
79
+ return '() => {}';
80
+ if (t.endsWith('[]') || t.startsWith('Array<'))
81
+ return '[]';
82
+ return 'undefined as any';
83
+ }
84
+ function escapeRegex(str) {
85
+ return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
86
+ }
@@ -0,0 +1,171 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ require("jasmine");
5
+ const fs = tslib_1.__importStar(require("fs"));
6
+ const os = tslib_1.__importStar(require("os"));
7
+ const path = tslib_1.__importStar(require("path"));
8
+ const viewModelParser_1 = require("./viewModelParser");
9
+ describe('viewModelParser', () => {
10
+ let tmpDir;
11
+ beforeEach(() => {
12
+ tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'vmp-test-'));
13
+ });
14
+ afterEach(() => {
15
+ fs.rmSync(tmpDir, { recursive: true, force: true });
16
+ });
17
+ function writeComponent(filename, content) {
18
+ const filePath = path.join(tmpDir, filename);
19
+ fs.writeFileSync(filePath, content, 'utf8');
20
+ return filePath;
21
+ }
22
+ describe('parseComponentFile', () => {
23
+ it('parses a simple Component with ViewModel', () => {
24
+ const filePath = writeComponent('Simple.tsx', `
25
+ import { Component } from 'valdi_core/src/Component';
26
+
27
+ export interface SimpleViewModel {
28
+ title: string;
29
+ count: number;
30
+ enabled: boolean;
31
+ }
32
+
33
+ export class Simple extends Component<SimpleViewModel, {}> {
34
+ onRender(): void {}
35
+ }
36
+ `);
37
+ const result = (0, viewModelParser_1.parseComponentFile)(filePath);
38
+ expect(result.componentName).toBe('Simple');
39
+ expect(result.viewModelName).toBe('SimpleViewModel');
40
+ expect(result.props.length).toBe(3);
41
+ expect(result.props[0].name).toBe('title');
42
+ expect(result.props[0].typeString).toBe('string');
43
+ expect(result.props[0].optional).toBe(false);
44
+ expect(result.props[1].name).toBe('count');
45
+ expect(result.props[1].typeString).toBe('number');
46
+ expect(result.props[2].name).toBe('enabled');
47
+ expect(result.props[2].isBoolean).toBe(true);
48
+ });
49
+ it('parses optional props', () => {
50
+ const filePath = writeComponent('Optional.tsx', `
51
+ export interface OptViewModel {
52
+ label: string;
53
+ subtitle?: string;
54
+ icon?: number;
55
+ }
56
+ export class OptComponent extends Component<OptViewModel, {}> {
57
+ onRender(): void {}
58
+ }
59
+ `);
60
+ const result = (0, viewModelParser_1.parseComponentFile)(filePath);
61
+ expect(result.props.length).toBe(3);
62
+ expect(result.props[0].optional).toBe(false);
63
+ expect(result.props[1].optional).toBe(true);
64
+ expect(result.props[2].optional).toBe(true);
65
+ });
66
+ it('parses callback props', () => {
67
+ const filePath = writeComponent('Callback.tsx', `
68
+ export interface CbViewModel {
69
+ onTap: () => void;
70
+ onChange: (val: boolean) => void;
71
+ onSelect: (item: string) => void;
72
+ }
73
+ export class CbComponent extends Component<CbViewModel, {}> {
74
+ onRender(): void {}
75
+ }
76
+ `);
77
+ const result = (0, viewModelParser_1.parseComponentFile)(filePath);
78
+ expect(result.props.length).toBe(3);
79
+ expect(result.props[0].isCallback).toBe(true);
80
+ expect(result.props[0].callbackParamType).toBeUndefined();
81
+ expect(result.props[1].isCallback).toBe(true);
82
+ expect(result.props[1].callbackParamType).toBe('boolean');
83
+ expect(result.props[2].isCallback).toBe(true);
84
+ expect(result.props[2].callbackParamType).toBe('string');
85
+ });
86
+ it('parses StatefulComponent', () => {
87
+ const filePath = writeComponent('Stateful.tsx', `
88
+ export interface StatefulVM {
89
+ checked: boolean;
90
+ }
91
+ export class MyStateful extends StatefulComponent<StatefulVM> {
92
+ onRender(): void {}
93
+ }
94
+ `);
95
+ const result = (0, viewModelParser_1.parseComponentFile)(filePath);
96
+ expect(result.componentName).toBe('MyStateful');
97
+ expect(result.viewModelName).toBe('StatefulVM');
98
+ });
99
+ it('throws when no Component class is found', () => {
100
+ const filePath = writeComponent('NoClass.tsx', `
101
+ export interface SomeViewModel { title: string; }
102
+ `);
103
+ expect(() => (0, viewModelParser_1.parseComponentFile)(filePath)).toThrowError(/Could not find an exported Component class/);
104
+ });
105
+ it('throws when ViewModel interface is missing', () => {
106
+ const filePath = writeComponent('NoVM.tsx', `
107
+ export class Broken extends Component<MissingViewModel, {}> {
108
+ onRender(): void {}
109
+ }
110
+ `);
111
+ expect(() => (0, viewModelParser_1.parseComponentFile)(filePath)).toThrowError(/Could not find interface MissingViewModel/);
112
+ });
113
+ });
114
+ describe('detectInteractiveState', () => {
115
+ it('pairs boolean prop with onChange callback', () => {
116
+ const props = [
117
+ { name: 'on', typeString: 'boolean', optional: false, isBoolean: true, isCallback: false, callbackParamType: undefined },
118
+ { name: 'onChange', typeString: '(val: boolean) => void', optional: false, isBoolean: false, isCallback: true, callbackParamType: 'boolean' },
119
+ ];
120
+ const pairs = (0, viewModelParser_1.detectInteractiveState)(props);
121
+ expect(pairs.length).toBe(1);
122
+ expect(pairs[0].boolPropName).toBe('on');
123
+ expect(pairs[0].callbackPropName).toBe('onChange');
124
+ });
125
+ it('pairs boolean prop with onTap callback', () => {
126
+ const props = [
127
+ { name: 'selected', typeString: 'boolean', optional: false, isBoolean: true, isCallback: false, callbackParamType: undefined },
128
+ { name: 'onTap', typeString: '(val: boolean) => void', optional: false, isBoolean: false, isCallback: true, callbackParamType: 'boolean' },
129
+ ];
130
+ const pairs = (0, viewModelParser_1.detectInteractiveState)(props);
131
+ expect(pairs.length).toBe(1);
132
+ expect(pairs[0].boolPropName).toBe('selected');
133
+ expect(pairs[0].callbackPropName).toBe('onTap');
134
+ });
135
+ it('returns empty when no matching pair exists', () => {
136
+ const props = [
137
+ { name: 'title', typeString: 'string', optional: false, isBoolean: false, isCallback: false, callbackParamType: undefined },
138
+ { name: 'onTap', typeString: '() => void', optional: false, isBoolean: false, isCallback: true, callbackParamType: undefined },
139
+ ];
140
+ const pairs = (0, viewModelParser_1.detectInteractiveState)(props);
141
+ expect(pairs.length).toBe(0);
142
+ });
143
+ it('skips optional boolean props', () => {
144
+ const props = [
145
+ { name: 'checked', typeString: 'boolean', optional: true, isBoolean: true, isCallback: false, callbackParamType: undefined },
146
+ { name: 'onToggle', typeString: '(val: boolean) => void', optional: false, isBoolean: false, isCallback: true, callbackParamType: 'boolean' },
147
+ ];
148
+ const pairs = (0, viewModelParser_1.detectInteractiveState)(props);
149
+ expect(pairs.length).toBe(0);
150
+ });
151
+ });
152
+ describe('sampleValueForType', () => {
153
+ it('returns correct sample for primitive types', () => {
154
+ expect((0, viewModelParser_1.sampleValueForType)('boolean')).toBe('false');
155
+ expect((0, viewModelParser_1.sampleValueForType)('string')).toBe("'Sample'");
156
+ expect((0, viewModelParser_1.sampleValueForType)('number')).toBe('42');
157
+ expect((0, viewModelParser_1.sampleValueForType)('Date')).toBe('new Date()');
158
+ });
159
+ it('returns noop for function types', () => {
160
+ expect((0, viewModelParser_1.sampleValueForType)('() => void')).toBe('() => {}');
161
+ expect((0, viewModelParser_1.sampleValueForType)('(val: boolean) => void')).toBe('() => {}');
162
+ });
163
+ it('returns empty array for array types', () => {
164
+ expect((0, viewModelParser_1.sampleValueForType)('string[]')).toBe('[]');
165
+ expect((0, viewModelParser_1.sampleValueForType)('Array<number>')).toBe('[]');
166
+ });
167
+ it('falls back to undefined for unknown types', () => {
168
+ expect((0, viewModelParser_1.sampleValueForType)('SomeCustomType')).toBe('undefined as any');
169
+ });
170
+ });
171
+ });
@@ -8,20 +8,7 @@ const constants_1 = require("../core/constants");
8
8
  const LoadingIndicator_1 = require("../utils/LoadingIndicator");
9
9
  const cliUtils_1 = require("../utils/cliUtils");
10
10
  const logUtils_1 = require("../utils/logUtils");
11
- const tempDir_1 = require("../utils/tempDir");
12
- const zipUtils_1 = require("../utils/zipUtils");
13
- const versions_1 = require("./versions");
14
11
  exports.HOME_DIR = process.env['HOME'] ?? '';
15
- function getAndroidHomeDir() {
16
- const platform = process.platform;
17
- if (platform === 'darwin') {
18
- return path_1.default.join(exports.HOME_DIR, 'Library', 'Android', 'sdk');
19
- }
20
- else {
21
- return path_1.default.join(exports.HOME_DIR, 'Android', 'Sdk');
22
- }
23
- }
24
- const ANDROID_HOME_TARGET_DIR = getAndroidHomeDir();
25
12
  class DevSetupHelper {
26
13
  async download(url) {
27
14
  return new LoadingIndicator_1.LoadingIndicator(async () => {
@@ -106,9 +93,6 @@ class DevSetupHelper {
106
93
  console.log(' 3. Run `valdi doctor` to verify your setup');
107
94
  console.log(' 4. Create your first project with `valdi bootstrap`');
108
95
  }
109
- async setupGitLfs() {
110
- await this.runShell('Initializing git-lfs', ['git lfs install']);
111
- }
112
96
  async setupShellAutoComplete() {
113
97
  const rcFile = this.getRcFile();
114
98
  if (!rcFile) {
@@ -160,44 +144,6 @@ class DevSetupHelper {
160
144
  .setText((0, logUtils_1.wrapInColor)('Setting up shell autocomplete...', constants_1.ANSI_COLORS.YELLOW_COLOR))
161
145
  .show();
162
146
  }
163
- async setupAndroidSDK(commandLineToolsURL, javaHomeOverride) {
164
- console.log((0, logUtils_1.wrapInColor)('Setting up Android SDK...', constants_1.ANSI_COLORS.YELLOW_COLOR));
165
- if (!process.env['ANDROID_HOME']) {
166
- await (0, tempDir_1.withTempDir)(async (tempDir) => {
167
- const filename = path_1.default.join(tempDir, path_1.default.basename(commandLineToolsURL));
168
- await this.downloadToPath(commandLineToolsURL, filename);
169
- const targetDir = path_1.default.join(ANDROID_HOME_TARGET_DIR, 'cmdline-tools');
170
- await (0, zipUtils_1.decompressTo)(filename, targetDir);
171
- const target = path_1.default.join(targetDir, 'latest');
172
- if (fs_1.default.existsSync(target)) {
173
- await fs_1.default.promises.rm(target, { recursive: true, force: true });
174
- }
175
- fs_1.default.renameSync(path_1.default.join(targetDir, 'cmdline-tools'), target);
176
- });
177
- process.env['ANDROID_HOME'] = ANDROID_HOME_TARGET_DIR;
178
- const androidHomeValue = process.platform === 'darwin'
179
- ? '"$HOME/Library/Android/sdk"'
180
- : '"$HOME/Android/Sdk"';
181
- await this.writeEnvVariablesToRcFile([{ name: 'ANDROID_HOME', value: androidHomeValue }]);
182
- }
183
- const androidHome = process.env['ANDROID_HOME'] ?? '';
184
- const sdkManagerBin = path_1.default.join(androidHome, 'cmdline-tools/latest/bin/sdkmanager');
185
- const sdkManagerEnvVariables = {};
186
- if (javaHomeOverride) {
187
- sdkManagerEnvVariables['JAVA_HOME'] = javaHomeOverride;
188
- }
189
- await this.runShell('Installing Android platform', [`${sdkManagerBin} --install 'platforms;${versions_1.ANDROID_PLATFORM_VERSION}'`], sdkManagerEnvVariables);
190
- await this.runShell('Installing Android NDK', [`${sdkManagerBin} --install 'ndk;${versions_1.ANDROID_NDK_VERSION}'`], sdkManagerEnvVariables);
191
- await this.runShell('Installing Android build-tools', [`${sdkManagerBin} --install 'build-tools;${versions_1.ANDROID_BUILD_TOOLS_VERSION}'`], sdkManagerEnvVariables);
192
- const ndkBundle = path_1.default.join(androidHome, 'ndk-bundle');
193
- if (!fs_1.default.existsSync(ndkBundle)) {
194
- fs_1.default.symlinkSync(`ndk/${versions_1.ANDROID_NDK_VERSION}`, ndkBundle);
195
- }
196
- await this.writeEnvVariablesToRcFile([
197
- { name: 'ANDROID_NDK_HOME', value: `"$ANDROID_HOME/ndk-bundle"` },
198
- { name: 'PATH', value: `"$ANDROID_HOME/platform-tools:$PATH"` },
199
- ]);
200
- }
201
147
  getRcFile() {
202
148
  const homeDir = process.env['HOME'] ?? '';
203
149
  const shell = process.env['SHELL'] ?? '';
@@ -11,7 +11,6 @@ const cliUtils_1 = require("../utils/cliUtils");
11
11
  const linuxDistro_1 = require("../utils/linuxDistro");
12
12
  const logUtils_1 = require("../utils/logUtils");
13
13
  const DevSetupHelper_1 = require("./DevSetupHelper");
14
- const versions_1 = require("./versions");
15
14
  const BAZELISK_URL = 'https://github.com/bazelbuild/bazelisk/releases/download/v1.26.0/bazelisk-linux-amd64';
16
15
  function getDebianArchitecture() {
17
16
  const nodeArch = os_1.default.arch();
@@ -43,7 +42,6 @@ async function linuxSetup() {
43
42
  console.log((0, logUtils_1.wrapInColor)('Unable to detect Linux distribution.', constants_1.ANSI_COLORS.YELLOW_COLOR));
44
43
  console.log((0, logUtils_1.wrapInColor)('Please manually install the following dependencies and re-run this command:', constants_1.ANSI_COLORS.YELLOW_COLOR));
45
44
  console.log(' - git');
46
- console.log(' - git-lfs');
47
45
  console.log(' - npm (Node.js)');
48
46
  console.log(' - openjdk-17-jdk (or equivalent Java 17 JDK)');
49
47
  console.log(' - watchman');
@@ -55,15 +53,6 @@ async function linuxSetup() {
55
53
  throw new Error('Unable to proceed with automatic setup on unknown Linux distribution');
56
54
  }
57
55
  const packageMappings = (0, linuxDistro_1.getCommonPackageMappings)();
58
- const repoSetupCommand = (0, linuxDistro_1.getGitLfsRepoSetupCommand)(distro);
59
- if (repoSetupCommand && (0, linuxDistro_1.needsGitLfsRepoSetup)(distro)) {
60
- try {
61
- await devSetup.runShell('Setting up git-lfs repository', [repoSetupCommand]);
62
- }
63
- catch {
64
- console.log((0, logUtils_1.wrapInColor)(`Warning: git-lfs repository setup failed. Will try to install git-lfs from standard repositories.`, constants_1.ANSI_COLORS.YELLOW_COLOR));
65
- }
66
- }
67
56
  const packagesToInstall = [];
68
57
  if (!(0, cliUtils_1.checkCommandExists)('npm')) {
69
58
  packagesToInstall.push((0, linuxDistro_1.getPackageName)(packageMappings['npm'], distro));
@@ -71,9 +60,6 @@ async function linuxSetup() {
71
60
  if (!(0, cliUtils_1.checkCommandExists)('java')) {
72
61
  packagesToInstall.push((0, linuxDistro_1.getPackageName)(packageMappings['openjdk-17'], distro));
73
62
  }
74
- if (!(0, cliUtils_1.checkCommandExists)('git-lfs')) {
75
- packagesToInstall.push((0, linuxDistro_1.getPackageName)(packageMappings['git-lfs'], distro));
76
- }
77
63
  if (!(0, cliUtils_1.checkCommandExists)('watchman')) {
78
64
  packagesToInstall.push((0, linuxDistro_1.getPackageName)(packageMappings['watchman'], distro));
79
65
  }
@@ -105,7 +91,6 @@ async function linuxSetup() {
105
91
  else {
106
92
  console.log((0, logUtils_1.wrapInColor)('All required packages are already installed.', constants_1.ANSI_COLORS.GREEN_COLOR));
107
93
  }
108
- await devSetup.setupGitLfs();
109
94
  await devSetup.setupShellAutoComplete();
110
95
  if (distro.type === linuxDistro_1.LinuxDistroType.DEBIAN) {
111
96
  const libtinfoInstalled = (0, cliUtils_1.checkCommandExists)('dpkg') &&
@@ -164,6 +149,5 @@ async function linuxSetup() {
164
149
  fs_1.default.chmodSync(bazeliskTargetPath, stats.mode | 0o111);
165
150
  }
166
151
  await devSetup.writeEnvVariablesToRcFile([{ name: 'PATH', value: `"$HOME/.valdi/bin:$PATH"` }]);
167
- await devSetup.setupAndroidSDK(versions_1.ANDROID_LINUX_COMMANDLINE_TOOLS);
168
152
  devSetup.onComplete();
169
153
  }
@@ -6,7 +6,6 @@ const fs_1 = tslib_1.__importDefault(require("fs"));
6
6
  const errors_1 = require("../core/errors");
7
7
  const cliUtils_1 = require("../utils/cliUtils");
8
8
  const DevSetupHelper_1 = require("./DevSetupHelper");
9
- const versions_1 = require("./versions");
10
9
  async function macOSSetup() {
11
10
  const devSetup = new DevSetupHelper_1.DevSetupHelper();
12
11
  if (!(0, cliUtils_1.checkCommandExists)('xcode-select')) {
@@ -69,7 +68,7 @@ async function macOSSetup() {
69
68
  console.log('Note: Could not automatically configure Homebrew PATH in .zprofile');
70
69
  }
71
70
  }
72
- const packages = ['npm', 'bazelisk', 'openjdk@17', 'temurin', 'git-lfs', 'watchman', 'ios-webkit-debug-proxy'];
71
+ const packages = ['npm', 'bazelisk', 'openjdk@17', 'temurin', 'watchman', 'ios-webkit-debug-proxy', 'android-platform-tools'];
73
72
  const packagesToInstall = [];
74
73
  for (const pkg of packages) {
75
74
  try {
@@ -88,7 +87,6 @@ async function macOSSetup() {
88
87
  else {
89
88
  console.log('All Homebrew dependencies are already installed');
90
89
  }
91
- await devSetup.setupGitLfs();
92
90
  await devSetup.setupShellAutoComplete();
93
91
  const jdkSymlinkPath = '/Library/Java/JavaVirtualMachines/openjdk-17.jdk';
94
92
  const jdkSourcePath = '/opt/homebrew/opt/openjdk@17/libexec/openjdk.jdk';
@@ -117,7 +115,5 @@ async function macOSSetup() {
117
115
  { name: 'PATH', value: '"/opt/homebrew/opt/openjdk@17/bin:$PATH"' },
118
116
  { name: 'JAVA_HOME', value: '`/usr/libexec/java_home -v 17`' },
119
117
  ]);
120
- const javaHome = await (0, cliUtils_1.runCliCommand)('/usr/libexec/java_home');
121
- await devSetup.setupAndroidSDK(versions_1.ANDROID_MACOS_COMMANDLINE_TOOLS, javaHome.stdout.trim());
122
118
  devSetup.onComplete();
123
119
  }
@@ -67,6 +67,12 @@ class BazelLabel {
67
67
  return new BazelLabel(repo, str, undefined);
68
68
  }
69
69
  }
70
+ get apparentRepo() {
71
+ if (!this.repo)
72
+ return undefined;
73
+ const tildeIndex = this.repo.indexOf('~');
74
+ return tildeIndex >= 0 ? this.repo.slice(0, tildeIndex) : this.repo;
75
+ }
70
76
  toString() {
71
77
  const repoPrefix = this.repo ? `@${this.repo}` : '';
72
78
  if (this.name) {
@@ -76,6 +82,15 @@ class BazelLabel {
76
82
  return repoPrefix + this.target;
77
83
  }
78
84
  }
85
+ toBuildableString() {
86
+ const repoPrefix = this.apparentRepo ? `@${this.apparentRepo}` : '';
87
+ if (this.name) {
88
+ return `${repoPrefix}${this.target}:${this.name}`;
89
+ }
90
+ else {
91
+ return repoPrefix + this.target;
92
+ }
93
+ }
79
94
  }
80
95
  exports.BazelLabel = BazelLabel;
81
96
  class BazelCommandCache {