@snap/valdi 1.0.6 → 1.0.8

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 (161) hide show
  1. package/README.md +22 -10
  2. package/bundled-skills/CONTRIBUTING_SKILLS.md +74 -0
  3. package/bundled-skills/registry.json +20 -0
  4. package/bundled-skills/skills/valdi-android/skill.md +89 -0
  5. package/bundled-skills/skills/valdi-async/skill.md +246 -0
  6. package/bundled-skills/skills/valdi-async/tests/BUILD.bazel +19 -0
  7. package/bundled-skills/skills/valdi-async/tests/README.md +25 -0
  8. package/bundled-skills/skills/valdi-async/tests/src/reference.tsx +210 -0
  9. package/bundled-skills/skills/valdi-async/tests/tsconfig.json +1 -0
  10. package/bundled-skills/skills/valdi-bazel/skill.md +122 -0
  11. package/bundled-skills/skills/valdi-compiler/skill.md +108 -0
  12. package/bundled-skills/skills/valdi-component-tests/skill.md +430 -0
  13. package/bundled-skills/skills/valdi-component-tests/tests/BUILD.bazel +24 -0
  14. package/bundled-skills/skills/valdi-component-tests/tests/README.md +35 -0
  15. package/bundled-skills/skills/valdi-component-tests/tests/src/ProfileCard.tsx +38 -0
  16. package/bundled-skills/skills/valdi-component-tests/tests/test/ProfileCardTest.spec.tsx +107 -0
  17. package/bundled-skills/skills/valdi-component-tests/tests/tsconfig.json +1 -0
  18. package/bundled-skills/skills/valdi-cpp-runtime/skill.md +103 -0
  19. package/bundled-skills/skills/valdi-custom-view/skill.md +62 -0
  20. package/bundled-skills/skills/valdi-ios/skill.md +93 -0
  21. package/bundled-skills/skills/valdi-migrate/skill.md +175 -0
  22. package/bundled-skills/skills/valdi-migrate/tests/BUILD.bazel +23 -0
  23. package/bundled-skills/skills/valdi-migrate/tests/README.md +70 -0
  24. package/bundled-skills/skills/valdi-migrate/tests/check_antipatterns.py +89 -0
  25. package/bundled-skills/skills/valdi-migrate/tests/compose_example.kt +94 -0
  26. package/bundled-skills/skills/valdi-migrate/tests/flutter_example.dart +129 -0
  27. package/bundled-skills/skills/valdi-migrate/tests/react_example.tsx +98 -0
  28. package/bundled-skills/skills/valdi-migrate/tests/src/expected_valdi.tsx +267 -0
  29. package/bundled-skills/skills/valdi-migrate/tests/tsconfig.json +3 -0
  30. package/{.metadata/.cursorrules.template → bundled-skills/skills/valdi-overview/skill.md} +23 -13
  31. package/bundled-skills/skills/valdi-perf/skill.md +197 -0
  32. package/bundled-skills/skills/valdi-perf/tests/BUILD.bazel +19 -0
  33. package/bundled-skills/skills/valdi-perf/tests/README.md +26 -0
  34. package/bundled-skills/skills/valdi-perf/tests/src/reference.tsx +202 -0
  35. package/bundled-skills/skills/valdi-perf/tests/tsconfig.json +1 -0
  36. package/bundled-skills/skills/valdi-polyglot-module/skill.md +85 -0
  37. package/bundled-skills/skills/valdi-setup/skill.md +129 -0
  38. package/bundled-skills/skills/valdi-testing/skill.md +65 -0
  39. package/bundled-skills/skills/valdi-tsx/skill.md +385 -0
  40. package/bundled-skills/skills/valdi-tsx/tests/BUILD.bazel +19 -0
  41. package/bundled-skills/skills/valdi-tsx/tests/README.md +29 -0
  42. package/bundled-skills/skills/valdi-tsx/tests/src/reference.tsx +173 -0
  43. package/bundled-skills/skills/valdi-tsx/tests/tsconfig.json +1 -0
  44. package/dist/commands/bootstrap.js +3 -9
  45. package/dist/commands/newModule.js +10 -14
  46. package/dist/commands/skills.js +16 -0
  47. package/dist/commands/skills_commands/create.js +125 -0
  48. package/dist/commands/skills_commands/install.js +96 -0
  49. package/dist/commands/skills_commands/list.js +83 -0
  50. package/dist/commands/skills_commands/remove.js +41 -0
  51. package/dist/commands/skills_commands/update.js +59 -0
  52. package/dist/core/constants.js +1 -1
  53. package/dist/index.js +5 -0
  54. package/dist/setup/versions.js +1 -1
  55. package/dist/utils/skillsAdapters.js +140 -0
  56. package/dist/utils/skillsRegistry.js +40 -0
  57. package/package.json +6 -1
  58. package/.bazelignore +0 -2
  59. package/.bootstrap/apps/cli_application/AGENTS.md.template +0 -291
  60. package/.bootstrap/apps/cli_application/BUILD.bazel.template +0 -7
  61. package/.bootstrap/apps/cli_application/modules/{{MODULE_NAME}}/BUILD.bazel.template +0 -11
  62. package/.bootstrap/apps/cli_application/modules/{{MODULE_NAME}}/src/index.ts +0 -1
  63. package/.bootstrap/apps/ui_application/.eslint.rc +0 -27
  64. package/.bootstrap/apps/ui_application/AGENTS.md.template +0 -278
  65. package/.bootstrap/apps/ui_application/BUILD.bazel.template +0 -19
  66. package/.bootstrap/apps/ui_application/modules/{{MODULE_NAME}}/BUILD.bazel.template +0 -21
  67. package/.bootstrap/apps/ui_application/modules/{{MODULE_NAME}}/res/valdi@3x.png +0 -0
  68. package/.bootstrap/apps/ui_application/modules/{{MODULE_NAME}}/src/App.tsx +0 -133
  69. package/.bootstrap/apps/ui_application/package.json +0 -24
  70. package/.bootstrap/modules/cpp_bridge_module/BUILD.bazel.template +0 -21
  71. package/.bootstrap/modules/cpp_bridge_module/cpp/CalculatorModuleFactory.cpp.template +0 -28
  72. package/.bootstrap/modules/cpp_bridge_module/src/Calculator.d.ts +0 -4
  73. package/.bootstrap/modules/ios_android_bridge_module/BUILD.bazel.template +0 -39
  74. package/.bootstrap/modules/ios_android_bridge_module/android/CalculatorModuleFactory.kt.template +0 -18
  75. package/.bootstrap/modules/ios_android_bridge_module/ios/SCCCalculatorModuleFactory.m.template +0 -31
  76. package/.bootstrap/modules/ios_android_bridge_module/src/Calculator.d.ts +0 -4
  77. package/.bootstrap/modules/ios_android_view_module/BUILD.bazel.template +0 -41
  78. package/.bootstrap/modules/ios_android_view_module/android/CircleView.kt.template +0 -42
  79. package/.bootstrap/modules/ios_android_view_module/android/CircleViewAttributesBinder.kt.template +0 -60
  80. package/.bootstrap/modules/ios_android_view_module/ios/SCCCircleView.h +0 -6
  81. package/.bootstrap/modules/ios_android_view_module/ios/SCCCircleView.m +0 -82
  82. package/.bootstrap/modules/ios_android_view_module/src/Circle.tsx.template +0 -15
  83. package/.bootstrap/modules/ui_component/BUILD.bazel.template +0 -34
  84. package/.bootstrap/modules/ui_component/src/NewModuleComponent.tsx +0 -45
  85. package/.config/copyconfig.json +0 -10
  86. package/.editorconfig +0 -21
  87. package/.eslintignore +0 -1
  88. package/.eslintrc.js +0 -72
  89. package/.github/README.md +0 -164
  90. package/.metadata/.bazelrc.template +0 -91
  91. package/.metadata/.bazelversion.template +0 -1
  92. package/.metadata/.editorconfig.template +0 -37
  93. package/.metadata/.eslintrc.js.template +0 -27
  94. package/.metadata/.gitignore.template +0 -4
  95. package/.metadata/.prettierrc.json.template +0 -7
  96. package/.metadata/.watchmanconfig.template +0 -8
  97. package/.metadata/README.md.template +0 -31
  98. package/.metadata/WORKSPACE.template +0 -57
  99. package/.metadata/config.yaml.template +0 -1
  100. package/.metadata/package.json.template +0 -23
  101. package/.prettierignore +0 -2
  102. package/.prettierrc.json +0 -7
  103. package/LINUX_COMPATIBILITY.md +0 -248
  104. package/prettier.config.js +0 -4
  105. package/scripts/sync-agents-md.sh +0 -44
  106. package/scripts/update-agents-templates.ts +0 -170
  107. package/spec/support/jasmine.json +0 -6
  108. package/src/commands/bootstrap.ts +0 -409
  109. package/src/commands/build.ts +0 -89
  110. package/src/commands/devSetup.ts +0 -17
  111. package/src/commands/doctor.ts +0 -1832
  112. package/src/commands/export.ts +0 -131
  113. package/src/commands/hotreload.ts +0 -108
  114. package/src/commands/install.ts +0 -93
  115. package/src/commands/lint.ts +0 -15
  116. package/src/commands/lint_commands/lintCheck.ts +0 -53
  117. package/src/commands/lint_commands/lintFormat.ts +0 -49
  118. package/src/commands/log.ts +0 -108
  119. package/src/commands/newModule.ts +0 -286
  120. package/src/commands/package.ts +0 -102
  121. package/src/commands/projectsync.ts +0 -488
  122. package/src/commands/test.ts +0 -68
  123. package/src/core/constants.ts +0 -97
  124. package/src/core/errors.ts +0 -10
  125. package/src/index.ts +0 -22
  126. package/src/setup/DevSetupHelper.ts +0 -290
  127. package/src/setup/linuxSetup.ts +0 -261
  128. package/src/setup/macOSSetup.ts +0 -156
  129. package/src/setup/setupEntryPoint.ts +0 -64
  130. package/src/setup/versions.ts +0 -8
  131. package/src/utils/ArgumentsResolver.ts +0 -23
  132. package/src/utils/BazelClient.ts +0 -285
  133. package/src/utils/Digraph.ts +0 -81
  134. package/src/utils/LoadingIndicator.ts +0 -43
  135. package/src/utils/applicationUtils.ts +0 -276
  136. package/src/utils/buildInfo.ts +0 -99
  137. package/src/utils/byString.ts +0 -3
  138. package/src/utils/cliUtils.ts +0 -112
  139. package/src/utils/copyBootstrapFiles.ts +0 -30
  140. package/src/utils/deviceUtils.ts +0 -76
  141. package/src/utils/errorUtils.ts +0 -63
  142. package/src/utils/fileUtils.ts +0 -257
  143. package/src/utils/githubUtils.ts +0 -102
  144. package/src/utils/jsonUtils.ts +0 -30
  145. package/src/utils/lintUtils.ts +0 -190
  146. package/src/utils/linuxDistro.spec.ts +0 -219
  147. package/src/utils/linuxDistro.ts +0 -326
  148. package/src/utils/logUtils.ts +0 -9
  149. package/src/utils/pathUtils.ts +0 -12
  150. package/src/utils/stringUtils.spec.ts +0 -95
  151. package/src/utils/stringUtils.ts +0 -103
  152. package/src/utils/tempDir.ts +0 -24
  153. package/src/utils/zipUtils.ts +0 -14
  154. package/test/ValdiSmokeTest.ts +0 -279
  155. package/test/helpers/AsyncHelpers.ts +0 -113
  156. package/test/helpers/CommandHelpers.ts +0 -37
  157. package/test/helpers/ProjectHelpers.ts +0 -153
  158. package/test/helpers/StreamHelpers.ts +0 -37
  159. package/test/helpers/TypeScriptClient.ts +0 -217
  160. package/tsconfig.dist.json +0 -8
  161. package/tsconfig.json +0 -42
