@gefyra/diffyr6-cli 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/config.js CHANGED
@@ -1,147 +1,147 @@
1
- import fsp from 'fs/promises';
2
- import path from 'path';
3
- import { fileURLToPath } from 'url';
4
- import { pathExists } from './utils/fs.js';
5
-
6
- const __filename = fileURLToPath(import.meta.url);
7
- const __dirname = path.dirname(__filename);
8
-
9
- export const CONFIG_VERSION = '1.0.0';
10
-
11
- /**
12
- * Default configuration values
13
- */
14
- export const DEFAULT_CONFIG = {
15
- configVersion: CONFIG_VERSION,
16
- packageId: null,
17
- packageVersion: 'current',
18
- enableGoFSH: true,
19
- resourcesDir: 'Resources',
20
- resourcesR6Dir: 'ResourcesR6',
21
- compareDir: 'compare',
22
- outputDir: 'output',
23
- rulesConfigPath: null,
24
- validatorJarPath: null,
25
- workdir: null,
26
- compareMode: 'incremental',
27
- };
28
-
29
- /**
30
- * Loads and validates a configuration file
31
- */
32
- export async function loadConfig(configPath) {
33
- const raw = await fsp.readFile(configPath, 'utf8');
34
- const config = JSON.parse(raw);
35
-
36
- // Validate config version
37
- validateConfigVersion(config);
38
-
39
- // Merge with defaults
40
- const merged = { ...DEFAULT_CONFIG, ...config };
41
-
42
- // Validate required fields
43
- validateConfig(merged);
44
-
45
- return merged;
46
- }
47
-
48
- /**
49
- * Validates the configuration version
50
- */
51
- function validateConfigVersion(config) {
52
- if (!config.configVersion) {
53
- throw new Error(
54
- `Missing 'configVersion' field in config. Expected version: ${CONFIG_VERSION}`
55
- );
56
- }
57
-
58
- const [major, minor] = config.configVersion.split('.').map(Number);
59
- const [expectedMajor] = CONFIG_VERSION.split('.').map(Number);
60
-
61
- if (major !== expectedMajor) {
62
- throw new Error(
63
- `Incompatible config version: ${config.configVersion}. Expected major version: ${expectedMajor}`
64
- );
65
- }
66
- }
67
-
68
- /**
69
- * Validates the configuration object
70
- */
71
- function validateConfig(config) {
72
- const errors = [];
73
-
74
- if (!config.packageId && config.enableGoFSH) {
75
- errors.push('packageId is required when enableGoFSH is true');
76
- }
77
-
78
- if (!config.resourcesDir) {
79
- errors.push('resourcesDir is required');
80
- }
81
-
82
- if (!config.resourcesR6Dir) {
83
- errors.push('resourcesR6Dir is required');
84
- }
85
-
86
- if (!config.compareDir) {
87
- errors.push('compareDir is required');
88
- }
89
-
90
- if (!config.outputDir) {
91
- errors.push('outputDir is required');
92
- }
93
-
94
- if (config.compareMode && !['incremental', 'full'].includes(config.compareMode)) {
95
- errors.push('compareMode must be either "incremental" or "full"');
96
- }
97
-
98
- if (errors.length > 0) {
99
- throw new Error(`Invalid configuration:\n${errors.map(e => ` - ${e}`).join('\n')}`);
100
- }
101
- }
102
-
103
- /**
104
- * Creates an example configuration file
105
- */
106
- export async function createExampleConfig(outputPath) {
107
- const example = {
108
- configVersion: CONFIG_VERSION,
109
- packageId: 'de.basisprofil.r4#1.5.0',
110
- packageVersion: '1.5.0',
111
- enableGoFSH: true,
112
- resourcesDir: 'Resources',
113
- resourcesR6Dir: 'ResourcesR6',
114
- compareDir: 'compare',
115
- outputDir: 'output',
116
- rulesConfigPath: null,
117
- validatorJarPath: null,
118
- workdir: null,
119
- compareMode: 'incremental'
120
- };
121
-
122
- await fsp.writeFile(
123
- outputPath,
124
- JSON.stringify(example, null, 2),
125
- 'utf8'
126
- );
127
- }
128
-
129
- /**
130
- * Loads the default rules configuration
131
- */
132
- export async function loadDefaultRules() {
133
- const rulesPath = path.join(__dirname, '..', 'config', 'default-rules.json');
134
- const raw = await fsp.readFile(rulesPath, 'utf8');
135
- return JSON.parse(raw);
136
- }
137
-
138
- /**
139
- * Loads rules from a custom path or falls back to default
140
- */
141
- export async function loadRules(customPath) {
142
- if (customPath && await pathExists(customPath)) {
143
- const raw = await fsp.readFile(customPath, 'utf8');
144
- return JSON.parse(raw);
145
- }
146
- return loadDefaultRules();
147
- }
1
+ import fsp from 'fs/promises';
2
+ import path from 'path';
3
+ import { fileURLToPath } from 'url';
4
+ import { pathExists } from './utils/fs.js';
5
+
6
+ const __filename = fileURLToPath(import.meta.url);
7
+ const __dirname = path.dirname(__filename);
8
+
9
+ export const CONFIG_VERSION = '1.0.0';
10
+
11
+ /**
12
+ * Default configuration values
13
+ */
14
+ export const DEFAULT_CONFIG = {
15
+ configVersion: CONFIG_VERSION,
16
+ packageId: null,
17
+ packageVersion: 'current',
18
+ enableGoFSH: true,
19
+ resourcesDir: 'Resources',
20
+ resourcesR6Dir: 'ResourcesR6',
21
+ compareDir: 'compare',
22
+ outputDir: 'output',
23
+ rulesConfigPath: null,
24
+ validatorJarPath: null,
25
+ workdir: null,
26
+ compareMode: 'incremental',
27
+ };
28
+
29
+ /**
30
+ * Loads and validates a configuration file
31
+ */
32
+ export async function loadConfig(configPath) {
33
+ const raw = await fsp.readFile(configPath, 'utf8');
34
+ const config = JSON.parse(raw);
35
+
36
+ // Validate config version
37
+ validateConfigVersion(config);
38
+
39
+ // Merge with defaults
40
+ const merged = { ...DEFAULT_CONFIG, ...config };
41
+
42
+ // Validate required fields
43
+ validateConfig(merged);
44
+
45
+ return merged;
46
+ }
47
+
48
+ /**
49
+ * Validates the configuration version
50
+ */
51
+ function validateConfigVersion(config) {
52
+ if (!config.configVersion) {
53
+ throw new Error(
54
+ `Missing 'configVersion' field in config. Expected version: ${CONFIG_VERSION}`
55
+ );
56
+ }
57
+
58
+ const [major, minor] = config.configVersion.split('.').map(Number);
59
+ const [expectedMajor] = CONFIG_VERSION.split('.').map(Number);
60
+
61
+ if (major !== expectedMajor) {
62
+ throw new Error(
63
+ `Incompatible config version: ${config.configVersion}. Expected major version: ${expectedMajor}`
64
+ );
65
+ }
66
+ }
67
+
68
+ /**
69
+ * Validates the configuration object
70
+ */
71
+ function validateConfig(config) {
72
+ const errors = [];
73
+
74
+ if (!config.packageId && config.enableGoFSH) {
75
+ errors.push('packageId is required when enableGoFSH is true');
76
+ }
77
+
78
+ if (!config.resourcesDir) {
79
+ errors.push('resourcesDir is required');
80
+ }
81
+
82
+ if (!config.resourcesR6Dir) {
83
+ errors.push('resourcesR6Dir is required');
84
+ }
85
+
86
+ if (!config.compareDir) {
87
+ errors.push('compareDir is required');
88
+ }
89
+
90
+ if (!config.outputDir) {
91
+ errors.push('outputDir is required');
92
+ }
93
+
94
+ if (config.compareMode && !['incremental', 'full'].includes(config.compareMode)) {
95
+ errors.push('compareMode must be either "incremental" or "full"');
96
+ }
97
+
98
+ if (errors.length > 0) {
99
+ throw new Error(`Invalid configuration:\n${errors.map(e => ` - ${e}`).join('\n')}`);
100
+ }
101
+ }
102
+
103
+ /**
104
+ * Creates an example configuration file
105
+ */
106
+ export async function createExampleConfig(outputPath) {
107
+ const example = {
108
+ configVersion: CONFIG_VERSION,
109
+ packageId: 'de.basisprofil.r4#1.5.0',
110
+ packageVersion: '1.5.0',
111
+ enableGoFSH: true,
112
+ resourcesDir: 'Resources',
113
+ resourcesR6Dir: 'ResourcesR6',
114
+ compareDir: 'compare',
115
+ outputDir: 'output',
116
+ rulesConfigPath: null,
117
+ validatorJarPath: null,
118
+ workdir: null,
119
+ compareMode: 'incremental'
120
+ };
121
+
122
+ await fsp.writeFile(
123
+ outputPath,
124
+ JSON.stringify(example, null, 2),
125
+ 'utf8'
126
+ );
127
+ }
128
+
129
+ /**
130
+ * Loads the default rules configuration
131
+ */
132
+ export async function loadDefaultRules() {
133
+ const rulesPath = path.join(__dirname, '..', 'config', 'default-rules.json');
134
+ const raw = await fsp.readFile(rulesPath, 'utf8');
135
+ return JSON.parse(raw);
136
+ }
137
+
138
+ /**
139
+ * Loads rules from a custom path or falls back to default
140
+ */
141
+ export async function loadRules(customPath) {
142
+ if (customPath && await pathExists(customPath)) {
143
+ const raw = await fsp.readFile(customPath, 'utf8');
144
+ return JSON.parse(raw);
145
+ }
146
+ return loadDefaultRules();
147
+ }