Skip to content

Commit

Permalink
Merge branch 'master' into cb-14242-remove-bundled-dependencies-and-n…
Browse files Browse the repository at this point in the history
…ode-modules
  • Loading branch information
raphinesse committed Sep 11, 2018
2 parents 63f069f + 004b830 commit 32b079e
Show file tree
Hide file tree
Showing 20 changed files with 915 additions and 151 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -10,3 +10,4 @@ console.log
node_modules
coverage/
npm-debug.log
.nyc_output/
5 changes: 0 additions & 5 deletions .istanbul.yml

This file was deleted.

5 changes: 3 additions & 2 deletions .travis.yml
@@ -1,5 +1,5 @@
language: objective-c
osx_image: xcode9.2
osx_image: xcode9.3
sudo: false

env:
Expand All @@ -19,12 +19,13 @@ install:
script:
- node --version
- npm --version
- npm run eslint
- npm run unit-tests
- npm run test:component
- npm run e2e-tests
- open -b com.apple.iphonesimulator
- npm run objc-tests
- npm run cover
- npm run eslint

after_script:
- codecov
40 changes: 40 additions & 0 deletions bin/templates/scripts/cordova/Api.js
Expand Up @@ -233,6 +233,26 @@ Api.prototype.addPlugin = function (plugin, installOptions) {

return PluginManager.get(self.platform, self.locations, xcodeproj)
.addPlugin(plugin, installOptions)
.then(function () {
if (plugin != null) {
var headerTags = plugin.getHeaderFiles(self.platform);
var bridgingHeaders = headerTags.filter(function (obj) {
return (obj.type === 'BridgingHeader');
});
if (bridgingHeaders.length > 0) {
var project_dir = self.locations.root;
var project_name = self.locations.xcodeCordovaProj.split('/').pop();
var BridgingHeader = require('./lib/BridgingHeader').BridgingHeader;
var bridgingHeaderFile = new BridgingHeader(path.join(project_dir, project_name, 'Bridging-Header.h'));
events.emit('verbose', 'Adding Bridging-Headers since the plugin contained <header-file> with type="BridgingHeader"');
bridgingHeaders.forEach(function (obj) {
var bridgingHeaderPath = path.basename(obj.src);
bridgingHeaderFile.addHeader(plugin.id, bridgingHeaderPath);
});
bridgingHeaderFile.write();
}
}
})
.then(function () {
var frameworkTags = plugin.getFrameworks(self.platform);
var frameworkPods = frameworkTags.filter(function (obj) {
Expand Down Expand Up @@ -318,6 +338,26 @@ Api.prototype.removePlugin = function (plugin, uninstallOptions) {

return PluginManager.get(self.platform, self.locations, xcodeproj)
.removePlugin(plugin, uninstallOptions)
.then(function () {
if (plugin != null) {
var headerTags = plugin.getHeaderFiles(self.platform);
var bridgingHeaders = headerTags.filter(function (obj) {
return (obj.type === 'BridgingHeader');
});
if (bridgingHeaders.length > 0) {
var project_dir = self.locations.root;
var project_name = self.locations.xcodeCordovaProj.split('/').pop();
var BridgingHeader = require('./lib/BridgingHeader').BridgingHeader;
var bridgingHeaderFile = new BridgingHeader(path.join(project_dir, project_name, 'Bridging-Header.h'));
events.emit('verbose', 'Removing Bridging-Headers since the plugin contained <header-file> with type="BridgingHeader"');
bridgingHeaders.forEach(function (obj) {
var bridgingHeaderPath = path.basename(obj.src);
bridgingHeaderFile.removeHeader(plugin.id, bridgingHeaderPath);
});
bridgingHeaderFile.write();
}
}
})
.then(function () {
var frameworkTags = plugin.getFrameworks(self.platform);
var frameworkPods = frameworkTags.filter(function (obj) {
Expand Down
125 changes: 125 additions & 0 deletions bin/templates/scripts/cordova/lib/BridgingHeader.js
@@ -0,0 +1,125 @@
/*
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.
*/
'use strict';

var fs = require('fs');
var CordovaError = require('cordova-common').CordovaError;

function BridgingHeader (bridgingHeaderPath) {
this.path = bridgingHeaderPath;
this.bridgingHeaders = null;
if (!fs.existsSync(this.path)) {
throw new CordovaError('BridgingHeader.h is not found.');
}
this.bridgingHeaders = this.__parseForBridgingHeader(fs.readFileSync(this.path, 'utf8'));
}

BridgingHeader.prototype.addHeader = function (plugin_id, header_path) {
this.bridgingHeaders.push({type: 'code', code: '#import "' + header_path + '"\n'});
};

BridgingHeader.prototype.removeHeader = function (plugin_id, header_path) {
this.bridgingHeaders = this.bridgingHeaders.filter(function (line) {
if (this.found) {
return true;
}
if (line.type === 'code') {
var re = new RegExp('#import\\s+"' + preg_quote(header_path) + '"(\\s*|\\s.+)(\\n|$)');
if (re.test(line.code)) {
this.found = true;
return false;
}
}
return true;
}, {found: false});
};

BridgingHeader.prototype.write = function () {
var text = this.__stringifyForBridgingHeader(this.bridgingHeaders);
fs.writeFileSync(this.path, text, 'utf8');
};

BridgingHeader.prototype.__stringifyForBridgingHeader = function (bridgingHeaders) {
return bridgingHeaders.map(function (obj) {
return obj.code;
}).join('');
};

BridgingHeader.prototype.__parseForBridgingHeader = function (text) {
var i = 0;
var list = [];
var type = 'code';
var start = 0;
while (i < text.length) {
switch (type) {
case 'comment':
if (i + 1 < text.length && text[i] === '*' && text[i + 1] === '/') {
i += 2;
list.push({type: type, code: text.slice(start, i)});
type = 'code';
start = i;
} else {
i += 1;
}
break;
case 'line-comment':
if (i < text.length && text[i] === '\n') {
i += 1;
list.push({type: type, code: text.slice(start, i)});
type = 'code';
start = i;
} else {
i += 1;
}
break;
case 'code':
default:
if (i + 1 < text.length && text[i] === '/' && text[i + 1] === '*') { // comment
if (start < i) {
list.push({type: type, code: text.slice(start, i)});
}
type = 'comment';
start = i;
} else if (i + 1 < text.length && text[i] === '/' && text[i + 1] === '/') { // line comment
if (start < i) {
list.push({type: type, code: text.slice(start, i)});
}
type = 'line-comment';
start = i;
} else if (i < text.length && text[i] === '\n') {
i += 1;
list.push({type: type, code: text.slice(start, i)});
start = i;
} else {
i += 1;
}
break;
}
}
if (start < i) {
list.push({type: type, code: text.slice(start, i)});
}
return list;
};

function preg_quote (str, delimiter) {
return (str + '').replace(new RegExp('[.\\\\+*?\\[\\^\\]$(){}=!<>|:\\' + (delimiter || '') + '-]', 'g'), '\\$&');
}

module.exports.BridgingHeader = BridgingHeader;
3 changes: 0 additions & 3 deletions bin/templates/scripts/cordova/lib/build.js
Expand Up @@ -36,7 +36,6 @@ var projectName = null;
// These are regular expressions to detect if the user is changing any of the built-in xcodebuildArgs
/* eslint-disable no-useless-escape */
var buildFlagMatchers = {
'xcconfig': /^\-xcconfig\s*(.*)$/,
'workspace': /^\-workspace\s*(.*)/,
'scheme': /^\-scheme\s*(.*)/,
'configuration': /^\-configuration\s*(.*)/,
Expand Down Expand Up @@ -291,7 +290,6 @@ function getXcodeBuildArgs (projectName, projectPath, configuration, isDevice, b

if (isDevice) {
options = [
'-xcconfig', customArgs.xcconfig || path.join(__dirname, '..', 'build-' + configuration.toLowerCase() + '.xcconfig'),
'-workspace', customArgs.workspace || projectName + '.xcworkspace',
'-scheme', customArgs.scheme || projectName,
'-configuration', customArgs.configuration || configuration,
Expand All @@ -314,7 +312,6 @@ function getXcodeBuildArgs (projectName, projectPath, configuration, isDevice, b
}
} else { // emulator
options = [
'-xcconfig', customArgs.xcconfig || path.join(__dirname, '..', 'build-' + configuration.toLowerCase() + '.xcconfig'),
'-workspace', customArgs.project || projectName + '.xcworkspace',
'-scheme', customArgs.scheme || projectName,
'-configuration', customArgs.configuration || configuration,
Expand Down
14 changes: 12 additions & 2 deletions bin/templates/scripts/cordova/lib/prepare.js
Expand Up @@ -277,10 +277,11 @@ function handleBuildSettings (platformConfig, locations, infoPlist) {
var targetDevice = parseTargetDevicePreference(platformConfig.getPreference('target-device', 'ios'));
var deploymentTarget = platformConfig.getPreference('deployment-target', 'ios');
var needUpdatedBuildSettingsForLaunchStoryboard = checkIfBuildSettingsNeedUpdatedForLaunchStoryboard(platformConfig, infoPlist);
var swiftVersion = platformConfig.getPreference('SwiftVersion', 'ios');

// no build settings provided and we don't need to update build settings for launch storyboards,
// then we don't need to parse and update .pbxproj file
if (!targetDevice && !deploymentTarget && !needUpdatedBuildSettingsForLaunchStoryboard) {
if (!targetDevice && !deploymentTarget && !needUpdatedBuildSettingsForLaunchStoryboard && !swiftVersion) {
return Q();
}

Expand All @@ -302,6 +303,11 @@ function handleBuildSettings (platformConfig, locations, infoPlist) {
proj.updateBuildProperty('IPHONEOS_DEPLOYMENT_TARGET', deploymentTarget);
}

if (swiftVersion) {
events.emit('verbose', 'Set SwiftVersion to "' + swiftVersion + '".');
proj.updateBuildProperty('SWIFT_VERSION', swiftVersion);
}

updateBuildSettingsForLaunchStoryboard(proj, platformConfig, infoPlist);

fs.writeFileSync(locations.pbxproj, proj.writeSync(), 'utf-8');
Expand Down Expand Up @@ -497,7 +503,11 @@ function updateFileResources (cordovaProject, locations) {
let targetPath = path.join(project.resources_dir, target);
targetPath = path.relative(cordovaProject.root, targetPath);

project.xcode.addResourceFile(target);
if (!fs.existsSync(targetPath)) {
project.xcode.addResourceFile(target);
} else {
events.emit('warn', 'Overwriting existing resource file at ' + targetPath);
}

resourceMap[targetPath] = src;
});
Expand Down
26 changes: 18 additions & 8 deletions package.json
Expand Up @@ -18,15 +18,16 @@
"cordova:platform"
],
"scripts": {
"test": "npm run e2e-tests && npm run objc-tests && npm run unit-tests",
"test": "npm run unit-tests && npm run test:component && npm run objc-tests && npm run e2e-tests",
"test:component": "jasmine --config=tests/spec/component.json",
"posttest": "npm run eslint",
"cover": "istanbul cover --root bin/templates/scripts/cordova --print detail jasmine -- --config=tests/spec/jasmine.json",
"cover": "nyc jasmine --config=tests/spec/coverage.json",
"e2e-tests": "jasmine tests/spec/create.spec.js",
"objc-tests": "npm run objc-tests-lib && npm run objc-tests-framework",
"objc-tests-lib": "xcodebuild test -workspace tests/cordova-ios.xcworkspace -scheme CordovaLibTests -destination \"platform=iOS Simulator,name=iPhone 5\" CONFIGURATION_BUILD_DIR=\"`mktemp -d 2>/dev/null || mktemp -d -t 'cordova-ios'`\"",
"objc-tests-framework": "xcodebuild test -workspace tests/cordova-ios.xcworkspace -scheme CordovaFrameworkApp -destination \"platform=iOS Simulator,name=iPhone 5\" CONFIGURATION_BUILD_DIR=\"`mktemp -d 2>/dev/null || mktemp -d -t 'cordova-ios'`\"",
"objc-tests-lib": "xcodebuild test -workspace tests/cordova-ios.xcworkspace -scheme CordovaLibTests -destination \"platform=iOS Simulator,name=iPhone 8\" CONFIGURATION_BUILD_DIR=\"`mktemp -d 2>/dev/null || mktemp -d -t 'cordova-ios'`\"",
"objc-tests-framework": "xcodebuild test -workspace tests/cordova-ios.xcworkspace -scheme CordovaFrameworkApp -destination \"platform=iOS Simulator,name=iPhone 8\" CONFIGURATION_BUILD_DIR=\"`mktemp -d 2>/dev/null || mktemp -d -t 'cordova-ios'`\"",
"preobjc-tests": "tests/scripts/killsim.js",
"unit-tests": "jasmine --config=tests/spec/jasmine.json",
"unit-tests": "jasmine --config=tests/spec/unit.json",
"eslint": "eslint bin tests"
},
"author": "Apache Software Foundation",
Expand All @@ -39,10 +40,10 @@
"eslint-plugin-node": "^5.1.0",
"eslint-plugin-promise": "^3.5.0",
"eslint-plugin-standard": "^3.0.1",
"istanbul": "^0.4.2",
"jasmine": "~2.6.0",
"jasmine": "~3.1.0",
"nodeunit": "^0.8.7",
"rewire": "^2.5.1",
"nyc": "^12.0.2",
"rewire": "^4.0.1",
"tmp": "^0.0.26"
},
"engines": {
Expand All @@ -58,5 +59,14 @@
"shelljs": "^0.5.3",
"xcode": "^0.9.0",
"xml-escape": "^1.1.0"
},
"nyc": {
"include": [
"bin/templates/scripts/**"
],
"reporter": [
"lcov",
"text"
]
}
}
8 changes: 8 additions & 0 deletions tests/spec/component.json
@@ -0,0 +1,8 @@
{
"spec_dir": "tests/spec",
"spec_files": [
"component/**/*[sS]pec.js"
],
"stopSpecOnExpectationFailure": false,
"random": false
}
63 changes: 63 additions & 0 deletions tests/spec/component/versions.spec.js
@@ -0,0 +1,63 @@
/**
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 rewire = require('rewire');
var versions = rewire('../../../bin/templates/scripts/cordova/lib/versions');

// These tests can not run on windows.
if (process.platform === 'darwin') {
describe('versions', function () {
describe('get_tool_version method', () => {
it('should not have found tool by name.', (done) => {
versions.get_tool_version('unknown').catch((error) => {
expect(error).toContain('is not valid tool name');
done();
});
});

it('should find xcodebuild version.', (done) => {
versions.get_tool_version('xcodebuild').then((version) => {
expect(version).not.toBe(undefined);
done();
});
});

it('should find ios-sim version.', (done) => {
versions.get_tool_version('ios-sim').then((version) => {
expect(version).not.toBe(undefined);
done();
});
});

it('should find ios-deploy version.', (done) => {
versions.get_tool_version('ios-deploy').then((version) => {
expect(version).not.toBe(undefined);
done();
});
});

it('should find pod version.', (done) => {
versions.get_tool_version('pod').then((version) => {
expect(version).not.toBe(undefined);
done();
});
});
});
});
}

0 comments on commit 32b079e

Please sign in to comment.