@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
package/.bazelignore
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
# AGENTS.md - Guide for AI Coding Assistants
|
|
2
|
+
|
|
3
|
+
This document provides context and guidelines for AI coding assistants working on this Valdi CLI application.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This is a Valdi command-line application that runs in a terminal. Valdi compiles TypeScript to native code, enabling you to write performant CLI tools in TypeScript with access to native platform APIs.
|
|
8
|
+
|
|
9
|
+
## Project Structure
|
|
10
|
+
|
|
11
|
+
- **`modules/`** - Your application modules
|
|
12
|
+
- Each module contains TypeScript source files
|
|
13
|
+
- `BUILD.bazel` files define how modules are built
|
|
14
|
+
- `src/` contains your application logic code
|
|
15
|
+
- **`WORKSPACE`** - Bazel workspace configuration
|
|
16
|
+
- **`config.yaml`** - Valdi project configuration
|
|
17
|
+
- **`.bazelrc`** - Bazel build settings
|
|
18
|
+
|
|
19
|
+
## Key Technologies
|
|
20
|
+
|
|
21
|
+
- **Valdi** - Framework that compiles TypeScript to native code
|
|
22
|
+
- **TypeScript** - Primary development language
|
|
23
|
+
- **Bazel** - Build system (note: `bzl` is an alias for `bazel`)
|
|
24
|
+
|
|
25
|
+
## Development Workflow
|
|
26
|
+
|
|
27
|
+
### Initial Setup
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
# Install Valdi CLI (if not already installed)
|
|
31
|
+
cd path/to/valdi/npm_modules/cli
|
|
32
|
+
npm run cli:install
|
|
33
|
+
|
|
34
|
+
# Setup development environment
|
|
35
|
+
valdi dev_setup
|
|
36
|
+
|
|
37
|
+
# Sync project (run after changing dependencies or config)
|
|
38
|
+
valdi projectsync
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Building and Running
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
# Build the CLI application
|
|
45
|
+
bazel build //modules/{{MODULE_NAME}}:{{MODULE_NAME}}
|
|
46
|
+
|
|
47
|
+
# Run the application
|
|
48
|
+
bazel run //modules/{{MODULE_NAME}}:{{MODULE_NAME}}
|
|
49
|
+
|
|
50
|
+
# Build and run with arguments
|
|
51
|
+
bazel run //modules/{{MODULE_NAME}}:{{MODULE_NAME}} -- --your-args-here
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Common Commands
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
# Sync project configuration
|
|
58
|
+
valdi projectsync
|
|
59
|
+
|
|
60
|
+
# Build specific targets
|
|
61
|
+
bazel build //modules/{{MODULE_NAME}}:{{MODULE_NAME}}
|
|
62
|
+
|
|
63
|
+
# Run tests
|
|
64
|
+
bazel test //modules/{{MODULE_NAME}}:tests
|
|
65
|
+
|
|
66
|
+
# Clean build cache
|
|
67
|
+
bazel clean
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## TypeScript Development
|
|
71
|
+
|
|
72
|
+
### Entry Point
|
|
73
|
+
|
|
74
|
+
Your CLI application typically has an entry point file (e.g., `index.ts`):
|
|
75
|
+
|
|
76
|
+
```typescript
|
|
77
|
+
// Example CLI application entry point
|
|
78
|
+
function main(args: string[]) {
|
|
79
|
+
console.log('Hello from Valdi CLI!');
|
|
80
|
+
console.log('Arguments:', args);
|
|
81
|
+
|
|
82
|
+
// Your application logic here
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Entry point
|
|
86
|
+
main(process.argv.slice(2));
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Using Standard Library Modules
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
// HTTP requests
|
|
93
|
+
import { HTTPClient } from 'valdi_http/src/HTTPClient';
|
|
94
|
+
|
|
95
|
+
// Utilities
|
|
96
|
+
import { Base64 } from 'coreutils/src/Base64';
|
|
97
|
+
import { UUID } from 'coreutils/src/uuidUtils';
|
|
98
|
+
|
|
99
|
+
// File system operations
|
|
100
|
+
import { FileSystem } from 'file_system/src/FileSystem';
|
|
101
|
+
|
|
102
|
+
// Persistence
|
|
103
|
+
import { PersistentStorage } from 'persistence/src/PersistentStorage';
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Available Standard Library Modules
|
|
107
|
+
|
|
108
|
+
- `valdi_core` - Core runtime APIs
|
|
109
|
+
- `valdi_http` - Promise-based HTTP client for network requests
|
|
110
|
+
- `valdi_rxjs` - RxJS integration for reactive programming
|
|
111
|
+
- `persistence` - Key-value storage with encryption and TTL support
|
|
112
|
+
- `file_system` - Low-level file I/O operations
|
|
113
|
+
- `foundation`, `coreutils` - Common utilities (arrays, Base64, LRU cache, UUID, etc.)
|
|
114
|
+
- `worker` - Worker service support for background execution
|
|
115
|
+
|
|
116
|
+
## Debugging
|
|
117
|
+
|
|
118
|
+
- **VSCode Integration** - Set breakpoints and debug TypeScript code
|
|
119
|
+
- **Console logging** - Use `console.log()`, `console.error()`, etc.
|
|
120
|
+
- **Command line arguments** - Pass arguments after `--` in bazel run
|
|
121
|
+
|
|
122
|
+
## Common Patterns
|
|
123
|
+
|
|
124
|
+
### Command Line Arguments
|
|
125
|
+
|
|
126
|
+
```typescript
|
|
127
|
+
interface CliArgs {
|
|
128
|
+
input?: string;
|
|
129
|
+
output?: string;
|
|
130
|
+
verbose?: boolean;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function parseArgs(args: string[]): CliArgs {
|
|
134
|
+
const parsed: CliArgs = {};
|
|
135
|
+
|
|
136
|
+
for (let i = 0; i < args.length; i++) {
|
|
137
|
+
if (args[i] === '--input' && i + 1 < args.length) {
|
|
138
|
+
parsed.input = args[i + 1];
|
|
139
|
+
i++;
|
|
140
|
+
} else if (args[i] === '--output' && i + 1 < args.length) {
|
|
141
|
+
parsed.output = args[i + 1];
|
|
142
|
+
i++;
|
|
143
|
+
} else if (args[i] === '--verbose') {
|
|
144
|
+
parsed.verbose = true;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return parsed;
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### Async Operations
|
|
153
|
+
|
|
154
|
+
```typescript
|
|
155
|
+
async function fetchData(url: string): Promise<void> {
|
|
156
|
+
try {
|
|
157
|
+
const client = new HTTPClient();
|
|
158
|
+
const response = await client.get(url);
|
|
159
|
+
console.log('Response:', response);
|
|
160
|
+
} catch (error) {
|
|
161
|
+
console.error('Error fetching data:', error);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### File Operations
|
|
167
|
+
|
|
168
|
+
```typescript
|
|
169
|
+
import { FileSystem } from 'file_system/src/FileSystem';
|
|
170
|
+
|
|
171
|
+
function readConfigFile(path: string): string {
|
|
172
|
+
try {
|
|
173
|
+
const fs = FileSystem.getInstance();
|
|
174
|
+
return fs.readFileSync(path, 'utf8');
|
|
175
|
+
} catch (error) {
|
|
176
|
+
console.error('Error reading file:', error);
|
|
177
|
+
return '';
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
## Common Pitfalls
|
|
183
|
+
|
|
184
|
+
1. **Always run `valdi projectsync`** after changing dependencies or config files
|
|
185
|
+
2. **Use async/await** for asynchronous operations
|
|
186
|
+
3. **Error handling** - Always handle errors gracefully in CLI applications
|
|
187
|
+
4. **Build cache** - If builds seem stuck, try `bazel clean`
|
|
188
|
+
5. **Arguments** - Remember to use `--` before passing arguments to your CLI app
|
|
189
|
+
|
|
190
|
+
## Important Files
|
|
191
|
+
|
|
192
|
+
- **`config.yaml`** - Project configuration (dependencies, settings)
|
|
193
|
+
- **`WORKSPACE`** - Bazel workspace and external dependencies
|
|
194
|
+
- **`BUILD.bazel`** - Build rules for each module
|
|
195
|
+
- **`.bazelrc`** - Bazel build flags and configuration
|
|
196
|
+
|
|
197
|
+
## Getting Help
|
|
198
|
+
|
|
199
|
+
- **Documentation** - Valdi docs in the framework repository at `/docs/`
|
|
200
|
+
- **Discord** - Join the [Valdi Discord community](https://discord.gg/uJyNEeYX2U)
|
|
201
|
+
- **Examples** - Check `/apps/` directory in Valdi repository for examples
|
|
202
|
+
- **CLI Documentation** - See `/docs/docs/workflow-cli-application.md`
|
|
203
|
+
|
|
204
|
+
## Key Points for AI Assistants
|
|
205
|
+
|
|
206
|
+
1. **This is a CLI application** - No UI components, terminal-based
|
|
207
|
+
2. **TypeScript compiles to native** - Performant native executable
|
|
208
|
+
3. **Use Bazel commands** - Primary tool for building and running CLI apps
|
|
209
|
+
4. **Standard library available** - Access to HTTP, file system, persistence, etc.
|
|
210
|
+
5. **Cross-platform** - Can build for Linux, macOS, and potentially other platforms
|
|
211
|
+
|
|
212
|
+
---
|
|
213
|
+
|
|
214
|
+
*This document is intended for AI coding assistants to quickly understand this Valdi CLI application. For comprehensive Valdi framework documentation, refer to the main Valdi repository at https://github.com/Snapchat/Valdi*
|
|
215
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
console.log('Hello world!');
|
|
@@ -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,202 @@
|
|
|
1
|
+
# AGENTS.md - Guide for AI Coding Assistants
|
|
2
|
+
|
|
3
|
+
This document provides context and guidelines for AI coding assistants working on this Valdi application.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This is a Valdi application that runs natively on iOS, Android, and macOS. Valdi is a cross-platform UI framework that compiles declarative TypeScript components to native views - no web views, no JavaScript bridges.
|
|
8
|
+
|
|
9
|
+
## Project Structure
|
|
10
|
+
|
|
11
|
+
- **`modules/`** - Your application modules
|
|
12
|
+
- Each module contains TypeScript/TSX source files
|
|
13
|
+
- `BUILD.bazel` files define how modules are built
|
|
14
|
+
- `src/` contains your component and business logic code
|
|
15
|
+
- **`WORKSPACE`** - Bazel workspace configuration
|
|
16
|
+
- **`config.yaml`** - Valdi project configuration
|
|
17
|
+
- **`.bazelrc`** - Bazel build settings
|
|
18
|
+
|
|
19
|
+
## Key Technologies
|
|
20
|
+
|
|
21
|
+
- **Valdi** - Cross-platform UI framework that compiles to native code
|
|
22
|
+
- **TypeScript/TSX** - React-like syntax for declarative UI (but compiles to native, not React)
|
|
23
|
+
- **Bazel** - Build system (note: `bzl` is an alias for `bazel`)
|
|
24
|
+
- **Flexbox** - Layout system with automatic RTL support
|
|
25
|
+
|
|
26
|
+
## Development Workflow
|
|
27
|
+
|
|
28
|
+
### Initial Setup
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
# Install Valdi CLI (if not already installed)
|
|
32
|
+
cd path/to/valdi/npm_modules/cli
|
|
33
|
+
npm run cli:install
|
|
34
|
+
|
|
35
|
+
# Setup development environment
|
|
36
|
+
valdi dev_setup
|
|
37
|
+
|
|
38
|
+
# Sync project (run after changing dependencies or config)
|
|
39
|
+
valdi projectsync
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Building and Running
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
# Install and run on iOS
|
|
46
|
+
valdi install ios
|
|
47
|
+
|
|
48
|
+
# Install and run on Android
|
|
49
|
+
valdi install android
|
|
50
|
+
|
|
51
|
+
# Install and run on macOS
|
|
52
|
+
valdi install macos
|
|
53
|
+
|
|
54
|
+
# Start hot reload (for instant updates while developing)
|
|
55
|
+
valdi hotreload
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Common Commands
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
# Sync project configuration and generate IDE files
|
|
62
|
+
valdi projectsync
|
|
63
|
+
|
|
64
|
+
# Build specific targets with Bazel
|
|
65
|
+
bazel build //modules/{{MODULE_NAME}}:{{MODULE_NAME}}
|
|
66
|
+
|
|
67
|
+
# Run tests
|
|
68
|
+
bazel test //modules/{{MODULE_NAME}}:tests
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Valdi Component Basics
|
|
72
|
+
|
|
73
|
+
Components use a class-based pattern with lifecycle methods:
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
import { Component } from 'valdi_core/src/Component';
|
|
77
|
+
|
|
78
|
+
class MyComponent extends Component {
|
|
79
|
+
// Required: Render the component's UI
|
|
80
|
+
onRender() {
|
|
81
|
+
<view backgroundColor="#FFFC00" padding={30}>
|
|
82
|
+
<label value="Hello World" color="black" />
|
|
83
|
+
</view>;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Optional lifecycle methods:
|
|
87
|
+
// onMount() - Called when component is first mounted
|
|
88
|
+
// onUnmount() - Called before component is removed
|
|
89
|
+
// onUpdate(prevProps) - Called when component updates
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Key Concepts
|
|
94
|
+
|
|
95
|
+
- **TSX/JSX Syntax** - Similar to React but compiles to native views
|
|
96
|
+
- **State Management** - Use component properties and setState
|
|
97
|
+
- **Flexbox Layout** - Use flexbox properties for layout
|
|
98
|
+
- **Event Handlers** - Handle user interactions with callbacks
|
|
99
|
+
- **Provider Pattern** - Dependency injection for passing services down the component tree
|
|
100
|
+
|
|
101
|
+
## Common Patterns
|
|
102
|
+
|
|
103
|
+
### Styling Components
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
<view
|
|
107
|
+
backgroundColor="#FFFFFF"
|
|
108
|
+
padding={20}
|
|
109
|
+
flexDirection="column"
|
|
110
|
+
alignItems="center"
|
|
111
|
+
>
|
|
112
|
+
<label value="Styled text" fontSize={16} color="#000000" />
|
|
113
|
+
</view>
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### Handling Events
|
|
117
|
+
|
|
118
|
+
```typescript
|
|
119
|
+
class MyButton extends Component {
|
|
120
|
+
private handlePress() {
|
|
121
|
+
console.log('Button pressed!');
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
onRender() {
|
|
125
|
+
<view onPress={() => this.handlePress()}>
|
|
126
|
+
<label value="Click Me" />
|
|
127
|
+
</view>;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### Using Providers
|
|
133
|
+
|
|
134
|
+
```typescript
|
|
135
|
+
import { Provider } from 'valdi_core/src/Provider';
|
|
136
|
+
|
|
137
|
+
class App extends Component {
|
|
138
|
+
onRender() {
|
|
139
|
+
const myService = new MyService();
|
|
140
|
+
|
|
141
|
+
<Provider value={myService}>
|
|
142
|
+
<MyChildComponent />
|
|
143
|
+
</Provider>;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## Available Standard Library Modules
|
|
149
|
+
|
|
150
|
+
- `valdi_core` - Core component and runtime APIs
|
|
151
|
+
- `valdi_http` - Promise-based HTTP client for network requests
|
|
152
|
+
- `valdi_navigation` - Navigation utilities
|
|
153
|
+
- `valdi_rxjs` - RxJS integration for reactive programming
|
|
154
|
+
- `persistence` - Key-value storage with encryption and TTL support
|
|
155
|
+
- `foundation`, `coreutils` - Common utilities (arrays, Base64, LRU cache, UUID, etc.)
|
|
156
|
+
- `worker` - Worker service support for background JavaScript execution
|
|
157
|
+
|
|
158
|
+
## Debugging
|
|
159
|
+
|
|
160
|
+
- **VSCode Integration** - Set breakpoints and debug TypeScript code
|
|
161
|
+
- **Hermes Debugger** - Use Chrome DevTools for JavaScript debugging
|
|
162
|
+
- **Hot Reload** - See changes instantly without rebuilding
|
|
163
|
+
- **Native Debugging** - Use Xcode or Android Studio for platform-specific issues
|
|
164
|
+
|
|
165
|
+
See Valdi documentation at `/docs/docs/workflow-hermes-debugger.md` for detailed debugging instructions.
|
|
166
|
+
|
|
167
|
+
## Common Pitfalls
|
|
168
|
+
|
|
169
|
+
1. **Always run `valdi projectsync`** after changing dependencies or config files
|
|
170
|
+
2. **Use hot reload during development** - Much faster than rebuilding
|
|
171
|
+
3. **Flexbox layout** - Valdi uses flexbox, not native iOS/Android layout
|
|
172
|
+
4. **Component state** - Remember to call `setState()` to trigger re-renders
|
|
173
|
+
5. **Build cache** - If builds seem stuck, try `bazel clean`
|
|
174
|
+
|
|
175
|
+
## Important Files
|
|
176
|
+
|
|
177
|
+
- **`config.yaml`** - Project configuration (dependencies, settings)
|
|
178
|
+
- **`WORKSPACE`** - Bazel workspace and external dependencies
|
|
179
|
+
- **`BUILD.bazel`** - Build rules for each module
|
|
180
|
+
- **`.bazelrc`** - Bazel build flags and configuration
|
|
181
|
+
|
|
182
|
+
## Getting Help
|
|
183
|
+
|
|
184
|
+
- **Documentation** - Valdi docs in the framework repository at `/docs/`
|
|
185
|
+
- **Discord** - Join the [Valdi Discord community](https://discord.gg/uJyNEeYX2U)
|
|
186
|
+
- **Examples** - Check `/apps/` directory in Valdi repository for examples
|
|
187
|
+
- **API Reference** - See `/docs/api/` for comprehensive API documentation
|
|
188
|
+
- **Codelabs** - Step-by-step tutorials at `/docs/codelabs/`
|
|
189
|
+
|
|
190
|
+
## Key Points for AI Assistants
|
|
191
|
+
|
|
192
|
+
1. **This is a Valdi application** - Not React, React Native, or web-based
|
|
193
|
+
2. **TSX compiles to native** - No JavaScript runtime on device, components are compiled
|
|
194
|
+
3. **Use `valdi` CLI commands** - Primary tool for building and running
|
|
195
|
+
4. **Hot reload is fast** - Encourage using it for rapid iteration
|
|
196
|
+
5. **Bazel is the build system** - Direct bazel commands available but CLI preferred
|
|
197
|
+
6. **Cross-platform by default** - Code runs on iOS, Android, and macOS
|
|
198
|
+
|
|
199
|
+
---
|
|
200
|
+
|
|
201
|
+
*This document is intended for AI coding assistants to quickly understand this Valdi application. For comprehensive Valdi framework documentation, refer to the main Valdi repository at https://github.com/Snapchat/Valdi*
|
|
202
|
+
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
load("@valdi//bzl/valdi:valdi_application.bzl", "valdi_application")
|
|
2
|
+
load("@valdi//bzl/valdi:valdi_exported_library.bzl", "valdi_exported_library")
|
|
3
|
+
|
|
4
|
+
valdi_application(
|
|
5
|
+
name = "{{MODULE_NAME}}_app",
|
|
6
|
+
ios_bundle_id = "com.website.{{MODULE_NAME}}",
|
|
7
|
+
ios_families = ["iphone"],
|
|
8
|
+
root_component_path = "App@{{MODULE_NAME}}/src/App",
|
|
9
|
+
title = "{{MODULE_NAME}}",
|
|
10
|
+
version = "1.0.0",
|
|
11
|
+
deps = ["//modules/{{MODULE_NAME}}"],
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
valdi_exported_library(
|
|
15
|
+
name = "{{MODULE_NAME}}_export",
|
|
16
|
+
ios_bundle_id = "com.website.{{MODULE_NAME}}.lib",
|
|
17
|
+
ios_bundle_name = "{{MODULE_NAME_PASCAL_CASED}}",
|
|
18
|
+
deps = ["//modules/{{MODULE_NAME}}"],
|
|
19
|
+
)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
load("@valdi//bzl/valdi:valdi_module.bzl", "valdi_module")
|
|
2
|
+
|
|
3
|
+
valdi_module(
|
|
4
|
+
name = "{{MODULE_NAME}}",
|
|
5
|
+
srcs = glob([
|
|
6
|
+
"src/**/*.ts",
|
|
7
|
+
"src/**/*.tsx",
|
|
8
|
+
]),
|
|
9
|
+
res = glob([
|
|
10
|
+
"res/**/*.jpeg",
|
|
11
|
+
"res/**/*.jpg",
|
|
12
|
+
"res/**/*.png",
|
|
13
|
+
"res/**/*.svg",
|
|
14
|
+
"res/**/*.webp",
|
|
15
|
+
]),
|
|
16
|
+
visibility = ["//visibility:public"],
|
|
17
|
+
deps = [
|
|
18
|
+
"@valdi//src/valdi_modules/src/valdi/valdi_core",
|
|
19
|
+
"@valdi//src/valdi_modules/src/valdi/valdi_tsx",
|
|
20
|
+
],
|
|
21
|
+
)
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { StatefulComponent } from 'valdi_core/src/Component';
|
|
2
|
+
import { ImageView, Label, View } from 'valdi_tsx/src/NativeTemplateElements';
|
|
3
|
+
import { Style } from 'valdi_core/src/Style';
|
|
4
|
+
import { systemBoldFont, systemFont } from 'valdi_core/src/SystemFont';
|
|
5
|
+
import { AttributedText } from 'valdi_tsx/src/AttributedText';
|
|
6
|
+
import { AttributedTextBuilder } from 'valdi_core/src/utils/AttributedTextBuilder';
|
|
7
|
+
import { Device } from 'valdi_core/src/Device';
|
|
8
|
+
import { getDaemonClientManager } from 'valdi_core/src/debugging/DaemonClientManagerResolver';
|
|
9
|
+
import { IDaemonClientManagerListener } from 'valdi_core/src/debugging/DaemonClientManager';
|
|
10
|
+
import res from '../res';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @ViewModel
|
|
14
|
+
* @ExportModel
|
|
15
|
+
*/
|
|
16
|
+
export interface AppViewModel {}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @Context
|
|
20
|
+
* @ExportModel
|
|
21
|
+
*/
|
|
22
|
+
export interface AppComponentContext {}
|
|
23
|
+
|
|
24
|
+
interface State {
|
|
25
|
+
hotReloaderConnected: boolean;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @Component
|
|
30
|
+
* @ExportModel
|
|
31
|
+
*/
|
|
32
|
+
export class App extends StatefulComponent<AppViewModel, AppComponentContext> implements IDaemonClientManagerListener {
|
|
33
|
+
state: State = { hotReloaderConnected: false };
|
|
34
|
+
|
|
35
|
+
onCreate(): void {
|
|
36
|
+
console.log('On App create!');
|
|
37
|
+
getDaemonClientManager().addListener(this);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
onDestroy(): void {
|
|
41
|
+
console.log('On App destroy!');
|
|
42
|
+
getDaemonClientManager().removeListener(this);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
onAvailabilityChanged(available: boolean): void {
|
|
46
|
+
this.setState({ hotReloaderConnected: available });
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
onRender(): void {
|
|
50
|
+
console.log('On App render!');
|
|
51
|
+
<view style={styles.main}>
|
|
52
|
+
<image style={styles.logo} src={res.valdi} />
|
|
53
|
+
<layout padding={20}>
|
|
54
|
+
<label style={styles.title} value={`Welcome to Valdi!`} />
|
|
55
|
+
</layout>
|
|
56
|
+
<label style={styles.subtitle} value={this.renderLabel()} />
|
|
57
|
+
</view>;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
private renderLabel(): AttributedText {
|
|
61
|
+
const textBuilder = new AttributedTextBuilder();
|
|
62
|
+
|
|
63
|
+
textBuilder.appendText('This is currently running on ');
|
|
64
|
+
textBuilder.appendStyled({
|
|
65
|
+
content: this.getPlatformString(),
|
|
66
|
+
attributes: {
|
|
67
|
+
color: 'red',
|
|
68
|
+
font: systemBoldFont(20),
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
textBuilder.appendText('\nHot reloader ');
|
|
73
|
+
if (this.state.hotReloaderConnected) {
|
|
74
|
+
textBuilder.appendStyled({
|
|
75
|
+
content: 'connected',
|
|
76
|
+
attributes: {
|
|
77
|
+
color: 'green',
|
|
78
|
+
font: systemBoldFont(20),
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
} else {
|
|
82
|
+
textBuilder.appendStyled({
|
|
83
|
+
content: 'disconnected',
|
|
84
|
+
attributes: {
|
|
85
|
+
color: 'red',
|
|
86
|
+
font: systemBoldFont(20),
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return textBuilder.build();
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
private getPlatformString(): string {
|
|
95
|
+
if (Device.isDesktop()) {
|
|
96
|
+
return 'Desktop';
|
|
97
|
+
} else if (Device.isIOS()) {
|
|
98
|
+
return 'iOS';
|
|
99
|
+
} else if (Device.isAndroid()) {
|
|
100
|
+
return 'Android';
|
|
101
|
+
} else {
|
|
102
|
+
return 'Unknown';
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const styles = {
|
|
108
|
+
main: new Style<View>({
|
|
109
|
+
backgroundColor: 'white',
|
|
110
|
+
justifyContent: 'center',
|
|
111
|
+
}),
|
|
112
|
+
logo: new Style<ImageView>({
|
|
113
|
+
width: 80,
|
|
114
|
+
height: 80,
|
|
115
|
+
alignSelf: 'center',
|
|
116
|
+
borderRadius: 16,
|
|
117
|
+
boxShadow: '0 0 3 rgba(0, 0, 0, 0.15)',
|
|
118
|
+
}),
|
|
119
|
+
title: new Style<Label>({
|
|
120
|
+
color: 'black',
|
|
121
|
+
font: systemBoldFont(24),
|
|
122
|
+
accessibilityCategory: 'header',
|
|
123
|
+
alignSelf: 'center',
|
|
124
|
+
}),
|
|
125
|
+
|
|
126
|
+
subtitle: new Style<Label>({
|
|
127
|
+
alignSelf: 'center',
|
|
128
|
+
color: 'black',
|
|
129
|
+
font: systemFont(20),
|
|
130
|
+
numberOfLines: 0,
|
|
131
|
+
textAlign: 'center',
|
|
132
|
+
}),
|
|
133
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
}
|
|
24
|
+
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
load("@valdi//bzl/valdi:valdi_module.bzl", "valdi_module")
|
|
2
|
+
|
|
3
|
+
cc_library(
|
|
4
|
+
name = "{{MODULE_NAME}}_cpp",
|
|
5
|
+
srcs = glob(["cpp/**/*.cpp"]),
|
|
6
|
+
hdrs = glob(["cpp/**/*.hpp"]),
|
|
7
|
+
includes = [],
|
|
8
|
+
deps = ["@valdi//valdi_core"],
|
|
9
|
+
alwayslink = 1,
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
valdi_module(
|
|
13
|
+
name = "{{MODULE_NAME}}",
|
|
14
|
+
srcs = glob([
|
|
15
|
+
"src/**/*.ts",
|
|
16
|
+
"src/**/*.tsx",
|
|
17
|
+
]),
|
|
18
|
+
native_deps = [":{{MODULE_NAME}}_cpp"],
|
|
19
|
+
visibility = ["//visibility:public"],
|
|
20
|
+
deps = [],
|
|
21
|
+
)
|