Scaffolding for Nuxt module

This commit is contained in:
Jarek Rozanski 2023-05-14 15:25:44 +00:00
commit 51db5e8b53
19 changed files with 16655 additions and 0 deletions

12
.editorconfig Normal file
View file

@ -0,0 +1,12 @@
root = true
[*]
indent_size = 2
indent_style = space
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[*.md]
trim_trailing_whitespace = false

2
.eslintignore Normal file
View file

@ -0,0 +1,2 @@
dist
node_modules

4
.eslintrc Normal file
View file

@ -0,0 +1,4 @@
{
"root": true,
"extends": ["@nuxt/eslint-config"]
}

56
.gitignore vendored Normal file
View file

@ -0,0 +1,56 @@
# Dependencies
node_modules
# Logs
*.log*
# Temp directories
.temp
.tmp
.cache
# Yarn
**/.yarn/cache
**/.yarn/*state*
# Generated dirs
dist
# Nuxt
.nuxt
.output
.vercel_build_output
.build-*
.env
.netlify
# Env
.env
# Testing
reports
coverage
*.lcov
.nyc_output
# VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
!.vscode/*.code-snippets
# Intellij idea
*.iml
.idea
# OSX
.DS_Store
.AppleDouble
.LSOverride
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

2
.npmrc Normal file
View file

@ -0,0 +1,2 @@
shamefully-hoist=true
strict-peer-dependencies=false

2
.nuxtrc Normal file
View file

@ -0,0 +1,2 @@
imports.autoImport=false
typescript.includeWorkspace=true

94
README.md Normal file
View file

@ -0,0 +1,94 @@
<!--
Get your module up and running quickly.
Find and replace all on all files (CMD+SHIFT+F):
- Name: My Module
- Package name: wideangle
- Description: My new Nuxt module
-->
# My Module
[![npm version][npm-version-src]][npm-version-href]
[![npm downloads][npm-downloads-src]][npm-downloads-href]
[![License][license-src]][license-href]
[![Nuxt][nuxt-src]][nuxt-href]
My new Nuxt module for doing amazing things.
- [✨ &nbsp;Release Notes](/CHANGELOG.md)
<!-- - [🏀 Online playground](https://stackblitz.com/github/your-org/wideangle?file=playground%2Fapp.vue) -->
<!-- - [📖 &nbsp;Documentation](https://example.com) -->
## Features
<!-- Highlight some of the features your module provide here -->
- ⛰ &nbsp;Foo
- 🚠 &nbsp;Bar
- 🌲 &nbsp;Baz
## Quick Setup
1. Add `wideangle` dependency to your project
```bash
# Using pnpm
pnpm add -D wideangle
# Using yarn
yarn add --dev wideangle
# Using npm
npm install --save-dev wideangle
```
2. Add `wideangle` to the `modules` section of `nuxt.config.ts`
```js
export default defineNuxtConfig({
modules: [
'wideangle'
]
})
```
That's it! You can now use My Module in your Nuxt app ✨
## Development
```bash
# Install dependencies
npm install
# Generate type stubs
npm run dev:prepare
# Develop with the playground
npm run dev
# Build the playground
npm run dev:build
# Run ESLint
npm run lint
# Run Vitest
npm run test
npm run test:watch
# Release new version
npm run release
```
<!-- Badges -->
[npm-version-src]: https://img.shields.io/npm/v/wideangle/latest.svg?style=flat&colorA=18181B&colorB=28CF8D
[npm-version-href]: https://npmjs.com/package/wideangle
[npm-downloads-src]: https://img.shields.io/npm/dm/wideangle.svg?style=flat&colorA=18181B&colorB=28CF8D
[npm-downloads-href]: https://npmjs.com/package/wideangle
[license-src]: https://img.shields.io/npm/l/wideangle.svg?style=flat&colorA=18181B&colorB=28CF8D
[license-href]: https://npmjs.com/package/wideangle
[nuxt-src]: https://img.shields.io/badge/Nuxt-18181B?logo=nuxt.js
[nuxt-href]: https://nuxt.com

16353
package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

54
package.json Normal file
View file

@ -0,0 +1,54 @@
{
"name": "wideangle",
"version": "0.0.1",
"description": "Wide Angle Analytics module for Nuxt",
"repository": "inputobjects/wideangle-nuxt",
"author": "Wide Angle Analytics <developers@wideangle.co>",
"license": "Apache-2.0",
"type": "module",
"keywords": [
"wide angle analytics",
"web analytics",
"vue.js",
"vuejs",
"plugin",
"vuejs plugin"
],
"exports": {
".": {
"types": "./dist/types.d.ts",
"import": "./dist/module.mjs",
"require": "./dist/module.cjs"
}
},
"main": "./dist/module.cjs",
"types": "./dist/types.d.ts",
"files": [
"dist"
],
"scripts": {
"prepack": "nuxt-module-build",
"dev": "nuxi dev playground",
"dev:build": "nuxi build playground",
"dev:prepare": "nuxt-module-build --stub && nuxi prepare playground",
"release": "npm run lint && npm run test && npm run prepack && changelogen --release && npm publish && git push --follow-tags",
"lint": "eslint .",
"test": "vitest run",
"test:watch": "vitest watch"
},
"dependencies": {
"@nuxt/kit": "^3.4.3",
"wideangle-vuejs": "^0.0.2"
},
"devDependencies": {
"@nuxt/eslint-config": "^0.1.1",
"@nuxt/module-builder": "^0.3.0",
"@nuxt/schema": "^3.4.3",
"@nuxt/test-utils": "^3.4.3",
"@types/node": "^18",
"changelogen": "^0.5.3",
"eslint": "^8.39.0",
"nuxt": "^3.4.3",
"vitest": "^0.30.1"
}
}

8
playground/app.vue Normal file
View file

@ -0,0 +1,8 @@
<template>
<div>
Nuxt module playground!
</div>
</template>
<script setup>
</script>

View file

@ -0,0 +1,4 @@
export default defineNuxtConfig({
modules: ['../src/module'],
myModule: {}
})

4
playground/package.json Normal file
View file

@ -0,0 +1,4 @@
{
"private": true,
"name": "wideangle-playground"
}

19
src/module.ts Normal file
View file

@ -0,0 +1,19 @@
import { defineNuxtModule, addPlugin, createResolver } from '@nuxt/kit'
// Module options TypeScript interface definition
export interface ModuleOptions {}
export default defineNuxtModule<ModuleOptions>({
meta: {
name: 'wideangle',
configKey: 'myModule'
},
// Default configuration options of the Nuxt module
defaults: {},
setup (options, nuxt) {
const resolver = createResolver(import.meta.url)
// Do not add the extension since the `.ts` will be transpiled to `.mjs` after `npm run prepack`
addPlugin(resolver.resolve('./runtime/plugin'))
}
})

5
src/runtime/plugin.ts Normal file
View file

@ -0,0 +1,5 @@
import { defineNuxtPlugin } from '#app'
export default defineNuxtPlugin((nuxtApp) => {
console.log('Plugin injected by wideangle!')
})

15
test/basic.test.ts Normal file
View file

@ -0,0 +1,15 @@
import { describe, it, expect } from 'vitest'
import { fileURLToPath } from 'node:url'
import { setup, $fetch } from '@nuxt/test-utils'
describe('ssr', async () => {
await setup({
rootDir: fileURLToPath(new URL('./fixtures/basic', import.meta.url)),
})
it('renders the index page', async () => {
// Get response to a server-rendered page with `$fetch`.
const html = await $fetch('/')
expect(html).toContain('<div>basic</div>')
})
})

6
test/fixtures/basic/app.vue vendored Normal file
View file

@ -0,0 +1,6 @@
<template>
<div>basic</div>
</template>
<script setup>
</script>

7
test/fixtures/basic/nuxt.config.ts vendored Normal file
View file

@ -0,0 +1,7 @@
import MyModule from '../../../src/module'
export default defineNuxtConfig({
modules: [
MyModule
]
})

5
test/fixtures/basic/package.json vendored Normal file
View file

@ -0,0 +1,5 @@
{
"private": true,
"name": "basic",
"type": "module"
}

3
tsconfig.json Normal file
View file

@ -0,0 +1,3 @@
{
"extends": "./playground/.nuxt/tsconfig.json"
}