Skip to content

Commit 32b079e

Browse files
authored
Merge branch 'master' into cb-14242-remove-bundled-dependencies-and-node-modules
2 parents 63f069f + 004b830 commit 32b079e

20 files changed

+915
-151
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ console.log
1010
node_modules
1111
coverage/
1212
npm-debug.log
13+
.nyc_output/

.istanbul.yml

-5
This file was deleted.

.travis.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
language: objective-c
2-
osx_image: xcode9.2
2+
osx_image: xcode9.3
33
sudo: false
44

55
env:
@@ -19,12 +19,13 @@ install:
1919
script:
2020
- node --version
2121
- npm --version
22+
- npm run eslint
2223
- npm run unit-tests
24+
- npm run test:component
2325
- npm run e2e-tests
2426
- open -b com.apple.iphonesimulator
2527
- npm run objc-tests
2628
- npm run cover
27-
- npm run eslint
2829

2930
after_script:
3031
- codecov

bin/templates/scripts/cordova/Api.js

+40
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,26 @@ Api.prototype.addPlugin = function (plugin, installOptions) {
233233

234234
return PluginManager.get(self.platform, self.locations, xcodeproj)
235235
.addPlugin(plugin, installOptions)
236+
.then(function () {
237+
if (plugin != null) {
238+
var headerTags = plugin.getHeaderFiles(self.platform);
239+
var bridgingHeaders = headerTags.filter(function (obj) {
240+
return (obj.type === 'BridgingHeader');
241+
});
242+
if (bridgingHeaders.length > 0) {
243+
var project_dir = self.locations.root;
244+
var project_name = self.locations.xcodeCordovaProj.split('/').pop();
245+
var BridgingHeader = require('./lib/BridgingHeader').BridgingHeader;
246+
var bridgingHeaderFile = new BridgingHeader(path.join(project_dir, project_name, 'Bridging-Header.h'));
247+
events.emit('verbose', 'Adding Bridging-Headers since the plugin contained <header-file> with type="BridgingHeader"');
248+
bridgingHeaders.forEach(function (obj) {
249+
var bridgingHeaderPath = path.basename(obj.src);
250+
bridgingHeaderFile.addHeader(plugin.id, bridgingHeaderPath);
251+
});
252+
bridgingHeaderFile.write();
253+
}
254+
}
255+
})
236256
.then(function () {
237257
var frameworkTags = plugin.getFrameworks(self.platform);
238258
var frameworkPods = frameworkTags.filter(function (obj) {
@@ -318,6 +338,26 @@ Api.prototype.removePlugin = function (plugin, uninstallOptions) {
318338

319339
return PluginManager.get(self.platform, self.locations, xcodeproj)
320340
.removePlugin(plugin, uninstallOptions)
341+
.then(function () {
342+
if (plugin != null) {
343+
var headerTags = plugin.getHeaderFiles(self.platform);
344+
var bridgingHeaders = headerTags.filter(function (obj) {
345+
return (obj.type === 'BridgingHeader');
346+
});
347+
if (bridgingHeaders.length > 0) {
348+
var project_dir = self.locations.root;
349+
var project_name = self.locations.xcodeCordovaProj.split('/').pop();
350+
var BridgingHeader = require('./lib/BridgingHeader').BridgingHeader;
351+
var bridgingHeaderFile = new BridgingHeader(path.join(project_dir, project_name, 'Bridging-Header.h'));
352+
events.emit('verbose', 'Removing Bridging-Headers since the plugin contained <header-file> with type="BridgingHeader"');
353+
bridgingHeaders.forEach(function (obj) {
354+
var bridgingHeaderPath = path.basename(obj.src);
355+
bridgingHeaderFile.removeHeader(plugin.id, bridgingHeaderPath);
356+
});
357+
bridgingHeaderFile.write();
358+
}
359+
}
360+
})
321361
.then(function () {
322362
var frameworkTags = plugin.getFrameworks(self.platform);
323363
var frameworkPods = frameworkTags.filter(function (obj) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
/*
2+
Licensed to the Apache Software Foundation (ASF) under one
3+
or more contributor license agreements. See the NOTICE file
4+
distributed with this work for additional information
5+
regarding copyright ownership. The ASF licenses this file
6+
to you under the Apache License, Version 2.0 (the
7+
"License"); you may not use this file except in compliance
8+
with the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing,
13+
software distributed under the License is distributed on an
14+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
KIND, either express or implied. See the License for the
16+
specific language governing permissions and limitations
17+
under the License.
18+
*/
19+
'use strict';
20+
21+
var fs = require('fs');
22+
var CordovaError = require('cordova-common').CordovaError;
23+
24+
function BridgingHeader (bridgingHeaderPath) {
25+
this.path = bridgingHeaderPath;
26+
this.bridgingHeaders = null;
27+
if (!fs.existsSync(this.path)) {
28+
throw new CordovaError('BridgingHeader.h is not found.');
29+
}
30+
this.bridgingHeaders = this.__parseForBridgingHeader(fs.readFileSync(this.path, 'utf8'));
31+
}
32+
33+
BridgingHeader.prototype.addHeader = function (plugin_id, header_path) {
34+
this.bridgingHeaders.push({type: 'code', code: '#import "' + header_path + '"\n'});
35+
};
36+
37+
BridgingHeader.prototype.removeHeader = function (plugin_id, header_path) {
38+
this.bridgingHeaders = this.bridgingHeaders.filter(function (line) {
39+
if (this.found) {
40+
return true;
41+
}
42+
if (line.type === 'code') {
43+
var re = new RegExp('#import\\s+"' + preg_quote(header_path) + '"(\\s*|\\s.+)(\\n|$)');
44+
if (re.test(line.code)) {
45+
this.found = true;
46+
return false;
47+
}
48+
}
49+
return true;
50+
}, {found: false});
51+
};
52+
53+
BridgingHeader.prototype.write = function () {
54+
var text = this.__stringifyForBridgingHeader(this.bridgingHeaders);
55+
fs.writeFileSync(this.path, text, 'utf8');
56+
};
57+
58+
BridgingHeader.prototype.__stringifyForBridgingHeader = function (bridgingHeaders) {
59+
return bridgingHeaders.map(function (obj) {
60+
return obj.code;
61+
}).join('');
62+
};
63+
64+
BridgingHeader.prototype.__parseForBridgingHeader = function (text) {
65+
var i = 0;
66+
var list = [];
67+
var type = 'code';
68+
var start = 0;
69+
while (i < text.length) {
70+
switch (type) {
71+
case 'comment':
72+
if (i + 1 < text.length && text[i] === '*' && text[i + 1] === '/') {
73+
i += 2;
74+
list.push({type: type, code: text.slice(start, i)});
75+
type = 'code';
76+
start = i;
77+
} else {
78+
i += 1;
79+
}
80+
break;
81+
case 'line-comment':
82+
if (i < text.length && text[i] === '\n') {
83+
i += 1;
84+
list.push({type: type, code: text.slice(start, i)});
85+
type = 'code';
86+
start = i;
87+
} else {
88+
i += 1;
89+
}
90+
break;
91+
case 'code':
92+
default:
93+
if (i + 1 < text.length && text[i] === '/' && text[i + 1] === '*') { // comment
94+
if (start < i) {
95+
list.push({type: type, code: text.slice(start, i)});
96+
}
97+
type = 'comment';
98+
start = i;
99+
} else if (i + 1 < text.length && text[i] === '/' && text[i + 1] === '/') { // line comment
100+
if (start < i) {
101+
list.push({type: type, code: text.slice(start, i)});
102+
}
103+
type = 'line-comment';
104+
start = i;
105+
} else if (i < text.length && text[i] === '\n') {
106+
i += 1;
107+
list.push({type: type, code: text.slice(start, i)});
108+
start = i;
109+
} else {
110+
i += 1;
111+
}
112+
break;
113+
}
114+
}
115+
if (start < i) {
116+
list.push({type: type, code: text.slice(start, i)});
117+
}
118+
return list;
119+
};
120+
121+
function preg_quote (str, delimiter) {
122+
return (str + '').replace(new RegExp('[.\\\\+*?\\[\\^\\]$(){}=!<>|:\\' + (delimiter || '') + '-]', 'g'), '\\$&');
123+
}
124+
125+
module.exports.BridgingHeader = BridgingHeader;

bin/templates/scripts/cordova/lib/build.js

-3
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ var projectName = null;
3636
// These are regular expressions to detect if the user is changing any of the built-in xcodebuildArgs
3737
/* eslint-disable no-useless-escape */
3838
var buildFlagMatchers = {
39-
'xcconfig': /^\-xcconfig\s*(.*)$/,
4039
'workspace': /^\-workspace\s*(.*)/,
4140
'scheme': /^\-scheme\s*(.*)/,
4241
'configuration': /^\-configuration\s*(.*)/,
@@ -291,7 +290,6 @@ function getXcodeBuildArgs (projectName, projectPath, configuration, isDevice, b
291290

292291
if (isDevice) {
293292
options = [
294-
'-xcconfig', customArgs.xcconfig || path.join(__dirname, '..', 'build-' + configuration.toLowerCase() + '.xcconfig'),
295293
'-workspace', customArgs.workspace || projectName + '.xcworkspace',
296294
'-scheme', customArgs.scheme || projectName,
297295
'-configuration', customArgs.configuration || configuration,
@@ -314,7 +312,6 @@ function getXcodeBuildArgs (projectName, projectPath, configuration, isDevice, b
314312
}
315313
} else { // emulator
316314
options = [
317-
'-xcconfig', customArgs.xcconfig || path.join(__dirname, '..', 'build-' + configuration.toLowerCase() + '.xcconfig'),
318315
'-workspace', customArgs.project || projectName + '.xcworkspace',
319316
'-scheme', customArgs.scheme || projectName,
320317
'-configuration', customArgs.configuration || configuration,

bin/templates/scripts/cordova/lib/prepare.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -277,10 +277,11 @@ function handleBuildSettings (platformConfig, locations, infoPlist) {
277277
var targetDevice = parseTargetDevicePreference(platformConfig.getPreference('target-device', 'ios'));
278278
var deploymentTarget = platformConfig.getPreference('deployment-target', 'ios');
279279
var needUpdatedBuildSettingsForLaunchStoryboard = checkIfBuildSettingsNeedUpdatedForLaunchStoryboard(platformConfig, infoPlist);
280+
var swiftVersion = platformConfig.getPreference('SwiftVersion', 'ios');
280281

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

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

306+
if (swiftVersion) {
307+
events.emit('verbose', 'Set SwiftVersion to "' + swiftVersion + '".');
308+
proj.updateBuildProperty('SWIFT_VERSION', swiftVersion);
309+
}
310+
305311
updateBuildSettingsForLaunchStoryboard(proj, platformConfig, infoPlist);
306312

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

500-
project.xcode.addResourceFile(target);
506+
if (!fs.existsSync(targetPath)) {
507+
project.xcode.addResourceFile(target);
508+
} else {
509+
events.emit('warn', 'Overwriting existing resource file at ' + targetPath);
510+
}
501511

502512
resourceMap[targetPath] = src;
503513
});

package.json

+18-8
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,16 @@
1818
"cordova:platform"
1919
],
2020
"scripts": {
21-
"test": "npm run e2e-tests && npm run objc-tests && npm run unit-tests",
21+
"test": "npm run unit-tests && npm run test:component && npm run objc-tests && npm run e2e-tests",
22+
"test:component": "jasmine --config=tests/spec/component.json",
2223
"posttest": "npm run eslint",
23-
"cover": "istanbul cover --root bin/templates/scripts/cordova --print detail jasmine -- --config=tests/spec/jasmine.json",
24+
"cover": "nyc jasmine --config=tests/spec/coverage.json",
2425
"e2e-tests": "jasmine tests/spec/create.spec.js",
2526
"objc-tests": "npm run objc-tests-lib && npm run objc-tests-framework",
26-
"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'`\"",
27-
"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'`\"",
27+
"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'`\"",
28+
"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'`\"",
2829
"preobjc-tests": "tests/scripts/killsim.js",
29-
"unit-tests": "jasmine --config=tests/spec/jasmine.json",
30+
"unit-tests": "jasmine --config=tests/spec/unit.json",
3031
"eslint": "eslint bin tests"
3132
},
3233
"author": "Apache Software Foundation",
@@ -39,10 +40,10 @@
3940
"eslint-plugin-node": "^5.1.0",
4041
"eslint-plugin-promise": "^3.5.0",
4142
"eslint-plugin-standard": "^3.0.1",
42-
"istanbul": "^0.4.2",
43-
"jasmine": "~2.6.0",
43+
"jasmine": "~3.1.0",
4444
"nodeunit": "^0.8.7",
45-
"rewire": "^2.5.1",
45+
"nyc": "^12.0.2",
46+
"rewire": "^4.0.1",
4647
"tmp": "^0.0.26"
4748
},
4849
"engines": {
@@ -58,5 +59,14 @@
5859
"shelljs": "^0.5.3",
5960
"xcode": "^0.9.0",
6061
"xml-escape": "^1.1.0"
62+
},
63+
"nyc": {
64+
"include": [
65+
"bin/templates/scripts/**"
66+
],
67+
"reporter": [
68+
"lcov",
69+
"text"
70+
]
6171
}
6272
}

tests/spec/component.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"spec_dir": "tests/spec",
3+
"spec_files": [
4+
"component/**/*[sS]pec.js"
5+
],
6+
"stopSpecOnExpectationFailure": false,
7+
"random": false
8+
}

tests/spec/component/versions.spec.js

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/**
2+
Licensed to the Apache Software Foundation (ASF) under one
3+
or more contributor license agreements. See the NOTICE file
4+
distributed with this work for additional information
5+
regarding copyright ownership. The ASF licenses this file
6+
to you under the Apache License, Version 2.0 (the
7+
"License"); you may not use this file except in compliance
8+
with the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing,
13+
software distributed under the License is distributed on an
14+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
KIND, either express or implied. See the License for the
16+
specific language governing permissions and limitations
17+
under the License.
18+
*/
19+
20+
var rewire = require('rewire');
21+
var versions = rewire('../../../bin/templates/scripts/cordova/lib/versions');
22+
23+
// These tests can not run on windows.
24+
if (process.platform === 'darwin') {
25+
describe('versions', function () {
26+
describe('get_tool_version method', () => {
27+
it('should not have found tool by name.', (done) => {
28+
versions.get_tool_version('unknown').catch((error) => {
29+
expect(error).toContain('is not valid tool name');
30+
done();
31+
});
32+
});
33+
34+
it('should find xcodebuild version.', (done) => {
35+
versions.get_tool_version('xcodebuild').then((version) => {
36+
expect(version).not.toBe(undefined);
37+
done();
38+
});
39+
});
40+
41+
it('should find ios-sim version.', (done) => {
42+
versions.get_tool_version('ios-sim').then((version) => {
43+
expect(version).not.toBe(undefined);
44+
done();
45+
});
46+
});
47+
48+
it('should find ios-deploy version.', (done) => {
49+
versions.get_tool_version('ios-deploy').then((version) => {
50+
expect(version).not.toBe(undefined);
51+
done();
52+
});
53+
});
54+
55+
it('should find pod version.', (done) => {
56+
versions.get_tool_version('pod').then((version) => {
57+
expect(version).not.toBe(undefined);
58+
done();
59+
});
60+
});
61+
});
62+
});
63+
}

0 commit comments

Comments
 (0)