@@ -1,6 +0,0 @@
1
- {
2
- "spec_dir": ".",
3
- "spec_files": [
4
- "**/*.spec.ts"
5
- ]
6
- }
@@ -1,409 +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.2';
62
- /** Pinned Valdi_Widgets release used by default. Should match the Valdi release cycle. */
63
- const DEFAULT_VALDI_WIDGETS_RELEASE_TAG = 'beta-0.0.2';
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
- ];
236
-
237
- TEMPLATE_FILES.forEach(templateFile => {
238
- console.log(
239
- wrapInColor(`Creating ${templateFile.baseName} in ${templateFile.outputPath}...`, ANSI_COLORS.YELLOW_COLOR),
240
- );
241
- templateFile.expandTemplate();
242
- });
243
-
244
- // Copy GitHub templates directory (if it exists)
245
- const replacements: Replacements = {
246
- MODULE_NAME: projectName,
247
- MODULE_NAME_PASCAL_CASED: toPascalCase(projectName),
248
- };
249
- const githubSourcePath = path.join(BOOTSTRAP_DIR_PATH, '.github');
250
- if (fileExists(githubSourcePath)) {
251
- console.log(wrapInColor('Creating GitHub templates...', ANSI_COLORS.YELLOW_COLOR));
252
- const githubDestPath = path.join(process.cwd(), '.github');
253
- copyBootstrapFiles(githubSourcePath, githubDestPath, replacements);
254
- }
255
-
256
- // Copy .cursor rules directory (if it exists)
257
- const cursorSourcePath = path.join(META_DIR_PATH, '.cursor');
258
- if (fileExists(cursorSourcePath)) {
259
- console.log(wrapInColor('Creating Cursor AI rules...', ANSI_COLORS.YELLOW_COLOR));
260
- const cursorDestPath = path.join(process.cwd(), '.cursor');
261
- copyBootstrapFiles(cursorSourcePath, cursorDestPath, replacements);
262
- }
263
-
264
- // Setup hello world application
265
- console.log(wrapInColor(`Initializing ${template.name} application...`, ANSI_COLORS.YELLOW_COLOR));
266
- const sourcePath = path.join(BOOTSTRAP_DIR_PATH, 'apps', template.path);
267
- const destPath = process.cwd();
268
-
269
- copyBootstrapFiles(sourcePath, destPath, replacements);
270
- }
271
-
272
- async function valdiBootstrap(argv: ArgumentsResolver<CommandParameters>) {
273
- // 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:
274
- // user_config.yaml: User configuration file
275
- // application_names.bzl: Bazel macro file with application names
276
- const curDir = process.cwd();
277
-
278
- console.log(`\nCurrent directory: ${wrapInColor(curDir, ANSI_COLORS.GREEN_COLOR)}`);
279
-
280
- if (isAlreadyInitialized()) {
281
- // Check for existing project files
282
- // If the directory already contains a project, prompt the user to re-run command with explicit --with-cleanup flag
283
- if (argv.getArgument('withCleanup')) {
284
- console.log(wrapInColor('Deleting all files in current directory...', ANSI_COLORS.YELLOW_COLOR));
285
- deleteAll(curDir);
286
- } else {
287
- throw new CliError(
288
- `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.`,
289
- );
290
- }
291
- } else if (!isDirectoryEmpty(curDir)) {
292
- // Folder contains non project files
293
- // Prompt for manual clean up to prevent accidental deletion of important files
294
- throw new CliError(
295
- "Current directory is not empty. Please run 'valdi bootstrap' in an empty directory or manually clean up existing files.",
296
- );
297
- }
298
-
299
- if (!(await getShouldBootstrap(argv))) {
300
- throw new CliError('Bootstrap process aborted.');
301
- }
302
-
303
- const applicationType = await getApplicationType(argv);
304
-
305
- // Prompt user for input
306
- // - Application Name
307
- let projectName = await getProjectName(argv);
308
-
309
- // Validate project name if provided via command line argument
310
- if (argv.getArgument('projectName')) {
311
- const validationError = validateProjectName(projectName);
312
- if (validationError) {
313
- throw new CliError(validationError);
314
- }
315
- projectName = sanitizeProjectName(projectName);
316
- }
317
-
318
- if (!projectName) {
319
- throw new CliError('Project name cannot be empty.');
320
- }
321
-
322
- const valdiReleaseTag = await resolveValdiReleaseTag(argv, VALDI_GIT_URL, DEFAULT_VALDI_RELEASE_TAG);
323
- const valdiWidgetsReleaseTag = await resolveValdiReleaseTag(
324
- argv,
325
- VALDI_WIDGETS_GIT_URL,
326
- DEFAULT_VALDI_WIDGETS_RELEASE_TAG,
327
- 'valdiWidgetsVersion',
328
- );
329
-
330
- const valdiImport = getValdiImport(argv, valdiReleaseTag);
331
- const valdiWidgetsImport = getValdiWidgetsImport(argv, valdiWidgetsReleaseTag);
332
-
333
- // Creating basic config files and Hello World application
334
- console.log(wrapInColor('Initializing config files...', ANSI_COLORS.BLUE_COLOR));
335
- initializeConfigFiles(projectName, applicationType, valdiImport, valdiWidgetsImport);
336
-
337
- // Check bazel version matches .bazelversion
338
- console.log(wrapInColor('Verifying Bazel installation...', ANSI_COLORS.BLUE_COLOR));
339
- const bazel = new BazelClient();
340
- const [returnCode, versionInfo, errors] = await bazel.getVersion();
341
-
342
- if (returnCode !== 0) {
343
- throw new CliError(`Bazel installation failed to verify with errors: ${errors.toString()}`);
344
- }
345
-
346
- console.log(versionInfo);
347
-
348
- if (argv.getArgument('skipProjectsync')) {
349
- console.log(wrapInColor('Skipping projectsync', ANSI_COLORS.YELLOW_COLOR));
350
- } else {
351
- console.log(wrapInColor('Running projectsync...', ANSI_COLORS.BLUE_COLOR));
352
- // eslint-disable-next-line unicorn/no-useless-undefined
353
- await runProjectSync(bazel, await getAllProjectSyncTargets(bazel), undefined, true);
354
- }
355
-
356
- // Finalize message
357
- console.log(wrapInColor('Bootstrap complete!', ANSI_COLORS.GREEN_COLOR));
358
- }
359
-
360
- export const command = 'bootstrap';
361
- export const describe = 'Prepares and initializes a project to build and run in Valdi';
362
- export const builder = (yargs: Argv<CommandParameters>) => {
363
- yargs
364
- .option('confirmBootstrap', {
365
- describe: 'Skip confirmation prompt and start bootstrap process',
366
- type: 'boolean',
367
- alias: 'y',
368
- })
369
- .option('applicationType', {
370
- describe: 'Type of application to create',
371
- alias: 't',
372
- })
373
- .option('projectName', {
374
- describe: 'Name of the project',
375
- type: 'string',
376
- alias: 'n',
377
- })
378
- .option('valdiImport', {
379
- describe:
380
- 'Path to a local checkout of the Valdi repo. If not specified, uses the pinned release (see valdiVersion).',
381
- type: 'string',
382
- alias: 'l',
383
- })
384
- .option('valdiWidgetsImport', {
385
- describe:
386
- 'Path to a local checkout of the Valdi_Widgets repo. If not specified, uses the pinned release (see valdiWidgetsVersion).',
387
- type: 'string',
388
- alias: 'w',
389
- })
390
- .option('valdiVersion', {
391
- describe: `Valdi release tag to use (e.g. v1.0.0). Use "latest" to fetch the GitHub latest release. Default: ${DEFAULT_VALDI_RELEASE_TAG}`,
392
- type: 'string',
393
- })
394
- .option('valdiWidgetsVersion', {
395
- describe: `Valdi_Widgets release tag to use. Use "latest" to fetch the GitHub latest release. Default: ${DEFAULT_VALDI_WIDGETS_RELEASE_TAG}`,
396
- type: 'string',
397
- })
398
- .option('skipProjectsync', {
399
- describe: 'Skip projectsync for testing purposes',
400
- type: 'boolean',
401
- alias: 'p',
402
- })
403
- .option('withCleanup', {
404
- describe: 'Deletes all existing files in the current directory before initiating bootstrap',
405
- type: 'boolean',
406
- alias: 'c',
407
- });
408
- };
409
- 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);