Skip to content

Commit

Permalink
Add printStartupLog option
Browse files Browse the repository at this point in the history
  • Loading branch information
octoape committed Aug 20, 2024
1 parent 9ccc096 commit 935c1e5
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ publish.bat
publish.sh
package-lock.json
.hintrc
.github/*
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export type MockOptions = {
mockModules?: string[]
noHandlerResponse404?: boolean
middlewares?: MockLayer[]
printStartupLog?: boolean
}

// default options
Expand All @@ -99,7 +100,8 @@ const options: MockOptions = {
mockTsSuffix: '.mock.ts',
noHandlerResponse404: true,
mockModules: [],
middlewares: []
middlewares: [],
printStartupLog: true
}
```

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vite-plugin-mock-server",
"version": "1.2.0",
"version": "1.3.0",
"description": "Vite mock server plugin",
"main": "dist/index.js",
"scripts": {
Expand Down
6 changes: 5 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export type MockOptions = {
mockModules?: string[]
noHandlerResponse404?: boolean
middlewares?: MockLayer[]
printStartupLog?: boolean
}

export default (options?: MockOptions): Plugin => {
Expand All @@ -66,14 +67,17 @@ export default (options?: MockOptions): Plugin => {
options.mockJsSuffix = options.mockJsSuffix || '.mock.js'
options.mockTsSuffix = options.mockTsSuffix || '.mock.ts'
options.noHandlerResponse404 = options.noHandlerResponse404 || true
options.printStartupLog = options.printStartupLog || true
if (options.mockModules && options.mockModules.length > 0) {
console.warn('[' + PLUGIN_NAME + '] mock modules will be set automatically, and the configuration will be ignored', options.mockModules)
}
options.mockModules = []
LOG_LEVEL = options.logLevel
// watch mock files
watchMockFiles(options).then(() => {
console.log('[' + PLUGIN_NAME + '] mock server started. options =', options)
if (options.printStartupLog) {
console.log('[' + PLUGIN_NAME + '] mock server started. options =', options)
}
})
if (options.middlewares) {
for (const [, layer] of options.middlewares.entries()) {
Expand Down

0 comments on commit 935c1e5

Please sign in to comment.