UNPKG

1.15 kBJavaScriptView Raw
1///@ts-check
2"use strict";
3var gulp = require("gulp");
4var fs = require("fs");
5var path = require("path");
6var compileJs = require("../compiler/compile-javascript");
7var unlink = require("../lib/unlink");
8var extToGlob = require("../lib/ext-to-glob");
9var watchLog = require("../log/watch");
10
11// var JS_EXTS = ["js", "wxs"];
12/**
13 * @param {object} config
14 * @param {string[]} JS_EXTS
15 */
16exports.build = function (config, JS_EXTS) {
17 return function () {
18 return compileJs(config, extToGlob(config, JS_EXTS));
19 };
20};
21
22
23/**
24 * @param {object} config
25 * @param {string[]} JS_EXTS
26 */
27exports.watch = function (config, JS_EXTS) {
28 return function (cb) {
29 var glob = extToGlob(config, JS_EXTS);
30 watchLog("javascript-" + JS_EXTS.join('-'), glob);
31 gulp.watch(glob)
32 .on("change", function (file) {
33 return compileJs(config, file);
34 })
35 .on("add", function (file) {
36 return compileJs(config, file);
37 })
38 .on("unlink", unlink(config.src, config.dist, ".js"));
39 cb && cb();
40 };
41};