|
| 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