@snap/valdi 1.0.1 → 1.0.6

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 (39) hide show
  1. package/.bootstrap/apps/cli_application/AGENTS.md.template +76 -0
  2. package/.bootstrap/apps/ui_application/AGENTS.md.template +79 -3
  3. package/.bootstrap/modules/cpp_bridge_module/BUILD.bazel.template +3 -3
  4. package/.bootstrap/modules/cpp_bridge_module/cpp/CalculatorModuleFactory.cpp.template +18 -19
  5. package/.bootstrap/modules/cpp_bridge_module/src/Calculator.d.ts +3 -0
  6. package/.github/README.md +164 -0
  7. package/.metadata/.cursorrules.template +53 -0
  8. package/.metadata/.editorconfig.template +37 -0
  9. package/LINUX_COMPATIBILITY.md +248 -0
  10. package/README.md +99 -15
  11. package/dist/commands/bootstrap.js +79 -19
  12. package/dist/commands/doctor.js +361 -54
  13. package/dist/commands/newModule.js +15 -12
  14. package/dist/core/constants.js +2 -0
  15. package/dist/setup/DevSetupHelper.js +81 -6
  16. package/dist/setup/linuxSetup.js +149 -11
  17. package/dist/setup/macOSSetup.js +96 -8
  18. package/dist/utils/githubUtils.js +74 -2
  19. package/dist/utils/linuxDistro.js +255 -0
  20. package/dist/utils/linuxDistro.spec.js +170 -0
  21. package/dist/utils/stringUtils.js +60 -0
  22. package/dist/utils/stringUtils.spec.js +63 -0
  23. package/package.json +11 -3
  24. package/scripts/sync-agents-md.sh +44 -0
  25. package/scripts/update-agents-templates.ts +170 -0
  26. package/src/commands/bootstrap.ts +117 -25
  27. package/src/commands/doctor.ts +469 -59
  28. package/src/commands/newModule.ts +18 -19
  29. package/src/core/constants.ts +2 -0
  30. package/src/setup/DevSetupHelper.ts +108 -6
  31. package/src/setup/linuxSetup.ts +235 -12
  32. package/src/setup/macOSSetup.ts +122 -8
  33. package/src/utils/githubUtils.ts +98 -2
  34. package/src/utils/linuxDistro.spec.ts +219 -0
  35. package/src/utils/linuxDistro.ts +326 -0
  36. package/src/utils/stringUtils.spec.ts +77 -1
  37. package/src/utils/stringUtils.ts +88 -0
  38. package/test/ValdiSmokeTest.ts +5 -4
  39. package/test/helpers/TypeScriptClient.ts +2 -2
