@snap/valdi 1.0.11 → 1.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/.metadata/.bazelrc.template +7 -6
  2. package/.metadata/MODULE.bazel.template +154 -0
  3. package/bundled-skills/registry.json +13 -2
  4. package/bundled-skills/skills/valdi-animations/skill.md +197 -0
  5. package/bundled-skills/skills/valdi-async/tests/src/reference.tsx +1 -1
  6. package/bundled-skills/skills/valdi-compiler/skill.md +4 -4
  7. package/bundled-skills/skills/valdi-component-dedup/skill.md +263 -0
  8. package/bundled-skills/skills/valdi-component-tests/tests/test/ProfileCardTest.spec.tsx +1 -1
  9. package/bundled-skills/skills/valdi-custom-view/skill.md +43 -1
  10. package/bundled-skills/skills/valdi-error-handling/skill.md +238 -0
  11. package/bundled-skills/skills/valdi-gestures/skill.md +198 -0
  12. package/bundled-skills/skills/valdi-inspect/skill.md +19 -1
  13. package/bundled-skills/skills/valdi-localization/skill.md +142 -0
  14. package/bundled-skills/skills/valdi-mock-breakdown/skill.md +327 -0
  15. package/bundled-skills/skills/valdi-mock-iterate/skill.md +216 -0
  16. package/bundled-skills/skills/valdi-mock-to-module/scripts/diff.py +392 -0
  17. package/bundled-skills/skills/valdi-mock-to-module/scripts/extract_colors.py +277 -0
  18. package/bundled-skills/skills/valdi-mock-to-module/scripts/find_icon.py +303 -0
  19. package/bundled-skills/skills/valdi-mock-to-module/scripts/snapshot-and-diff.sh +53 -0
  20. package/bundled-skills/skills/valdi-mock-to-module/scripts/test_diff.py +207 -0
  21. package/bundled-skills/skills/valdi-mock-to-module/scripts/test_extract_colors.py +167 -0
  22. package/bundled-skills/skills/valdi-mock-to-module/scripts/test_find_icon.py +188 -0
  23. package/bundled-skills/skills/valdi-mock-to-module/scripts/watch-and-diff.sh +181 -0
  24. package/bundled-skills/skills/valdi-mock-to-module/skill.md +451 -0
  25. package/bundled-skills/skills/valdi-navigation/skill.md +187 -0
  26. package/bundled-skills/skills/valdi-overview/skill.md +7 -4
  27. package/bundled-skills/skills/valdi-perf/skill.md +223 -0
  28. package/bundled-skills/skills/valdi-polyglot-module/skill.md +80 -0
  29. package/bundled-skills/skills/valdi-preview/skill.md +303 -0
  30. package/bundled-skills/skills/valdi-setup/skill.md +55 -5
  31. package/bundled-skills/skills/valdi-testing/skill.md +23 -7
  32. package/bundled-skills/skills/valdi-tsx/skill.md +69 -5
  33. package/bundled-skills/skills/valdi-tsx/tests/src/reference.tsx +29 -5
  34. package/dist/commands/agentCheck.js +184 -0
  35. package/dist/commands/analyze.js +16 -0
  36. package/dist/commands/analyze_commands/duplicates.js +134 -0
  37. package/dist/commands/bootstrap.js +57 -73
  38. package/dist/commands/build.js +6 -0
  39. package/dist/commands/doctor.js +42 -266
  40. package/dist/commands/hotreload.js +15 -0
  41. package/dist/commands/inspect_commands/snapshot.js +71 -6
  42. package/dist/commands/inspect_commands/snapshot.spec.js +105 -0
  43. package/dist/commands/install.js +6 -0
  44. package/dist/commands/preview.js +81 -0
  45. package/dist/commands/projectsync.js +9 -7
  46. package/dist/commands/skills_commands/install.js +6 -1
  47. package/dist/commands/skills_commands/update.js +2 -1
  48. package/dist/core/analyze/clusterer.js +150 -0
  49. package/dist/core/analyze/fingerprint.js +2 -0
  50. package/dist/core/analyze/knownPatterns.js +76 -0
  51. package/dist/core/analyze/parser.js +177 -0
  52. package/dist/core/analyze/reporter.js +83 -0
  53. package/dist/core/analyze/scanner.js +172 -0
  54. package/dist/core/analyze/similarity.js +56 -0
  55. package/dist/core/constants.js +6 -3
  56. package/dist/core/packageFiles.spec.js +1 -1
  57. package/dist/preview/previewGenerator.js +240 -0
  58. package/dist/preview/previewGenerator.spec.js +203 -0
  59. package/dist/preview/viewModelParser.js +86 -0
  60. package/dist/preview/viewModelParser.spec.js +171 -0
  61. package/dist/setup/DevSetupHelper.js +0 -54
  62. package/dist/setup/linuxSetup.js +0 -16
  63. package/dist/setup/macOSSetup.js +1 -5
  64. package/dist/utils/BazelClient.js +15 -0
  65. package/dist/utils/applicationUtils.js +15 -0
  66. package/dist/utils/daemonClient.js +3 -1
  67. package/dist/utils/linuxDistro.js +0 -21
  68. package/dist/utils/linuxDistro.spec.js +0 -48
  69. package/dist/utils/skillsAdapters.js +126 -19
  70. package/dist/utils/skillsAdapters.spec.js +141 -0
  71. package/dist/utils/skillsRegistry.js +8 -0
  72. package/package.json +16 -8
  73. package/.metadata/WORKSPACE.template +0 -57
  74. package/dist/setup/versions.js +0 -8
