@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.
- package/.bazelignore +2 -0
- package/.bootstrap/apps/cli_application/AGENTS.md.template +215 -0
- package/.bootstrap/apps/cli_application/BUILD.bazel.template +7 -0
- package/.bootstrap/apps/cli_application/modules/{{MODULE_NAME}}/BUILD.bazel.template +11 -0
- package/.bootstrap/apps/cli_application/modules/{{MODULE_NAME}}/src/index.ts +1 -0
- package/.bootstrap/apps/ui_application/.eslint.rc +27 -0
- package/.bootstrap/apps/ui_application/AGENTS.md.template +202 -0
- package/.bootstrap/apps/ui_application/BUILD.bazel.template +19 -0
- package/.bootstrap/apps/ui_application/modules/{{MODULE_NAME}}/BUILD.bazel.template +21 -0
- 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 +133 -0
- package/.bootstrap/apps/ui_application/package.json +24 -0
- package/.bootstrap/modules/cpp_bridge_module/BUILD.bazel.template +21 -0
- package/.bootstrap/modules/cpp_bridge_module/cpp/CalculatorModuleFactory.cpp.template +29 -0
- package/.bootstrap/modules/cpp_bridge_module/src/Calculator.d.ts +1 -0
- package/.bootstrap/modules/ios_android_bridge_module/BUILD.bazel.template +39 -0
- package/.bootstrap/modules/ios_android_bridge_module/android/CalculatorModuleFactory.kt.template +18 -0
- package/.bootstrap/modules/ios_android_bridge_module/ios/SCCCalculatorModuleFactory.m.template +31 -0
- package/.bootstrap/modules/ios_android_bridge_module/src/Calculator.d.ts +4 -0
- package/.bootstrap/modules/ios_android_view_module/BUILD.bazel.template +41 -0
- package/.bootstrap/modules/ios_android_view_module/android/CircleView.kt.template +42 -0
- package/.bootstrap/modules/ios_android_view_module/android/CircleViewAttributesBinder.kt.template +60 -0
- package/.bootstrap/modules/ios_android_view_module/ios/SCCCircleView.h +6 -0
- package/.bootstrap/modules/ios_android_view_module/ios/SCCCircleView.m +82 -0
- package/.bootstrap/modules/ios_android_view_module/src/Circle.tsx.template +15 -0
- package/.bootstrap/modules/ui_component/BUILD.bazel.template +34 -0
- package/.bootstrap/modules/ui_component/src/NewModuleComponent.tsx +45 -0
- package/.config/copyconfig.json +10 -0
- package/.editorconfig +21 -0
- package/.eslintignore +1 -0
- package/.eslintrc.js +72 -0
- package/.metadata/.bazelrc.template +91 -0
- package/.metadata/.bazelversion.template +1 -0
- package/.metadata/.eslintrc.js.template +27 -0
- package/.metadata/.gitignore.template +4 -0
- package/.metadata/.prettierrc.json.template +7 -0
- package/.metadata/.watchmanconfig.template +8 -0
- package/.metadata/README.md.template +31 -0
- package/.metadata/WORKSPACE.template +57 -0
- package/.metadata/config.yaml.template +1 -0
- package/.metadata/package.json.template +23 -0
- package/.prettierignore +2 -0
- package/.prettierrc.json +7 -0
- package/README.md +123 -0
- package/dist/commands/bootstrap.js +233 -0
- package/dist/commands/build.js +67 -0
- package/dist/commands/devSetup.js +18 -0
- package/dist/commands/doctor.js +892 -0
- package/dist/commands/export.js +84 -0
- package/dist/commands/hotreload.js +89 -0
- package/dist/commands/install.js +71 -0
- package/dist/commands/lint.js +18 -0
- package/dist/commands/lint_commands/lintCheck.js +31 -0
- package/dist/commands/lint_commands/lintFormat.js +31 -0
- package/dist/commands/log.js +84 -0
- package/dist/commands/newModule.js +208 -0
- package/dist/commands/package.js +66 -0
- package/dist/commands/projectsync.js +316 -0
- package/dist/commands/test.js +54 -0
- package/dist/core/constants.js +76 -0
- package/dist/core/errors.js +12 -0
- package/dist/index.js +22 -0
- package/dist/setup/DevSetupHelper.js +146 -0
- package/dist/setup/linuxSetup.js +31 -0
- package/dist/setup/macOSSetup.js +35 -0
- package/dist/setup/setupEntryPoint.js +56 -0
- package/dist/setup/versions.js +8 -0
- package/dist/utils/ArgumentsResolver.js +23 -0
- package/dist/utils/BazelClient.js +219 -0
- package/dist/utils/Digraph.js +71 -0
- package/dist/utils/LoadingIndicator.js +38 -0
- package/dist/utils/applicationUtils.js +201 -0
- package/dist/utils/buildInfo.js +60 -0
- package/dist/utils/byString.js +6 -0
- package/dist/utils/cliUtils.js +93 -0
- package/dist/utils/copyBootstrapFiles.js +26 -0
- package/dist/utils/deviceUtils.js +72 -0
- package/dist/utils/errorUtils.js +55 -0
- package/dist/utils/fileUtils.js +204 -0
- package/dist/utils/githubUtils.js +8 -0
- package/dist/utils/jsonUtils.js +28 -0
- package/dist/utils/lintUtils.js +149 -0
- package/dist/utils/logUtils.js +8 -0
- package/dist/utils/pathUtils.js +12 -0
- package/dist/utils/stringUtils.js +17 -0
- package/dist/utils/stringUtils.spec.js +18 -0
- package/dist/utils/tempDir.js +26 -0
- package/dist/utils/zipUtils.js +16 -0
- package/package.json +51 -0
- package/prettier.config.js +4 -0
- package/spec/support/jasmine.json +6 -0
- package/src/commands/bootstrap.ts +317 -0
- package/src/commands/build.ts +89 -0
- package/src/commands/devSetup.ts +17 -0
- package/src/commands/doctor.ts +1422 -0
- package/src/commands/export.ts +131 -0
- package/src/commands/hotreload.ts +108 -0
- package/src/commands/install.ts +93 -0
- package/src/commands/lint.ts +15 -0
- package/src/commands/lint_commands/lintCheck.ts +53 -0
- package/src/commands/lint_commands/lintFormat.ts +49 -0
- package/src/commands/log.ts +108 -0
- package/src/commands/newModule.ts +287 -0
- package/src/commands/package.ts +102 -0
- package/src/commands/projectsync.ts +488 -0
- package/src/commands/test.ts +68 -0
- package/src/core/constants.ts +95 -0
- package/src/core/errors.ts +10 -0
- package/src/index.ts +22 -0
- package/src/setup/DevSetupHelper.ts +188 -0
- package/src/setup/linuxSetup.ts +38 -0
- package/src/setup/macOSSetup.ts +42 -0
- package/src/setup/setupEntryPoint.ts +64 -0
- package/src/setup/versions.ts +8 -0
- package/src/utils/ArgumentsResolver.ts +23 -0
- package/src/utils/BazelClient.ts +285 -0
- package/src/utils/Digraph.ts +81 -0
- package/src/utils/LoadingIndicator.ts +43 -0
- package/src/utils/applicationUtils.ts +276 -0
- package/src/utils/buildInfo.ts +99 -0
- package/src/utils/byString.ts +3 -0
- package/src/utils/cliUtils.ts +112 -0
- package/src/utils/copyBootstrapFiles.ts +30 -0
- package/src/utils/deviceUtils.ts +76 -0
- package/src/utils/errorUtils.ts +63 -0
- package/src/utils/fileUtils.ts +257 -0
- package/src/utils/githubUtils.ts +6 -0
- package/src/utils/jsonUtils.ts +30 -0
- package/src/utils/lintUtils.ts +190 -0
- package/src/utils/logUtils.ts +9 -0
- package/src/utils/pathUtils.ts +12 -0
- package/src/utils/stringUtils.spec.ts +19 -0
- package/src/utils/stringUtils.ts +15 -0
- package/src/utils/tempDir.ts +24 -0
- package/src/utils/zipUtils.ts +14 -0
- package/test/ValdiSmokeTest.ts +278 -0
- package/test/helpers/AsyncHelpers.ts +113 -0
- package/test/helpers/CommandHelpers.ts +37 -0
- package/test/helpers/ProjectHelpers.ts +153 -0
- package/test/helpers/StreamHelpers.ts +37 -0
- package/test/helpers/TypeScriptClient.ts +217 -0
- package/tsconfig.dist.json +8 -0
- package/tsconfig.json +42 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeArgsBuilder = makeArgsBuilder;
|
|
4
|
+
exports.selectBazelTarget = selectBazelTarget;
|
|
5
|
+
exports.getApplicationTargetTagForPlatform = getApplicationTargetTagForPlatform;
|
|
6
|
+
exports.getExportedLibraryTargetTagForPlatform = getExportedLibraryTargetTagForPlatform;
|
|
7
|
+
exports.applicationExtensionForPlatform = applicationExtensionForPlatform;
|
|
8
|
+
exports.exportedLibraryExtensionForPlatform = exportedLibraryExtensionForPlatform;
|
|
9
|
+
exports.getOutputFilePath = getOutputFilePath;
|
|
10
|
+
exports.resolveBazelBuildArgs = resolveBazelBuildArgs;
|
|
11
|
+
const tslib_1 = require("tslib");
|
|
12
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
13
|
+
const constants_1 = require("../core/constants");
|
|
14
|
+
const errors_1 = require("../core/errors");
|
|
15
|
+
const cliUtils_1 = require("./cliUtils");
|
|
16
|
+
const logUtils_1 = require("./logUtils");
|
|
17
|
+
function makeArgsBuilder(nestedBuilder) {
|
|
18
|
+
return yargs => {
|
|
19
|
+
yargs
|
|
20
|
+
.positional('platform', {
|
|
21
|
+
describe: 'Platform to build the library or application for: <ios|android>',
|
|
22
|
+
type: 'string',
|
|
23
|
+
choices: constants_1.VALID_PLATFORMS,
|
|
24
|
+
coerce: arg => {
|
|
25
|
+
return arg === undefined ? undefined : String(arg).toLowerCase();
|
|
26
|
+
},
|
|
27
|
+
})
|
|
28
|
+
.option('build_config', {
|
|
29
|
+
describe: 'Specifiy whether the application or library should be built in release or debug mode',
|
|
30
|
+
type: 'string',
|
|
31
|
+
choices: ['debug', 'release'],
|
|
32
|
+
default: 'debug',
|
|
33
|
+
requiresArg: true,
|
|
34
|
+
})
|
|
35
|
+
.option('enable_runtime_logs', {
|
|
36
|
+
describe: 'Specifiy Valdi runtime logs should be enabled',
|
|
37
|
+
type: 'boolean',
|
|
38
|
+
default: false,
|
|
39
|
+
})
|
|
40
|
+
.option('enable_runtime_traces', {
|
|
41
|
+
describe: 'Specifiy Valdi runtime traces should be enabled',
|
|
42
|
+
type: 'boolean',
|
|
43
|
+
default: false,
|
|
44
|
+
})
|
|
45
|
+
.option('bazel_args', {
|
|
46
|
+
describe: `Additional arguments to pass to bazel build. Use format ${(0, logUtils_1.wrapInColor)('--bazel_args="<args>"', constants_1.ANSI_COLORS.YELLOW_COLOR)}.`,
|
|
47
|
+
type: 'string',
|
|
48
|
+
requiresArg: true,
|
|
49
|
+
});
|
|
50
|
+
nestedBuilder(yargs);
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
async function selectBazelTarget(bazel, tag, targetTypeName, promptText) {
|
|
54
|
+
const unfilteredAvailableTargets = await bazel.queryTargetsForTag(tag);
|
|
55
|
+
const availableTargets = unfilteredAvailableTargets.filter(c => !c.endsWith('_DO_NOT_USE'));
|
|
56
|
+
if (availableTargets.length === 0) {
|
|
57
|
+
throw new errors_1.CliError(`No ${targetTypeName} targets found...`);
|
|
58
|
+
}
|
|
59
|
+
else if (availableTargets.length === 1) {
|
|
60
|
+
console.log(`Only one ${targetTypeName} target found, using it:`, (0, logUtils_1.wrapInColor)(availableTargets[0], constants_1.ANSI_COLORS.GREEN_COLOR));
|
|
61
|
+
return availableTargets[0] ?? '';
|
|
62
|
+
}
|
|
63
|
+
const choices = availableTargets.map((target, index) => ({
|
|
64
|
+
name: `${index + 1}. ${target}`,
|
|
65
|
+
value: target,
|
|
66
|
+
}));
|
|
67
|
+
return await (0, cliUtils_1.getUserChoice)(choices, promptText);
|
|
68
|
+
}
|
|
69
|
+
function getApplicationTargetTagForPlatform(platform) {
|
|
70
|
+
switch (platform) {
|
|
71
|
+
case constants_1.PLATFORM.IOS: {
|
|
72
|
+
return constants_1.IOS_BAZEL_APPLICATION_TAG;
|
|
73
|
+
}
|
|
74
|
+
case constants_1.PLATFORM.ANDROID: {
|
|
75
|
+
return constants_1.ANDROID_BAZEL_APPLICATION_TAG;
|
|
76
|
+
}
|
|
77
|
+
case constants_1.PLATFORM.MACOS: {
|
|
78
|
+
return constants_1.MACOS_BAZEL_APPLICATION_TAG;
|
|
79
|
+
}
|
|
80
|
+
case constants_1.PLATFORM.CLI: {
|
|
81
|
+
return constants_1.CLI_BAZEL_APPLICATION_TAG;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
function getExportedLibraryTargetTagForPlatform(platform) {
|
|
86
|
+
switch (platform) {
|
|
87
|
+
case constants_1.PLATFORM.IOS: {
|
|
88
|
+
return constants_1.IOS_EXPORTED_LIBRARY_TAG;
|
|
89
|
+
}
|
|
90
|
+
case constants_1.PLATFORM.ANDROID: {
|
|
91
|
+
return constants_1.ANDROID_EXPORTED_LIBRARY_TAG;
|
|
92
|
+
}
|
|
93
|
+
case constants_1.PLATFORM.MACOS: {
|
|
94
|
+
throw new errors_1.CliError('Exported library is not yet supported for macOS platform');
|
|
95
|
+
}
|
|
96
|
+
case constants_1.PLATFORM.CLI: {
|
|
97
|
+
throw new errors_1.CliError('Exported library is not supported for CLI platform');
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
function applicationExtensionForPlatform(platform) {
|
|
102
|
+
switch (platform) {
|
|
103
|
+
case constants_1.PLATFORM.IOS: {
|
|
104
|
+
return '.ipa';
|
|
105
|
+
}
|
|
106
|
+
case constants_1.PLATFORM.ANDROID: {
|
|
107
|
+
return '.apk';
|
|
108
|
+
}
|
|
109
|
+
case constants_1.PLATFORM.MACOS: {
|
|
110
|
+
return '.zip';
|
|
111
|
+
}
|
|
112
|
+
case constants_1.PLATFORM.CLI: {
|
|
113
|
+
return '';
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
function exportedLibraryExtensionForPlatform(platform) {
|
|
118
|
+
switch (platform) {
|
|
119
|
+
case constants_1.PLATFORM.IOS: {
|
|
120
|
+
return '.xcframework';
|
|
121
|
+
}
|
|
122
|
+
case constants_1.PLATFORM.ANDROID: {
|
|
123
|
+
return '.aar';
|
|
124
|
+
}
|
|
125
|
+
case constants_1.PLATFORM.MACOS: {
|
|
126
|
+
return '.zip';
|
|
127
|
+
}
|
|
128
|
+
case constants_1.PLATFORM.CLI: {
|
|
129
|
+
return '.zip';
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
async function getOutputFilePath(bazel, expectedExtension, target, bazelArgs = '') {
|
|
134
|
+
const workspaceRootResult = await bazel.getWorkspaceRoot();
|
|
135
|
+
const buildOutputsResult = await bazel.queryBuildOutputs([target], bazelArgs);
|
|
136
|
+
let appChoices = buildOutputsResult;
|
|
137
|
+
if (expectedExtension.length > 0) {
|
|
138
|
+
appChoices = buildOutputsResult.filter(output => output.endsWith(expectedExtension) && !output.includes('_unsigned'));
|
|
139
|
+
}
|
|
140
|
+
let outputPath;
|
|
141
|
+
if (appChoices.length === 0) {
|
|
142
|
+
throw new errors_1.CliError('No outputs are found...');
|
|
143
|
+
}
|
|
144
|
+
else if (appChoices.length === 1) {
|
|
145
|
+
outputPath = appChoices[0];
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
outputPath = await (0, cliUtils_1.getUserChoice)(appChoices.map((output, index) => ({ name: `${index + 1}. ${output}`, value: output })), 'Please select the app to install:');
|
|
149
|
+
}
|
|
150
|
+
return outputPath === undefined ? '' : path_1.default.join(workspaceRootResult, outputPath);
|
|
151
|
+
}
|
|
152
|
+
function androidBuildFlagsForArchitecture(architecture) {
|
|
153
|
+
switch (architecture) {
|
|
154
|
+
case constants_1.Architecture.ARM64: {
|
|
155
|
+
return constants_1.ANDROID_ARM64_BUILD_FLAGS;
|
|
156
|
+
}
|
|
157
|
+
case constants_1.Architecture.ARMV7: {
|
|
158
|
+
return constants_1.ANDROID_ARMV7_BUILD_FLAGS;
|
|
159
|
+
}
|
|
160
|
+
case constants_1.Architecture.X86_64: {
|
|
161
|
+
return constants_1.ANDROID_X86_64_BUILD_FLAGS;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
function resolveBazelBuildArgs(platform, buildConfig, architectures, forDevice, enableRuntimeLogs, enableRuntimeTracing, additionalBazelArgs) {
|
|
166
|
+
const allArgs = [];
|
|
167
|
+
if (buildConfig === 'release') {
|
|
168
|
+
allArgs.push(...constants_1.RELEASE_BUILD_FLAGS);
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
allArgs.push(...constants_1.DEBUG_BUILD_FLAGS);
|
|
172
|
+
}
|
|
173
|
+
if (enableRuntimeLogs) {
|
|
174
|
+
allArgs.push(...constants_1.ENABLE_RUNTIME_LOGS_BUILD_FLAGS);
|
|
175
|
+
}
|
|
176
|
+
if (enableRuntimeTracing) {
|
|
177
|
+
allArgs.push(...constants_1.ENABLE_RUNTIME_TRACES_BUILD_FLAGS);
|
|
178
|
+
}
|
|
179
|
+
if (platform === constants_1.PLATFORM.IOS) {
|
|
180
|
+
allArgs.push(constants_1.IOS_BUILD_FLAGS);
|
|
181
|
+
if (forDevice) {
|
|
182
|
+
allArgs.push(constants_1.IOS_DEVICE_BUILD_FLAGS);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
if (platform === constants_1.PLATFORM.CLI) {
|
|
186
|
+
allArgs.push(...constants_1.CLI_BUILD_FLAGS);
|
|
187
|
+
}
|
|
188
|
+
else if (platform === constants_1.PLATFORM.MACOS) {
|
|
189
|
+
allArgs.push(...constants_1.MACOS_BUILD_FLAGS);
|
|
190
|
+
}
|
|
191
|
+
if (platform === constants_1.PLATFORM.ANDROID) {
|
|
192
|
+
allArgs.push(...constants_1.ANDROID_BUILD_FLAGS);
|
|
193
|
+
for (const architecture of architectures) {
|
|
194
|
+
allArgs.push(...androidBuildFlagsForArchitecture(architecture));
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
if (additionalBazelArgs) {
|
|
198
|
+
allArgs.push(additionalBazelArgs);
|
|
199
|
+
}
|
|
200
|
+
return allArgs.join(' ');
|
|
201
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getBuildInfo = getBuildInfo;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const separator_1 = tslib_1.__importDefault(require("inquirer/lib/objects/separator"));
|
|
6
|
+
const constants_1 = require("../core/constants");
|
|
7
|
+
const errors_1 = require("../core/errors");
|
|
8
|
+
const applicationUtils_1 = require("./applicationUtils");
|
|
9
|
+
const cliUtils_1 = require("./cliUtils");
|
|
10
|
+
const deviceUtils_1 = require("./deviceUtils");
|
|
11
|
+
const logUtils_1 = require("./logUtils");
|
|
12
|
+
async function getDeviceChoice(platform) {
|
|
13
|
+
const availableDevices = await (0, deviceUtils_1.getConnectedDevices)(platform);
|
|
14
|
+
if (availableDevices.length === 0) {
|
|
15
|
+
throw new errors_1.CliError('No devices connected...');
|
|
16
|
+
}
|
|
17
|
+
else if (availableDevices.length === 1) {
|
|
18
|
+
const selectedDevice = availableDevices[0];
|
|
19
|
+
console.log('Only one device connected, using it:', (0, logUtils_1.wrapInColor)(selectedDevice, constants_1.ANSI_COLORS.GREEN_COLOR));
|
|
20
|
+
return selectedDevice;
|
|
21
|
+
}
|
|
22
|
+
const choices = [];
|
|
23
|
+
if (platform === constants_1.PLATFORM.ANDROID) {
|
|
24
|
+
choices.push(new separator_1.default('-----Android Devices-----'));
|
|
25
|
+
}
|
|
26
|
+
else if (platform === constants_1.PLATFORM.IOS) {
|
|
27
|
+
choices.push(new separator_1.default('-----iOS Devices-----'));
|
|
28
|
+
}
|
|
29
|
+
choices.push(...availableDevices.map(device => ({ name: device, value: device })));
|
|
30
|
+
return await (0, cliUtils_1.getUserChoice)(choices, 'Please select a device to perform the install:');
|
|
31
|
+
}
|
|
32
|
+
async function getBuildInfo(argv, bazel, checkDevice) {
|
|
33
|
+
const platform = argv.getArgument('platform');
|
|
34
|
+
const forDevice = !!argv.getArgument('simulator');
|
|
35
|
+
let selectedDevice;
|
|
36
|
+
let architectures = constants_1.ALL_ARCHITECTURES;
|
|
37
|
+
if (platform === constants_1.PLATFORM.ANDROID) {
|
|
38
|
+
if (checkDevice) {
|
|
39
|
+
selectedDevice = await argv.getArgumentOrResolve('device_id', () => {
|
|
40
|
+
console.log('Detecting Connected Devices...');
|
|
41
|
+
return getDeviceChoice(platform);
|
|
42
|
+
});
|
|
43
|
+
architectures = [await (0, deviceUtils_1.getArchitectureForAndroidDevice)(selectedDevice)];
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
architectures = (0, deviceUtils_1.getAllArchitecturesForAndroid)();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
const bazelArgs = (0, applicationUtils_1.resolveBazelBuildArgs)(platform, argv.getArgument('build_config'), architectures, forDevice, argv.getArgument('enable_runtime_logs'), argv.getArgument('enable_runtime_traces'), argv.getArgument('bazel_args'));
|
|
50
|
+
const application = await argv.getArgumentOrResolve('application', () => {
|
|
51
|
+
console.log('No application specified querying available targets...');
|
|
52
|
+
return (0, applicationUtils_1.selectBazelTarget)(bazel, (0, applicationUtils_1.getApplicationTargetTagForPlatform)(platform), 'valdi_application', 'Please select an application target to install:');
|
|
53
|
+
});
|
|
54
|
+
return {
|
|
55
|
+
platform: platform,
|
|
56
|
+
application: application,
|
|
57
|
+
bazelArgs: bazelArgs,
|
|
58
|
+
selectedDevice: selectedDevice,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runCliCommand = runCliCommand;
|
|
4
|
+
exports.spawnCliCommand = spawnCliCommand;
|
|
5
|
+
exports.getUserChoice = getUserChoice;
|
|
6
|
+
exports.getUserConfirmation = getUserConfirmation;
|
|
7
|
+
exports.getScriptDirectory = getScriptDirectory;
|
|
8
|
+
exports.checkCommandExists = checkCommandExists;
|
|
9
|
+
const tslib_1 = require("tslib");
|
|
10
|
+
const child_process_1 = require("child_process");
|
|
11
|
+
const inquirer_1 = tslib_1.__importDefault(require("inquirer"));
|
|
12
|
+
function runCliCommand(command, cwd, rejectOnFailure) {
|
|
13
|
+
return new Promise((resolve, reject) => {
|
|
14
|
+
(0, child_process_1.exec)(command, { cwd: cwd, shell: getShell() }, (error, stdout, stderr) => {
|
|
15
|
+
const returnCode = error ? (error.code ?? 1) : 0;
|
|
16
|
+
if (returnCode !== 0 && rejectOnFailure) {
|
|
17
|
+
reject(new Error(stderr.trim()));
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
resolve({ returnCode, stdout, stderr });
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
function spawnCliCommand(command, cwd, stdioMode, quiet, rejectOnFailure) {
|
|
26
|
+
return new Promise((resolve, reject) => {
|
|
27
|
+
const child = (0, child_process_1.spawn)(command, {
|
|
28
|
+
stdio: stdioMode,
|
|
29
|
+
shell: getShell(),
|
|
30
|
+
cwd: cwd,
|
|
31
|
+
env: { ...process.env, FORCE_COLOR: '1' },
|
|
32
|
+
});
|
|
33
|
+
let stdout = '';
|
|
34
|
+
let stderr = '';
|
|
35
|
+
child.stdout?.on('data', (data) => {
|
|
36
|
+
stdout += data.toString();
|
|
37
|
+
if (!quiet) {
|
|
38
|
+
process.stdout.write(stdout);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
child.stderr?.on('data', (data) => {
|
|
42
|
+
stderr += data.toString();
|
|
43
|
+
if (!quiet) {
|
|
44
|
+
process.stderr.write(stderr);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
child.on('close', code => {
|
|
48
|
+
if (code !== 0 && rejectOnFailure) {
|
|
49
|
+
reject(new Error(stderr.trim()));
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
resolve({ returnCode: code ?? 0, stdout, stderr });
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
child.on('error', err => {
|
|
56
|
+
reject(err);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
async function getUserChoice(choices, promptMessage, maxChoices) {
|
|
61
|
+
const answers = await inquirer_1.default.prompt([
|
|
62
|
+
{
|
|
63
|
+
type: 'list',
|
|
64
|
+
name: 'selectedChoice',
|
|
65
|
+
message: promptMessage ?? 'Please select an option:',
|
|
66
|
+
choices: choices,
|
|
67
|
+
loop: false,
|
|
68
|
+
pageSize: maxChoices ?? 10,
|
|
69
|
+
},
|
|
70
|
+
]);
|
|
71
|
+
return answers.selectedChoice;
|
|
72
|
+
}
|
|
73
|
+
async function getUserConfirmation(promptMessage, defaultConfirm = false) {
|
|
74
|
+
const answer = await inquirer_1.default.prompt([
|
|
75
|
+
{ type: 'confirm', name: 'confirm', message: promptMessage ?? 'Are you sure?', default: defaultConfirm },
|
|
76
|
+
]);
|
|
77
|
+
return answer.confirm;
|
|
78
|
+
}
|
|
79
|
+
function getScriptDirectory() {
|
|
80
|
+
return '';
|
|
81
|
+
}
|
|
82
|
+
function getShell() {
|
|
83
|
+
return process.env['SHELL'] ?? '/bin/bash';
|
|
84
|
+
}
|
|
85
|
+
function checkCommandExists(command) {
|
|
86
|
+
try {
|
|
87
|
+
(0, child_process_1.execSync)(`command -v ${command}`, { stdio: 'ignore' });
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.copyBootstrapFiles = copyBootstrapFiles;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
6
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
7
|
+
const glob_1 = require("glob");
|
|
8
|
+
const constants_1 = require("../core/constants");
|
|
9
|
+
const fileUtils_1 = require("./fileUtils");
|
|
10
|
+
const logUtils_1 = require("./logUtils");
|
|
11
|
+
function copyBootstrapFiles(from, to, replacements) {
|
|
12
|
+
(0, fileUtils_1.copyFiles)(from, to);
|
|
13
|
+
const keys = Object.keys(replacements);
|
|
14
|
+
const filenamesToReplace = (0, glob_1.globSync)(keys.map(key => `**/{{${key}}}`));
|
|
15
|
+
for (const filename of filenamesToReplace) {
|
|
16
|
+
fs_1.default.renameSync(filename, (0, fileUtils_1.processReplacements)(filename, replacements));
|
|
17
|
+
}
|
|
18
|
+
const templateFiles = (0, glob_1.globSync)(`${to}/**/*.template`);
|
|
19
|
+
templateFiles.forEach(templateFile => {
|
|
20
|
+
const parsedPath = path_1.default.parse(templateFile);
|
|
21
|
+
console.log((0, logUtils_1.wrapInColor)(`Updating template file ${parsedPath.name} in ${parsedPath.dir}...`, constants_1.ANSI_COLORS.YELLOW_COLOR));
|
|
22
|
+
const templateFileWithoutSuffix = templateFile.replace(/.template$/, '');
|
|
23
|
+
fs_1.default.renameSync(templateFile, templateFileWithoutSuffix);
|
|
24
|
+
(0, fileUtils_1.copyFileWithReplacement)(templateFileWithoutSuffix, templateFileWithoutSuffix, replacements);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getArchitectureForAndroidDevice = getArchitectureForAndroidDevice;
|
|
4
|
+
exports.getAllArchitecturesForAndroid = getAllArchitecturesForAndroid;
|
|
5
|
+
exports.getConnectedAndroidDevices = getConnectedAndroidDevices;
|
|
6
|
+
exports.getConnectedIOSDevices = getConnectedIOSDevices;
|
|
7
|
+
exports.getConnectedDevices = getConnectedDevices;
|
|
8
|
+
exports.installAndroidApk = installAndroidApk;
|
|
9
|
+
exports.startAndroidActivity = startAndroidActivity;
|
|
10
|
+
const constants_1 = require("../core/constants");
|
|
11
|
+
const errors_1 = require("../core/errors");
|
|
12
|
+
const cliUtils_1 = require("./cliUtils");
|
|
13
|
+
function parseAndroidDevices(devicesString) {
|
|
14
|
+
const deviceIDs = devicesString
|
|
15
|
+
.split('\n')
|
|
16
|
+
.filter(line => line.trim().endsWith('device') && !line.startsWith('List of devices'))
|
|
17
|
+
.map(line => line.split('\t')?.[0]?.trim() ?? '');
|
|
18
|
+
return deviceIDs ?? [];
|
|
19
|
+
}
|
|
20
|
+
async function getArchitectureForAndroidDevice(deviceId) {
|
|
21
|
+
const { stdout } = await (0, cliUtils_1.runCliCommand)(`adb -s ${deviceId} shell getprop ro.product.cpu.abi`, undefined, true);
|
|
22
|
+
const architectureString = stdout.trim();
|
|
23
|
+
switch (architectureString) {
|
|
24
|
+
case 'arm64-v8a': {
|
|
25
|
+
return constants_1.Architecture.ARM64;
|
|
26
|
+
}
|
|
27
|
+
case 'armeabi-v7a': {
|
|
28
|
+
return constants_1.Architecture.ARMV7;
|
|
29
|
+
}
|
|
30
|
+
case 'armeabi': {
|
|
31
|
+
return constants_1.Architecture.ARMV7;
|
|
32
|
+
}
|
|
33
|
+
case 'x86_64': {
|
|
34
|
+
return constants_1.Architecture.X86_64;
|
|
35
|
+
}
|
|
36
|
+
default: {
|
|
37
|
+
throw new errors_1.CliError(`Unsupported device architecture: ${architectureString}`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function getAllArchitecturesForAndroid() {
|
|
42
|
+
return [constants_1.Architecture.ARM64, constants_1.Architecture.ARMV7, constants_1.Architecture.X86_64];
|
|
43
|
+
}
|
|
44
|
+
async function getConnectedAndroidDevices() {
|
|
45
|
+
const commandListDevices = 'adb devices';
|
|
46
|
+
const { stdout: devicesString } = await (0, cliUtils_1.runCliCommand)(commandListDevices, undefined, true);
|
|
47
|
+
const androidDevices = parseAndroidDevices(devicesString);
|
|
48
|
+
return androidDevices;
|
|
49
|
+
}
|
|
50
|
+
async function getConnectedIOSDevices() {
|
|
51
|
+
return Promise.resolve(['-1']);
|
|
52
|
+
}
|
|
53
|
+
async function getConnectedDevices(platform) {
|
|
54
|
+
if (platform === constants_1.PLATFORM.ANDROID) {
|
|
55
|
+
const androidDevices = await getConnectedAndroidDevices();
|
|
56
|
+
return androidDevices;
|
|
57
|
+
}
|
|
58
|
+
else if (platform === constants_1.PLATFORM.IOS) {
|
|
59
|
+
const iosDevices = await getConnectedIOSDevices();
|
|
60
|
+
return iosDevices;
|
|
61
|
+
}
|
|
62
|
+
return [];
|
|
63
|
+
}
|
|
64
|
+
async function installAndroidApk(apkPath, emulatorId) {
|
|
65
|
+
const idString = emulatorId ? ` -s ${emulatorId} ` : ' ';
|
|
66
|
+
const commandInstallApk = `adb${idString}install -r ${apkPath}`;
|
|
67
|
+
await (0, cliUtils_1.spawnCliCommand)(commandInstallApk, undefined, 'pipe', false, true);
|
|
68
|
+
}
|
|
69
|
+
async function startAndroidActivity(activityName) {
|
|
70
|
+
const commandStartActivity = `adb shell am start -n ${activityName}`;
|
|
71
|
+
await (0, cliUtils_1.spawnCliCommand)(commandStartActivity, undefined, 'pipe', false, true);
|
|
72
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.logReproduceThisCommandIfNeeded = logReproduceThisCommandIfNeeded;
|
|
4
|
+
exports.makeCommandHandler = makeCommandHandler;
|
|
5
|
+
const constants_1 = require("../core/constants");
|
|
6
|
+
const errors_1 = require("../core/errors");
|
|
7
|
+
const ArgumentsResolver_1 = require("./ArgumentsResolver");
|
|
8
|
+
const logUtils_1 = require("./logUtils");
|
|
9
|
+
function logReproduceWith(keys, additionalResolvedArguments) {
|
|
10
|
+
const allArguments = ['valdi', ...process.argv.slice(2)];
|
|
11
|
+
keys.sort();
|
|
12
|
+
for (const key of keys.sort()) {
|
|
13
|
+
const value = additionalResolvedArguments[key];
|
|
14
|
+
if (Array.isArray(value)) {
|
|
15
|
+
for (const item of value) {
|
|
16
|
+
allArguments.push(`--${key}`, item.toString());
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
allArguments.push(`--${key}`, value.toString());
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
console.log(`\n${(0, logUtils_1.wrapInColor)('Note: Use the following command next time to reproduce without prompts', constants_1.ANSI_COLORS.GREEN_COLOR)}\n${allArguments.join(' ')}\n`);
|
|
24
|
+
}
|
|
25
|
+
function logReproduceThisCommandIfNeeded(argumentsResolver) {
|
|
26
|
+
const keys = Object.keys(argumentsResolver.additionalResolvedArguments);
|
|
27
|
+
if (keys.length > 0) {
|
|
28
|
+
logReproduceWith(keys, argumentsResolver.additionalResolvedArguments);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function makeCommandHandler(cb) {
|
|
32
|
+
const command = async (argv) => {
|
|
33
|
+
const argumentsResolver = new ArgumentsResolver_1.ArgumentsResolver(argv);
|
|
34
|
+
try {
|
|
35
|
+
await cb(argumentsResolver);
|
|
36
|
+
process.exitCode = 0;
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
process.exitCode = 1;
|
|
40
|
+
if (error instanceof errors_1.CliError) {
|
|
41
|
+
console.log((0, logUtils_1.wrapInColor)(error.message, error.textColor));
|
|
42
|
+
}
|
|
43
|
+
else if (error instanceof Error) {
|
|
44
|
+
console.log(error.stack);
|
|
45
|
+
console.log((0, logUtils_1.wrapInColor)(error.message, constants_1.ANSI_COLORS.RED_COLOR));
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
return (argv) => {
|
|
53
|
+
void command(argv);
|
|
54
|
+
};
|
|
55
|
+
}
|