forked from hedyorg/hedy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add script for validating texts yaml, comparing it to the English ver…
…sion; add missing keys to some languages. (hedyorg#485)
- Loading branch information
Showing
10 changed files
with
114 additions
and
1,246 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"pajv": "^1.2.0" | ||
"pajv": "^1.2.0", | ||
"yaml": "1.10.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
const fs = require ('fs'); | ||
const yaml = require ('yaml'); | ||
|
||
const ajv = new (require ('ajv')); | ||
|
||
const path = require ('path').join (process.argv [2], '../coursedata/texts') + '/'; | ||
|
||
const file = fs.readFileSync(path + 'en.yaml', 'utf8'); | ||
|
||
const texts = yaml.parse (file); | ||
|
||
const properties = {}; | ||
Object.keys (texts).map (function (topKey) { | ||
const props = {}; | ||
Object.keys (texts [topKey]).map (function (subKey) { | ||
props [subKey] = {type: 'string'}; | ||
}); | ||
properties [topKey] = {type: 'object', additionalProperties: false, properties: props, required: Object.keys (props)}; | ||
}); | ||
|
||
const schema = {type: 'object', additionalProperties: false, properties: properties, required: Object.keys (properties)}; | ||
|
||
const files = fs.readdirSync(path); | ||
|
||
files.map (function (file) { | ||
if (! file.match (/.yaml$/)) return; | ||
|
||
let parsed; | ||
|
||
try { | ||
parsed = yaml.parse (fs.readFileSync (path + file, 'utf8')); | ||
} | ||
catch (error) { | ||
console.log ('Invalid yaml ' + file); | ||
process.exit (1); | ||
} | ||
if (! ajv.validate (schema, parsed)) { | ||
console.log ('Invalid file ' + file, JSON.stringify (ajv.errors)); | ||
process.exit (1); | ||
} | ||
console.log (path + file, 'OK'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters