@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,146 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DevSetupHelper = exports.HOME_DIR = void 0;
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 constants_1 = require("../core/constants");
8
+ const LoadingIndicator_1 = require("../utils/LoadingIndicator");
9
+ const cliUtils_1 = require("../utils/cliUtils");
10
+ const logUtils_1 = require("../utils/logUtils");
11
+ const tempDir_1 = require("../utils/tempDir");
12
+ const zipUtils_1 = require("../utils/zipUtils");
13
+ const versions_1 = require("./versions");
14
+ exports.HOME_DIR = process.env['HOME'] ?? '';
15
+ const ANDROID_HOME_DIR_SUFFIX = '.valdi/android_home';
16
+ const ANDROID_HOME_TARET_DIR = path_1.default.join(exports.HOME_DIR, ANDROID_HOME_DIR_SUFFIX);
17
+ class DevSetupHelper {
18
+ async download(url) {
19
+ return new LoadingIndicator_1.LoadingIndicator(async () => {
20
+ const response = await fetch(url);
21
+ return response.arrayBuffer();
22
+ })
23
+ .setText(`${(0, logUtils_1.wrapInColor)('Downloading', constants_1.ANSI_COLORS.YELLOW_COLOR)} ${url}...`)
24
+ .show();
25
+ }
26
+ async downloadToPath(url, dest) {
27
+ const body = await this.download(url);
28
+ const dir = path_1.default.dirname(dest);
29
+ if (!fs_1.default.existsSync(dir)) {
30
+ fs_1.default.mkdirSync(dir, { recursive: true });
31
+ }
32
+ await fs_1.default.promises.writeFile(dest, new Uint8Array(body));
33
+ }
34
+ async runShell(guide, commands, additionalEnvVariables = {}) {
35
+ let command = '';
36
+ for (const key in additionalEnvVariables) {
37
+ command += `export ${key}="${additionalEnvVariables[key]}"\n`;
38
+ }
39
+ command += commands.join(' && ');
40
+ console.log(`${(0, logUtils_1.wrapInColor)(guide, constants_1.ANSI_COLORS.YELLOW_COLOR)}...`);
41
+ for (const command of commands) {
42
+ console.log(`- ${command}`);
43
+ }
44
+ const result = await (0, cliUtils_1.spawnCliCommand)(command, undefined, 'inherit', false, true);
45
+ return result.stdout;
46
+ }
47
+ async writeEnvVariablesToRcFile(envVariables) {
48
+ const expectedEnvVariable = envVariables.map(e => `export ${e.name}=${e.value}`);
49
+ const rcFile = this.getRcFile();
50
+ if (!rcFile) {
51
+ console.log();
52
+ console.log(`${(0, logUtils_1.wrapInColor)(`Unrecognized shell ${process.env['SHELL'] ?? ''}. Please add the following env variables to your shell configuration file manually:`, constants_1.ANSI_COLORS.RED_COLOR)}`);
53
+ for (const l of expectedEnvVariable) {
54
+ console.log(l);
55
+ }
56
+ console.log();
57
+ return;
58
+ }
59
+ return new LoadingIndicator_1.LoadingIndicator(async () => {
60
+ let originalRcLines = [];
61
+ let rcLines = [];
62
+ if (fs_1.default.existsSync(rcFile)) {
63
+ const fileBody = await fs_1.default.promises.readFile(rcFile, 'utf8');
64
+ originalRcLines = fileBody.split('\n');
65
+ rcLines = [...originalRcLines];
66
+ }
67
+ const valdiConfHeader = `# Valdi configuration end`;
68
+ let insertionIndex = rcLines.indexOf(valdiConfHeader);
69
+ if (insertionIndex < 0) {
70
+ rcLines.push(`# Valdi configuration begin`, valdiConfHeader);
71
+ insertionIndex = rcLines.length - 1;
72
+ }
73
+ for (const envVariable of expectedEnvVariable) {
74
+ if (!rcLines.includes(envVariable)) {
75
+ rcLines.splice(insertionIndex++, 0, envVariable);
76
+ }
77
+ }
78
+ if (rcLines.length !== originalRcLines.length) {
79
+ const content = rcLines.join('\n');
80
+ await fs_1.default.promises.writeFile(rcFile, content, 'utf8');
81
+ }
82
+ })
83
+ .setText((0, logUtils_1.wrapInColor)(`Updating ${rcFile} to include ${envVariables.map(e => e.name).join(', ')}...`, constants_1.ANSI_COLORS.YELLOW_COLOR))
84
+ .show();
85
+ }
86
+ onComplete() {
87
+ let suffix = '';
88
+ const rcFile = this.getRcFile();
89
+ if (rcFile) {
90
+ suffix += ` Please run ${(0, logUtils_1.wrapInColor)(`source ${rcFile}`, constants_1.ANSI_COLORS.YELLOW_COLOR)} or restart your terminal.`;
91
+ }
92
+ console.log(`${(0, logUtils_1.wrapInColor)('Dev setup completed!', constants_1.ANSI_COLORS.GREEN_COLOR)}.${suffix}`);
93
+ }
94
+ async setupAndroidSDK(commandLineToolsURL, javaHomeOverride) {
95
+ console.log((0, logUtils_1.wrapInColor)('Setting up Android SDK...', constants_1.ANSI_COLORS.YELLOW_COLOR));
96
+ if (!process.env['ANDROID_HOME']) {
97
+ await (0, tempDir_1.withTempDir)(async (tempDir) => {
98
+ const filename = path_1.default.join(tempDir, path_1.default.basename(commandLineToolsURL));
99
+ await this.downloadToPath(commandLineToolsURL, filename);
100
+ const targetDir = path_1.default.join(ANDROID_HOME_TARET_DIR, 'cmdline-tools');
101
+ await (0, zipUtils_1.decompressTo)(filename, targetDir);
102
+ const target = path_1.default.join(targetDir, 'latest');
103
+ if (fs_1.default.existsSync(target)) {
104
+ await fs_1.default.promises.rm(target, { recursive: true, force: true });
105
+ }
106
+ fs_1.default.renameSync(path_1.default.join(targetDir, 'cmdline-tools'), target);
107
+ });
108
+ process.env['ANDROID_HOME'] = path_1.default.join(exports.HOME_DIR, ANDROID_HOME_DIR_SUFFIX);
109
+ await this.writeEnvVariablesToRcFile([{ name: 'ANDROID_HOME', value: `"$HOME/${ANDROID_HOME_DIR_SUFFIX}"` }]);
110
+ }
111
+ const androidHome = process.env['ANDROID_HOME'] ?? '';
112
+ const sdkManagerBin = path_1.default.join(androidHome, 'cmdline-tools/latest/bin/sdkmanager');
113
+ const sdkManagerEnvVariables = {};
114
+ if (javaHomeOverride) {
115
+ sdkManagerEnvVariables['JAVA_HOME'] = javaHomeOverride;
116
+ }
117
+ await this.runShell('Installing Android platform', [`${sdkManagerBin} --install 'platforms;${versions_1.ANDROID_PLATFORM_VERSION}'`], sdkManagerEnvVariables);
118
+ await this.runShell('Installing Android NDK', [`${sdkManagerBin} --install 'ndk;${versions_1.ANDROID_NDK_VERSION}'`], sdkManagerEnvVariables);
119
+ await this.runShell('Installing Android build-tools', [`${sdkManagerBin} --install 'build-tools;${versions_1.ANDROID_BUILD_TOOLS_VERSION}'`], sdkManagerEnvVariables);
120
+ const ndkBundle = path_1.default.join(androidHome, 'ndk-bundle');
121
+ if (!fs_1.default.existsSync(ndkBundle)) {
122
+ fs_1.default.symlinkSync(`ndk/${versions_1.ANDROID_NDK_VERSION}`, ndkBundle);
123
+ }
124
+ await this.writeEnvVariablesToRcFile([{ name: 'ANDROID_NDK_HOME', value: `"$ANDROID_HOME/ndk-bundle"` }]);
125
+ }
126
+ getRcFile() {
127
+ const homeDir = process.env['HOME'] ?? '';
128
+ const shell = process.env['SHELL'] ?? '';
129
+ if (shell.endsWith('/zsh')) {
130
+ return path_1.default.join(homeDir, '.zshrc');
131
+ }
132
+ else if (shell.endsWith('/bash')) {
133
+ return path_1.default.join(homeDir, '.bashrc');
134
+ }
135
+ else if (shell.endsWith('/ksh')) {
136
+ return path_1.default.join(homeDir, '.kshrc');
137
+ }
138
+ else if (shell.endsWith('/tcsh')) {
139
+ return path_1.default.join(homeDir, '.tcshrc');
140
+ }
141
+ else {
142
+ return undefined;
143
+ }
144
+ }
145
+ }
146
+ exports.DevSetupHelper = DevSetupHelper;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.linuxSetup = linuxSetup;
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 cliUtils_1 = require("../utils/cliUtils");
8
+ const DevSetupHelper_1 = require("./DevSetupHelper");
9
+ const versions_1 = require("./versions");
10
+ const BAZELISK_URL = 'https://github.com/bazelbuild/bazelisk/releases/download/v1.26.0/bazelisk-linux-amd64';
11
+ async function linuxSetup() {
12
+ const devSetup = new DevSetupHelper_1.DevSetupHelper();
13
+ await devSetup.runShell('Installing dependencies from apt', [
14
+ `sudo apt-get install zlib1g-dev git-lfs watchman libfontconfig-dev adb`,
15
+ ]);
16
+ await devSetup.runShell('Installing libtinfo5', [
17
+ `wget http://security.ubuntu.com/ubuntu/pool/universe/n/ncurses/libtinfo5_6.3-2ubuntu0.1_amd64.deb`,
18
+ `sudo apt install ./libtinfo5_6.3-2ubuntu0.1_amd64.deb`,
19
+ ]);
20
+ if (!(0, cliUtils_1.checkCommandExists)('java')) {
21
+ await devSetup.runShell('Installing Java Runtime Environment', ['sudo apt install default-jre']);
22
+ }
23
+ const bazeliskPathSuffix = '.valdi/bin/bazelisk';
24
+ const bazeliskTargetPath = path_1.default.join(DevSetupHelper_1.HOME_DIR, bazeliskPathSuffix);
25
+ await devSetup.downloadToPath(BAZELISK_URL, bazeliskTargetPath);
26
+ const stats = fs_1.default.statSync(bazeliskTargetPath);
27
+ fs_1.default.chmodSync(bazeliskTargetPath, stats.mode | 0o111);
28
+ await devSetup.writeEnvVariablesToRcFile([{ name: 'PATH', value: `"$HOME/.valdi/bin:$PATH"` }]);
29
+ await devSetup.setupAndroidSDK(versions_1.ANDROID_LINUX_COMMANDLINE_TOOLS);
30
+ devSetup.onComplete();
31
+ }
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.macOSSetup = macOSSetup;
4
+ const tslib_1 = require("tslib");
5
+ const fs_1 = tslib_1.__importDefault(require("fs"));
6
+ const errors_1 = require("../core/errors");
7
+ const cliUtils_1 = require("../utils/cliUtils");
8
+ const DevSetupHelper_1 = require("./DevSetupHelper");
9
+ const versions_1 = require("./versions");
10
+ async function macOSSetup() {
11
+ const devSetup = new DevSetupHelper_1.DevSetupHelper();
12
+ if (!(0, cliUtils_1.checkCommandExists)('xcode-select')) {
13
+ throw new errors_1.CliError('Xcode is not installed. Please install Xcode from the App Store as setup requires Xcode command line tools');
14
+ }
15
+ if (!(0, cliUtils_1.checkCommandExists)('brew')) {
16
+ await devSetup.runShell('Homebrew not found. Installing', [
17
+ '/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"',
18
+ ]);
19
+ }
20
+ await devSetup.runShell('Installing dependencies from Homebrew', [
21
+ 'brew install npm bazelisk openjdk@11 temurin git-lfs watchman ios-webkit-debug-proxy',
22
+ ]);
23
+ if (!fs_1.default.existsSync('/Library/Java/JavaVirtualMachines/openjdk-11.jdk')) {
24
+ await devSetup.runShell('Setting up JDK', [
25
+ 'sudo ln -sfn /opt/homebrew/opt/openjdk@11/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-11.jdk',
26
+ ]);
27
+ }
28
+ await devSetup.writeEnvVariablesToRcFile([
29
+ { name: 'PATH', value: '"/opt/homebrew/opt/openjdk@11/bin:$PATH"' },
30
+ { name: 'JAVA_HOME', value: '`/usr/libexec/java_home -v 11`' },
31
+ ]);
32
+ const javaHome = await (0, cliUtils_1.runCliCommand)('/usr/libexec/java_home');
33
+ await devSetup.setupAndroidSDK(versions_1.ANDROID_MACOS_COMMANDLINE_TOOLS, javaHome.stdout.trim());
34
+ devSetup.onComplete();
35
+ }
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.beginEnvironmentSetup = beginEnvironmentSetup;
4
+ const constants_1 = require("../core/constants");
5
+ const logUtils_1 = require("../utils/logUtils");
6
+ const linuxSetup_1 = require("./linuxSetup");
7
+ const macOSSetup_1 = require("./macOSSetup");
8
+ var OSType;
9
+ (function (OSType) {
10
+ OSType["MACOS"] = "macos";
11
+ OSType["WINDOWS"] = "windows";
12
+ OSType["LINUX"] = "linux";
13
+ OSType["UNKNOWN"] = "unknown";
14
+ })(OSType || (OSType = {}));
15
+ function getOSType() {
16
+ switch (process.platform) {
17
+ case 'darwin': {
18
+ return OSType.MACOS;
19
+ }
20
+ case 'win32': {
21
+ return OSType.WINDOWS;
22
+ }
23
+ case 'linux': {
24
+ return OSType.LINUX;
25
+ }
26
+ default: {
27
+ return OSType.UNKNOWN;
28
+ }
29
+ }
30
+ }
31
+ async function beginEnvironmentSetup() {
32
+ const os = getOSType();
33
+ const returnCode = 0;
34
+ switch (os) {
35
+ case OSType.MACOS: {
36
+ console.log((0, logUtils_1.wrapInColor)('Setting up development environment for MacOS...', constants_1.ANSI_COLORS.BLUE_COLOR));
37
+ await (0, macOSSetup_1.macOSSetup)();
38
+ break;
39
+ }
40
+ case OSType.WINDOWS: {
41
+ console.log((0, logUtils_1.wrapInColor)('Windows is not a supported operating system...aborting...', constants_1.ANSI_COLORS.RED_COLOR));
42
+ return 1;
43
+ }
44
+ case OSType.LINUX: {
45
+ console.log((0, logUtils_1.wrapInColor)('Setting up development environment for Linux...', constants_1.ANSI_COLORS.BLUE_COLOR));
46
+ await (0, linuxSetup_1.linuxSetup)();
47
+ break;
48
+ }
49
+ default: {
50
+ console.log((0, logUtils_1.wrapInColor)('Could not determine current operating system, skipping automated environment setup...', constants_1.ANSI_COLORS.RED_COLOR));
51
+ console.log('Please see https://github.com/Snapchat/Valdi/blob/main/docs/INSTALL.md for manual setup instructions.');
52
+ return 1;
53
+ }
54
+ }
55
+ return returnCode;
56
+ }
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ANDROID_LINUX_COMMANDLINE_TOOLS = exports.ANDROID_MACOS_COMMANDLINE_TOOLS = exports.ANDROID_PLATFORM_VERSION = exports.ANDROID_NDK_VERSION = exports.ANDROID_BUILD_TOOLS_VERSION = void 0;
4
+ exports.ANDROID_BUILD_TOOLS_VERSION = '34.0.0';
5
+ exports.ANDROID_NDK_VERSION = '25.2.9519653';
6
+ exports.ANDROID_PLATFORM_VERSION = 'android-35';
7
+ exports.ANDROID_MACOS_COMMANDLINE_TOOLS = 'https://dl.google.com/android/repository/commandlinetools-mac-13114758_latest.zip';
8
+ exports.ANDROID_LINUX_COMMANDLINE_TOOLS = 'https://dl.google.com/android/repository/commandlinetools-linux-13114758_latest.zip';
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ArgumentsResolver = void 0;
4
+ class ArgumentsResolver {
5
+ args;
6
+ additionalResolvedArguments = {};
7
+ constructor(args) {
8
+ this.args = args;
9
+ }
10
+ getArgument(key) {
11
+ return this.args[key];
12
+ }
13
+ async getArgumentOrResolve(key, resolve) {
14
+ const value = this.args[key];
15
+ if (value) {
16
+ return value;
17
+ }
18
+ const resolved = await resolve();
19
+ this.additionalResolvedArguments[key] = resolved;
20
+ return resolved;
21
+ }
22
+ }
23
+ exports.ArgumentsResolver = ArgumentsResolver;
@@ -0,0 +1,219 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BazelClient = exports.BazelLabel = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const path_1 = tslib_1.__importDefault(require("path"));
6
+ const constants_1 = require("../core/constants");
7
+ const errors_1 = require("../core/errors");
8
+ const Digraph_1 = require("./Digraph");
9
+ const LoadingIndicator_1 = require("./LoadingIndicator");
10
+ const cliUtils_1 = require("./cliUtils");
11
+ const logUtils_1 = require("./logUtils");
12
+ const BAZEL_QUIET_OPTIONS = '--noshow_progress --noshow_loading_progress --ui_event_filters=-info,-progress';
13
+ const BAZEL_PREFIXED_OPTIONS = '--max_idle_secs=5';
14
+ const BAZEL_POSTFIXED_OPTIONS = '--color=yes';
15
+ const DEFAULT_STDIO_MODE = ['pipe', 'pipe', 'inherit'];
16
+ let cached_bazel_executable;
17
+ function getBazelCli() {
18
+ if (!cached_bazel_executable) {
19
+ const bazelBinEnv = process.env[constants_1.BAZEL_BIN_ENV];
20
+ if (bazelBinEnv) {
21
+ cached_bazel_executable = bazelBinEnv;
22
+ return bazelBinEnv;
23
+ }
24
+ const found = constants_1.BAZEL_EXECUTABLES.find(element => (0, cliUtils_1.checkCommandExists)(element));
25
+ if (!found) {
26
+ throw new Error('Could not find bazel executable (bzl or bazel)');
27
+ }
28
+ cached_bazel_executable = found;
29
+ }
30
+ return cached_bazel_executable;
31
+ }
32
+ function getBazelCommandString(baseCommand, extraArgs, quiet) {
33
+ return `${getBazelCli()} ${BAZEL_PREFIXED_OPTIONS} ${baseCommand} ${extraArgs} ${quiet ? BAZEL_QUIET_OPTIONS : ''} ${BAZEL_POSTFIXED_OPTIONS}`.trim();
34
+ }
35
+ function escapeQuery(str) {
36
+ return str.replaceAll('"', '\\"');
37
+ }
38
+ class BazelLabel {
39
+ repo;
40
+ target;
41
+ name;
42
+ constructor(repo, target, name) {
43
+ this.repo = repo;
44
+ this.target = target;
45
+ this.name = name;
46
+ }
47
+ static fromString(str) {
48
+ let repo;
49
+ if (str.startsWith('@')) {
50
+ const slashSlashIndex = str.indexOf('//');
51
+ if (slashSlashIndex <= 0) {
52
+ throw new Error(`Expected // after repo name (got ${str})`);
53
+ }
54
+ repo = str.slice(1, slashSlashIndex);
55
+ str = str.slice(slashSlashIndex);
56
+ }
57
+ if (str.endsWith('/')) {
58
+ str = str.slice(0, -1);
59
+ }
60
+ const separatorIndex = str.indexOf(':');
61
+ if (separatorIndex >= 0) {
62
+ const target = str.slice(0, separatorIndex);
63
+ const name = str.slice(separatorIndex + 1);
64
+ return new BazelLabel(repo, target, name);
65
+ }
66
+ else {
67
+ return new BazelLabel(repo, str, undefined);
68
+ }
69
+ }
70
+ toString() {
71
+ const repoPrefix = this.repo ? `@${this.repo}` : '';
72
+ if (this.name) {
73
+ return `${repoPrefix}${this.target}:${this.name}`;
74
+ }
75
+ else {
76
+ return repoPrefix + this.target;
77
+ }
78
+ }
79
+ }
80
+ exports.BazelLabel = BazelLabel;
81
+ class BazelCommandCache {
82
+ execute;
83
+ cache = new Map();
84
+ constructor(execute) {
85
+ this.execute = execute;
86
+ }
87
+ get(args) {
88
+ const existingPromise = this.cache.get(args);
89
+ if (existingPromise) {
90
+ return existingPromise;
91
+ }
92
+ const ret = this.execute(args);
93
+ this.cache.set(args, ret);
94
+ return ret;
95
+ }
96
+ }
97
+ class BazelClient {
98
+ workspaceRootCache;
99
+ executionRootCache;
100
+ constructor() {
101
+ this.workspaceRootCache = new BazelCommandCache(async () => {
102
+ return this.runCommandAndGetTrimmedStdOut('info workspace');
103
+ });
104
+ this.executionRootCache = new BazelCommandCache(async () => {
105
+ return this.runCommandAndGetTrimmedStdOut('info execution_root');
106
+ });
107
+ }
108
+ async resolveLabel(str) {
109
+ const unresolvedLabel = BazelLabel.fromString(str);
110
+ const requiresResolve = unresolvedLabel.target.split('/').includes('..');
111
+ if (!requiresResolve) {
112
+ return unresolvedLabel;
113
+ }
114
+ const resolvedTarget = await this.resolveTarget(unresolvedLabel.target);
115
+ return new BazelLabel(unresolvedLabel.repo, resolvedTarget, unresolvedLabel.name);
116
+ }
117
+ async getWorkspaceRoot() {
118
+ return this.workspaceRootCache.get(process.cwd());
119
+ }
120
+ async getExecutionRoot() {
121
+ return this.executionRootCache.get(process.cwd());
122
+ }
123
+ async queryTargetsForKinds(kinds) {
124
+ const command = `query "kind(${kinds.join('|')}, //...)"`;
125
+ const { stdout: targetStrings } = await this.spawnCommand(command);
126
+ const targets = targetStrings.split('\n').filter(target => target.length > 0);
127
+ return targets;
128
+ }
129
+ async queryTargetsForTag(kind) {
130
+ const command = `query 'attr("tags", "${kind}", //...)'`;
131
+ const { stdout: targetStrings } = await this.spawnCommand(command);
132
+ const targets = targetStrings.split('\n').filter(target => target.length > 0);
133
+ return targets;
134
+ }
135
+ async query(queryStr) {
136
+ const command = `query "${escapeQuery(queryStr)}"`;
137
+ return await this.runCommandWithLinesOutput(command);
138
+ }
139
+ async graphQuery(queryStr) {
140
+ const command = `query "${escapeQuery(queryStr)}" --output=graph`;
141
+ const { stdout } = await this.runCommand(command);
142
+ return Digraph_1.Digraph.parse(stdout.trim());
143
+ }
144
+ async queryBuildOutputs(targets, extraArgs = '') {
145
+ const command = `cquery 'set(${targets.join(' ')})' --output files ${extraArgs}`;
146
+ const lines = await this.runCommandWithLinesOutput(command);
147
+ return lines.sort();
148
+ }
149
+ async buildTarget(target, extraArgs = '') {
150
+ const commandBuildTarget = `build ${target} ${extraArgs}`;
151
+ return await this.spawnCommand(commandBuildTarget, 'inherit').catch(() => {
152
+ throw new errors_1.CliError(`Failed to build target: ${target}`);
153
+ });
154
+ }
155
+ async buildTargets(targets) {
156
+ const allTargets = targets.join(' ');
157
+ const commandBuildTarget = `build ${allTargets} --show_result=${targets.length}`;
158
+ return await this.spawnCommand(commandBuildTarget, 'inherit').catch(() => {
159
+ throw new errors_1.CliError(`Failed to build targets: ${targets.join(' ')}`);
160
+ });
161
+ }
162
+ async runTarget(target, extraArgs = '') {
163
+ const commandBuildTarget = `run ${target} ${extraArgs}`;
164
+ return await this.spawnCommand(commandBuildTarget, 'inherit').catch(() => {
165
+ throw new errors_1.CliError(`Failed to run target: ${target}`);
166
+ });
167
+ }
168
+ async queryTargetsByKindWithFilter(queryKind, filters, stdioMode = DEFAULT_STDIO_MODE) {
169
+ let command = `query "kind(${queryKind}, //...)"`;
170
+ if (filters !== undefined && filters.length > 0) {
171
+ const filtersString = filters.join('|');
172
+ command = `query 'filter("${filtersString}", kind("${queryKind}", //...))'`;
173
+ }
174
+ return await this.spawnCommand(command, stdioMode).then(result => {
175
+ const targets = result.stdout.split('\n').filter(target => target.length > 0);
176
+ return targets;
177
+ });
178
+ }
179
+ async testTargets(targets, extraArgs = '') {
180
+ const targetsString = targets.join(' ');
181
+ const commandTestTarget = `test ${targetsString} ${extraArgs}`;
182
+ return await this.spawnCommand(commandTestTarget, 'inherit', extraArgs).catch(() => {
183
+ throw new errors_1.CliError(`Failed to test targets: ${targetsString}`);
184
+ });
185
+ }
186
+ async getVersion() {
187
+ const commandBazelInfoVersion = `version --gnu_format`;
188
+ const { returnCode: returnCode, stdout: versionInfo, stderr: error, } = await this.runCommand(commandBazelInfoVersion);
189
+ return [returnCode, versionInfo.trim(), String(error)];
190
+ }
191
+ async runCommandWithLinesOutput(command) {
192
+ const { stdout: outputStrings } = await this.runCommand(command);
193
+ return outputStrings.split('\n').filter(output => output.length > 0);
194
+ }
195
+ async runCommandAndGetTrimmedStdOut(command) {
196
+ const { stdout: root } = await this.runCommand(command);
197
+ return root.trim();
198
+ }
199
+ runCommand(command) {
200
+ const commandWithOptions = getBazelCommandString(command, '', false);
201
+ return LoadingIndicator_1.LoadingIndicator.fromTask((0, cliUtils_1.runCliCommand)(commandWithOptions, undefined, true))
202
+ .setText(`${(0, logUtils_1.wrapInColor)('Running Bazel command:', constants_1.ANSI_COLORS.YELLOW_COLOR)} ${getBazelCli()} ${command}`)
203
+ .show();
204
+ }
205
+ async spawnCommand(command, stdioMode = DEFAULT_STDIO_MODE, extraArgs = '') {
206
+ const commandWithOptions = getBazelCommandString(command, extraArgs, false);
207
+ console.log(`${(0, logUtils_1.wrapInColor)('Running Bazel command:', constants_1.ANSI_COLORS.YELLOW_COLOR)} ${getBazelCli()} ${command} ${extraArgs}`);
208
+ return await (0, cliUtils_1.spawnCliCommand)(commandWithOptions, undefined, stdioMode, true, true);
209
+ }
210
+ async resolveTarget(pathStr) {
211
+ const absolutePath = path_1.default.resolve(pathStr);
212
+ const root = await this.getWorkspaceRoot();
213
+ if (!absolutePath.startsWith(root)) {
214
+ throw new Error(`Could not resolve target at relative path, found Bazel workspace root at '${root}', resolved target path at ${absolutePath}`);
215
+ }
216
+ return '/' + absolutePath.slice(root.length);
217
+ }
218
+ }
219
+ exports.BazelClient = BazelClient;
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Digraph = void 0;
4
+ function unquote(str) {
5
+ return str.slice(1, -1);
6
+ }
7
+ class Digraph {
8
+ nodeByName = new Map();
9
+ _allNodes = [];
10
+ constructor() { }
11
+ get nodes() {
12
+ return this._allNodes;
13
+ }
14
+ static parse(str) {
15
+ const lines = str.split('\n');
16
+ const graph = new Digraph();
17
+ let index = 0;
18
+ for (const line of lines) {
19
+ const trimmedLine = line.trim();
20
+ if (trimmedLine.startsWith('digraph ')) {
21
+ if (index !== 0) {
22
+ this.throwInvalidGraph();
23
+ }
24
+ }
25
+ else if (trimmedLine === '}') {
26
+ if (index !== lines.length - 1) {
27
+ this.throwInvalidGraph();
28
+ }
29
+ }
30
+ else if (trimmedLine.startsWith('node ')) {
31
+ }
32
+ else if (trimmedLine.startsWith('"')) {
33
+ const edgeIndex = trimmedLine.indexOf('->');
34
+ if (edgeIndex >= 0) {
35
+ const fromEdge = unquote(trimmedLine.slice(0, edgeIndex).trim());
36
+ const toEdge = unquote(trimmedLine.slice(edgeIndex + 2).trim());
37
+ graph.addEdge(fromEdge, toEdge);
38
+ }
39
+ else {
40
+ graph.getOrCreateNode(unquote(trimmedLine));
41
+ }
42
+ }
43
+ else {
44
+ this.throwInvalidGraph();
45
+ }
46
+ index++;
47
+ }
48
+ return graph;
49
+ }
50
+ static throwInvalidGraph() {
51
+ throw new Error('Could not parse digraph');
52
+ }
53
+ getNode(name) {
54
+ return this.nodeByName.get(name);
55
+ }
56
+ getOrCreateNode(name) {
57
+ let node = this.nodeByName.get(name);
58
+ if (!node) {
59
+ node = { name, edges: [] };
60
+ this.nodeByName.set(name, node);
61
+ this._allNodes.push(node);
62
+ }
63
+ return node;
64
+ }
65
+ addEdge(from, to) {
66
+ const fromNode = this.getOrCreateNode(from);
67
+ const toNode = this.getOrCreateNode(to);
68
+ fromNode.edges.push(toNode);
69
+ }
70
+ }
71
+ exports.Digraph = Digraph;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LoadingIndicator = void 0;
4
+ const ora = new Function("return import('ora')");
5
+ class LoadingIndicator {
6
+ runnable;
7
+ text = '';
8
+ successText;
9
+ failureText;
10
+ constructor(runnable) {
11
+ this.runnable = runnable;
12
+ }
13
+ static fromTask(task) {
14
+ return new LoadingIndicator(() => task);
15
+ }
16
+ setText(text) {
17
+ this.text = text;
18
+ return this;
19
+ }
20
+ setSuccessText(successText) {
21
+ this.successText = successText;
22
+ return this;
23
+ }
24
+ setFailureText(failureText) {
25
+ this.failureText = failureText;
26
+ return this;
27
+ }
28
+ show() {
29
+ return ora().then(ora => {
30
+ return ora.oraPromise(this.runnable(), {
31
+ text: this.text,
32
+ successText: this.successText,
33
+ failText: this.failureText,
34
+ });
35
+ });
36
+ }
37
+ }
38
+ exports.LoadingIndicator = LoadingIndicator;