@@ -0,0 +1,184 @@
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 LoadingIndicator_1 = require("../utils/LoadingIndicator");
7
+ const errorUtils_1 = require("../utils/errorUtils");
8
+ const logUtils_1 = require("../utils/logUtils");
9
+ async function runStep(name, fn, json) {
10
+ const start = Date.now();
11
+ if (!json) {
12
+ console.log((0, logUtils_1.wrapInColor)(`▸ ${name}...`, constants_1.ANSI_COLORS.YELLOW_COLOR));
13
+ }
14
+ try {
15
+ await fn();
16
+ const durationMs = Date.now() - start;
17
+ if (!json) {
18
+ console.log((0, logUtils_1.wrapInColor)(` ✓ ${name} (${durationMs}ms)`, constants_1.ANSI_COLORS.GREEN_COLOR));
19
+ }
20
+ return { name, status: 'pass', durationMs };
21
+ }
22
+ catch (error) {
23
+ const durationMs = Date.now() - start;
24
+ const message = error instanceof Error ? error.message : String(error);
25
+ if (!json) {
26
+ console.log((0, logUtils_1.wrapInColor)(` ✗ ${name}: ${message}`, constants_1.ANSI_COLORS.RED_COLOR));
27
+ }
28
+ return { name, status: 'fail', durationMs, message };
29
+ }
30
+ }
31
+ async function getModuleTargets(client, module) {
32
+ const allTargets = await client.queryTargetsByKindWithFilter('valdi_module', [module], 'pipe');
33
+ const androidDebug = allTargets.filter((t) => t.includes('android.debug'));
34
+ return androidDebug.length > 0 ? androidDebug : allTargets;
35
+ }
36
+ async function getTestTargets(client, module) {
37
+ return await client.queryTargetsByKindWithFilter('test', [module], 'pipe');
38
+ }
39
+ async function valdiAgentCheck(argv) {
40
+ const json = argv.getArgument('json') ?? false;
41
+ const quick = argv.getArgument('quick') ?? false;
42
+ const bazelClient = new BazelClient_1.BazelClient();
43
+ const moduleName = argv.getArgument('module');
44
+ const targetName = argv.getArgument('target');
45
+ if (!moduleName && !targetName) {
46
+ throw new Error('Either --module or --target is required');
47
+ }
48
+ const results = [];
49
+ const totalStart = Date.now();
50
+ if (!json) {
51
+ const mode = quick ? 'Quick' : 'Full';
52
+ console.log((0, logUtils_1.wrapInColor)(`\n═══ Valdi Agent Check (${mode}) ═══\n`, constants_1.ANSI_COLORS.GREEN_COLOR));
53
+ }
54
+ let buildTargets = [];
55
+ let testTargets = [];
56
+ if (targetName) {
57
+ buildTargets = [targetName];
58
+ }
59
+ else if (moduleName) {
60
+ const resolveResult = await runStep('Resolve module targets', async () => {
61
+ const task = getModuleTargets(bazelClient, moduleName);
62
+ buildTargets = json
63
+ ? await task
64
+ : await LoadingIndicator_1.LoadingIndicator.fromTask(task)
65
+ .setText((0, logUtils_1.wrapInColor)('Resolving module targets...', constants_1.ANSI_COLORS.YELLOW_COLOR))
66
+ .setSuccessText((0, logUtils_1.wrapInColor)('Resolved module targets.', constants_1.ANSI_COLORS.GREEN_COLOR))
67
+ .setFailureText((0, logUtils_1.wrapInColor)('Failed to resolve targets.', constants_1.ANSI_COLORS.RED_COLOR))
68
+ .show();
69
+ if (buildTargets.length === 0) {
70
+ throw new Error(`No valdi_module targets found for module "${moduleName}"`);
71
+ }
72
+ }, json);
73
+ results.push(resolveResult);
74
+ if (resolveResult.status === 'fail') {
75
+ return outputResults(results, totalStart, json);
76
+ }
77
+ testTargets = await getTestTargets(bazelClient, moduleName).catch(() => []);
78
+ }
79
+ if (!quick) {
80
+ const buildResult = await runStep('Build', async () => {
81
+ await bazelClient.buildTargets(buildTargets);
82
+ }, json);
83
+ results.push(buildResult);
84
+ }
85
+ else {
86
+ if (!json) {
87
+ console.log((0, logUtils_1.wrapInColor)(' ⊘ Build: skipped (--quick mode, hot reloader handles compilation)', constants_1.ANSI_COLORS.YELLOW_COLOR));
88
+ }
89
+ results.push({ name: 'Build', status: 'skip', durationMs: 0, message: 'Skipped in quick mode' });
90
+ }
91
+ const lintPromise = (buildTargets.length > 0)
92
+ ? runStep('Lint check', async () => {
93
+ const { runCliCommand } = await Promise.resolve().then(() => __importStar(require('../utils/cliUtils')));
94
+ const { globSync } = await Promise.resolve().then(() => __importStar(require('glob')));
95
+ const firstTarget = buildTargets[0] ?? '';
96
+ const packagePath = firstTarget.replace(/^\/\//, '').replace(/:.*$/, '') || '.';
97
+ const globPattern = `${packagePath}/**/*.{ts,tsx}`;
98
+ const tsFiles = globSync(globPattern);
99
+ if (tsFiles.length === 0) {
100
+ return;
101
+ }
102
+ const result = await runCliCommand(`npx prettier --check "${globPattern}"`);
103
+ if (result.returnCode !== 0) {
104
+ throw new Error('Lint check failed — files not formatted');
105
+ }
106
+ }, json)
107
+ : Promise.resolve({ name: 'Lint check', status: 'skip', durationMs: 0, message: 'No targets resolved for lint' });
108
+ const testPromise = (testTargets.length > 0)
109
+ ? runStep('Tests', async () => {
110
+ await bazelClient.testTargets(testTargets, '');
111
+ }, json)
112
+ : (() => {
113
+ if (!json) {
114
+ console.log((0, logUtils_1.wrapInColor)(' ⊘ Tests: skipped (no test targets found)', constants_1.ANSI_COLORS.YELLOW_COLOR));
115
+ }
116
+ return Promise.resolve({ name: 'Tests', status: 'skip', durationMs: 0, message: 'No test targets found' });
117
+ })();
118
+ const [lintResult, testResult] = await Promise.all([lintPromise, testPromise]);
119
+ results.push(lintResult);
120
+ results.push(testResult);
121
+ return outputResults(results, totalStart, json);
122
+ }
123
+ function outputResults(results, totalStart, json) {
124
+ const totalDurationMs = Date.now() - totalStart;
125
+ const passed = results.filter(r => r.status === 'pass').length;
126
+ const failed = results.filter(r => r.status === 'fail').length;
127
+ const skipped = results.filter(r => r.status === 'skip').length;
128
+ if (json) {
129
+ const output = {
130
+ timestamp: new Date().toISOString(),
131
+ totalDurationMs,
132
+ summary: { passed, failed, skipped, total: results.length },
133
+ results,
134
+ success: failed === 0,
135
+ };
136
+ console.log(JSON.stringify(output, null, 2));
137
+ }
138
+ else {
139
+ console.log((0, logUtils_1.wrapInColor)('\n═══ Summary ═══', constants_1.ANSI_COLORS.GREEN_COLOR));
140
+ console.log(` Passed: ${passed}`);
141
+ console.log(` Failed: ${failed}`);
142
+ console.log(` Skipped: ${skipped}`);
143
+ console.log(` Total: ${totalDurationMs}ms`);
144
+ if (failed > 0) {
145
+ console.log((0, logUtils_1.wrapInColor)('\n✗ Agent check FAILED', constants_1.ANSI_COLORS.RED_COLOR));
146
+ process.exitCode = 1;
147
+ }
148
+ else {
149
+ console.log((0, logUtils_1.wrapInColor)('\n✓ Agent check PASSED', constants_1.ANSI_COLORS.GREEN_COLOR));
150
+ }
151
+ }
152
+ if (failed > 0) {
153
+ process.exitCode = 1;
154
+ }
155
+ }
156
+ exports.command = 'agent-check [--module module_name] [--target target_name] [--quick]';
157
+ exports.describe = 'Validate a Valdi module: resolve targets, build, lint, and test in one command. '
158
+ + 'Use --quick to skip the build step when the hot reloader is already compiling your changes. '
159
+ + 'Use --json for structured output that AI agents can parse directly.';
160
+ const builder = (yargs) => {
161
+ yargs
162
+ .option('module', {
163
+ describe: 'Name of the Valdi module to validate',
164
+ type: 'string',
165
+ requiresArg: true,
166
+ })
167
+ .option('target', {
168
+ describe: 'Bazel target path to validate',
169
+ type: 'string',
170
+ requiresArg: true,
171
+ })
172
+ .option('quick', {
173
+ describe: 'Skip the build step (use when hot reloader is running). Runs only lint + test.',
174
+ type: 'boolean',
175
+ default: false,
176
+ })
177
+ .option('json', {
178
+ describe: 'Output results as machine-readable JSON',
179
+ type: 'boolean',
180
+ default: false,
181
+ });
182
+ };
183
+ exports.builder = builder;
184
+ exports.handler = (0, errorUtils_1.makeCommandHandler)(valdiAgentCheck);
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.handler = exports.builder = exports.describe = exports.command = void 0;
4
+ exports.command = 'analyze <command>';
5
+ exports.describe = 'Analyze Valdi modules — component duplication, patterns, health';
6
+ const builder = (yargs) => {
7
+ return yargs
8
+ .commandDir('analyze_commands', { extensions: ['js', 'ts'] })
9
+ .demandCommand(1, 'Use: duplicates')
10
+ .recommendCommands()
11
+ .wrap(yargs.terminalWidth())
12
+ .help();
13
+ };
14
+ exports.builder = builder;
15
+ const handler = () => { };
16
+ exports.handler = handler;
@@ -0,0 +1,134 @@
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 fs = tslib_1.__importStar(require("fs"));
6
+ const errorUtils_1 = require("../../utils/errorUtils");
7
+ const scanner_1 = require("../../core/analyze/scanner");
8
+ const parser_1 = require("../../core/analyze/parser");
9
+ const clusterer_1 = require("../../core/analyze/clusterer");
10
+ const knownPatterns_1 = require("../../core/analyze/knownPatterns");
11
+ const reporter_1 = require("../../core/analyze/reporter");
12
+ async function analyzeDuplicates(argv) {
13
+ const moduleFilter = argv.getArgument('module');
14
+ const json = argv.getArgument('json');
15
+ const threshold = argv.getArgument('threshold');
16
+ const patternFilter = argv.getArgument('pattern');
17
+ const outputPath = argv.getArgument('output');
18
+ const verbose = argv.getArgument('verbose');
19
+ const scanRootArg = argv.getArgument('scan-root');
20
+ const sharedLibArg = argv.getArgument('shared-lib');
21
+ const startTime = Date.now();
22
+ const cwd = process.cwd();
23
+ const config = (0, scanner_1.resolveScanConfig)(cwd, scanRootArg, sharedLibArg);
24
+ if (!json) {
25
+ process.stdout.write('Scanning files...');
26
+ }
27
+ const tsxFiles = (0, scanner_1.discoverTsxFiles)(config, moduleFilter);
28
+ if (!json) {
29
+ process.stdout.write(` found ${tsxFiles.length} .tsx files\n`);
30
+ process.stdout.write('Fingerprinting components...');
31
+ }
32
+ const fingerprints = [];
33
+ for (const file of tsxFiles) {
34
+ const fp = (0, parser_1.parseFile)(file, config);
35
+ if (fp)
36
+ fingerprints.push(fp);
37
+ }
38
+ if (!json) {
39
+ process.stdout.write(` extracted ${fingerprints.length} component fingerprints\n`);
40
+ }
41
+ const modulesScanned = new Set(fingerprints.map(fp => fp.moduleName)).size;
42
+ if (!json) {
43
+ process.stdout.write('Detecting known patterns...');
44
+ }
45
+ const knownPatterns = (0, knownPatterns_1.detectKnownPatterns)(fingerprints, config, patternFilter);
46
+ if (!json) {
47
+ process.stdout.write(` found ${knownPatterns.length} patterns\n`);
48
+ process.stdout.write('Clustering similar components...');
49
+ }
50
+ const genericClusters = patternFilter ? [] : (0, clusterer_1.clusterFingerprints)(fingerprints, config, threshold);
51
+ if (!json) {
52
+ process.stdout.write(` found ${genericClusters.length} clusters\n\n`);
53
+ }
54
+ const durationMs = Date.now() - startTime;
55
+ const totalKnownPatternMatches = knownPatterns.reduce((sum, p) => sum + p.matchCount, 0);
56
+ const totalDuplicatedFiles = new Set(genericClusters.flatMap(c => c.files.map(f => f.path))).size;
57
+ const report = {
58
+ timestamp: new Date().toISOString(),
59
+ config,
60
+ scanStats: {
61
+ filesScanned: tsxFiles.length,
62
+ modulesScanned,
63
+ durationMs,
64
+ },
65
+ knownPatterns,
66
+ genericClusters,
67
+ summary: {
68
+ totalClusters: genericClusters.length,
69
+ totalDuplicatedFiles,
70
+ totalKnownPatternMatches,
71
+ },
72
+ };
73
+ if (outputPath) {
74
+ fs.writeFileSync(outputPath, (0, reporter_1.formatJsonReport)(report), 'utf8');
75
+ if (!json) {
76
+ console.log(`Report written to ${outputPath}`);
77
+ }
78
+ }
79
+ if (json) {
80
+ console.log((0, reporter_1.formatJsonReport)(report));
81
+ }
82
+ else {
83
+ (0, reporter_1.printHumanReport)(report, verbose);
84
+ }
85
+ }
86
+ exports.command = 'duplicates';
87
+ exports.describe = 'Find duplicated component patterns across Valdi modules';
88
+ const builder = (yargs) => {
89
+ yargs
90
+ .option('module', {
91
+ describe: 'Scope scan to a single module',
92
+ type: 'string',
93
+ })
94
+ .option('json', {
95
+ describe: 'Machine-readable JSON output',
96
+ type: 'boolean',
97
+ default: false,
98
+ alias: 'j',
99
+ })
100
+ .option('threshold', {
101
+ describe: 'Similarity threshold for clustering (0-1)',
102
+ type: 'number',
103
+ default: 0.6,
104
+ alias: 't',
105
+ })
106
+ .option('pattern', {
107
+ describe: 'Only detect a specific known pattern: async, button, shimmer',
108
+ type: 'string',
109
+ choices: ['async', 'button', 'shimmer'],
110
+ })
111
+ .option('output', {
112
+ describe: 'Write JSON report to file',
113
+ type: 'string',
114
+ alias: 'o',
115
+ })
116
+ .option('verbose', {
117
+ describe: 'Show per-file detail in output',
118
+ type: 'boolean',
119
+ default: false,
120
+ alias: 'v',
121
+ })
122
+ .option('scan-root', {
123
+ describe: 'Root directory to scan (repeatable). Auto-detected if omitted.',
124
+ type: 'string',
125
+ array: true,
126
+ })
127
+ .option('shared-lib', {
128
+ describe: 'Shared component library name (repeatable). Defaults: coreui (internal) or valdi_widgets (external).',
129
+ type: 'string',
130
+ array: true,
131
+ });
132
+ };
133
+ exports.builder = builder;
134
+ exports.handler = (0, errorUtils_1.makeCommandHandler)(analyzeDuplicates);
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.handler = exports.builder = exports.describe = exports.command = void 0;
4
4
  const tslib_1 = require("tslib");
5
+ const fs_1 = tslib_1.__importDefault(require("fs"));
5
6
  const path_1 = tslib_1.__importDefault(require("path"));
6
7
  const inquirer_1 = tslib_1.__importDefault(require("inquirer"));
7
8
  const constants_1 = require("../core/constants");
@@ -29,34 +30,10 @@ const ALL_APPLICATION_TEMPLATES = [
29
30
  ];
30
31
  const VALDI_GIT_URL = 'https://github.com/Snapchat/Valdi';
31
32
  const VALDI_WIDGETS_GIT_URL = 'https://github.com/Snapchat/Valdi_Widgets';
32
- const DEFAULT_VALDI_RELEASE_TAG = 'beta-0.0.3';
33
- const DEFAULT_VALDI_WIDGETS_RELEASE_TAG = 'beta-0.0.3';
34
- const DEFAULT_VALDI_IMPORT = `
35
- http_archive(
36
- name = "valdi",
37
- strip_prefix = "Valdi-{{VALDI_RELEASE_TAG}}",
38
- url = "${VALDI_GIT_URL}/archive/{{VALDI_RELEASE_REF}}.tar.gz",
39
- )`;
40
- const DEFAULT_VALDI_WIDGETS_IMPORT = `
41
- http_archive(
42
- name = "valdi_widgets",
43
- strip_prefix = "Valdi_Widgets-{{VALDI_WIDGETS_RELEASE_TAG}}",
44
- url = "${VALDI_WIDGETS_GIT_URL}/archive/{{VALDI_WIDGETS_RELEASE_REF}}.tar.gz",
45
- )`;
46
- const LOCAL_VALDI_IMPORT_TEMPLATE = `
47
- local_repository(
48
- name = "valdi",
49
- path = "{{PATH}}",
50
- )
51
- `;
52
- const LOCAL_VALDI_WIDGETS_IMPORT_TEMPLATE = `
53
- local_repository(
54
- name = "valdi_widgets",
55
- path = "{{PATH}}",
56
- )
57
- `;
33
+ const DEFAULT_VALDI_RELEASE_TAG = 'beta-0.1.1';
34
+ const DEFAULT_VALDI_WIDGETS_RELEASE_TAG = 'beta-0.1.1';
58
35
  function isAlreadyInitialized() {
59
- return (0, fileUtils_1.fileExists)(path_1.default.join(process.cwd(), 'WORKSPACE'));
36
+ return (0, fileUtils_1.fileExists)(path_1.default.join(process.cwd(), 'MODULE.bazel')) || (0, fileUtils_1.fileExists)(path_1.default.join(process.cwd(), 'WORKSPACE'));
60
37
  }
61
38
  async function getShouldBootstrap(argv) {
62
39
  return argv.getArgumentOrResolve('confirmBootstrap', () => {
@@ -123,42 +100,18 @@ function resolveValdiReleaseTag(argv, gitUrl, defaultTag, versionOption = 'valdi
123
100
  }
124
101
  return Promise.resolve(override);
125
102
  }
126
- function getValdiImport(argv, valdiReleaseRef) {
127
- const valdiImport = argv.getArgument('valdiImport');
128
- if (valdiImport) {
129
- return (0, fileUtils_1.processReplacements)(LOCAL_VALDI_IMPORT_TEMPLATE, { PATH: valdiImport });
130
- }
131
- else {
132
- const valdiReleaseTag = valdiReleaseRef.split('/').pop();
133
- return (0, fileUtils_1.processReplacements)(DEFAULT_VALDI_IMPORT, {
134
- VALDI_RELEASE_REF: valdiReleaseRef,
135
- VALDI_RELEASE_TAG: valdiReleaseTag,
136
- });
137
- }
138
- }
139
- function getValdiWidgetsImport(argv, valdiWidgetsReleaseRef) {
140
- const valdiWidgetsImport = argv.getArgument('valdiWidgetsImport');
141
- if (valdiWidgetsImport) {
142
- return (0, fileUtils_1.processReplacements)(LOCAL_VALDI_WIDGETS_IMPORT_TEMPLATE, { PATH: valdiWidgetsImport });
143
- }
144
- else {
145
- const valdiWidgetsReleaseTag = valdiWidgetsReleaseRef.split('/').pop();
146
- return (0, fileUtils_1.processReplacements)(DEFAULT_VALDI_WIDGETS_IMPORT, {
147
- VALDI_WIDGETS_RELEASE_REF: valdiWidgetsReleaseRef,
148
- VALDI_WIDGETS_RELEASE_TAG: valdiWidgetsReleaseTag,
149
- });
150
- }
151
- }
152
- function initializeConfigFiles(projectName, template, valdiImport, valdiWidgetsImport) {
103
+ function initializeConfigFiles(projectName, template, valdiReleaseTag, valdiWidgetsReleaseTag) {
153
104
  const TEMPLATE_FILES = [
154
105
  fileUtils_1.TemplateFile.init(constants_1.TEMPLATE_BASE_PATHS.USER_CONFIG).withOutputPath((0, fileUtils_1.resolveFilePath)(constants_1.VALDI_CONFIG_PATHS[0] ?? '')),
155
106
  fileUtils_1.TemplateFile.init(constants_1.TEMPLATE_BASE_PATHS.BAZEL_VERSION),
156
- fileUtils_1.TemplateFile.init(constants_1.TEMPLATE_BASE_PATHS.WORKSPACE).withReplacements({
107
+ fileUtils_1.TemplateFile.init(constants_1.TEMPLATE_BASE_PATHS.MODULE_BAZEL).withReplacements({
157
108
  WORKSPACE_NAME: projectName,
158
- VALDI_IMPORT: valdiImport,
159
- VALDI_WIDGETS_IMPORT: valdiWidgetsImport,
109
+ VALDI_RELEASE_TAG: valdiReleaseTag,
110
+ VALDI_WIDGETS_RELEASE_TAG: valdiWidgetsReleaseTag,
111
+ }),
112
+ fileUtils_1.TemplateFile.init(constants_1.TEMPLATE_BASE_PATHS.BAZEL_RC).withReplacements({
113
+ VALDI_RELEASE_TAG: valdiReleaseTag,
160
114
  }),
161
- fileUtils_1.TemplateFile.init(constants_1.TEMPLATE_BASE_PATHS.BAZEL_RC),
162
115
  fileUtils_1.TemplateFile.init(constants_1.TEMPLATE_BASE_PATHS.README),
163
116
  fileUtils_1.TemplateFile.init(constants_1.TEMPLATE_BASE_PATHS.GIT_IGNORE),
164
117
  fileUtils_1.TemplateFile.init(constants_1.TEMPLATE_BASE_PATHS.WATCHMAN_CONFIG),
@@ -184,6 +137,39 @@ function initializeConfigFiles(projectName, template, valdiImport, valdiWidgetsI
184
137
  const destPath = process.cwd();
185
138
  (0, copyBootstrapFiles_1.copyBootstrapFiles)(sourcePath, destPath, replacements);
186
139
  }
140
+ const VALDI_SUB_MODULES = [
141
+ { name: 'android_macros', subPath: 'bzl/macros' },
142
+ { name: 'snap_macros', subPath: 'bzl/valdi/snap_macros' },
143
+ { name: 'snap_client_toolchains', subPath: 'bzl/toolchains' },
144
+ { name: 'snap_platforms', subPath: 'bzl/platforms' },
145
+ { name: 'skia_user_config', subPath: 'third-party/skia_user_config' },
146
+ { name: 'rules_hdrs', subPath: 'third-party/rules_hdrs' },
147
+ { name: 'valdi_toolchain', subPath: 'bin' },
148
+ { name: 'resvg_libs', subPath: 'third-party/resvg/resvg_libs' },
149
+ ];
150
+ function applyLocalOverrides(localValdiPath) {
151
+ const resolvedPath = path_1.default.resolve(localValdiPath);
152
+ const registryPath = path_1.default.join(resolvedPath, 'registry');
153
+ const moduleBazelPath = path_1.default.join(process.cwd(), 'MODULE.bazel');
154
+ let content = fs_1.default.readFileSync(moduleBazelPath, 'utf-8');
155
+ content = content.replace(/VALDI_TAG = .*\nVALDI_URL = .*\nVALDI_PREFIX = .*\n\nbazel_dep\(name = "valdi".*\)\narchive_override\(\n\s+module_name = "valdi",\n\s+urls = \[VALDI_URL\],\n\s+strip_prefix = VALDI_PREFIX,\n\)/, `bazel_dep(name = "valdi", version = "0.1")\nlocal_path_override(module_name = "valdi", path = "${resolvedPath}")`);
156
+ for (const sub of VALDI_SUB_MODULES) {
157
+ const subModuleBazel = path_1.default.join(resolvedPath, sub.subPath, 'MODULE.bazel');
158
+ const regex = new RegExp(`\\nbazel_dep\\(name = "${sub.name}"\\)\\narchive_override\\(module_name = "${sub.name}".*\\)`);
159
+ if (fs_1.default.existsSync(subModuleBazel)) {
160
+ content = content.replace(regex, `\nbazel_dep(name = "${sub.name}")\nlocal_path_override(module_name = "${sub.name}", path = "${resolvedPath}/${sub.subPath}")`);
161
+ }
162
+ else {
163
+ content = content.replace(regex, '');
164
+ }
165
+ }
166
+ content = content.replace(/# -- Valdi Widgets.*\nWIDGETS_TAG = .*\n\nbazel_dep\(name = "valdi_widgets"\)\narchive_override\(\n\s+module_name = "valdi_widgets",\n\s+urls = \[.*\],\n\s+strip_prefix = .*,\n\)/, '');
167
+ fs_1.default.writeFileSync(moduleBazelPath, content);
168
+ const bazelrcPath = path_1.default.join(process.cwd(), '.bazelrc');
169
+ let bazelrc = fs_1.default.readFileSync(bazelrcPath, 'utf-8');
170
+ bazelrc = bazelrc.replace(/common --registry=https:\/\/raw\.githubusercontent\.com\/Snapchat\/Valdi\/.*\/registry/, `common --registry=file://${registryPath}`);
171
+ fs_1.default.writeFileSync(bazelrcPath, bazelrc);
172
+ }
187
173
  async function valdiBootstrap(argv) {
188
174
  const curDir = process.cwd();
189
175
  console.log(`\nCurrent directory: ${(0, logUtils_1.wrapInColor)(curDir, constants_1.ANSI_COLORS.GREEN_COLOR)}`);
@@ -216,10 +202,13 @@ async function valdiBootstrap(argv) {
216
202
  }
217
203
  const valdiReleaseTag = await resolveValdiReleaseTag(argv, VALDI_GIT_URL, DEFAULT_VALDI_RELEASE_TAG);
218
204
  const valdiWidgetsReleaseTag = await resolveValdiReleaseTag(argv, VALDI_WIDGETS_GIT_URL, DEFAULT_VALDI_WIDGETS_RELEASE_TAG, 'valdiWidgetsVersion');
219
- const valdiImport = getValdiImport(argv, valdiReleaseTag);
220
- const valdiWidgetsImport = getValdiWidgetsImport(argv, valdiWidgetsReleaseTag);
221
205
  console.log((0, logUtils_1.wrapInColor)('Initializing config files...', constants_1.ANSI_COLORS.BLUE_COLOR));
222
- initializeConfigFiles(projectName, applicationType, valdiImport, valdiWidgetsImport);
206
+ initializeConfigFiles(projectName, applicationType, valdiReleaseTag, valdiWidgetsReleaseTag);
207
+ const localValdiPath = argv.getArgument('localValdiPath');
208
+ if (localValdiPath) {
209
+ console.log((0, logUtils_1.wrapInColor)(`Applying local overrides for ${localValdiPath}...`, constants_1.ANSI_COLORS.YELLOW_COLOR));
210
+ applyLocalOverrides(localValdiPath);
211
+ }
223
212
  console.log((0, logUtils_1.wrapInColor)('Verifying Bazel installation...', constants_1.ANSI_COLORS.BLUE_COLOR));
224
213
  const bazel = new BazelClient_1.BazelClient();
225
214
  const [returnCode, versionInfo, errors] = await bazel.getVersion();
@@ -253,24 +242,19 @@ const builder = (yargs) => {
253
242
  describe: 'Name of the project',
254
243
  type: 'string',
255
244
  alias: 'n',
256
- })
257
- .option('valdiImport', {
258
- describe: 'Path to a local checkout of the Valdi repo. If not specified, uses the pinned release (see valdiVersion).',
259
- type: 'string',
260
- alias: 'l',
261
- })
262
- .option('valdiWidgetsImport', {
263
- describe: 'Path to a local checkout of the Valdi_Widgets repo. If not specified, uses the pinned release (see valdiWidgetsVersion).',
264
- type: 'string',
265
- alias: 'w',
266
245
  })
267
246
  .option('valdiVersion', {
268
- describe: `Valdi release tag to use (e.g. v1.0.0). Use "latest" to fetch the GitHub latest release. Default: ${DEFAULT_VALDI_RELEASE_TAG}`,
247
+ describe: `Valdi release tag or branch to use (e.g. beta-0.1.0, main). Use "latest" for the GitHub latest release, or "main" for bleeding edge. Default: ${DEFAULT_VALDI_RELEASE_TAG}`,
269
248
  type: 'string',
270
249
  })
271
250
  .option('valdiWidgetsVersion', {
272
- describe: `Valdi_Widgets release tag to use. Use "latest" to fetch the GitHub latest release. Default: ${DEFAULT_VALDI_WIDGETS_RELEASE_TAG}`,
251
+ describe: `Valdi_Widgets release tag or branch to use. Use "latest" for the GitHub latest release, or "main" for bleeding edge. Default: ${DEFAULT_VALDI_WIDGETS_RELEASE_TAG}`,
273
252
  type: 'string',
253
+ })
254
+ .option('localValdiPath', {
255
+ describe: 'Path to a local Valdi checkout. Generates local_path_override entries instead of archive_override.',
256
+ type: 'string',
257
+ alias: 'l',
274
258
  })
275
259
  .option('skipProjectsync', {
276
260
  describe: 'Skip projectsync for testing purposes',
@@ -32,6 +32,12 @@ async function valdiBuild(argv) {
32
32
  await bazel.buildTarget(buildInfo.application, buildInfo.bazelArgs);
33
33
  break;
34
34
  }
35
+ case constants_1.PLATFORM.LINUX: {
36
+ (0, errorUtils_1.logReproduceThisCommandIfNeeded)(argv);
37
+ console.log('Building Linux application...');
38
+ await bazel.buildTarget(buildInfo.application, buildInfo.bazelArgs);
39
+ break;
40
+ }
35
41
  case constants_1.PLATFORM.CLI: {
36
42
  (0, errorUtils_1.logReproduceThisCommandIfNeeded)(argv);
37
43
  console.log('Build CLI application...');