@snap/valdi 1.0.7 → 1.0.11

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 (170) hide show
  1. package/.bootstrap/modules/{ios_android_bridge_module → polyglot_bridge_module}/BUILD.bazel.template +16 -1
  2. package/.bootstrap/modules/polyglot_bridge_module/web/Calculator.ts +11 -0
  3. package/.bootstrap/modules/polyglot_bridge_module/web/tsconfig.json +16 -0
  4. package/.bootstrap/modules/polyglot_view_module/BUILD.bazel.template +75 -0
  5. package/.bootstrap/modules/polyglot_view_module/android/PolyglotNativeView.kt.template +41 -0
  6. package/.bootstrap/modules/polyglot_view_module/android/PolyglotNativeViewAttributesBinder.kt.template +17 -0
  7. package/.bootstrap/modules/polyglot_view_module/ios/SCPolyglotView.h +8 -0
  8. package/.bootstrap/modules/polyglot_view_module/ios/SCPolyglotView.m +23 -0
  9. package/.bootstrap/modules/polyglot_view_module/macos/SCPolyglotView.h +8 -0
  10. package/.bootstrap/modules/polyglot_view_module/macos/SCPolyglotView.m +23 -0
  11. package/.bootstrap/modules/polyglot_view_module/src/PolyglotCustomView.tsx.template +23 -0
  12. package/.bootstrap/modules/polyglot_view_module/web/PolyglotWeb.ts.template +30 -0
  13. package/.bootstrap/modules/polyglot_view_module/web/tsconfig.json +16 -0
  14. package/.metadata/AGENTS.md.template +8 -274
  15. package/.metadata/skill-reference.tsx.template +8 -0
  16. package/.metadata/skill-tests-BUILD.bazel.template +21 -0
  17. package/.metadata/skill-tests-README.md.template +17 -0
  18. package/.metadata/skill.md.template +27 -0
  19. package/README.md +12 -3
  20. package/bundled-skills/CONTRIBUTING_SKILLS.md +74 -0
  21. package/bundled-skills/registry.json +21 -0
  22. package/bundled-skills/skills/valdi-android/skill.md +89 -0
  23. package/bundled-skills/skills/valdi-async/skill.md +246 -0
  24. package/bundled-skills/skills/valdi-async/tests/BUILD.bazel +19 -0
  25. package/bundled-skills/skills/valdi-async/tests/README.md +25 -0
  26. package/bundled-skills/skills/valdi-async/tests/src/reference.tsx +210 -0
  27. package/bundled-skills/skills/valdi-async/tests/tsconfig.json +1 -0
  28. package/bundled-skills/skills/valdi-bazel/skill.md +141 -0
  29. package/bundled-skills/skills/valdi-compiler/skill.md +108 -0
  30. package/bundled-skills/skills/valdi-component-tests/skill.md +430 -0
  31. package/bundled-skills/skills/valdi-component-tests/tests/BUILD.bazel +24 -0
  32. package/bundled-skills/skills/valdi-component-tests/tests/README.md +35 -0
  33. package/bundled-skills/skills/valdi-component-tests/tests/src/ProfileCard.tsx +38 -0
  34. package/bundled-skills/skills/valdi-component-tests/tests/test/ProfileCardTest.spec.tsx +107 -0
  35. package/bundled-skills/skills/valdi-component-tests/tests/tsconfig.json +1 -0
  36. package/bundled-skills/skills/valdi-cpp-runtime/skill.md +103 -0
  37. package/bundled-skills/skills/valdi-custom-view/skill.md +64 -0
  38. package/bundled-skills/skills/valdi-inspect/skill.md +199 -0
  39. package/bundled-skills/skills/valdi-ios/skill.md +93 -0
  40. package/bundled-skills/skills/valdi-migrate/skill.md +175 -0
  41. package/bundled-skills/skills/valdi-migrate/tests/BUILD.bazel +23 -0
  42. package/bundled-skills/skills/valdi-migrate/tests/README.md +70 -0
  43. package/bundled-skills/skills/valdi-migrate/tests/check_antipatterns.py +89 -0
  44. package/bundled-skills/skills/valdi-migrate/tests/compose_example.kt +94 -0
  45. package/bundled-skills/skills/valdi-migrate/tests/flutter_example.dart +129 -0
  46. package/bundled-skills/skills/valdi-migrate/tests/react_example.tsx +98 -0
  47. package/bundled-skills/skills/valdi-migrate/tests/src/expected_valdi.tsx +267 -0
  48. package/bundled-skills/skills/valdi-migrate/tests/tsconfig.json +3 -0
  49. package/bundled-skills/skills/valdi-overview/skill.md +63 -0
  50. package/bundled-skills/skills/valdi-perf/skill.md +197 -0
  51. package/bundled-skills/skills/valdi-perf/tests/BUILD.bazel +19 -0
  52. package/bundled-skills/skills/valdi-perf/tests/README.md +26 -0
  53. package/bundled-skills/skills/valdi-perf/tests/src/reference.tsx +202 -0
  54. package/bundled-skills/skills/valdi-perf/tests/tsconfig.json +1 -0
  55. package/bundled-skills/skills/valdi-polyglot-module/skill.md +124 -0
  56. package/bundled-skills/skills/valdi-profile/skill.md +126 -0
  57. package/bundled-skills/skills/valdi-setup/skill.md +129 -0
  58. package/bundled-skills/skills/valdi-testing/skill.md +65 -0
  59. package/bundled-skills/skills/valdi-tsx/skill.md +385 -0
  60. package/bundled-skills/skills/valdi-tsx/tests/BUILD.bazel +19 -0
  61. package/bundled-skills/skills/valdi-tsx/tests/README.md +29 -0
  62. package/bundled-skills/skills/valdi-tsx/tests/src/reference.tsx +173 -0
  63. package/bundled-skills/skills/valdi-tsx/tests/tsconfig.json +1 -0
  64. package/dist/commands/bootstrap.js +0 -7
  65. package/dist/commands/inspect.js +16 -0
  66. package/dist/commands/inspect_commands/contexts.js +55 -0
  67. package/dist/commands/inspect_commands/devices.js +53 -0
  68. package/dist/commands/inspect_commands/heap.js +59 -0
  69. package/dist/commands/inspect_commands/select.js +43 -0
  70. package/dist/commands/inspect_commands/snapshot.js +64 -0
  71. package/dist/commands/inspect_commands/status.js +68 -0
  72. package/dist/commands/inspect_commands/tree.js +86 -0
  73. package/dist/commands/newModule.js +10 -14
  74. package/dist/commands/profile.js +16 -0
  75. package/dist/commands/profile_commands/capture.js +106 -0
  76. package/dist/commands/skills.js +16 -0
  77. package/dist/commands/skills_commands/create.js +125 -0
  78. package/dist/commands/skills_commands/install.js +96 -0
  79. package/dist/commands/skills_commands/list.js +83 -0
  80. package/dist/commands/skills_commands/remove.js +41 -0
  81. package/dist/commands/skills_commands/update.js +59 -0
  82. package/dist/core/constants.js +0 -1
  83. package/dist/core/packageFiles.spec.js +29 -0
  84. package/dist/setup/versions.js +1 -1
  85. package/dist/utils/daemonClient.js +342 -0
  86. package/dist/utils/hermesClient.js +252 -0
  87. package/dist/utils/skillsAdapters.js +140 -0
  88. package/dist/utils/skillsRegistry.js +40 -0
  89. package/dist/utils/stringUtils.spec.js +1 -1
  90. package/package.json +20 -5
  91. package/.bazelignore +0 -2
  92. package/.bootstrap/modules/cpp_bridge_module/BUILD.bazel.template +0 -21
  93. package/.bootstrap/modules/cpp_bridge_module/cpp/CalculatorModuleFactory.cpp.template +0 -28
  94. package/.bootstrap/modules/ios_android_bridge_module/src/Calculator.d.ts +0 -4
  95. package/.bootstrap/modules/ios_android_view_module/BUILD.bazel.template +0 -41
  96. package/.bootstrap/modules/ios_android_view_module/android/CircleView.kt.template +0 -42
  97. package/.bootstrap/modules/ios_android_view_module/android/CircleViewAttributesBinder.kt.template +0 -60
  98. package/.bootstrap/modules/ios_android_view_module/ios/SCCCircleView.h +0 -6
  99. package/.bootstrap/modules/ios_android_view_module/ios/SCCCircleView.m +0 -82
  100. package/.bootstrap/modules/ios_android_view_module/src/Circle.tsx.template +0 -15
  101. package/.config/copyconfig.json +0 -10
  102. package/.editorconfig +0 -21
  103. package/.eslintignore +0 -1
  104. package/.eslintrc.js +0 -72
  105. package/.github/README.md +0 -164
  106. package/.metadata/.cursorrules.template +0 -60
  107. package/.prettierignore +0 -2
  108. package/.prettierrc.json +0 -7
  109. package/LINUX_COMPATIBILITY.md +0 -248
  110. package/prettier.config.js +0 -4
  111. package/scripts/sync-agents-md.sh +0 -44
  112. package/scripts/update-agents-templates.ts +0 -170
  113. package/spec/support/jasmine.json +0 -6
  114. package/src/commands/bootstrap.ts +0 -410
  115. package/src/commands/build.ts +0 -89
  116. package/src/commands/devSetup.ts +0 -17
  117. package/src/commands/doctor.ts +0 -1832
  118. package/src/commands/export.ts +0 -131
  119. package/src/commands/hotreload.ts +0 -108
  120. package/src/commands/install.ts +0 -93
  121. package/src/commands/lint.ts +0 -15
  122. package/src/commands/lint_commands/lintCheck.ts +0 -53
  123. package/src/commands/lint_commands/lintFormat.ts +0 -49
  124. package/src/commands/log.ts +0 -108
  125. package/src/commands/newModule.ts +0 -286
  126. package/src/commands/package.ts +0 -102
  127. package/src/commands/projectsync.ts +0 -488
  128. package/src/commands/test.ts +0 -68
  129. package/src/core/constants.ts +0 -98
  130. package/src/core/errors.ts +0 -10
  131. package/src/index.ts +0 -27
  132. package/src/setup/DevSetupHelper.ts +0 -290
  133. package/src/setup/linuxSetup.ts +0 -261
  134. package/src/setup/macOSSetup.ts +0 -156
  135. package/src/setup/setupEntryPoint.ts +0 -64
  136. package/src/setup/versions.ts +0 -8
  137. package/src/utils/ArgumentsResolver.ts +0 -23
  138. package/src/utils/BazelClient.ts +0 -285
  139. package/src/utils/Digraph.ts +0 -81
  140. package/src/utils/LoadingIndicator.ts +0 -43
  141. package/src/utils/applicationUtils.ts +0 -276
  142. package/src/utils/buildInfo.ts +0 -99
  143. package/src/utils/byString.ts +0 -3
  144. package/src/utils/cliUtils.ts +0 -112
  145. package/src/utils/copyBootstrapFiles.ts +0 -30
  146. package/src/utils/deviceUtils.ts +0 -76
  147. package/src/utils/errorUtils.ts +0 -63
  148. package/src/utils/fileUtils.ts +0 -257
  149. package/src/utils/githubUtils.ts +0 -102
  150. package/src/utils/jsonUtils.ts +0 -30
  151. package/src/utils/lintUtils.ts +0 -190
  152. package/src/utils/linuxDistro.spec.ts +0 -219
  153. package/src/utils/linuxDistro.ts +0 -326
  154. package/src/utils/logUtils.ts +0 -9
  155. package/src/utils/pathUtils.ts +0 -12
  156. package/src/utils/stringUtils.spec.ts +0 -95
  157. package/src/utils/stringUtils.ts +0 -103
  158. package/src/utils/tempDir.ts +0 -24
  159. package/src/utils/zipUtils.ts +0 -14
  160. package/test/ValdiSmokeTest.ts +0 -279
  161. package/test/helpers/AsyncHelpers.ts +0 -113
  162. package/test/helpers/CommandHelpers.ts +0 -37
  163. package/test/helpers/ProjectHelpers.ts +0 -153
  164. package/test/helpers/StreamHelpers.ts +0 -37
  165. package/test/helpers/TypeScriptClient.ts +0 -217
  166. package/tsconfig.dist.json +0 -8
  167. package/tsconfig.json +0 -42
  168. /package/.bootstrap/modules/{ios_android_bridge_module → polyglot_bridge_module}/android/CalculatorModuleFactory.kt.template +0 -0
  169. /package/.bootstrap/modules/{ios_android_bridge_module → polyglot_bridge_module}/ios/SCCCalculatorModuleFactory.m.template +0 -0
  170. /package/.bootstrap/modules/{cpp_bridge_module → polyglot_bridge_module}/src/Calculator.d.ts +0 -0
