diff --git a/README.md b/README.md index 1bc38ba..d97a83a 100644 --- a/README.md +++ b/README.md @@ -41,3 +41,7 @@ In this case, the `` is the campaign folder, which contains the deployments The command `yarn xls2csv ` can be used to convert a XLSX file to CSV. On this case, each spreadsheet in the file will be exported to CSV, directly in the `campaigns` folder. Example of XLSX file: https://docs.google.com/spreadsheets/d/17v-ZfeWoPZoCAVSs57Y3Q1gKUe6S49fZ8rC2KOO_myY/edit?usp=sharing + +### YAML Schema + +The file `campaigns-schema.yaml` describes the format used in the campaigns files. \ No newline at end of file diff --git a/campaigns-schema.yaml b/campaigns-schema.yaml new file mode 100644 index 0000000..3e9ee62 --- /dev/null +++ b/campaigns-schema.yaml @@ -0,0 +1,34 @@ +--- +deployments: + required: true + type: list + schema: + type: dict + schema: + name: + required: true + type: string + platforms: + required: true + type: list + schema: + type: dict + schema: + name: + required: true + type: string + tsv_format: + require: false + type: boolean + rename_as_ict: + require: false + type: boolean + process_as_ict: + require: false + type: boolean + coords_divisor: + require: false + type: integer + files: + required: true + type: list \ No newline at end of file diff --git a/task/package.json b/task/package.json index 70522e8..83743aa 100644 --- a/task/package.json +++ b/task/package.json @@ -21,6 +21,7 @@ "meow": "^12.1.1", "simplify-geojson": "^1.0.5", "slugify": "^1.6.6", + "superstruct": "^1.0.4", "xlsx": "^0.18.5", "xml2js": "^0.6.2", "yaml": "2.3.4" diff --git a/task/tests/validate-yaml.test.js b/task/tests/validate-yaml.test.js new file mode 100644 index 0000000..7171f4a --- /dev/null +++ b/task/tests/validate-yaml.test.js @@ -0,0 +1,38 @@ +const fs = require('fs'); +const path = require('path'); +const { + array, + assert, + boolean, + number, + object, + optional, + string, +} = require('superstruct'); +const { readCampaignYaml } = require('../src/utils'); + +const structure = array( + object({ + name: string(), + platforms: array( + object({ + name: string(), + tsv_format: optional(boolean()), + rename_as_ict: optional(boolean()), + process_as_ict: optional(boolean()), + coords_divisor: optional(number()), + files: array(string()), + }) + ), + }) +); + +test('YAML files should be valid', () => { + const campaigns = fs.readdirSync('../campaigns/'); + campaigns + .filter((c) => fs.existsSync(path.join('../campaigns/', c, 'deployments.yaml'))) + .forEach((c) => { + console.log(`Checking: ${c}`); + assert(readCampaignYaml(path.join('../campaigns/', c)), structure); + }); +}); diff --git a/task/yarn.lock b/task/yarn.lock index d3622a1..2eea81e 100644 --- a/task/yarn.lock +++ b/task/yarn.lock @@ -4165,6 +4165,11 @@ strnum@^1.0.5: resolved "https://registry.yarnpkg.com/strnum/-/strnum-1.0.5.tgz#5c4e829fe15ad4ff0d20c3db5ac97b73c9b072db" integrity sha512-J8bbNyKKXl5qYcR36TIO8W3mVGVHrmmxsd5PAItGkmyzwJvybiw2IVq5nqd0i4LSNSkB/sx9VHllbfFdr9k1JA== +superstruct@^1.0.4: + version "1.0.4" + resolved "https://registry.yarnpkg.com/superstruct/-/superstruct-1.0.4.tgz#0adb99a7578bd2f1c526220da6571b2d485d91ca" + integrity sha512-7JpaAoX2NGyoFlI9NBh66BQXGONc+uE+MRS5i2iOBKuS4e+ccgMDjATgZldkah+33DakBxDHiss9kvUcGAO8UQ== + supports-color@^5.3.0: version "5.5.0" resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-5.5.0.tgz#e2e69a44ac8772f78a1ec0b35b689df6530efc8f"