2 |
3 | create-nuxt-module default content
4 |
5 |
6 |
7 |
10 |
--------------------------------------------------------------------------------
/template/project/javascript/test/system/module.test.js:
--------------------------------------------------------------------------------
1 | const puppeteer = require('puppeteer')
2 | const request = require('request-promise-native')
3 |
4 | const { Nuxt, Builder } = require('nuxt')
5 | const config = require('../fixture/nuxt.config')
6 |
7 | const url = path => `http://localhost:3000${path}`
8 | const get = path => request(url(path))
9 |
10 | jest.setTimeout(10000)
11 |
12 | describe('module E2E test', () => {
13 | let nuxt
14 | let page
15 | let browser
16 |
17 | beforeAll(async () => {
18 | nuxt = new Nuxt(config)
19 |
20 | const createNuxt = async () => {
21 | await new Builder(nuxt).build()
22 | await nuxt.listen(3000)
23 | }
24 | const createBrowser = async () => {
25 | browser = await puppeteer.launch({
26 | args: [
27 | '--no-sandbox'
28 | ],
29 | headless: process.env.NODE_ENV !== 'development',
30 | timeout: 0
31 | })
32 | page = await browser.newPage()
33 | }
34 | await Promise.all([createNuxt(), createBrowser()])
35 | }, 300000)
36 |
37 | afterAll(async () => {
38 | await browser.close()
39 | await nuxt.close()
40 | })
41 |
42 | test('WIP', () => {
43 | // TODO: write test
44 | expect(true).toBe(true)
45 | })
46 | })
47 |
--------------------------------------------------------------------------------
/template/project/javascript/test/unit/module.middleware.test.js:
--------------------------------------------------------------------------------
1 | describe('module.middleware.js', () => {
2 | describe('sample', () => {
3 | it('should returns true', () => {
4 | expect(true).toBe(true)
5 | })
6 | })
7 | })
8 |
--------------------------------------------------------------------------------
/template/project/javascript/test/unit/module.test.js:
--------------------------------------------------------------------------------
1 | describe('module.js', () => {
2 | describe('sample', () => {
3 | it('should returns true', () => {
4 | expect(true).toBe(true)
5 | })
6 | })
7 | })
8 |
--------------------------------------------------------------------------------
/template/project/typescript/.circleci/config.yml:
--------------------------------------------------------------------------------
1 | # Generated by create-nuxt-module
2 | version: 2
3 | jobs:
4 | build:
5 | docker:
6 | - image: circleci/node:10.14.0-browsers
7 |
8 | working_directory: ~/app
9 |
10 | steps:
11 | - checkout
12 |
13 | - restore_cache:
14 | keys:
15 | - v1-dependencies-{{ checksum "package.json" }}
16 |
17 | - run: yarn install
18 |
19 | - save_cache:
20 | paths:
21 | - node_modules
22 | key: v1-dependencies-{{ checksum "package.json" }}
23 |
24 | - run: NODE_ENV=test yarn test:coverage
25 | - store_artifacts:
26 | path: ~/app/coverage/lcov-apprt/
27 |
--------------------------------------------------------------------------------
/template/project/typescript/.gitignore:
--------------------------------------------------------------------------------
1 | .nuxt/
2 | lib/**/*.js
3 | coverage/
4 | node_modules/
5 | dist/
6 |
--------------------------------------------------------------------------------
/template/project/typescript/.prettierignore:
--------------------------------------------------------------------------------
1 | .nuxt/
2 | coverage/
3 | dist/
4 | lib/
5 |
--------------------------------------------------------------------------------
/template/project/typescript/.prettierrc:
--------------------------------------------------------------------------------
1 | {
2 | "semi": false,
3 | "singleQuote": true
4 | }
5 |
--------------------------------------------------------------------------------
/template/project/typescript/README.md:
--------------------------------------------------------------------------------
1 | # <%= name %>
2 |
3 | <%= description %>
4 |
5 | ## Installation
6 |
7 | ```bash
8 | $ yarn add <%= name %> # or npm install
9 | ```
10 |
11 | ## Usage
12 |
13 | ## Development
14 |
15 | ```bash
16 | $ git clone https://github.com/<%= author %>/<%= name %>.git
17 | $ cd <%= name %>
18 | $ yarn
19 | ```
20 |
21 | ## License
22 |
23 | ## Note
24 |
25 | This project generated by [create-nuxt-module](https://github.com/potato4d/create-nuxt-module)
26 |
--------------------------------------------------------------------------------
/template/project/typescript/jest.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | preset: 'ts-jest',
3 | testEnvironment: 'node'
4 | }
5 |
--------------------------------------------------------------------------------
/template/project/typescript/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "<%= name %>",
3 | "version": "0.1.0",
4 | "description": "<%= description %>",
5 | "author": {
6 | "name": "<%= author %>"
7 | },
8 | "keywords": [
9 | "vue",
10 | "nuxt",
11 | "nuxt.js"
12 | ],
13 | "main": "lib/module.js",
14 | "license": "MIT",
15 | "scripts": {
16 | "dev": "nuxt test/fixture",
17 | "test": "NODE_ENV=test jest",
18 | "build": "tsc",
19 | "watch": "tsc --watch",
20 | "test:unit": "NODE_ENV=test jest --testRegex \"/test/unit/(.+)\\.test\\.js$\"",
21 | "test:system": "NODE_ENV=test jest --testRegex \"/test/system/(.+)\\.test\\.js$\"",
22 | "test:coverage": "NODE_ENV=test yarn test --coverage",
23 | "format": "prettier './**/*.{js,ts,json,vue}' --write"
24 | },
25 | "devDependencies": {
26 | "@types/consola": "^1.0.0",
27 | "@types/jest": "^23.3.13",
28 | "@types/jsdom": "^12.2.1",
29 | "@types/node": "^10.12.21",
30 | "jest": "^23.4.1",
31 | "nuxt": "^2.4.0",
32 | "prettier": "^1.16.1",
33 | "puppeteer": "^1.6.1",
34 | "ts-jest": "^23.10.5",
35 | "typescript": "^3.2.4"
36 | },
37 | "jest": {
38 | "testEnvironment": "node",
39 | "collectCoverageFrom": [
40 | "lib/**/*.{js,jsx}"
41 | ]
42 | },
43 | "dependencies": {
44 | "consola": "^2.3.2"
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/template/project/typescript/src/middleware.ts:
--------------------------------------------------------------------------------
1 | import { ModuleOptions } from './types/nuxt'
2 | import { ClientRequest, ServerResponse } from 'http'
3 |
4 | export const createMiddleware = (options: ModuleOptions) => {
5 | return (req: ClientRequest, res: ServerResponse, next: () => void) => {
6 | res.writeHead(503, { 'Content-Type': 'text/html' })
7 | res.write('')
8 | res.end()
9 | return res.end()
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/template/project/typescript/src/module.ts:
--------------------------------------------------------------------------------
1 | import { ModuleOptions } from './types/nuxt'
2 | // import { createMiddleware } from './module.middleware'
3 | // import plugin from './module.plugin'
4 |
5 | const optionName = '<%= name %>'
6 |
7 | type TODO = any
8 |
9 | module.exports = function(this: TODO, moduleOptions: ModuleOptions) {
10 | const consola = require('consola')
11 | const options = Object.assign(
12 | {},
13 | this.options[optionName],
14 | moduleOptions || {}
15 | )
16 | const { enabled } = options
17 | if (enabled === false) {
18 | consola.info('Skip activation of <%= name %> module')
19 | return false
20 | }
21 | consola.info('Add <%= name %> module to server middleware')
22 | return true
23 | }
24 |
25 | module.exports.meta = require('../package.json')
26 |
--------------------------------------------------------------------------------
/template/project/typescript/src/types/nuxt.ts:
--------------------------------------------------------------------------------
1 | export interface ModuleOptions {
2 | enabled?: boolean
3 | }
4 |
--------------------------------------------------------------------------------
/template/project/typescript/test/fixture/nuxt.config.ts:
--------------------------------------------------------------------------------
1 | const resolve = require('path').resolve
2 |
3 | const optionConfig = {}
4 |
5 | export default {
6 | rootDir: resolve(__dirname, '../..'),
7 | srcDir: __dirname,
8 | modules: ['~/../../lib/module'],
9 | '<%= name %>': optionConfig,
10 | dev: process.env.NODE_ENV !== 'test' && process.env.NODE_ENV === 'production'
11 | }
12 |
--------------------------------------------------------------------------------
/template/project/typescript/test/fixture/pages/index.vue:
--------------------------------------------------------------------------------
1 |