Skip to content

Commit 0d98b03

Browse files
committed
breaking: replace more shell.cp w/ fs.copySync
* Added missing defaults.xml test fixture file
1 parent f1d36cb commit 0d98b03

File tree

8 files changed

+94
-43
lines changed

8 files changed

+94
-43
lines changed

bin/templates/scripts/cordova/lib/plugman/pluginHandlers.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
'use strict';
1818
const fs = require('fs-extra');
1919
const path = require('path');
20-
const shell = require('shelljs');
2120
const util = require('util');
2221
const events = require('cordova-common').events;
2322
const CordovaError = require('cordova-common').CordovaError;
@@ -323,11 +322,8 @@ function copyFile (plugin_dir, src, project_dir, dest, link) {
323322

324323
if (link) {
325324
linkFileOrDirTree(src, dest);
326-
} else if (fs.statSync(src).isDirectory()) {
327-
// XXX shelljs decides to create a directory when -R|-r is used which sucks. http://goo.gl/nbsjq
328-
shell.cp('-Rf', path.join(src, '/*'), dest);
329325
} else {
330-
shell.cp('-f', src, dest);
326+
fs.copySync(src, dest);
331327
}
332328
}
333329

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
const Q = require('q');
2222
const fs = require('fs-extra');
2323
const path = require('path');
24-
const shell = require('shelljs');
2524
const unorm = require('unorm');
2625
const plist = require('plist');
2726
const URL = require('url');
@@ -109,7 +108,7 @@ function updateConfigFile (sourceConfig, configMunger, locations) {
109108

110109
// First cleanup current config and merge project's one into own
111110
// Overwrite platform config.xml with defaults.xml.
112-
shell.cp('-f', locations.defaultConfigXml, locations.configXml);
111+
fs.copySync(locations.defaultConfigXml, locations.configXml);
113112

114113
// Then apply config changes from global munge to all config files
115114
// in project (including project's config)

tests/spec/unit/Plugman/common.spec.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
const fs = require('fs-extra');
2020
const path = require('path');
2121
const osenv = require('os');
22-
const shell = require('shelljs');
2322
const rewire = require('rewire');
2423

2524
const common = rewire('../../../../bin/templates/scripts/cordova/lib/plugman/pluginHandlers');
@@ -107,13 +106,13 @@ describe('common handler routines', () => {
107106
fs.ensureDirSync(srcDirTree);
108107
fs.writeFileSync(srcFile, 'contents', 'utf-8');
109108

110-
const s = spyOn(shell, 'cp').and.callThrough();
109+
spyOn(fs, 'copySync').and.callThrough();
111110
const resolvedDest = path.resolve(project_dir, dest);
112111

113112
copyFile(test_dir, srcFile, project_dir, dest);
114113

115-
expect(s).toHaveBeenCalled();
116-
expect(s).toHaveBeenCalledWith('-f', srcFile, resolvedDest);
114+
expect(fs.copySync).toHaveBeenCalled();
115+
expect(fs.copySync).toHaveBeenCalledWith(srcFile, resolvedDest);
117116

118117
fs.removeSync(project_dir);
119118
});
@@ -129,7 +128,6 @@ describe('common handler routines', () => {
129128
});
130129

131130
describe('deleteJava', () => {
132-
// This is testing that shelljs.rm is removing the source file.
133131
it('Test 009 : source file should have been removed', () => {
134132
fs.ensureDirSync(srcDirTree);
135133
fs.writeFileSync(srcFile, 'contents', 'utf-8');

tests/spec/unit/Plugman/pluginHandler.spec.js

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ const os = require('os');
2121
const fs = require('fs-extra');
2222
const path = require('path');
2323
const rewire = require('rewire');
24-
const shell = require('shelljs');
2524
const EventEmitter = require('events');
2625

2726
const PluginInfo = require('cordova-common').PluginInfo;
@@ -32,7 +31,7 @@ const pluginHandlers = rewire('../../../../bin/templates/scripts/cordova/lib/plu
3231
const temp = path.join(os.tmpdir(), 'plugman');
3332

3433
const FIXTURES = path.join(__dirname, '../fixtures');
35-
const iosProject = path.join(FIXTURES, 'ios-config-xml', '*');
34+
const iosProject = path.join(FIXTURES, 'ios-config-xml');
3635
const faultyplugin = path.join(FIXTURES, 'org.test.plugins.faultyplugin');
3736
const dummyplugin = path.join(FIXTURES, 'org.test.plugins.dummyplugin');
3837
const weblessplugin = path.join(FIXTURES, 'org.test.plugins.weblessplugin');
@@ -68,7 +67,7 @@ describe('ios plugin handler', () => {
6867
let dummyProject;
6968

7069
beforeEach(() => {
71-
shell.cp('-rf', iosProject, temp);
70+
fs.copySync(iosProject, temp);
7271
projectFile.purgeProjectFileCache(temp);
7372

7473
dummyProject = projectFile.parse({
@@ -118,15 +117,15 @@ describe('ios plugin handler', () => {
118117
});
119118
it('Test 005 : should cp the file to the right target location when element has no target-dir', () => {
120119
const source = copyArray(valid_source).filter(s => s.targetDir === undefined);
121-
const spy = spyOn(shell, 'cp');
120+
spyOn(fs, 'copySync');
122121
install(source[0], dummyPluginInfo, dummyProject);
123-
expect(spy).toHaveBeenCalledWith('-f', path.join(dummyplugin, 'src', 'ios', 'DummyPluginCommand.m'), path.join(temp, 'SampleApp', 'Plugins', dummy_id, 'DummyPluginCommand.m'));
122+
expect(fs.copySync).toHaveBeenCalledWith(path.join(dummyplugin, 'src', 'ios', 'DummyPluginCommand.m'), path.join(temp, 'SampleApp', 'Plugins', dummy_id, 'DummyPluginCommand.m'));
124123
});
125124
it('Test 006 : should cp the file to the right target location when element has a target-dir', () => {
126125
const source = copyArray(valid_source).filter(s => s.targetDir !== undefined);
127-
const spy = spyOn(shell, 'cp');
126+
spyOn(fs, 'copySync');
128127
install(source[0], dummyPluginInfo, dummyProject);
129-
expect(spy).toHaveBeenCalledWith('-f', path.join(dummyplugin, 'src', 'ios', 'TargetDirTest.m'), path.join(temp, 'SampleApp', 'Plugins', dummy_id, 'targetDir', 'TargetDirTest.m'));
128+
expect(fs.copySync).toHaveBeenCalledWith(path.join(dummyplugin, 'src', 'ios', 'TargetDirTest.m'), path.join(temp, 'SampleApp', 'Plugins', dummy_id, 'targetDir', 'TargetDirTest.m'));
130129
});
131130
it('Test 007 : should call into xcodeproj\'s addFramework appropriately when element has framework=true set', () => {
132131
const source = copyArray(valid_source).filter(s => s.framework);
@@ -173,15 +172,15 @@ describe('ios plugin handler', () => {
173172
});
174173
it('Test 012 : should cp the file to the right target location when element has no target-dir', () => {
175174
const headers = copyArray(valid_headers).filter(s => s.targetDir === undefined);
176-
const spy = spyOn(shell, 'cp');
175+
spyOn(fs, 'copySync');
177176
install(headers[0], dummyPluginInfo, dummyProject);
178-
expect(spy).toHaveBeenCalledWith('-f', path.join(dummyplugin, 'src', 'ios', 'DummyPluginCommand.h'), path.join(temp, 'SampleApp', 'Plugins', dummy_id, 'DummyPluginCommand.h'));
177+
expect(fs.copySync).toHaveBeenCalledWith(path.join(dummyplugin, 'src', 'ios', 'DummyPluginCommand.h'), path.join(temp, 'SampleApp', 'Plugins', dummy_id, 'DummyPluginCommand.h'));
179178
});
180179
it('Test 013 : should cp the file to the right target location when element has a target-dir', () => {
181180
const headers = copyArray(valid_headers).filter(s => s.targetDir !== undefined);
182-
const spy = spyOn(shell, 'cp');
181+
spyOn(fs, 'copySync');
183182
install(headers[0], dummyPluginInfo, dummyProject);
184-
expect(spy).toHaveBeenCalledWith('-f', path.join(dummyplugin, 'src', 'ios', 'TargetDirTest.h'), path.join(temp, 'SampleApp', 'Plugins', dummy_id, 'targetDir', 'TargetDirTest.h'));
183+
expect(fs.copySync).toHaveBeenCalledWith(path.join(dummyplugin, 'src', 'ios', 'TargetDirTest.h'), path.join(temp, 'SampleApp', 'Plugins', dummy_id, 'targetDir', 'TargetDirTest.h'));
185184
});
186185
});
187186

@@ -215,9 +214,9 @@ describe('ios plugin handler', () => {
215214
});
216215
it('Test 017 : should cp the file to the right target location', () => {
217216
const resources = copyArray(valid_resources);
218-
const spy = spyOn(shell, 'cp');
217+
spyOn(fs, 'copySync');
219218
install(resources[0], dummyPluginInfo, dummyProject);
220-
expect(spy).toHaveBeenCalledWith('-f', path.join(dummyplugin, 'src', 'ios', 'DummyPlugin.bundle'), path.join(temp, 'SampleApp', 'Resources', 'DummyPlugin.bundle'));
219+
expect(fs.copySync).toHaveBeenCalledWith(path.join(dummyplugin, 'src', 'ios', 'DummyPlugin.bundle'), path.join(temp, 'SampleApp', 'Resources', 'DummyPlugin.bundle'));
221220
});
222221

223222
it('Test 018 : should link files to the right target location', () => {
@@ -274,9 +273,9 @@ describe('ios plugin handler', () => {
274273
});
275274
it('Test 022 : should cp the file to the right target location', () => {
276275
const frameworks = copyArray(valid_custom_frameworks);
277-
const spy = spyOn(shell, 'cp');
276+
spyOn(fs, 'copySync');
278277
install(frameworks[0], dummyPluginInfo, dummyProject);
279-
expect(spy).toHaveBeenCalledWith('-Rf', path.join(dummyplugin, 'src', 'ios', 'Custom.framework', '*'),
278+
expect(fs.copySync).toHaveBeenCalledWith(path.join(dummyplugin, 'src', 'ios', 'Custom.framework'),
280279
path.join(temp, 'SampleApp/Plugins/org.test.plugins.dummyplugin/Custom.framework'));
281280
});
282281

@@ -325,21 +324,21 @@ describe('ios plugin handler', () => {
325324
/* eslint-enable no-unused-vars */
326325

327326
beforeEach(() => {
328-
spyOn(shell, 'cp');
327+
spyOn(fs, 'copySync');
329328
wwwDest = path.resolve(dummyProject.www, asset.target);
330329
platformWwwDest = path.resolve(dummyProject.platformWww, asset.target);
331330
});
332331

333332
it('Test 026 : should put asset to both www and platform_www when options.usePlatformWww flag is specified', () => {
334333
install(asset, dummyPluginInfo, dummyProject, { usePlatformWww: true });
335-
expect(shell.cp).toHaveBeenCalledWith('-f', path.resolve(dummyPluginInfo.dir, asset.src), path.resolve(dummyProject.www, asset.target));
336-
expect(shell.cp).toHaveBeenCalledWith('-f', path.resolve(dummyPluginInfo.dir, asset.src), path.resolve(dummyProject.platformWww, asset.target));
334+
expect(fs.copySync).toHaveBeenCalledWith(path.resolve(dummyPluginInfo.dir, asset.src), path.resolve(dummyProject.www, asset.target));
335+
expect(fs.copySync).toHaveBeenCalledWith(path.resolve(dummyPluginInfo.dir, asset.src), path.resolve(dummyProject.platformWww, asset.target));
337336
});
338337

339338
it('Test 027 : should put asset to www only when options.usePlatformWww flag is not specified', () => {
340339
install(asset, dummyPluginInfo, dummyProject);
341-
expect(shell.cp).toHaveBeenCalledWith('-f', path.resolve(dummyPluginInfo.dir, asset.src), path.resolve(dummyProject.www, asset.target));
342-
expect(shell.cp).not.toHaveBeenCalledWith(path.resolve(dummyPluginInfo.dir, asset.src), path.resolve(dummyProject.platformWww, asset.target));
340+
expect(fs.copySync).toHaveBeenCalledWith(path.resolve(dummyPluginInfo.dir, asset.src), path.resolve(dummyProject.www, asset.target));
341+
expect(fs.copySync).not.toHaveBeenCalledWith(path.resolve(dummyPluginInfo.dir, asset.src), path.resolve(dummyProject.platformWww, asset.target));
343342
});
344343
});
345344

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
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+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing,
14+
software distributed under the License is distributed on an
15+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
KIND, either express or implied. See the License for the
17+
specific language governing permissions and limitations
18+
under the License.
19+
-->
20+
<widget xmlns = "http://www.w3.org/ns/widgets"
21+
id = "io.cordova.helloCordova"
22+
version = "2.0.0">
23+
24+
<!-- Preferences for iOS -->
25+
<preference name="AllowInlineMediaPlayback" value="false" />
26+
<preference name="BackupWebStorage" value="cloud" />
27+
<preference name="DisallowOverscroll" value="false" />
28+
<preference name="EnableViewportScale" value="false" />
29+
<preference name="KeyboardDisplayRequiresUserAction" value="true" />
30+
<preference name="MediaTypesRequiringUserActionForPlayback" value="none" />
31+
<preference name="SuppressesIncrementalRendering" value="false" />
32+
<preference name="SuppressesLongPressGesture" value="false" />
33+
<preference name="Suppresses3DTouchGesture" value="false" />
34+
<preference name="GapBetweenPages" value="0" />
35+
<preference name="PageLength" value="0" />
36+
<preference name="PaginationBreakingMode" value="page" /> <!-- page, column -->
37+
<preference name="PaginationMode" value="unpaginated" /> <!-- unpaginated, leftToRight, topToBottom, bottomToTop, rightToLeft -->
38+
39+
<feature name="CDVWebViewEngine">
40+
<param name="ios-package" value="CDVWebViewEngine" />
41+
</feature>
42+
<feature name="LocalStorage">
43+
<param name="ios-package" value="CDVLocalStorage"/>
44+
</feature>
45+
<feature name="Console">
46+
<param name="ios-package" value="CDVLogger"/>
47+
<param name="onload" value="true"/>
48+
</feature>
49+
<feature name="HandleOpenUrl">
50+
<param name="ios-package" value="CDVHandleOpenURL"/>
51+
<param name="onload" value="true"/>
52+
</feature>
53+
<feature name="IntentAndNavigationFilter">
54+
<param name="ios-package" value="CDVIntentAndNavigationFilter"/>
55+
<param name="onload" value="true"/>
56+
</feature>
57+
<feature name="GestureHandler">
58+
<param name="ios-package" value="CDVGestureHandler"/>
59+
<param name="onload" value="true"/>
60+
</feature>
61+
62+
</widget>

tests/spec/unit/prepare.spec.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ const fs = require('fs-extra');
2323
const EventEmitter = require('events');
2424
const os = require('os');
2525
const path = require('path');
26-
const shell = require('shelljs');
2726
const plist = require('plist');
2827
const xcode = require('xcode');
2928
const rewire = require('rewire');
@@ -46,12 +45,12 @@ describe('prepare', () => {
4645
Api = rewire('../../../bin/templates/scripts/cordova/Api');
4746

4847
fs.ensureDirSync(iosPlatform);
49-
shell.cp('-rf', `${iosProjectFixture}/*`, iosPlatform);
48+
fs.copySync(iosProjectFixture, iosPlatform);
5049
p = new Api('ios', iosPlatform, new EventEmitter());
5150
});
5251

5352
afterEach(() => {
54-
fs.removeSync(path.join(__dirname, 'some'));
53+
fs.removeSync(iosPlatform);
5554
});
5655

5756
describe('launch storyboard feature (CB-9762)', () => {
@@ -364,7 +363,7 @@ describe('prepare', () => {
364363
};
365364

366365
// copy the splash screen fixtures to the iOS project
367-
shell.cp('-rf', path.join(FIXTURES, 'launch-storyboard-support', 'res'), iosProject);
366+
fs.copySync(path.join(FIXTURES, 'launch-storyboard-support', 'res'), path.join(iosProject, 'res'));
368367

369368
// copy splash screens and update Contents.json
370369
updateLaunchStoryboardImages(project, p.locations);
@@ -411,7 +410,7 @@ describe('prepare', () => {
411410
projectConfig: new ConfigParser(path.join(FIXTURES, 'launch-storyboard-support', 'configs', 'modern-only.xml'))
412411
};
413412

414-
shell.cp('-rf', path.join(FIXTURES, 'launch-storyboard-support', 'res'), iosProject);
413+
fs.copySync(path.join(FIXTURES, 'launch-storyboard-support', 'res'), path.join(iosProject, 'res'));
415414
updateLaunchStoryboardImages(project, p.locations);
416415

417416
// now, clean the images

tests/spec/unit/preparePlatform.spec.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
const path = require('path');
2121
const fs = require('fs-extra');
22-
const shell = require('shelljs');
2322
const EventEmitter = require('events').EventEmitter;
2423
const ConfigParser = require('cordova-common').ConfigParser;
2524
const PluginInfo = require('cordova-common').PluginInfo;
@@ -37,7 +36,7 @@ describe('prepare after plugin add', () => {
3736
let api;
3837
beforeEach(() => {
3938
fs.ensureDirSync(iosPlatform);
40-
shell.cp('-rf', `${iosProjectFixture}/*`, iosPlatform);
39+
fs.copySync(iosProjectFixture, iosPlatform);
4140
api = new Api('ios', iosPlatform, new EventEmitter());
4241

4342
jasmine.addMatchers({

tests/spec/unit/projectFile.spec.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,10 @@
2020
const os = require('os');
2121
const path = require('path');
2222
const fs = require('fs-extra');
23-
const shell = require('shelljs');
2423
const projectFile = require('../../../bin/templates/scripts/cordova/lib/projectFile');
2524

2625
const iosProject = path.join(os.tmpdir(), 'plugman/projectFile');
27-
const iosProjectFixture = path.join(__dirname, 'fixtures/ios-config-xml/*');
26+
const iosProjectFixture = path.join(__dirname, 'fixtures/ios-config-xml');
2827

2928
const locations = {
3029
root: iosProject,
@@ -33,7 +32,7 @@ const locations = {
3332

3433
describe('projectFile', () => {
3534
beforeEach(() => {
36-
shell.cp('-rf', iosProjectFixture, iosProject);
35+
fs.copySync(iosProjectFixture, iosProject);
3736
});
3837

3938
afterEach(() => {
@@ -59,7 +58,7 @@ describe('projectFile', () => {
5958
// Create a folder named A with config.xml and .plist files in it
6059
const pathToFolderA = path.join(iosProject, 'A');
6160
fs.ensureDirSync(pathToFolderA);
62-
shell.cp('-rf', path.join(iosProject, 'SampleApp/*'), pathToFolderA);
61+
fs.copySync(path.join(iosProject, 'SampleApp'), pathToFolderA);
6362

6463
const parsedProjectFile = projectFile.parse(locations);
6564
const pluginsDir = parsedProjectFile.plugins_dir;

0 commit comments

Comments
 (0)