Skip to content

Commit 28ef35f

Browse files
committed
Merge pull request #11 from thgreasi/rollup
chore: use es6 & rollup
2 parents a9f8860 + be69913 commit 28ef35f

17 files changed

+342
-250
lines changed

.babelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": [ "es2015-rollup" ]
3+
}

.eslintrc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"parser": "babel-eslint",
3+
"parserOptions": {
4+
"ecmaVersion": 6,
5+
"sourceType": "module",
6+
"ecmaFeatures": {
7+
"modules": true
8+
}
9+
},
10+
"extends": "eslint:recommended",
11+
"env": {
12+
"node": true,
13+
"mocha": true
14+
},
15+
"rules":{
16+
"no-console": 0
17+
},
18+
"globals": {
19+
"localforage": true,
20+
"Promise": true,
21+
"console": true,
22+
"self": true,
23+
"System": true
24+
}
25+
}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
.DS_Store
22
.swp
3+
dist
4+
build
35
bower_components
46
node_modules
57
components

.jscsrc

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"esnext": true,
3+
"disallowSpacesInAnonymousFunctionExpression": {
4+
"beforeOpeningRoundBrace": true
5+
},
6+
"disallowTrailingComma": true,
7+
"requireBlocksOnNewline": true,
8+
"requireLineFeedAtFileEnd": true,
9+
"requireSpaceAfterKeywords": [
10+
"if",
11+
"else",
12+
"for",
13+
"while",
14+
"do",
15+
"switch",
16+
"return",
17+
"try",
18+
"catch"
19+
],
20+
"requireSpaceBeforeBlockStatements": true,
21+
"requireSpacesInConditionalExpression": true,
22+
"requireSpacesInFunctionExpression": {
23+
"beforeOpeningCurlyBrace": true
24+
},
25+
"safeContextKeyword": ["globalObject", "self"],
26+
"validateQuoteMarks": {
27+
"escape": true,
28+
"mark": "'"
29+
},
30+
"validateIndentation": 4
31+
}

.jshintrc

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"asi": false,
3+
"bitwise": true,
4+
"browser": true,
5+
"curly": true,
6+
"eqeqeq": true,
7+
"eqnull": true,
8+
"esnext": true,
9+
"immed": true,
10+
"latedef": true,
11+
"newcap": true,
12+
"noarg": true,
13+
"nonew": true,
14+
"quotmark": false,
15+
"strict": false,
16+
"trailing": false,
17+
"undef": true,
18+
"unused": true,
19+
20+
"validthis": true,
21+
22+
"globals": {
23+
"console": true,
24+
"define": true,
25+
"localforage": true,
26+
"module": true,
27+
"Promise": true,
28+
"require": true,
29+
"self": true,
30+
"System": true
31+
}
32+
}

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
language: node_js
2+
node_js:
3+
- "4.0"
4+
- "5.0"

bower.json

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "localforage-cordovasqlitedriver",
3-
"version": "1.3.0",
3+
"version": "1.4.0",
44
"main": [
55
"src/localforage-cordovasqlitedriver.js"
66
],
@@ -19,13 +19,5 @@
1919
],
2020
"dependencies": {
2121
"localforage": "^1.4.0"
22-
},
23-
"devDependencies": {
24-
"es6-promise": "~1.0.0",
25-
"requirejs": "~2.1.10",
26-
"mocha": "~1.18.2",
27-
"expect": "~0.3.1",
28-
"assert": "~0.1.0",
29-
"modernizr": "~2.8.1"
3022
}
3123
}

component.json

Lines changed: 0 additions & 11 deletions
This file was deleted.