@@ -0,0 +1,255 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LinuxDistroType = void 0;
4
+ exports.detectLinuxDistro = detectLinuxDistro;
5
+ exports.getPackageName = getPackageName;
6
+ exports.buildInstallCommand = buildInstallCommand;
7
+ exports.getCommonPackageMappings = getCommonPackageMappings;
8
+ exports.needsGitLfsRepoSetup = needsGitLfsRepoSetup;
9
+ exports.getGitLfsRepoSetupCommand = getGitLfsRepoSetupCommand;
10
+ const tslib_1 = require("tslib");
11
+ const fs_1 = tslib_1.__importDefault(require("fs"));
12
+ const cliUtils_1 = require("./cliUtils");
13
+ var LinuxDistroType;
14
+ (function (LinuxDistroType) {
15
+ LinuxDistroType["DEBIAN"] = "debian";
16
+ LinuxDistroType["REDHAT"] = "redhat";
17
+ LinuxDistroType["ARCH"] = "arch";
18
+ LinuxDistroType["SUSE"] = "suse";
19
+ LinuxDistroType["UNKNOWN"] = "unknown";
20
+ })(LinuxDistroType || (exports.LinuxDistroType = LinuxDistroType = {}));
21
+ function detectLinuxDistro() {
22
+ if (fs_1.default.existsSync('/etc/os-release')) {
23
+ try {
24
+ const osRelease = fs_1.default.readFileSync('/etc/os-release', 'utf8');
25
+ const lines = osRelease.split('\n');
26
+ const info = {};
27
+ for (const line of lines) {
28
+ const match = line.match(/^([^=]+)=(.*)$/);
29
+ if (match && match[1] && match[2]) {
30
+ info[match[1]] = match[2].replaceAll(/^["']|["']$/g, '');
31
+ }
32
+ }
33
+ const id = info['ID']?.toLowerCase() ?? '';
34
+ const idLike = info['ID_LIKE']?.toLowerCase() ?? '';
35
+ const name = info['NAME'] ?? 'Linux';
36
+ const version = info['VERSION_ID'];
37
+ if (id.includes('debian') || id.includes('ubuntu') || idLike.includes('debian') || idLike.includes('ubuntu')) {
38
+ const result = {
39
+ type: LinuxDistroType.DEBIAN,
40
+ name,
41
+ packageManager: getPackageManager(LinuxDistroType.DEBIAN),
42
+ };
43
+ if (version)
44
+ result.version = version;
45
+ return result;
46
+ }
47
+ else if (id.includes('fedora') ||
48
+ id.includes('rhel') ||
49
+ id.includes('centos') ||
50
+ id.includes('rocky') ||
51
+ idLike.includes('fedora') ||
52
+ idLike.includes('rhel')) {
53
+ const result = {
54
+ type: LinuxDistroType.REDHAT,
55
+ name,
56
+ packageManager: getPackageManager(LinuxDistroType.REDHAT),
57
+ };
58
+ if (version)
59
+ result.version = version;
60
+ return result;
61
+ }
62
+ else if (id.includes('arch') || id.includes('manjaro') || idLike.includes('arch')) {
63
+ const result = {
64
+ type: LinuxDistroType.ARCH,
65
+ name,
66
+ packageManager: getPackageManager(LinuxDistroType.ARCH),
67
+ };
68
+ if (version)
69
+ result.version = version;
70
+ return result;
71
+ }
72
+ else if (id.includes('suse') || idLike.includes('suse')) {
73
+ const result = {
74
+ type: LinuxDistroType.SUSE,
75
+ name,
76
+ packageManager: getPackageManager(LinuxDistroType.SUSE),
77
+ };
78
+ if (version)
79
+ result.version = version;
80
+ return result;
81
+ }
82
+ }
83
+ catch {
84
+ }
85
+ }
86
+ if ((0, cliUtils_1.checkCommandExists)('apt-get')) {
87
+ return {
88
+ type: LinuxDistroType.DEBIAN,
89
+ name: 'Debian/Ubuntu',
90
+ packageManager: getPackageManager(LinuxDistroType.DEBIAN),
91
+ };
92
+ }
93
+ else if ((0, cliUtils_1.checkCommandExists)('dnf')) {
94
+ return {
95
+ type: LinuxDistroType.REDHAT,
96
+ name: 'Fedora/RHEL',
97
+ packageManager: getPackageManager(LinuxDistroType.REDHAT),
98
+ };
99
+ }
100
+ else if ((0, cliUtils_1.checkCommandExists)('yum')) {
101
+ return {
102
+ type: LinuxDistroType.REDHAT,
103
+ name: 'RHEL/CentOS',
104
+ packageManager: getPackageManager(LinuxDistroType.REDHAT),
105
+ };
106
+ }
107
+ else if ((0, cliUtils_1.checkCommandExists)('pacman')) {
108
+ return {
109
+ type: LinuxDistroType.ARCH,
110
+ name: 'Arch Linux',
111
+ packageManager: getPackageManager(LinuxDistroType.ARCH),
112
+ };
113
+ }
114
+ else if ((0, cliUtils_1.checkCommandExists)('zypper')) {
115
+ return {
116
+ type: LinuxDistroType.SUSE,
117
+ name: 'openSUSE/SLES',
118
+ packageManager: getPackageManager(LinuxDistroType.SUSE),
119
+ };
120
+ }
121
+ return {
122
+ type: LinuxDistroType.UNKNOWN,
123
+ name: 'Unknown Linux',
124
+ packageManager: {
125
+ name: 'unknown',
126
+ installCommand: '',
127
+ requiresSudo: true,
128
+ },
129
+ };
130
+ }
131
+ function getPackageManager(distroType) {
132
+ switch (distroType) {
133
+ case LinuxDistroType.DEBIAN: {
134
+ return {
135
+ name: 'apt',
136
+ installCommand: 'apt-get install',
137
+ requiresSudo: true,
138
+ updateCommand: 'apt-get update',
139
+ };
140
+ }
141
+ case LinuxDistroType.REDHAT: {
142
+ if ((0, cliUtils_1.checkCommandExists)('dnf')) {
143
+ return {
144
+ name: 'dnf',
145
+ installCommand: 'dnf install',
146
+ requiresSudo: true,
147
+ };
148
+ }
149
+ else {
150
+ return {
151
+ name: 'yum',
152
+ installCommand: 'yum install',
153
+ requiresSudo: true,
154
+ };
155
+ }
156
+ }
157
+ case LinuxDistroType.ARCH: {
158
+ return {
159
+ name: 'pacman',
160
+ installCommand: 'pacman -S',
161
+ requiresSudo: true,
162
+ updateCommand: 'pacman -Sy',
163
+ };
164
+ }
165
+ case LinuxDistroType.SUSE: {
166
+ return {
167
+ name: 'zypper',
168
+ installCommand: 'zypper install',
169
+ requiresSudo: true,
170
+ };
171
+ }
172
+ default: {
173
+ return {
174
+ name: 'unknown',
175
+ installCommand: '',
176
+ requiresSudo: true,
177
+ };
178
+ }
179
+ }
180
+ }
181
+ function getPackageName(packageMap, distro = detectLinuxDistro()) {
182
+ return packageMap[distro.type] ?? packageMap.unknown;
183
+ }
184
+ function buildInstallCommand(packages, distro = detectLinuxDistro()) {
185
+ if (distro.type === LinuxDistroType.UNKNOWN) {
186
+ return `# Unable to determine package manager. Please install manually: ${packages.join(', ')}`;
187
+ }
188
+ const { packageManager } = distro;
189
+ const sudo = packageManager.requiresSudo ? 'sudo ' : '';
190
+ return `${sudo}${packageManager.installCommand} ${packages.join(' ')}`;
191
+ }
192
+ function getCommonPackageMappings() {
193
+ return {
194
+ git: {
195
+ unknown: 'git',
196
+ },
197
+ 'git-lfs': {
198
+ unknown: 'git-lfs',
199
+ },
200
+ npm: {
201
+ unknown: 'npm',
202
+ },
203
+ 'openjdk-17': {
204
+ debian: 'openjdk-17-jdk',
205
+ redhat: 'java-17-openjdk-devel',
206
+ arch: 'jdk17-openjdk',
207
+ suse: 'java-17-openjdk-devel',
208
+ unknown: 'openjdk-17-jdk',
209
+ },
210
+ watchman: {
211
+ debian: 'watchman',
212
+ redhat: 'watchman',
213
+ arch: 'watchman',
214
+ suse: 'watchman',
215
+ unknown: 'watchman',
216
+ },
217
+ adb: {
218
+ debian: 'adb',
219
+ redhat: 'android-tools',
220
+ arch: 'android-tools',
221
+ suse: 'android-tools',
222
+ unknown: 'adb',
223
+ },
224
+ fontconfig: {
225
+ debian: 'libfontconfig1-dev',
226
+ redhat: 'fontconfig-devel',
227
+ arch: 'fontconfig',
228
+ suse: 'fontconfig-devel',
229
+ unknown: 'fontconfig',
230
+ },
231
+ zlib: {
232
+ debian: 'zlib1g-dev',
233
+ redhat: 'zlib-devel',
234
+ arch: 'zlib',
235
+ suse: 'zlib-devel',
236
+ unknown: 'zlib',
237
+ },
238
+ };
239
+ }
240
+ function needsGitLfsRepoSetup(distro = detectLinuxDistro()) {
241
+ return distro.type === LinuxDistroType.DEBIAN;
242
+ }
243
+ function getGitLfsRepoSetupCommand(distro = detectLinuxDistro()) {
244
+ switch (distro.type) {
245
+ case LinuxDistroType.DEBIAN: {
246
+ return 'curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | sudo bash';
247
+ }
248
+ case LinuxDistroType.REDHAT: {
249
+ return 'curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.rpm.sh | sudo bash';
250
+ }
251
+ default: {
252
+ return null;
253
+ }
254
+ }
255
+ }
@@ -0,0 +1,170 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ require("jasmine");
4
+ const linuxDistro_1 = require("./linuxDistro");
5
+ describe('linuxDistro', () => {
6
+ describe('getPackageName', () => {
7
+ it('returns Debian package name for Debian distribution', () => {
8
+ const packageMap = {
9
+ debian: 'openjdk-17-jdk',
10
+ redhat: 'java-17-openjdk-devel',
11
+ unknown: 'openjdk-17',
12
+ };
13
+ const distro = {
14
+ type: linuxDistro_1.LinuxDistroType.DEBIAN,
15
+ name: 'Ubuntu',
16
+ packageManager: { name: 'apt', installCommand: 'apt-get install', requiresSudo: true },
17
+ };
18
+ const result = (0, linuxDistro_1.getPackageName)(packageMap, distro);
19
+ expect(result).toBe('openjdk-17-jdk');
20
+ });
21
+ it('returns RedHat package name for RedHat distribution', () => {
22
+ const packageMap = {
23
+ debian: 'openjdk-17-jdk',
24
+ redhat: 'java-17-openjdk-devel',
25
+ unknown: 'openjdk-17',
26
+ };
27
+ const distro = {
28
+ type: linuxDistro_1.LinuxDistroType.REDHAT,
29
+ name: 'Fedora',
30
+ packageManager: { name: 'dnf', installCommand: 'dnf install', requiresSudo: true },
31
+ };
32
+ const result = (0, linuxDistro_1.getPackageName)(packageMap, distro);
33
+ expect(result).toBe('java-17-openjdk-devel');
34
+ });
35
+ it('returns unknown fallback for distributions without specific mapping', () => {
36
+ const packageMap = {
37
+ debian: 'openjdk-17-jdk',
38
+ unknown: 'openjdk-17',
39
+ };
40
+ const distro = {
41
+ type: linuxDistro_1.LinuxDistroType.ARCH,
42
+ name: 'Arch Linux',
43
+ packageManager: { name: 'pacman', installCommand: 'pacman -S', requiresSudo: true },
44
+ };
45
+ const result = (0, linuxDistro_1.getPackageName)(packageMap, distro);
46
+ expect(result).toBe('openjdk-17');
47
+ });
48
+ });
49
+ describe('buildInstallCommand', () => {
50
+ it('builds install command for Debian', () => {
51
+ const distro = {
52
+ type: linuxDistro_1.LinuxDistroType.DEBIAN,
53
+ name: 'Ubuntu',
54
+ packageManager: { name: 'apt', installCommand: 'apt-get install', requiresSudo: true },
55
+ };
56
+ const result = (0, linuxDistro_1.buildInstallCommand)(['git', 'npm', 'watchman'], distro);
57
+ expect(result).toBe('sudo apt-get install git npm watchman');
58
+ });
59
+ it('builds install command for RedHat', () => {
60
+ const distro = {
61
+ type: linuxDistro_1.LinuxDistroType.REDHAT,
62
+ name: 'Fedora',
63
+ packageManager: { name: 'dnf', installCommand: 'dnf install', requiresSudo: true },
64
+ };
65
+ const result = (0, linuxDistro_1.buildInstallCommand)(['git', 'npm'], distro);
66
+ expect(result).toBe('sudo dnf install git npm');
67
+ });
68
+ it('builds install command for Arch', () => {
69
+ const distro = {
70
+ type: linuxDistro_1.LinuxDistroType.ARCH,
71
+ name: 'Arch Linux',
72
+ packageManager: { name: 'pacman', installCommand: 'pacman -S', requiresSudo: true },
73
+ };
74
+ const result = (0, linuxDistro_1.buildInstallCommand)(['git', 'npm'], distro);
75
+ expect(result).toBe('sudo pacman -S git npm');
76
+ });
77
+ it('returns comment for unknown distribution', () => {
78
+ const distro = {
79
+ type: linuxDistro_1.LinuxDistroType.UNKNOWN,
80
+ name: 'Unknown',
81
+ packageManager: { name: 'unknown', installCommand: '', requiresSudo: true },
82
+ };
83
+ const result = (0, linuxDistro_1.buildInstallCommand)(['git', 'npm'], distro);
84
+ expect(result).toContain('Unable to determine package manager');
85
+ expect(result).toContain('git, npm');
86
+ });
87
+ });
88
+ describe('needsGitLfsRepoSetup', () => {
89
+ it('returns true for Debian distributions', () => {
90
+ const distro = {
91
+ type: linuxDistro_1.LinuxDistroType.DEBIAN,
92
+ name: 'Ubuntu',
93
+ packageManager: { name: 'apt', installCommand: 'apt-get install', requiresSudo: true },
94
+ };
95
+ expect((0, linuxDistro_1.needsGitLfsRepoSetup)(distro)).toBe(true);
96
+ });
97
+ it('returns false for Arch distributions', () => {
98
+ const distro = {
99
+ type: linuxDistro_1.LinuxDistroType.ARCH,
100
+ name: 'Arch Linux',
101
+ packageManager: { name: 'pacman', installCommand: 'pacman -S', requiresSudo: true },
102
+ };
103
+ expect((0, linuxDistro_1.needsGitLfsRepoSetup)(distro)).toBe(false);
104
+ });
105
+ });
106
+ describe('getGitLfsRepoSetupCommand', () => {
107
+ it('returns Debian script for Debian distributions', () => {
108
+ const distro = {
109
+ type: linuxDistro_1.LinuxDistroType.DEBIAN,
110
+ name: 'Ubuntu',
111
+ packageManager: { name: 'apt', installCommand: 'apt-get install', requiresSudo: true },
112
+ };
113
+ const result = (0, linuxDistro_1.getGitLfsRepoSetupCommand)(distro);
114
+ expect(result).toContain('script.deb.sh');
115
+ });
116
+ it('returns RPM script for RedHat distributions', () => {
117
+ const distro = {
118
+ type: linuxDistro_1.LinuxDistroType.REDHAT,
119
+ name: 'Fedora',
120
+ packageManager: { name: 'dnf', installCommand: 'dnf install', requiresSudo: true },
121
+ };
122
+ const result = (0, linuxDistro_1.getGitLfsRepoSetupCommand)(distro);
123
+ expect(result).toContain('script.rpm.sh');
124
+ });
125
+ it('returns null for distributions with git-lfs in standard repos', () => {
126
+ const distro = {
127
+ type: linuxDistro_1.LinuxDistroType.ARCH,
128
+ name: 'Arch Linux',
129
+ packageManager: { name: 'pacman', installCommand: 'pacman -S', requiresSudo: true },
130
+ };
131
+ const result = (0, linuxDistro_1.getGitLfsRepoSetupCommand)(distro);
132
+ expect(result).toBeNull();
133
+ });
134
+ });
135
+ describe('getCommonPackageMappings', () => {
136
+ it('returns package mappings for common dependencies', () => {
137
+ const mappings = (0, linuxDistro_1.getCommonPackageMappings)();
138
+ expect(mappings['git']).toBeDefined();
139
+ expect(mappings['git-lfs']).toBeDefined();
140
+ expect(mappings['npm']).toBeDefined();
141
+ expect(mappings['openjdk-17']).toBeDefined();
142
+ expect(mappings['watchman']).toBeDefined();
143
+ expect(mappings['adb']).toBeDefined();
144
+ expect(mappings['fontconfig']).toBeDefined();
145
+ expect(mappings['zlib']).toBeDefined();
146
+ });
147
+ it('has platform-specific mappings for Java', () => {
148
+ const mappings = (0, linuxDistro_1.getCommonPackageMappings)();
149
+ const javaMappings = mappings['openjdk-17'];
150
+ expect(javaMappings).toBeDefined();
151
+ if (javaMappings) {
152
+ expect(javaMappings.debian).toBe('openjdk-17-jdk');
153
+ expect(javaMappings.redhat).toBe('java-17-openjdk-devel');
154
+ expect(javaMappings.arch).toBe('jdk17-openjdk');
155
+ expect(javaMappings.suse).toBe('java-17-openjdk-devel');
156
+ }
157
+ });
158
+ it('has platform-specific mappings for adb', () => {
159
+ const mappings = (0, linuxDistro_1.getCommonPackageMappings)();
160
+ const adbMappings = mappings['adb'];
161
+ expect(adbMappings).toBeDefined();
162
+ if (adbMappings) {
163
+ expect(adbMappings.debian).toBe('adb');
164
+ expect(adbMappings.redhat).toBe('android-tools');
165
+ expect(adbMappings.arch).toBe('android-tools');
166
+ expect(adbMappings.suse).toBe('android-tools');
167
+ }
168
+ });
169
+ });
170
+ });
@@ -1,8 +1,68 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sanitizeProjectName = sanitizeProjectName;
4
+ exports.validateProjectName = validateProjectName;
3
5
  exports.toPascalCase = toPascalCase;
4
6
  exports.toSnakeCase = toSnakeCase;
5
7
  const wordSplitRegex = /[\W_]/;
8
+ const RESERVED_PROJECT_NAMES = new Set([
9
+ 'test',
10
+ 'tests',
11
+ 'build',
12
+ 'workspace',
13
+ 'native',
14
+ 'rule',
15
+ 'package',
16
+ 'glob',
17
+ 'select',
18
+ 'repository',
19
+ 'external',
20
+ 'bazel',
21
+ 'class',
22
+ 'function',
23
+ 'var',
24
+ 'let',
25
+ 'const',
26
+ 'if',
27
+ 'else',
28
+ 'for',
29
+ 'while',
30
+ 'return',
31
+ 'import',
32
+ 'export',
33
+ 'module',
34
+ 'require',
35
+ 'main',
36
+ 'lib',
37
+ 'src',
38
+ 'bin',
39
+ 'data',
40
+ 'config',
41
+ ]);
42
+ function sanitizeProjectName(name) {
43
+ let sanitized = name.replace(/-/g, '_');
44
+ sanitized = sanitized.replace(/[^a-zA-Z0-9_]/g, '');
45
+ if (sanitized.length > 0 && /^[0-9]/.test(sanitized)) {
46
+ sanitized = '_' + sanitized;
47
+ }
48
+ return sanitized;
49
+ }
50
+ function validateProjectName(name) {
51
+ if (!name || name.trim().length === 0) {
52
+ return 'Project name cannot be empty.';
53
+ }
54
+ const sanitized = sanitizeProjectName(name);
55
+ if (sanitized.length === 0) {
56
+ return 'Project name must contain at least one alphanumeric character.';
57
+ }
58
+ if (RESERVED_PROJECT_NAMES.has(sanitized.toLowerCase())) {
59
+ return `Project name "${name}" (sanitized to "${sanitized}") is a reserved word and cannot be used. Please choose a different name.`;
60
+ }
61
+ if (sanitized !== name.replace(/-/g, '_')) {
62
+ return `Project name "${name}" contains invalid characters. It will be sanitized to "${sanitized}". Please use only letters, numbers, underscores, and dashes.`;
63
+ }
64
+ return null;
65
+ }
6
66
  function toPascalCase(str) {
7
67
  const words = str.trim().toLowerCase().split(wordSplitRegex);
8
68
  return words.reduce((acc, curr) => {
@@ -15,4 +15,67 @@ describe('stringUtils', () => {
15
15
  expect((0, stringUtils_1.toSnakeCase)(input)).toBe(expected);
16
16
  });
17
17
  });
18
+ describe('sanitizeProjectName', () => {
19
+ it('replaces dashes with underscores', () => {
20
+ expect((0, stringUtils_1.sanitizeProjectName)('my-project')).toBe('my_project');
21
+ expect((0, stringUtils_1.sanitizeProjectName)('my-cool-app')).toBe('my_cool_app');
22
+ });
23
+ it('preserves original case', () => {
24
+ expect((0, stringUtils_1.sanitizeProjectName)('MyProject')).toBe('MyProject');
25
+ expect((0, stringUtils_1.sanitizeProjectName)('MY_PROJECT')).toBe('MY_PROJECT');
26
+ expect((0, stringUtils_1.sanitizeProjectName)('testNewModule')).toBe('testNewModule');
27
+ });
28
+ it('removes invalid characters', () => {
29
+ expect((0, stringUtils_1.sanitizeProjectName)('my project!')).toBe('myproject');
30
+ expect((0, stringUtils_1.sanitizeProjectName)('my@project#')).toBe('myproject');
31
+ expect((0, stringUtils_1.sanitizeProjectName)('my.project')).toBe('myproject');
32
+ });
33
+ it('prefixes with underscore if starts with number', () => {
34
+ expect((0, stringUtils_1.sanitizeProjectName)('123project')).toBe('_123project');
35
+ expect((0, stringUtils_1.sanitizeProjectName)('7-eleven')).toBe('_7_eleven');
36
+ });
37
+ it('handles mixed cases', () => {
38
+ expect((0, stringUtils_1.sanitizeProjectName)('My-Cool_Project123')).toBe('My_Cool_Project123');
39
+ });
40
+ it('handles already valid names', () => {
41
+ expect((0, stringUtils_1.sanitizeProjectName)('my_project')).toBe('my_project');
42
+ expect((0, stringUtils_1.sanitizeProjectName)('myproject')).toBe('myproject');
43
+ expect((0, stringUtils_1.sanitizeProjectName)('my_project_123')).toBe('my_project_123');
44
+ });
45
+ });
46
+ describe('validateProjectName', () => {
47
+ it('rejects empty names', () => {
48
+ expect((0, stringUtils_1.validateProjectName)('')).toBeTruthy();
49
+ expect((0, stringUtils_1.validateProjectName)(' ')).toBeTruthy();
50
+ });
51
+ it('rejects reserved words (case-insensitive)', () => {
52
+ expect((0, stringUtils_1.validateProjectName)('test')).toContain('reserved word');
53
+ expect((0, stringUtils_1.validateProjectName)('Test')).toContain('reserved word');
54
+ expect((0, stringUtils_1.validateProjectName)('TEST')).toContain('reserved word');
55
+ expect((0, stringUtils_1.validateProjectName)('build')).toContain('reserved word');
56
+ expect((0, stringUtils_1.validateProjectName)('workspace')).toContain('reserved word');
57
+ expect((0, stringUtils_1.validateProjectName)('native')).toContain('reserved word');
58
+ expect((0, stringUtils_1.validateProjectName)('package')).toContain('reserved word');
59
+ });
60
+ it('accepts valid names with mixed case', () => {
61
+ expect((0, stringUtils_1.validateProjectName)('my_project')).toBeNull();
62
+ expect((0, stringUtils_1.validateProjectName)('myproject')).toBeNull();
63
+ expect((0, stringUtils_1.validateProjectName)('my_cool_app')).toBeNull();
64
+ expect((0, stringUtils_1.validateProjectName)('project123')).toBeNull();
65
+ expect((0, stringUtils_1.validateProjectName)('MyProject')).toBeNull();
66
+ expect((0, stringUtils_1.validateProjectName)('testNewModule')).toBeNull();
67
+ });
68
+ it('accepts names with dashes (they will be sanitized)', () => {
69
+ expect((0, stringUtils_1.validateProjectName)('my-project')).toBeNull();
70
+ expect((0, stringUtils_1.validateProjectName)('my-cool-app')).toBeNull();
71
+ });
72
+ it('rejects names with only invalid characters', () => {
73
+ expect((0, stringUtils_1.validateProjectName)('!!!')).toBeTruthy();
74
+ expect((0, stringUtils_1.validateProjectName)('...')).toBeTruthy();
75
+ expect((0, stringUtils_1.validateProjectName)('@#$')).toBeTruthy();
76
+ });
77
+ it('handles names that start with numbers', () => {
78
+ expect((0, stringUtils_1.validateProjectName)('123project')).toBeNull();
79
+ });
80
+ });
18
81
  });
package/package.json CHANGED
@@ -1,8 +1,14 @@
1
1
  {
2
2
  "name": "@snap/valdi",
3
- "version": "1.0.1",
3
+ "version": "1.0.6",
4
4
  "description": "Valdi CLI tools for developers",
5
- "license": "ISC",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/Snapchat/Valdi.git",
9
+ "directory": "npm_modules/cli"
10
+ },
11
+ "publishConfig": { "access": "public" },
6
12
  "bin": {
7
13
  "valdi": "dist/index.js"
8
14
  },
@@ -17,7 +23,9 @@
17
23
  "eslint:fix": "npm run eslint -- --fix",
18
24
  "cli:install": "npm ci && npm link",
19
25
  "cli:uninstall": "PKG_NAME=$(npm pkg get name | tr -d '\"') && npm uninstall $PKG_NAME -g",
20
- "cli:uninstall_all": "PKG_NAME=$(npm pkg get name | tr -d '\"') && npm uninstall $PKG_NAME && npm uninstall -g $PKG_NAME"
26
+ "cli:uninstall_all": "PKG_NAME=$(npm pkg get name | tr -d '\"') && npm uninstall $PKG_NAME && npm uninstall -g $PKG_NAME",
27
+ "update-agents-templates": "ts-node scripts/update-agents-templates.ts",
28
+ "validate-agents": "bash scripts/sync-agents-md.sh"
21
29
  },
