UNPKG

935 BJavaScriptView Raw
1///@ts-check
2'use strict';
3var gulp = require('gulp');
4var extToGlob = require('../lib/ext-to-glob');
5var unlink = require('../lib/unlink');
6var compileJson = require('../compiler/compile-json');
7var watchLog = require('../log/watch');
8
9var JSON_EXTS = ['json', 'jsonc', 'cjson', 'json5'];
10
11/**
12 * @param {object} config
13 */
14exports.build = function (config) {
15 return function () {
16 return compileJson(config, extToGlob(config, JSON_EXTS));
17 };
18}
19/**
20 * @param {object} config
21 */
22exports.watch = function (config) {
23 return function (cb) {
24 var glob = extToGlob(config, JSON_EXTS);
25 watchLog('json', glob)
26 gulp.watch(glob, {})
27 .on('change', function (file) { return compileJson(config, file); })
28 .on('add', function (file) { return compileJson(config, file); })
29 .on('unlink', unlink(config.src, config.dist, '.json'))
30 ;
31 cb && cb();
32 }
33}
\No newline at end of file