Skip to content

Commit 9f80241

Browse files
committed
Merge pull request #90 from maxlinc/converters
Tasks to lint or convert YAML/JSON samples
2 parents 9d98629 + d023292 commit 9f80241

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

.travis.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ language: scala
22
scala:
33
- 2.10.4
44
script:
5-
- sbt ++$TRAVIS_SCALA_VERSION test
65
- npm install
6+
- gulp lint
7+
- sbt ++$TRAVIS_SCALA_VERSION test
78
- mocha
89
env:
910
- VALIDATORS=tv4

gulpfile.js

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
var gulp = require('gulp');
2+
3+
var jsonlint = require("gulp-jsonlint");
4+
var gulpyaml = require('gulp-yaml');
5+
var ext_replace = require('gulp-ext-replace');
6+
var map = require('map-stream');
7+
var YAML = require('json2yaml');
8+
var gutil = require('gulp-util');
9+
10+
var exitCode = 0;
11+
12+
var json_paths = {
13+
examples: 'examples/**/*.json',
14+
models: 'samples/v2.0/json/models/**/*.json',
15+
resources: 'samples/v2.0/json/resources/**/*.json',
16+
responses: 'samples/v2.0/json/responses/**/*.json'
17+
// What are the other files in samples/v2.0/json/*.json
18+
};
19+
20+
gulp.task('lint', function() {
21+
return gulp.src(['./**/*.json', '!./node_modules/**/*.json'])
22+
.pipe(jsonlint())
23+
.pipe(jsonlint.reporter());
24+
25+
// YAML linting/formatting?
26+
});
27+
28+
gulp.task('yaml2json', function(){
29+
gulp.src('./samples/v2.0/yaml/**.yaml')
30+
.pipe(gulpyaml({ pretty: true }))
31+
.pipe(gulp.dest('./samples/v2.0/json'));
32+
33+
gulp.src(json_paths.examples)
34+
.pipe(gulpyaml({ pretty: true }))
35+
.pipe(gulp.dest('examples/'));
36+
});
37+
38+
gulp.task('json2yaml', function(){
39+
return gulp.src('./samples/v2.0/json/**/*.json')
40+
.pipe(map(function(file, cb) {
41+
data = JSON.parse(file.contents);
42+
file.contents = new Buffer(String(YAML.stringify(data)));
43+
cb(null, file);
44+
}))
45+
.pipe(ext_replace('.yaml'))
46+
.pipe(gulp.dest('samples/v2.0/yaml'));
47+
});
48+

0 commit comments

Comments
 (0)