Skip to content

Commit

Permalink
feat: add support for nuxt3 via postinstall script
Browse files Browse the repository at this point in the history
  • Loading branch information
justintaddei committed Nov 7, 2023
1 parent deedebe commit 352cf03
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 2 deletions.
29 changes: 29 additions & 0 deletions nuxt/v3/postinstall.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const fs = require('fs')
const path = require('path')

const pkg = require(path.join(process.env.INIT_CWD, 'package.json'))

const nuxtVersion = pkg.dependencies.nuxt ?? pkg.devDependencies.nuxt

if (!nuxtVersion || /2\.\d+\.\d+/.test(nuxtVersion)) {
process.exit(0)
}

if (!fs.existsSync(path.join(process.env.INIT_CWD, 'plugins'))) {
fs.mkdirSync(path.join(process.env.INIT_CWD, 'plugins'))
}

try {
fs.copyFileSync(
path.join(__dirname, 'v-wave.client.ts'),
path.join(process.env.INIT_CWD, 'plugins', 'v-wave.client.ts'),
fs.constants.COPYFILE_EXCL
)
fs.copyFileSync(
path.join(__dirname, 'v-wave.server.ts'),
path.join(process.env.INIT_CWD, 'plugins', 'v-wave.server.ts'),
fs.constants.COPYFILE_EXCL
)
} catch (e) {
process.exit(0)
}
9 changes: 9 additions & 0 deletions nuxt/v3/v-wave.client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import vWave, { type IVWavePluginOptions } from 'v-wave'

export const options: Partial<IVWavePluginOptions> = {
// Place any global v-wave options here
}

export default defineNuxtPlugin((nuxtApp) => {
nuxtApp.vueApp.use(vWave, options)
})
6 changes: 6 additions & 0 deletions nuxt/v3/v-wave.server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { options } from './v-wave.client';

export default defineNuxtPlugin(({ vueApp }) => {
vueApp.directive(options.directive ?? 'wave', {});
vueApp.directive(`${options.directive ?? 'wave'}-trigger`, {});
});
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"lint": "tslint -p tsconfig.json",
"prepare": "npm run build && husky install",
"prepublishOnly": "npm test && npm run lint",
"release": "npm run lint && npm run format && npm run test && standard-version"
"release": "npm run lint && npm run format && npm run test && standard-version",
"postinstall": "node ./nuxt/v3/postinstall.js"
},
"husky": {
"hooks": {
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,4 @@ const VWave: VWaveInstallObject & { createLocalWaveDirective: typeof createDirec
}

export default VWave
export { IVWaveDirectiveOptions, IVWavePluginOptions }
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
"esModuleInterop": true
},
"include": ["src"],
"exclude": ["node_modules", "**/__tests__/*"]
"exclude": ["node_modules", "**/__tests__/*", "nuxt"]
}

0 comments on commit 352cf03

Please sign in to comment.