@snap/valdi 1.0.6 → 1.0.8
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/README.md +22 -10
- package/bundled-skills/CONTRIBUTING_SKILLS.md +74 -0
- package/bundled-skills/registry.json +20 -0
- package/bundled-skills/skills/valdi-android/skill.md +89 -0
- package/bundled-skills/skills/valdi-async/skill.md +246 -0
- package/bundled-skills/skills/valdi-async/tests/BUILD.bazel +19 -0
- package/bundled-skills/skills/valdi-async/tests/README.md +25 -0
- package/bundled-skills/skills/valdi-async/tests/src/reference.tsx +210 -0
- package/bundled-skills/skills/valdi-async/tests/tsconfig.json +1 -0
- package/bundled-skills/skills/valdi-bazel/skill.md +122 -0
- package/bundled-skills/skills/valdi-compiler/skill.md +108 -0
- package/bundled-skills/skills/valdi-component-tests/skill.md +430 -0
- package/bundled-skills/skills/valdi-component-tests/tests/BUILD.bazel +24 -0
- package/bundled-skills/skills/valdi-component-tests/tests/README.md +35 -0
- package/bundled-skills/skills/valdi-component-tests/tests/src/ProfileCard.tsx +38 -0
- package/bundled-skills/skills/valdi-component-tests/tests/test/ProfileCardTest.spec.tsx +107 -0
- package/bundled-skills/skills/valdi-component-tests/tests/tsconfig.json +1 -0
- package/bundled-skills/skills/valdi-cpp-runtime/skill.md +103 -0
- package/bundled-skills/skills/valdi-custom-view/skill.md +62 -0
- package/bundled-skills/skills/valdi-ios/skill.md +93 -0
- package/bundled-skills/skills/valdi-migrate/skill.md +175 -0
- package/bundled-skills/skills/valdi-migrate/tests/BUILD.bazel +23 -0
- package/bundled-skills/skills/valdi-migrate/tests/README.md +70 -0
- package/bundled-skills/skills/valdi-migrate/tests/check_antipatterns.py +89 -0
- package/bundled-skills/skills/valdi-migrate/tests/compose_example.kt +94 -0
- package/bundled-skills/skills/valdi-migrate/tests/flutter_example.dart +129 -0
- package/bundled-skills/skills/valdi-migrate/tests/react_example.tsx +98 -0
- package/bundled-skills/skills/valdi-migrate/tests/src/expected_valdi.tsx +267 -0
- package/bundled-skills/skills/valdi-migrate/tests/tsconfig.json +3 -0
- package/{.metadata/.cursorrules.template → bundled-skills/skills/valdi-overview/skill.md} +23 -13
- package/bundled-skills/skills/valdi-perf/skill.md +197 -0
- package/bundled-skills/skills/valdi-perf/tests/BUILD.bazel +19 -0
- package/bundled-skills/skills/valdi-perf/tests/README.md +26 -0
- package/bundled-skills/skills/valdi-perf/tests/src/reference.tsx +202 -0
- package/bundled-skills/skills/valdi-perf/tests/tsconfig.json +1 -0
- package/bundled-skills/skills/valdi-polyglot-module/skill.md +85 -0
- package/bundled-skills/skills/valdi-setup/skill.md +129 -0
- package/bundled-skills/skills/valdi-testing/skill.md +65 -0
- package/bundled-skills/skills/valdi-tsx/skill.md +385 -0
- package/bundled-skills/skills/valdi-tsx/tests/BUILD.bazel +19 -0
- package/bundled-skills/skills/valdi-tsx/tests/README.md +29 -0
- package/bundled-skills/skills/valdi-tsx/tests/src/reference.tsx +173 -0
- package/bundled-skills/skills/valdi-tsx/tests/tsconfig.json +1 -0
- package/dist/commands/bootstrap.js +3 -9
- package/dist/commands/newModule.js +10 -14
- package/dist/commands/skills.js +16 -0
- package/dist/commands/skills_commands/create.js +125 -0
- package/dist/commands/skills_commands/install.js +96 -0
- package/dist/commands/skills_commands/list.js +83 -0
- package/dist/commands/skills_commands/remove.js +41 -0
- package/dist/commands/skills_commands/update.js +59 -0
- package/dist/core/constants.js +1 -1
- package/dist/index.js +5 -0
- package/dist/setup/versions.js +1 -1
- package/dist/utils/skillsAdapters.js +140 -0
- package/dist/utils/skillsRegistry.js +40 -0
- package/package.json +6 -1
- package/.bazelignore +0 -2
- package/.bootstrap/apps/cli_application/AGENTS.md.template +0 -291
- package/.bootstrap/apps/cli_application/BUILD.bazel.template +0 -7
- package/.bootstrap/apps/cli_application/modules/{{MODULE_NAME}}/BUILD.bazel.template +0 -11
- package/.bootstrap/apps/cli_application/modules/{{MODULE_NAME}}/src/index.ts +0 -1
- package/.bootstrap/apps/ui_application/.eslint.rc +0 -27
- package/.bootstrap/apps/ui_application/AGENTS.md.template +0 -278
- package/.bootstrap/apps/ui_application/BUILD.bazel.template +0 -19
- package/.bootstrap/apps/ui_application/modules/{{MODULE_NAME}}/BUILD.bazel.template +0 -21
- 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 +0 -133
- package/.bootstrap/apps/ui_application/package.json +0 -24
- package/.bootstrap/modules/cpp_bridge_module/BUILD.bazel.template +0 -21
- package/.bootstrap/modules/cpp_bridge_module/cpp/CalculatorModuleFactory.cpp.template +0 -28
- package/.bootstrap/modules/cpp_bridge_module/src/Calculator.d.ts +0 -4
- package/.bootstrap/modules/ios_android_bridge_module/BUILD.bazel.template +0 -39
- package/.bootstrap/modules/ios_android_bridge_module/android/CalculatorModuleFactory.kt.template +0 -18
- package/.bootstrap/modules/ios_android_bridge_module/ios/SCCCalculatorModuleFactory.m.template +0 -31
- package/.bootstrap/modules/ios_android_bridge_module/src/Calculator.d.ts +0 -4
- package/.bootstrap/modules/ios_android_view_module/BUILD.bazel.template +0 -41
- package/.bootstrap/modules/ios_android_view_module/android/CircleView.kt.template +0 -42
- package/.bootstrap/modules/ios_android_view_module/android/CircleViewAttributesBinder.kt.template +0 -60
- package/.bootstrap/modules/ios_android_view_module/ios/SCCCircleView.h +0 -6
- package/.bootstrap/modules/ios_android_view_module/ios/SCCCircleView.m +0 -82
- package/.bootstrap/modules/ios_android_view_module/src/Circle.tsx.template +0 -15
- package/.bootstrap/modules/ui_component/BUILD.bazel.template +0 -34
- package/.bootstrap/modules/ui_component/src/NewModuleComponent.tsx +0 -45
- package/.config/copyconfig.json +0 -10
- package/.editorconfig +0 -21
- package/.eslintignore +0 -1
- package/.eslintrc.js +0 -72
- package/.github/README.md +0 -164
- package/.metadata/.bazelrc.template +0 -91
- package/.metadata/.bazelversion.template +0 -1
- package/.metadata/.editorconfig.template +0 -37
- package/.metadata/.eslintrc.js.template +0 -27
- package/.metadata/.gitignore.template +0 -4
- package/.metadata/.prettierrc.json.template +0 -7
- package/.metadata/.watchmanconfig.template +0 -8
- package/.metadata/README.md.template +0 -31
- package/.metadata/WORKSPACE.template +0 -57
- package/.metadata/config.yaml.template +0 -1
- package/.metadata/package.json.template +0 -23
- package/.prettierignore +0 -2
- package/.prettierrc.json +0 -7
- package/LINUX_COMPATIBILITY.md +0 -248
- package/prettier.config.js +0 -4
- package/scripts/sync-agents-md.sh +0 -44
- package/scripts/update-agents-templates.ts +0 -170
- package/spec/support/jasmine.json +0 -6
- package/src/commands/bootstrap.ts +0 -409
- package/src/commands/build.ts +0 -89
- package/src/commands/devSetup.ts +0 -17
- package/src/commands/doctor.ts +0 -1832
- package/src/commands/export.ts +0 -131
- package/src/commands/hotreload.ts +0 -108
- package/src/commands/install.ts +0 -93
- package/src/commands/lint.ts +0 -15
- package/src/commands/lint_commands/lintCheck.ts +0 -53
- package/src/commands/lint_commands/lintFormat.ts +0 -49
- package/src/commands/log.ts +0 -108
- package/src/commands/newModule.ts +0 -286
- package/src/commands/package.ts +0 -102
- package/src/commands/projectsync.ts +0 -488
- package/src/commands/test.ts +0 -68
- package/src/core/constants.ts +0 -97
- package/src/core/errors.ts +0 -10
- package/src/index.ts +0 -22
- package/src/setup/DevSetupHelper.ts +0 -290
- package/src/setup/linuxSetup.ts +0 -261
- package/src/setup/macOSSetup.ts +0 -156
- package/src/setup/setupEntryPoint.ts +0 -64
- package/src/setup/versions.ts +0 -8
- package/src/utils/ArgumentsResolver.ts +0 -23
- package/src/utils/BazelClient.ts +0 -285
- package/src/utils/Digraph.ts +0 -81
- package/src/utils/LoadingIndicator.ts +0 -43
- package/src/utils/applicationUtils.ts +0 -276
- package/src/utils/buildInfo.ts +0 -99
- package/src/utils/byString.ts +0 -3
- package/src/utils/cliUtils.ts +0 -112
- package/src/utils/copyBootstrapFiles.ts +0 -30
- package/src/utils/deviceUtils.ts +0 -76
- package/src/utils/errorUtils.ts +0 -63
- package/src/utils/fileUtils.ts +0 -257
- package/src/utils/githubUtils.ts +0 -102
- package/src/utils/jsonUtils.ts +0 -30
- package/src/utils/lintUtils.ts +0 -190
- package/src/utils/linuxDistro.spec.ts +0 -219
- package/src/utils/linuxDistro.ts +0 -326
- package/src/utils/logUtils.ts +0 -9
- package/src/utils/pathUtils.ts +0 -12
- package/src/utils/stringUtils.spec.ts +0 -95
- package/src/utils/stringUtils.ts +0 -103
- package/src/utils/tempDir.ts +0 -24
- package/src/utils/zipUtils.ts +0 -14
- package/test/ValdiSmokeTest.ts +0 -279
- package/test/helpers/AsyncHelpers.ts +0 -113
- package/test/helpers/CommandHelpers.ts +0 -37
- package/test/helpers/ProjectHelpers.ts +0 -153
- package/test/helpers/StreamHelpers.ts +0 -37
- package/test/helpers/TypeScriptClient.ts +0 -217
- package/tsconfig.dist.json +0 -8
- package/tsconfig.json +0 -42
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ALL_ADAPTERS = void 0;
|
|
4
|
+
exports.detectAdapters = detectAdapters;
|
|
5
|
+
exports.getAdapterByName = getAdapterByName;
|
|
6
|
+
const tslib_1 = require("tslib");
|
|
7
|
+
const fs = tslib_1.__importStar(require("fs"));
|
|
8
|
+
const path = tslib_1.__importStar(require("path"));
|
|
9
|
+
const os = tslib_1.__importStar(require("os"));
|
|
10
|
+
const ClaudeCodeAdapter = {
|
|
11
|
+
name: 'claude',
|
|
12
|
+
detect() {
|
|
13
|
+
const claudeDir = path.join(os.homedir(), '.claude');
|
|
14
|
+
return fs.existsSync(claudeDir);
|
|
15
|
+
},
|
|
16
|
+
install(skillName, content, meta) {
|
|
17
|
+
const skillDir = path.join(os.homedir(), '.claude', 'plugins', 'valdi', 'skills', skillName);
|
|
18
|
+
fs.mkdirSync(skillDir, { recursive: true });
|
|
19
|
+
const frontmatter = `---\nname: ${meta.name}\ndescription: ${meta.description}\n---\n\n`;
|
|
20
|
+
fs.writeFileSync(path.join(skillDir, 'SKILL.md'), frontmatter + content, 'utf8');
|
|
21
|
+
},
|
|
22
|
+
remove(skillName) {
|
|
23
|
+
const skillDir = path.join(os.homedir(), '.claude', 'plugins', 'valdi', 'skills', skillName);
|
|
24
|
+
if (fs.existsSync(skillDir)) {
|
|
25
|
+
fs.rmSync(skillDir, { recursive: true, force: true });
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
listInstalled() {
|
|
29
|
+
const skillsDir = path.join(os.homedir(), '.claude', 'plugins', 'valdi', 'skills');
|
|
30
|
+
if (!fs.existsSync(skillsDir))
|
|
31
|
+
return [];
|
|
32
|
+
return fs
|
|
33
|
+
.readdirSync(skillsDir)
|
|
34
|
+
.filter((entry) => fs.statSync(path.join(skillsDir, entry)).isDirectory());
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
const CursorAdapter = {
|
|
38
|
+
name: 'cursor',
|
|
39
|
+
detect() {
|
|
40
|
+
const cursorDir = path.join(os.homedir(), '.cursor');
|
|
41
|
+
return fs.existsSync(cursorDir);
|
|
42
|
+
},
|
|
43
|
+
install(skillName, content, meta) {
|
|
44
|
+
const rulesDir = path.join(os.homedir(), '.cursor', 'rules');
|
|
45
|
+
fs.mkdirSync(rulesDir, { recursive: true });
|
|
46
|
+
const frontmatter = `---\ndescription: ${meta.description}\nalwaysApply: false\n---\n\n`;
|
|
47
|
+
fs.writeFileSync(path.join(rulesDir, `valdi-${skillName}.mdc`), frontmatter + content, 'utf8');
|
|
48
|
+
},
|
|
49
|
+
remove(skillName) {
|
|
50
|
+
const filePath = path.join(os.homedir(), '.cursor', 'rules', `valdi-${skillName}.mdc`);
|
|
51
|
+
if (fs.existsSync(filePath)) {
|
|
52
|
+
fs.unlinkSync(filePath);
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
listInstalled() {
|
|
56
|
+
const rulesDir = path.join(os.homedir(), '.cursor', 'rules');
|
|
57
|
+
if (!fs.existsSync(rulesDir))
|
|
58
|
+
return [];
|
|
59
|
+
return fs
|
|
60
|
+
.readdirSync(rulesDir)
|
|
61
|
+
.filter((f) => f.startsWith('valdi-') && f.endsWith('.mdc'))
|
|
62
|
+
.map((f) => f.replace(/^valdi-/u, '').replace(/\.mdc$/u, ''));
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
const CopilotAdapter = {
|
|
66
|
+
name: 'copilot',
|
|
67
|
+
detect() {
|
|
68
|
+
const githubDir = path.join(process.cwd(), '.github');
|
|
69
|
+
return fs.existsSync(githubDir);
|
|
70
|
+
},
|
|
71
|
+
install(skillName, content, _meta) {
|
|
72
|
+
const githubDir = path.join(process.cwd(), '.github');
|
|
73
|
+
fs.mkdirSync(githubDir, { recursive: true });
|
|
74
|
+
const instructionsFile = path.join(githubDir, 'copilot-instructions.md');
|
|
75
|
+
const section = `\n\n## ${skillName}\n\n${content}`;
|
|
76
|
+
if (fs.existsSync(instructionsFile)) {
|
|
77
|
+
fs.appendFileSync(instructionsFile, section, 'utf8');
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
fs.writeFileSync(instructionsFile, `# Copilot Instructions${section}`, 'utf8');
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
remove(skillName) {
|
|
84
|
+
const instructionsFile = path.join(process.cwd(), '.github', 'copilot-instructions.md');
|
|
85
|
+
if (!fs.existsSync(instructionsFile))
|
|
86
|
+
return;
|
|
87
|
+
const contents = fs.readFileSync(instructionsFile, 'utf8');
|
|
88
|
+
const sectionRegex = new RegExp(`\\n\\n## ${skillName}\\n[\\s\\S]*?(?=\\n\\n## |$)`, 'u');
|
|
89
|
+
const updated = contents.replace(sectionRegex, '');
|
|
90
|
+
fs.writeFileSync(instructionsFile, updated, 'utf8');
|
|
91
|
+
},
|
|
92
|
+
listInstalled() {
|
|
93
|
+
const instructionsFile = path.join(process.cwd(), '.github', 'copilot-instructions.md');
|
|
94
|
+
if (!fs.existsSync(instructionsFile))
|
|
95
|
+
return [];
|
|
96
|
+
const contents = fs.readFileSync(instructionsFile, 'utf8');
|
|
97
|
+
const matches = contents.match(/^## (valdi-\S+)/gmu);
|
|
98
|
+
if (!matches)
|
|
99
|
+
return [];
|
|
100
|
+
return matches.map((m) => m.replace(/^## /u, ''));
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
const GenericAdapter = {
|
|
104
|
+
name: 'generic',
|
|
105
|
+
detect() {
|
|
106
|
+
return true;
|
|
107
|
+
},
|
|
108
|
+
install(skillName, content, _meta) {
|
|
109
|
+
const skillsDir = path.join(os.homedir(), '.valdi', 'skills');
|
|
110
|
+
fs.mkdirSync(skillsDir, { recursive: true });
|
|
111
|
+
fs.writeFileSync(path.join(skillsDir, `${skillName}.md`), content, 'utf8');
|
|
112
|
+
},
|
|
113
|
+
remove(skillName) {
|
|
114
|
+
const filePath = path.join(os.homedir(), '.valdi', 'skills', `${skillName}.md`);
|
|
115
|
+
if (fs.existsSync(filePath)) {
|
|
116
|
+
fs.unlinkSync(filePath);
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
listInstalled() {
|
|
120
|
+
const skillsDir = path.join(os.homedir(), '.valdi', 'skills');
|
|
121
|
+
if (!fs.existsSync(skillsDir))
|
|
122
|
+
return [];
|
|
123
|
+
return fs
|
|
124
|
+
.readdirSync(skillsDir)
|
|
125
|
+
.filter((f) => f.endsWith('.md'))
|
|
126
|
+
.map((f) => f.replace(/\.md$/u, ''));
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
exports.ALL_ADAPTERS = [
|
|
130
|
+
ClaudeCodeAdapter,
|
|
131
|
+
CursorAdapter,
|
|
132
|
+
CopilotAdapter,
|
|
133
|
+
GenericAdapter,
|
|
134
|
+
];
|
|
135
|
+
function detectAdapters() {
|
|
136
|
+
return exports.ALL_ADAPTERS.filter((a) => a.detect());
|
|
137
|
+
}
|
|
138
|
+
function getAdapterByName(name) {
|
|
139
|
+
return exports.ALL_ADAPTERS.find((a) => a.name === name);
|
|
140
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.loadLocalRegistry = loadLocalRegistry;
|
|
4
|
+
exports.fetchRegistry = fetchRegistry;
|
|
5
|
+
exports.fetchSkillContent = fetchSkillContent;
|
|
6
|
+
const tslib_1 = require("tslib");
|
|
7
|
+
const path = tslib_1.__importStar(require("path"));
|
|
8
|
+
const fs = tslib_1.__importStar(require("fs"));
|
|
9
|
+
function findBundledSkillsDir() {
|
|
10
|
+
const candidate = path.resolve(__dirname, '..', '..', 'bundled-skills');
|
|
11
|
+
return fs.existsSync(path.join(candidate, 'registry.json')) ? candidate : null;
|
|
12
|
+
}
|
|
13
|
+
function loadLocalRegistry() {
|
|
14
|
+
const bundledDir = findBundledSkillsDir();
|
|
15
|
+
if (bundledDir == null)
|
|
16
|
+
return null;
|
|
17
|
+
try {
|
|
18
|
+
return JSON.parse(fs.readFileSync(path.join(bundledDir, 'registry.json'), 'utf8'));
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
async function fetchRegistry() {
|
|
25
|
+
const local = loadLocalRegistry();
|
|
26
|
+
if (local != null) {
|
|
27
|
+
return local;
|
|
28
|
+
}
|
|
29
|
+
throw new Error('No bundled skills found. Re-install @snap/valdi to get the latest bundle.');
|
|
30
|
+
}
|
|
31
|
+
async function fetchSkillContent(skillPath) {
|
|
32
|
+
const bundledDir = findBundledSkillsDir();
|
|
33
|
+
if (bundledDir != null) {
|
|
34
|
+
const candidate = path.join(bundledDir, skillPath);
|
|
35
|
+
if (fs.existsSync(candidate)) {
|
|
36
|
+
return fs.readFileSync(candidate, 'utf8');
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
throw new Error(`Skill content not found for "${skillPath}". Re-install @snap/valdi to get the latest bundle.`);
|
|
40
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@snap/valdi",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
4
4
|
"description": "Valdi CLI tools for developers",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -12,8 +12,13 @@
|
|
|
12
12
|
"bin": {
|
|
13
13
|
"valdi": "dist/index.js"
|
|
14
14
|
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"bundled-skills"
|
|
18
|
+
],
|
|
15
19
|
"scripts": {
|
|
16
20
|
"prepare": "npm run build",
|
|
21
|
+
"prebuild": "node scripts/bundle-skills.js",
|
|
17
22
|
"build": "npm exec --package=typescript@5.9.2 tsc -- --project ./tsconfig.dist.json",
|
|
18
23
|
"test": "ts-node node_modules/jasmine/bin/jasmine",
|
|
19
24
|
"watch": "tsc --watch",
|
package/.bazelignore
DELETED
|
@@ -1,291 +0,0 @@
|
|
|
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
|
-
|
|
10
|
-
## 🚨 CRITICAL: Valdi is NOT React!
|
|
11
|
-
|
|
12
|
-
**AI assistants often suggest React patterns that DON'T EXIST in Valdi.** This is because TSX/JSX syntax looks like React, but Valdi compiles to native code.
|
|
13
|
-
|
|
14
|
-
### ❌ FORBIDDEN Patterns (Don't exist in Valdi)
|
|
15
|
-
|
|
16
|
-
```typescript
|
|
17
|
-
// ❌ WRONG - React hooks don't exist
|
|
18
|
-
const [count, setCount] = useState(0);
|
|
19
|
-
useEffect(() => { ... }, []);
|
|
20
|
-
|
|
21
|
-
// ❌ WRONG - Functional components don't exist
|
|
22
|
-
const MyComponent = () => <view />;
|
|
23
|
-
|
|
24
|
-
// ❌ WRONG - Common AI mistakes
|
|
25
|
-
this.markNeedsRender(); // Doesn't exist!
|
|
26
|
-
this.props.title; // Should be: this.viewModel.title
|
|
27
|
-
onMount() { } // Should be: onCreate()
|
|
28
|
-
onUpdate() { } // Should be: onViewModelUpdate()
|
|
29
|
-
onUnmount() { } // Should be: onDestroy()
|
|
30
|
-
this.context.get(Service); // Wrong pattern, use withProviders()
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
### ✅ CORRECT Valdi Patterns
|
|
34
|
-
|
|
35
|
-
```typescript
|
|
36
|
-
// ✅ Stateful component with state
|
|
37
|
-
import { StatefulComponent } from 'valdi_core/src/Component';
|
|
38
|
-
|
|
39
|
-
class MyComponent extends StatefulComponent<ViewModel, State> {
|
|
40
|
-
state = { count: 0 };
|
|
41
|
-
|
|
42
|
-
// Lifecycle methods
|
|
43
|
-
onCreate() { } // Component created
|
|
44
|
-
onViewModelUpdate(prev: ViewModel) { } // Props changed
|
|
45
|
-
onDestroy() { } // Before removal
|
|
46
|
-
|
|
47
|
-
// State updates
|
|
48
|
-
handleClick() {
|
|
49
|
-
this.setState({ count: this.state.count + 1 }); // Auto re-renders
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// Render (returns void, JSX is statement)
|
|
53
|
-
onRender() {
|
|
54
|
-
<button
|
|
55
|
-
title={`Count: ${this.state.count}`}
|
|
56
|
-
onPress={this.handleClick}
|
|
57
|
-
/>;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// ✅ Stateless component (props only)
|
|
62
|
-
import { Component } from 'valdi_core/src/Component';
|
|
63
|
-
|
|
64
|
-
class SimpleComponent extends Component<ViewModel> {
|
|
65
|
-
onRender() {
|
|
66
|
-
<label value={this.viewModel.title} />; // viewModel, not props!
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
### Key Differences from React
|
|
72
|
-
|
|
73
|
-
| Concept | React | Valdi |
|
|
74
|
-
|---------|-------|-------|
|
|
75
|
-
| **Components** | Functions or classes | Classes only (Component or StatefulComponent) |
|
|
76
|
-
| **State** | `useState` hook | `state = { }` + `setState()` |
|
|
77
|
-
| **Props** | `this.props` | `this.viewModel` |
|
|
78
|
-
| **Lifecycle** | `useEffect` | `onCreate`, `onViewModelUpdate`, `onDestroy` |
|
|
79
|
-
| **Re-render** | `setCount(...)` | `this.setState(...)` |
|
|
80
|
-
| **Return** | `return <view />` | `<view />;` (statement, returns void) |
|
|
81
|
-
|
|
82
|
-
For complete framework documentation, see: https://github.com/Snapchat/Valdi
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
## Project Structure
|
|
86
|
-
|
|
87
|
-
- **`modules/`** - Your application modules
|
|
88
|
-
- Each module contains TypeScript source files
|
|
89
|
-
- `BUILD.bazel` files define how modules are built
|
|
90
|
-
- `src/` contains your application logic code
|
|
91
|
-
- **`WORKSPACE`** - Bazel workspace configuration
|
|
92
|
-
- **`config.yaml`** - Valdi project configuration
|
|
93
|
-
- **`.bazelrc`** - Bazel build settings
|
|
94
|
-
|
|
95
|
-
## Key Technologies
|
|
96
|
-
|
|
97
|
-
- **Valdi** - Framework that compiles TypeScript to native code
|
|
98
|
-
- **TypeScript** - Primary development language
|
|
99
|
-
- **Bazel** - Build system (note: `bzl` is an alias for `bazel`)
|
|
100
|
-
|
|
101
|
-
## Development Workflow
|
|
102
|
-
|
|
103
|
-
### Initial Setup
|
|
104
|
-
|
|
105
|
-
```bash
|
|
106
|
-
# Install Valdi CLI (if not already installed)
|
|
107
|
-
cd path/to/valdi/npm_modules/cli
|
|
108
|
-
npm run cli:install
|
|
109
|
-
|
|
110
|
-
# Setup development environment
|
|
111
|
-
valdi dev_setup
|
|
112
|
-
|
|
113
|
-
# Sync project (run after changing dependencies or config)
|
|
114
|
-
valdi projectsync
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
### Building and Running
|
|
118
|
-
|
|
119
|
-
```bash
|
|
120
|
-
# Build the CLI application
|
|
121
|
-
bazel build //modules/{{MODULE_NAME}}:{{MODULE_NAME}}
|
|
122
|
-
|
|
123
|
-
# Run the application
|
|
124
|
-
bazel run //modules/{{MODULE_NAME}}:{{MODULE_NAME}}
|
|
125
|
-
|
|
126
|
-
# Build and run with arguments
|
|
127
|
-
bazel run //modules/{{MODULE_NAME}}:{{MODULE_NAME}} -- --your-args-here
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
### Common Commands
|
|
131
|
-
|
|
132
|
-
```bash
|
|
133
|
-
# Sync project configuration
|
|
134
|
-
valdi projectsync
|
|
135
|
-
|
|
136
|
-
# Build specific targets
|
|
137
|
-
bazel build //modules/{{MODULE_NAME}}:{{MODULE_NAME}}
|
|
138
|
-
|
|
139
|
-
# Run tests
|
|
140
|
-
bazel test //modules/{{MODULE_NAME}}:tests
|
|
141
|
-
|
|
142
|
-
# Clean build cache
|
|
143
|
-
bazel clean
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
## TypeScript Development
|
|
147
|
-
|
|
148
|
-
### Entry Point
|
|
149
|
-
|
|
150
|
-
Your CLI application typically has an entry point file (e.g., `index.ts`):
|
|
151
|
-
|
|
152
|
-
```typescript
|
|
153
|
-
// Example CLI application entry point
|
|
154
|
-
function main(args: string[]) {
|
|
155
|
-
console.log('Hello from Valdi CLI!');
|
|
156
|
-
console.log('Arguments:', args);
|
|
157
|
-
|
|
158
|
-
// Your application logic here
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
// Entry point
|
|
162
|
-
main(process.argv.slice(2));
|
|
163
|
-
```
|
|
164
|
-
|
|
165
|
-
### Using Standard Library Modules
|
|
166
|
-
|
|
167
|
-
```typescript
|
|
168
|
-
// HTTP requests
|
|
169
|
-
import { HTTPClient } from 'valdi_http/src/HTTPClient';
|
|
170
|
-
|
|
171
|
-
// Utilities
|
|
172
|
-
import { Base64 } from 'coreutils/src/Base64';
|
|
173
|
-
import { UUID } from 'coreutils/src/uuidUtils';
|
|
174
|
-
|
|
175
|
-
// File system operations
|
|
176
|
-
import { FileSystem } from 'file_system/src/FileSystem';
|
|
177
|
-
|
|
178
|
-
// Persistence
|
|
179
|
-
import { PersistentStorage } from 'persistence/src/PersistentStorage';
|
|
180
|
-
```
|
|
181
|
-
|
|
182
|
-
## Available Standard Library Modules
|
|
183
|
-
|
|
184
|
-
- `valdi_core` - Core runtime APIs
|
|
185
|
-
- `valdi_http` - Promise-based HTTP client for network requests
|
|
186
|
-
- `valdi_rxjs` - RxJS integration for reactive programming
|
|
187
|
-
- `persistence` - Key-value storage with encryption and TTL support
|
|
188
|
-
- `file_system` - Low-level file I/O operations
|
|
189
|
-
- `foundation`, `coreutils` - Common utilities (arrays, Base64, LRU cache, UUID, etc.)
|
|
190
|
-
- `worker` - Worker service support for background execution
|
|
191
|
-
|
|
192
|
-
## Debugging
|
|
193
|
-
|
|
194
|
-
- **VSCode Integration** - Set breakpoints and debug TypeScript code
|
|
195
|
-
- **Console logging** - Use `console.log()`, `console.error()`, etc.
|
|
196
|
-
- **Command line arguments** - Pass arguments after `--` in bazel run
|
|
197
|
-
|
|
198
|
-
## Common Patterns
|
|
199
|
-
|
|
200
|
-
### Command Line Arguments
|
|
201
|
-
|
|
202
|
-
```typescript
|
|
203
|
-
interface CliArgs {
|
|
204
|
-
input?: string;
|
|
205
|
-
output?: string;
|
|
206
|
-
verbose?: boolean;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
function parseArgs(args: string[]): CliArgs {
|
|
210
|
-
const parsed: CliArgs = {};
|
|
211
|
-
|
|
212
|
-
for (let i = 0; i < args.length; i++) {
|
|
213
|
-
if (args[i] === '--input' && i + 1 < args.length) {
|
|
214
|
-
parsed.input = args[i + 1];
|
|
215
|
-
i++;
|
|
216
|
-
} else if (args[i] === '--output' && i + 1 < args.length) {
|
|
217
|
-
parsed.output = args[i + 1];
|
|
218
|
-
i++;
|
|
219
|
-
} else if (args[i] === '--verbose') {
|
|
220
|
-
parsed.verbose = true;
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
return parsed;
|
|
225
|
-
}
|
|
226
|
-
```
|
|
227
|
-
|
|
228
|
-
### Async Operations
|
|
229
|
-
|
|
230
|
-
```typescript
|
|
231
|
-
async function fetchData(url: string): Promise<void> {
|
|
232
|
-
try {
|
|
233
|
-
const client = new HTTPClient();
|
|
234
|
-
const response = await client.get(url);
|
|
235
|
-
console.log('Response:', response);
|
|
236
|
-
} catch (error) {
|
|
237
|
-
console.error('Error fetching data:', error);
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
```
|
|
241
|
-
|
|
242
|
-
### File Operations
|
|
243
|
-
|
|
244
|
-
```typescript
|
|
245
|
-
import { FileSystem } from 'file_system/src/FileSystem';
|
|
246
|
-
|
|
247
|
-
function readConfigFile(path: string): string {
|
|
248
|
-
try {
|
|
249
|
-
const fs = FileSystem.getInstance();
|
|
250
|
-
return fs.readFileSync(path, 'utf8');
|
|
251
|
-
} catch (error) {
|
|
252
|
-
console.error('Error reading file:', error);
|
|
253
|
-
return '';
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
```
|
|
257
|
-
|
|
258
|
-
## Common Pitfalls
|
|
259
|
-
|
|
260
|
-
1. **Always run `valdi projectsync`** after changing dependencies or config files
|
|
261
|
-
2. **Use async/await** for asynchronous operations
|
|
262
|
-
3. **Error handling** - Always handle errors gracefully in CLI applications
|
|
263
|
-
4. **Build cache** - If builds seem stuck, try `bazel clean`
|
|
264
|
-
5. **Arguments** - Remember to use `--` before passing arguments to your CLI app
|
|
265
|
-
|
|
266
|
-
## Important Files
|
|
267
|
-
|
|
268
|
-
- **`config.yaml`** - Project configuration (dependencies, settings)
|
|
269
|
-
- **`WORKSPACE`** - Bazel workspace and external dependencies
|
|
270
|
-
- **`BUILD.bazel`** - Build rules for each module
|
|
271
|
-
- **`.bazelrc`** - Bazel build flags and configuration
|
|
272
|
-
|
|
273
|
-
## Getting Help
|
|
274
|
-
|
|
275
|
-
- **Documentation** - Valdi docs in the framework repository at `/docs/`
|
|
276
|
-
- **Discord** - Join the [Valdi Discord community](https://discord.gg/uJyNEeYX2U)
|
|
277
|
-
- **Examples** - Check `/apps/` directory in Valdi repository for examples
|
|
278
|
-
- **CLI Documentation** - See `/docs/docs/workflow-cli-application.md`
|
|
279
|
-
|
|
280
|
-
## Key Points for AI Assistants
|
|
281
|
-
|
|
282
|
-
1. **This is a CLI application** - No UI components, terminal-based
|
|
283
|
-
2. **TypeScript compiles to native** - Performant native executable
|
|
284
|
-
3. **Use Bazel commands** - Primary tool for building and running CLI apps
|
|
285
|
-
4. **Standard library available** - Access to HTTP, file system, persistence, etc.
|
|
286
|
-
5. **Cross-platform** - Can build for Linux, macOS, and potentially other platforms
|
|
287
|
-
|
|
288
|
-
---
|
|
289
|
-
|
|
290
|
-
*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*
|
|
291
|
-
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
console.log('Hello world!');
|
|
@@ -1,27 +0,0 @@
|
|
|
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
|
-
};
|