Skip to content

Commit

Permalink
refactor: refactor to single package
Browse files Browse the repository at this point in the history
  • Loading branch information
pooya parsa committed Jun 8, 2019
1 parent b992235 commit 1e1ae7b
Show file tree
Hide file tree
Showing 49 changed files with 199 additions and 1,461 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Expand Up @@ -26,4 +26,4 @@ jobs:
# Test
- run:
name: Tests
command: yarn test && yarn codecov
command: yarn test --coverage && yarn codecov
2 changes: 1 addition & 1 deletion .eslintignore
Expand Up @@ -3,4 +3,4 @@
**/dist

# Contains Lodash templates
packages/icon/plugin.js
**/plugin.js
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -11,10 +11,10 @@

> Progressive Web Apps (PWA) are reliable, fast, and engaging, although there are many things that can take a PWA from a baseline to exemplary experience. ([learn more](https://developers.google.com/web/progressive-web-apps))
Using Nuxt PWA you can supercharge your current or next Nuxt project with a heavily tested, updated and stable PWA solution and zero-config!
Supercharge Nuxt with a heavily tested, updated, zero-config and stable PWA solution!

📖 [**Read Documentation**](https://pwa.nuxtjs.org)

## License

MIT - Nuxt Community - Pooya Parsa
MIT - Nuxt Community - Pooya Parsa
11 changes: 11 additions & 0 deletions jest.config.js
@@ -0,0 +1,11 @@
module.exports = {
testEnvironment: 'node',
collectCoverageFrom: [
'lib/**/*.js',
'!lib/**/plugin.js',
'!lib/**/templates/*.js'
],
transform: {
'^.+\\.js$': 'babel-jest'
}
}
15 changes: 0 additions & 15 deletions lerna.json

This file was deleted.

15 changes: 6 additions & 9 deletions packages/icon/index.js → lib/icon/module.js
Expand Up @@ -2,17 +2,17 @@ const fs = require('fs-extra')
const path = require('path')
const hasha = require('hasha')
const { fork } = require('child_process')
const { joinUrl, getRouteParams } = require('@nuxtjs/pwa-utils')
const { joinUrl, getRouteParams } = require('../utils')

module.exports = function (options) {
this.nuxt.hook('build:before', () => run.call(this, options, true))
module.exports = function (iconOptions) {
this.nuxt.hook('build:before', () => run.call(this, iconOptions, true))

if (this.options.mode === 'spa' && !this.options.dev) {
return run.call(this, options, false) // Fill meta
return run.call(this, iconOptions, false) // Fill meta
}
}

async function run (moduleOptions, _emitAssets) {
async function run (iconOptions, _emitAssets) {
const { publicPath } = getRouteParams(this.options)

// Defaults
Expand All @@ -34,8 +34,7 @@ async function run (moduleOptions, _emitAssets) {
// Merge options
const options = {
...defaults,
...this.options.icon,
...moduleOptions
...iconOptions
}

// Find iconSrc
Expand Down Expand Up @@ -174,5 +173,3 @@ async function resizeIcons (options) {
})
})
}

module.exports.meta = require('./package.json')
File renamed without changes.
File renamed without changes.
13 changes: 6 additions & 7 deletions packages/manifest/index.js → lib/manifest/module.js
@@ -1,10 +1,10 @@
const hash = require('hash-sum')

const { joinUrl, getRouteParams, find } = require('@nuxtjs/pwa-utils')
const { joinUrl, getRouteParams, find } = require('../utils')

module.exports = function nuxtManifest (options) {
module.exports = function nuxtManifest (manifestOptions) {
const hook = () => {
addManifest.call(this, options)
addManifest.call(this, manifestOptions)
}

if (this.options.mode === 'spa') {
Expand All @@ -14,7 +14,7 @@ module.exports = function nuxtManifest (options) {
this.nuxt.hook('build:before', hook)
}

function addManifest (_options) {
function addManifest (manifestOptions) {
const { routerBase, publicPath } = getRouteParams(this.options)

// Combine sources
Expand All @@ -30,7 +30,8 @@ function addManifest (_options) {
theme_color: this.options.loading && this.options.loading.color,
lang: 'en'
}
const options = { ...defaults, ...this.options.manifest, ..._options }

const options = { ...defaults, ...manifestOptions }

// Remve extra fields from manifest
const manifest = { ...options }
Expand Down Expand Up @@ -68,5 +69,3 @@ function addManifest (_options) {
console.warn('Manifest meta already provided!')
}
}

module.exports.meta = require('./package.json')
12 changes: 5 additions & 7 deletions packages/meta/index.js → lib/meta/module.js
@@ -1,8 +1,8 @@
const { find, isUrl } = require('@nuxtjs/pwa-utils')
const { find, isUrl } = require('../utils')

module.exports = function nuxtMeta (_options) {
module.exports = function nuxtMeta (metaOptions) {
const hook = () => {
generateMeta.call(this, _options)
generateMeta.call(this, metaOptions)
}

if (this.options.mode === 'spa') {
Expand All @@ -12,7 +12,7 @@ module.exports = function nuxtMeta (_options) {
this.nuxt.hook('build:before', hook)
}

function generateMeta (_options) {
function generateMeta (metaOptions) {
// Defaults
const defaults = {
name: process.env.npm_package_name,
Expand Down Expand Up @@ -40,7 +40,7 @@ function generateMeta (_options) {
}

// Combine sources
const options = Object.assign({}, defaults, this.options.manifest, this.options.meta, _options)
const options = { ...defaults, ...this.options.manifest, ...metaOptions }

// Default value for viewport
if (options.viewport === undefined) {
Expand Down Expand Up @@ -226,5 +226,3 @@ function generateMeta (_options) {
this.options.head.meta.push({ hid: 'twitter:creator', name: 'twitter:creator', property: 'twitter:creator', content: options.twitterCreator })
}
}

module.exports.meta = require('./package.json')
13 changes: 13 additions & 0 deletions lib/module.js
@@ -0,0 +1,13 @@
module.exports = async function nuxtPWA (options) {
const modules = ['icon', 'manifest', 'meta', 'workbox']
for (const name of modules) {
if (options[name] === false || this.options[name] === false) {
continue
}
const moduleFn = require(`./${name}/module.js`)
const moduleOptions = { ...this.options[name], ...options[name] }
await moduleFn.call(this, moduleOptions)
}
}

module.exports.meta = require('../package.json')
14 changes: 6 additions & 8 deletions packages/onesignal/index.js → lib/onesignal/module.js
@@ -1,16 +1,16 @@
const path = require('path')
const { writeFileSync, readFileSync } = require('fs')
const hashSum = require('hash-sum')
const { defaultsDeep } = require('lodash')
const { getRouteParams, joinUrl } = require('@nuxtjs/pwa-utils')
const defu = require('defu')
const { getRouteParams, joinUrl } = require('../utils')

// =============================================
// oneSignal Module
// =============================================

module.exports = function nuxtOneSignal (moduleOptions) {
module.exports = function nuxtOneSignal (oneSignalOptions) {
const hook = () => {
addOneSignal.call(this, moduleOptions)
addOneSignal.call(this, oneSignalOptions)
}

if (this.options.mode === 'spa') {
Expand All @@ -24,7 +24,7 @@ module.exports = function nuxtOneSignal (moduleOptions) {
// addOneSignal
// =============================================

function addOneSignal (moduleOptions) {
function addOneSignal (oneSignalOptions) {
const { publicPath } = getRouteParams(this.options)

// Merge options
Expand All @@ -43,7 +43,7 @@ function addOneSignal (moduleOptions) {
}
}

const options = defaultsDeep({}, this.options.oneSignal, moduleOptions, defaults)
const options = defu(oneSignalOptions, defaults)

if (options.OneSignalSDK === undefined) {
if (options.cdn) {
Expand Down Expand Up @@ -108,5 +108,3 @@ function addOneSignal (moduleOptions) {
options
})
}

module.exports.meta = require('./package.json')
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 3 additions & 5 deletions packages/workbox/lib/module.js → lib/workbox/module.js
Expand Up @@ -3,10 +3,10 @@ const path = require('path')
const { getOptions } = require('./options')
const { readJSFiles } = require('./utils')

module.exports = function nuxtWorkbox (moduleOptions) {
module.exports = function nuxtWorkbox (workboxOptions) {
this.nuxt.hook('build:before', () => {
// Get options
const options = getOptions.call(this, moduleOptions)
const options = getOptions.call(this, workboxOptions)

// Warning for dev option
if (options.dev) {
Expand All @@ -16,7 +16,7 @@ module.exports = function nuxtWorkbox (moduleOptions) {
// Register plugin
if (options.autoRegister) {
this.addPlugin({
src: path.resolve(__dirname, '../templates/workbox.js'),
src: path.resolve(__dirname, 'templates/workbox.js'),
ssr: false,
fileName: 'workbox.js',
options: {
Expand All @@ -40,5 +40,3 @@ module.exports = function nuxtWorkbox (moduleOptions) {
}
})
}

module.exports.meta = require('../package.json')
9 changes: 4 additions & 5 deletions packages/workbox/lib/options.js → lib/workbox/options.js
@@ -1,10 +1,9 @@
const path = require('path')

const defaults = require('./defaults')
const { joinUrl, getRouteParams, startCase } = require('@nuxtjs/pwa-utils')
const { joinUrl, getRouteParams, startCase } = require('../utils')

function getOptions (moduleOptions) {
const options = Object.assign({}, defaults, moduleOptions, this.options.workbox)
function getOptions (workboxOptions) {
const options = { ...defaults, ...workboxOptions }

// routerBase
if (!options.routerBase) {
Expand All @@ -20,7 +19,7 @@ function getOptions (moduleOptions) {
// swTemplate
if (!options.swTemplate) {
const disabled = this.options.dev && !options.dev
options.swTemplate = path.resolve(__dirname, `../templates/sw${disabled ? '.disable' : ''}.js`)
options.swTemplate = path.resolve(__dirname, `templates/sw${disabled ? '.disable' : ''}.js`)
}

// swDest
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
42 changes: 19 additions & 23 deletions package.json
@@ -1,30 +1,26 @@
{
"version": "0.0.0",
"private": true,
"contributors": [
"Pooya Parsa <pooya@pi0.ir>",
"Alexander Lichter <hello@lichter.io>",
"Jonas Galvez <jonasgalvez@gmail.com>"
"name": "@nuxtjs/pwa",
"version": "3.0.0-beta.16",
"description": "Supercharge Nuxt with a heavily tested, updated, zero-config and stable PWA solution!",
"repository": "nuxt-community/pwa-module",
"files": [
"lib"
],
"main": "lib/module.js",
"scripts": {
"test": "yarn lint && jest",
"lint": "eslint --ext .js packages",
"release": "lerna publish --conventional-commits"
"lint": "eslint --ext .js lib",
"release": "yarn test && standard-version && git push --follow-tags && npm publish",
"generate": "yarn nuxt generate test/fixture",
"test": "yarn lint && yarn generate && jest"
},
"repository": {
"type": "git",
"url": "https://github.com/nuxt-community/pwa-module.git"
},
"workspaces": [
"packages/*"
],
"publishConfig": {
"access": "public"
},
"jest": {
"testEnvironment": "node",
"coverageDirectory": "./coverage/",
"collectCoverage": true
"dependencies": {
"defu": "^0.0.3",
"execa": "^1.0.0",
"fs-extra": "^8.0.1",
"hash-sum": "^1.0.2",
"hasha": "^5.0.0",
"jimp": "^0.6.4",
"workbox-cdn": "^4.3.1"
},
"devDependencies": {
"axios": "^0.18.0",
Expand Down

0 comments on commit 1e1ae7b

Please sign in to comment.