@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,27 @@
1
+
2
+ module.exports = {
3
+ root: true,
4
+ parser: '@typescript-eslint/parser',
5
+ parserOptions: {
6
+ tsconfigRootDir: __dirname,
7
+ project: ['./src/valdi/_configs/eslint.tsconfig.json'],
8
+ },
9
+ plugins: ['@typescript-eslint', 'unused-imports', 'rxjs', 'prettier', '@snapchat/eslint-plugin-valdi'],
10
+ extends: [
11
+ 'eslint:recommended',
12
+ 'plugin:@typescript-eslint/recommended',
13
+ 'plugin:import/recommended',
14
+ 'plugin:import/typescript',
15
+ 'prettier',
16
+ ],
17
+ rules: {
18
+ '@snapchat/valdi/attributed-text-no-array-assignment': 'error',
19
+ '@snapchat/valdi/jsx-no-lambda': 'error',
20
+ '@snapchat/valdi/assign-timer-id': 'error',
21
+ '@snapchat/valdi/only-const-enum': 'off',
22
+ '@snapchat/valdi/no-implicit-index-import': 'error',
23
+ '@snapchat/valdi/mutate-state-without-set-state': 'error',
24
+ '@snapchat/valdi/no-import-from-test-outside-test-dir': 'error',
25
+ '@snapchat/valdi/no-declare-test-without-describe': 'error',
26
+ },
27
+ };
@@ -0,0 +1,4 @@
1
+ *.DS_Store
2
+
3
+ bazel-*
4
+ node_modules
@@ -0,0 +1,7 @@
1
+ {
2
+ "printWidth": 120,
3
+ "singleQuote": true,
4
+ "jsxSingleQuote": true,
5
+ "arrowParens": "avoid",
6
+ "trailingComma": "all"
7
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "root_files": [".watchmanconfig"],
3
+ "ignore_dirs": [
4
+ "bazel-out",
5
+ "bazel-bin",
6
+ "bazel-testlogs"
7
+ ]
8
+ }
@@ -0,0 +1,31 @@
1
+ # valdi_demo
2
+ Demo of a hello world app using Valdi open source
3
+
4
+ ## Usage
5
+
6
+ All commands requires `valdi` to be available on PATH.
7
+
8
+ Get auto completion in VSCode
9
+ ```sh
10
+ valdi projectsync
11
+ ```
12
+
13
+ Build and install iOS:
14
+ ```sh
15
+ valdi install ios
16
+ ```
17
+
18
+ Build and install Android:
19
+ ```sh
20
+ valdi install android
21
+ ```
22
+
23
+ Build and install MacOS:
24
+ ```sh
25
+ valdi install macos
26
+ ```
27
+
28
+ Start hot reloader:
29
+ ```sh
30
+ valdi hotreload
31
+ ```
@@ -0,0 +1,57 @@
1
+ workspace(name = "{{WORKSPACE_NAME}}")
2
+
3
+ load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
4
+ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
5
+
6
+ {{VALDI_IMPORT}}
7
+
8
+ {{VALDI_WIDGETS_IMPORT}}
9
+
10
+ load("@valdi//bzl:workspace_prepare.bzl", "valdi_prepare_workspace")
11
+
12
+ valdi_prepare_workspace()
13
+
14
+ load("@valdi//bzl:workspace_preinit.bzl", "valdi_preinitialize_workspace")
15
+
16
+ valdi_preinitialize_workspace()
17
+
18
+ load("@aspect_bazel_lib//lib:repositories.bzl", "aspect_bazel_lib_dependencies", "aspect_bazel_lib_register_toolchains", "register_yq_toolchains")
19
+
20
+ register_yq_toolchains()
21
+
22
+ # Required bazel-lib dependencies
23
+
24
+ aspect_bazel_lib_dependencies()
25
+
26
+ # Required rules_shell dependencies
27
+ load("@rules_shell//shell:repositories.bzl", "rules_shell_dependencies", "rules_shell_toolchains")
28
+
29
+ rules_shell_dependencies()
30
+
31
+ rules_shell_toolchains()
32
+
33
+ # Register bazel-lib toolchains
34
+
35
+ aspect_bazel_lib_register_toolchains()
36
+
37
+ # Create the host platform repository transitively required by bazel-lib
38
+
39
+ load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
40
+ load("@platforms//host:extension.bzl", "host_platform_repo")
41
+
42
+ maybe(
43
+ host_platform_repo,
44
+ name = "host_platform",
45
+ )
46
+
47
+ load("@valdi//bzl:workspace_init.bzl", "valdi_initialize_workspace")
48
+
49
+ valdi_initialize_workspace()
50
+
51
+ load("@valdi_npm//:repositories.bzl", "npm_repositories")
52
+
53
+ npm_repositories()
54
+
55
+ load("@valdi//bzl:workspace_postinit.bzl", "valdi_post_initialize_workspace")
56
+
57
+ valdi_post_initialize_workspace()
@@ -0,0 +1 @@
1
+ logs_output_dir: ~/.valdi/logs
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "hello_world",
3
+ "version": "1.0.0",
4
+ "description": "Valdi Helloworld app",
5
+ "license": "ISC",
6
+ "devDependencies": {
7
+ "@snap/eslint-plugin-valdi": "1.0.2",
8
+ "@types/eslint": "^9.6.1",
9
+ "@types/jasmine": "^5.1.7",
10
+ "@typescript-eslint/eslint-plugin": "^6.21.0",
11
+ "@typescript-eslint/parser": "^6.21.0",
12
+ "@typescript-eslint/utils": "^6.21.0",
13
+ "eslint": "^8.27.0",
14
+ "eslint-config-prettier": "^8.5.0",
15
+ "eslint-plugin-import": "^2.26.0",
16
+ "eslint-plugin-prettier": "^4.2.1",
17
+ "eslint-plugin-rxjs": "^5.0.2",
18
+ "eslint-plugin-unused-imports": "^3.2.0",
19
+ "jasmine": "^5.6.0",
20
+ "ts-node": "^10.9.2",
21
+ "typescript": "5.3.3"
22
+ }
23
+ }
@@ -0,0 +1,2 @@
1
+ node_modules
2
+ .vscode
@@ -0,0 +1,7 @@
1
+ {
2
+ "printWidth": 120,
3
+ "singleQuote": true,
4
+ "trailingComma": "all",
5
+ "arrowParens": "avoid",
6
+ "tabWidth": 2
7
+ }
package/README.md ADDED
@@ -0,0 +1,123 @@
1
+ # Valdi CLI
2
+
3
+ The Valdi CLI tool provides helpful commands for working with Valdi applications.
4
+
5
+ When working on this module please set your npm registry
6
+
7
+ ```sh
8
+ npm config set registry https://registry.npmjs.org/
9
+ ```
10
+
11
+ ## General Use
12
+
13
+ ### New Module Creations
14
+
15
+ ```sh
16
+ valdi new_module
17
+
18
+ # Create module without prompts
19
+ valdi new_module my_new_module --skip-checks --android-class-path='com.example.my_module' --ios-module-name='XYZMyModule'
20
+
21
+ # Help
22
+ $ valdi new_module --help
23
+ valdi new_module [module-name]
24
+
25
+
26
+ ******************************************
27
+ Valdi Module Creation Guide
28
+ ******************************************
29
+
30
+ Requirements for Valdi module names:
31
+ - May contain: A-Z, a-z, 0-9, '-', '_', '.'
32
+ - Must start with a letter.
33
+
34
+ Recommended Directory Structure:
35
+ my_application/ # Root directory of your application
36
+ ├── WORKSPACE # Bazel Workspace
37
+ ├── BUILD.bazel # Bazel build
38
+ └── modules/
39
+ ├── module_a/
40
+ │ ├── BUILD.bazel
41
+ │ ├── android/ # Native Android sources
42
+ │ ├── ios/ # Native iOS sources
43
+ │ ├── cpp/ # Native C++ sources
44
+ │ └── src/ # Valdi sources
45
+ │ └── ModuleAComponent.tsx
46
+ ├── module_b/
47
+ ├── BUILD.bazel
48
+ │ ├── res/ # Image and font resources
49
+ │ ├── strings/ # Localizable strings
50
+ └── src/
51
+ └── ModuleBComponent.tsx
52
+
53
+ For more comprehensive details, refer to the core-module documentation:
54
+ https://github.com/Snapchat/Valdi/blob/main/docs/docs/core-module.md
55
+
56
+ ******************************************
57
+
58
+
59
+ Positionals:
60
+ module-name Name of the Valdi module.
61
+
62
+ Options:
63
+ --debug Run with debug logging [boolean] [default: false]
64
+ --version Show version number [boolean]
65
+ --help Show help [boolean]
66
+ --skip-checks Skips confirmation prompts. [boolean]
67
+ --android-class-path Android class path to use for generated Android sources. [string]
68
+ --ios-module-name iOS class prefix to use for generated iOS sources. [string]
69
+ ```
70
+
71
+ ## Development Setup
72
+
73
+ # Install dependencies
74
+
75
+ ```sh
76
+ npm install
77
+ ```
78
+
79
+ ## Development
80
+
81
+ # Run the cli
82
+
83
+ ```sh
84
+ npm run main
85
+ ```
86
+
87
+ # Pass in command line arguments
88
+
89
+ ```sh
90
+ npm run main bootstrap -- --confirm-bootstrap
91
+ ```
92
+
93
+ # Build javascript output to ./dist
94
+
95
+ ```sh
96
+ npm run build
97
+ ```
98
+
99
+ # Develop with hotreload
100
+
101
+ ```sh
102
+ npm run watch
103
+ node ./dist/index.js
104
+ node ./dist/index.js bootstrap --confirm-bootstrap
105
+ ```
106
+
107
+ # Show the help menu
108
+
109
+ ```sh
110
+ node ./dist/index.js new_module --help
111
+ ```
112
+
113
+ # Run unit tests
114
+
115
+ ```sh
116
+ npm test
117
+ ```
118
+
119
+ # Install the `valdi` command
120
+
121
+ ```sh
122
+ npm run cli:install
123
+ ```
@@ -0,0 +1,233 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.handler = exports.builder = exports.describe = exports.command = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const path_1 = tslib_1.__importDefault(require("path"));
6
+ const inquirer_1 = tslib_1.__importDefault(require("inquirer"));
7
+ const constants_1 = require("../core/constants");
8
+ const errors_1 = require("../core/errors");
9
+ const BazelClient_1 = require("../utils/BazelClient");
10
+ const cliUtils_1 = require("../utils/cliUtils");
11
+ const copyBootstrapFiles_1 = require("../utils/copyBootstrapFiles");
12
+ const errorUtils_1 = require("../utils/errorUtils");
13
+ const fileUtils_1 = require("../utils/fileUtils");
14
+ const logUtils_1 = require("../utils/logUtils");
15
+ const stringUtils_1 = require("../utils/stringUtils");
16
+ const projectsync_1 = require("./projectsync");
17
+ const githubUtils_1 = require("../utils/githubUtils");
18
+ const ALL_APPLICATION_TEMPLATES = [
19
+ {
20
+ name: 'UI Application',
21
+ path: 'ui_application',
22
+ description: `An application rendering UI in a window on iOS, Android and macOS.`,
23
+ },
24
+ {
25
+ name: 'CLI Application',
26
+ path: 'cli_application',
27
+ description: `A command line application that runs in a terminal`,
28
+ },
29
+ ];
30
+ const VALDI_GIT_URL = 'https://github.com/Snapchat/Valdi';
31
+ const VALDI_WIDGETS_GIT_URL = 'https://github.com/Snapchat/Valdi_Widgets';
32
+ const DEFAULT_VALDI_IMPORT = `
33
+ http_archive(
34
+ name = "valdi",
35
+ strip_prefix = "Valdi-{{VALDI_RELEASE_TAG}}",
36
+ url = "${VALDI_GIT_URL}/archive/{{VALDI_RELEASE_REF}}.tar.gz",
37
+ )`;
38
+ const DEFAULT_VALDI_WIDGETS_IMPORT = `
39
+ http_archive(
40
+ name = "valdi_widgets",
41
+ strip_prefix = "Valdi_Widgets-{{VALDI_WIDGETS_RELEASE_TAG}}",
42
+ url = "${VALDI_WIDGETS_GIT_URL}/archive/{{VALDI_WIDGETS_RELEASE_REF}}.tar.gz",
43
+ )`;
44
+ const LOCAL_VALDI_IMPORT_TEMPLATE = `
45
+ local_repository(
46
+ name = "valdi",
47
+ path = "{{PATH}}",
48
+ )
49
+ `;
50
+ const LOCAL_VALDI_WIDGETS_IMPORT_TEMPLATE = `
51
+ local_repository(
52
+ name = "valdi_widgets",
53
+ path = "{{PATH}}",
54
+ )
55
+ `;
56
+ function isAlreadyInitialized() {
57
+ return (0, fileUtils_1.fileExists)(path_1.default.join(process.cwd(), 'WORKSPACE'));
58
+ }
59
+ async function getShouldBootstrap(argv) {
60
+ return argv.getArgumentOrResolve('confirmBootstrap', () => {
61
+ return (0, cliUtils_1.getUserConfirmation)('Do you want to create a new project in the current directory?', true);
62
+ });
63
+ }
64
+ const defaultProjectName = path_1.default.basename(process.cwd());
65
+ async function getApplicationType(argv) {
66
+ const applicationType = argv.getArgument('applicationType');
67
+ if (applicationType) {
68
+ const target = ALL_APPLICATION_TEMPLATES.find(target => target.path === applicationType);
69
+ if (target) {
70
+ return target;
71
+ }
72
+ else {
73
+ throw new errors_1.CliError(`Unknown application type: ${applicationType}`);
74
+ }
75
+ }
76
+ const choices = ALL_APPLICATION_TEMPLATES.map(target => ({
77
+ name: `${(0, logUtils_1.wrapInColor)(target.name, constants_1.ANSI_COLORS.GREEN_COLOR)} . ${target.description}`,
78
+ value: target,
79
+ }));
80
+ return await (0, cliUtils_1.getUserChoice)(choices, `Please choose the application type:`);
81
+ }
82
+ async function getProjectName(argv) {
83
+ return argv.getArgumentOrResolve('projectName', async () => {
84
+ const result = await inquirer_1.default.prompt([
85
+ {
86
+ type: 'input',
87
+ name: 'projectName',
88
+ message: 'Please provide a name for this project:',
89
+ default: defaultProjectName,
90
+ },
91
+ ]);
92
+ return result.projectName;
93
+ });
94
+ }
95
+ function getValdiImport(argv, valdiReleaseRef) {
96
+ const valdiImport = argv.getArgument('valdiImport');
97
+ if (valdiImport) {
98
+ return (0, fileUtils_1.processReplacements)(LOCAL_VALDI_IMPORT_TEMPLATE, { PATH: valdiImport });
99
+ }
100
+ else {
101
+ const valdiReleaseTag = valdiReleaseRef.split('/').pop();
102
+ return (0, fileUtils_1.processReplacements)(DEFAULT_VALDI_IMPORT, {
103
+ VALDI_RELEASE_REF: valdiReleaseRef,
104
+ VALDI_RELEASE_TAG: valdiReleaseTag,
105
+ });
106
+ }
107
+ }
108
+ function getValdiWidgetsImport(argv, valdiWidgetsReleaseRef) {
109
+ const valdiWidgetsImport = argv.getArgument('valdiWidgetsImport');
110
+ if (valdiWidgetsImport) {
111
+ return (0, fileUtils_1.processReplacements)(LOCAL_VALDI_WIDGETS_IMPORT_TEMPLATE, { PATH: valdiWidgetsImport });
112
+ }
113
+ else {
114
+ const valdiWidgetsReleaseTag = valdiWidgetsReleaseRef.split('/').pop();
115
+ return (0, fileUtils_1.processReplacements)(DEFAULT_VALDI_WIDGETS_IMPORT, {
116
+ VALDI_WIDGETS_RELEASE_REF: valdiWidgetsReleaseRef,
117
+ VALDI_WIDGETS_RELEASE_TAG: valdiWidgetsReleaseTag,
118
+ });
119
+ }
120
+ }
121
+ function initializeConfigFiles(projectName, template, valdiImport, valdiWidgetsImport) {
122
+ const TEMPLATE_FILES = [
123
+ fileUtils_1.TemplateFile.init(constants_1.TEMPLATE_BASE_PATHS.USER_CONFIG).withOutputPath((0, fileUtils_1.resolveFilePath)(constants_1.VALDI_CONFIG_PATHS[0] ?? '')),
124
+ fileUtils_1.TemplateFile.init(constants_1.TEMPLATE_BASE_PATHS.BAZEL_VERSION),
125
+ fileUtils_1.TemplateFile.init(constants_1.TEMPLATE_BASE_PATHS.WORKSPACE).withReplacements({
126
+ WORKSPACE_NAME: projectName,
127
+ VALDI_IMPORT: valdiImport,
128
+ VALDI_WIDGETS_IMPORT: valdiWidgetsImport,
129
+ }),
130
+ fileUtils_1.TemplateFile.init(constants_1.TEMPLATE_BASE_PATHS.BAZEL_RC),
131
+ fileUtils_1.TemplateFile.init(constants_1.TEMPLATE_BASE_PATHS.README),
132
+ fileUtils_1.TemplateFile.init(constants_1.TEMPLATE_BASE_PATHS.GIT_IGNORE),
133
+ fileUtils_1.TemplateFile.init(constants_1.TEMPLATE_BASE_PATHS.WATCHMAN_CONFIG),
134
+ ];
135
+ TEMPLATE_FILES.forEach(templateFile => {
136
+ console.log((0, logUtils_1.wrapInColor)(`Creating ${templateFile.baseName} in ${templateFile.outputPath}...`, constants_1.ANSI_COLORS.YELLOW_COLOR));
137
+ templateFile.expandTemplate();
138
+ });
139
+ console.log((0, logUtils_1.wrapInColor)(`Initializing ${template.name} application...`, constants_1.ANSI_COLORS.YELLOW_COLOR));
140
+ const sourcePath = path_1.default.join(constants_1.BOOTSTRAP_DIR_PATH, 'apps', template.path);
141
+ const destPath = process.cwd();
142
+ const replacements = {
143
+ MODULE_NAME: projectName,
144
+ MODULE_NAME_PASCAL_CASED: (0, stringUtils_1.toPascalCase)(projectName),
145
+ };
146
+ (0, copyBootstrapFiles_1.copyBootstrapFiles)(sourcePath, destPath, replacements);
147
+ }
148
+ async function valdiBootstrap(argv) {
149
+ const curDir = process.cwd();
150
+ console.log(`\nCurrent directory: ${(0, logUtils_1.wrapInColor)(curDir, constants_1.ANSI_COLORS.GREEN_COLOR)}`);
151
+ if (isAlreadyInitialized()) {
152
+ if (argv.getArgument('withCleanup')) {
153
+ console.log((0, logUtils_1.wrapInColor)('Deleting all files in current directory...', constants_1.ANSI_COLORS.YELLOW_COLOR));
154
+ (0, fileUtils_1.deleteAll)(curDir);
155
+ }
156
+ else {
157
+ throw new errors_1.CliError(`Detected existing project files. Please remove them before re-running 'valdi bootstrap'.\nYou can run '${(0, logUtils_1.wrapInColor)('valdi bootstrap --with-cleanup', constants_1.ANSI_COLORS.YELLOW_COLOR, constants_1.ANSI_COLORS.RED_COLOR)}' to remove ALL FILES in the current directory.`);
158
+ }
159
+ }
160
+ else if (!(0, fileUtils_1.isDirectoryEmpty)(curDir)) {
161
+ throw new errors_1.CliError("Current directory is not empty. Please run 'valdi bootstrap' in an empty directory or manually clean up existing files.");
162
+ }
163
+ if (!(await getShouldBootstrap(argv))) {
164
+ throw new errors_1.CliError('Bootstrap process aborted.');
165
+ }
166
+ const applicationType = await getApplicationType(argv);
167
+ const projectName = await getProjectName(argv);
168
+ if (!projectName) {
169
+ throw new errors_1.CliError('Project name cannot be empty.');
170
+ }
171
+ const valdiCommitHash = await (0, githubUtils_1.resolveLatestReleaseRef)(`${VALDI_GIT_URL}.git`);
172
+ const valdiWidgetsCommitHash = await (0, githubUtils_1.resolveLatestReleaseRef)(`${VALDI_WIDGETS_GIT_URL}.git`);
173
+ const valdiImport = getValdiImport(argv, valdiCommitHash);
174
+ const valdiWidgetsImport = getValdiWidgetsImport(argv, valdiWidgetsCommitHash);
175
+ console.log((0, logUtils_1.wrapInColor)('Initializing config files...', constants_1.ANSI_COLORS.BLUE_COLOR));
176
+ initializeConfigFiles(projectName, applicationType, valdiImport, valdiWidgetsImport);
177
+ console.log((0, logUtils_1.wrapInColor)('Verifying Bazel installation...', constants_1.ANSI_COLORS.BLUE_COLOR));
178
+ const bazel = new BazelClient_1.BazelClient();
179
+ const [returnCode, versionInfo, errors] = await bazel.getVersion();
180
+ if (returnCode !== 0) {
181
+ throw new errors_1.CliError(`Bazel installation failed to verify with errors: ${errors.toString()}`);
182
+ }
183
+ console.log(versionInfo);
184
+ if (argv.getArgument('skipProjectsync')) {
185
+ console.log((0, logUtils_1.wrapInColor)('Skipping projectsync', constants_1.ANSI_COLORS.YELLOW_COLOR));
186
+ }
187
+ else {
188
+ console.log((0, logUtils_1.wrapInColor)('Running projectsync...', constants_1.ANSI_COLORS.BLUE_COLOR));
189
+ await (0, projectsync_1.runProjectSync)(bazel, await (0, projectsync_1.getAllProjectSyncTargets)(bazel), undefined, true);
190
+ }
191
+ console.log((0, logUtils_1.wrapInColor)('Bootstrap complete!', constants_1.ANSI_COLORS.GREEN_COLOR));
192
+ }
193
+ exports.command = 'bootstrap';
194
+ exports.describe = 'Prepares and initializes a project to build and run in Valdi';
195
+ const builder = (yargs) => {
196
+ yargs
197
+ .option('confirmBootstrap', {
198
+ describe: 'Skip confirmation prompt and start bootstrap process',
199
+ type: 'boolean',
200
+ alias: 'y',
201
+ })
202
+ .option('applicationType', {
203
+ describe: 'Type of application to create',
204
+ alias: 't',
205
+ })
206
+ .option('projectName', {
207
+ describe: 'Name of the project',
208
+ type: 'string',
209
+ alias: 'n',
210
+ })
211
+ .option('valdiImport', {
212
+ describe: 'Path to a local checkout of the Valdi repo. If not specified, uses the latest release from GitHub.',
213
+ type: 'string',
214
+ alias: 'l',
215
+ })
216
+ .option('valdiWidgetsImport', {
217
+ describe: 'Path to a local checkout of the Valdi_Widgets repo. If not specified, uses the latest release from GitHub.',
218
+ type: 'string',
219
+ alias: 'w',
220
+ })
221
+ .option('skipProjectsync', {
222
+ describe: 'Skip projectsync for testing purposes',
223
+ type: 'boolean',
224
+ alias: 'p',
225
+ })
226
+ .option('withCleanup', {
227
+ describe: 'Deletes all existing files in the current directory before initiating bootstrap',
228
+ type: 'boolean',
229
+ alias: 'c',
230
+ });
231
+ };
232
+ exports.builder = builder;
233
+ exports.handler = (0, errorUtils_1.makeCommandHandler)(valdiBootstrap);
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.handler = exports.builder = exports.describe = exports.command = void 0;
4
+ const constants_1 = require("../core/constants");
5
+ const BazelClient_1 = require("../utils/BazelClient");
6
+ const applicationUtils_1 = require("../utils/applicationUtils");
7
+ const buildInfo_1 = require("../utils/buildInfo");
8
+ const errorUtils_1 = require("../utils/errorUtils");
9
+ const logUtils_1 = require("../utils/logUtils");
10
+ async function valdiBuild(argv) {
11
+ const bazel = new BazelClient_1.BazelClient();
12
+ const buildInfo = await (0, buildInfo_1.getBuildInfo)(argv, bazel, false);
13
+ console.log(`Building: ${(0, logUtils_1.wrapInColor)(buildInfo.application, constants_1.ANSI_COLORS.GREEN_COLOR)}`);
14
+ switch (buildInfo.platform) {
15
+ case constants_1.PLATFORM.ANDROID: {
16
+ const outputFilePath = await argv.getArgumentOrResolve('target_output_path', () => {
17
+ console.log('Resolving output paths...');
18
+ return (0, applicationUtils_1.getOutputFilePath)(bazel, (0, applicationUtils_1.applicationExtensionForPlatform)(buildInfo.platform), buildInfo.application, buildInfo.bazelArgs);
19
+ });
20
+ await bazel.buildTarget(buildInfo.application, buildInfo.bazelArgs);
21
+ break;
22
+ }
23
+ case constants_1.PLATFORM.IOS: {
24
+ console.log('Building iOS application...');
25
+ await bazel.buildTarget(buildInfo.application, buildInfo.bazelArgs);
26
+ (0, errorUtils_1.logReproduceThisCommandIfNeeded)(argv);
27
+ break;
28
+ }
29
+ case constants_1.PLATFORM.MACOS: {
30
+ (0, errorUtils_1.logReproduceThisCommandIfNeeded)(argv);
31
+ console.log('Building MacOS application...');
32
+ await bazel.buildTarget(buildInfo.application, buildInfo.bazelArgs);
33
+ break;
34
+ }
35
+ case constants_1.PLATFORM.CLI: {
36
+ (0, errorUtils_1.logReproduceThisCommandIfNeeded)(argv);
37
+ console.log('Build CLI application...');
38
+ await bazel.buildTarget(buildInfo.application, buildInfo.bazelArgs);
39
+ break;
40
+ }
41
+ }
42
+ }
43
+ exports.command = 'build <platform>';
44
+ exports.describe = 'Build the application';
45
+ exports.builder = (0, applicationUtils_1.makeArgsBuilder)((yargs) => {
46
+ yargs
47
+ .option('application', {
48
+ describe: 'Name of the application to install',
49
+ type: 'string',
50
+ requiresArg: true,
51
+ })
52
+ .option('device_id', {
53
+ describe: 'Device ID that will receive the application',
54
+ type: 'string',
55
+ requiresArg: true,
56
+ })
57
+ .option('target_output_path', {
58
+ describe: 'The output path for the Bazel target',
59
+ type: 'string',
60
+ requiresArg: true,
61
+ })
62
+ .option('simulator', {
63
+ describe: 'Whether to build for simulator or for device',
64
+ type: 'boolean',
65
+ });
66
+ });
67
+ exports.handler = (0, errorUtils_1.makeCommandHandler)(valdiBuild);
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.handler = exports.builder = exports.describe = exports.command = void 0;
4
+ const constants_1 = require("../core/constants");
5
+ const setupEntryPoint_1 = require("../setup/setupEntryPoint");
6
+ const errorUtils_1 = require("../utils/errorUtils");
7
+ const logUtils_1 = require("../utils/logUtils");
8
+ async function valdiSetup() {
9
+ const returnCode = await (0, setupEntryPoint_1.beginEnvironmentSetup)();
10
+ if (returnCode !== 0) {
11
+ console.log((0, logUtils_1.wrapInColor)('Environment setup did not complete successfully.', constants_1.ANSI_COLORS.YELLOW_COLOR));
12
+ }
13
+ }
14
+ exports.command = 'dev_setup';
15
+ exports.describe = 'Sets up the development environment for Valdi';
16
+ const builder = () => { };
17
+ exports.builder = builder;
18
+ exports.handler = (0, errorUtils_1.makeCommandHandler)(valdiSetup);