diff --git a/.eslintrc.json b/.eslintrc.json index a39ac05..286e9de 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,20 +1,17 @@ { - "env": { - "browser": true, - "es6": true, - "commonjs": true - }, - "extends": "eslint:recommended", - "rules": { - "quotes": [ - "error", - "single" - ] - }, - "parserOptions": { - "sourceType": "module" - }, - "globals": { - "L": true - } -} \ No newline at end of file + "env": { + "browser": true, + "es6": true, + "amd": true, + "commonjs": true + }, + "extends": "eslint:recommended", + "rules": { + "indent": ["error", 2], + "quotes": ["error", "single"], + "no-extra-semi": "off" + }, + "globals": { + "L": true + } +} diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..df64aa5 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,2 @@ +ko_fi: surunzi +open_collective: eruda \ No newline at end of file diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..d47b285 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,27 @@ +name: CI + +on: + workflow_dispatch: + push: + branches: + - 'master' + paths: + - 'src/**/*' + +jobs: + ci: + + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [16.x] + + steps: + - uses: actions/checkout@v2 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v2 + with: + node-version: ${{ matrix.node-version }} + - run: npm i + - run: npm run ci diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..590412d --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,28 @@ +name: Publish to NPM + +on: + workflow_dispatch: + release: + types: [created] + +jobs: + publish: + + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Setup Node + uses: actions/setup-node@v2 + with: + node-version: '18.x' + registry-url: 'https://registry.npmjs.org' + - name: Build eruda-geolocation + run: | + npm i + npm run build + - name: Publish package on NPM + run: npm publish + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} \ No newline at end of file diff --git a/.npmignore b/.npmignore deleted file mode 100644 index 3eaa041..0000000 --- a/.npmignore +++ /dev/null @@ -1,11 +0,0 @@ -src/ -eustia/ -.eslintignore -.eslintrc.json -.gitignore -.npmignore -.prettierignore -.travis.yml -index.html -prettier.config.js -webpack.config.js \ No newline at end of file diff --git a/.prettierignore b/.prettierignore deleted file mode 100644 index f03e6c9..0000000 --- a/.prettierignore +++ /dev/null @@ -1,3 +0,0 @@ -src/util.js -eruda-geolocation.js -eruda-geolocation.min.js \ No newline at end of file diff --git a/.prettierrc.json b/.prettierrc.json new file mode 100644 index 0000000..1ddf8df --- /dev/null +++ b/.prettierrc.json @@ -0,0 +1,5 @@ +{ + "singleQuote": true, + "tabWidth": 2, + "semi": false +} diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 65f2ccf..0000000 --- a/.travis.yml +++ /dev/null @@ -1,5 +0,0 @@ -language: node_js -node_js: - - "8" -script: - - npm run ci \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 230ce1c..83786ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## v2.1.0 (6 Aug 2024) + +* fix: obsolete api + ## v2.0.0 (6 Jan 2020) * feat: theme support \ No newline at end of file diff --git a/README.md b/README.md index 8912558..eb48b53 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,13 @@ # eruda-geolocation [![NPM version][npm-image]][npm-url] -[![Build status][travis-image]][travis-url] +[![Build status][ci-image]][ci-url] [![License][license-image]][npm-url] [npm-image]: https://img.shields.io/npm/v/eruda-geolocation.svg [npm-url]: https://npmjs.org/package/eruda-geolocation -[travis-image]: https://img.shields.io/travis/liriliri/eruda-geolocation.svg -[travis-url]: https://travis-ci.org/liriliri/eruda-geolocation +[ci-image]: https://img.shields.io/github/actions/workflow/status/liriliri/eruda-geolocation/main.yml?branch=master&style=flat-square +[ci-url]: https://github.com/liriliri/eruda-geolocation/actions/workflows/main.yml [license-image]: https://img.shields.io/npm/l/eruda-geolocation.svg Eruda plugin for testing geolocation. @@ -15,7 +15,7 @@ Eruda plugin for testing geolocation. ## Demo Browse it on your phone: -[http://eruda.liriliri.io/?plugin=geolocation](http://eruda.liriliri.io/?plugin=geolocation) +[https://eruda.liriliri.io/?plugin=geolocation](https://eruda.liriliri.io/?plugin=geolocation) ## Install diff --git a/eustia/loadCss.js b/eustia/loadCss.js deleted file mode 100644 index 3adb307..0000000 --- a/eustia/loadCss.js +++ /dev/null @@ -1,10 +0,0 @@ -function exports(src, container) { - var link = document.createElement('link') - - link.rel = 'stylesheet' - link.type = 'text/css' - link.href = src - - container = container || document.head - container.appendChild(link) -} diff --git a/index.html b/index.html index 9f85d11..f38eed0 100644 --- a/index.html +++ b/index.html @@ -1,24 +1,14 @@ - - - - Eruda-geolocation - - - - - - - - + + + + Eruda-geolocation + + + + + + + + \ No newline at end of file diff --git a/package.json b/package.json index 40938d1..77116cc 100644 --- a/package.json +++ b/package.json @@ -1,55 +1,53 @@ { "name": "eruda-geolocation", - "version": "2.0.0", + "version": "2.1.0", "description": "Eruda plugin for testing geolocation", "main": "eruda-geolocation.js", + "browserslist": [ + "since 2015", + "not dead" + ], + "files": [ + "eruda-geolocation.js", + "eruda-geolocation.js.map" + ], "scripts": { - "dev": "webpack-dev-server --host 0.0.0.0", - "build": "webpack && webpack -p", - "ci": "npm run format && npm run lint && npm run build", - "format": "prettier *.js eustia/*.js src/*.js src/style.scss index.html --write", - "lint": "eslint src/**/*.js" + "dev": "webpack-dev-server --host 0.0.0.0 --mode development", + "build": "webpack --mode production", + "ci": "npm run lint && npm run build && npm run es5", + "lint": "eslint src/**/*.js", + "format": "lsla prettier \"src/*.{js,scss}\" \"*.json\" --write", + "es5": "es-check es5 eruda-geolocation.js" }, "keywords": [ "eruda", "plugin", "geolocation" ], - "eustia": { - "files": "src/**/*.js", - "output": "src/util.js", - "format": "commonjs" - }, - "author": "redhoodsu", + "author": "surunzi", "license": "MIT", "bugs": { "url": "https://github.com/liriliri/eruda-geolocation/issues" }, "homepage": "https://github.com/liriliri/eruda-geolocation#readme", "devDependencies": { - "autoprefixer": "^7.2.2", - "babel-core": "^6.26.3", - "babel-loader": "^7.1.5", - "babel-plugin-transform-object-rest-spread": "^6.26.0", - "babel-plugin-transform-runtime": "^6.23.0", - "babel-preset-env": "^1.7.0", - "css-loader": "^0.28.7", - "eruda": "^2.0.0", - "eslint": "^5.4.0", - "eslint-config-standard": "^12.0.0", - "eslint-plugin-import": "^2.14.0", - "eslint-plugin-node": "^7.0.1", - "eslint-plugin-promise": "^4.0.0", - "eslint-plugin-standard": "^3.1.0", - "handlebars": "^4.0.11", - "handlebars-loader": "^1.6.0", - "node-sass": "^4.7.2", - "postcss": "^6.0.14", + "@babel/core": "^7.21.3", + "@babel/plugin-transform-runtime": "^7.21.0", + "@babel/preset-env": "^7.20.2", + "autoprefixer": "^10.4.14", + "babel-loader": "^9.1.2", + "css-loader": "^3.4.2", + "eruda": "^3.2.0", + "es-check": "^7.2.1", + "eslint": "^8.57.0", + "licia": "^1.41.1", + "postcss": "^8.4.21", "postcss-class-prefix": "^0.3.0", - "postcss-loader": "^2.0.9", - "prettier": "^1.14.2", - "sass-loader": "^6.0.6", - "webpack": "^3.10.0", - "webpack-dev-server": "^2.9.7" + "postcss-loader": "^7.0.2", + "sass": "^1.77.8", + "sass-loader": "^14.2.1", + "webpack": "^5.93.0", + "webpack-cli": "^5.1.4", + "webpack-dev-server": "^4.12.0" } } diff --git a/prettier.config.js b/prettier.config.js deleted file mode 100644 index beee66e..0000000 --- a/prettier.config.js +++ /dev/null @@ -1,5 +0,0 @@ -module.exports = { - tabWidth: 2, - semi: false, - singleQuote: true -} diff --git a/src/index.js b/src/index.js index 54b9853..4bffe02 100644 --- a/src/index.js +++ b/src/index.js @@ -1,7 +1,7 @@ -import { loadCss, loadJs } from './util' +const loadJs = require('licia/loadJs') -module.exports = function(eruda) { - let { evalCss } = eruda.util +module.exports = function (eruda) { + const { evalCss } = eruda.util class Geolocation extends eruda.Tool { constructor() { @@ -11,7 +11,9 @@ module.exports = function(eruda) { } init($el, container) { super.init($el, container) - $el.html(require('./template.hbs')()) + $el.html( + '
' + ) this._initMap() this._$info = this._$el.find('.eruda-info') @@ -25,14 +27,14 @@ module.exports = function(eruda) { if (!navigator.geolocation) return navigator.geolocation.getCurrentPosition( - position => { + (position) => { var coords = position.coords, longitude = coords.longitude, latitude = coords.latitude this.setView(latitude, longitude) }, - e => { + (e) => { this.setInfo(e.message) } ) @@ -56,27 +58,21 @@ module.exports = function(eruda) { } _initMap() { loadCss( - 'https://unpkg.com/leaflet@1.3.1/dist/leaflet.css', + 'https://unpkg.com/leaflet@1.9.4/dist/leaflet.css', this._$el.get(0) ) - loadJs('https://unpkg.com/leaflet@1.3.1/dist/leaflet.js', isLoaded => { + loadJs('https://unpkg.com/leaflet@1.9.4/dist/leaflet.js', (isLoaded) => { if (!isLoaded) return this.setInfo('Failed to init map') this.setInfo('Map successfully initialized') - this._map = L.map(this._$el.find('#eruda-map').get(0)).setView( - [39.9, 116.39], - 12 + this._map = L.map(this._$el.find('#eruda-map').get(0), { + center: [39.9, 116.39], + zoom: 2, + }) + L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {}).addTo( + this._map ) - L.tileLayer( - 'https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token={accessToken}', - { - maxZoom: 18, - id: 'mapbox.streets', - accessToken: - 'pk.eyJ1Ijoic3VydW56aSIsImEiOiJjamVqbnk4c2gxN3JzMnltb3ByMXdkbDB5In0.Y6rCE361t15ATgiDb-o3Rw' - } - ).addTo(this._map) this.resetView() }) @@ -85,3 +81,14 @@ module.exports = function(eruda) { return new Geolocation() } + +function loadCss(src, container) { + const link = document.createElement('link') + + link.rel = 'stylesheet' + link.type = 'text/css' + link.href = src + + container = container || document.head + container.appendChild(link) +} diff --git a/src/template.hbs b/src/template.hbs deleted file mode 100644 index f2e3595..0000000 --- a/src/template.hbs +++ /dev/null @@ -1,2 +0,0 @@ -
-
test
\ No newline at end of file diff --git a/src/util.js b/src/util.js deleted file mode 100644 index 456f153..0000000 --- a/src/util.js +++ /dev/null @@ -1,59 +0,0 @@ -// Built by eustia. -"use strict"; - -var _ = {}; - -/* ------------------------------ loadCss ------------------------------ */ _.loadCss = (function () { - function exports(src, container) { - var link = document.createElement('link'); - - link.rel = 'stylesheet'; - link.type = 'text/css'; - link.href = src; - - container = container || document.head - container.appendChild(link); - } - - return exports; -})(); - -/* ------------------------------ loadJs ------------------------------ */ _.loadJs = (function () { - /* Inject script tag into page with given src value. - * - * |Name|Type |Desc | - * |----|--------|---------------| - * |src |string |Script source | - * |cb |function|Onload callback| - * - * ```javascript - * loadJs('main.js', function (isLoaded) - * { - * // Do something... - * }); - * ``` - */ - - /* module - * env: browser - * test: browser - */ - - function exports(src, cb) { - var script = document.createElement('script'); - script.src = src; - script.onload = function() { - var isNotLoaded = - script.readyState && - script.readyState != 'complete' && - script.readyState != 'loaded'; - - cb && cb(!isNotLoaded); - }; - document.body.appendChild(script); - } - - return exports; -})(); - -module.exports = _; \ No newline at end of file diff --git a/webpack.config.js b/webpack.config.js index 6727394..0f1bb7a 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,75 +1,96 @@ const autoprefixer = require('autoprefixer') const postcss = require('postcss') const webpack = require('webpack') +const path = require('path') const pkg = require('./package.json') const classPrefix = require('postcss-class-prefix') +const TerserPlugin = require('terser-webpack-plugin') const banner = pkg.name + ' v' + pkg.version + ' ' + pkg.homepage -var exports = { - devtool: 'source-map', - entry: './src/index.js', - devServer: { - contentBase: './', - port: 3000 - }, - output: { - path: __dirname, - filename: 'eruda-geolocation.js', - publicPath: '/assets/', - library: ['erudaGeolocation'], - libraryTarget: 'umd' - }, - module: { - loaders: [ - { - test: /\.js$/, - exclude: /node_modules/, - use: { - loader: 'babel-loader', - options: { - presets: ['env'], - plugins: ['transform-runtime', 'transform-object-rest-spread'] - } - } +module.exports = (env, argv) => { + const config = { + devtool: 'source-map', + entry: './src/index.js', + devServer: { + static: { + directory: path.join(__dirname, './'), }, - { - test: /\.scss$/, - loaders: [ - 'css-loader', - { - loader: 'postcss-loader', + port: 8080, + }, + output: { + path: __dirname, + filename: 'eruda-geolocation.js', + publicPath: '/assets/', + library: ['erudaGeolocation'], + libraryTarget: 'umd', + }, + module: { + rules: [ + { + test: /\.js$/, + exclude: /node_modules/, + use: { + loader: 'babel-loader', options: { - plugins: function() { - return [ - postcss.plugin('postcss-namespace', function() { - // Add '.dev-tools .tools ' to every selector. - return function(root) { - root.walkRules(function(rule) { - if (!rule.selectors) return rule + sourceType: 'unambiguous', + presets: ['@babel/preset-env'], + plugins: ['@babel/plugin-transform-runtime'], + }, + }, + }, + { + test: /\.scss$/, + use: [ + 'css-loader', + { + loader: 'postcss-loader', + options: { + postcssOptions: { + plugins: [ + postcss.plugin('postcss-namespace', function () { + // Add '.dev-tools .tools ' to every selector. + return function (root) { + root.walkRules(function (rule) { + if (!rule.selectors) return rule - rule.selectors = rule.selectors.map(function(selector) { - return '.dev-tools .tools ' + selector + rule.selectors = rule.selectors.map(function ( + selector + ) { + return '.dev-tools .tools ' + selector + }) }) - }) - } - }), - classPrefix('eruda-'), - autoprefixer - ] - } - } + } + }), + classPrefix('eruda-'), + autoprefixer, + ], + }, + }, + }, + 'sass-loader', + ], + }, + ], + }, + plugins: [new webpack.BannerPlugin(banner)], + } + + if (argv.mode === 'production') { + config.optimization = { + minimize: true, + minimizer: [ + new TerserPlugin({ + terserOptions: { + format: { + comments: false, + }, }, - 'sass-loader' - ] - }, - { - test: /\.hbs$/, - loader: 'handlebars-loader' - } - ] - }, - plugins: [new webpack.BannerPlugin(banner)] -} + extractComments: false, + }), + ], + } + } -module.exports = exports + return config +}