Skip to content

Commit 8d74e59

Browse files
committed
feat(helper): add check file name and directory level
1 parent b3cc236 commit 8d74e59

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

packages/field-plugin/helpers/vite/src/plugins.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@ import type { PluginOption, ViteDevServer } from 'vite'
22
import { generateSandboxUrl } from './sandbox'
33
import { bold, green } from './utils/text'
44
import { arrows } from './utils/arrows'
5+
import { MANIFEST_FILE_NAME } from '@storyblok/manifest-helper'
6+
import path from 'path'
57

68
export function watchConfigFile(): PluginOption {
79
return {
810
name: 'storyblok-field-plugin-watch-config-file',
911
handleHotUpdate({ file, server }) {
10-
if (file.endsWith('field-plugin.config.json')) {
12+
// NOTE: This condition checks if the file is on the same directory level as where the command has been executed and checks the file name
13+
if (isFileInSameLevel(file) && getFileName(file) === MANIFEST_FILE_NAME) {
1114
printSandboxUrl(server)
1215
}
1316
},
@@ -78,3 +81,14 @@ function printSandboxUrl(server: ViteDevServer) {
7881
}
7982

8083
export const plugins = [printProd(), printDev(), watchConfigFile()]
84+
85+
function getFileName(filePath: string) {
86+
return path.basename(filePath)
87+
}
88+
89+
function isFileInSameLevel(fileName: string): boolean {
90+
const currentDir = process.cwd()
91+
const filePath = path.resolve(currentDir, fileName)
92+
const fileDir = path.dirname(filePath)
93+
return currentDir === fileDir
94+
}

0 commit comments

Comments
 (0)