@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.
- package/README.md +22 -10
- package/bundled-skills/CONTRIBUTING_SKILLS.md +74 -0
- package/bundled-skills/registry.json +20 -0
- package/bundled-skills/skills/valdi-android/skill.md +89 -0
- package/bundled-skills/skills/valdi-async/skill.md +246 -0
- package/bundled-skills/skills/valdi-async/tests/BUILD.bazel +19 -0
- package/bundled-skills/skills/valdi-async/tests/README.md +25 -0
- package/bundled-skills/skills/valdi-async/tests/src/reference.tsx +210 -0
- package/bundled-skills/skills/valdi-async/tests/tsconfig.json +1 -0
- package/bundled-skills/skills/valdi-bazel/skill.md +122 -0
- package/bundled-skills/skills/valdi-compiler/skill.md +108 -0
- package/bundled-skills/skills/valdi-component-tests/skill.md +430 -0
- package/bundled-skills/skills/valdi-component-tests/tests/BUILD.bazel +24 -0
- package/bundled-skills/skills/valdi-component-tests/tests/README.md +35 -0
- package/bundled-skills/skills/valdi-component-tests/tests/src/ProfileCard.tsx +38 -0
- package/bundled-skills/skills/valdi-component-tests/tests/test/ProfileCardTest.spec.tsx +107 -0
- package/bundled-skills/skills/valdi-component-tests/tests/tsconfig.json +1 -0
- package/bundled-skills/skills/valdi-cpp-runtime/skill.md +103 -0
- package/bundled-skills/skills/valdi-custom-view/skill.md +62 -0
- package/bundled-skills/skills/valdi-ios/skill.md +93 -0
- package/bundled-skills/skills/valdi-migrate/skill.md +175 -0
- package/bundled-skills/skills/valdi-migrate/tests/BUILD.bazel +23 -0
- package/bundled-skills/skills/valdi-migrate/tests/README.md +70 -0
- package/bundled-skills/skills/valdi-migrate/tests/check_antipatterns.py +89 -0
- package/bundled-skills/skills/valdi-migrate/tests/compose_example.kt +94 -0
- package/bundled-skills/skills/valdi-migrate/tests/flutter_example.dart +129 -0
- package/bundled-skills/skills/valdi-migrate/tests/react_example.tsx +98 -0
- package/bundled-skills/skills/valdi-migrate/tests/src/expected_valdi.tsx +267 -0
- package/bundled-skills/skills/valdi-migrate/tests/tsconfig.json +3 -0
- package/{.metadata/.cursorrules.template → bundled-skills/skills/valdi-overview/skill.md} +23 -13
- package/bundled-skills/skills/valdi-perf/skill.md +197 -0
- package/bundled-skills/skills/valdi-perf/tests/BUILD.bazel +19 -0
- package/bundled-skills/skills/valdi-perf/tests/README.md +26 -0
- package/bundled-skills/skills/valdi-perf/tests/src/reference.tsx +202 -0
- package/bundled-skills/skills/valdi-perf/tests/tsconfig.json +1 -0
- package/bundled-skills/skills/valdi-polyglot-module/skill.md +85 -0
- package/bundled-skills/skills/valdi-setup/skill.md +129 -0
- package/bundled-skills/skills/valdi-testing/skill.md +65 -0
- package/bundled-skills/skills/valdi-tsx/skill.md +385 -0
- package/bundled-skills/skills/valdi-tsx/tests/BUILD.bazel +19 -0
- package/bundled-skills/skills/valdi-tsx/tests/README.md +29 -0
- package/bundled-skills/skills/valdi-tsx/tests/src/reference.tsx +173 -0
- package/bundled-skills/skills/valdi-tsx/tests/tsconfig.json +1 -0
- package/dist/commands/bootstrap.js +3 -9
- package/dist/commands/newModule.js +10 -14
- package/dist/commands/skills.js +16 -0
- package/dist/commands/skills_commands/create.js +125 -0
- package/dist/commands/skills_commands/install.js +96 -0
- package/dist/commands/skills_commands/list.js +83 -0
- package/dist/commands/skills_commands/remove.js +41 -0
- package/dist/commands/skills_commands/update.js +59 -0
- package/dist/core/constants.js +1 -1
- package/dist/index.js +5 -0
- package/dist/setup/versions.js +1 -1
- package/dist/utils/skillsAdapters.js +140 -0
- package/dist/utils/skillsRegistry.js +40 -0
- package/package.json +6 -1
- package/.bazelignore +0 -2
- package/.bootstrap/apps/cli_application/AGENTS.md.template +0 -291
- package/.bootstrap/apps/cli_application/BUILD.bazel.template +0 -7
- package/.bootstrap/apps/cli_application/modules/{{MODULE_NAME}}/BUILD.bazel.template +0 -11
- package/.bootstrap/apps/cli_application/modules/{{MODULE_NAME}}/src/index.ts +0 -1
- package/.bootstrap/apps/ui_application/.eslint.rc +0 -27
- package/.bootstrap/apps/ui_application/AGENTS.md.template +0 -278
- package/.bootstrap/apps/ui_application/BUILD.bazel.template +0 -19
- package/.bootstrap/apps/ui_application/modules/{{MODULE_NAME}}/BUILD.bazel.template +0 -21
- package/.bootstrap/apps/ui_application/modules/{{MODULE_NAME}}/res/valdi@3x.png +0 -0
- package/.bootstrap/apps/ui_application/modules/{{MODULE_NAME}}/src/App.tsx +0 -133
- package/.bootstrap/apps/ui_application/package.json +0 -24
- package/.bootstrap/modules/cpp_bridge_module/BUILD.bazel.template +0 -21
- package/.bootstrap/modules/cpp_bridge_module/cpp/CalculatorModuleFactory.cpp.template +0 -28
- package/.bootstrap/modules/cpp_bridge_module/src/Calculator.d.ts +0 -4
- package/.bootstrap/modules/ios_android_bridge_module/BUILD.bazel.template +0 -39
- package/.bootstrap/modules/ios_android_bridge_module/android/CalculatorModuleFactory.kt.template +0 -18
- package/.bootstrap/modules/ios_android_bridge_module/ios/SCCCalculatorModuleFactory.m.template +0 -31
- package/.bootstrap/modules/ios_android_bridge_module/src/Calculator.d.ts +0 -4
- package/.bootstrap/modules/ios_android_view_module/BUILD.bazel.template +0 -41
- package/.bootstrap/modules/ios_android_view_module/android/CircleView.kt.template +0 -42
- package/.bootstrap/modules/ios_android_view_module/android/CircleViewAttributesBinder.kt.template +0 -60
- package/.bootstrap/modules/ios_android_view_module/ios/SCCCircleView.h +0 -6
- package/.bootstrap/modules/ios_android_view_module/ios/SCCCircleView.m +0 -82
- package/.bootstrap/modules/ios_android_view_module/src/Circle.tsx.template +0 -15
- package/.bootstrap/modules/ui_component/BUILD.bazel.template +0 -34
- package/.bootstrap/modules/ui_component/src/NewModuleComponent.tsx +0 -45
- package/.config/copyconfig.json +0 -10
- package/.editorconfig +0 -21
- package/.eslintignore +0 -1
- package/.eslintrc.js +0 -72
- package/.github/README.md +0 -164
- package/.metadata/.bazelrc.template +0 -91
- package/.metadata/.bazelversion.template +0 -1
- package/.metadata/.editorconfig.template +0 -37
- package/.metadata/.eslintrc.js.template +0 -27
- package/.metadata/.gitignore.template +0 -4
- package/.metadata/.prettierrc.json.template +0 -7
- package/.metadata/.watchmanconfig.template +0 -8
- package/.metadata/README.md.template +0 -31
- package/.metadata/WORKSPACE.template +0 -57
- package/.metadata/config.yaml.template +0 -1
- package/.metadata/package.json.template +0 -23
- package/.prettierignore +0 -2
- package/.prettierrc.json +0 -7
- package/LINUX_COMPATIBILITY.md +0 -248
- package/prettier.config.js +0 -4
- package/scripts/sync-agents-md.sh +0 -44
- package/scripts/update-agents-templates.ts +0 -170
- package/spec/support/jasmine.json +0 -6
- package/src/commands/bootstrap.ts +0 -409
- package/src/commands/build.ts +0 -89
- package/src/commands/devSetup.ts +0 -17
- package/src/commands/doctor.ts +0 -1832
- package/src/commands/export.ts +0 -131
- package/src/commands/hotreload.ts +0 -108
- package/src/commands/install.ts +0 -93
- package/src/commands/lint.ts +0 -15
- package/src/commands/lint_commands/lintCheck.ts +0 -53
- package/src/commands/lint_commands/lintFormat.ts +0 -49
- package/src/commands/log.ts +0 -108
- package/src/commands/newModule.ts +0 -286
- package/src/commands/package.ts +0 -102
- package/src/commands/projectsync.ts +0 -488
- package/src/commands/test.ts +0 -68
- package/src/core/constants.ts +0 -97
- package/src/core/errors.ts +0 -10
- package/src/index.ts +0 -22
- package/src/setup/DevSetupHelper.ts +0 -290
- package/src/setup/linuxSetup.ts +0 -261
- package/src/setup/macOSSetup.ts +0 -156
- package/src/setup/setupEntryPoint.ts +0 -64
- package/src/setup/versions.ts +0 -8
- package/src/utils/ArgumentsResolver.ts +0 -23
- package/src/utils/BazelClient.ts +0 -285
- package/src/utils/Digraph.ts +0 -81
- package/src/utils/LoadingIndicator.ts +0 -43
- package/src/utils/applicationUtils.ts +0 -276
- package/src/utils/buildInfo.ts +0 -99
- package/src/utils/byString.ts +0 -3
- package/src/utils/cliUtils.ts +0 -112
- package/src/utils/copyBootstrapFiles.ts +0 -30
- package/src/utils/deviceUtils.ts +0 -76
- package/src/utils/errorUtils.ts +0 -63
- package/src/utils/fileUtils.ts +0 -257
- package/src/utils/githubUtils.ts +0 -102
- package/src/utils/jsonUtils.ts +0 -30
- package/src/utils/lintUtils.ts +0 -190
- package/src/utils/linuxDistro.spec.ts +0 -219
- package/src/utils/linuxDistro.ts +0 -326
- package/src/utils/logUtils.ts +0 -9
- package/src/utils/pathUtils.ts +0 -12
- package/src/utils/stringUtils.spec.ts +0 -95
- package/src/utils/stringUtils.ts +0 -103
- package/src/utils/tempDir.ts +0 -24
- package/src/utils/zipUtils.ts +0 -14
- package/test/ValdiSmokeTest.ts +0 -279
- package/test/helpers/AsyncHelpers.ts +0 -113
- package/test/helpers/CommandHelpers.ts +0 -37
- package/test/helpers/ProjectHelpers.ts +0 -153
- package/test/helpers/StreamHelpers.ts +0 -37
- package/test/helpers/TypeScriptClient.ts +0 -217
- package/tsconfig.dist.json +0 -8
- package/tsconfig.json +0 -42
|
@@ -1,276 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import type { Argv } from 'yargs';
|
|
3
|
-
import {
|
|
4
|
-
ANDROID_ARM64_BUILD_FLAGS,
|
|
5
|
-
ANDROID_ARMV7_BUILD_FLAGS,
|
|
6
|
-
ANDROID_BAZEL_APPLICATION_TAG,
|
|
7
|
-
ANDROID_BUILD_FLAGS,
|
|
8
|
-
ANDROID_EXPORTED_LIBRARY_TAG,
|
|
9
|
-
ANDROID_X86_64_BUILD_FLAGS,
|
|
10
|
-
ANSI_COLORS,
|
|
11
|
-
Architecture,
|
|
12
|
-
CLI_BAZEL_APPLICATION_TAG,
|
|
13
|
-
CLI_BUILD_FLAGS,
|
|
14
|
-
DEBUG_BUILD_FLAGS,
|
|
15
|
-
ENABLE_RUNTIME_LOGS_BUILD_FLAGS,
|
|
16
|
-
ENABLE_RUNTIME_TRACES_BUILD_FLAGS,
|
|
17
|
-
IOS_BAZEL_APPLICATION_TAG,
|
|
18
|
-
IOS_BUILD_FLAGS,
|
|
19
|
-
IOS_DEVICE_BUILD_FLAGS,
|
|
20
|
-
IOS_EXPORTED_LIBRARY_TAG,
|
|
21
|
-
MACOS_BAZEL_APPLICATION_TAG,
|
|
22
|
-
MACOS_BUILD_FLAGS,
|
|
23
|
-
PLATFORM,
|
|
24
|
-
RELEASE_BUILD_FLAGS,
|
|
25
|
-
VALID_PLATFORMS,
|
|
26
|
-
} from '../core/constants';
|
|
27
|
-
import { CliError } from '../core/errors';
|
|
28
|
-
import type { BazelClient } from './BazelClient';
|
|
29
|
-
import type { CliChoice } from './cliUtils';
|
|
30
|
-
import { getUserChoice } from './cliUtils';
|
|
31
|
-
import { wrapInColor } from './logUtils';
|
|
32
|
-
|
|
33
|
-
export interface SharedCommandParameters {
|
|
34
|
-
platform: string | undefined;
|
|
35
|
-
bazel_args: string | undefined;
|
|
36
|
-
build_config: 'debug' | 'release';
|
|
37
|
-
enable_runtime_logs: boolean | undefined;
|
|
38
|
-
enable_runtime_traces: boolean | undefined;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export function makeArgsBuilder<T extends SharedCommandParameters>(
|
|
42
|
-
nestedBuilder: (yargs: Argv<T>) => void,
|
|
43
|
-
): (yargs: Argv<T>) => void {
|
|
44
|
-
return yargs => {
|
|
45
|
-
yargs
|
|
46
|
-
.positional('platform', {
|
|
47
|
-
describe: 'Platform to build the library or application for: <ios|android>',
|
|
48
|
-
type: 'string',
|
|
49
|
-
choices: VALID_PLATFORMS,
|
|
50
|
-
coerce: arg => {
|
|
51
|
-
return arg === undefined ? undefined : String(arg).toLowerCase();
|
|
52
|
-
},
|
|
53
|
-
})
|
|
54
|
-
.option('build_config', {
|
|
55
|
-
describe: 'Specifiy whether the application or library should be built in release or debug mode',
|
|
56
|
-
type: 'string',
|
|
57
|
-
choices: ['debug', 'release'],
|
|
58
|
-
default: 'debug',
|
|
59
|
-
requiresArg: true,
|
|
60
|
-
})
|
|
61
|
-
.option('enable_runtime_logs', {
|
|
62
|
-
describe: 'Specifiy Valdi runtime logs should be enabled',
|
|
63
|
-
type: 'boolean',
|
|
64
|
-
default: false,
|
|
65
|
-
})
|
|
66
|
-
.option('enable_runtime_traces', {
|
|
67
|
-
describe: 'Specifiy Valdi runtime traces should be enabled',
|
|
68
|
-
type: 'boolean',
|
|
69
|
-
default: false,
|
|
70
|
-
})
|
|
71
|
-
.option('bazel_args', {
|
|
72
|
-
describe: `Additional arguments to pass to bazel build. Use format ${wrapInColor('--bazel_args="<args>"', ANSI_COLORS.YELLOW_COLOR)}.`,
|
|
73
|
-
type: 'string',
|
|
74
|
-
requiresArg: true,
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
nestedBuilder(yargs);
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export async function selectBazelTarget(
|
|
82
|
-
bazel: BazelClient,
|
|
83
|
-
tag: string,
|
|
84
|
-
targetTypeName: string,
|
|
85
|
-
promptText: string,
|
|
86
|
-
): Promise<string> {
|
|
87
|
-
const unfilteredAvailableTargets = await bazel.queryTargetsForTag(tag);
|
|
88
|
-
const availableTargets = unfilteredAvailableTargets.filter(c => !c.endsWith('_DO_NOT_USE'));
|
|
89
|
-
|
|
90
|
-
if (availableTargets.length === 0) {
|
|
91
|
-
throw new CliError(`No ${targetTypeName} targets found...`);
|
|
92
|
-
} else if (availableTargets.length === 1) {
|
|
93
|
-
console.log(
|
|
94
|
-
`Only one ${targetTypeName} target found, using it:`,
|
|
95
|
-
wrapInColor(availableTargets[0], ANSI_COLORS.GREEN_COLOR),
|
|
96
|
-
);
|
|
97
|
-
|
|
98
|
-
return availableTargets[0] ?? '';
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// Prompt user to select an application target
|
|
102
|
-
const choices: Array<CliChoice<string>> = availableTargets.map((target, index) => ({
|
|
103
|
-
name: `${index + 1}. ${target}`,
|
|
104
|
-
value: target,
|
|
105
|
-
}));
|
|
106
|
-
|
|
107
|
-
return await getUserChoice(choices, promptText);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
export function getApplicationTargetTagForPlatform(platform: PLATFORM): string {
|
|
111
|
-
switch (platform) {
|
|
112
|
-
case PLATFORM.IOS: {
|
|
113
|
-
return IOS_BAZEL_APPLICATION_TAG;
|
|
114
|
-
}
|
|
115
|
-
case PLATFORM.ANDROID: {
|
|
116
|
-
return ANDROID_BAZEL_APPLICATION_TAG;
|
|
117
|
-
}
|
|
118
|
-
case PLATFORM.MACOS: {
|
|
119
|
-
return MACOS_BAZEL_APPLICATION_TAG;
|
|
120
|
-
}
|
|
121
|
-
case PLATFORM.CLI: {
|
|
122
|
-
return CLI_BAZEL_APPLICATION_TAG;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
export function getExportedLibraryTargetTagForPlatform(platform: PLATFORM): string {
|
|
128
|
-
switch (platform) {
|
|
129
|
-
case PLATFORM.IOS: {
|
|
130
|
-
return IOS_EXPORTED_LIBRARY_TAG;
|
|
131
|
-
}
|
|
132
|
-
case PLATFORM.ANDROID: {
|
|
133
|
-
return ANDROID_EXPORTED_LIBRARY_TAG;
|
|
134
|
-
}
|
|
135
|
-
case PLATFORM.MACOS: {
|
|
136
|
-
throw new CliError('Exported library is not yet supported for macOS platform');
|
|
137
|
-
}
|
|
138
|
-
case PLATFORM.CLI: {
|
|
139
|
-
throw new CliError('Exported library is not supported for CLI platform');
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
export function applicationExtensionForPlatform(platform: PLATFORM): string {
|
|
145
|
-
switch (platform) {
|
|
146
|
-
case PLATFORM.IOS: {
|
|
147
|
-
return '.ipa';
|
|
148
|
-
}
|
|
149
|
-
case PLATFORM.ANDROID: {
|
|
150
|
-
return '.apk';
|
|
151
|
-
}
|
|
152
|
-
case PLATFORM.MACOS: {
|
|
153
|
-
return '.zip';
|
|
154
|
-
}
|
|
155
|
-
case PLATFORM.CLI: {
|
|
156
|
-
return '';
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
export function exportedLibraryExtensionForPlatform(platform: PLATFORM): string {
|
|
162
|
-
switch (platform) {
|
|
163
|
-
case PLATFORM.IOS: {
|
|
164
|
-
return '.xcframework';
|
|
165
|
-
}
|
|
166
|
-
case PLATFORM.ANDROID: {
|
|
167
|
-
return '.aar';
|
|
168
|
-
}
|
|
169
|
-
case PLATFORM.MACOS: {
|
|
170
|
-
return '.zip';
|
|
171
|
-
}
|
|
172
|
-
case PLATFORM.CLI: {
|
|
173
|
-
return '.zip';
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
// Reads and selects the output path for the build & install
|
|
179
|
-
export async function getOutputFilePath(
|
|
180
|
-
bazel: BazelClient,
|
|
181
|
-
expectedExtension: string,
|
|
182
|
-
target: string,
|
|
183
|
-
bazelArgs: string = '',
|
|
184
|
-
): Promise<string> {
|
|
185
|
-
const workspaceRootResult = await bazel.getWorkspaceRoot();
|
|
186
|
-
const buildOutputsResult = await bazel.queryBuildOutputs([target], bazelArgs);
|
|
187
|
-
|
|
188
|
-
// TODO(yhuang6): Have a way to prompt for selection and memorize it and/or
|
|
189
|
-
// add an option to specify name of apk.
|
|
190
|
-
let appChoices = buildOutputsResult;
|
|
191
|
-
if (expectedExtension.length > 0) {
|
|
192
|
-
appChoices = buildOutputsResult.filter(
|
|
193
|
-
output => output.endsWith(expectedExtension) && !output.includes('_unsigned'),
|
|
194
|
-
);
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
let outputPath;
|
|
198
|
-
if (appChoices.length === 0) {
|
|
199
|
-
throw new CliError('No outputs are found...');
|
|
200
|
-
} else if (appChoices.length === 1) {
|
|
201
|
-
outputPath = appChoices[0];
|
|
202
|
-
} else {
|
|
203
|
-
outputPath = await getUserChoice(
|
|
204
|
-
appChoices.map((output, index) => ({ name: `${index + 1}. ${output}`, value: output })),
|
|
205
|
-
'Please select the app to install:',
|
|
206
|
-
);
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
return outputPath === undefined ? '' : path.join(workspaceRootResult, outputPath);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
function androidBuildFlagsForArchitecture(architecture: Architecture): readonly string[] {
|
|
213
|
-
switch (architecture) {
|
|
214
|
-
case Architecture.ARM64: {
|
|
215
|
-
return ANDROID_ARM64_BUILD_FLAGS;
|
|
216
|
-
}
|
|
217
|
-
case Architecture.ARMV7: {
|
|
218
|
-
return ANDROID_ARMV7_BUILD_FLAGS;
|
|
219
|
-
}
|
|
220
|
-
case Architecture.X86_64: {
|
|
221
|
-
return ANDROID_X86_64_BUILD_FLAGS;
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
export function resolveBazelBuildArgs(
|
|
227
|
-
platform: PLATFORM,
|
|
228
|
-
buildConfig: 'debug' | 'release' | undefined,
|
|
229
|
-
architectures: Architecture[],
|
|
230
|
-
forDevice: boolean,
|
|
231
|
-
enableRuntimeLogs: boolean | undefined,
|
|
232
|
-
enableRuntimeTracing: boolean | undefined,
|
|
233
|
-
additionalBazelArgs: string | undefined,
|
|
234
|
-
): string {
|
|
235
|
-
const allArgs: string[] = [];
|
|
236
|
-
|
|
237
|
-
if (buildConfig === 'release') {
|
|
238
|
-
allArgs.push(...RELEASE_BUILD_FLAGS);
|
|
239
|
-
} else {
|
|
240
|
-
allArgs.push(...DEBUG_BUILD_FLAGS);
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
if (enableRuntimeLogs) {
|
|
244
|
-
allArgs.push(...ENABLE_RUNTIME_LOGS_BUILD_FLAGS);
|
|
245
|
-
}
|
|
246
|
-
if (enableRuntimeTracing) {
|
|
247
|
-
allArgs.push(...ENABLE_RUNTIME_TRACES_BUILD_FLAGS);
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
if (platform === PLATFORM.IOS) {
|
|
251
|
-
allArgs.push(IOS_BUILD_FLAGS);
|
|
252
|
-
|
|
253
|
-
if (forDevice) {
|
|
254
|
-
allArgs.push(IOS_DEVICE_BUILD_FLAGS);
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
if (platform === PLATFORM.CLI) {
|
|
259
|
-
allArgs.push(...CLI_BUILD_FLAGS);
|
|
260
|
-
} else if (platform === PLATFORM.MACOS) {
|
|
261
|
-
allArgs.push(...MACOS_BUILD_FLAGS);
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
if (platform === PLATFORM.ANDROID) {
|
|
265
|
-
allArgs.push(...ANDROID_BUILD_FLAGS);
|
|
266
|
-
|
|
267
|
-
for (const architecture of architectures) {
|
|
268
|
-
allArgs.push(...androidBuildFlagsForArchitecture(architecture));
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
if (additionalBazelArgs) {
|
|
273
|
-
allArgs.push(additionalBazelArgs);
|
|
274
|
-
}
|
|
275
|
-
return allArgs.join(' ');
|
|
276
|
-
}
|
package/src/utils/buildInfo.ts
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import Separator from "inquirer/lib/objects/separator";
|
|
2
|
-
import { ALL_ARCHITECTURES, ANSI_COLORS, Architecture, PLATFORM } from "../core/constants";
|
|
3
|
-
import { CliError } from "../core/errors";
|
|
4
|
-
import { getApplicationTargetTagForPlatform, resolveBazelBuildArgs, selectBazelTarget, SharedCommandParameters } from "./applicationUtils";
|
|
5
|
-
import { ArgumentsResolver } from "./ArgumentsResolver";
|
|
6
|
-
import { CliChoice, getUserChoice } from "./cliUtils";
|
|
7
|
-
import { getAllArchitecturesForAndroid, getArchitectureForAndroidDevice, getConnectedDevices } from "./deviceUtils";
|
|
8
|
-
import { wrapInColor } from "./logUtils";
|
|
9
|
-
import { BazelClient } from "./BazelClient";
|
|
10
|
-
|
|
11
|
-
export interface BuildInfo {
|
|
12
|
-
platform: PLATFORM;
|
|
13
|
-
application: string;
|
|
14
|
-
bazelArgs: string;
|
|
15
|
-
selectedDevice: string | undefined
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export interface CommandParameters extends SharedCommandParameters {
|
|
19
|
-
application: string | undefined;
|
|
20
|
-
device_id: string | undefined;
|
|
21
|
-
target_output_path: string | undefined;
|
|
22
|
-
simulator: boolean | undefined;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// Prompts User to choose from the list of available devices
|
|
26
|
-
// No prompt if only one device is available
|
|
27
|
-
async function getDeviceChoice(platform: string): Promise<string> {
|
|
28
|
-
const availableDevices = await getConnectedDevices(platform);
|
|
29
|
-
|
|
30
|
-
if (availableDevices.length === 0) {
|
|
31
|
-
throw new CliError('No devices connected...');
|
|
32
|
-
} else if (availableDevices.length === 1) {
|
|
33
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
34
|
-
const selectedDevice: string = availableDevices[0]!;
|
|
35
|
-
console.log('Only one device connected, using it:', wrapInColor(selectedDevice, ANSI_COLORS.GREEN_COLOR));
|
|
36
|
-
return selectedDevice;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// Prompt user to select a device
|
|
40
|
-
const choices: Array<CliChoice<string> | Separator> = [];
|
|
41
|
-
|
|
42
|
-
if (platform === PLATFORM.ANDROID) {
|
|
43
|
-
choices.push(new Separator('-----Android Devices-----'));
|
|
44
|
-
} else if (platform === PLATFORM.IOS) {
|
|
45
|
-
choices.push(new Separator('-----iOS Devices-----'));
|
|
46
|
-
}
|
|
47
|
-
choices.push(...availableDevices.map(device => ({ name: device, value: device })));
|
|
48
|
-
|
|
49
|
-
return await getUserChoice(choices, 'Please select a device to perform the install:');
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export async function getBuildInfo(argv: ArgumentsResolver<CommandParameters>, bazel: BazelClient, checkDevice: boolean): Promise<BuildInfo> {
|
|
53
|
-
const platform = argv.getArgument('platform') as PLATFORM;
|
|
54
|
-
const forDevice = !!argv.getArgument('simulator');
|
|
55
|
-
|
|
56
|
-
let selectedDevice: string | undefined;
|
|
57
|
-
let architectures: Architecture[] = ALL_ARCHITECTURES;
|
|
58
|
-
|
|
59
|
-
if (platform === PLATFORM.ANDROID) {
|
|
60
|
-
if (checkDevice) {
|
|
61
|
-
selectedDevice = await argv.getArgumentOrResolve('device_id', () => {
|
|
62
|
-
console.log('Detecting Connected Devices...');
|
|
63
|
-
return getDeviceChoice(platform);
|
|
64
|
-
});
|
|
65
|
-
architectures = [await getArchitectureForAndroidDevice(selectedDevice)];
|
|
66
|
-
} else {
|
|
67
|
-
architectures = getAllArchitecturesForAndroid();
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const bazelArgs = resolveBazelBuildArgs(
|
|
72
|
-
platform,
|
|
73
|
-
argv.getArgument('build_config'),
|
|
74
|
-
architectures,
|
|
75
|
-
forDevice,
|
|
76
|
-
argv.getArgument('enable_runtime_logs'),
|
|
77
|
-
argv.getArgument('enable_runtime_traces'),
|
|
78
|
-
argv.getArgument('bazel_args'),
|
|
79
|
-
);
|
|
80
|
-
|
|
81
|
-
// Application Selection
|
|
82
|
-
// ---------------------
|
|
83
|
-
const application = await argv.getArgumentOrResolve('application', () => {
|
|
84
|
-
console.log('No application specified querying available targets...');
|
|
85
|
-
return selectBazelTarget(
|
|
86
|
-
bazel,
|
|
87
|
-
getApplicationTargetTagForPlatform(platform),
|
|
88
|
-
'valdi_application',
|
|
89
|
-
'Please select an application target to install:',
|
|
90
|
-
);
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
return {
|
|
94
|
-
platform: platform,
|
|
95
|
-
application: application,
|
|
96
|
-
bazelArgs: bazelArgs,
|
|
97
|
-
selectedDevice: selectedDevice,
|
|
98
|
-
};
|
|
99
|
-
}
|
package/src/utils/byString.ts
DELETED
package/src/utils/cliUtils.ts
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import type { StdioOptions } from 'child_process';
|
|
2
|
-
import { exec, execSync, spawn } from 'child_process';
|
|
3
|
-
import inquirer from 'inquirer';
|
|
4
|
-
import type Separator from 'inquirer/lib/objects/separator';
|
|
5
|
-
|
|
6
|
-
export type CommandResult = { returnCode: number; stdout: string; stderr: string };
|
|
7
|
-
export type CliChoice<T> = { name: string; value: T };
|
|
8
|
-
|
|
9
|
-
export function runCliCommand(command: string, cwd?: string, rejectOnFailure?: boolean): Promise<CommandResult> {
|
|
10
|
-
return new Promise((resolve, reject) => {
|
|
11
|
-
exec(command, { cwd: cwd, shell: getShell() }, (error, stdout, stderr) => {
|
|
12
|
-
const returnCode = error ? (error.code ?? 1) : 0;
|
|
13
|
-
if (returnCode !== 0 && rejectOnFailure) {
|
|
14
|
-
reject(new Error(stderr.trim()));
|
|
15
|
-
} else {
|
|
16
|
-
resolve({ returnCode, stdout, stderr });
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export function spawnCliCommand(
|
|
23
|
-
command: string,
|
|
24
|
-
cwd: string | undefined,
|
|
25
|
-
stdioMode: StdioOptions,
|
|
26
|
-
quiet: boolean,
|
|
27
|
-
rejectOnFailure: boolean,
|
|
28
|
-
): Promise<CommandResult> {
|
|
29
|
-
return new Promise((resolve, reject) => {
|
|
30
|
-
const child = spawn(command, {
|
|
31
|
-
stdio: stdioMode,
|
|
32
|
-
shell: getShell(),
|
|
33
|
-
cwd: cwd,
|
|
34
|
-
env: { ...process.env, FORCE_COLOR: '1' },
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
// When using mode = 'inherit', the following output and error capture is a no-op
|
|
38
|
-
|
|
39
|
-
let stdout = '';
|
|
40
|
-
let stderr = '';
|
|
41
|
-
|
|
42
|
-
child.stdout?.on('data', (data: Buffer) => {
|
|
43
|
-
stdout += data.toString();
|
|
44
|
-
if (!quiet) {
|
|
45
|
-
process.stdout.write(stdout);
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
child.stderr?.on('data', (data: Buffer) => {
|
|
50
|
-
stderr += data.toString();
|
|
51
|
-
if (!quiet) {
|
|
52
|
-
process.stderr.write(stderr);
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
child.on('close', code => {
|
|
57
|
-
if (code !== 0 && rejectOnFailure) {
|
|
58
|
-
reject(new Error(stderr.trim()));
|
|
59
|
-
} else {
|
|
60
|
-
resolve({ returnCode: code ?? 0, stdout, stderr });
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
child.on('error', err => {
|
|
65
|
-
reject(err);
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export async function getUserChoice<T>(
|
|
71
|
-
choices: Array<CliChoice<T> | Separator>,
|
|
72
|
-
promptMessage?: string,
|
|
73
|
-
maxChoices?: number,
|
|
74
|
-
): Promise<T> {
|
|
75
|
-
const answers = await inquirer.prompt<{ selectedChoice: T }>([
|
|
76
|
-
{
|
|
77
|
-
type: 'list',
|
|
78
|
-
name: 'selectedChoice',
|
|
79
|
-
message: promptMessage ?? 'Please select an option:',
|
|
80
|
-
choices: choices,
|
|
81
|
-
loop: false,
|
|
82
|
-
pageSize: maxChoices ?? 10,
|
|
83
|
-
},
|
|
84
|
-
]);
|
|
85
|
-
|
|
86
|
-
return answers.selectedChoice;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export async function getUserConfirmation(promptMessage?: string, defaultConfirm: boolean = false): Promise<boolean> {
|
|
90
|
-
const answer = await inquirer.prompt<{ confirm: boolean }>([
|
|
91
|
-
{ type: 'confirm', name: 'confirm', message: promptMessage ?? 'Are you sure?', default: defaultConfirm },
|
|
92
|
-
]);
|
|
93
|
-
|
|
94
|
-
return answer.confirm;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export function getScriptDirectory(): string {
|
|
98
|
-
return '';
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
function getShell(): string {
|
|
102
|
-
return process.env['SHELL'] ?? '/bin/bash';
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
export function checkCommandExists(command: string): boolean {
|
|
106
|
-
try {
|
|
107
|
-
execSync(`command -v ${command}`, { stdio: 'ignore' });
|
|
108
|
-
return true;
|
|
109
|
-
} catch {
|
|
110
|
-
return false;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import { globSync } from 'glob';
|
|
4
|
-
import { ANSI_COLORS } from '../core/constants';
|
|
5
|
-
import type { Replacements } from './fileUtils';
|
|
6
|
-
import { copyFileWithReplacement, copyFiles, processReplacements } from './fileUtils';
|
|
7
|
-
import { wrapInColor } from './logUtils';
|
|
8
|
-
|
|
9
|
-
export function copyBootstrapFiles(from: string, to: string, replacements: Replacements) {
|
|
10
|
-
copyFiles(from, to);
|
|
11
|
-
|
|
12
|
-
const keys = Object.keys(replacements);
|
|
13
|
-
|
|
14
|
-
const filenamesToReplace = globSync(keys.map(key => `**/{{${key}}}`));
|
|
15
|
-
|
|
16
|
-
for (const filename of filenamesToReplace) {
|
|
17
|
-
fs.renameSync(filename, processReplacements(filename, replacements));
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const templateFiles = globSync(`${to}/**/*.template`);
|
|
21
|
-
templateFiles.forEach(templateFile => {
|
|
22
|
-
const parsedPath = path.parse(templateFile);
|
|
23
|
-
console.log(
|
|
24
|
-
wrapInColor(`Updating template file ${parsedPath.name} in ${parsedPath.dir}...`, ANSI_COLORS.YELLOW_COLOR),
|
|
25
|
-
);
|
|
26
|
-
const templateFileWithoutSuffix = templateFile.replace(/.template$/, '');
|
|
27
|
-
fs.renameSync(templateFile, templateFileWithoutSuffix);
|
|
28
|
-
copyFileWithReplacement(templateFileWithoutSuffix, templateFileWithoutSuffix, replacements);
|
|
29
|
-
});
|
|
30
|
-
}
|
package/src/utils/deviceUtils.ts
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { Architecture, PLATFORM } from '../core/constants';
|
|
2
|
-
import { CliError } from '../core/errors';
|
|
3
|
-
import { runCliCommand, spawnCliCommand } from './cliUtils';
|
|
4
|
-
|
|
5
|
-
function parseAndroidDevices(devicesString: string): string[] {
|
|
6
|
-
const deviceIDs: string[] = devicesString
|
|
7
|
-
.split('\n')
|
|
8
|
-
.filter(line => line.trim().endsWith('device') && !line.startsWith('List of devices'))
|
|
9
|
-
.map(line => line.split('\t')?.[0]?.trim() ?? ''); // Extract the device ID
|
|
10
|
-
|
|
11
|
-
return deviceIDs ?? [];
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export async function getArchitectureForAndroidDevice(deviceId: string): Promise<Architecture> {
|
|
15
|
-
const { stdout } = await runCliCommand(`adb -s ${deviceId} shell getprop ro.product.cpu.abi`, undefined, true);
|
|
16
|
-
|
|
17
|
-
const architectureString = stdout.trim();
|
|
18
|
-
|
|
19
|
-
switch (architectureString) {
|
|
20
|
-
case 'arm64-v8a': {
|
|
21
|
-
return Architecture.ARM64;
|
|
22
|
-
}
|
|
23
|
-
case 'armeabi-v7a': {
|
|
24
|
-
return Architecture.ARMV7;
|
|
25
|
-
}
|
|
26
|
-
case 'armeabi': {
|
|
27
|
-
return Architecture.ARMV7;
|
|
28
|
-
}
|
|
29
|
-
case 'x86_64': {
|
|
30
|
-
return Architecture.X86_64;
|
|
31
|
-
}
|
|
32
|
-
default: {
|
|
33
|
-
throw new CliError(`Unsupported device architecture: ${architectureString}`);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export function getAllArchitecturesForAndroid() {
|
|
39
|
-
return [Architecture.ARM64, Architecture.ARMV7, Architecture.X86_64];
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export async function getConnectedAndroidDevices(): Promise<string[]> {
|
|
43
|
-
const commandListDevices = 'adb devices';
|
|
44
|
-
const { stdout: devicesString } = await runCliCommand(commandListDevices, undefined, true);
|
|
45
|
-
const androidDevices = parseAndroidDevices(devicesString);
|
|
46
|
-
|
|
47
|
-
return androidDevices;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export async function getConnectedIOSDevices(): Promise<string[]> {
|
|
51
|
-
// eslint-disable-next-line unicorn/no-useless-promise-resolve-reject
|
|
52
|
-
return Promise.resolve(['-1']);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export async function getConnectedDevices(platform: string): Promise<string[]> {
|
|
56
|
-
if (platform === PLATFORM.ANDROID) {
|
|
57
|
-
const androidDevices = await getConnectedAndroidDevices();
|
|
58
|
-
return androidDevices;
|
|
59
|
-
} else if (platform === PLATFORM.IOS) {
|
|
60
|
-
const iosDevices = await getConnectedIOSDevices();
|
|
61
|
-
return iosDevices;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
return [];
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export async function installAndroidApk(apkPath: string, emulatorId?: string) {
|
|
68
|
-
const idString = emulatorId ? ` -s ${emulatorId} ` : ' ';
|
|
69
|
-
const commandInstallApk = `adb${idString}install -r ${apkPath}`;
|
|
70
|
-
await spawnCliCommand(commandInstallApk, undefined, 'pipe', false, true);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export async function startAndroidActivity(activityName: string) {
|
|
74
|
-
const commandStartActivity = `adb shell am start -n ${activityName}`;
|
|
75
|
-
await spawnCliCommand(commandStartActivity, undefined, 'pipe', false, true);
|
|
76
|
-
}
|
package/src/utils/errorUtils.ts
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
|
2
|
-
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
|
3
|
-
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
4
|
-
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
|
5
|
-
import { ANSI_COLORS } from '../core/constants';
|
|
6
|
-
import { CliError } from '../core/errors';
|
|
7
|
-
import { ArgumentsResolver } from './ArgumentsResolver';
|
|
8
|
-
import { wrapInColor } from './logUtils';
|
|
9
|
-
|
|
10
|
-
function logReproduceWith(keys: string[], additionalResolvedArguments: any) {
|
|
11
|
-
const allArguments = ['valdi', ...process.argv.slice(2)];
|
|
12
|
-
keys.sort();
|
|
13
|
-
|
|
14
|
-
for (const key of keys.sort()) {
|
|
15
|
-
const value = additionalResolvedArguments[key];
|
|
16
|
-
if (Array.isArray(value)) {
|
|
17
|
-
for (const item of value) {
|
|
18
|
-
allArguments.push(`--${key}`, item.toString());
|
|
19
|
-
}
|
|
20
|
-
} else {
|
|
21
|
-
allArguments.push(`--${key}`, value.toString());
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
console.log(
|
|
26
|
-
`\n${wrapInColor('Note: Use the following command next time to reproduce without prompts', ANSI_COLORS.GREEN_COLOR)}\n${allArguments.join(' ')}\n`,
|
|
27
|
-
);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export function logReproduceThisCommandIfNeeded<T>(argumentsResolver: ArgumentsResolver<T>) {
|
|
31
|
-
const keys = Object.keys(argumentsResolver.additionalResolvedArguments);
|
|
32
|
-
if (keys.length > 0) {
|
|
33
|
-
logReproduceWith(keys, argumentsResolver.additionalResolvedArguments);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export function makeCommandHandler<T>(cb: (argv: ArgumentsResolver<T>) => Promise<void>): (argv: T) => void {
|
|
38
|
-
const command = async (argv: T) => {
|
|
39
|
-
const argumentsResolver = new ArgumentsResolver(argv);
|
|
40
|
-
try {
|
|
41
|
-
await cb(argumentsResolver);
|
|
42
|
-
process.exitCode = 0;
|
|
43
|
-
} catch (error) {
|
|
44
|
-
process.exitCode = 1;
|
|
45
|
-
|
|
46
|
-
if (error instanceof CliError) {
|
|
47
|
-
// Managed Error
|
|
48
|
-
console.log(wrapInColor(error.message, error.textColor));
|
|
49
|
-
} else if (error instanceof Error) {
|
|
50
|
-
// Unmanaged Error
|
|
51
|
-
console.log(error.stack);
|
|
52
|
-
console.log(wrapInColor(error.message, ANSI_COLORS.RED_COLOR));
|
|
53
|
-
} else {
|
|
54
|
-
// Something went really wrong
|
|
55
|
-
throw error;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
return (argv: T) => {
|
|
61
|
-
void command(argv);
|
|
62
|
-
};
|
|
63
|
-
}
|