From 2f41a83eabe5ca7cadf5d2a795ab39aa7abf9760 Mon Sep 17 00:00:00 2001 From: piano-analytics Date: Thu, 22 Sep 2022 17:38:05 +0200 Subject: [PATCH] 6.5.0 --- CHANGELOG.md | 4 ++++ Gruntfile.js | 4 ++++ package.json | 27 ++++++++++++++------------ rollup.config-react-native.js | 25 ++++++++++++++++++++++++ src/config.js | 2 +- src/utils/request/http-react-native.js | 21 ++++++++++++++++++++ 6 files changed, 70 insertions(+), 13 deletions(-) create mode 100644 rollup.config-react-native.js create mode 100644 src/utils/request/http-react-native.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 0bb87b6..0430174 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 6.5.0 +### Added or Changed +- Added React Native compatibility + ## 6.4.1 ### Added or Changed - Fix version number diff --git a/Gruntfile.js b/Gruntfile.js index 915e2a7..0d4cea3 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -11,6 +11,10 @@ module.exports = function (grunt) { src: 'src/utils/request/http-browserless.js', dest: 'src/utils/request/http.js' }, + reactnative: { + src: 'src/utils/request/http-react-native.js', + dest: 'src/utils/request/http.js' + }, browser: { src: 'src/utils/request/http-browser.js', dest: 'src/utils/request/http.js' diff --git a/package.json b/package.json index 3350fd8..d4a64b5 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,11 @@ { "name": "piano-analytics-js", "description": "JavaScript library for Piano Analytics", - "version": "6.4.1", + "version": "6.5.0", "main": "dist/browserless/piano-analytics.cjs.js", "module": "dist/browserless/piano-analytics.esm.js", "browser": "dist/browser/piano-analytics.umd.js", + "react-native": "dist/browserless/piano-analytics.react-native.umd.js", "license": "MIT", "author": { "name": "Atinternet A Piano Company", @@ -22,34 +23,36 @@ "scripts": { "prebuild:browser": "grunt copy:browser", "prebuild:browserless": "grunt copy:browserless", - "postbuild": "grunt copy:clean", - "rollup:browser": "npm run prebuild:browser && rollup --config rollup.config-browser.js && npm run postbuild", - "rollup:browserless": "npm run prebuild:browserless && rollup --config rollup.config-browserless.js && npm run postbuild", - "build": "npm run rollup:browser --omit=dev && npm run rollup:browserless --omit=dev", + "prebuild:reactnative": "grunt copy:reactnative", + "clean": "grunt copy:clean", + "rollup:browser": "npm run prebuild:browser && rollup --config rollup.config-browser.js && npm run clean", + "rollup:browserless": "npm run prebuild:browserless && rollup --config rollup.config-browserless.js && npm run clean", + "rollup:reactnative": "npm run prebuild:reactnative && rollup --config rollup.config-react-native.js && npm run clean", + "build": "npm run rollup:browser --omit=dev && npm run rollup:browserless --omit=dev && npm run rollup:reactnative --omit=dev", "test": "npm run test:browser && npm run test:browserless", "test:browser": "npm run rollup:browser && karma start", "test:browserless": "npm run rollup:browserless && node test/browserless.run.js" }, "devDependencies": { - "@babel/core": "7.18.10", - "@babel/preset-env": "7.18.10", + "@babel/core": "7.19.1", + "@babel/preset-env": "7.19.1", "@rollup/plugin-babel": "5.3.1", "chai": "4.3.6", - "eslint": "8.21.0", + "eslint": "8.23.1", "eslint-config-standard": "17.0.0", "eslint-plugin-import": "2.26.0", "eslint-plugin-node": "11.1.0", - "eslint-plugin-promise": "6.0.0", + "eslint-plugin-promise": "6.0.1", "grunt": "1.5.3", "grunt-contrib-copy": "^1.0.0", - "karma": "6.4.0", + "karma": "6.4.1", "karma-chai": "0.1.0", "karma-chrome-launcher": "3.1.1", "karma-mocha": "2.0.1", "load-grunt-tasks": "5.1.0", "mocha": "10.0.0", - "puppeteer": "16.1.0", - "rollup": "2.77.3", + "puppeteer": "18.0.4", + "rollup": "2.79.1", "rollup-plugin-eslint": "7.0.0", "rollup-plugin-replace": "2.2.0", "rollup-plugin-uglify": "6.0.4" diff --git a/rollup.config-react-native.js b/rollup.config-react-native.js new file mode 100644 index 0000000..aadc86b --- /dev/null +++ b/rollup.config-react-native.js @@ -0,0 +1,25 @@ +import {babel} from '@rollup/plugin-babel'; +import {eslint} from 'rollup-plugin-eslint'; +import {uglify} from 'rollup-plugin-uglify'; +import replace from 'rollup-plugin-replace'; + +export default { + input: 'src/exports.js', + plugins: [ + eslint({ + configFile: './src/.eslintrc.json' + }), + replace({ + BUILD_BROWSER: 'false' + }), + babel({babelHelpers: 'bundled'}), + process.env.NODE_ENV === 'production' && uglify() + ], + output: [ + { + file: 'dist/browserless/piano-analytics.react-native.umd.js', + format: 'umd', + name: 'pianoAnalytics' + } + ] +}; diff --git a/src/config.js b/src/config.js index cff6c9f..8aaf76a 100644 --- a/src/config.js +++ b/src/config.js @@ -23,7 +23,7 @@ export default { ], 'storageVisitor': 'pa_vid', 'storageUser': 'pa_user', - 'version': '6.4.1', + 'version': '6.5.0', 'minHeartbeat': 5, 'minBufferingHeartbeat': 1, 'queueVarName': '_paq', diff --git a/src/utils/request/http-react-native.js b/src/utils/request/http-react-native.js new file mode 100644 index 0000000..0bb8f1b --- /dev/null +++ b/src/utils/request/http-react-native.js @@ -0,0 +1,21 @@ +const http = { + post: function (url, data, callback) { + return fetch(url, { + method: 'POST', + headers: { + Accept: 'application/json', + 'Content-Type': 'application/json', + 'Content-Length': data.length + }, + body: data + }) + .then((data) => { + callback && callback(url, data); + }) + .catch((error) => { + console.error(error); + }); + } +}; + +export {http};