tweak
This commit is contained in:
		@@ -1,6 +1,9 @@
 | 
				
			|||||||
const chokidar = require('chokidar')
 | 
					const chokidar = require('chokidar')
 | 
				
			||||||
const bodyParser = require('body-parser')
 | 
					const bodyParser = require('body-parser')
 | 
				
			||||||
const chalk = require('chalk')
 | 
					const chalk = require('chalk')
 | 
				
			||||||
 | 
					const path = require('path')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const mockDir = path.join(process.cwd(), 'mock')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function registerRoutes(app) {
 | 
					function registerRoutes(app) {
 | 
				
			||||||
  let mockLastIndex
 | 
					  let mockLastIndex
 | 
				
			||||||
@@ -18,7 +21,7 @@ function registerRoutes(app) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
function unregisterRoutes() {
 | 
					function unregisterRoutes() {
 | 
				
			||||||
  Object.keys(require.cache).forEach(i => {
 | 
					  Object.keys(require.cache).forEach(i => {
 | 
				
			||||||
    if (i.includes('/mock') || i.includes('\\mock') || i.includes('./mock')) {
 | 
					    if (i.includes(mockDir)) {
 | 
				
			||||||
      delete require.cache[require.resolve(i)]
 | 
					      delete require.cache[require.resolve(i)]
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  })
 | 
					  })
 | 
				
			||||||
@@ -40,9 +43,8 @@ module.exports = app => {
 | 
				
			|||||||
  var mockStartIndex = mockRoutes.mockStartIndex
 | 
					  var mockStartIndex = mockRoutes.mockStartIndex
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // watch files, hot reload mock server
 | 
					  // watch files, hot reload mock server
 | 
				
			||||||
  chokidar.watch(('./mock'), {
 | 
					  chokidar.watch(mockDir, {
 | 
				
			||||||
    ignored: 'mock/mock-server.js',
 | 
					    ignored: /mock-server/,
 | 
				
			||||||
    persistent: true,
 | 
					 | 
				
			||||||
    ignoreInitial: true
 | 
					    ignoreInitial: true
 | 
				
			||||||
  }).on('all', (event, path) => {
 | 
					  }).on('all', (event, path) => {
 | 
				
			||||||
    if (event === 'change' || event === 'add') {
 | 
					    if (event === 'change' || event === 'add') {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user