@iqb/validate-md-profile 0.1.0 → 0.2.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iqb/validate-md-profile",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "author": "IQB - Institut zur Qualitätsentwicklung im Bildungswesen",
5
5
  "license": "MIT",
6
6
  "description": "Data interfaces for metadata profiling and values",
package/src/index.ts DELETED
@@ -1 +0,0 @@
1
- export * from "./validate-md-profile";
@@ -1,74 +0,0 @@
1
- import Ajv from "ajv";
2
-
3
- const fs = require('fs');
4
- const schemaFilename = 'md-profile.schema.json';
5
- let fileToCheckName = './profile.json';
6
- let schema = null;
7
- if (process.argv[2]) {
8
- fileToCheckName = `./${process.argv[2]}`;
9
- }
10
- if (!fs.existsSync(fileToCheckName)) {
11
- console.log(`\x1b[0;31mERROR\x1b[0m profile file '${fileToCheckName}' not found`);
12
- process.exitCode = 1;
13
- } else {
14
- let schemaFullFilename = `${__dirname}/${schemaFilename}`;
15
- if (!fs.existsSync(schemaFullFilename)) {
16
- schemaFullFilename = `./json_schema/md-profile/${schemaFilename}`;
17
- }
18
- if (!fs.existsSync(schemaFullFilename)) {
19
- console.log(`\x1b[0;31mERROR\x1b[0m profile file '${schemaFilename}' not found`);
20
- process.exitCode = 1;
21
- } else {
22
- try {
23
- schema = fs.readFileSync(schemaFullFilename, 'utf8');
24
- } catch (err) {
25
- console.log(`\x1b[0;31mERROR\x1b[0m reading schema '${schemaFilename}':`);
26
- console.error(err);
27
- process.exitCode = 1;
28
- schema = null;
29
- }
30
- }
31
- }
32
-
33
- if (schema) {
34
- let compiledSchema;
35
- const ajv = new Ajv() // options can be passed, e.g. {allErrors: true}
36
- try {
37
- compiledSchema = ajv.compile(JSON.parse(schema))
38
- } catch (err) {
39
- console.log(`\x1b[0;31mERROR\x1b[0m parsing schema '${schemaFilename}':`);
40
- console.error(err);
41
- process.exitCode = 1;
42
- compiledSchema = null;
43
- }
44
- if (compiledSchema) {
45
- let profileData;
46
- try {
47
- const profile_data_raw = fs.readFileSync(fileToCheckName, 'utf8');
48
- profileData = JSON.parse(profile_data_raw);
49
- } catch (err) {
50
- console.log(`\x1b[0;31mERROR\x1b[0m reading and parsing config file '${fileToCheckName}':`);
51
- console.error(err);
52
- profileData = null;
53
- process.exitCode = 1;
54
- }
55
- if (profileData) {
56
- try {
57
- const valid = compiledSchema ? compiledSchema(profileData) : null;
58
- if (valid) {
59
- console.log(`'${fileToCheckName}' is valid`);
60
- } else {
61
- console.log(`\x1b[0;31mERROR\x1b[0m invalid profile file '${fileToCheckName}':`);
62
- console.error(compiledSchema ? compiledSchema.errors : 'error unknown')
63
- profileData = null;
64
- process.exitCode = 1;
65
- }
66
- } catch (err) {
67
- console.log(`\x1b[0;31mERROR\x1b[0m invalid profile file '${fileToCheckName}':`);
68
- console.error(err);
69
- profileData = null;
70
- process.exitCode = 1;
71
- }
72
- }
73
- }
74
- }
package/tsconfig.json DELETED
@@ -1,18 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "declaration": true,
4
- "strictNullChecks": true,
5
- "strict": true,
6
- "target": "es5",
7
- "module": "commonjs",
8
- "forceConsistentCasingInFileNames": true,
9
- "outDir": "dist",
10
- "moduleResolution": "node",
11
- "sourceMap": true,
12
- "lib": ["es2015", "dom", "es2021"],
13
- "rootDir": "src",
14
- "allowSyntheticDefaultImports": true
15
- },
16
- "include": ["src"],
17
- "exclude": ["node_modules", "dist"]
18
- }