Skip to content

Commit

Permalink
chore: update module (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardogobbosouza authored and Pooya Parsa committed Jul 30, 2019
1 parent ba89128 commit 1a1c0fd
Show file tree
Hide file tree
Showing 22 changed files with 2,382 additions and 1,246 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ jobs:
name: Lint
command: yarn lint

# Test
# Tests
- run:
name: Test
name: Tests
command: yarn jest

# Coverage
Expand Down
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# editorconfig.org
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
5 changes: 5 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Common
node_modules
dist
.nuxt
coverage
8 changes: 0 additions & 8 deletions .eslintrc

This file was deleted.

5 changes: 5 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
extends: [
'@nuxtjs'
]
}
8 changes: 5 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
.idea
*.iml
node_modules
*.iml
.idea
*.log*
.nuxt
.vscode
.DS_Store
coverage
!example/node_modules
dist
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2017 Fandogh - Nuxt Community
Copyright (c) Nuxt Community

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
55 changes: 39 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,34 @@
# Hapi Plugin for Nuxt.js

[![npm](https://img.shields.io/npm/dt/hapi-nuxt.svg?style=flat-square)](https://npmjs.com/package/hapi-nuxt)
[![npm release](https://img.shields.io/npm/v/hapi-nuxt/latest.svg?style=flat-square)](https://npmjs.com/package/hapi-nuxt)
[![CircleCI](https://img.shields.io/circleci/project/github/nuxt-community/hapi-nuxt.svg?style=flat-square)](https://circleci.com/gh/nuxt-community/hapi-nuxt)
[![Codecov](https://img.shields.io/codecov/c/github/nuxt-community/hapi-nuxt.svg?style=flat-square)](https://codecov.io/gh/nuxt-community/hapi-nuxt)
[![Greenkeeper badge](https://img.shields.io/badge/greenkeepr-enabled-green.svg?style=flat-square)](https://greenkeeper.io/)
[![dependencies Status](https://david-dm.org/expressjs/express/status.svg?style=flat-square)](https://david-dm.org/expressjs/express)
[![npm version][npm-version-src]][npm-version-href]
[![npm downloads][npm-downloads-src]][npm-downloads-href]
[![Circle CI][circle-ci-src]][circle-ci-href]
[![Codecov][codecov-src]][codecov-href]
[![License][license-src]][license-href]

> [Nuxt.js](https://nuxtjs.org) plugin for [Hapi.js](https://hapijs.com/)
**IMPORTANT:** This plugin is compatible with Hapi >= 17

## Quick start
## Setup

Install plugin:
1. Add `@nuxtjs/hapi` dependency to your project

```bash
yarn add @nuxtjs/hapi # or npm install @nuxtjs/hapi
```

Register it on your server:
2. Register it on your server:

```js
const Hapi = require('@hapi/hapi')
const nuxtPlugin = require('@nuxtjs/hapi')

await server.register({
plugin: nuxtPlugin
options: {
// plugin options
}
plugin: nuxtPlugin
options: {
// plugin options
}
}
```
Expand Down Expand Up @@ -80,14 +79,38 @@ Hapi route method. (Can be set to `GET` for more strict handling)
This plugin exposes nuxt and builder (for dev only) instances to hapi.
```js
server = new Hapi.Server()
const server = new Hapi.Server()

await server.register(HapiNuxt)

// Access to nuxt and builder instances using server.plugins.nuxt
const { nuxt, builder } = server.plugins.nuxt
```
# License
## Development
MIT
1. Clone this repository
2. Install dependencies using `yarn install` or `npm install`
3. Start development server using `npm run dev`
## License
[MIT License](./LICENSE)
Copyright (c) Nuxt Community
<!-- Badges -->
[npm-version-src]: https://img.shields.io/npm/v/@nuxtjs/hapi/latest.svg?style=flat-square
[npm-version-href]: https://npmjs.com/package/@nuxtjs/hapi
[npm-downloads-src]: https://img.shields.io/npm/dt/@nuxtjs/hapi.svg?style=flat-square
[npm-downloads-href]: https://npmjs.com/package/@nuxtjs/hapi
[circle-ci-src]: https://img.shields.io/circleci/project/github/nuxt-community/hapi-nuxt.svg?style=flat-square
[circle-ci-href]: https://circleci.com/gh/nuxt-community/hapi-nuxt
[codecov-src]: https://img.shields.io/codecov/c/github/nuxt-community/hapi-nuxt.svg?style=flat-square
[codecov-href]: https://codecov.io/gh/nuxt-community/hapi-nuxt
[license-src]: https://img.shields.io/npm/l/@nuxtjs/hapi.svg?style=flat-square
[license-href]: https://npmjs.com/package/@nuxtjs/hapi
5 changes: 5 additions & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
extends: [
'@commitlint/config-conventional'
]
}
2 changes: 1 addition & 1 deletion example/api/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const route1 = {
path: '/api',
method: 'GET',
handler(request, h) {
handler (request, h) {
return {
works: true
}
Expand Down
14 changes: 6 additions & 8 deletions example/package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
{
"name": "hapi-nuxt-example",
"version": "0.0.0",
"private": true,
"scripts": {
"dev": "nodemon -w api server.js",
"start": "NODE_ENV=production node server.js",
"build": "nuxt build"
}
"private": true,
"scripts": {
"dev": "nodemon -w api server.js",
"start": "NODE_ENV=production node server.js",
"build": "nuxt build"
}
}
4 changes: 2 additions & 2 deletions example/pages/index.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div>
<div>
Hello world!
</div>
</div>
</template>
2 changes: 1 addition & 1 deletion example/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { Server } = require('@hapi/hapi')
const Routes = require('./api')
const nuxtPlugin = require('..')

async function start() {
async function start () {
const server = new Server({ port: 3000 })

await server.register({
Expand Down
7 changes: 7 additions & 0 deletions husky.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
hooks: {
'commit-msg': 'commitlint -E HUSKY_GIT_PARAMS',
'pre-commit': 'yarn lint',
'pre-push': 'yarn lint'
}
}
7 changes: 7 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
testEnvironment: 'node',
collectCoverage: true,
collectCoverageFrom: [
'lib/**/*.js'
]
}
4 changes: 2 additions & 2 deletions lib/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { resolve } = require('path')
const { existsSync } = require('fs')
const esm = require('esm')

exports.register = async function nuxtPlugin(server, _config) {
exports.register = async function (server, _config) {
// Apply defaults
const config = {
dev: process.env.NODE_ENV !== 'production',
Expand Down Expand Up @@ -49,7 +49,7 @@ exports.register = async function nuxtPlugin(server, _config) {
auth: false,
...config.route
},
handler(request, h) {
handler (request, h) {
const { req, res } = request.raw
nuxt.render(req, res)

Expand Down
55 changes: 26 additions & 29 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,41 @@
"name": "@nuxtjs/hapi",
"version": "2.2.1",
"description": "Nuxt.js plugin for Hapi.js",
"repository": "nuxt-community/hapi-nuxt",
"license": "MIT",
"contributors": [
"Pooya Parsa <pooya@pi0.ir>"
],
"main": "lib/plugin.js",
"files": [
"lib"
],
"repository": "nuxt-community/hapi-nuxt",
"publishConfig": {
"access": "public"
},
"scripts": {
"coverage": "codecov",
"lint": "eslint lib test example",
"dev": "cd example && yarn dev",
"lint": "eslint --ext .js,.vue example lib test",
"test": "yarn lint && jest",
"release": "standard-version && git push --follow-tags && npm publish"
},
"jest": {
"collectCoverage": true,
"coverageDirectory": "./coverage/",
"testEnvironment": "node"
"release": "yarn test && standard-version && git push --follow-tags && npm publish"
},
"files": [
"lib"
],
"dependencies": {
"esm": "^3.2.22"
"esm": "^3.2.25"
},
"devDependencies": {
"@hapi/hapi": "^18.3.1",
"@nuxtjs/eslint-config": "^0.0.1",
"axios": "^0.18.0",
"codecov": "^3.4.0",
"eslint": "^5.16.0",
"eslint-config-standard": "^12.0.0",
"eslint-plugin-import": "^2.17.2",
"eslint-plugin-jest": "^22.5.1",
"eslint-plugin-node": "^9.0.1",
"eslint-plugin-promise": "^4.1.1",
"eslint-plugin-standard": "^4.0.0",
"eslint-plugin-vue": "^5.2.2",
"jest": "^24.8.0",
"nodemon": "^1.19.0",
"nuxt-edge": "^2.7.0-25961769.126c8c14",
"standard-version": "^6.0.1"
"@commitlint/cli": "latest",
"@commitlint/config-conventional": "latest",
"@hapi/hapi": "latest",
"@nuxtjs/eslint-config": "latest",
"axios": "latest",
"codecov": "latest",
"eslint": "latest",
"get-port": "latest",
"husky": "latest",
"jest": "latest",
"nodemon": "latest",
"nuxt": "^2.8.1",
"nuxt-edge": "latest",
"standard-version": "latest"
}
}
30 changes: 17 additions & 13 deletions test/dev.test.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,36 @@
const path = require('path')
const { join } = require('path')
const { Server } = require('@hapi/hapi')
const { Builder } = require('nuxt-edge')
const getPort = require('get-port')
const hapiNuxt = require('..')

Builder.prototype.build = jest.fn(() => Promise.resolve())

describe('dev', () => {
let server
const options = {
srcDir: path.join(__dirname, 'fixture'),
edge: true,
dev: true
}
let server, port

const options = {
srcDir: join(__dirname, 'fixture'),
edge: true,
dev: true
}

it('setup dev server', async () => {
server = new Server()
describe('dev', () => {
beforeAll(async () => {
port = await getPort()
server = new Server({ port })

// Register plugin
await server.register({
plugin: hapiNuxt,
options
})

// Expect builder.build to be called
expect(Builder.prototype.build).toBeCalled()
})

afterAll(async () => {
await server.stop()
})

test('setup dev server', () => {
expect(Builder.prototype.build).toBeCalled()
})
})
6 changes: 4 additions & 2 deletions test/fixture/pages/index.vue
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<template>
<div> Hello Nuxt! </div>
</template>
<div>
Hello Nuxt!
</div>
</template>
Loading

0 comments on commit 1a1c0fd

Please sign in to comment.