Stefan Huber

cordova changes

1 node_modules/ 1 node_modules/
2 .vscode/ 2 .vscode/
3 +.tmp/
......
...@@ -13,3 +13,12 @@ Within the main process bsync needs to be integrated an initiated. ...@@ -13,3 +13,12 @@ Within the main process bsync needs to be integrated an initiated.
13 import {Bsync} from 'bsync'; 13 import {Bsync} from 'bsync';
14 Bsync.init(ipcMain, filePath); 14 Bsync.init(ipcMain, filePath);
15 15
16 +# Testing (Browser)
17 +
18 +`npm test`
19 +
20 +# Testing (Cordova)
21 +
22 +
23 +
24 +
......
...@@ -15,9 +15,9 @@ module.exports = function(config) { ...@@ -15,9 +15,9 @@ module.exports = function(config) {
15 15
16 // list of files / patterns to load in the browser 16 // list of files / patterns to load in the browser
17 files: [ 17 files: [
18 - './node_modules/rxjs/bundles/Rx.min.js' , 18 + '../node_modules/rxjs/bundles/Rx.min.js' ,
19 - './node_modules/pouchdb/dist/pouchdb.min.js' , 19 + '../node_modules/pouchdb/dist/pouchdb.min.js' ,
20 - './.tmp/browser-test.js' 20 + '../.tmp/browser-test.js'
21 ], 21 ],
22 22
23 23
......
1 +import typescript from 'rollup-plugin-typescript';
2 +
3 +export default {
4 +
5 + moduleName : 'bsync',
6 +
7 + entry: './spec/cordova-test.ts',
8 + dest: './.tmp/cordova-test-build.js',
9 +
10 + format: 'cjs',
11 +
12 + plugins: [
13 + typescript()
14 + ]
15 +};
...\ No newline at end of file ...\ No newline at end of file
1 -'use strict'; 1 +(function (global, factory) {
2 - 2 + typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('events'), require('rxjs')) :
3 -Object.defineProperty(exports, '__esModule', { value: true }); 3 + typeof define === 'function' && define.amd ? define(['exports', 'events', 'rxjs'], factory) :
4 - 4 + (factory((global.bsync = global.bsync || {}),global.events,global.rxjs));
5 -var events = require('events'); 5 +}(this, (function (exports,events,rxjs) { 'use strict';
6 -var rxjs = require('rxjs');
7 6
8 function __extends(d, b) { 7 function __extends(d, b) {
9 for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; 8 for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
...@@ -40,6 +39,28 @@ var ElectronFileHandler = (function () { ...@@ -40,6 +39,28 @@ var ElectronFileHandler = (function () {
40 return ElectronFileHandler; 39 return ElectronFileHandler;
41 }()); 40 }());
42 41
42 +var CordovaDownloader = (function () {
43 + function CordovaDownloader() {
44 + }
45 + CordovaDownloader.prototype.download = function (source, target) {
46 + return Rx.Observable.create(function (subscriber) {
47 + if (!window['FileTransfer']) {
48 + subscriber.error("Cordova FileTransfer object undefined");
49 + }
50 + var fileTransfer = new window['FileTransfer']();
51 + fileTransfer.onprogress = function (progress) {
52 + subscriber.next(progress.total / progress.loaded);
53 + };
54 + fileTransfer.download(source, target, function (entry) {
55 + subscriber.complete();
56 + }, function (error) {
57 + subscriber.error(error);
58 + }, true);
59 + });
60 + };
61 + return CordovaDownloader;
62 +}());
63 +
43 var Util = (function () { 64 var Util = (function () {
44 function Util() { 65 function Util() {
45 } 66 }
...@@ -277,6 +298,9 @@ var ServiceLocator = (function () { ...@@ -277,6 +298,9 @@ var ServiceLocator = (function () {
277 if (environment === ENV_ELECTRON) { 298 if (environment === ENV_ELECTRON) {
278 return new ElectronFileHandler(window['require']('electron').ipcRenderer); 299 return new ElectronFileHandler(window['require']('electron').ipcRenderer);
279 } 300 }
301 + if (environment === ENV_CORDOVA) {
302 + return new CordovaDownloader();
303 + }
280 return null; 304 return null;
281 }; 305 };
282 ServiceLocator.getFileReplicator = function () { 306 ServiceLocator.getFileReplicator = function () {
...@@ -362,4 +386,8 @@ exports.ENV_ELECTRON = ENV_ELECTRON; ...@@ -362,4 +386,8 @@ exports.ENV_ELECTRON = ENV_ELECTRON;
362 exports.ENV_CORDOVA = ENV_CORDOVA; 386 exports.ENV_CORDOVA = ENV_CORDOVA;
363 exports.ENV_UNKNOWN = ENV_UNKNOWN; 387 exports.ENV_UNKNOWN = ENV_UNKNOWN;
364 exports.ServiceLocator = ServiceLocator; 388 exports.ServiceLocator = ServiceLocator;
389 +
390 +Object.defineProperty(exports, '__esModule', { value: true });
391 +
392 +})));
365 //# sourceMappingURL=browser-build.js.map 393 //# sourceMappingURL=browser-build.js.map
......
This diff is collapsed. Click to expand it.
...@@ -5,14 +5,14 @@ ...@@ -5,14 +5,14 @@
5 "main": "dist/browser-build.js", 5 "main": "dist/browser-build.js",
6 "scripts": { 6 "scripts": {
7 "build": "npm run build:node && npm run build:browser", 7 "build": "npm run build:node && npm run build:browser",
8 - "build:node": "rollup -c ./rollup.config.node.js", 8 + "build:node": "rollup -c ./config/rollup.config.node.js",
9 - "build:browser": "rollup --config ./rollup.config.browser.js", 9 + "build:browser": "rollup --config ./config/rollup.config.browser.js",
10 "pretest": "scripts/before-test.sh", 10 "pretest": "scripts/before-test.sh",
11 "posttest": "scripts/after-test.sh", 11 "posttest": "scripts/after-test.sh",
12 "test": "npm run test:node && npm run test:browser", 12 "test": "npm run test:node && npm run test:browser",
13 - "test:node": "rollup --config ./rollup.config.node-test.js && jasmine", 13 + "test:node": "rollup --config ./config/rollup.config.node-test.js && jasmine",
14 - "test:browser": "rollup --config ./rollup.config.browser-test.js && karma start", 14 + "test:browser": "rollup --config ./config/rollup.config.browser-test.js && karma start ./config/karma.conf.js",
15 - "test:cordova": "npm run build:browser && scripts/prepare-cordova-test.sh" 15 + "test:cordova": "./scripts/prepare-cordova-test.sh"
16 }, 16 },
17 "author": "", 17 "author": "",
18 "license": "ISC", 18 "license": "ISC",
......
...@@ -5,20 +5,26 @@ PLATFORM=${2:-android} ...@@ -5,20 +5,26 @@ PLATFORM=${2:-android}
5 5
6 echo "cordova $COMMAND $PLATFORM" 6 echo "cordova $COMMAND $PLATFORM"
7 7
8 +rollup --config ./config/rollup.config.cordova-test.js
9 +cp ./spec/cordova-plugin-test/plugin.xml .tmp/plugin.xml
10 +cp ./node_modules/rxjs/bundles/Rx.min.js .tmp/Rx.min.js
11 +
8 cd .. 12 cd ..
9 -rm -r ./bysnc-client-test-app 13 +rm -r ./bsync-client-test-app
10 -./bsync-client/node_modules/.bin/cordova create bysnc-client-test-app 14 +./bsync-client/node_modules/.bin/cordova create bsync-client-test-app
11 -cd ./bysnc-client-test-app 15 +cd ./bsync-client-test-app
12 16
13 ../bsync-client/node_modules/.bin/cordova platform add $PLATFORM 17 ../bsync-client/node_modules/.bin/cordova platform add $PLATFORM
14 ../bsync-client/node_modules/.bin/cordova plugin add ../bsync-client 18 ../bsync-client/node_modules/.bin/cordova plugin add ../bsync-client
15 -../bsync-client/node_modules/.bin/cordova plugin add ../bsync-client/spec/cordova 19 +../bsync-client/node_modules/.bin/cordova plugin add ../bsync-client/.tmp
16 ../bsync-client/node_modules/.bin/cordova plugin add cordova-plugin-test-framework 20 ../bsync-client/node_modules/.bin/cordova plugin add cordova-plugin-test-framework
17 21
18 sed -i 's/index\.html/cdvtests\/index\.html/g' ./config.xml 22 sed -i 's/index\.html/cdvtests\/index\.html/g' ./config.xml
19 23
20 if [ $COMMAND == "run" ]; then 24 if [ $COMMAND == "run" ]; then
21 - ../bsync-client/node_modules/.bin/cordova run $PLATFORM 25 + cordova run $PLATFORM
22 else 26 else
23 - ../bsync-client/node_modules/.bin/cordova emulate $PLATFORM 27 + cordova emulate $PLATFORM
24 fi 28 fi
29 +
30 +rm -R ../bsync-client/.tmp
...\ No newline at end of file ...\ No newline at end of file
......
1 +<!doctype html>
2 +<!--
3 + Licensed to the Apache Software Foundation (ASF) under one
4 + or more contributor license agreements. See the NOTICE file
5 + distributed with this work for additional information
6 + regarding copyright ownership. The ASF licenses this file
7 + to you under the Apache License, Version 2.0 (the
8 + "License"); you may not use this file except in compliance
9 + with the License. You may obtain a copy of the License at
10 + http://www.apache.org/licenses/LICENSE-2.0
11 + Unless required by applicable law or agreed to in writing,
12 + software distributed under the License is distributed on an
13 + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 + KIND, either express or implied. See the License for the
15 + specific language governing permissions and limitations
16 + under the License.
17 +-->
18 +<html>
19 + <head>
20 + <!--
21 + Inject CSP
22 + If not hosted in mobilespec, the injection script will likely not
23 + exist. It would be up to the hosting app to provide the named
24 + script to setup CSP as desired.
25 + -->
26 + <script type="text/javascript" src="../csp-incl.js"></script>
27 +
28 + <title>Cordova tests</title>
29 + <meta charset="utf-8" />
30 +
31 + <meta name="format-detection" content="telephone=no" />
32 + <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width" />
33 +
34 + <link rel="stylesheet" type="text/css" href="cdvtests/topcoat-0.7.5/css/topcoat-mobile-light.min.css">
35 + <link rel="stylesheet" type="text/css" href="cdvtests/jasmine-2.4.1/jasmine.css" media="screen">
36 + <link rel="stylesheet" type="text/css" href="cdvtests/main.css" media="screen">
37 +
38 + <script type="text/javascript" src="cdvtests/jasmine-2.4.1/jasmine.js"></script>
39 + <script type="text/javascript" src="cdvtests/jasmine-2.4.1/jasmine-html.js"></script>
40 + <script type="text/javascript" src="cdvtests/jasmine-medic.js"></script>
41 +
42 + <script type="text/javascript" src="cordova.js"></script>
43 +
44 + <!-- App scripts -->
45 + <script type="text/javascript" src="cdvtests/main-bootstrap.js"></script>
46 + </head>
47 +
48 + <body>
49 + <div id='title'></div>
50 + <div id='middle'>
51 + <div id='buttons'></div>
52 + <div id='content'></div>
53 + </div>
54 + <div id='log'>
55 + <div id='log--title'>Log</div>
56 + <div id='log--content'></div>
57 + </div>
58 + </body>
59 +</html>
...\ No newline at end of file ...\ No newline at end of file
...@@ -8,7 +8,11 @@ ...@@ -8,7 +8,11 @@
8 <name>bsync cordova test</name> 8 <name>bsync cordova test</name>
9 <license>Apache 2.0 License</license> 9 <license>Apache 2.0 License</license>
10 10
11 - <js-module src="cordova-test.spec.js" name="tests"> 11 + <js-module src="Rx.min.js" name="Rx">
12 + <clobbers target="Rx" />
13 + </js-module>
14 +
15 + <js-module src="cordova-test-build.js" name="tests">
12 </js-module> 16 </js-module>
13 17
14 </plugin> 18 </plugin>
...\ No newline at end of file ...\ No newline at end of file
......
1 +import { CordovaDownloader } from '../src/file-handler/cordova-file-handler';
2 +
3 +declare var cordova;
4 +
1 exports.defineAutoTests = function() { 5 exports.defineAutoTests = function() {
2 6
3 - console.log(bsync); 7 + describe("Cordova downloader", () => {
4 8
5 - describe("Cordova tests", () => {
6 - /*
7 let downloader = new CordovaDownloader(); 9 let downloader = new CordovaDownloader();
8 10
9 it("should download sample image from https source and store with new name", (done) => { 11 it("should download sample image from https source and store with new name", (done) => {
10 12
11 let source = "https://upload.wikimedia.org/wikipedia/commons/thumb/e/e1/FullMoon2010.jpg/800px-FullMoon2010.jpg"; 13 let source = "https://upload.wikimedia.org/wikipedia/commons/thumb/e/e1/FullMoon2010.jpg/800px-FullMoon2010.jpg";
12 - let target = "cdvfile://full-moon.jpg"; 14 + let target = cordova.file.dataDirectory + "full-moon.jpg";
13 let lastProgress = 0; 15 let lastProgress = 0;
14 16
15 downloader.download(source, target) 17 downloader.download(source, target)
...@@ -18,18 +20,22 @@ exports.defineAutoTests = function() { ...@@ -18,18 +20,22 @@ exports.defineAutoTests = function() {
18 expect(progress).toBeGreaterThan(lastProgress); 20 expect(progress).toBeGreaterThan(lastProgress);
19 lastProgress = progress; 21 lastProgress = progress;
20 } , 22 } ,
21 - (error:any) => {} , 23 + (error:any) => {
24 + fail();
25 + } ,
22 () => { 26 () => {
23 expect(lastProgress).toEqual(1); 27 expect(lastProgress).toEqual(1);
24 - // expect(fs.existsSync(target)).toBeTruthy(); 28 +
29 + window['resolveLocalFileSystemURL'](target, (entry:any) => {
30 + expect(entry.isFile).toBeTruthy();
31 + expect(entry.name).toEqual("full-moon.jpg");
25 done(); 32 done();
33 + });
26 } 34 }
27 ); 35 );
28 36
29 }); 37 });
30 - */
31 38
32 }); 39 });
33 40
34 -
35 }; 41 };
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -14,7 +14,7 @@ export class CordovaDownloader implements FileHandler { ...@@ -14,7 +14,7 @@ export class CordovaDownloader implements FileHandler {
14 let fileTransfer = new window['FileTransfer'](); 14 let fileTransfer = new window['FileTransfer']();
15 15
16 fileTransfer.onprogress = (progress:ProgressEvent) => { 16 fileTransfer.onprogress = (progress:ProgressEvent) => {
17 - subscriber.next(progress.total / progress.loaded); 17 + subscriber.next(progress.loaded / progress.total);
18 }; 18 };
19 19
20 fileTransfer.download( 20 fileTransfer.download(
......
1 -import { Observable, Subscriber } from 'rxjs'; 1 +import { Observable } from 'rxjs/Observable';
2 +import { Subscriber } from 'rxjs/Subscriber';
2 import { FileHandler } from '../api/file-handler'; 3 import { FileHandler } from '../api/file-handler';
3 import * as http from 'http'; 4 import * as http from 'http';
4 import * as https from 'https'; 5 import * as https from 'https';
......
1 import {FileHandler} from './api/file-handler'; 1 import {FileHandler} from './api/file-handler';
2 import {ElectronFileHandler} from './file-handler/electron-file-handler'; 2 import {ElectronFileHandler} from './file-handler/electron-file-handler';
3 +import {CordovaDownloader} from './file-handler/cordova-file-handler';
3 import {FileReplicator} from './file-replicator'; 4 import {FileReplicator} from './file-replicator';
4 import { 5 import {
5 Config, 6 Config,
...@@ -54,6 +55,10 @@ export class ServiceLocator { ...@@ -54,6 +55,10 @@ export class ServiceLocator {
54 return new ElectronFileHandler(window['require']('electron').ipcRenderer); 55 return new ElectronFileHandler(window['require']('electron').ipcRenderer);
55 } 56 }
56 57
58 + if (environment === ENV_CORDOVA) {
59 + return new CordovaDownloader();
60 + }
61 +
57 return null; 62 return null;
58 } 63 }
59 64
......