Skip to content

Commit 79d3461

Browse files
committed
Allow reading from folders
1 parent 797eab4 commit 79d3461

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Simple proof-of-concept to validate STAC Items, Catalogs, Collections and core extensions with node.
44

5-
Version: 0.1.0 - supports STAC 1.0.0-beta.1
5+
Version: 0.2.0 - supports STAC 1.0.0-beta.1
66

77
## Setup
88

@@ -13,6 +13,7 @@ Version: 0.1.0 - supports STAC 1.0.0-beta.1
1313

1414
- Validate a single file: `stac-node-validator /path/to/your/file.json`
1515
- Validate multiple files: `stac-node-validator /path/to/your/catalog.json /path/to/your/item.json`
16+
- Validate a single folder (considers all `json` files in `examples` folders): `stac-node-validator ./stac-spec`
1617
- Validate all examples in the STAC spec repo (only present if installed from GitHub): `stac-node-validator`
1718

1819
### Development

index.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@ async function run() {
1515
let files = process.argv.slice(2);
1616
if (files.length === 0) {
1717
console.log('No file specified, validating all examples in STAC spec repository');
18-
files = await readExamples();
18+
files = await readExamples('./stac-spec/');
19+
}
20+
else if (files.length === 1) {
21+
let stat = await fs.lstat(files[0]);
22+
if (stat.isDirectory()) {
23+
files = await readExamples(files[0]);
24+
}
1925
}
2026

2127
let stats = {
@@ -77,10 +83,10 @@ async function run() {
7783
}
7884
}
7985

80-
async function readExamples() {
86+
async function readExamples(folder) {
8187
var files = [];
82-
for await (let file of klaw('./stac-spec/')) {
83-
let relPath = path.relative('./stac-spec/', file.path);
88+
for await (let file of klaw(folder)) {
89+
let relPath = path.relative(folder, file.path);
8490
if (relPath.includes(path.sep + 'examples' + path.sep) && path.extname(relPath) === '.json') {
8591
files.push(file.path);
8692
}
@@ -96,10 +102,10 @@ async function loadSchema(name) {
96102
let file;
97103
switch(name) {
98104
case 'core':
99-
file = './core.json';
105+
file = path.join(__dirname, './core.json');
100106
break;
101107
default:
102-
file = './stac-spec/extensions/' + name + '/json-schema/schema.json';
108+
file = path.join(__dirname, './stac-spec/extensions/' + name + '/json-schema/schema.json');
103109
}
104110
if (!await fs.exists(file)) {
105111
throw "No schema file for " + name;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "stac-node-validator",
3-
"version": "0.1.0",
3+
"version": "0.2.0",
44
"description": "STAC Validator for NodeJS",
55
"author": "Matthias Mohr",
66
"license": "Apache-2.0",

0 commit comments

Comments
 (0)