Browse Source

keep negated paths when cleaning old resources

pull/9157/head
Arman Ozak 5 years ago
parent
commit
3035cdaed7
  1. 23
      npm/packs/aspnetcore.mvc.ui/gulp/copy-resources.js

23
npm/packs/aspnetcore.mvc.ui/gulp/copy-resources.js

@ -4,7 +4,7 @@
var gulp = require("gulp"), var gulp = require("gulp"),
merge = require("merge-stream"), merge = require("merge-stream"),
fse = require('fs-extra'), fs = require('fs'),
glob = require('glob'), glob = require('glob'),
micromatch = require('micromatch'), micromatch = require('micromatch'),
path = require("path"), path = require("path"),
@ -47,10 +47,19 @@
function cleanDirsAndFiles(patterns) { function cleanDirsAndFiles(patterns) {
const { dirs, files } = findDirsAndFiles(patterns); const { dirs, files } = findDirsAndFiles(patterns);
files.forEach(file => fse.unlinkSync(file)); files.forEach(file => {
try {
fs.unlinkSync(file);
} catch (_) {}
});
dirs.sort((a, b) => a < b ? 1 : -1);
dirs.forEach(dir => { dirs.forEach(dir => {
if (fs.readdirSync(dir).length) return;
try { try {
fse.rmdirSync(dir); fs.rmdirSync(dir, {});
} catch (_) {} } catch (_) {}
}); });
} }
@ -66,9 +75,9 @@
}); });
matches.forEach(match => { matches.forEach(match => {
if (!fse.pathExistsSync(match)) return; if (!fs.existsSync(match)) return;
(fse.statSync(match).isDirectory() ? dirs : files).push(match); (fs.statSync(match).isDirectory() ? dirs : files).push(match);
}); });
return { dirs, files }; return { dirs, files };
@ -144,8 +153,10 @@
if (resourceMapping.mappings) { if (resourceMapping.mappings) {
for (var mapping in resourceMapping.mappings) { for (var mapping in resourceMapping.mappings) {
if (resourceMapping.mappings.hasOwnProperty(mapping)) { if (resourceMapping.mappings.hasOwnProperty(mapping)) {
var source = replaceAliases(mapping);
var destination = replaceAliases(resourceMapping.mappings[mapping]); var destination = replaceAliases(resourceMapping.mappings[mapping]);
if (fs.existsSync(destination)) continue;
var source = replaceAliases(mapping);
tasks.push( tasks.push(
gulp.src(source).pipe(gulp.dest(destination)) gulp.src(source).pipe(gulp.dest(destination))
); );

Loading…
Cancel
Save