-
Notifications
You must be signed in to change notification settings - Fork 1
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 #1 from localForage-extensions/rollup
chore: use es6 & rollup
- Loading branch information
Showing
17 changed files
with
286 additions
and
178 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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"presets": [ "es2015-rollup" ] | ||
} |
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,18 @@ | ||
{ | ||
"parser": "babel-eslint", | ||
"extends": "eslint:recommended", | ||
"env": { | ||
"node": true, | ||
"mocha": true | ||
}, | ||
"rules":{ | ||
"no-console": 0 | ||
}, | ||
"globals": { | ||
"localforage": true, | ||
"Promise": true, | ||
"console": true, | ||
"self": true, | ||
"System": true | ||
} | ||
} |
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,3 +1,5 @@ | ||
dist | ||
build | ||
bower_components | ||
node_modules | ||
components |
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,31 @@ | ||
{ | ||
"esnext": true, | ||
"disallowSpacesInAnonymousFunctionExpression": { | ||
"beforeOpeningRoundBrace": true | ||
}, | ||
"disallowTrailingComma": true, | ||
"requireBlocksOnNewline": true, | ||
"requireLineFeedAtFileEnd": true, | ||
"requireSpaceAfterKeywords": [ | ||
"if", | ||
"else", | ||
"for", | ||
"while", | ||
"do", | ||
"switch", | ||
"return", | ||
"try", | ||
"catch" | ||
], | ||
"requireSpaceBeforeBlockStatements": true, | ||
"requireSpacesInConditionalExpression": true, | ||
"requireSpacesInFunctionExpression": { | ||
"beforeOpeningCurlyBrace": true | ||
}, | ||
"safeContextKeyword": ["globalObject", "self"], | ||
"validateQuoteMarks": { | ||
"escape": true, | ||
"mark": "'" | ||
}, | ||
"validateIndentation": 4 | ||
} |
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,32 @@ | ||
{ | ||
"asi": false, | ||
"bitwise": true, | ||
"browser": true, | ||
"curly": true, | ||
"eqeqeq": true, | ||
"eqnull": true, | ||
"esnext": true, | ||
"immed": true, | ||
"latedef": true, | ||
"newcap": true, | ||
"noarg": true, | ||
"nonew": true, | ||
"quotmark": false, | ||
"strict": false, | ||
"trailing": false, | ||
"undef": true, | ||
"unused": true, | ||
|
||
"validthis": true, | ||
|
||
"globals": { | ||
"console": true, | ||
"define": true, | ||
"localforage": true, | ||
"module": true, | ||
"Promise": true, | ||
"require": true, | ||
"self": true, | ||
"System": true | ||
} | ||
} |
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,4 @@ | ||
language: node_js | ||
node_js: | ||
- "4.0" | ||
- "5.0" |
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
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,83 @@ | ||
// // you can access the serializer and thedrivers by: | ||
// import { getSerializerPromise, getDriverPromise } from './utils'; | ||
|
||
// getSerializerPromise(); | ||
// getDriverPromise(localforage.WEBSQL); | ||
|
||
function handleMethodCall(localforageInstance, methodName, args) { | ||
return localforageInstance.ready() | ||
.then(function () { | ||
console.log('Invoking ' + methodName + ' with arguments: ', args); | ||
var promise = localforageInstance._baseMethods[methodName].apply(localforageInstance, args); | ||
promise.then(function(result) { | ||
console.log('Invoking ' + methodName + ' resolved with: ', result); | ||
}, function(err) { | ||
console.log('Invoking ' + methodName + ' rejected with: ', err); | ||
}); | ||
return promise; | ||
}); | ||
} | ||
|
||
// wraps the localForage methods of the WrappedLibraryMethods array and | ||
// allows you to execute code before & after their invocation | ||
function wireUpMethods(localforageInstance) { | ||
var WrappedLibraryMethods = [ | ||
'clear', | ||
'getItem', | ||
'iterate', | ||
'key', | ||
'keys', | ||
'length', | ||
'removeItem', | ||
'setItem' | ||
]; | ||
|
||
function wireUpMethod(localforageInstance, methodName) { | ||
localforageInstance._baseMethods = localforageInstance._baseMethods || {}; | ||
localforageInstance._baseMethods[methodName] = localforageInstance[methodName]; | ||
localforageInstance[methodName] = function () { | ||
return handleMethodCall(this, methodName, arguments); | ||
}; | ||
} | ||
|
||
for (var i = 0, len = WrappedLibraryMethods.length; i < len; i++) { | ||
var methodName = WrappedLibraryMethods[i]; | ||
wireUpMethod(localforageInstance, methodName); | ||
} | ||
} | ||
|
||
// place your plugin initialization logic here | ||
// useful in case that you need to preserve a state | ||
function setup(localforageInstance) { | ||
if (!localforageInstance._pluginPrivateVariables) { | ||
localforageInstance._pluginPrivateVariables = { | ||
listOfImportantThings: [], | ||
callCount: 0 | ||
}; | ||
|
||
// in case you need to observe the invocation of some methods | ||
wireUpMethods(localforageInstance); | ||
} | ||
} | ||
|
||
// this will be available as `localforage.pluginMethod('test');` | ||
export function localforagePluginBoilerplate(/*option*/) { | ||
var localforageInstance = this; | ||
|
||
// this will initialize your plugin lazily | ||
// after the first invocation of your method | ||
setup(localforageInstance); | ||
|
||
console.log('Hello world from the plugin method!'); | ||
return Promise.resolve('Hello world result!'); | ||
} | ||
|
||
// add your plugin method to every localForage instance | ||
export function extendPrototype(localforage) { | ||
var localforagePrototype = Object.getPrototypeOf(localforage); | ||
if (localforagePrototype) { | ||
localforagePrototype.pluginMethod = localforagePluginBoilerplate; | ||
} | ||
} | ||
|
||
export var extendPrototypeResult = extendPrototype(localforage); |
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,26 @@ | ||
export function getSerializerPromise(localForageInstance) { | ||
if (getSerializerPromise.result) { | ||
return getSerializerPromise.result; | ||
} | ||
if (!localForageInstance || typeof localForageInstance.getSerializer !== 'function') { | ||
Promise.reject(new Error( | ||
'localforage.getSerializer() was not available! ' + | ||
'localforage v1.4+ is required!')); | ||
} | ||
getSerializerPromise.result = localForageInstance.getSerializer(); | ||
return getSerializerPromise.result; | ||
} | ||
|
||
export function getDriverPromise(localForageInstance, driverName) { | ||
getDriverPromise.result = getDriverPromise.result || {}; | ||
if (getDriverPromise.result[driverName]) { | ||
return getDriverPromise.result[driverName]; | ||
} | ||
if (!localForageInstance || typeof localForageInstance.getDriver !== 'function') { | ||
Promise.reject(new Error( | ||
'localforage.getDriver() was not available! ' + | ||
'localforage v1.4+ is required!')); | ||
} | ||
getDriverPromise.result[driverName] = localForageInstance.getDriver(driverName); | ||
return getDriverPromise.result[driverName]; | ||
} |
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,41 +1,41 @@ | ||
{ | ||
"name": "localforage-plugin-boilerplate", | ||
"author": "Thodoris Greasidis", | ||
"description": "A simple plugin boilerplate for localForage.", | ||
"keywords": [ | ||
"localforage", | ||
"plugin" | ||
], | ||
"version": "1.0.0", | ||
"description": "A simple plugin boilerplate for localForage.", | ||
"homepage": "https://github.com/localForage-extensions/localForage-plugin-boilerplate", | ||
"main": "src/localforage-plugin-boilerplate.js", | ||
"jsnext:main": "dist/localforage-plugin-boilerplate.es6.js", | ||
"scripts": { | ||
"prebuild": "eslint lib test", | ||
"build": "rollup -c rollup.config.umd.js && rollup -c rollup.config.es6.js", | ||
"pretest": "rollup -c rollup.config.test.js", | ||
"test": "mocha build/test-bundle.js", | ||
"prepublish": "npm run build && npm test" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/localForage-extensions/localForage-plugin-boilerplate.git" | ||
}, | ||
"devDependencies": { | ||
"cors": "^2.3.1", | ||
"grunt": "^0.4.2", | ||
"grunt-contrib-concat": "^0.3.0", | ||
"grunt-contrib-connect": "^0.8.0", | ||
"grunt-contrib-jshint": "^0.9.2", | ||
"grunt-contrib-uglify": "^0.4.0", | ||
"grunt-contrib-watch": "^0.5.0", | ||
"grunt-es3-safe-recast": "^0.1.0", | ||
"grunt-jscs": "^0.8.0", | ||
"grunt-mocha": "^0.4.10", | ||
"grunt-saucelabs": "^5.1.2", | ||
"grunt-shell": "^0.6.4", | ||
"load-grunt-tasks": "^0.4.0", | ||
"mocha": "^1.18.2", | ||
"phantomjs": "^1.9.7-12", | ||
"uglify-js": "^2.3.x" | ||
}, | ||
"browser": "src/localforage-plugin-boilerplate.js", | ||
"main": "src/localforage-plugin-boilerplate.js", | ||
"keywords": [ | ||
"localforage", | ||
"plugin" | ||
], | ||
"author": "Thodoris Greasidis", | ||
"licence": "Apache-2.0", | ||
"bugs": { | ||
"url": "http://github.com/localForage-extensions/localForage-plugin-boilerplate/issues" | ||
}, | ||
"devDependencies": { | ||
"babel-eslint": "^6.0.4", | ||
"babel-preset-es2015-rollup": "^1.1.1", | ||
"eslint": "^2.8.0", | ||
"mocha": "^2.4.5", | ||
"rollup": "^0.26.1", | ||
"rollup-plugin-babel": "^2.4.0", | ||
"rollup-plugin-multi-entry": "^1.2.0", | ||
"source-map-support": "^0.4.0" | ||
}, | ||
"dependencies": { | ||
"localforage": ">=1.4.0" | ||
} | ||
} |
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,6 @@ | ||
import config from './rollup.config'; | ||
|
||
config.format = 'es6'; | ||
config.dest = 'dist/localforage-plugin-boilerplate.es6.js'; | ||
|
||
export default config; |
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,7 @@ | ||
import babel from 'rollup-plugin-babel'; | ||
|
||
export default { | ||
entry: 'lib/localforage-plugin-boilerplate.js', | ||
// sourceMap: true, | ||
plugins: [babel()] | ||
}; |
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,11 @@ | ||
import babel from 'rollup-plugin-babel'; | ||
import multiEntry from 'rollup-plugin-multi-entry'; | ||
|
||
export default { | ||
entry: 'test/**/*_test.js', | ||
plugins: [babel(), multiEntry()], | ||
format: 'cjs', | ||
intro: 'require("source-map-support").install();', | ||
dest: 'build/test-bundle.js', | ||
sourceMap: true | ||
}; |
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,7 @@ | ||
import config from './rollup.config'; | ||
|
||
config.format = 'umd'; | ||
config.dest = 'dist/localforage-plugin-boilerplate.js'; | ||
config.moduleName = 'localforagePluginBoilerplate'; | ||
|
||
export default config; |
Oops, something went wrong.