@snap/valdi 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (143) hide show
  1. package/.bazelignore +2 -0
  2. package/.bootstrap/apps/cli_application/AGENTS.md.template +215 -0
  3. package/.bootstrap/apps/cli_application/BUILD.bazel.template +7 -0
  4. package/.bootstrap/apps/cli_application/modules/{{MODULE_NAME}}/BUILD.bazel.template +11 -0
  5. package/.bootstrap/apps/cli_application/modules/{{MODULE_NAME}}/src/index.ts +1 -0
  6. package/.bootstrap/apps/ui_application/.eslint.rc +27 -0
  7. package/.bootstrap/apps/ui_application/AGENTS.md.template +202 -0
  8. package/.bootstrap/apps/ui_application/BUILD.bazel.template +19 -0
  9. package/.bootstrap/apps/ui_application/modules/{{MODULE_NAME}}/BUILD.bazel.template +21 -0
  10. package/.bootstrap/apps/ui_application/modules/{{MODULE_NAME}}/res/valdi@3x.png +0 -0
  11. package/.bootstrap/apps/ui_application/modules/{{MODULE_NAME}}/src/App.tsx +133 -0
  12. package/.bootstrap/apps/ui_application/package.json +24 -0
  13. package/.bootstrap/modules/cpp_bridge_module/BUILD.bazel.template +21 -0
  14. package/.bootstrap/modules/cpp_bridge_module/cpp/CalculatorModuleFactory.cpp.template +29 -0
  15. package/.bootstrap/modules/cpp_bridge_module/src/Calculator.d.ts +1 -0
  16. package/.bootstrap/modules/ios_android_bridge_module/BUILD.bazel.template +39 -0
  17. package/.bootstrap/modules/ios_android_bridge_module/android/CalculatorModuleFactory.kt.template +18 -0
  18. package/.bootstrap/modules/ios_android_bridge_module/ios/SCCCalculatorModuleFactory.m.template +31 -0
  19. package/.bootstrap/modules/ios_android_bridge_module/src/Calculator.d.ts +4 -0
  20. package/.bootstrap/modules/ios_android_view_module/BUILD.bazel.template +41 -0
  21. package/.bootstrap/modules/ios_android_view_module/android/CircleView.kt.template +42 -0
  22. package/.bootstrap/modules/ios_android_view_module/android/CircleViewAttributesBinder.kt.template +60 -0
  23. package/.bootstrap/modules/ios_android_view_module/ios/SCCCircleView.h +6 -0
  24. package/.bootstrap/modules/ios_android_view_module/ios/SCCCircleView.m +82 -0
  25. package/.bootstrap/modules/ios_android_view_module/src/Circle.tsx.template +15 -0
  26. package/.bootstrap/modules/ui_component/BUILD.bazel.template +34 -0
  27. package/.bootstrap/modules/ui_component/src/NewModuleComponent.tsx +45 -0
  28. package/.config/copyconfig.json +10 -0
  29. package/.editorconfig +21 -0
  30. package/.eslintignore +1 -0
  31. package/.eslintrc.js +72 -0
  32. package/.metadata/.bazelrc.template +91 -0
  33. package/.metadata/.bazelversion.template +1 -0
  34. package/.metadata/.eslintrc.js.template +27 -0
  35. package/.metadata/.gitignore.template +4 -0
  36. package/.metadata/.prettierrc.json.template +7 -0
  37. package/.metadata/.watchmanconfig.template +8 -0
  38. package/.metadata/README.md.template +31 -0
  39. package/.metadata/WORKSPACE.template +57 -0
  40. package/.metadata/config.yaml.template +1 -0
  41. package/.metadata/package.json.template +23 -0
  42. package/.prettierignore +2 -0
  43. package/.prettierrc.json +7 -0
  44. package/README.md +123 -0
  45. package/dist/commands/bootstrap.js +233 -0
  46. package/dist/commands/build.js +67 -0
  47. package/dist/commands/devSetup.js +18 -0
  48. package/dist/commands/doctor.js +892 -0
  49. package/dist/commands/export.js +84 -0
  50. package/dist/commands/hotreload.js +89 -0
  51. package/dist/commands/install.js +71 -0
  52. package/dist/commands/lint.js +18 -0
  53. package/dist/commands/lint_commands/lintCheck.js +31 -0
  54. package/dist/commands/lint_commands/lintFormat.js +31 -0
  55. package/dist/commands/log.js +84 -0
  56. package/dist/commands/newModule.js +208 -0
  57. package/dist/commands/package.js +66 -0
  58. package/dist/commands/projectsync.js +316 -0
  59. package/dist/commands/test.js +54 -0
  60. package/dist/core/constants.js +76 -0
  61. package/dist/core/errors.js +12 -0
  62. package/dist/index.js +22 -0
  63. package/dist/setup/DevSetupHelper.js +146 -0
  64. package/dist/setup/linuxSetup.js +31 -0
  65. package/dist/setup/macOSSetup.js +35 -0
  66. package/dist/setup/setupEntryPoint.js +56 -0
  67. package/dist/setup/versions.js +8 -0
  68. package/dist/utils/ArgumentsResolver.js +23 -0
  69. package/dist/utils/BazelClient.js +219 -0
  70. package/dist/utils/Digraph.js +71 -0
  71. package/dist/utils/LoadingIndicator.js +38 -0
  72. package/dist/utils/applicationUtils.js +201 -0
  73. package/dist/utils/buildInfo.js +60 -0
  74. package/dist/utils/byString.js +6 -0
  75. package/dist/utils/cliUtils.js +93 -0
  76. package/dist/utils/copyBootstrapFiles.js +26 -0
  77. package/dist/utils/deviceUtils.js +72 -0
  78. package/dist/utils/errorUtils.js +55 -0
  79. package/dist/utils/fileUtils.js +204 -0
  80. package/dist/utils/githubUtils.js +8 -0
  81. package/dist/utils/jsonUtils.js +28 -0
  82. package/dist/utils/lintUtils.js +149 -0
  83. package/dist/utils/logUtils.js +8 -0
  84. package/dist/utils/pathUtils.js +12 -0
  85. package/dist/utils/stringUtils.js +17 -0
  86. package/dist/utils/stringUtils.spec.js +18 -0
  87. package/dist/utils/tempDir.js +26 -0
  88. package/dist/utils/zipUtils.js +16 -0
  89. package/package.json +51 -0
  90. package/prettier.config.js +4 -0
  91. package/spec/support/jasmine.json +6 -0
  92. package/src/commands/bootstrap.ts +317 -0
  93. package/src/commands/build.ts +89 -0
  94. package/src/commands/devSetup.ts +17 -0
  95. package/src/commands/doctor.ts +1422 -0
  96. package/src/commands/export.ts +131 -0
  97. package/src/commands/hotreload.ts +108 -0
  98. package/src/commands/install.ts +93 -0
  99. package/src/commands/lint.ts +15 -0
  100. package/src/commands/lint_commands/lintCheck.ts +53 -0
  101. package/src/commands/lint_commands/lintFormat.ts +49 -0
  102. package/src/commands/log.ts +108 -0
  103. package/src/commands/newModule.ts +287 -0
  104. package/src/commands/package.ts +102 -0
  105. package/src/commands/projectsync.ts +488 -0
  106. package/src/commands/test.ts +68 -0
  107. package/src/core/constants.ts +95 -0
  108. package/src/core/errors.ts +10 -0
  109. package/src/index.ts +22 -0
  110. package/src/setup/DevSetupHelper.ts +188 -0
  111. package/src/setup/linuxSetup.ts +38 -0
  112. package/src/setup/macOSSetup.ts +42 -0
  113. package/src/setup/setupEntryPoint.ts +64 -0
  114. package/src/setup/versions.ts +8 -0
  115. package/src/utils/ArgumentsResolver.ts +23 -0
  116. package/src/utils/BazelClient.ts +285 -0
  117. package/src/utils/Digraph.ts +81 -0
  118. package/src/utils/LoadingIndicator.ts +43 -0
  119. package/src/utils/applicationUtils.ts +276 -0
  120. package/src/utils/buildInfo.ts +99 -0
  121. package/src/utils/byString.ts +3 -0
  122. package/src/utils/cliUtils.ts +112 -0
  123. package/src/utils/copyBootstrapFiles.ts +30 -0
  124. package/src/utils/deviceUtils.ts +76 -0
  125. package/src/utils/errorUtils.ts +63 -0
  126. package/src/utils/fileUtils.ts +257 -0
  127. package/src/utils/githubUtils.ts +6 -0
  128. package/src/utils/jsonUtils.ts +30 -0
  129. package/src/utils/lintUtils.ts +190 -0
  130. package/src/utils/logUtils.ts +9 -0
  131. package/src/utils/pathUtils.ts +12 -0
  132. package/src/utils/stringUtils.spec.ts +19 -0
  133. package/src/utils/stringUtils.ts +15 -0
  134. package/src/utils/tempDir.ts +24 -0
  135. package/src/utils/zipUtils.ts +14 -0
  136. package/test/ValdiSmokeTest.ts +278 -0
  137. package/test/helpers/AsyncHelpers.ts +113 -0
  138. package/test/helpers/CommandHelpers.ts +37 -0
  139. package/test/helpers/ProjectHelpers.ts +153 -0
  140. package/test/helpers/StreamHelpers.ts +37 -0
  141. package/test/helpers/TypeScriptClient.ts +217 -0
  142. package/tsconfig.dist.json +8 -0
  143. package/tsconfig.json +42 -0
