-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from Geminii/feat/rewrite-module
feat!: rewrite module
- Loading branch information
Showing
23 changed files
with
4,322 additions
and
2,408 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,6 @@ node_modules | |
dist | ||
.nuxt | ||
coverage | ||
templates/* | ||
example/static | ||
test/fixture/static | ||
sdk | ||
src/runtime/plugin.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"extends": [ | ||
"@nuxtjs/eslint-config-typescript" | ||
] | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ node_modules | |
.vscode | ||
.DS_Store | ||
coverage | ||
dist |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,9 @@ | ||
module.exports = { | ||
testEnvironment: 'node', | ||
preset: '@nuxt/test-utils', | ||
collectCoverage: true, | ||
collectCoverageFrom: [ | ||
'lib/**/*.js', | ||
'!lib/plugin.js' | ||
], | ||
moduleNameMapper: { | ||
'^~/(.*)$': '<rootDir>/lib/$1', | ||
'^~~$': '<rootDir>', | ||
'^@@$': '<rootDir>', | ||
'^@/(.*)$': '<rootDir>/lib/$1' | ||
}, | ||
transform: { | ||
'^.+\\.js$': 'babel-jest' | ||
} | ||
'src/**', | ||
'!src/runtime/**' | ||
] | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,39 +9,40 @@ | |
"name": "pooya parsa <[email protected]>" | ||
} | ||
], | ||
"main": "dist/module.js", | ||
"files": [ | ||
"lib", | ||
"templates", | ||
"dist" | ||
"dist", | ||
"sdk" | ||
], | ||
"main": "lib/module.js", | ||
"scripts": { | ||
"dev": "nuxt example", | ||
"lint": "eslint --ext .js,.vue .", | ||
"build": "siroc build && mkdist --src src/runtime --dist dist/runtime", | ||
"dev": "nuxt test/fixture", | ||
"format": "yarn lint --fix", | ||
"lint": "eslint --ext .js,.ts,.vue .", | ||
"release": "yarn test && standard-version && git push --follow-tags && npm publish", | ||
"test": "yarn lint && jest" | ||
}, | ||
"dependencies": { | ||
"defu": "^1.0.0", | ||
"defu": "^3.2.2", | ||
"hasha": "^5.2.0" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "latest", | ||
"@babel/preset-env": "latest", | ||
"@babel/preset-env": "^7.12.11", | ||
"@babel/preset-typescript": "^7.12.7", | ||
"@commitlint/cli": "latest", | ||
"@commitlint/config-conventional": "latest", | ||
"@nuxtjs/eslint-config": "latest", | ||
"@nuxtjs/module-test-utils": "latest", | ||
"@nuxtjs/pwa": "latest", | ||
"babel-eslint": "latest", | ||
"babel-jest": "latest", | ||
"eslint": "latest", | ||
"husky": "latest", | ||
"jest": "latest", | ||
"nuxt-edge": "latest", | ||
"puppeteer": "latest", | ||
"standard-version": "latest", | ||
"tib": "latest" | ||
"@nuxt/test-utils": "^0.1.2", | ||
"@nuxt/types": "^2.14.12", | ||
"@nuxtjs/eslint-config-typescript": "^5.0.0", | ||
"@nuxtjs/pwa": "^3.3.4", | ||
"eslint": "^7.18.0", | ||
"husky": "^4.3.8", | ||
"jest": "^26.6.3", | ||
"mkdist": "^0.1.1", | ||
"nuxt-edge": "^2.15.0-26854632.498f8553", | ||
"playwright": "^1.8.0", | ||
"siroc": "^0.6.3", | ||
"standard-version": "latest" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import { writeFileSync, readFileSync } from 'fs' | ||
import { resolve, join } from 'path' | ||
import defu from 'defu' | ||
import hasha from 'hasha' | ||
import { ModuleOptions, moduleDefaults } from './options' | ||
import { getRouteParams, joinUrl } from './utils' | ||
import './types' | ||
|
||
// https://github.com/OneSignal/OneSignal-Website-SDK | ||
function oneSignalModule (moduleOptions) { | ||
const { nuxt } = this | ||
|
||
const hook = () => { | ||
addOneSignal.call(this, moduleOptions) | ||
} | ||
|
||
if (nuxt.options.mode === 'spa') { | ||
return hook() | ||
} | ||
|
||
nuxt.hook('build:before', hook) | ||
} | ||
|
||
function addOneSignal (moduleOptions) { | ||
const { nuxt, addPlugin } = this | ||
const { publicPath } = getRouteParams(nuxt.options) | ||
|
||
// Merge all options sources | ||
const options: ModuleOptions = defu( | ||
moduleOptions, | ||
nuxt.options.oneSignal, | ||
moduleDefaults | ||
) | ||
|
||
// Define oneSignalSDK usage | ||
/* istanbul ignore next */ | ||
if (options.OneSignalSDK === undefined) { | ||
if (options.cdn) { | ||
// Use OneSignalSDK.js from CDN | ||
options.OneSignalSDK = 'https://cdn.onesignal.com/sdks/OneSignalSDK.js' | ||
} else { | ||
// Use OneSignalSDK.js from Sdk | ||
const OneSignalSDKJS = readFileSync(resolve(__dirname, '../sdk/OneSignalSDK.js')) | ||
const OneSignalSDKHash = hasha(OneSignalSDKJS) | ||
const OneSignalSDKFile = `ons.${OneSignalSDKHash}.js` | ||
|
||
options.OneSignalSDK = joinUrl(publicPath, OneSignalSDKFile) | ||
|
||
nuxt.options.build.plugins.push({ | ||
apply (compiler: any) { | ||
compiler.hooks.emit.tap('nuxt-pwa-onesignal', (compilation: any) => { | ||
compilation.assets[OneSignalSDKFile] = { | ||
source: () => OneSignalSDKJS, | ||
size: () => OneSignalSDKJS.length | ||
} | ||
}) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
// Add the oneSignal SDK script to head | ||
if (!nuxt.options.head.script.find((script: any) => script.hid === 'onesignal')) { | ||
nuxt.options.head.script.push({ | ||
async: true, | ||
src: options.OneSignalSDK, | ||
hid: 'onesignal' | ||
}) | ||
} | ||
|
||
// Adjust manifest for oneSignal | ||
nuxt.options.manifest = options.manifest | ||
|
||
// Adjust swURL option of Workbox for oneSignal | ||
nuxt.options.workbox = options.workbox | ||
|
||
// Provide OneSignalSDKWorker.js and OneSignalSDKUpdaterWorker.js | ||
const makeSW = (name: string, scripts: Array<String>) => { | ||
const workerScript = `importScripts(${scripts.map(i => `'${i}'`).join(', ')})\r\n` | ||
writeFileSync(resolve(nuxt.options.srcDir, 'static', name), workerScript, 'utf-8') | ||
} | ||
|
||
makeSW('OneSignalSDKWorker.js', [].concat(options.importScripts).concat(options.OneSignalSDK)) | ||
makeSW('OneSignalSDKUpdaterWorker.js', [options.OneSignalSDK]) | ||
|
||
// Add OneSignal plugin | ||
addPlugin({ | ||
src: resolve(__dirname, 'runtime/plugin.js'), | ||
ssr: false, | ||
fileName: join('onesignal.js'), | ||
options | ||
}) | ||
} | ||
|
||
oneSignalModule.meta = require('../package.json') | ||
|
||
export default oneSignalModule |
Oops, something went wrong.