@@ -1,170 +0,0 @@
1
- #!/usr/bin/env ts-node
2
- /**
3
- * Updates AGENTS.md templates in bootstrap directory with correct Valdi patterns
4
- * Ensures consistency with root AGENTS.md anti-hallucination guidelines
5
- */
6
-
7
- import fs from 'fs';
8
- import path from 'path';
9
-
10
- const CLI_ROOT = path.join(__dirname, '..');
11
- const OPEN_SOURCE_ROOT = path.join(CLI_ROOT, '../..');
12
-
13
- // Common Valdi patterns section that should be consistent across all AGENTS.md files
14
- const VALDI_PATTERNS_SECTION = `
15
- ## 🚨 CRITICAL: Valdi is NOT React!
16
-
17
- **AI assistants often suggest React patterns that DON'T EXIST in Valdi.** This is because TSX/JSX syntax looks like React, but Valdi compiles to native code.
18
-
19
- ### ❌ FORBIDDEN Patterns (Don't exist in Valdi)
20
-
21
- \`\`\`typescript
22
- // ❌ WRONG - React hooks don't exist
23
- const [count, setCount] = useState(0);
24
- useEffect(() => { ... }, []);
25
-
26
- // ❌ WRONG - Functional components don't exist
27
- const MyComponent = () => <view />;
28
-
29
- // ❌ WRONG - Common AI mistakes
30
- this.markNeedsRender(); // Doesn't exist!
31
- this.props.title; // Should be: this.viewModel.title
32
- onMount() { } // Should be: onCreate()
33
- onUpdate() { } // Should be: onViewModelUpdate()
34
- onUnmount() { } // Should be: onDestroy()
35
- this.context.get(Service); // Wrong pattern, use withProviders()
36
- \`\`\`
37
-
38
- ### ✅ CORRECT Valdi Patterns
39
-
40
- \`\`\`typescript
41
- // ✅ Stateful component with state
42
- import { StatefulComponent } from 'valdi_core/src/Component';
43
-
44
- class MyComponent extends StatefulComponent<ViewModel, State> {
45
- state = { count: 0 };
46
-
47
- // Lifecycle methods
48
- onCreate() { } // Component created
49
- onViewModelUpdate(prev: ViewModel) { } // Props changed
50
- onDestroy() { } // Before removal
51
-
52
- // State updates
53
- handleClick() {
54
- this.setState({ count: this.state.count + 1 }); // Auto re-renders
55
- }
56
-
57
- // Render (returns void, JSX is statement)
58
- onRender() {
59
- <button
60
- title={\`Count: \${this.state.count}\`}
61
- onPress={this.handleClick}
62
- />;
63
- }
64
- }
65
-
66
- // ✅ Stateless component (props only)
67
- import { Component } from 'valdi_core/src/Component';
68
-
69
- class SimpleComponent extends Component<ViewModel> {
70
- onRender() {
71
- <label value={this.viewModel.title} />; // viewModel, not props!
72
- }
73
- }
74
- \`\`\`
75
-
76
- ### Key Differences from React
77
-
78
- | Concept | React | Valdi |
79
- |---------|-------|-------|
80
- | **Components** | Functions or classes | Classes only (Component or StatefulComponent) |
81
- | **State** | \`useState\` hook | \`state = { }\` + \`setState()\` |
82
- | **Props** | \`this.props\` | \`this.viewModel\` |
83
- | **Lifecycle** | \`useEffect\` | \`onCreate\`, \`onViewModelUpdate\`, \`onDestroy\` |
84
- | **Re-render** | \`setCount(...)\` | \`this.setState(...)\` |
85
- | **Return** | \`return <view />\` | \`<view />;\` (statement, returns void) |
86
-
87
- For complete framework documentation, see: https://github.com/Snapchat/Valdi
88
- `;
89
-
90
- function updateAgentsTemplate(templatePath: string, _isCliApp: boolean) {
91
- console.log(`\nUpdating: ${path.relative(CLI_ROOT, templatePath)}`);
92
-
93
- let content = fs.readFileSync(templatePath, 'utf-8');
94
-
95
- // Fix incorrect lifecycle method comments
96
- content = content.replace(
97
- /\/\/ onMount\(\) - Called when component is first mounted/g,
98
- '// onCreate() - Called when component is first created'
99
- );
100
- content = content.replace(
101
- /\/\/ onUnmount\(\) - Called before component is removed/g,
102
- '// onDestroy() - Called before component is removed'
103
- );
104
- content = content.replace(
105
- /\/\/ onUpdate\(prevProps\) - Called when component updates/g,
106
- '// onViewModelUpdate(previousViewModel) - Called when viewModel updates'
107
- );
108
-
109
- // Find where to insert the patterns section (after Overview, before Project Structure or Development Workflow)
110
- const insertAfter = '## Overview';
111
- const insertIndex = content.indexOf(insertAfter);
112
-
113
- if (insertIndex === -1) {
114
- console.warn(' ⚠️ Could not find Overview section, skipping pattern insertion');
115
- } else {
116
- // Find the end of the Overview section (next ## heading)
117
- const nextHeadingMatch = content.substring(insertIndex + insertAfter.length).match(/\n## /);
118
- if (nextHeadingMatch) {
119
- const insertPosition = insertIndex + insertAfter.length + nextHeadingMatch.index!;
120
-
121
- // Check if patterns section already exists
122
- if (!content.includes('🚨 CRITICAL: Valdi is NOT React!')) {
123
- content =
124
- content.substring(0, insertPosition) +
125
- '\n' +
126
- VALDI_PATTERNS_SECTION +
127
- '\n' +
128
- content.substring(insertPosition);
129
- console.log(' ✅ Added Valdi patterns section');
130
- } else {
131
- console.log(' ℹ️ Patterns section already exists, preserving custom content');
132
- }
133
- }
134
- }
135
-
136
- // Update Provider pattern example if it exists
137
- if (content.includes('import { Provider }')) {
138
- console.log(' ⚠️ Found old Provider pattern, consider updating to withProviders() HOC');
139
- }
140
-
141
- fs.writeFileSync(templatePath, content, 'utf-8');
142
- console.log(' ✅ Template updated');
143
- }
144
-
145
- function main() {
146
- console.log('Updating AGENTS.md bootstrap templates with correct Valdi patterns...\n');
147
-
148
- const uiTemplate = path.join(CLI_ROOT, '.bootstrap/apps/ui_application/AGENTS.md.template');
149
- const cliTemplate = path.join(CLI_ROOT, '.bootstrap/apps/cli_application/AGENTS.md.template');
150
-
151
- if (fs.existsSync(uiTemplate)) {
152
- updateAgentsTemplate(uiTemplate, false);
153
- } else {
154
- console.warn(`UI template not found: ${uiTemplate}`);
155
- }
156
-
157
- if (fs.existsSync(cliTemplate)) {
158
- updateAgentsTemplate(cliTemplate, true);
159
- } else {
160
- console.warn(`CLI template not found: ${cliTemplate}`);
161
- }
162
-
163
- console.log('\n✅ All templates updated!');
164
- console.log('\nNext steps:');
165
- console.log(' 1. Review the changes in the templates');
166
- console.log(' 2. Test with: valdi bootstrap (in a test directory)');
167
- console.log(' 3. Commit the updated templates');
168
- }
169
-
170
- main();
@@ -1,6 +0,0 @@
1
- {
2
- "spec_dir": ".",
3
- "spec_files": [
4
- "**/*.spec.ts"
5
- ]
6
- }
@@ -1,410 +0,0 @@
1
- import path from 'path';
2
- import inquirer from 'inquirer';
3
- import type { Argv } from 'yargs';
4
- import { ANSI_COLORS, BOOTSTRAP_DIR_PATH, META_DIR_PATH, TEMPLATE_BASE_PATHS, VALDI_CONFIG_PATHS } from '../core/constants';
5
- import { CliError } from '../core/errors';
6
- import type { ArgumentsResolver } from '../utils/ArgumentsResolver';
7
- import { BazelClient } from '../utils/BazelClient';
8
- import type { CliChoice } from '../utils/cliUtils';
9
- import { getUserChoice, getUserConfirmation } from '../utils/cliUtils';
10
- import { copyBootstrapFiles } from '../utils/copyBootstrapFiles';
11
- import { makeCommandHandler } from '../utils/errorUtils';
12
- import type { Replacements } from '../utils/fileUtils';
13
- import {
14
- TemplateFile,
15
- deleteAll,
16
- fileExists,
17
- isDirectoryEmpty,
18
- processReplacements,
19
- resolveFilePath,
20
- } from '../utils/fileUtils';
21
- import { wrapInColor } from '../utils/logUtils';
22
- import { toPascalCase, sanitizeProjectName, validateProjectName } from '../utils/stringUtils';
23
- import { getAllProjectSyncTargets, runProjectSync } from './projectsync';
24
- import { getLatestReleaseTag } from '../utils/githubUtils';
25
-
26
- interface CommandParameters {
27
- confirmBootstrap: boolean;
28
- projectName: string;
29
- applicationType: string;
30
- valdiImport: string;
31
- valdiWidgetsImport: string;
32
- valdiVersion: string;
33
- valdiWidgetsVersion: string;
34
- skipProjectsync: boolean;
35
- withCleanup: boolean;
36
- }
37
-
38
- interface ApplicationTemplate {
39
- name: string;
40
- path: string;
41
- description: string;
42
- }
43
-
44
- const ALL_APPLICATION_TEMPLATES: readonly ApplicationTemplate[] = [
45
- {
46
- name: 'UI Application',
47
- path: 'ui_application',
48
- description: `An application rendering UI in a window on iOS, Android and macOS.`,
49
- },
50
- {
51
- name: 'CLI Application',
52
- path: 'cli_application',
53
- description: `A command line application that runs in a terminal`,
54
- },
55
- ];
56
-
57
- const VALDI_GIT_URL = 'https://github.com/Snapchat/Valdi';
58
- const VALDI_WIDGETS_GIT_URL = 'https://github.com/Snapchat/Valdi_Widgets';
59
-
60
- /** Pinned Valdi release used by default for reproducible bootstraps. Bump when cutting a new Valdi release. */
61
- const DEFAULT_VALDI_RELEASE_TAG = 'beta-0.0.3';
62
- /** Pinned Valdi_Widgets release used by default. Should match the Valdi release cycle. */
63
- const DEFAULT_VALDI_WIDGETS_RELEASE_TAG = 'beta-0.0.3';
64
-
65
- const DEFAULT_VALDI_IMPORT = `
66
- http_archive(
67
- name = "valdi",
68
- strip_prefix = "Valdi-{{VALDI_RELEASE_TAG}}",
69
- url = "${VALDI_GIT_URL}/archive/{{VALDI_RELEASE_REF}}.tar.gz",
70
- )`;
71
-
72
- const DEFAULT_VALDI_WIDGETS_IMPORT = `
73
- http_archive(
74
- name = "valdi_widgets",
75
- strip_prefix = "Valdi_Widgets-{{VALDI_WIDGETS_RELEASE_TAG}}",
76
- url = "${VALDI_WIDGETS_GIT_URL}/archive/{{VALDI_WIDGETS_RELEASE_REF}}.tar.gz",
77
- )`;
78
-
79
- const LOCAL_VALDI_IMPORT_TEMPLATE = `
80
- local_repository(
81
- name = "valdi",
82
- path = "{{PATH}}",
83
- )
84
- `;
85
-
86
- const LOCAL_VALDI_WIDGETS_IMPORT_TEMPLATE = `
87
- local_repository(
88
- name = "valdi_widgets",
89
- path = "{{PATH}}",
90
- )
91
- `;
92
-
93
- function isAlreadyInitialized(): boolean {
94
- return fileExists(path.join(process.cwd(), 'WORKSPACE'));
95
- }
96
-
97
- async function getShouldBootstrap(argv: ArgumentsResolver<CommandParameters>): Promise<boolean> {
98
- // Get confirmation on directory path
99
- return argv.getArgumentOrResolve('confirmBootstrap', () => {
100
- return getUserConfirmation('Do you want to create a new project in the current directory?', true);
101
- });
102
- }
103
-
104
- const defaultProjectName = path.basename(process.cwd());
105
-
106
- async function getApplicationType(argv: ArgumentsResolver<CommandParameters>): Promise<ApplicationTemplate> {
107
- const applicationType = argv.getArgument('applicationType');
108
-
109
- if (applicationType) {
110
- const target = ALL_APPLICATION_TEMPLATES.find(target => target.path === applicationType);
111
-
112
- if (target) {
113
- return target;
114
- } else {
115
- throw new CliError(`Unknown application type: ${applicationType}`);
116
- }
117
- }
118
-
119
- const choices: CliChoice<ApplicationTemplate>[] = ALL_APPLICATION_TEMPLATES.map(target => ({
120
- name: `${wrapInColor(target.name, ANSI_COLORS.GREEN_COLOR)} . ${target.description}`,
121
- value: target,
122
- }));
123
-
124
- return await getUserChoice(choices, `Please choose the application type:`);
125
- }
126
-
127
- async function getProjectName(argv: ArgumentsResolver<CommandParameters>): Promise<string> {
128
- return argv.getArgumentOrResolve('projectName', async () => {
129
- let projectName = '';
130
- let isValid = false;
131
-
132
- while (!isValid) {
133
- const result = await inquirer.prompt<{ projectName: string }>([
134
- {
135
- type: 'input',
136
- name: 'projectName',
137
- message: 'Please provide a name for this project:',
138
- default: defaultProjectName,
139
- },
140
- ]);
141
-
142
- projectName = result.projectName;
143
- const validationError = validateProjectName(projectName);
144
-
145
- if (validationError) {
146
- console.log(wrapInColor(`\n❌ ${validationError}\n`, ANSI_COLORS.RED_COLOR));
147
- continue;
148
- }
149
-
150
- const sanitized = sanitizeProjectName(projectName);
151
- if (sanitized !== projectName) {
152
- console.log(
153
- wrapInColor(
154
- `\n⚠️ Project name will be sanitized from "${projectName}" to "${sanitized}"`,
155
- ANSI_COLORS.YELLOW_COLOR,
156
- ),
157
- );
158
- const confirm = await getUserConfirmation('Do you want to continue with this name?', true);
159
- if (!confirm) {
160
- continue;
161
- }
162
- }
163
-
164
- isValid = true;
165
- }
166
-
167
- return sanitizeProjectName(projectName);
168
- });
169
- }
170
-
171
- function resolveValdiReleaseTag(
172
- argv: ArgumentsResolver<CommandParameters>,
173
- gitUrl: string,
174
- defaultTag: string,
175
- versionOption: 'valdiVersion' | 'valdiWidgetsVersion' = 'valdiVersion',
176
- ): Promise<string> {
177
- const override = argv.getArgument(versionOption);
178
- if (!override) {
179
- return Promise.resolve(defaultTag);
180
- }
181
- if (override === 'latest') {
182
- return getLatestReleaseTag(gitUrl);
183
- }
184
- return Promise.resolve(override);
185
- }
186
-
187
- function getValdiImport(argv: ArgumentsResolver<CommandParameters>, valdiReleaseRef: string): string {
188
- const valdiImport = argv.getArgument('valdiImport');
189
- if (valdiImport) {
190
- return processReplacements(LOCAL_VALDI_IMPORT_TEMPLATE, { PATH: valdiImport });
191
- } else {
192
- const valdiReleaseTag = valdiReleaseRef.split('/').pop()!;
193
- return processReplacements(DEFAULT_VALDI_IMPORT, {
194
- VALDI_RELEASE_REF: valdiReleaseRef,
195
- VALDI_RELEASE_TAG: valdiReleaseTag,
196
- });
197
- }
198
- }
199
-
200
- function getValdiWidgetsImport(argv: ArgumentsResolver<CommandParameters>, valdiWidgetsReleaseRef: string): string {
201
- const valdiWidgetsImport = argv.getArgument('valdiWidgetsImport');
202
- if (valdiWidgetsImport) {
203
- return processReplacements(LOCAL_VALDI_WIDGETS_IMPORT_TEMPLATE, { PATH: valdiWidgetsImport });
204
- } else {
205
- const valdiWidgetsReleaseTag = valdiWidgetsReleaseRef.split('/').pop()!;
206
- return processReplacements(DEFAULT_VALDI_WIDGETS_IMPORT, {
207
- VALDI_WIDGETS_RELEASE_REF: valdiWidgetsReleaseRef,
208
- VALDI_WIDGETS_RELEASE_TAG: valdiWidgetsReleaseTag,
209
- });
210
- }
211
- }
212
-
213
- // Create files from templates
214
- function initializeConfigFiles(
215
- projectName: string,
216
- template: ApplicationTemplate,
217
- valdiImport: string,
218
- valdiWidgetsImport: string,
219
- ) {
220
-
221
- const TEMPLATE_FILES = [
222
- TemplateFile.init(TEMPLATE_BASE_PATHS.USER_CONFIG).withOutputPath(resolveFilePath(VALDI_CONFIG_PATHS[0] ?? '')),
223
- TemplateFile.init(TEMPLATE_BASE_PATHS.BAZEL_VERSION),
224
- TemplateFile.init(TEMPLATE_BASE_PATHS.WORKSPACE).withReplacements({
225
- WORKSPACE_NAME: projectName,
226
- VALDI_IMPORT: valdiImport,
227
- VALDI_WIDGETS_IMPORT: valdiWidgetsImport,
228
- }),
229
- TemplateFile.init(TEMPLATE_BASE_PATHS.BAZEL_RC),
230
- TemplateFile.init(TEMPLATE_BASE_PATHS.README),
231
- TemplateFile.init(TEMPLATE_BASE_PATHS.GIT_IGNORE),
232
- TemplateFile.init(TEMPLATE_BASE_PATHS.WATCHMAN_CONFIG),
233
- TemplateFile.init(TEMPLATE_BASE_PATHS.EDITOR_CONFIG),
234
- TemplateFile.init(TEMPLATE_BASE_PATHS.CURSOR_RULES),
235
- TemplateFile.init(TEMPLATE_BASE_PATHS.AGENTS).withReplacements({ MODULE_NAME: projectName }),
236
- ];
237
-
238
- TEMPLATE_FILES.forEach(templateFile => {
239
- console.log(
240
- wrapInColor(`Creating ${templateFile.baseName} in ${templateFile.outputPath}...`, ANSI_COLORS.YELLOW_COLOR),
241
- );
242
- templateFile.expandTemplate();
243
- });
244
-
245
- // Copy GitHub templates directory (if it exists)
246
- const replacements: Replacements = {
247
- MODULE_NAME: projectName,
248
- MODULE_NAME_PASCAL_CASED: toPascalCase(projectName),
249
- };
250
- const githubSourcePath = path.join(BOOTSTRAP_DIR_PATH, '.github');
251
- if (fileExists(githubSourcePath)) {
252
- console.log(wrapInColor('Creating GitHub templates...', ANSI_COLORS.YELLOW_COLOR));
253
- const githubDestPath = path.join(process.cwd(), '.github');
254
- copyBootstrapFiles(githubSourcePath, githubDestPath, replacements);
255
- }
256
-
257
- // Copy .cursor rules directory (if it exists)
258
- const cursorSourcePath = path.join(META_DIR_PATH, '.cursor');
259
- if (fileExists(cursorSourcePath)) {
260
- console.log(wrapInColor('Creating Cursor AI rules...', ANSI_COLORS.YELLOW_COLOR));
261
- const cursorDestPath = path.join(process.cwd(), '.cursor');
262
- copyBootstrapFiles(cursorSourcePath, cursorDestPath, replacements);
263
- }
264
-
265
- // Setup hello world application
266
- console.log(wrapInColor(`Initializing ${template.name} application...`, ANSI_COLORS.YELLOW_COLOR));
267
- const sourcePath = path.join(BOOTSTRAP_DIR_PATH, 'apps', template.path);
268
- const destPath = process.cwd();
269
-
270
- copyBootstrapFiles(sourcePath, destPath, replacements);
271
- }
272
-
273
- async function valdiBootstrap(argv: ArgumentsResolver<CommandParameters>) {
274
- // Set up a Valdi project in the current directory. Will go through a flow to ask some questions to the user like the name of the application. This will create the following files:
275
- // user_config.yaml: User configuration file
276
- // application_names.bzl: Bazel macro file with application names
277
- const curDir = process.cwd();
278
-
279
- console.log(`\nCurrent directory: ${wrapInColor(curDir, ANSI_COLORS.GREEN_COLOR)}`);
280
-
281
- if (isAlreadyInitialized()) {
282
- // Check for existing project files
283
- // If the directory already contains a project, prompt the user to re-run command with explicit --with-cleanup flag
284
- if (argv.getArgument('withCleanup')) {
285
- console.log(wrapInColor('Deleting all files in current directory...', ANSI_COLORS.YELLOW_COLOR));
286
- deleteAll(curDir);
287
- } else {
288
- throw new CliError(
289
- `Detected existing project files. Please remove them before re-running 'valdi bootstrap'.\nYou can run '${wrapInColor('valdi bootstrap --with-cleanup', ANSI_COLORS.YELLOW_COLOR, ANSI_COLORS.RED_COLOR)}' to remove ALL FILES in the current directory.`,
290
- );
291
- }
292
- } else if (!isDirectoryEmpty(curDir)) {
293
- // Folder contains non project files
294
- // Prompt for manual clean up to prevent accidental deletion of important files
295
- throw new CliError(
296
- "Current directory is not empty. Please run 'valdi bootstrap' in an empty directory or manually clean up existing files.",
297
- );
298
- }
299
-
300
- if (!(await getShouldBootstrap(argv))) {
301
- throw new CliError('Bootstrap process aborted.');
302
- }
303
-
304
- const applicationType = await getApplicationType(argv);
305
-
306
- // Prompt user for input
307
- // - Application Name
308
- let projectName = await getProjectName(argv);
309
-
310
- // Validate project name if provided via command line argument
311
- if (argv.getArgument('projectName')) {
312
- const validationError = validateProjectName(projectName);
313
- if (validationError) {
314
- throw new CliError(validationError);
315
- }
316
- projectName = sanitizeProjectName(projectName);
317
- }
318
-
319
- if (!projectName) {
320
- throw new CliError('Project name cannot be empty.');
321
- }
322
-
323
- const valdiReleaseTag = await resolveValdiReleaseTag(argv, VALDI_GIT_URL, DEFAULT_VALDI_RELEASE_TAG);
324
- const valdiWidgetsReleaseTag = await resolveValdiReleaseTag(
325
- argv,
326
- VALDI_WIDGETS_GIT_URL,
327
- DEFAULT_VALDI_WIDGETS_RELEASE_TAG,
328
- 'valdiWidgetsVersion',
329
- );
330
-
331
- const valdiImport = getValdiImport(argv, valdiReleaseTag);
332
- const valdiWidgetsImport = getValdiWidgetsImport(argv, valdiWidgetsReleaseTag);
333
-
334
- // Creating basic config files and Hello World application
335
- console.log(wrapInColor('Initializing config files...', ANSI_COLORS.BLUE_COLOR));
336
- initializeConfigFiles(projectName, applicationType, valdiImport, valdiWidgetsImport);
337
-
338
- // Check bazel version matches .bazelversion
339
- console.log(wrapInColor('Verifying Bazel installation...', ANSI_COLORS.BLUE_COLOR));
340
- const bazel = new BazelClient();
341
- const [returnCode, versionInfo, errors] = await bazel.getVersion();
342
-
343
- if (returnCode !== 0) {
344
- throw new CliError(`Bazel installation failed to verify with errors: ${errors.toString()}`);
345
- }
346
-
347
- console.log(versionInfo);
348
-
349
- if (argv.getArgument('skipProjectsync')) {
350
- console.log(wrapInColor('Skipping projectsync', ANSI_COLORS.YELLOW_COLOR));
351
- } else {
352
- console.log(wrapInColor('Running projectsync...', ANSI_COLORS.BLUE_COLOR));
353
- // eslint-disable-next-line unicorn/no-useless-undefined
354
- await runProjectSync(bazel, await getAllProjectSyncTargets(bazel), undefined, true);
355
- }
356
-
357
- // Finalize message
358
- console.log(wrapInColor('Bootstrap complete!', ANSI_COLORS.GREEN_COLOR));
359
- }
360
-
361
- export const command = 'bootstrap';
362
- export const describe = 'Prepares and initializes a project to build and run in Valdi';
363
- export const builder = (yargs: Argv<CommandParameters>) => {
364
- yargs
365
- .option('confirmBootstrap', {
366
- describe: 'Skip confirmation prompt and start bootstrap process',
367
- type: 'boolean',
368
- alias: 'y',
369
- })
370
- .option('applicationType', {
371
- describe: 'Type of application to create',
372
- alias: 't',
373
- })
374
- .option('projectName', {
375
- describe: 'Name of the project',
376
- type: 'string',
377
- alias: 'n',
378
- })
379
- .option('valdiImport', {
380
- describe:
381
- 'Path to a local checkout of the Valdi repo. If not specified, uses the pinned release (see valdiVersion).',
382
- type: 'string',
383
- alias: 'l',
384
- })
385
- .option('valdiWidgetsImport', {
386
- describe:
387
- 'Path to a local checkout of the Valdi_Widgets repo. If not specified, uses the pinned release (see valdiWidgetsVersion).',
388
- type: 'string',
389
- alias: 'w',
390
- })
391
- .option('valdiVersion', {
392
- describe: `Valdi release tag to use (e.g. v1.0.0). Use "latest" to fetch the GitHub latest release. Default: ${DEFAULT_VALDI_RELEASE_TAG}`,
393
- type: 'string',
394
- })
395
- .option('valdiWidgetsVersion', {
396
- describe: `Valdi_Widgets release tag to use. Use "latest" to fetch the GitHub latest release. Default: ${DEFAULT_VALDI_WIDGETS_RELEASE_TAG}`,
397
- type: 'string',
398
- })
399
- .option('skipProjectsync', {
400
- describe: 'Skip projectsync for testing purposes',
401
- type: 'boolean',
402
- alias: 'p',
403
- })
404
- .option('withCleanup', {
405
- describe: 'Deletes all existing files in the current directory before initiating bootstrap',
406
- type: 'boolean',
407
- alias: 'c',
408
- });
409
- };
410
- export const handler = makeCommandHandler(valdiBootstrap);
@@ -1,89 +0,0 @@
1
- import { type Argv } from 'yargs';
2
- import { ANSI_COLORS, PLATFORM } from '../core/constants';
3
- import type { ArgumentsResolver } from '../utils/ArgumentsResolver';
4
- import { BazelClient } from '../utils/BazelClient';
5
- import {
6
- applicationExtensionForPlatform,
7
- getOutputFilePath,
8
- makeArgsBuilder,
9
- } from '../utils/applicationUtils';
10
- import type { CommandParameters} from '../utils/buildInfo';
11
- import { getBuildInfo } from '../utils/buildInfo';
12
- import { installAndroidApk } from '../utils/deviceUtils';
13
- import { logReproduceThisCommandIfNeeded, makeCommandHandler } from '../utils/errorUtils';
14
- import { wrapInColor } from '../utils/logUtils';
15
-
16
-
17
- async function valdiBuild(argv: ArgumentsResolver<CommandParameters>) {
18
- const bazel = new BazelClient();
19
-
20
- const buildInfo = await getBuildInfo(argv, bazel, false);
21
-
22
- // Output Selection
23
- // ----------------
24
-
25
- // Perform build and install
26
- // -------------------------
27
- console.log(`Building: ${wrapInColor(buildInfo.application, ANSI_COLORS.GREEN_COLOR)}`);
28
-
29
- switch (buildInfo.platform) {
30
- case PLATFORM.ANDROID: {
31
- const outputFilePath = await argv.getArgumentOrResolve('target_output_path', () => {
32
- console.log('Resolving output paths...');
33
- return getOutputFilePath(bazel, applicationExtensionForPlatform(buildInfo.platform), buildInfo.application, buildInfo.bazelArgs);
34
- });
35
- await bazel.buildTarget(buildInfo.application, buildInfo.bazelArgs);
36
- break;
37
- }
38
- case PLATFORM.IOS: {
39
- console.log('Building iOS application...');
40
- await bazel.buildTarget(buildInfo.application, buildInfo.bazelArgs);
41
- logReproduceThisCommandIfNeeded(argv);
42
- break;
43
- }
44
- case PLATFORM.MACOS: {
45
- logReproduceThisCommandIfNeeded(argv);
46
- console.log('Building MacOS application...');
47
- await bazel.buildTarget(buildInfo.application, buildInfo.bazelArgs);
48
- break;
49
- }
50
- case PLATFORM.CLI: {
51
- logReproduceThisCommandIfNeeded(argv);
52
- console.log('Build CLI application...');
53
- await bazel.buildTarget(buildInfo.application, buildInfo.bazelArgs);
54
- break;
55
- }
56
- }
57
- }
58
-
59
- export const command = 'build <platform>';
60
- export const describe = 'Build the application';
61
- export const builder = makeArgsBuilder((yargs: Argv<CommandParameters>) => {
62
- yargs
63
- .option('application', {
64
- describe: 'Name of the application to install',
65
- type: 'string',
66
- requiresArg: true,
67
- })
68
- .option('device_id', {
69
- describe: 'Device ID that will receive the application',
70
- type: 'string',
71
- requiresArg: true,
72
- })
73
- .option('target_output_path', {
74
- describe: 'The output path for the Bazel target',
75
- type: 'string',
76
- requiresArg: true,
77
- })
78
- .option('simulator', {
79
- describe: 'Whether to build for simulator or for device',
80
- type: 'boolean',
81
- });
82
- });
83
- export const handler = makeCommandHandler(valdiBuild);
84
-
85
- // TODOs:
86
- // - Cached bazel query results
87
-
88
- // Extract 'custom_package' from android_binary
89
- // Extract 'bundle_id' from ios_application target
@@ -1,17 +0,0 @@
1
- import { ANSI_COLORS } from '../core/constants';
2
- import { beginEnvironmentSetup } from '../setup/setupEntryPoint';
3
- import { makeCommandHandler } from '../utils/errorUtils';
4
- import { wrapInColor } from '../utils/logUtils';
5
-
6
- async function valdiSetup() {
7
- const returnCode = await beginEnvironmentSetup();
8
-
9
- if (returnCode !== 0) {
10
- console.log(wrapInColor('Environment setup did not complete successfully.', ANSI_COLORS.YELLOW_COLOR));
11
- }
12
- }
13
-
14
- export const command = 'dev_setup';
15
- export const describe = 'Sets up the development environment for Valdi';
16
- export const builder = () => {};
17
- export const handler = makeCommandHandler(valdiSetup);