@rbleattler/omp-ts-typegen 0.2025.1 → 0.2025.68

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.
@@ -1,88 +1,88 @@
1
- /**
2
- * Note: This is a simplified validator that checks if the JSON is
3
- * compatible with the TypeScript interfaces. For a full check,
4
- * we would need to compile the TypeScript and use the runtime types.
5
- */
6
-
7
- import fs from 'fs/promises';
8
- import path from 'path';
9
- import { exec } from 'child_process';
10
- import { promisify } from 'util';
11
-
12
- const execAsync = promisify(exec);
13
-
14
- const TEMP_DIR = path.join(process.cwd(), 'temp');
15
-
16
- /**
17
- * Validates a JSON config against the TypeScript interface
18
- * @param config The configuration object to validate
19
- * @param themeName Optional theme name to use as part of the test file name
20
- * @returns Validation result with valid status and any errors
21
- */
22
- export async function validate(config: any, themeName?: string): Promise<{ valid: boolean; errors?: string[] }> {
23
- const { default: chalk } = await import('chalk');
24
-
25
- // Create a unique filename based on the theme name or a timestamp
26
- const safeThemeName = themeName ?
27
- themeName.replace(/[^\w.-]/g, '_') :
28
- `config_${Date.now()}`;
29
-
30
- const testFilePath = path.join(TEMP_DIR, `${safeThemeName}.test.ts`);
31
-
32
- try {
33
- // Create temp directory if it doesn't exist
34
- await fs.mkdir(TEMP_DIR, { recursive: true });
35
-
36
- // Create a temporary TypeScript file that imports the types and validates the config
37
- const testContent = `
38
- // This is a generated test file for ${themeName || 'unknown theme'}
39
- import { OhMyPosh } from '../src/types/omp';
40
-
41
- // The config to validate
42
- const config: OhMyPosh = ${JSON.stringify(config, null, 2)};
43
-
44
- // If TypeScript compiles this, it means the config is valid
45
- console.log('Config is valid!');
46
- `;
47
-
48
- // Save the test file
49
- await fs.writeFile(testFilePath, testContent);
50
-
51
- try {
52
- // Run tsc with verbose error output and report all errors
53
- const { stdout, stderr } = await execAsync(`npx tsc --noEmit --pretty ${testFilePath}`);
54
-
55
- // If we get here and stderr is empty, compilation succeeded
56
- if (!stderr.trim()) {
57
- return { valid: true };
58
- } else {
59
- return {
60
- valid: false,
61
- errors: [
62
- `TypeScript validation failed for ${themeName || 'config'}:`,
63
- stderr
64
- ]
65
- };
66
- }
67
- } catch (execError: any) {
68
- // TypeScript compilation failed - get the full error details
69
- return {
70
- valid: false,
71
- errors: [
72
- `TypeScript validation failed for ${themeName || 'config'}:`,
73
- execError.stderr || execError.message || 'Unknown error'
74
- ]
75
- };
76
- } finally {
77
- // Clean up the test file
78
- try {
79
- await fs.unlink(testFilePath).catch(() => {});
80
- } catch (error) {
81
- // Ignore errors during cleanup
82
- }
83
- }
84
- } catch (error: any) {
85
- // Other errors (file system, etc.)
86
- return { valid: false, errors: [`Error during validation: ${error.message}`] };
87
- }
88
- }
1
+ /**
2
+ * Note: This is a simplified validator that checks if the JSON is
3
+ * compatible with the TypeScript interfaces. For a full check,
4
+ * we would need to compile the TypeScript and use the runtime types.
5
+ */
6
+
7
+ import fs from 'fs/promises';
8
+ import path from 'path';
9
+ import { exec } from 'child_process';
10
+ import { promisify } from 'util';
11
+
12
+ const execAsync = promisify(exec);
13
+
14
+ const TEMP_DIR = path.join(process.cwd(), 'temp');
15
+
16
+ /**
17
+ * Validates a JSON config against the TypeScript interface
18
+ * @param config The configuration object to validate
19
+ * @param themeName Optional theme name to use as part of the test file name
20
+ * @returns Validation result with valid status and any errors
21
+ */
22
+ export async function validate(config: any, themeName?: string): Promise<{ valid: boolean; errors?: string[] }> {
23
+ const { default: chalk } = await import('chalk');
24
+
25
+ // Create a unique filename based on the theme name or a timestamp
26
+ const safeThemeName = themeName ?
27
+ themeName.replace(/[^\w.-]/g, '_') :
28
+ `config_${Date.now()}`;
29
+
30
+ const testFilePath = path.join(TEMP_DIR, `${safeThemeName}.test.ts`);
31
+
32
+ try {
33
+ // Create temp directory if it doesn't exist
34
+ await fs.mkdir(TEMP_DIR, { recursive: true });
35
+
36
+ // Create a temporary TypeScript file that imports the types and validates the config
37
+ const testContent = `
38
+ // This is a generated test file for ${themeName || 'unknown theme'}
39
+ import { OhMyPosh } from '../src/types/omp';
40
+
41
+ // The config to validate
42
+ const config: OhMyPosh = ${JSON.stringify(config, null, 2)};
43
+
44
+ // If TypeScript compiles this, it means the config is valid
45
+ console.log('Config is valid!');
46
+ `;
47
+
48
+ // Save the test file
49
+ await fs.writeFile(testFilePath, testContent);
50
+
51
+ try {
52
+ // Run tsc with verbose error output and report all errors
53
+ const { stdout, stderr } = await execAsync(`npx tsc --noEmit --pretty ${testFilePath}`);
54
+
55
+ // If we get here and stderr is empty, compilation succeeded
56
+ if (!stderr.trim()) {
57
+ return { valid: true };
58
+ } else {
59
+ return {
60
+ valid: false,
61
+ errors: [
62
+ `TypeScript validation failed for ${themeName || 'config'}:`,
63
+ stderr
64
+ ]
65
+ };
66
+ }
67
+ } catch (execError: any) {
68
+ // TypeScript compilation failed - get the full error details
69
+ return {
70
+ valid: false,
71
+ errors: [
72
+ `TypeScript validation failed for ${themeName || 'config'}:`,
73
+ execError.stderr || execError.message || 'Unknown error'
74
+ ]
75
+ };
76
+ } finally {
77
+ // Clean up the test file
78
+ try {
79
+ await fs.unlink(testFilePath).catch(() => {});
80
+ } catch (error) {
81
+ // Ignore errors during cleanup
82
+ }
83
+ }
84
+ } catch (error: any) {
85
+ // Other errors (file system, etc.)
86
+ return { valid: false, errors: [`Error during validation: ${error.message}`] };
87
+ }
88
+ }
package/src/index.ts CHANGED
@@ -1 +1 @@
1
- export * from './types/omp';
1
+ export * from './types/omp';