Skip to content

Commit 7ab1c6f

Browse files
author
Mark Matyas
committed
First attempt at travis ci curation validation
Signed-off-by: Mark Matyas <[email protected]>
1 parent 0646492 commit 7ab1c6f

File tree

6 files changed

+189
-0
lines changed

6 files changed

+189
-0
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
npm-debug.log*
2+
node_modules/
3+
.prettierrc

.travis.yml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
language: node_js
2+
# node version specified in .nvmrc
3+
4+
cache:
5+
directories:
6+
- "node_modules"
7+
8+
script: npm run-script build
File renamed without changes.

package-lock.json

+112
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "curated-data",
3+
"version": "0.0.0",
4+
"description": "This repository contains curation patches for clearlydefined.io.",
5+
"repository": {
6+
"type": "git",
7+
"url": "git+https://github.com/clearlydefined/curated-data.git"
8+
},
9+
"license": "MIT",
10+
"scripts": {
11+
"build": "node scripts/build.js"
12+
},
13+
"dependencies": {
14+
"glob": "^7.1.2",
15+
"js-yaml": "^3.10.0"
16+
}
17+
}

scripts/build.js

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright (c) 2017, The Linux Foundation. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
const glob = require('glob');
5+
const yaml = require('js-yaml');
6+
const fs = require('fs');
7+
const {log} = require('console');
8+
const ERROR = 1;
9+
const isCLI = require.main === module;
10+
11+
// @todo only load new/changed yaml - use git diff
12+
function getYamlFilePaths() {
13+
return glob.sync('{**/*.yaml,**/*.yml}');
14+
}
15+
16+
function failure(error = 'Error') {
17+
log(`${error}`);
18+
process.exitCode = ERROR;
19+
return ERROR;
20+
}
21+
22+
function loadYamlFile(path) {
23+
try {
24+
let data = yaml.safeLoad(fs.readFileSync(path, 'utf8'));
25+
return {data, path};
26+
} catch (error) {
27+
return failure(`> Invalid yaml file: ${path}\n`);
28+
}
29+
}
30+
31+
function logYamlDoc({data, path}) {
32+
log(path);
33+
log(data);
34+
}
35+
36+
function run() {
37+
let paths = getYamlFilePaths();
38+
if (!paths.length) {
39+
return failure('> 0 yaml files');
40+
}
41+
42+
let docs = paths.map(loadYamlFile).filter(x => x !== ERROR);
43+
log('> Valid yaml file(s):\n');
44+
docs.forEach(logYamlDoc);
45+
}
46+
47+
if (isCLI) {
48+
run();
49+
}

0 commit comments

Comments
 (0)