22
30
  "dependencies": {
23
31
  "@bazel/bazelisk": "^1.19.0",
@@ -0,0 +1,44 @@
1
+ #!/bin/bash
2
+ # Sync AGENTS.md content between root and bootstrap templates
3
+ # This script extracts common sections from the root AGENTS.md and updates bootstrap templates
4
+
5
+ set -e
6
+
7
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
8
+ CLI_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
9
+ OPEN_SOURCE_ROOT="$(cd "$CLI_ROOT/../.." && pwd)"
10
+
11
+ ROOT_AGENTS="$OPEN_SOURCE_ROOT/AGENTS.md"
12
+ UI_AGENTS_TEMPLATE="$CLI_ROOT/.bootstrap/apps/ui_application/AGENTS.md.template"
13
+ CLI_AGENTS_TEMPLATE="$CLI_ROOT/.bootstrap/apps/cli_application/AGENTS.md.template"
14
+
15
+ echo "Syncing AGENTS.md patterns from root to bootstrap templates..."
16
+ echo "Root AGENTS.md: $ROOT_AGENTS"
17
+ echo "UI Template: $UI_AGENTS_TEMPLATE"
18
+ echo "CLI Template: $CLI_AGENTS_TEMPLATE"
19
+
20
+ # Extract the Anti-Hallucination section from root AGENTS.md
21
+ # This ensures patterns stay consistent
22
+ ANTI_HALLUCINATION_START="## 🚨 AI Anti-Hallucination: This is NOT React!"
23
+ ANTI_HALLUCINATION_END="## Directory Structure"
24
+
25
+ # For now, just validate that the files exist
26
+ if [ ! -f "$ROOT_AGENTS" ]; then
27
+ echo "Error: Root AGENTS.md not found at $ROOT_AGENTS"
28
+ exit 1
29
+ fi
30
+
31
+ if [ ! -f "$UI_AGENTS_TEMPLATE" ]; then
32
+ echo "Error: UI AGENTS.md template not found at $UI_AGENTS_TEMPLATE"
33
+ exit 1
34
+ fi
35
+
36
+ if [ ! -f "$CLI_AGENTS_TEMPLATE" ]; then
37
+ echo "Error: CLI AGENTS.md template not found at $CLI_AGENTS_TEMPLATE"
38
+ exit 1
39
+ fi
40
+
41
+ echo "✅ All AGENTS.md files found"
42
+ echo ""
43
+ echo "Note: This script currently validates file existence."
44
+ echo "To fully implement sync, run: npm run update-agents-templates"