@@ -0,0 +1,317 @@
1
+ import path from 'path';
2
+ import inquirer from 'inquirer';
3
+ import type { Argv } from 'yargs';
4
+ import { ANSI_COLORS, BOOTSTRAP_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 } from '../utils/stringUtils';
23
+ import { getAllProjectSyncTargets, runProjectSync } from './projectsync';
24
+ import { resolveLatestReleaseRef } from '../utils/githubUtils';
25
+
26
+ interface CommandParameters {
27
+ confirmBootstrap: boolean;
28
+ projectName: string;
29
+ applicationType: string;
30
+ valdiImport: string;
31
+ valdiWidgetsImport: string;
32
+ skipProjectsync: boolean;
33
+ withCleanup: boolean;
34
+ }
35
+
36
+ interface ApplicationTemplate {
37
+ name: string;
38
+ path: string;
39
+ description: string;
40
+ }
41
+
42
+ const ALL_APPLICATION_TEMPLATES: readonly ApplicationTemplate[] = [
43
+ {
44
+ name: 'UI Application',
45
+ path: 'ui_application',
46
+ description: `An application rendering UI in a window on iOS, Android and macOS.`,
47
+ },
48
+ {
49
+ name: 'CLI Application',
50
+ path: 'cli_application',
51
+ description: `A command line application that runs in a terminal`,
52
+ },
53
+ ];
54
+
55
+ const VALDI_GIT_URL = 'https://github.com/Snapchat/Valdi';
56
+ const VALDI_WIDGETS_GIT_URL = 'https://github.com/Snapchat/Valdi_Widgets';
57
+
58
+ const DEFAULT_VALDI_IMPORT = `
59
+ http_archive(
60
+ name = "valdi",
61
+ strip_prefix = "Valdi-{{VALDI_RELEASE_TAG}}",
62
+ url = "${VALDI_GIT_URL}/archive/{{VALDI_RELEASE_REF}}.tar.gz",
63
+ )`;
64
+
65
+ const DEFAULT_VALDI_WIDGETS_IMPORT = `
66
+ http_archive(
67
+ name = "valdi_widgets",
68
+ strip_prefix = "Valdi_Widgets-{{VALDI_WIDGETS_RELEASE_TAG}}",
69
+ url = "${VALDI_WIDGETS_GIT_URL}/archive/{{VALDI_WIDGETS_RELEASE_REF}}.tar.gz",
70
+ )`;
71
+
72
+ const LOCAL_VALDI_IMPORT_TEMPLATE = `
73
+ local_repository(
74
+ name = "valdi",
75
+ path = "{{PATH}}",
76
+ )
77
+ `;
78
+
79
+ const LOCAL_VALDI_WIDGETS_IMPORT_TEMPLATE = `
80
+ local_repository(
81
+ name = "valdi_widgets",
82
+ path = "{{PATH}}",
83
+ )
84
+ `;
85
+
86
+ function isAlreadyInitialized(): boolean {
87
+ return fileExists(path.join(process.cwd(), 'WORKSPACE'));
88
+ }
89
+
90
+ async function getShouldBootstrap(argv: ArgumentsResolver<CommandParameters>): Promise<boolean> {
91
+ // Get confirmation on directory path
92
+ return argv.getArgumentOrResolve('confirmBootstrap', () => {
93
+ return getUserConfirmation('Do you want to create a new project in the current directory?', true);
94
+ });
95
+ }
96
+
97
+ const defaultProjectName = path.basename(process.cwd());
98
+
99
+ async function getApplicationType(argv: ArgumentsResolver<CommandParameters>): Promise<ApplicationTemplate> {
100
+ const applicationType = argv.getArgument('applicationType');
101
+
102
+ if (applicationType) {
103
+ const target = ALL_APPLICATION_TEMPLATES.find(target => target.path === applicationType);
104
+
105
+ if (target) {
106
+ return target;
107
+ } else {
108
+ throw new CliError(`Unknown application type: ${applicationType}`);
109
+ }
110
+ }
111
+
112
+ const choices: CliChoice<ApplicationTemplate>[] = ALL_APPLICATION_TEMPLATES.map(target => ({
113
+ name: `${wrapInColor(target.name, ANSI_COLORS.GREEN_COLOR)} . ${target.description}`,
114
+ value: target,
115
+ }));
116
+
117
+ return await getUserChoice(choices, `Please choose the application type:`);
118
+ }
119
+
120
+ async function getProjectName(argv: ArgumentsResolver<CommandParameters>): Promise<string> {
121
+ return argv.getArgumentOrResolve('projectName', async () => {
122
+ const result = await inquirer.prompt<{ projectName: string }>([
123
+ {
124
+ type: 'input',
125
+ name: 'projectName',
126
+ message: 'Please provide a name for this project:',
127
+ default: defaultProjectName,
128
+ },
129
+ ]);
130
+
131
+ return result.projectName;
132
+ });
133
+ }
134
+
135
+ function getValdiImport(argv: ArgumentsResolver<CommandParameters>, valdiReleaseRef: string): string {
136
+ const valdiImport = argv.getArgument('valdiImport');
137
+ if (valdiImport) {
138
+ return processReplacements(LOCAL_VALDI_IMPORT_TEMPLATE, { PATH: valdiImport });
139
+ } else {
140
+ const valdiReleaseTag = valdiReleaseRef.split('/').pop()!;
141
+ return processReplacements(DEFAULT_VALDI_IMPORT, {
142
+ VALDI_RELEASE_REF: valdiReleaseRef,
143
+ VALDI_RELEASE_TAG: valdiReleaseTag,
144
+ });
145
+ }
146
+ }
147
+
148
+ function getValdiWidgetsImport(argv: ArgumentsResolver<CommandParameters>, valdiWidgetsReleaseRef: string): string {
149
+ const valdiWidgetsImport = argv.getArgument('valdiWidgetsImport');
150
+ if (valdiWidgetsImport) {
151
+ return processReplacements(LOCAL_VALDI_WIDGETS_IMPORT_TEMPLATE, { PATH: valdiWidgetsImport });
152
+ } else {
153
+ const valdiWidgetsReleaseTag = valdiWidgetsReleaseRef.split('/').pop()!;
154
+ return processReplacements(DEFAULT_VALDI_WIDGETS_IMPORT, {
155
+ VALDI_WIDGETS_RELEASE_REF: valdiWidgetsReleaseRef,
156
+ VALDI_WIDGETS_RELEASE_TAG: valdiWidgetsReleaseTag,
157
+ });
158
+ }
159
+ }
160
+
161
+ // Create files from templates
162
+ function initializeConfigFiles(
163
+ projectName: string,
164
+ template: ApplicationTemplate,
165
+ valdiImport: string,
166
+ valdiWidgetsImport: string,
167
+ ) {
168
+
169
+ const TEMPLATE_FILES = [
170
+ TemplateFile.init(TEMPLATE_BASE_PATHS.USER_CONFIG).withOutputPath(resolveFilePath(VALDI_CONFIG_PATHS[0] ?? '')),
171
+ TemplateFile.init(TEMPLATE_BASE_PATHS.BAZEL_VERSION),
172
+ TemplateFile.init(TEMPLATE_BASE_PATHS.WORKSPACE).withReplacements({
173
+ WORKSPACE_NAME: projectName,
174
+ VALDI_IMPORT: valdiImport,
175
+ VALDI_WIDGETS_IMPORT: valdiWidgetsImport,
176
+ }),
177
+ TemplateFile.init(TEMPLATE_BASE_PATHS.BAZEL_RC),
178
+ TemplateFile.init(TEMPLATE_BASE_PATHS.README),
179
+ TemplateFile.init(TEMPLATE_BASE_PATHS.GIT_IGNORE),
180
+ TemplateFile.init(TEMPLATE_BASE_PATHS.WATCHMAN_CONFIG),
181
+ ];
182
+
183
+ TEMPLATE_FILES.forEach(templateFile => {
184
+ console.log(
185
+ wrapInColor(`Creating ${templateFile.baseName} in ${templateFile.outputPath}...`, ANSI_COLORS.YELLOW_COLOR),
186
+ );
187
+ templateFile.expandTemplate();
188
+ });
189
+
190
+ // Setup hello world application
191
+ console.log(wrapInColor(`Initializing ${template.name} application...`, ANSI_COLORS.YELLOW_COLOR));
192
+ const sourcePath = path.join(BOOTSTRAP_DIR_PATH, 'apps', template.path);
193
+ const destPath = process.cwd();
194
+
195
+ const replacements: Replacements = {
196
+ MODULE_NAME: projectName,
197
+ MODULE_NAME_PASCAL_CASED: toPascalCase(projectName),
198
+ };
199
+
200
+ copyBootstrapFiles(sourcePath, destPath, replacements);
201
+ }
202
+
203
+ async function valdiBootstrap(argv: ArgumentsResolver<CommandParameters>) {
204
+ // 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:
205
+ // user_config.yaml: User configuration file
206
+ // application_names.bzl: Bazel macro file with application names
207
+ const curDir = process.cwd();
208
+
209
+ console.log(`\nCurrent directory: ${wrapInColor(curDir, ANSI_COLORS.GREEN_COLOR)}`);
210
+
211
+ if (isAlreadyInitialized()) {
212
+ // Check for existing project files
213
+ // If the directory already contains a project, prompt the user to re-run command with explicit --with-cleanup flag
214
+ if (argv.getArgument('withCleanup')) {
215
+ console.log(wrapInColor('Deleting all files in current directory...', ANSI_COLORS.YELLOW_COLOR));
216
+ deleteAll(curDir);
217
+ } else {
218
+ throw new CliError(
219
+ `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.`,
220
+ );
221
+ }
222
+ } else if (!isDirectoryEmpty(curDir)) {
223
+ // Folder contains non project files
224
+ // Prompt for manual clean up to prevent accidental deletion of important files
225
+ throw new CliError(
226
+ "Current directory is not empty. Please run 'valdi bootstrap' in an empty directory or manually clean up existing files.",
227
+ );
228
+ }
229
+
230
+ if (!(await getShouldBootstrap(argv))) {
231
+ throw new CliError('Bootstrap process aborted.');
232
+ }
233
+
234
+ const applicationType = await getApplicationType(argv);
235
+
236
+ // Prompt user for input
237
+ // - Application Name
238
+ const projectName = await getProjectName(argv);
239
+ if (!projectName) {
240
+ throw new CliError('Project name cannot be empty.');
241
+ }
242
+
243
+ const valdiCommitHash = await resolveLatestReleaseRef(`${VALDI_GIT_URL}.git`);
244
+ const valdiWidgetsCommitHash = await resolveLatestReleaseRef(`${VALDI_WIDGETS_GIT_URL}.git`);
245
+
246
+ const valdiImport = getValdiImport(argv, valdiCommitHash);
247
+ const valdiWidgetsImport = getValdiWidgetsImport(argv, valdiWidgetsCommitHash);
248
+
249
+ // Creating basic config files and Hello World application
250
+ console.log(wrapInColor('Initializing config files...', ANSI_COLORS.BLUE_COLOR));
251
+ initializeConfigFiles(projectName, applicationType, valdiImport, valdiWidgetsImport);
252
+
253
+ // Check bazel version matches .bazelversion
254
+ console.log(wrapInColor('Verifying Bazel installation...', ANSI_COLORS.BLUE_COLOR));
255
+ const bazel = new BazelClient();
256
+ const [returnCode, versionInfo, errors] = await bazel.getVersion();
257
+
258
+ if (returnCode !== 0) {
259
+ throw new CliError(`Bazel installation failed to verify with errors: ${errors.toString()}`);
260
+ }
261
+
262
+ console.log(versionInfo);
263
+
264
+ if (argv.getArgument('skipProjectsync')) {
265
+ console.log(wrapInColor('Skipping projectsync', ANSI_COLORS.YELLOW_COLOR));
266
+ } else {
267
+ console.log(wrapInColor('Running projectsync...', ANSI_COLORS.BLUE_COLOR));
268
+ // eslint-disable-next-line unicorn/no-useless-undefined
269
+ await runProjectSync(bazel, await getAllProjectSyncTargets(bazel), undefined, true);
270
+ }
271
+
272
+ // Finalize message
273
+ console.log(wrapInColor('Bootstrap complete!', ANSI_COLORS.GREEN_COLOR));
274
+ }
275
+
276
+ export const command = 'bootstrap';
277
+ export const describe = 'Prepares and initializes a project to build and run in Valdi';
278
+ export const builder = (yargs: Argv<CommandParameters>) => {
279
+ yargs
280
+ .option('confirmBootstrap', {
281
+ describe: 'Skip confirmation prompt and start bootstrap process',
282
+ type: 'boolean',
283
+ alias: 'y',
284
+ })
285
+ .option('applicationType', {
286
+ describe: 'Type of application to create',
287
+ alias: 't',
288
+ })
289
+ .option('projectName', {
290
+ describe: 'Name of the project',
291
+ type: 'string',
292
+ alias: 'n',
293
+ })
294
+ .option('valdiImport', {
295
+ describe:
296
+ 'Path to a local checkout of the Valdi repo. If not specified, uses the latest release from GitHub.',
297
+ type: 'string',
298
+ alias: 'l',
299
+ })
300
+ .option('valdiWidgetsImport', {
301
+ describe:
302
+ 'Path to a local checkout of the Valdi_Widgets repo. If not specified, uses the latest release from GitHub.',
303
+ type: 'string',
304
+ alias: 'w',
305
+ })
306
+ .option('skipProjectsync', {
307
+ describe: 'Skip projectsync for testing purposes',
308
+ type: 'boolean',
309
+ alias: 'p',
310
+ })
311
+ .option('withCleanup', {
312
+ describe: 'Deletes all existing files in the current directory before initiating bootstrap',
313
+ type: 'boolean',
314
+ alias: 'c',
315
+ });
316
+ };
317
+ export const handler = makeCommandHandler(valdiBootstrap);
@@ -0,0 +1,89 @@
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
@@ -0,0 +1,17 @@
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);