You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by er...@apache.org on 2020/07/16 03:48:00 UTC
[cordova-electron] branch master updated: refactor: remove more
platform-centered files & update code (#156)
This is an automated email from the ASF dual-hosted git repository.
erisu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cordova-electron.git
The following commit(s) were added to refs/heads/master by this push:
new d6fbdb8 refactor: remove more platform-centered files & update code (#156)
d6fbdb8 is described below
commit d6fbdb83fdacda274d762e955c72607bf38c1e50
Author: エリス <er...@users.noreply.github.com>
AuthorDate: Thu Jul 16 12:47:51 2020 +0900
refactor: remove more platform-centered files & update code (#156)
* chore: remove left over platform-centered files
* chore: remove code related to platform-centered workflow
* chore: added missing test cleanup
* chore: apply suggestions
---
bin/templates/www/css/index.css | 116 ------------------------------------
bin/templates/www/icons/icon.png | Bin 39830 -> 0 bytes
bin/templates/www/img/logo.png | Bin 20554 -> 0 bytes
bin/templates/www/img/splash.png | Bin 37564 -> 0 bytes
bin/templates/www/index.html | 44 --------------
bin/templates/www/js/index.js | 49 ---------------
lib/Api.js | 8 ++-
package.json | 1 -
tests/spec/unit/lib/Api.spec.js | 17 +++++-
tests/spec/unit/lib/build.spec.js | 18 +++++-
tests/spec/unit/lib/prepare.spec.js | 22 ++++---
11 files changed, 52 insertions(+), 223 deletions(-)
diff --git a/bin/templates/www/css/index.css b/bin/templates/www/css/index.css
deleted file mode 100644
index 3463fa2..0000000
--- a/bin/templates/www/css/index.css
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
-*/
-
-* {
- -webkit-tap-highlight-color: rgba(0,0,0,0); /* make transparent link selection, adjust last value opacity 0 to 1.0 */
-}
-
-body {
- -webkit-touch-callout: none; /* prevent callout to copy image, etc when tap to hold */
- -webkit-text-size-adjust: none; /* prevent webkit from resizing text to fit */
- -webkit-user-select: none; /* prevent copy paste, to allow, change 'none' to 'text' */
- background-color:#E4E4E4;
- background-image:linear-gradient(top, #A7A7A7 0%, #E4E4E4 51%);
- background-image:-webkit-linear-gradient(top, #A7A7A7 0%, #E4E4E4 51%);
- background-image:-ms-linear-gradient(top, #A7A7A7 0%, #E4E4E4 51%);
- background-image:-webkit-gradient(
- linear,
- left top,
- left bottom,
- color-stop(0, #A7A7A7),
- color-stop(0.51, #E4E4E4)
- );
- background-attachment:fixed;
- font-family:'HelveticaNeue-Light', 'HelveticaNeue', Helvetica, Arial, sans-serif;
- font-size:12px;
- height:100%;
- margin:0px;
- padding:0px;
- text-transform:uppercase;
- width:100%;
-}
-
-/* Portrait layout (default) */
-.app {
- background:url(../img/logo.png) no-repeat center top; /* 170px x 200px */
- position:absolute; /* position in the center of the screen */
- left:50%;
- top:50%;
- height:50px; /* text area height */
- width:225px; /* text area width */
- text-align:center;
- padding:180px 0px 0px 0px; /* image height is 200px (bottom 20px are overlapped with text) */
- margin:-115px 0px 0px -112px; /* offset vertical: half of image height and text area height */
- /* offset horizontal: half of text area width */
-}
-
-/* Landscape layout (with min-width) */
-@media screen and (min-aspect-ratio: 1/1) and (min-width:400px) {
- .app {
- background-position:left center;
- padding:75px 0px 75px 170px; /* padding-top + padding-bottom + text area = image height */
- margin:-90px 0px 0px -198px; /* offset vertical: half of image height */
- /* offset horizontal: half of image width and text area width */
- }
-}
-
-h1 {
- font-size:24px;
- font-weight:normal;
- margin:0px;
- overflow:visible;
- padding:0px;
- text-align:center;
-}
-
-.event {
- border-radius:4px;
- -webkit-border-radius:4px;
- color:#FFFFFF;
- font-size:12px;
- margin:0px 30px;
- padding:2px 0px;
-}
-
-.event.listening {
- background-color:#333333;
- display:block;
-}
-
-.event.received {
- background-color:#4B946A;
- display:none;
-}
-
-@keyframes fade {
- from { opacity: 1.0; }
- 50% { opacity: 0.4; }
- to { opacity: 1.0; }
-}
-
-@-webkit-keyframes fade {
- from { opacity: 1.0; }
- 50% { opacity: 0.4; }
- to { opacity: 1.0; }
-}
-
-.blink {
- animation:fade 3000ms infinite;
- -webkit-animation:fade 3000ms infinite;
-}
diff --git a/bin/templates/www/icons/icon.png b/bin/templates/www/icons/icon.png
deleted file mode 100644
index c9465f3..0000000
Binary files a/bin/templates/www/icons/icon.png and /dev/null differ
diff --git a/bin/templates/www/img/logo.png b/bin/templates/www/img/logo.png
deleted file mode 100644
index 4453279..0000000
Binary files a/bin/templates/www/img/logo.png and /dev/null differ
diff --git a/bin/templates/www/img/splash.png b/bin/templates/www/img/splash.png
deleted file mode 100644
index 38acd8f..0000000
Binary files a/bin/templates/www/img/splash.png and /dev/null differ
diff --git a/bin/templates/www/index.html b/bin/templates/www/index.html
deleted file mode 100644
index 9ec8420..0000000
--- a/bin/templates/www/index.html
+++ /dev/null
@@ -1,44 +0,0 @@
-<!DOCTYPE html>
-<!--
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
--->
-<html>
- <head>
- <meta charset="utf-8" />
- <meta name="format-detection" content="telephone=no" />
- <meta name="theme-color" content="#2196F3"/>
- <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
- <link rel="stylesheet" type="text/css" href="css/index.css" />
- <link rel="manifest" href="manifest.json">
- <title>Hello World</title>
- </head>
- <body>
- <div class="app">
- <h1>Apache Cordova</h1>
- <div id="deviceready" class="blink">
- <p class="event listening">Connecting to Device</p>
- <p class="event received">Device is Ready</p>
- </div>
- </div>
- <script type="text/javascript" src="cordova.js"></script>
- <script type="text/javascript" src="js/index.js"></script>
- <script type="text/javascript">
- app.initialize();
- </script>
- </body>
-</html>
diff --git a/bin/templates/www/js/index.js b/bin/templates/www/js/index.js
deleted file mode 100644
index 693141f..0000000
--- a/bin/templates/www/js/index.js
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
-*/
-const app = {
- // Application Constructor
- initialize: () => {
- this.bindEvents();
- },
- // Bind Event Listeners
- //
- // Bind any events that are required on startup. Common events are:
- // 'load', 'deviceready', 'offline', and 'online'.
- bindEvents: () => {
- document.addEventListener('deviceready', this.onDeviceReady, false);
- },
- // deviceready Event Handler
- //
- // The scope of 'this' is the event. In order to call the 'receivedEvent'
- // function, we must explicity call 'app.receivedEvent(...);'
- onDeviceReady: () => {
- app.receivedEvent('deviceready');
- },
- // Update DOM on a Received Event
- receivedEvent: (id) => {
- const parentElement = document.getElementById(id);
- const listeningElement = parentElement.querySelector('.listening');
- const receivedElement = parentElement.querySelector('.received');
-
- listeningElement.setAttribute('style', 'display:none;');
- receivedElement.setAttribute('style', 'display:block;');
-
- console.log(`Received Event: ${id}`);
- }
-};
diff --git a/lib/Api.js b/lib/Api.js
index 0cecc9f..218288c 100644
--- a/lib/Api.js
+++ b/lib/Api.js
@@ -51,8 +51,12 @@ class Api {
constructor (platform, platformRootDir, events) {
this.platform = 'electron';
- // MyApp/platforms/electron
- this.root = platformRootDir || path.resolve(__dirname, '../bin/templates');
+ // The path to the platform root directory must always be provided.
+ if (!platformRootDir || !fs.existsSync(platformRootDir)) {
+ throw new CordovaError('The path to the platform root directory was undefined or invalid.');
+ }
+
+ this.root = platformRootDir;
this.events = setupEvents(events);
this.parser = new Parser(this.root);
this.handler = require('./handler');
diff --git a/package.json b/package.json
index daad6cc..6c99282 100644
--- a/package.json
+++ b/package.json
@@ -59,7 +59,6 @@
".npm-scripts/",
"bin/templates/build-res/",
"bin/templates/platform_www/",
- "bin/templates/www/",
"cordova-js-src/",
"cordova-lib/",
"coverage/",
diff --git a/tests/spec/unit/lib/Api.spec.js b/tests/spec/unit/lib/Api.spec.js
index d157ce7..b80e527 100644
--- a/tests/spec/unit/lib/Api.spec.js
+++ b/tests/spec/unit/lib/Api.spec.js
@@ -20,7 +20,7 @@
const fs = require('fs-extra');
const path = require('path');
const rewire = require('rewire');
-const { events, PluginInfo, ConfigParser } = require('cordova-common');
+const { events, PluginInfo, ConfigParser, CordovaError } = require('cordova-common');
const rootDir = path.resolve(__dirname, '../../../..');
const fixturesDir = path.join(rootDir, 'tests/spec/fixtures');
@@ -95,6 +95,21 @@ describe('Api class', () => {
expect(api.root).toEqual(testProjectDir);
expect(api.locations).toEqual(jasmine.objectContaining(mockExpectedLocations));
});
+
+ it('should throw error when the constructor is missing platformRootDir argument.', () => {
+ expect(() => new Api()).toThrowError(
+ CordovaError,
+ 'The path to the platform root directory was undefined or invalid.'
+ );
+ });
+
+ it('should throw error when the constructor contains an invalid platformRootDir path.', () => {
+ const fakePath = path.join(__dirname, '/some-fake-path');
+ expect(() => new Api(undefined, fakePath)).toThrowError(
+ CordovaError,
+ 'The path to the platform root directory was undefined or invalid.'
+ );
+ });
});
describe('getPlatformInfo method', () => {
diff --git a/tests/spec/unit/lib/build.spec.js b/tests/spec/unit/lib/build.spec.js
index a07d14a..cba5370 100644
--- a/tests/spec/unit/lib/build.spec.js
+++ b/tests/spec/unit/lib/build.spec.js
@@ -20,14 +20,29 @@
const rewire = require('rewire');
const path = require('path');
+const fs = require('fs-extra');
const rootDir = path.resolve(__dirname, '../../../..');
+const fixturesDir = path.join(rootDir, 'tests/spec/fixtures');
+const tmpDir = path.join(rootDir, 'temp');
+const testProjectDir = path.join(tmpDir, 'testapp');
const Api = rewire(path.join(rootDir, 'lib/Api'));
const check_reqs = require(path.join(rootDir, 'lib/check_reqs'));
describe('Testing build.js:', () => {
let build;
+ let api;
+
+ beforeAll(() => {
+ fs.ensureDirSync(tmpDir);
+ fs.copySync(path.resolve(fixturesDir, 'testapp'), path.resolve(tmpDir, 'testapp'));
+ api = new Api(null, testProjectDir);
+ });
+
+ afterAll(() => {
+ fs.removeSync(tmpDir);
+ });
beforeEach(() => {
build = rewire(path.join(rootDir, 'lib/build'));
@@ -41,7 +56,6 @@ describe('Testing build.js:', () => {
let emitSpy;
const emptyObj = {};
- const api = new Api(null);
beforeEach(() => {
ElectronBuilder = build.__get__('ElectronBuilder');
@@ -1695,7 +1709,6 @@ describe('Testing build.js:', () => {
describe('Module exports run', () => {
it('should have called configure and build.', () => {
- const api = new Api(null);
const platformConfig = {
mac: { arch: ['x64'] }
};
@@ -1745,7 +1758,6 @@ describe('Testing build.js:', () => {
});
it('should have failed requirement check and thrown error.', () => {
- const api = new Api(null);
const buildOptions = { debug: false, buildConfig: 'LOAD_MY_FAKE_DATA', argv: [] };
const errorMsg = 'error';
spyOn(check_reqs, 'run').and.callFake(() => Promise.reject(new Error(errorMsg)));
diff --git a/tests/spec/unit/lib/prepare.spec.js b/tests/spec/unit/lib/prepare.spec.js
index c97f6e9..f26c127 100644
--- a/tests/spec/unit/lib/prepare.spec.js
+++ b/tests/spec/unit/lib/prepare.spec.js
@@ -19,9 +19,13 @@
const rewire = require('rewire');
const path = require('path');
+const fs = require('fs-extra');
const CordovaError = require('cordova-common').CordovaError;
const rootDir = path.resolve(__dirname, '../../../..');
+const fixturesDir = path.join(rootDir, 'tests/spec/fixtures');
+const tmpDir = path.join(rootDir, 'temp');
+const testProjectDir = path.join(tmpDir, 'testapp');
const Api = require(path.join(rootDir, 'bin/templates/cordova/Api'));
let prepare;
@@ -209,6 +213,17 @@ describe('Testing prepare.js:', () => {
// define spies
let updatePathsSpy;
let cordovaProject;
+ let api;
+
+ beforeAll(() => {
+ fs.ensureDirSync(tmpDir);
+ fs.copySync(path.resolve(fixturesDir, 'testapp'), path.resolve(tmpDir, 'testapp'));
+ api = new Api(null, testProjectDir);
+ });
+
+ afterAll(() => {
+ fs.removeSync(tmpDir);
+ });
beforeEach(() => {
createSpies();
@@ -224,7 +239,6 @@ describe('Testing prepare.js:', () => {
// Mocking the scope with dummy API;
return Promise.resolve().then(function () {
// Create API instance and mock for test case.
- const api = new Api(null, '', '');
api.events = { emit: emitSpy };
api.parser.update_www = () => this;
api.parser.update_project = () => this;
@@ -280,7 +294,6 @@ describe('Testing prepare.js:', () => {
// Mocking the scope with dummy API;
return Promise.resolve().then(function () {
// Create API instance and mock for test case.
- const api = new Api(null, '', '');
api.events = { emit: emitSpy };
api.parser.update_www = () => this;
api.parser.update_project = () => this;
@@ -326,7 +339,6 @@ describe('Testing prepare.js:', () => {
// Mocking the scope with dummy API;
return Promise.resolve().then(function () {
// Create API instance and mock for test case.
- const api = new Api(null, '', '');
api.events = { emit: emitSpy };
api.parser.update_www = () => this;
api.parser.update_project = () => this;
@@ -371,7 +383,6 @@ describe('Testing prepare.js:', () => {
// Mocking the scope with dummy API;
return Promise.resolve().then(function () {
// Create API instance and mock for test case.
- const api = new Api(null, '', '');
api.events = { emit: emitSpy };
api.parser.update_www = () => this;
api.parser.update_project = () => this;
@@ -427,7 +438,6 @@ describe('Testing prepare.js:', () => {
// Mocking the scope with dummy API;
return Promise.resolve().then(function () {
// Create API instance and mock for test case.
- const api = new Api(null, '', '');
api.events = { emit: emitSpy };
api.parser.update_www = () => this;
api.parser.update_project = () => this;
@@ -484,7 +494,6 @@ describe('Testing prepare.js:', () => {
// Mocking the scope with dummy API;
return Promise.resolve().then(function () {
// Create API instance and mock for test case.
- const api = new Api(null, '', '');
api.events = { emit: emitSpy };
api.parser.update_www = () => this;
api.parser.update_project = () => this;
@@ -540,7 +549,6 @@ describe('Testing prepare.js:', () => {
// Mocking the scope with dummy API;
return Promise.resolve().then(function () {
// Create API instance and mock for test case.
- const api = new Api(null, '', '');
api.events = { emit: emitSpy };
api.parser.update_www = () => this;
api.parser.update_project = () => this;
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org