Gulp, после ошибки не компилирует LESS
Мне достался проект, вношу некоторые изменения в дизайн и верстку. Заметил, что после ошибки в LESS (если допускаю), то gulp перестает компилировать less, приходиться перезапускать весь проект заново npm start
Ковырялся, но так и не смог понять , помогите исправить БАГ, чтобы после исправлени ошибки в LESS компилировался
Вот GULP файл
var gulp = require("gulp"),
shell = require("gulp-shell"),
nodemon = require("gulp-nodemon"),
watch = require("gulp-watch"),
path = require("path"),
fs = require("fs"),
mongoose = require("mongoose"),
config = require("./config"),
core = require("./libraries/core"),
fs = require("fs"),
async = require("./shared/js/async"),
mkdirp = require("mkdirp"),
gulpif = require("gulp-if"),
uglify = require("gulp-uglify-es").default,
babel = require("gulp-babel"),
minifyCss = require("gulp-minify-css"),
htmlmin = require("gulp-htmlmin"),
less = require("gulp-less"),
plumber = require("gulp-plumber"),
useref = require("gulp-useref");
var uis = fs.readdirSync(config.uisPath);
gulp.task(
"build-ngpack",
shell.task(
uis.map(function(ui) {
var result =
"cd " +
path.join(config.uisPath, ui).split("\\").join("\\\\") +
" && ngpack build";
return result;
})
)
);
gulp.task("watch-ngpack", ["build-ngpack"], function() {
uis.forEach(function(ui) {
var uiPath = path.join(config.uisPath, ui),
moduleJSFilesPath = path.join(
uiPath,
config.publicPath,
"modules",
"./**/*.js"
),
ngpackConfigPath = path.join(uiPath, "ngpack.json");
watch([moduleJSFilesPath, ngpackConfigPath], function() {
gulp.start("build-ngpack");
});
});
});
gulp.task("move-ngpack-html", function() {
uis.forEach(function(ui) {
var uiPath = path.join(config.uisPath, ui),
moduleHTMLBasePath = path.join(uiPath, config.publicPath, "modules");
moduleHTMLFilesPath = path.join(moduleHTMLBasePath, "./**/*.html");
gulp
.src(moduleHTMLFilesPath, {
base: path.join(uiPath, config.publicPath),
})
.pipe(gulp.dest(path.join(config.uisPath, ui, config.buildPath)));
});
});
gulp.task("move-shared", function() {
var s = gulp.src("./shared/**", {
base: "./shared",
});
uis.forEach(function(ui) {
s.pipe(
gulp.dest(
path.join(config.uisPath, ui, config.publicPath, "shared_components")
)
);
});
});
gulp.task("watch-shared", ["move-shared"], function() {
watch(["./shared/**/*.js"], function() {
gulp.start("move-shared");
});
});
gulp.task("move-bootstrap-fonts", ["install-bower-packages"], function() {
uis.forEach(function(ui) {
return gulp
.src(
path.join(
config.uisPath,
ui,
config.publicPath,
"bower_components/bootstrap/fonts/**"
)
)
.pipe(
gulp.dest(
path.join(
config.uisPath,
ui,
config.buildPath,
"css/bootstrap",
"fonts"
)
)
);
});
uis.forEach(function(ui) {
return gulp
.src(
path.join(
config.uisPath,
ui,
config.publicPath,
"bower_components/bootstrap/fonts/**"
)
)
.pipe(
gulp.dest(path.join(config.uisPath, ui, config.buildPath, "fonts"))
);
});
});
gulp.task("move-cheditor", function() {
uis.forEach(function(ui) {
return gulp
.src(
path.join(
config.uisPath,
ui,
config.publicPath,
"libs_components/ckeditor/**"
)
)
.pipe(
gulp.dest(
path.join(
config.uisPath,
ui,
config.buildPath,
"libs_components/",
"ckeditor"
)
)
);
});
});
gulp.task("move-fonts", ["move-bootstrap-fonts"], function() {
console.log("Fonts Movied");
});
gulp.task("watch-less", ["move-fonts"], function() {
watch(["./less/**/*.less"], function() {
gulp.start("build-less-guest");
gulp.start("build-less-admin");
});
});
gulp.task("build-less", ["move-fonts"], function() {
gulp.start("build-less-guest");
gulp.start("build-less-admin");
});
gulp.task("write-api", function(callback) {
core.createModels();
var routesAsJSON = JSON.stringify(core.getRoutes());
async.each(
uis,
function(ui, cb) {
var publicAbsPath = path.join(config.uisPath, ui, config.publicPath);
mkdirp(publicAbsPath, function(err) {
if (err) {
cb(err);
} else {
fs.writeFile(path.join(publicAbsPath, "api.json"), routesAsJSON, cb);
}
});
},
callback
);
});
gulp.task("watch-api", ["write-api"], function() {
gulp.watch(["./routes/*.js"], ["write-api"]);
});
gulp.task("build-less-guest", ["install-bower-packages"], function() {
return gulp
.src("./less/guest/**/*.less")
.pipe(plumber())
.pipe(less())
.pipe(gulp.dest(path.join(config.uisPath + "/guest/public", "css")));
});
gulp.task("build-less-admin", ["install-bower-packages"], function() {
return gulp
.src("./less/admin/**/*.less")
.pipe(plumber())
.pipe(less())
.pipe(gulp.dest(path.join(config.uisPath + "/admin/public", "css")));
});
gulp.task("start-dev", function() {
return nodemon({
script: "server.js",
ext: "js",
ignore: ["node_modules/*", "uis/*"],
env: {
NODE_ENV: "development",
},
});
});
gulp.task("start-pro", function() {
return nodemon({
script: "server.js",
ext: "js",
ignore: ["node_modules/*", "uis/*"],
env: {
NODE_ENV: "production",
},
});
});
gulp.task(
"install-bower-packages",
shell.task(
uis.map(function(ui) {
var result =
"cd " +
path.join(config.uisPath, ui, "public").split("\\").join("\\\\") +
" && bower install --allow-root";
return result;
})
)
);
gulp.task("bower", ["install-bower-packages"], function() {
console.log("Success Bower");
});
gulp.task(
"start", [
"install-bower-packages",
"watch-ngpack",
"watch-shared",
"watch-api",
"build-less",
"watch-less",
"start-dev",
],
function() {
console.log("Success Start");
}
);
gulp.task(
"watch", [
"install-bower-packages",
"watch-ngpack",
"watch-shared",
"watch-api",
"build-less",
],
function() {
console.log("Success Watch");
}
);
gulp.task("database-drop", function(callback) {
mongoose.connect(config.mongoUrl);
mongoose.connection.on("open", function() {
mongoose.connection.db.dropDatabase(function(err) {
if (err) {
callback(err);
} else {
mongoose.connection.close(callback);
}
});
});
});
gulp.task("populate-users", function() {
return gulp.src("").pipe(shell(["node ./populations/populate-users"]));
});
gulp.task(
"drop-and-populate", ["database-drop", "populate-users"],
function() {}
);
// build
gulp.task(
"build-html-assets", ["install-bower-packages", "build-ngpack", "move-shared"],
function() {
uis.forEach(function(ui) {
var assets = useref.assets();
return gulp
.src(path.join(config.uisPath, ui, config.publicPath, "index.html"))
.pipe(assets)
.pipe(gulpif("*.js", uglify()))
.on("error", function(err) {
console.log(err);
})
.pipe(
gulpif(
"*.css",
minifyCss({
keepSpecialComments: 0,
})
)
)
.pipe(assets.restore())
.pipe(useref())
.pipe(gulp.dest(path.join(config.uisPath, ui, config.buildPath)));
});
setTimeout(function() {
console.log("Please wait...");
uis.forEach(function(ui) {
return gulp
.src(path.join(config.uisPath, ui, config.buildPath, "index.html"))
.pipe(
htmlmin({
collapseWhitespace: true,
removeComments: true,
minifyCSS: true,
collapseInlineTagWhitespace: true,
collapseBooleanAttributes: true,
minifyJS: {
mangle: false,
},
})
)
.on("error", function(err) {
console.log(err);
})
.pipe(gulp.dest(path.join(config.uisPath, ui, config.buildPath)));
});
}, 10000);
setTimeout(function() {
console.log("Copleted...");
uis.forEach(function(ui) {
if (ui === "guest") {
return gulp
.src(
path.join(
config.uisPath,
ui,
config.buildPath,
"modules/**/*.html"
)
)
.pipe(
htmlmin({
collapseWhitespace: true,
removeComments: true,
minifyCSS: true,
minifyJS: {
mangle: false,
},
})
)
.pipe(
gulp.dest(
path.join(config.uisPath, ui, config.buildPath, "modules")
)
);
}
});
}, 20000);
}
);
gulp.task("move-custom-fonts", function() {
uis.forEach(function(ui) {
return gulp
.src(path.join(config.uisPath, ui, config.publicPath, "fonts/**"))
.pipe(gulp.dest(path.join(config.uisPath, ui, config.buildPath, "css")));
});
uis.forEach(function(ui) {
return gulp
.src(path.join(config.uisPath, ui, config.publicPath, "fonts/**"))
.pipe(
gulp.dest(path.join(config.uisPath, ui, config.buildPath, "fonts"))
);
});
uis.forEach(function(ui) {
return gulp
.src(
path.join(
config.uisPath,
ui,
config.publicPath,
"/bower_components/font-awesome/webfonts/**"
)
)
.pipe(
gulp.dest(path.join(config.uisPath, ui, config.buildPath, "webfonts"))
);
});
uis.forEach(function(ui) {
return gulp
.src(
path.join(
config.uisPath,
ui,
config.publicPath,
"/libs_components/fontawesome-pro-5.7.2-web/webfonts/**"
)
)
.pipe(
gulp.dest(path.join(config.uisPath, ui, config.buildPath, "webfonts"))
);
});
});
gulp.task("move-images", function() {
uis.forEach(function(ui) {
return gulp
.src(path.join(config.uisPath, ui, config.publicPath, "img/**"))
.pipe(gulp.dest(path.join(config.uisPath, ui, config.buildPath, "img")));
});
uis.forEach(function(ui) {
return gulp
.src(path.join(config.uisPath, ui, config.publicPath, "banner/**"))
.pipe(
gulp.dest(path.join(config.uisPath, ui, config.buildPath, "banner"))
);
});
uis.forEach(function(ui) {
return gulp
.src(path.join(config.uisPath, ui, config.publicPath, "video/**"))
.pipe(
gulp.dest(path.join(config.uisPath, ui, config.buildPath, "video"))
);
});
uis.forEach(function(ui) {
return gulp
.src(path.join(config.uisPath, ui, config.publicPath, "sound/**"))
.pipe(
gulp.dest(path.join(config.uisPath, ui, config.buildPath, "sound"))
);
});
uis.forEach(function(ui) {
return gulp
.src(path.join(config.uisPath, ui, config.publicPath, "uploads/**"))
.pipe(
gulp.dest(path.join(config.uisPath, ui, config.buildPath, "uploads"))
);
});
});
gulp.task("move-api-json", ["write-api"], function() {
uis.forEach(function(ui) {
return gulp
.src(path.join(config.uisPath, ui, config.publicPath, "api.json"))
.pipe(gulp.dest(path.join(config.uisPath, ui, config.buildPath)));
});
});
gulp.task(
"build", [
"build-less",
"build-html-assets",
"move-ngpack-html",
"move-bootstrap-fonts",
"move-cheditor",
"move-custom-fonts",
"move-images",
"move-api-json",
],
function() {}
);