You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ra...@apache.org on 2019/10/10 17:54:40 UTC
[cordova-lib] branch master updated: Remove platform.check (#800)
This is an automated email from the ASF dual-hosted git repository.
raphinesse pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cordova-lib.git
The following commit(s) were added to refs/heads/master by this push:
new 46c75f6 Remove platform.check (#800)
46c75f6 is described below
commit 46c75f6179ae0437a7d1c231ef09f7b23bccaee9
Author: Raphael von der GrĂ¼n <ra...@gmail.com>
AuthorDate: Thu Oct 10 19:54:36 2019 +0200
Remove platform.check (#800)
---
spec/cordova/platform/check.spec.js | 67 -----------------
spec/cordova/platform/index.spec.js | 7 --
src/cordova/platform/check.js | 139 ------------------------------------
src/cordova/platform/index.js | 3 -
4 files changed, 216 deletions(-)
diff --git a/spec/cordova/platform/check.spec.js b/spec/cordova/platform/check.spec.js
deleted file mode 100644
index 631d6d7..0000000
--- a/spec/cordova/platform/check.spec.js
+++ /dev/null
@@ -1,67 +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.
-*/
-
-var fs = require('fs-extra');
-var events = require('cordova-common').events;
-var superspawn = require('cordova-common').superspawn;
-var rewire = require('rewire');
-var platform_check = rewire('../../../src/cordova/platform/check');
-var platform = require('../../../src/cordova/platform');
-var cordova_util = require('../../../src/cordova/util');
-
-describe('cordova/platform/check', function () {
- var projectRoot = '/some/path';
- var hooks_mock;
-
- beforeEach(function () {
- spyOn(events, 'emit');
- spyOn(superspawn, 'spawn').and.callThrough();
- spyOn(fs, 'removeSync');
- spyOn(cordova_util, 'listPlatforms').and.returnValue(['ios']);
- spyOn(platform, 'add').and.returnValue(Promise.resolve());
- });
-
- it('If no platforms, platforms cannot be updated', function () {
- cordova_util.listPlatforms.and.returnValue([]);
- return platform_check(hooks_mock, projectRoot).then(function () {
- expect(events.emit).toHaveBeenCalledWith('results', jasmine.stringMatching(/No platforms can be updated/));
- expect(superspawn.spawn).toHaveBeenCalledWith('npm', ['--loglevel=silent', '--json', 'outdated', 'cordova-lib'], jasmine.any(Object));
- expect(fs.removeSync).toHaveBeenCalledWith(jasmine.any(String));
- });
- });
-
- it('Should warn if install failed', function () {
- platform.add.and.returnValue(Promise.reject());
- return platform_check(hooks_mock, projectRoot).then(function () {
- expect(events.emit).toHaveBeenCalledWith('results', jasmine.stringMatching(/current did not install/));
- });
- });
-
- it('Should warn if version-empty', function () {
- superspawn.spawn.and.returnValue(Promise.resolve());
- return platform_check(hooks_mock, projectRoot).then(function () {
- expect(events.emit).toHaveBeenCalledWith('results', jasmine.stringMatching(/current version script failed to return a version/));
- });
- });
-
- it('Should warn if version-failed', function () {
- spyOn(superspawn, 'maybeSpawn').and.returnValue(Promise.resolve('version-failed'));
- return platform_check(hooks_mock, projectRoot).then(function () {
- expect(events.emit).toHaveBeenCalledWith('results', jasmine.stringMatching(/current version script failed, and/));
- });
- });
-});
diff --git a/spec/cordova/platform/index.spec.js b/spec/cordova/platform/index.spec.js
index 6c0c3a6..a2c664f 100644
--- a/spec/cordova/platform/index.spec.js
+++ b/spec/cordova/platform/index.spec.js
@@ -103,13 +103,6 @@ describe('cordova/platform', function () {
expect(platform.update).toHaveBeenCalled();
});
});
- it('should direct `check` commands to the `check` method/module', function () {
- spyOn(platform, 'check').and.returnValue(true);
- return platform('check', ['android'])
- .then(function () {
- expect(platform.check).toHaveBeenCalled();
- });
- });
it('should direct `list`, all other commands and no command at all to the `list` method/module', function () {
spyOn(platform, 'list').and.returnValue(true);
// test the `list` command directly
diff --git a/src/cordova/platform/check.js b/src/cordova/platform/check.js
deleted file mode 100644
index 2c01b61..0000000
--- a/src/cordova/platform/check.js
+++ /dev/null
@@ -1,139 +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.
-*/
-
-var fs = require('fs-extra');
-var path = require('path');
-var os = require('os');
-var semver = require('semver');
-var events = require('cordova-common').events;
-var superspawn = require('cordova-common').superspawn;
-var cordova_util = require('../util');
-var HooksRunner = require('../../hooks/HooksRunner');
-
-module.exports = check;
-
-function check (hooksRunner, projectRoot) {
- return Promise.all([
- getCordovaUpdateMessage(), getPlatformUpdateMessages(projectRoot)
- ]).then(messages => {
- events.emit('results', messages.join('\n'));
- });
-}
-
-function getCordovaUpdateMessage () {
- return superspawn.spawn('npm',
- ['--loglevel=silent', '--json', 'outdated', 'cordova-lib'],
- { cwd: path.dirname(require.main.filename) }
- ).then(function (output) {
- var vers;
- try {
- var json = JSON.parse(output)['cordova-lib'];
- vers = [json.latest, json.current];
- } catch (e) {
- vers = ('' || output).match(/cordova-lib@(\S+)\s+\S+\s+current=(\S+)/);
- }
- if (vers) {
- return [vers[1], vers[2]];
- }
- }).catch(function () {
- /* oh well */
- }).then(function (versions) {
- var message = '';
- if (versions && semver.gt(versions[0], versions[1])) {
- message = 'An update of cordova is available: ' + versions[0];
- }
- return message;
- });
-}
-
-function getPlatformUpdateMessages (projectRoot) {
- var installedPlatforms = cordova_util.listPlatforms(projectRoot);
- var scratch = path.join(os.tmpdir(), 'cordova-platform-check-' + Date.now());
- var listeners = events._events;
- events._events = {};
- function cleanup () {
- events._events = listeners;
- fs.removeSync(scratch);
- }
-
- // Acquire the version number of each platform we have installed, and output that too.
- return require('../cordova').create(scratch)
- .then(function () {
- var h = new HooksRunner(scratch);
- return Promise.all(installedPlatforms.map(p =>
- getPlatformUpdateMessage(p, h, projectRoot, scratch)
- ));
- })
- .then(platformsText => {
- var platformResults = '';
-
- if (platformsText) {
- platformResults = platformsText.filter(p => p).sort().join('\n');
- }
- if (!platformResults) {
- platformResults = 'No platforms can be updated at this time.';
- }
- return platformResults;
- })
- // .finally(cleanup)
- .then(
- res => { cleanup(); return res; },
- err => { cleanup(); throw err; }
- );
-}
-
-function getPlatformUpdateMessage (platform, h, projectRoot, scratch) {
- const availableVersionPromise = require('.').add(h, scratch, [platform], { spawnoutput: { stdio: 'ignore' } })
- .then(function () {
- return getPlatformVersion(scratch, platform).then(
- avail => avail || 'version-empty',
- _ => 'version-failed'
- );
- }, function () {
- /* If a platform doesn't install, then we can't realistically suggest updating */
- return 'install-failed';
- });
-
- const currentVersionPromise = getPlatformVersion(projectRoot, platform)
- .then(
- v => v || '',
- _ => 'broken'
- );
-
- return Promise.all([availableVersionPromise, currentVersionPromise])
- .then(([avail, v]) => {
- var prefix = platform + ' @ ' + (v || 'unknown');
- switch (avail) {
- case 'install-failed':
- return prefix + '; current did not install, and thus its version cannot be determined';
- case 'version-failed':
- return prefix + '; current version script failed, and thus its version cannot be determined';
- case 'version-empty':
- return prefix + '; current version script failed to return a version, and thus its version cannot be determined';
- default:
- if (!v || v === 'broken' || semver.gt(avail, v)) {
- return prefix + ' could be updated to: ' + avail;
- }
- }
- })
- .catch(function () {});
-}
-
-function getPlatformVersion (projectRoot, platform) {
- const bin = path.join(projectRoot, 'platforms', platform, 'cordova/version');
- return superspawn.maybeSpawn(bin, [], { chmod: true });
-}
diff --git a/src/cordova/platform/index.js b/src/cordova/platform/index.js
index 2aa86c3..2b47543 100644
--- a/src/cordova/platform/index.js
+++ b/src/cordova/platform/index.js
@@ -30,7 +30,6 @@ module.exports.update = function update (hooksRunner, projectRoot, targets, opts
return addHelper('update', hooksRunner, projectRoot, targets, opts);
};
module.exports.remove = require('./remove');
-module.exports.check = require('./check');
module.exports.list = require('./list');
module.exports.getPlatformDetailsFromDir = require('./getPlatformDetailsFromDir');
@@ -75,8 +74,6 @@ function platform (command, targets, opts) {
case 'update':
case 'up':
return module.exports.update(hooksRunner, projectRoot, targets, opts);
- case 'check':
- return module.exports.check(hooksRunner, projectRoot);
default:
return module.exports.list(hooksRunner, projectRoot, opts);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org