diff --git a/.config/karma.conf.js b/.config/karma.conf.js new file mode 100644 index 0000000..2cbc8fe --- /dev/null +++ b/.config/karma.conf.js @@ -0,0 +1,65 @@ +/*global module: false, require: false */ + +module.exports = function (config) { + 'use strict'; + + const mainJSFile = require('../package.json').main; + + config.set({ + basePath: '../', + frameworks: [ + 'mocha', + 'sinon-chai' + ], + port: 9876, + logLevel: config.LOG_INFO, + autoWatch: false, + browsers: [ + 'ChromiumHeadless' + ], + singleRun: false, + reporters: [ + 'progress', + 'coverage' + ], + preprocessors: { + [mainJSFile]: [ + 'coverage' + ] + }, + coverageReporter: { + dir: 'coverage', + reporters: [ + { + type: 'lcov', + subdir: '.' + } + ], + check: { + global: { + statements: 100, + functions: 100, + lines: 100, + branches: 100 + } + } + }, + customLaunchers: { + ChromeHeadlessCI: { + base: 'ChromeHeadless', + flags: [ + '--no-sandbox' + ] + } + }, + files: [ + '**/jquery/dist/jquery.js', + '**/angular/angular.js', + '**/angular-mocks/angular-mocks.js', + 'test/helpers/**/*.js', + '**/simple-web-notification/web-notification.js', + mainJSFile, + 'test/spec/**/*.js' + ] + }); +}; diff --git a/.eslintrc.js b/.eslintrc.js index 81f5f5a..5437e34 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,5 +1,33 @@ -'use strict'; - -const commons = require('js-project-commons'); - -module.exports = commons.lint.eslint.web; +module.exports = { + 'env': { + 'browser': true, + 'commonjs': true, + 'es2021': true, + 'mocha': true + }, + 'globals': { + 'angular': 'readonly' + }, + 'extends': 'eslint:recommended', + 'parserOptions': { + 'ecmaVersion': 13 + }, + 'rules': { + 'indent': [ + 'error', + 4 + ], + 'linebreak-style': [ + 'error', + 'unix' + ], + 'quotes': [ + 'error', + 'single' + ], + 'semi': [ + 'error', + 'always' + ] + } +}; diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 131e581..336c1e0 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -18,7 +18,7 @@ Your pull request build must pass (the build will run automatically).
You can run the following command locally to ensure the build will pass: ````sh -npm run build +npm run test ```` * This library is using multiple code inspection tools to validate certain level of standards.
The configuration is part of the repository and you can set your favorite IDE using that configuration.
You can run the following command locally to ensure the code inspection passes: diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8b84c03..6681b15 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,16 +11,14 @@ jobs: steps: - name: Checkout uses: actions/checkout@v2 - - name: Install - uses: ianwalter/puppeteer@v2.0.0 - with: - args: npm install + - name: Install Chrome + uses: browser-actions/setup-chrome@latest + - name: Install Dependencies + run: npm install - name: Run CI - uses: ianwalter/puppeteer@v2.0.0 - with: - args: npm test + run: npm test - name: Coveralls uses: coverallsapp/github-action@master with: github-token: ${{ secrets.GITHUB_TOKEN }} - path-to-lcov: './target/coverage/report/lcov.info' + path-to-lcov: './coverage/lcov.info' diff --git a/.gitignore b/.gitignore index c3a39cf..49a55d2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,8 @@ -.idea -.c9 target .temp node_modules bower_components npm-debug.log +package-lock.json +.nyc_output +coverage diff --git a/.jscs.json b/.jscs.json deleted file mode 100644 index 708e58b..0000000 --- a/.jscs.json +++ /dev/null @@ -1,209 +0,0 @@ -{ - "disallowDanglingUnderscores": { - "allExcept": [ - "__dirname" - ] - }, - "disallowEmptyBlocks": true, - "disallowImplicitTypeConversion": [ - "numeric", - "boolean", - "binary", - "string" - ], - "disallowKeywordsInComments": [ - "TODO", - "FIXME" - ], - "disallowKeywordsOnNewLine": [ - "else" - ], - "disallowKeywords": [ - "with" - ], - "disallowMixedSpacesAndTabs": true, - "disallowMultipleLineBreaks": true, - "disallowMultipleLineStrings": true, - "disallowMultipleSpaces": true, - "disallowNestedTernaries": true, - "disallowNewlineBeforeBlockStatements": true, - "disallowPaddingNewlinesBeforeKeywords": [ - "else", - "case", - "catch" - ], - "disallowPaddingNewlinesInBlocks": true, - "disallowSpaceAfterLineComment": true, - "disallowSpaceAfterObjectKeys": true, - "disallowSpaceBeforeBinaryOperators": [ - "," - ], - "disallowSpaceBeforeComma": true, - "disallowSpaceBeforePostfixUnaryOperators": [ - "++", - "--" - ], - "disallowSpaceBeforeSemicolon": true, - "disallowSpacesInCallExpression": true, - "disallowSpacesInFunctionDeclaration": { - "beforeOpeningRoundBrace": true - }, - "disallowSpacesInNamedFunctionExpression": { - "beforeOpeningRoundBrace": true - }, - "disallowSpacesInsideImportedObjectBraces": true, - "disallowSpacesInsideObjectBrackets": "all", - "disallowSpacesInsideParentheses": true, - "disallowSpacesInsideParenthesizedExpression": true, - "disallowSpacesInsideTemplateStringPlaceholders": true, - "disallowTabs": true, - "disallowTrailingComma": true, - "disallowTrailingWhitespace": true, - "disallowUnusedParams": true, - "disallowUnusedVariables": true, - "disallowYodaConditions": true, - "jsDoc": { - "checkParamExistence": true, - "checkParamNames": true, - "requireParamTypes": true, - "checkReturnTypes": true, - "checkRedundantReturns": true, - "requireReturnTypes": true, - "checkTypes": true, - "requireHyphenBeforeDescription": true, - "requireNewlineAfterDescription": true, - "requireParamDescription": true, - "requireReturnDescription": true - }, - "maximumLineLength": 400, - "requireBlocksOnNewline": true, - "requireCamelCaseOrUpperCaseIdentifiers": true, - "requireCapitalizedConstructors": true, - "requireCommaBeforeLineBreak": true, - "requireCurlyBraces": [ - "if", - "else", - "for", - "while", - "do", - "try", - "catch" - ], - "requireDollarBeforejQueryAssignment": true, - "requireKeywordsOnNewLine": [ - "switch", - "do", - "try", - "for" - ], - "requireLineBreakAfterVariableAssignment": true, - "requireLineFeedAtFileEnd": true, - "requireNamedUnassignedFunctions": true, - "requireObjectKeysOnNewLine": true, - "requireOperatorBeforeLineBreak": [ - "?", - "=", - "+", - "-", - "/", - "*", - "==", - "===", - "!=", - "!==", - ">", - ">=", - "<", - "<=" - ], - "requirePaddingNewLinesAfterUseStrict": true, - "requirePaddingNewLinesBeforeExport": true, - "requirePaddingNewLinesInObjects": true, - "requireParenthesesAroundArrowParam": true, - "requireParenthesesAroundIIFE": true, - "requireSemicolons": true, - "requireSpaceAfterBinaryOperators": [ - "=", - ",", - "+", - "-", - "/", - "*", - "==", - "===", - "!=", - "!==" - ], - "requireSpaceAfterComma": true, - "requireSpaceAfterKeywords": [ - "do", - "for", - "if", - "else", - "switch", - "case", - "try", - "catch", - "void", - "while", - "with", - "return", - "typeof", - "function" - ], - "requireSpaceBeforeBinaryOperators": [ - "=", - "+", - "-", - "/", - "*", - "==", - "===", - "!=", - "!==" - ], - "requireSpaceBeforeBlockStatements": true, - "requireSpaceBeforeDestructuredValues": true, - "requireSpaceBeforeKeywords": [], - "requireSpaceBeforeObjectValues": true, - "requireSpaceBetweenArguments": true, - "requireSpacesInAnonymousFunctionExpression": { - "beforeOpeningRoundBrace": true, - "beforeOpeningCurlyBrace": true, - "allExcept": [ - "shorthand" - ] - }, - "requireSpacesInConditionalExpression": { - "afterTest": true, - "beforeConsequent": true, - "afterConsequent": true, - "beforeAlternate": true - }, - "requireSpacesInForStatement": true, - "requireSpacesInFunctionDeclaration": { - "beforeOpeningCurlyBrace": true - }, - "requireSpacesInFunctionExpression": { - "beforeOpeningCurlyBrace": true - }, - "requireSpacesInFunction": { - "beforeOpeningCurlyBrace": true - }, - "requireSpacesInGenerator": { - "beforeStar": true, - "afterStar": true - }, - "requireSpacesInNamedFunctionExpression": { - "beforeOpeningCurlyBrace": true - }, - "safeContextKeyword": [ - "self" - ], - "validateLineBreaks": "LF", - "validateNewlineAfterArrayElements": { - "maximum": 5 - }, - "validateParameterSeparator": ", ", - "validateQuoteMarks": "'" -} diff --git a/.jshintrc b/.jshintrc deleted file mode 100644 index 4896e98..0000000 --- a/.jshintrc +++ /dev/null @@ -1,4 +0,0 @@ -{ - "extends": "./project/config/jshintrc-common.json", - "browser": true -} diff --git a/.jslintrc b/.jslintrc deleted file mode 100644 index 291c44d..0000000 --- a/.jslintrc +++ /dev/null @@ -1,31 +0,0 @@ -{ - "ass": false, - "bitwise": false, - "browser": true, - "closure": false, - "continue": false, - "couch": false, - "debug": false, - "devel": false, - "eqeq": false, - "evil": false, - "forin": false, - "indent": 4, - "maxerr": 50, - "maxlen": false, - "newcap": false, - "node": false, - "nomen": false, - "passfail": false, - "plusplus": true, - "predef": [], - "regexp": false, - "rhino": false, - "sloppy": false, - "stupid": false, - "sub": false, - "todo": false, - "unparam": false, - "vars": true, - "white": false -} diff --git a/.npmignore b/.npmignore index e9f733a..7b0fc8a 100644 --- a/.npmignore +++ b/.npmignore @@ -1,10 +1,8 @@ -.idea -.c9 target .temp -.travis.yml -.atom.*.yml -Gruntfile.js +.nyc_output +.config +coverage bower_components .github test diff --git a/.stylelintrc.json b/.stylelintrc.json new file mode 100644 index 0000000..40db42c --- /dev/null +++ b/.stylelintrc.json @@ -0,0 +1,3 @@ +{ + "extends": "stylelint-config-standard" +} diff --git a/Gruntfile.js b/Gruntfile.js deleted file mode 100644 index d4de73c..0000000 --- a/Gruntfile.js +++ /dev/null @@ -1,16 +0,0 @@ -'use strict'; - -/*jslint nomen: true*/ -//jscs:disable disallowDanglingUnderscores -/*eslint-disable no-underscore-dangle*/ - -module.exports = function (grunt) { - const commons = require('js-project-commons'); - - commons.grunt.config.initConfig(grunt, { - buildConfig: { - projectRoot: __dirname, - nodeProject: false - } - }); -}; diff --git a/package.json b/package.json index 310e8a0..772fd56 100644 --- a/package.json +++ b/package.json @@ -26,20 +26,15 @@ "example": "example" }, "scripts": { - "test": "grunt test", - "clean": "grunt cleanup", - "lint": "grunt lint", - "docs": "grunt docs", - "format": "grunt format", - "build": "grunt build", - "jstest": "grunt jstest", - "postpublish": "grunt post-publish", - "grunt": "grunt" - }, - "husky": { - "hooks": { - "pre-push": "npm run build" - } + "clean": "rm -Rf ./.nyc_output ./coverage", + "format": "js-beautify --config ./.jsbeautifyrc --file ./*.js ./test/**/*.js", + "lint-js": "eslint ./*.js ./test/**/*.js", + "lint-css": "stylelint --allow-empty-input ./docs/**/*.css", + "lint": "npm run lint-js && npm run lint-css", + "jstest": "karma start --single-run", + "docs": "jsdoc2md ./angular-web-notification.js > ./docs/api.md", + "test": "npm run clean && npm run format && npm run lint && npm run docs && npm run jstest", + "postpublish": "git fetch && git pull" }, "dependencies": { "angular": "^1", @@ -47,22 +42,20 @@ }, "devDependencies": { "angular-mocks": "^1", - "chai": "latest", - "grunt": "latest", - "grunt-cli": "latest", - "grunt-karma": "latest", - "husky": "latest", - "jquery": "latest", - "js-project-commons": "latest", - "karma": "latest", - "karma-chrome-launcher": "latest", - "karma-cli": "latest", - "karma-coverage": "latest", - "karma-mocha": "latest", - "karma-sinon-chai": "latest", - "lolex": "latest", - "mocha": "latest", - "sinon": "latest", - "sinon-chai": "latest" + "chai": "^4", + "eslint": "^8", + "jquery": "^3", + "js-beautify": "^1", + "jsdoc-to-markdown": "^7", + "karma": "^6", + "karma-chrome-launcher": "^3", + "karma-coverage": "^2", + "karma-mocha": "^2", + "karma-sinon-chai": "^2", + "mocha": "^9", + "sinon": "^11", + "sinon-chai": "^3", + "stylelint": "^13", + "stylelint-config-standard": "^22" } } diff --git a/project/config/README-footer-template.md b/project/config/README-footer-template.md deleted file mode 100644 index a78442a..0000000 --- a/project/config/README-footer-template.md +++ /dev/null @@ -1,13 +0,0 @@ -## API Documentation -See full docs at: [API Docs](docs/api.md) - -## Contributing -See [contributing guide](.github/CONTRIBUTING.md) - - -## Release History - -{"gitdown": "include", "file": "../../docs/CHANGELOG.md"} - -## License -Developed by Sagie Gur-Ari and licensed under the Apache 2 open source license. \ No newline at end of file diff --git a/project/config/README-template.md b/project/config/README-template.md deleted file mode 100644 index 56fe4a2..0000000 --- a/project/config/README-template.md +++ /dev/null @@ -1,145 +0,0 @@ -# {"gitdown": "gitinfo", "name": "name"} - -[![NPM Version](http://img.shields.io/npm/v/{"gitdown": "gitinfo", "name": "name"}.svg?style=flat)](https://www.npmjs.org/package/{"gitdown": "gitinfo", "name": "name"}) [![CI](https://github.com/{"gitdown": "gitinfo", "name": "username"}/{"gitdown": "gitinfo", "name": "name"}/workflows/CI/badge.svg?branch=master)](https://github.com/{"gitdown": "gitinfo", "name": "username"}/{"gitdown": "gitinfo", "name": "name"}/actions) [![Coverage Status](https://coveralls.io/repos/{"gitdown": "gitinfo", "name": "username"}/{"gitdown": "gitinfo", "name": "name"}/badge.svg)](https://coveralls.io/r/{"gitdown": "gitinfo", "name": "username"}/{"gitdown": "gitinfo", "name": "name"}) [![Known Vulnerabilities](https://snyk.io/test/github/{"gitdown": "gitinfo", "name": "username"}/{"gitdown": "gitinfo", "name": "name"}/badge.svg)](https://snyk.io/test/github/{"gitdown": "gitinfo", "name": "username"}/{"gitdown": "gitinfo", "name": "name"}) [![Inline docs](http://inch-ci.org/github/{"gitdown": "gitinfo", "name": "username"}/{"gitdown": "gitinfo", "name": "name"}.svg?branch=master)](http://inch-ci.org/github/{"gitdown": "gitinfo", "name": "username"}/{"gitdown": "gitinfo", "name": "name"}) [![License](https://img.shields.io/npm/l/{"gitdown": "gitinfo", "name": "name"}.svg?style=flat)](https://github.com/{"gitdown": "gitinfo", "name": "username"}/{"gitdown": "gitinfo", "name": "name"}/blob/master/LICENSE) - -> Web Notifications AngularJS Service - -* [Overview](#overview) -* [Demo](https://sagiegurari.github.io/angular-web-notification/) -* [Usage](#usage) -* [Installation](#installation) -* [Limitations](#limitations) -* [API Documentation](docs/api.md) -* [Contributing](.github/CONTRIBUTING.md) -* [Release History](#history) -* [License](#license) - - -## Overview -The {"gitdown": "gitinfo", "name": "name"} is an angular service wrapper for the web notifications API. - -It is using the [simple-web-notification](https://github.com/sagiegurari/simple-web-notification) library which provides a simple and easy notification API which works across browsers and provides automatic permission handling. - -See [W3 Specification](https://dvcs.w3.org/hg/notifications/raw-file/tip/Overview.html) and [simple-web-notification](https://github.com/sagiegurari/simple-web-notification) for more information. - -### Angular 2 and Up -For angular 2 and above, it is recommanded to use the [simple-web-notification](https://github.com/sagiegurari/simple-web-notification) library directly.
-It provides the same API and it is not dependend on angular. - -## Demo -[Live Demo](https://sagiegurari.github.io/angular-web-notification/) - - -## Usage -In order to use the angular service you first must add the relevant dependencies: - -```html - - - -``` - -Next you must define it as a dependency in your main angular module as follows: - -```js -angular.module('exampleApp', [ - 'angular-web-notification' -]); -``` - -Now you can inject and use the service into your modules (directives/services/...), for example: - -```js -angular.module('exampleApp').directive('showButton', ['webNotification', function (webNotification) { -return { - ... - link: function (scope, element) { - element.on('click', function onClick() { - webNotification.showNotification('Example Notification', { - body: 'Notification Text...', - icon: 'my-icon.ico', - onClick: function onNotificationClicked() { - console.log('Notification clicked.'); - }, - autoClose: 4000 //auto close the notification after 4 seconds (you can manually close it via hide function) - }, function onShow(error, hide) { - if (error) { - window.alert('Unable to show notification: ' + error.message); - } else { - console.log('Notification Shown.'); - - setTimeout(function hideNotification() { - console.log('Hiding notification....'); - hide(); //manually close the notification (you can skip this if you use the autoClose option) - }, 5000); - } - }); - }); - } -}; -}]); -``` - -In case you wish to use service worker web notifications, you must provide the serviceWorkerRegistration in the options as follows: - -````js -//Get the service worker registeration object at the startup of the application. -//This is an aysnc operation so you should not try to use it before the promise is finished. -var serviceWorkerRegistration; -navigator.serviceWorker.register('service-worker.js').then(function(registration) { - serviceWorkerRegistration = registration; -}); - -//when setting on even handlers in different areas of the application, use that registration object instance (must be done after the registration is available) -element.on('click', function onClick() { - webNotification.showNotification('Example Notification', { - serviceWorkerRegistration: serviceWorkerRegistration, - body: 'Notification Text...', - icon: 'my-icon.ico', - actions: [ - { - action: 'Start', - title: 'Start' - }, - { - action: 'Stop', - title: 'Stop' - } - ], - autoClose: 4000 //auto close the notification after 4 seconds (you can manually close it via hide function) - }, function onShow(error, hide) { - if (error) { - window.alert('Unable to show notification: ' + error.message); - } else { - console.log('Notification Shown.'); - - setTimeout(function hideNotification() { - console.log('Hiding notification....'); - hide(); //manually close the notification (you can skip this if you use the autoClose option) - }, 5000); - } - }); -}); -```` - - -## Installation -Run npm install in your project as follows: - -```sh -npm install --save {"gitdown": "gitinfo", "name": "name"} -``` - -Or if you are using bower, you can install it as follows: - -```sh -bower install {"gitdown": "gitinfo", "name": "name"} --save -``` - - -## Limitations -The web notifications API is not fully supported in all browsers. - -Please see [supported browser versions](http://caniuse.com/#feat=notifications) for more information on the official spec support. - -{"gitdown": "include", "file": "./README-footer-template.md"} diff --git a/project/config/jshintrc-common.json b/project/config/jshintrc-common.json deleted file mode 100644 index b899787..0000000 --- a/project/config/jshintrc-common.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "bitwise": true, - "curly": true, - "eqeqeq": true, - "esversion": 6, - "forin": true, - "freeze": true, - "futurehostile": true, - "latedef": true, - "maxcomplexity": 8, - "maxdepth": 5, - "maxerr": 100, - "maxparams": 5, - "maxstatements": 50, - "noarg": true, - "nocomma": false, - "nonbsp": true, - "nonew": true, - "singleGroups": false, - "strict": true, - "undef": true, - "unused": true, - "varstmt": false -} diff --git a/project/config/karma.conf.js b/project/config/karma.conf.js deleted file mode 100644 index b420523..0000000 --- a/project/config/karma.conf.js +++ /dev/null @@ -1,20 +0,0 @@ -/*global module: false, require: false */ - -module.exports = function (config) { - 'use strict'; - - const mainJSFile = require('../../package.json').main; - const commons = require('js-project-commons'); - - commons.tools.karma(config, { - files: [ - '**/jquery/dist/jquery.js', - '**/angular/angular.js', - '**/angular-mocks/angular-mocks.js', - 'test/helpers/**/*.js', - '**/simple-web-notification/web-notification.js', - mainJSFile, - 'test/spec/**/*.js' - ] - }, mainJSFile); -}; diff --git a/stylelint.config.js b/stylelint.config.js deleted file mode 100644 index a1e5863..0000000 --- a/stylelint.config.js +++ /dev/null @@ -1,5 +0,0 @@ -'use strict'; - -const commons = require('js-project-commons'); - -module.exports = commons.lint.stylelint;