lib/cordova-sqlite.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/* global document, sqlitePlugin */
2+
// we can't import this, since it gets defined later
3+
// import sqlitePlugin from 'sqlitePlugin';
4+
5+
var deviceReady = new Promise(function(resolve, reject) {
6+
if (typeof sqlitePlugin !== 'undefined') {
7+
resolve();
8+
} else if (typeof cordova === 'undefined') {
9+
reject();
10+
} else {
11+
// Wait for Cordova to load
12+
document.addEventListener("deviceready", resolve, false);
13+
}
14+
});
15+
16+
export var openDatabasePromise = deviceReady.catch(Promise.resolve).then(function() {
17+
return new Promise(function(resolve, reject) {
18+
if (typeof sqlitePlugin !== 'undefined' &&
19+
typeof sqlitePlugin.openDatabase === 'function') {
20+
resolve(sqlitePlugin.openDatabase);
21+
} else {
22+
reject('SQLite plugin is not present.');
23+
}
24+
});
25+
});
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
/*
2+
* Includes code from:
3+
*
4+
* localForage - websql driver
5+
* https://github.com/mozilla/localforage
6+
*
7+
* Copyright (c) 2015 Mozilla
8+
* Licensed under Apache 2.0 license.
9+
*
10+
*/
11+
// import localforage from 'localforage';
12+
import { getSerializerPromise, getWebSqlDriverPromise } from './utils';
13+
import { openDatabasePromise } from './cordova-sqlite';
14+
15+
// // If cordova is not present, we can stop now.
16+
// if (!globalObject.cordova) {
17+
// return;
18+
// }
19+
20+
// Open the cordova sqlite plugin database (automatically creates one if one didn't
21+
// previously exist), using any options set in the config.
22+
function _initStorage(options) {
23+
var self = this;
24+
var dbInfo = {
25+
db: null
26+
};
27+
28+
if (options) {
29+
for (var i in options) {
30+
dbInfo[i] = typeof(options[i]) !== 'string' ?
31+
options[i].toString() : options[i];
32+
}
33+
}
34+
35+
var dbInfoPromise = openDatabasePromise.then(function(openDatabase){
36+
return new Promise(function(resolve, reject) {
37+
// Open the database; the openDatabase API will automatically
38+
// create it for us if it doesn't exist.
39+
try {
40+
dbInfo.location = dbInfo.location || 'default';
41+
dbInfo.db = openDatabase({
42+
name: dbInfo.name,
43+
version: String(dbInfo.version),
44+
description: dbInfo.description,
45+
size: dbInfo.size,
46+
location: dbInfo.location
47+
});
48+
} catch (e) {
49+
reject(e);
50+
}
51+
52+
// Create our key/value table if it doesn't exist.
53+
dbInfo.db.transaction(function(t) {
54+
t.executeSql('CREATE TABLE IF NOT EXISTS ' + dbInfo.storeName +
55+
' (id INTEGER PRIMARY KEY, key unique, value)', [],
56+
function() {
57+
self._dbInfo = dbInfo;
58+
resolve();
59+
}, function(t, error) {
60+
reject(error);
61+
});
62+
});
63+
});
64+
});
65+
66+
var serializerPromise = getSerializerPromise(self);
67+
var webSqlDriverPromise = getWebSqlDriverPromise(self);
68+
69+
return Promise.all([
70+
serializerPromise,
71+
webSqlDriverPromise,
72+
dbInfoPromise
73+
]).then(function(results) {
74+
dbInfo.serializer = results[0];
75+
return dbInfoPromise;
76+
});
77+
}
78+
79+
var cordovaSQLiteDriver = {
80+
_driver: 'cordovaSQLiteDriver',
81+
_initStorage: _initStorage,
82+
_support: function() {
83+
return openDatabasePromise.then(function(openDatabase) {
84+
return !!openDatabase;
85+
}).catch(function(){
86+
return false;
87+
});
88+
}
89+
};
90+
91+
function wireUpDriverMethods(driver) {
92+
var LibraryMethods = [
93+
'clear',
94+
'getItem',
95+
'iterate',
96+
'key',
97+
'keys',
98+
'length',
99+
'removeItem',
100+
'setItem'
101+
];
102+
103+
function wireUpDriverMethod(driver, methodName) {
104+
driver[methodName] = function () {
105+
var localForageInstance = this;
106+
var args = arguments;
107+
return getWebSqlDriverPromise(localForageInstance).then(function (webSqlDriver) {
108+
return webSqlDriver[methodName].apply(localForageInstance, args);
109+
});
110+
};
111+
}
112+
113+
for (var i = 0, len = LibraryMethods.length; i < len; i++) {
114+
wireUpDriverMethod(driver, LibraryMethods[i]);
115+
}
116+
}
117+
118+
wireUpDriverMethods(cordovaSQLiteDriver);
119+
120+
export default cordovaSQLiteDriver;

0 commit comments

Comments
 (0)