opentwig 1.0.5 → 1.1.0

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.
@@ -0,0 +1,59 @@
1
+ const fs = require('fs');
2
+ const CONSTANTS = require('./src/constants');
3
+
4
+ function validateConfig(config) {
5
+ const errors = [];
6
+
7
+ // Required fields
8
+ CONSTANTS.REQUIRED_FIELDS.forEach(field => {
9
+ if (!config[field] || typeof config[field] !== 'string') {
10
+ errors.push(`The "${field}" field is required and must be a string.`);
11
+ }
12
+ });
13
+
14
+ // Optional fields
15
+ if (config.theme && !CONSTANTS.SUPPORTED_THEMES.includes(config.theme)) {
16
+ errors.push(
17
+ `Invalid theme "${config.theme}". Supported themes: ${CONSTANTS.SUPPORTED_THEMES.join(', ')}.`
18
+ );
19
+ }
20
+
21
+ if (config.links && !Array.isArray(config.links)) {
22
+ errors.push('The "links" field must be an array if provided.');
23
+ }
24
+
25
+ if (config.footerLinks && !Array.isArray(config.footerLinks)) {
26
+ errors.push('The "footerLinks" field must be an array if provided.');
27
+ }
28
+
29
+ if (config.share && typeof config.share !== 'object') {
30
+ errors.push('The "share" field must be an object if provided.');
31
+ }
32
+
33
+ return errors;
34
+ }
35
+
36
+ function main() {
37
+ try {
38
+ const raw = fs.readFileSync(CONSTANTS.CONFIG_FILE, 'utf-8');
39
+ const config = JSON.parse(raw);
40
+ const errors = validateConfig(config);
41
+
42
+ if (errors.length > 0) {
43
+ console.error(`${CONSTANTS.MESSAGES.ERROR_PREFIX} Validation errors in config.json:`);
44
+ errors.forEach(e => console.error('- ' + e));
45
+ process.exit(1);
46
+ } else {
47
+ console.log(`${CONSTANTS.MESSAGES.SUCCESS_PREFIX} config.json is valid!`);
48
+ }
49
+ } catch (err) {
50
+ console.error(`${CONSTANTS.MESSAGES.ERROR_PREFIX} Failed to read or validate config.json:`, err.message);
51
+ process.exit(1);
52
+ }
53
+ }
54
+
55
+ if (require.main === module) {
56
+ main();
57
+ }
58
+
59
+ module.exports = main;
@@ -0,0 +1,11 @@
1
+ module.exports = {
2
+ test: {
3
+ environment: 'node',
4
+ include: ['**/*.test.js'],
5
+ coverage: {
6
+ provider: 'v8',
7
+ reporter: ['text', 'json'],
8
+ exclude: ['node_modules/', 'dist/', '**/*.test.js', 'test-og.js']
9
+ }
10
+ }
11
+ };