From 49593b07b80f28625f0f81ce3ed7bc868d0d6550 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20Reyrol?= Date: Tue, 28 Jan 2020 11:16:17 +0100 Subject: [PATCH] feat: add module template --- .editorconfig | 13 +++++ .eslintignore | 8 +++ .eslintrc.js | 8 +++ .gitignore | 110 ++++++++++++++++++++++++++++++++++++++++ .vscode/extensions.json | 8 +++ .vscode/settings.json | 3 ++ LICENSE.md | 21 ++++++++ README.md | 57 +++++++++++++++++++++ babel.config.js | 12 +++++ commitlint.config.js | 3 ++ example/nuxt.config.js | 18 +++++++ example/pages/index.vue | 11 ++++ husky.config.js | 7 +++ jest.config.js | 14 +++++ lib/module.js | 16 ++++++ lib/plugin.js | 4 ++ package.json | 46 +++++++++++++++++ prettier.config.js | 6 +++ renovate.json | 3 ++ test/module.test.js | 18 +++++++ 20 files changed, 386 insertions(+) create mode 100755 .editorconfig create mode 100644 .eslintignore create mode 100644 .eslintrc.js create mode 100755 .gitignore create mode 100644 .vscode/extensions.json create mode 100644 .vscode/settings.json create mode 100644 LICENSE.md create mode 100755 README.md create mode 100644 babel.config.js create mode 100644 commitlint.config.js create mode 100644 example/nuxt.config.js create mode 100644 example/pages/index.vue create mode 100644 husky.config.js create mode 100644 jest.config.js create mode 100644 lib/module.js create mode 100644 lib/plugin.js create mode 100755 package.json create mode 100644 prettier.config.js create mode 100644 renovate.json create mode 100644 test/module.test.js diff --git a/.editorconfig b/.editorconfig new file mode 100755 index 0000000..9142239 --- /dev/null +++ b/.editorconfig @@ -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 diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..b4eaf65 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,8 @@ +# Common +node_modules +dist +.nuxt +coverage + +# Plugin +lib/plugin.js diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 0000000..67a4717 --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,8 @@ +module.exports = { + root: true, + parserOptions: { + parser: 'babel-eslint', + sourceType: 'module' + }, + extends: ['@nuxtjs', 'plugin:prettier/recommended'] +} diff --git a/.gitignore b/.gitignore new file mode 100755 index 0000000..b528f11 --- /dev/null +++ b/.gitignore @@ -0,0 +1,110 @@ +# Created by https://www.gitignore.io/api/node +# Edit at https://www.gitignore.io/?templates=node + +### Node ### +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* + +# Diagnostic reports (https://nodejs.org/api/report.html) +report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage +*.lcov + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# TypeScript v1 declaration files +typings/ + +# TypeScript cache +*.tsbuildinfo + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env +.env.test + +# parcel-bundler cache (https://parceljs.org/) +.cache + +# next.js build output +.next + +# nuxt.js build output +.nuxt + +# rollup.js default build output +dist/ + +# Uncomment the public line if your project uses Gatsby +# https://nextjs.org/blog/next-9-1#public-directory-support +# https://create-react-app.dev/docs/using-the-public-folder/#docsNav +# public + +# Storybook build outputs +.out +.storybook-out + +# vuepress build output +.vuepress/dist + +# Serverless directories +.serverless/ + +# FuseBox cache +.fusebox/ + +# DynamoDB Local files +.dynamodb/ + +# Temporary folders +tmp/ +temp/ + +# End of https://www.gitignore.io/api/node diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..0a173ae --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,8 @@ +{ + "recommendations": [ + "editorconfig.editorconfig", + "dbaeumer.vscode-eslint", + "esbenp.prettier-vscode", + "orta.vscode-jest" + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..ad92582 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "editor.formatOnSave": true +} diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..b800f8e --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,21 @@ +# The MIT License (MIT) + +Copyright (c) Dans Ma Culotte + +> Permission is hereby granted, free of charge, to any person obtaining a copy +> of this software and associated documentation files (the "Software"), to deal +> in the Software without restriction, including without limitation the rights +> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +> copies of the Software, and to permit persons to whom the Software is +> furnished to do so, subject to the following conditions: +> +> The above copyright notice and this permission notice shall be included in +> all copies or substantial portions of the Software. +> +> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +> THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100755 index 0000000..5a0a7f8 --- /dev/null +++ b/README.md @@ -0,0 +1,57 @@ +# @dansmaculotte/nuxt-csp + +[![npm version][npm-version-src]][npm-version-href] +[![npm downloads][npm-downloads-src]][npm-downloads-href] +[![License][license-src]][license-href] + +> Module for Nuxt.js to configure CSP headers + +## :construction: WIP + +This module is considered experimental and a work-in-progress. + +[📖 **Release Notes**](./CHANGELOG.md) + +## Setup + +1. Add `@dansmaculotte/nuxt-csp` dependency to your project + +```bash +yarn add @dansmaculotte/nuxt-csp # or npm install @dansmaculotte/nuxt-csp +``` + +2. Add `@dansmaculotte/nuxt-csp` to the `modules` section of `nuxt.config.js` + +```js +{ + modules: [ + // Simple usage + '@dansmaculotte/nuxt-csp', + + // With options + ['@dansmaculotte/nuxt-csp', { /* module options */ }] + ] +} +``` + +## Development + +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.md) + +Copyright (c) Dans Ma Culotte + + +[npm-version-src]: https://img.shields.io/npm/v/@dansmaculotte/nuxt-csp/latest.svg?style=flat-square +[npm-version-href]: https://npmjs.com/package/@dansmaculotte/nuxt-csp + +[npm-downloads-src]: https://img.shields.io/npm/dt/@dansmaculotte/nuxt-csp.svg?style=flat-square +[npm-downloads-href]: https://npmjs.com/package/@dansmaculotte/nuxt-csp + +[license-src]: https://img.shields.io/npm/l/@dansmaculotte/nuxt-csp.svg?style=flat-square +[license-href]: https://npmjs.com/package/@dansmaculotte/nuxt-csp diff --git a/babel.config.js b/babel.config.js new file mode 100644 index 0000000..c5d2710 --- /dev/null +++ b/babel.config.js @@ -0,0 +1,12 @@ +module.exports = { + presets: [ + [ + '@babel/preset-env', + { + targets: { + esmodules: true + } + } + ] + ] +} diff --git a/commitlint.config.js b/commitlint.config.js new file mode 100644 index 0000000..a4f4369 --- /dev/null +++ b/commitlint.config.js @@ -0,0 +1,3 @@ +module.exports = { + extends: ['@commitlint/config-conventional'] +} diff --git a/example/nuxt.config.js b/example/nuxt.config.js new file mode 100644 index 0000000..dbf2e32 --- /dev/null +++ b/example/nuxt.config.js @@ -0,0 +1,18 @@ +const { resolve } = require('path') + +require('dotenv').config() + +module.exports = { + rootDir: resolve(__dirname, '..'), + buildDir: resolve(__dirname, '.nuxt'), + srcDir: __dirname, + render: { + resourceHints: false + }, + modules: [ + { handler: require('../') } + ], + buildModules: [ + '@nuxtjs/dotenv', + ] +} diff --git a/example/pages/index.vue b/example/pages/index.vue new file mode 100644 index 0000000..6218ede --- /dev/null +++ b/example/pages/index.vue @@ -0,0 +1,11 @@ + + + diff --git a/husky.config.js b/husky.config.js new file mode 100644 index 0000000..817c553 --- /dev/null +++ b/husky.config.js @@ -0,0 +1,7 @@ +module.exports = { + hooks: { + 'commit-msg': 'commitlint -E HUSKY_GIT_PARAMS', + 'pre-commit': 'yarn lint', + 'pre-push': 'yarn lint' + } +} diff --git a/jest.config.js b/jest.config.js new file mode 100644 index 0000000..5dccad3 --- /dev/null +++ b/jest.config.js @@ -0,0 +1,14 @@ +module.exports = { + testEnvironment: 'node', + collectCoverage: true, + collectCoverageFrom: ['lib/**/*.js', '!lib/plugin.js'], + moduleNameMapper: { + '^~/(.*)$': '/lib/$1', + '^~~$': '', + '^@@$': '', + '^@/(.*)$': '/lib/$1' + }, + transform: { + '^.+\\.js$': 'babel-jest' + } +} diff --git a/lib/module.js b/lib/module.js new file mode 100644 index 0000000..3b2480c --- /dev/null +++ b/lib/module.js @@ -0,0 +1,16 @@ +const { resolve } = require('path') + +module.exports = async function (moduleOptions) { + const options = { + ...this.options['nuxt-csp'], + ...moduleOptions + } + + this.addPlugin({ + src: resolve(__dirname, 'plugin.js'), + fileName: 'nuxt-csp.js', + options + }) +} + +module.exports.meta = require('../package.json') diff --git a/lib/plugin.js b/lib/plugin.js new file mode 100644 index 0000000..1176860 --- /dev/null +++ b/lib/plugin.js @@ -0,0 +1,4 @@ +export default async function ({ router, store }) { + + +} diff --git a/package.json b/package.json new file mode 100755 index 0000000..f2e454d --- /dev/null +++ b/package.json @@ -0,0 +1,46 @@ +{ + "name": "@dansmaculotte/nuxt-csp", + "version": "0.0.0", + "description": "Module for Nuxt.js to configure CSP headers", + "repository": "dansmaculotte/nuxt-csp", + "license": "MIT", + "contributors": [ + { + "name": "Gaël Reyrol " + } + ], + "files": [ + "lib" + ], + "main": "lib/module.js", + "scripts": { + "dev": "nuxt example", + "lint": "eslint --ext .js,.vue example lib test", + "release": "yarn test && standard-version && git push --follow-tags && npm publish", + "test": "yarn lint && jest" + }, + "dependencies": {}, + "devDependencies": { + "@babel/core": "latest", + "@babel/preset-env": "latest", + "@commitlint/cli": "latest", + "@commitlint/config-conventional": "latest", + "@nuxtjs/dotenv": "latest", + "@nuxtjs/eslint-config": "latest", + "@nuxtjs/module-test-utils": "latest", + "babel-eslint": "latest", + "babel-jest": "latest", + "codecov": "latest", + "eslint": "latest", + "eslint-config-prettier": "latest", + "eslint-plugin-prettier": "latest", + "husky": "latest", + "jest": "latest", + "nuxt-edge": "latest", + "prettier": "latest", + "standard-version": "latest" + }, + "publishConfig": { + "access": "public" + } +} diff --git a/prettier.config.js b/prettier.config.js new file mode 100644 index 0000000..e891e21 --- /dev/null +++ b/prettier.config.js @@ -0,0 +1,6 @@ +module.exports = { + trailingComma: 'none', + tabWidth: 2, + semi: false, + singleQuote: true +} diff --git a/renovate.json b/renovate.json new file mode 100644 index 0000000..9cfbe66 --- /dev/null +++ b/renovate.json @@ -0,0 +1,3 @@ +{ + "extends": ["@nuxtjs"] +} diff --git a/test/module.test.js b/test/module.test.js new file mode 100644 index 0000000..fe8ccfb --- /dev/null +++ b/test/module.test.js @@ -0,0 +1,18 @@ +const { setup, loadConfig, get } = require('@nuxtjs/module-test-utils') + +describe('module', () => { + let nuxt + + beforeAll(async () => { + ;({ nuxt } = await setup(loadConfig(__dirname, '../../example'))) + }, 60000) + + afterAll(async () => { + await nuxt.close() + }) + + test('render', async () => { + const html = await get('/') + expect(html).toContain('Works!') + }) +})