Skip to content

Commit

Permalink
code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
harshit-bs committed Aug 2, 2023
1 parent 0a69a06 commit e60c8fd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const fs = require('fs');
const path = require('path');
const CDPConnection = require('./src/cdp.js');
const {injectRendererName, injectScript} = require('./src/utils/index.js');
const {injectRendererName, injectScript} = require('./src/utils/');

module.exports = function viteNightwatchPlugin(options = {}) {
const enableCdpConnection = options.enableCdpConnection || false;
Expand Down
18 changes: 12 additions & 6 deletions src/utils/injectScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,17 @@ const svelteScript = (path) =>
window['@component_class'] = Component;
`;


module.exports = function (content, componentType, path) {
return content.replace(
'<!-- script -->',
`<script type="module">
${componentType === 'react' ? reactScript(path) : (componentType === 'svelte' ? svelteScript(path) : vueScript(path))}
</script>`
);
let scriptType;

if (componentType === 'react') {
scriptType = reactScript(path);
} else if (componentType === 'svelte') {
scriptType = svelteScript(path);
} else {
scriptType = vueScript(path);
}

return content.replace('<!-- script -->', `<script type="module">${scriptType}</script>`);
};
3 changes: 1 addition & 2 deletions test/lib/vite.config-svelte.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { defineConfig } from 'vite';
import nightwatchPlugin from '../../index.js';

let asyncSvelte = async () => {
const asyncSvelte = async () => {
const SveltPlugin = await import('@sveltejs/vite-plugin-svelte');
return SveltPlugin.svelte();
};


export default defineConfig({
plugins: [
asyncSvelte(),
Expand Down

0 comments on commit e60c8fd

Please sign in to comment.