@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,286 +0,0 @@
1
- import fs from 'fs';
2
- import inquirer from 'inquirer';
3
- import path from 'path';
4
- import type { Argv } from 'yargs';
5
- import { ANSI_COLORS, BOOTSTRAP_DIR_PATH } from '../core/constants';
6
- import { CliError } from '../core/errors';
7
- import type { ArgumentsResolver } from '../utils/ArgumentsResolver';
8
- import { BazelClient } from '../utils/BazelClient';
9
- import type { CliChoice } from '../utils/cliUtils';
10
- import { getUserChoice } from '../utils/cliUtils';
11
- import { copyBootstrapFiles } from '../utils/copyBootstrapFiles';
12
- import { makeCommandHandler } from '../utils/errorUtils';
13
- import type { Replacements } from '../utils/fileUtils';
14
- import { fileExists } from '../utils/fileUtils';
15
- import { wrapInColor } from '../utils/logUtils';
16
- import { toPascalCase, toSnakeCase, sanitizeProjectName, validateProjectName } from '../utils/stringUtils';
17
-
18
- const referenceString = `
19
- ******************************************
20
- Valdi Module Creation Guide
21
- ******************************************
22
-
23
- Requirements for Valdi module names:
24
- - May contain: A-Z, a-z, 0-9, '-', '_', '.'
25
- - Must start with a letter.
26
-
27
- Recommended Directory Structure:
28
- my_application/ # Root directory of your application
29
- ├── WORKSPACE # Bazel Workspace
30
- ├── BUILD.bazel # Bazel build
31
- └── modules/
32
- ├── module_a/
33
- │ ├── BUILD.bazel
34
- │ ├── android/ # Native Android sources
35
- │ ├── ios/ # Native iOS sources
36
- │ ├── cpp/ # Native C++ sources
37
- │ └── src/ # Valdi sources
38
- │ └── ModuleAComponent.tsx
39
- ├── module_b/
40
- ├── BUILD.bazel
41
- │ ├── res/ # Image and font resources
42
- │ ├── strings/ # Localizable strings
43
- └── src/
44
- └── ModuleBComponent.tsx
45
-
46
- For more comprehensive details, refer to the core-module documentation:
47
- https://github.com/Snapchat/Valdi/blob/main/docs/docs/core-module.md
48
-
49
- ******************************************
50
- `;
51
-
52
- const ALL_MODULE_TEMPLATES: readonly ModuleTemplate[] = [
53
- {
54
- name: 'UI Component',
55
- path: 'ui_component',
56
- description: `Exports a Valdi component, which can render UI elements`,
57
- },
58
- {
59
- name: 'iOS/Android Bridge module',
60
- path: 'ios_android_bridge_module',
61
- description: `Bridge module with a TypeScript API backed by Objective-C and Kotlin implementation`,
62
- },
63
- {
64
- name: 'C++ Bridge module',
65
- path: 'cpp_bridge_module',
66
- description: `Bridge module with a TypeScript API backed by a cross-platform C++ implementation`,
67
- },
68
- {
69
- name: 'iOS/Android View module',
70
- path: 'ios_android_view_module',
71
- description: `iOS and Android view exported to TypeScript, rendered through a Valdi component`,
72
- },
73
- ];
74
-
75
- interface CommandParameters {
76
- debug: boolean;
77
- skipChecks: boolean;
78
- moduleName: string;
79
- template?: string
80
- }
81
-
82
- interface Checks {
83
- confirmBazelWorkspace?: boolean;
84
- confirmValdiPath?: boolean;
85
- valdiModulePath?: string;
86
- }
87
-
88
- interface ModuleTemplate {
89
- name: string;
90
- path: string;
91
- description: string;
92
- }
93
-
94
- async function promptChecks(): Promise<Checks> {
95
- let answers: Checks = {};
96
-
97
- /**
98
- * Verify Bazel Workspace
99
- */
100
- const bazelWorkspacePath = await getBazelWorkspaceRoot();
101
-
102
- answers = await inquirer.prompt<Checks>(
103
- [
104
- {
105
- type: 'confirm',
106
- name: 'confirmBazelWorkspace',
107
- message: 'Bazel WORKSPACE not found (did you run `valdi bootstrap` first?). Continue anyway?',
108
- default: true,
109
- when() {
110
- return !bazelWorkspacePath;
111
- },
112
- },
113
- ],
114
- answers,
115
- );
116
-
117
- if (!bazelWorkspacePath && !answers.confirmBazelWorkspace) {
118
- throw new CliError('Aborting.');
119
- }
120
-
121
- /**
122
- * Verify directory structure
123
- */
124
- answers = await inquirer.prompt<Checks>(
125
- {
126
- type: 'confirm',
127
- name: 'confirmValdiPath',
128
- message:
129
- '/modules directory not found (did you run `valdi bootstrap` first?). Create module in current directory?',
130
- default: true,
131
- when(answers) {
132
- const curDir = process.cwd();
133
- const parsedPath = path.parse(curDir);
134
- if (parsedPath.base === 'modules') {
135
- // Create the new module in the current directory
136
- answers.valdiModulePath = curDir;
137
- } else if (curDir === bazelWorkspacePath) {
138
- // Create the new module in ./modules
139
- const valdiPath = path.join(curDir, 'modules');
140
- if (fs.existsSync(valdiPath)) {
141
- answers.valdiModulePath = valdiPath;
142
- }
143
- }
144
-
145
- return !answers.valdiModulePath;
146
- },
147
- },
148
- answers,
149
- );
150
-
151
- if (!answers.valdiModulePath && !answers.confirmValdiPath) {
152
- throw new CliError('Aborting.');
153
- }
154
-
155
- return answers;
156
- }
157
-
158
- async function getModuleName(argv: ArgumentsResolver<CommandParameters>): Promise<string> {
159
- return argv.getArgumentOrResolve('moduleName', async () => {
160
- const result = await inquirer.prompt<{ moduleName?: string }>(
161
- [
162
- {
163
- type: 'input',
164
- name: 'moduleName',
165
- message: 'Please provide a name for this module:',
166
- validate: (input: string) => {
167
- const validationError = validateProjectName(input);
168
- if (validationError) {
169
- return validationError;
170
- }
171
-
172
- const sanitized = sanitizeProjectName(input);
173
- const destPath = path.join(process.cwd(), sanitized);
174
- if (fileExists(destPath)) {
175
- return `Path ${destPath} already exists. Choose a different name or delete the folder and try again.`;
176
- }
177
-
178
- return true;
179
- },
180
- },
181
- ],
182
- {},
183
- );
184
-
185
- return sanitizeProjectName(result.moduleName ?? '');
186
- });
187
- }
188
-
189
- async function finalConfirmation(destPath: string, argv: ArgumentsResolver<CommandParameters>): Promise<boolean> {
190
- return argv.getArgumentOrResolve('skipChecks', async () => {
191
- const confirmMessage = `
192
- Create module?
193
- Path: ${wrapInColor(destPath, ANSI_COLORS.GREEN_COLOR)}
194
- `;
195
- const answers = await inquirer.prompt<{ confirm?: boolean }>(
196
- [
197
- {
198
- type: 'confirm',
199
- name: 'confirm',
200
- message: confirmMessage,
201
- default: true,
202
- },
203
- ],
204
- {},
205
- );
206
-
207
- return answers.confirm ?? false;
208
- });
209
- }
210
-
211
- function getBazelWorkspaceRoot() {
212
- return new BazelClient().getWorkspaceRoot();
213
- }
214
-
215
- async function valdiNewModule(argv: ArgumentsResolver<CommandParameters>) {
216
- console.log(referenceString);
217
- const skipChecks = argv.getArgument('skipChecks');
218
-
219
- const checks: Checks = skipChecks ? {} : await promptChecks();
220
- const valdiModulePath = checks.valdiModulePath ?? path.join(await getBazelWorkspaceRoot(), 'modules');
221
-
222
- let moduleName = await getModuleName(argv);
223
-
224
- // Validate module name if provided via command line argument
225
- if (argv.getArgument('moduleName')) {
226
- const validationError = validateProjectName(moduleName);
227
- if (validationError) {
228
- throw new CliError(validationError);
229
- }
230
- moduleName = sanitizeProjectName(moduleName);
231
- }
232
-
233
- const destPath = path.join(valdiModulePath, moduleName);
234
- const didConfirm = skipChecks || (await finalConfirmation(destPath, argv));
235
- if (!didConfirm) {
236
- throw new CliError('Cancelled new module creation.');
237
- }
238
-
239
- /**
240
- * Do not overwrite existing files
241
- */
242
- if (fs.existsSync(destPath)) {
243
- throw new CliError(`Path already exists ${destPath}`);
244
- }
245
-
246
- const choices: CliChoice<ModuleTemplate>[] = ALL_MODULE_TEMPLATES.map(target => ({
247
- name: `${wrapInColor(target.name, ANSI_COLORS.GREEN_COLOR)} . ${target.description}`,
248
- value: target,
249
- }));
250
-
251
- const templateOption = argv.getArgument('template');
252
- const template = templateOption ? ALL_MODULE_TEMPLATES.find(template => template.path === templateOption) : undefined;
253
- const moduleTemplate = template ?? await getUserChoice(choices, `Please choose the module type:`);
254
-
255
- /**
256
- * Copy bootstrap files
257
- */
258
- const sourcePath = path.join(BOOTSTRAP_DIR_PATH, 'modules', moduleTemplate.path);
259
- const replacements: Replacements = {
260
- MODULE_NAME: moduleName,
261
- MODULE_NAME_PASCAL_CASED: toPascalCase(moduleName),
262
- };
263
-
264
- copyBootstrapFiles(sourcePath, destPath, replacements);
265
-
266
- // Finalize message
267
- console.log(`Success! New module directory: ${wrapInColor(destPath, ANSI_COLORS.GREEN_COLOR)}`);
268
- }
269
-
270
- export const command = `new_module [module-name]`;
271
- export const describe = referenceString;
272
- export const builder = (yargs: Argv<CommandParameters>) => {
273
- yargs
274
- .positional('module-name', {
275
- describe: 'Name of the Valdi module.',
276
- })
277
- .option('template', {
278
- describe: 'module template to use, will skip the prompt',
279
- choices: ALL_MODULE_TEMPLATES.map(template => template.path),
280
- })
281
- .option('skip-checks', {
282
- describe: 'Skips confirmation prompts.',
283
- type: 'boolean',
284
- });
285
- };
286
- export const handler = makeCommandHandler(valdiNewModule);
@@ -1,102 +0,0 @@
1
- import * as fs from 'fs';
2
- import path from 'path';
3
- import type { Argv } from 'yargs';
4
- import type { PLATFORM } from '../core/constants';
5
- import { ALL_ARCHITECTURES, ANSI_COLORS } from '../core/constants';
6
- import { CliError } from '../core/errors';
7
- import type { ArgumentsResolver } from '../utils/ArgumentsResolver';
8
- import { BazelClient } from '../utils/BazelClient';
9
- import type { SharedCommandParameters } from '../utils/applicationUtils';
10
- import {
11
- applicationExtensionForPlatform,
12
- getApplicationTargetTagForPlatform,
13
- getOutputFilePath,
14
- makeArgsBuilder,
15
- resolveBazelBuildArgs,
16
- selectBazelTarget,
17
- } from '../utils/applicationUtils';
18
- import { logReproduceThisCommandIfNeeded, makeCommandHandler } from '../utils/errorUtils';
19
- import { wrapInColor } from '../utils/logUtils';
20
-
21
- interface CommandParameters extends SharedCommandParameters {
22
- application: string | undefined;
23
- target_output_path: string | undefined;
24
- output_path: string;
25
- }
26
-
27
- async function valdiPackage(argv: ArgumentsResolver<CommandParameters>): Promise<void> {
28
- const bazel = new BazelClient();
29
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
30
- const platform = argv.getArgument('platform') as PLATFORM;
31
- const bazelArgs = resolveBazelBuildArgs(
32
- platform,
33
- argv.getArgument('build_config'),
34
- ALL_ARCHITECTURES,
35
- /* forDevice */ true,
36
- argv.getArgument('enable_runtime_logs'),
37
- argv.getArgument('enable_runtime_traces'),
38
- argv.getArgument('bazel_args'),
39
- );
40
-
41
- const resolvedOutputPath = path.resolve(argv.getArgument('output_path'));
42
- const expectedExtension = applicationExtensionForPlatform(platform);
43
- if (expectedExtension.length > 0 && !resolvedOutputPath.endsWith(expectedExtension)) {
44
- throw new CliError(`Output path for platform '${platform}' must have ${expectedExtension} file extension`);
45
- }
46
-
47
- if (fs.existsSync(resolvedOutputPath)) {
48
- fs.rmSync(resolvedOutputPath);
49
- }
50
- const directoryPath = path.dirname(resolvedOutputPath);
51
- if (!fs.existsSync(directoryPath)) {
52
- fs.mkdirSync(directoryPath, { recursive: true });
53
- }
54
-
55
- const application = await argv.getArgumentOrResolve('application', () => {
56
- console.log('No application specified querying available targets...');
57
- return selectBazelTarget(
58
- bazel,
59
- getApplicationTargetTagForPlatform(platform),
60
- 'valdi_application',
61
- 'Please select an application target to package:',
62
- );
63
- });
64
- console.log('Resolving output paths...');
65
-
66
- const bazelOutputFilePath = await argv.getArgumentOrResolve('target_output_path', () => {
67
- console.log('Resolving output paths...');
68
- return getOutputFilePath(bazel, expectedExtension, application, bazelArgs);
69
- });
70
- console.log(`Building: ${wrapInColor(application, ANSI_COLORS.GREEN_COLOR)}`);
71
-
72
- await bazel.buildTarget(application, bazelArgs);
73
-
74
- console.log(`Copying built target to ${resolvedOutputPath}...`);
75
- await fs.promises.copyFile(bazelOutputFilePath, resolvedOutputPath);
76
-
77
- logReproduceThisCommandIfNeeded(argv);
78
- console.log('All done!');
79
- }
80
-
81
- export const command = 'package <platform>';
82
- export const describe = 'Build and package a Valdi application';
83
- export const builder = makeArgsBuilder((yargs: Argv<CommandParameters>) => {
84
- yargs
85
- .option('application', {
86
- describe: 'Name of the application to build',
87
- type: 'string',
88
- requiresArg: true,
89
- })
90
- .option('target_output_path', {
91
- describe: 'The output path for the Bazel target',
92
- type: 'string',
93
- requiresArg: true,
94
- })
95
- .option('output_path', {
96
- describe: 'The path where to store the built application package',
97
- type: 'string',
98
- requiresArg: true,
99
- })
100
- .demandOption('output_path');
101
- });
102
- export const handler = makeCommandHandler(valdiPackage);