Skip to content

Commit 1880c2f

Browse files
committed
fix(server): 修复更改入口以后服务 / 打包报错
1 parent 97aca37 commit 1880c2f

File tree

6 files changed

+50
-0
lines changed

6 files changed

+50
-0
lines changed

lib/commands/server.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ var connect = require('connect'),
1414
webpackDevMiddleware = require("webpack-dev-middleware");
1515

1616
var Manager = require('../modules/manager.js');
17+
var UtilFs = require('../utils/fs.js');
1718

1819
exports.usage = "开发服务";
1920

@@ -212,6 +213,7 @@ exports.run = function (options) {
212213
fs.watch(projectConfigFilePath, function (eventType, filename) {
213214
if (eventType === 'change') {
214215
middlewareCache[projectName] = null;
216+
UtilFs.deleteFolderRecursive(project.cachePath);
215217
}
216218
});
217219
} else {

lib/models/Project.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ var Config = require('./Config.js'),
1212
Manager = require('../modules/manager.js'),
1313
ExtractTextPlugin = require("extract-text-webpack-plugin");
1414

15+
var UtilFs = require('../utils/fs.js');
16+
1517
var Project = function () {
1618
function Project(cwd) {
1719
_classCallCheck(this, Project);
@@ -28,6 +30,7 @@ var Project = function () {
2830
})[0] || '';
2931
this.extendConfig = this.configFile && this.configFile.match(/ykit\.([\w\.]+)\.js/)[1].replace(/\./g, '-');
3032
this.ignores = ["node_modules/**/*", "bower_components/**/*", "dev/**/*", "prd/**/*"];
33+
this.cachePath = this._isCacheDirExists(cwd) || '';
3134

3235
this.readConfig();
3336
}
@@ -253,6 +256,7 @@ var Project = function () {
253256
var _this3 = this;
254257

255258
var config = this.config.getConfig();
259+
UtilFs.deleteFolderRecursive(this.cachePath);
256260

257261
var process = function process() {
258262

lib/utils/fs.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"use strict";
2+
3+
var fs = require('fs');
4+
module.exports = {
5+
deleteFolderRecursive: function deleteFolderRecursive(path) {
6+
var self = this;
7+
if (fs.existsSync(path)) {
8+
fs.readdirSync(path).forEach(function (file, index) {
9+
var curPath = path + "/" + file;
10+
if (fs.lstatSync(curPath).isDirectory()) {
11+
// recurse
12+
self.deleteFolderRecursive(curPath);
13+
} else {
14+
// delete file
15+
fs.unlinkSync(curPath);
16+
}
17+
});
18+
fs.rmdirSync(path);
19+
}
20+
}
21+
};

src/commands/server.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ let connect = require('connect'),
1212
webpackDevMiddleware = require("webpack-dev-middleware");
1313

1414
let Manager = require('../modules/manager.js');
15+
let UtilFs = require('../utils/fs.js');
1516

1617
exports.usage = "开发服务";
1718

@@ -205,6 +206,7 @@ exports.run = (options) => {
205206
fs.watch(projectConfigFilePath, (eventType, filename) => {
206207
if(eventType === 'change') {
207208
middlewareCache[projectName] = null
209+
UtilFs.deleteFolderRecursive(project.cachePath)
208210
}
209211
});
210212
} else {

src/models/Project.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ let Config = require('./Config.js'),
66
Manager = require('../modules/manager.js'),
77
ExtractTextPlugin = require("extract-text-webpack-plugin");
88

9+
let UtilFs = require('../utils/fs.js');
10+
911
class Project {
1012
constructor(cwd) {
1113
this.cwd = cwd;
@@ -20,6 +22,7 @@ class Project {
2022
})[0] || '';
2123
this.extendConfig = this.configFile && this.configFile.match(/ykit\.([\w\.]+)\.js/)[1].replace(/\./g, '-');
2224
this.ignores = ["node_modules/**/*", "bower_components/**/*", "dev/**/*", "prd/**/*"];
25+
this.cachePath = this._isCacheDirExists(cwd) || ''
2326

2427
this.readConfig();
2528
}
@@ -222,6 +225,7 @@ class Project {
222225

223226
pack(opt, callback) {
224227
let config = this.config.getConfig();
228+
UtilFs.deleteFolderRecursive(this.cachePath)
225229

226230
let process = () => {
227231

src/utils/fs.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const fs = require('fs');
2+
module.exports = {
3+
deleteFolderRecursive: function(path) {
4+
const self = this
5+
if (fs.existsSync(path)) {
6+
fs.readdirSync(path).forEach(function(file, index) {
7+
const curPath = path + "/" + file;
8+
if (fs.lstatSync(curPath).isDirectory()) { // recurse
9+
self.deleteFolderRecursive(curPath);
10+
} else { // delete file
11+
fs.unlinkSync(curPath);
12+
}
13+
});
14+
fs.rmdirSync(path);
15+
}
16+
}
17+
}

0 commit comments

Comments
 (0)