@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,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,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
|
+
}
|
package/.prettierignore
ADDED
package/.prettierrc.json
ADDED
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);
|