From 11f00513f604844a3df4267adaf018cfa0b8d77c Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Tue, 15 May 2018 23:19:45 -0700 Subject: [PATCH] Switch to using fs-extra in favour of shelljs --- integration-tests/HooksRunner.spec.js | 54 +++++-------- integration-tests/platform.spec.js | 2 +- integration-tests/plugman_fetch.spec.js | 2 +- integration-tests/plugman_uninstall.spec.js | 2 +- package.json | 3 +- spec/cordova/metadata/parser.spec.js | 2 +- .../metadata/parserhelper/preferences.spec.js | 2 +- spec/cordova/platform/addHelper.spec.js | 5 +- spec/cordova/platform/check.spec.js | 6 +- .../getPlatformDetailsFromDir.spec.js | 2 +- spec/cordova/platform/remove.spec.js | 2 +- spec/cordova/plugin/add.spec.js | 2 +- spec/cordova/plugin/remove.spec.js | 2 +- spec/cordova/plugin/save.spec.js | 2 +- spec/cordova/plugin/util.spec.js | 6 +- spec/cordova/plugin_parser.spec.js | 2 +- spec/cordova/serve.spec.js | 2 +- spec/cordova/util.spec.js | 80 +++++++++---------- spec/helpers.js | 8 +- spec/plugman/add_platform.spec.js | 2 +- spec/plugman/create.spec.js | 5 +- spec/plugman/install.spec.js | 24 +++--- spec/plugman/platforms/common.spec.js | 65 ++++++++------- src/cordova/config.js | 5 +- src/cordova/info.js | 2 +- src/cordova/platform/addHelper.js | 5 +- src/cordova/platform/check.js | 6 +- src/cordova/platform/remove.js | 5 +- src/cordova/plugin/add.js | 2 +- src/cordova/plugin/remove.js | 2 +- src/cordova/plugin/save.js | 2 +- src/cordova/plugin/util.js | 4 +- src/cordova/restore-util.js | 2 +- src/cordova/serve.js | 2 +- src/cordova/util.js | 9 +-- src/hooks/HooksRunner.js | 2 +- src/hooks/scriptsFinder.js | 2 +- src/platforms/platforms.js | 2 +- src/plugman/browserify.js | 2 +- src/plugman/create.js | 7 +- src/plugman/createpackagejson.js | 2 +- src/plugman/fetch.js | 14 ++-- src/plugman/help.js | 2 +- src/plugman/init-defaults.js | 2 +- src/plugman/install.js | 13 ++- src/plugman/platform.js | 7 +- src/plugman/platforms/common.js | 22 +++-- src/plugman/registry/manifest.js | 2 +- src/plugman/uninstall.js | 5 +- src/plugman/util/dependencies.js | 2 +- src/plugman/util/metadata.js | 2 +- src/plugman/util/search-and-replace.js | 2 +- src/util/unpack.js | 2 +- 53 files changed, 192 insertions(+), 228 deletions(-) diff --git a/integration-tests/HooksRunner.spec.js b/integration-tests/HooksRunner.spec.js index 34d3e1bd8..726bf22f4 100644 --- a/integration-tests/HooksRunner.spec.js +++ b/integration-tests/HooksRunner.spec.js @@ -24,7 +24,7 @@ var cordova = require('../src/cordova/cordova'); var HooksRunner = require('../src/hooks/HooksRunner'); var shell = require('shelljs'); var path = require('path'); -var fs = require('fs'); +var fs = require('fs-extra'); var os = require('os'); var Q = require('q'); var child_process = require('child_process'); @@ -46,12 +46,12 @@ var testPluginFixturePath = path.join(fixtures, 'plugins', 'com.plugin.withhooks var cordovaUtil = require('../src/cordova/util'); // copy fixture -shell.rm('-rf', project); -shell.mkdir('-p', project); -shell.cp('-R', path.join(fixtures, 'projWithHooks', '*'), project); +fs.removeSync(project); +fs.ensureDirSync(project); +fs.copySync(path.join(fixtures, 'projWithHooks'), project); -shell.mkdir('-p', dotCordova); -shell.cp('-R', path.join(fixtures, 'projWithHooks', '.cordova'), project); +fs.ensureDirSync(dotCordova); +fs.copySync(path.join(fixtures, 'projWithHooks', '.cordova'), dotCordova); // copy sh/bat scripts if (ext === 'bat') { @@ -104,11 +104,8 @@ describe('HooksRunner', function () { hooksRunner = new HooksRunner(project); // Add the testing platform. - cordova.platform('add', [helpers.testPlatform], {'fetch': true}).fail(function (err) { - expect(err).toBeUndefined(); - console.error(err); - done(); - }).then(function () { + cordova.platform('add', [helpers.testPlatform], {'fetch': true}) + .then(function () { // Add the testing plugin projectRoot = cordovaUtil.isCordova(); @@ -121,14 +118,13 @@ describe('HooksRunner', function () { options = cordovaUtil.preProcessOptions(options); hookOptions = { projectRoot: project, cordova: options }; - cordova.plugin('add', testPluginFixturePath, {'fetch': true}).fail(function (err) { - expect(err && err.stack).toBeUndefined(); - done(); - }).then(function () { - testPluginInstalledPath = path.join(projectRoot, 'plugins', 'com.plugin.withhooks'); - done(); - }); - }); + return cordova.plugin('add', testPluginFixturePath, {'fetch': true}); + }) + .then(function () { + testPluginInstalledPath = path.join(projectRoot, 'plugins', 'com.plugin.withhooks'); + done(); + }) + .catch(done); }, 100000); describe('fire method', function () { @@ -653,27 +649,15 @@ describe('HooksRunner', function () { }); it('Test 024 :should not error if the hook is unrecognized', function (done) { - hooksRunner.fire('CLEAN YOUR SHORTS GODDAMNIT LIKE A BIG BOY!', hookOptions).fail(function (err) { - expect('Call with unrecognized hook ').toBe('successful.\n' + err); - }).fin(done); + hooksRunner.fire('CLEAN YOUR SHORTS GODDAMNIT LIKE A BIG BOY!', hookOptions) + .catch(done) + .then(done); }); }); // Cleanup. Must be the last spec. Is there a better place for final cleanup in Jasmine? it('Test 025 : should not fail during cleanup', function () { process.chdir(path.join(__dirname, '..')); // Non e2e tests assume CWD is repo root. - if (ext === 'sh') { - shell.rm('-rf', tmpDir); - } else { // Windows: - // For some mysterious reason, both shell.rm and RMDIR /S /Q won't - // delete the dir on Windows, but they do remove the files leaving - // only folders. But the dir is removed just fine by - // shell.rm('-rf', tmpDir) at the top of this file with the next - // invocation of this test. The benefit of RMDIR /S /Q is that it - // doesn't print warnings like shell.rmdir() that look like this: - // rm: could not remove directory (code ENOTEMPTY): C:\Users\... - var cmd = 'RMDIR /S /Q ' + tmpDir; - child_process.exec(cmd); - } + fs.removeSync(tmpDir); }); }); diff --git a/integration-tests/platform.spec.js b/integration-tests/platform.spec.js index 1ac691f34..520d2c890 100644 --- a/integration-tests/platform.spec.js +++ b/integration-tests/platform.spec.js @@ -17,7 +17,7 @@ var helpers = require('../spec/helpers'); var path = require('path'); -var fs = require('fs'); +var fs = require('fs-extra'); var shell = require('shelljs'); var superspawn = require('cordova-common').superspawn; var config = require('../src/cordova/config'); diff --git a/integration-tests/plugman_fetch.spec.js b/integration-tests/plugman_fetch.spec.js index 985b9a412..52ee61883 100644 --- a/integration-tests/plugman_fetch.spec.js +++ b/integration-tests/plugman_fetch.spec.js @@ -18,7 +18,7 @@ */ var rewire = require('rewire'); var fetch = rewire('../src/plugman/fetch'); -var fs = require('fs'); +var fs = require('fs-extra'); var os = require('os'); var path = require('path'); var shell = require('shelljs'); diff --git a/integration-tests/plugman_uninstall.spec.js b/integration-tests/plugman_uninstall.spec.js index babff69e5..116db395a 100644 --- a/integration-tests/plugman_uninstall.spec.js +++ b/integration-tests/plugman_uninstall.spec.js @@ -26,7 +26,7 @@ var common = require('../spec/common'); var platforms = require('../src/platforms/platforms'); var xmlHelpers = require('cordova-common').xmlHelpers; var et = require('elementtree'); -var fs = require('fs'); +var fs = require('fs-extra'); var path = require('path'); var shell = require('shelljs'); var Q = require('q'); diff --git a/package.json b/package.json index 4140abb1c..62a3f9c07 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ }, "dependencies": { "aliasify": "^2.1.0", - "cordova-common": "^2.2.0", + "cordova-common": "github:dpogue/cordova-common#fs-extra", "cordova-create": "^1.1.0", "cordova-fetch": "^1.3.0", "cordova-js": "^4.2.2", @@ -26,6 +26,7 @@ "dep-graph": "1.1.0", "detect-indent": "^5.0.0", "elementtree": "^0.1.7", + "fs-extra": "^6.0.1", "glob": "^7.1.2", "init-package-json": "^1.2.0", "nopt": "4.0.1", diff --git a/spec/cordova/metadata/parser.spec.js b/spec/cordova/metadata/parser.spec.js index 5b2ace4a8..992d8ddee 100644 --- a/spec/cordova/metadata/parser.spec.js +++ b/spec/cordova/metadata/parser.spec.js @@ -17,7 +17,7 @@ under the License. */ -var fs = require('fs'); +var fs = require('fs-extra'); var Parser = require('../../../src/cordova/metadata/parser'); var ParserHelper = require('../../../src/cordova/metadata/parserhelper/ParserHelper'); diff --git a/spec/cordova/metadata/parserhelper/preferences.spec.js b/spec/cordova/metadata/parserhelper/preferences.spec.js index 73dc0b961..f7ee89034 100644 --- a/spec/cordova/metadata/parserhelper/preferences.spec.js +++ b/spec/cordova/metadata/parserhelper/preferences.spec.js @@ -18,7 +18,7 @@ */ var path = require('path'); -var fs = require('fs'); +var fs = require('fs-extra'); var events = require('cordova-common').events; var preferences = require('../../../../src/cordova/metadata/parserhelper/preferences'); var ConfigParser = require('cordova-common').ConfigParser; diff --git a/spec/cordova/platform/addHelper.spec.js b/spec/cordova/platform/addHelper.spec.js index ce7607824..23da400af 100644 --- a/spec/cordova/platform/addHelper.spec.js +++ b/spec/cordova/platform/addHelper.spec.js @@ -17,9 +17,8 @@ /* eslint-env jasmine */ var path = require('path'); -var fs = require('fs'); +var fs = require('fs-extra'); var Q = require('q'); -var shell = require('shelljs'); var events = require('cordova-common').events; var rewire = require('rewire'); var platform_addHelper = rewire('../../../src/cordova/platform/addHelper'); @@ -64,7 +63,7 @@ describe('cordova/platform/addHelper', function () { prepare_mock = jasmine.createSpy('prepare mock').and.returnValue(Q()); prepare_mock.preparePlatforms = jasmine.createSpy('preparePlatforms mock').and.returnValue(Q()); prepare_revert_mock = platform_addHelper.__set__('prepare', prepare_mock); - spyOn(shell, 'mkdir'); + spyOn(fs, 'ensureDirSync'); spyOn(fs, 'existsSync').and.returnValue(false); spyOn(fs, 'readFileSync'); spyOn(fs, 'writeFileSync'); diff --git a/spec/cordova/platform/check.spec.js b/spec/cordova/platform/check.spec.js index bb4456d29..0100ad751 100644 --- a/spec/cordova/platform/check.spec.js +++ b/spec/cordova/platform/check.spec.js @@ -16,7 +16,7 @@ http://www.apache.org/licenses/LICENSE-2.0 */ var Q = require('q'); -var shell = require('shelljs'); +var fs = require('fs-extra'); var events = require('cordova-common').events; var superspawn = require('cordova-common').superspawn; var rewire = require('rewire'); @@ -30,7 +30,7 @@ describe('cordova/platform/check', function () { beforeEach(function () { spyOn(events, 'emit'); spyOn(superspawn, 'spawn').and.callThrough(); - spyOn(shell, 'rm'); + spyOn(fs, 'removeSync'); spyOn(cordova_util, 'listPlatforms'); }); @@ -39,7 +39,7 @@ describe('cordova/platform/check', function () { 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(shell.rm).toHaveBeenCalledWith('-rf', jasmine.any(String)); + expect(fs.removeSync).toHaveBeenCalledWith(jasmine.any(String)); }).fail(function (err) { fail('unexpected failure handler invoked!'); console.error(err); diff --git a/spec/cordova/platform/getPlatformDetailsFromDir.spec.js b/spec/cordova/platform/getPlatformDetailsFromDir.spec.js index c551f0816..247ae5f18 100644 --- a/spec/cordova/platform/getPlatformDetailsFromDir.spec.js +++ b/spec/cordova/platform/getPlatformDetailsFromDir.spec.js @@ -16,7 +16,7 @@ */ var path = require('path'); -var fs = require('fs'); +var fs = require('fs-extra'); var Q = require('q'); var rewire = require('rewire'); var cordova_util = require('../../../src/cordova/util'); diff --git a/spec/cordova/platform/remove.spec.js b/spec/cordova/platform/remove.spec.js index 9f42fe8ce..171dff489 100644 --- a/spec/cordova/platform/remove.spec.js +++ b/spec/cordova/platform/remove.spec.js @@ -16,7 +16,7 @@ */ var path = require('path'); -var fs = require('fs'); +var fs = require('fs-extra'); var Q = require('q'); var events = require('cordova-common').events; var rewire = require('rewire'); diff --git a/spec/cordova/plugin/add.spec.js b/spec/cordova/plugin/add.spec.js index 4164f9c5b..16e48af00 100644 --- a/spec/cordova/plugin/add.spec.js +++ b/spec/cordova/plugin/add.spec.js @@ -26,7 +26,7 @@ var add = rewire('../../../src/cordova/plugin/add'); var plugman = require('../../../src/plugman/plugman'); var cordova_util = require('../../../src/cordova/util'); var path = require('path'); -var fs = require('fs'); +var fs = require('fs-extra'); var config = require('../../../src/cordova/config'); var events = require('cordova-common').events; var plugin_util = require('../../../src/cordova/plugin/util'); diff --git a/spec/cordova/plugin/remove.spec.js b/spec/cordova/plugin/remove.spec.js index ec59b11da..da606bade 100644 --- a/spec/cordova/plugin/remove.spec.js +++ b/spec/cordova/plugin/remove.spec.js @@ -27,7 +27,7 @@ var cordova_util = require('../../../src/cordova/util'); var metadata = require('../../../src/plugman/util/metadata'); var events = require('cordova-common').events; var plugman = require('../../../src/plugman/plugman'); -var fs = require('fs'); +var fs = require('fs-extra'); var prepare = require('../../../src/cordova/prepare'); var plugin_util = require('../../../src/cordova/plugin/util'); var config = require('../../../src/cordova/config'); diff --git a/spec/cordova/plugin/save.spec.js b/spec/cordova/plugin/save.spec.js index d51cf1149..507259263 100644 --- a/spec/cordova/plugin/save.spec.js +++ b/spec/cordova/plugin/save.spec.js @@ -21,7 +21,7 @@ /* globals fail */ var rewire = require('rewire'); -var fs = require('fs'); +var fs = require('fs-extra'); var save = rewire('../../../src/cordova/plugin/save'); var cordova_util = require('../../../src/cordova/util'); var semver = require('semver'); diff --git a/spec/cordova/plugin/util.spec.js b/spec/cordova/plugin/util.spec.js index 47d066767..37ccf1c51 100644 --- a/spec/cordova/plugin/util.spec.js +++ b/spec/cordova/plugin/util.spec.js @@ -20,7 +20,7 @@ var rewire = require('rewire'); var plugin_util = rewire('../../../src/cordova/plugin/util'); -var shell = require('shelljs'); +var fs = require('fs-extra'); var events = require('cordova-common').events; describe('cordova/plugin/util', function () { @@ -29,7 +29,7 @@ describe('cordova/plugin/util', function () { var cfg_parser_revert_mock; var cfg_parser_mock = function () {}; beforeEach(function () { - spyOn(shell, 'rm'); + spyOn(fs, 'removeSync'); spyOn(events, 'emit'); cfg_parser_mock.prototype = jasmine.createSpyObj('config parser protytpe mock', ['getPlugin']); cfg_parser_revert_mock = plugin_util.__set__('ConfigParser', cfg_parser_mock); @@ -97,7 +97,7 @@ describe('cordova/plugin/util', function () { plugin_info_mock.prototype.getPreferences.and.returnValue({key: 'FCM_VERSION', value: undefined}); var opts = { cli_variables: {} }; expect(function () { plugin_util.mergeVariables(plugin_info_mock.prototype, cfg_parser_mock.prototype, opts); }).toThrow(); - expect(shell.rm).toHaveBeenCalledWith('-rf', undefined); + expect(fs.removeSync).toHaveBeenCalledWith(undefined); expect(events.emit).toHaveBeenCalledWith('verbose', 'Removing undefined because mandatory plugin variables were missing.'); }); }); diff --git a/spec/cordova/plugin_parser.spec.js b/spec/cordova/plugin_parser.spec.js index c0356971b..ce25c6353 100644 --- a/spec/cordova/plugin_parser.spec.js +++ b/spec/cordova/plugin_parser.spec.js @@ -18,7 +18,7 @@ */ /* eslint-env jasmine */ var path = require('path'); -var fs = require('fs'); +var fs = require('fs-extra'); var Plugin_parser = require('../../src/cordova/plugin_parser'); var xml = path.join(__dirname, 'fixtures', 'plugins', 'test', 'plugin.xml'); diff --git a/spec/cordova/serve.spec.js b/spec/cordova/serve.spec.js index 45d6dd651..bd482e3d6 100644 --- a/spec/cordova/serve.spec.js +++ b/spec/cordova/serve.spec.js @@ -23,7 +23,7 @@ var cordova = require('../../src/cordova/cordova'); var console = require('console'); var path = require('path'); var shell = require('shelljs'); -var fs = require('fs'); +var fs = require('fs-extra'); var Q = require('q'); var tempDir; var http = require('http'); diff --git a/spec/cordova/util.spec.js b/spec/cordova/util.spec.js index 8be8a085b..2d01a53f6 100644 --- a/spec/cordova/util.spec.js +++ b/spec/cordova/util.spec.js @@ -17,9 +17,8 @@ under the License. */ -var shell = require('shelljs'); var path = require('path'); -var fs = require('fs'); +var fs = require('fs-extra'); var util = require('../../src/cordova/util'); var events = require('../../cordova-lib').events; var helpers = require('../helpers'); @@ -36,12 +35,12 @@ describe('util module', function () { process.chdir(cwd); }); function removeDir (directory) { - shell.rm('-rf', directory); + fs.removeSync(directory); } it('Test 001 : should return false if it hits the home directory', function () { var somedir = path.join(home, 'somedir'); removeDir(somedir); - shell.mkdir(somedir); + fs.ensureDirSync(somedir); expect(util.isCordova(somedir)).toEqual(false); }); it('Test 002 : should return false if it cannot find a .cordova directory up the directory tree', function () { @@ -52,8 +51,8 @@ describe('util module', function () { var somedir = path.join(home, 'somedir'); var anotherdir = path.join(somedir, 'anotherdir'); removeDir(somedir); - shell.mkdir('-p', anotherdir); - shell.mkdir('-p', path.join(somedir, 'www', 'config.xml')); + fs.ensureDirSync(anotherdir); + fs.ensureDirSync(path.join(somedir, 'www', 'config.xml')); expect(util.isCordova(somedir)).toEqual(somedir); }); it('Test 004 : should ignore PWD when its undefined', function () { @@ -61,9 +60,9 @@ describe('util module', function () { var somedir = path.join(home, 'somedir'); var anotherdir = path.join(somedir, 'anotherdir'); removeDir(somedir); - shell.mkdir('-p', anotherdir); - shell.mkdir('-p', path.join(somedir, 'www')); - shell.mkdir('-p', path.join(somedir, 'config.xml')); + fs.ensureDirSync(anotherdir); + fs.ensureDirSync(path.join(somedir, 'www')); + fs.ensureDirSync(path.join(somedir, 'config.xml')); process.chdir(anotherdir); expect(util.isCordova()).toEqual(somedir); }); @@ -71,8 +70,8 @@ describe('util module', function () { var somedir = path.join(home, 'somedir'); var anotherdir = path.join(somedir, 'anotherdir'); removeDir(somedir); - shell.mkdir('-p', anotherdir); - shell.mkdir('-p', path.join(somedir, 'www', 'config.xml')); + fs.ensureDirSync(anotherdir); + fs.ensureDirSync(path.join(somedir, 'www', 'config.xml')); process.env['PWD'] = anotherdir; process.chdir(path.sep); expect(util.isCordova()).toEqual(somedir); @@ -81,8 +80,8 @@ describe('util module', function () { var somedir = path.join(home, 'somedir'); var anotherdir = path.join(somedir, 'anotherdir'); removeDir(somedir); - shell.mkdir('-p', anotherdir); - shell.mkdir('-p', path.join(somedir, 'www', 'config.xml')); + fs.ensureDirSync(anotherdir); + fs.ensureDirSync(path.join(somedir, 'www', 'config.xml')); process.env['PWD'] = path.sep; process.chdir(anotherdir); expect(util.isCordova()).toEqual(somedir); @@ -91,24 +90,24 @@ describe('util module', function () { var somedir = path.join(home, 'somedir'); var anotherdir = path.join(somedir, 'anotherdir'); removeDir(somedir); - shell.mkdir('-p', anotherdir); - shell.mkdir('-p', path.join(anotherdir, 'www', 'config.xml')); - shell.mkdir('-p', path.join(somedir, 'www')); - shell.mkdir('-p', path.join(somedir, 'config.xml')); + fs.ensureDirSync(anotherdir); + fs.ensureDirSync(path.join(anotherdir, 'www', 'config.xml')); + fs.ensureDirSync(path.join(somedir, 'www')); + fs.ensureDirSync(path.join(somedir, 'config.xml')); expect(util.isCordova(anotherdir)).toEqual(somedir); }); }); describe('deleteSvnFolders method', function () { afterEach(function () { - shell.rm('-rf', temp); + fs.removeSync(temp); }); it('Test 008 : should delete .svn folders in any subdirectory of specified dir', function () { var one = path.join(temp, 'one'); var two = path.join(temp, 'two'); var one_svn = path.join(one, '.svn'); var two_svn = path.join(two, '.svn'); - shell.mkdir('-p', one_svn); - shell.mkdir('-p', two_svn); + fs.ensureDirSync(one_svn); + fs.ensureDirSync(two_svn); util.deleteSvnFolders(temp); expect(fs.existsSync(one_svn)).toEqual(false); expect(fs.existsSync(two_svn)).toEqual(false); @@ -116,18 +115,18 @@ describe('util module', function () { }); describe('listPlatforms method', function () { afterEach(function () { - shell.rm('-rf', temp); + fs.removeSync(temp); }); it('Test 009 : should only return supported platform directories present in a cordova project dir', function () { var platforms = path.join(temp, 'platforms'); - shell.mkdir('-p', path.join(platforms, 'android')); - shell.mkdir('-p', path.join(platforms, 'ios')); - shell.mkdir('-p', path.join(platforms, 'wp8')); - shell.mkdir('-p', path.join(platforms, 'atari')); + fs.ensureDirSync(path.join(platforms, 'android')); + fs.ensureDirSync(path.join(platforms, 'ios')); + fs.ensureDirSync(path.join(platforms, 'wp8')); + fs.ensureDirSync(path.join(platforms, 'atari')); // create a typical platforms.json file, it should not be returned as a platform - shell.exec('touch ' + path.join(platforms, 'platforms.json')); + fs.ensureFileSync(path.join(platforms, 'platforms.json')); var res = util.listPlatforms(temp); expect(res.length).toEqual(4); @@ -135,16 +134,15 @@ describe('util module', function () { }); describe('getInstalledPlatformsWithVersions method', function () { afterEach(function () { - shell.rm('-rf', temp); + fs.removeSync(temp); }); it('Test 010 : should get the supported platforms in the cordova project dir along with their reported versions', function (done) { var platforms = path.join(temp, 'platforms'); var android = path.join(platforms, 'android'); - shell.mkdir('-p', android); + fs.ensureDirSync(android); - shell.cp('-R', - path.join(__dirname, 'fixtures', 'platforms', helpers.testPlatform), platforms); + fs.copySync(path.join(__dirname, 'fixtures', 'platforms', helpers.testPlatform), path.join(platforms, helpers.testPlatform)); util.getInstalledPlatformsWithVersions(temp) .then(function (platformMap) { expect(platformMap['android']).toBe('3.1.0'); @@ -153,7 +151,7 @@ describe('util module', function () { }); describe('findPlugins method', function () { afterEach(function () { - shell.rm('-rf', temp); + fs.removeSync(temp); }); it('Test 011 : should only return plugin directories present in a cordova project dir', function () { var plugins = path.join(temp, 'plugins'); @@ -161,10 +159,10 @@ describe('util module', function () { var ios = path.join(plugins, 'ios'); var wp8_dir = path.join(plugins, 'wp8'); var atari = path.join(plugins, 'atari'); - shell.mkdir('-p', android); - shell.mkdir('-p', ios); - shell.mkdir('-p', wp8_dir); - shell.mkdir('-p', atari); + fs.ensureDirSync(android); + fs.ensureDirSync(ios); + fs.ensureDirSync(wp8_dir); + fs.ensureDirSync(atari); var res = util.findPlugins(plugins); expect(res.length).toEqual(4); }); @@ -173,9 +171,9 @@ describe('util module', function () { var android = path.join(plugins, 'android'); var ios = path.join(plugins, 'ios'); var svn = path.join(plugins, '.svn'); - shell.mkdir('-p', android); - shell.mkdir('-p', ios); - shell.mkdir('-p', svn); + fs.ensureDirSync(android); + fs.ensureDirSync(ios); + fs.ensureDirSync(svn); var res = util.findPlugins(plugins); expect(res.length).toEqual(2); expect(res.indexOf('.svn')).toEqual(-1); @@ -185,9 +183,9 @@ describe('util module', function () { var android = path.join(plugins, 'android'); var ios = path.join(plugins, 'ios'); var cvs = path.join(plugins, 'CVS'); - shell.mkdir('-p', android); - shell.mkdir('-p', ios); - shell.mkdir('-p', cvs); + fs.ensureDirSync(android); + fs.ensureDirSync(ios); + fs.ensureDirSync(cvs); var res = util.findPlugins(plugins); expect(res.length).toEqual(2); expect(res.indexOf('CVS')).toEqual(-1); diff --git a/spec/helpers.js b/spec/helpers.js index f9fd7cdcd..24514f0ae 100644 --- a/spec/helpers.js +++ b/spec/helpers.js @@ -18,8 +18,7 @@ */ var path = require('path'); -var fs = require('fs'); -var shell = require('shelljs'); +var fs = require('fs-extra'); var os = require('os'); var ConfigParser = require('cordova-common').ConfigParser; @@ -40,10 +39,7 @@ module.exports.tmpDir = function (subdir) { if (subdir) { dir = path.join(dir, subdir); } - if (fs.existsSync(dir)) { - shell.rm('-rf', dir); - } - shell.mkdir('-p', dir); + fs.emptyDirSync(dir); return dir; }; diff --git a/spec/plugman/add_platform.spec.js b/spec/plugman/add_platform.spec.js index 9631d2ceb..8d8e727a6 100644 --- a/spec/plugman/add_platform.spec.js +++ b/spec/plugman/add_platform.spec.js @@ -18,7 +18,7 @@ */ var platform = require('../../src/plugman/platform'); var Q = require('q'); -var fs = require('fs'); +var fs = require('fs-extra'); describe('platform add/remove', function () { it('Test 001 : should call platform add', function () { diff --git a/spec/plugman/create.spec.js b/spec/plugman/create.spec.js index e538851e8..f2038acd6 100644 --- a/spec/plugman/create.spec.js +++ b/spec/plugman/create.spec.js @@ -18,8 +18,7 @@ */ var create = require('../../src/plugman/create'); var Q = require('q'); -var fs = require('fs'); -var shell = require('shelljs'); +var fs = require('fs-extra'); var plugman = require('../../src/plugman/plugman'); describe('create', function () { @@ -40,7 +39,7 @@ describe('create plugin', function () { beforeEach(function () { existsSync = spyOn(fs, 'existsSync').and.returnValue(false); - mkdir = spyOn(shell, 'mkdir').and.returnValue(true); + mkdir = spyOn(fs, 'ensureDirSync').and.returnValue(true); writeFileSync = spyOn(fs, 'writeFileSync'); done = false; }); diff --git a/spec/plugman/install.spec.js b/spec/plugman/install.spec.js index 3341ea395..a18d3c242 100644 --- a/spec/plugman/install.spec.js +++ b/spec/plugman/install.spec.js @@ -28,9 +28,9 @@ var plugman = require('../../src/plugman/plugman'); var platforms = require('../../src/plugman/platforms/common'); var knownPlatforms = require('../../src/platforms/platforms'); var common = require('../common'); -var fs = require('fs'); +var rawfs = require('fs'); +var fs = require('fs-extra'); var os = require('os'); -var shell = require('shelljs'); var child_process = require('child_process'); var semver = require('semver'); var Q = require('q'); @@ -60,11 +60,11 @@ var plugins = { 'C@1.0.0': path.join(plugins_dir, 'dependencies', 'C@1.0.0') }; var results = {}; -var TIMEOUT = 90000; +var TIMEOUT = 9000; var superspawn = require('cordova-common').superspawn; // Pre-crete the temp dir, without it the test fails. -shell.mkdir('-p', temp_dir); +fs.ensureDirSync(temp_dir); var existsSync = fs.existsSync; @@ -127,8 +127,8 @@ describe('plugman install start', function () { }); it('Test 001 : plugman install start', function (done) { - shell.rm('-rf', project); - shell.cp('-R', path.join(srcProject, '*'), project); + fs.removeSync(project); + fs.copySync(srcProject, project); // Every time when addPlugin is called it will return some truthy value var returnValueIndex = 0; @@ -191,15 +191,16 @@ describe('install', function () { cb(false, '', ''); // eslint-disable-line standard/no-callback-literal }); spawnSpy = spyOn(superspawn, 'spawn').and.returnValue(Q('3.1.0')); - spyOn(fs, 'mkdirSync').and.returnValue(true); - spyOn(shell, 'mkdir').and.returnValue(true); + spyOn(fs, 'ensureDirSync').and.returnValue(true); spyOn(platforms, 'copyFile').and.returnValue(true); fetchSpy = spyOn(plugman, 'fetch').and.returnValue(Q(plugins['com.cordova.engine'])); + chmod = spyOn(rawfs, 'chmodSync').and.returnValue(true); chmod = spyOn(fs, 'chmodSync').and.returnValue(true); + spyOn(rawfs, 'writeFileSync').and.returnValue(true); spyOn(fs, 'writeFileSync').and.returnValue(true); - cp = spyOn(shell, 'cp').and.returnValue(true); - rm = spyOn(shell, 'rm').and.returnValue(true); + cp = spyOn(fs, 'copySync').and.returnValue(true); + rm = spyOn(fs, 'removeSync').and.returnValue(true); add_to_queue = spyOn(PlatformJson.prototype, 'addInstalledPluginToPrepareQueue'); done = false; }); @@ -322,6 +323,7 @@ describe('install', function () { describe('with dependencies', function () { var emit; beforeEach(function () { + spyOn(rawfs, 'existsSync').and.callFake(fake['existsSync']['noPlugins']); spyOn(fs, 'existsSync').and.callFake(fake['existsSync']['noPlugins']); fetchSpy.and.callFake(fake['fetch']['dependencies']); emit = spyOn(events, 'emit'); @@ -526,6 +528,6 @@ describe('install', function () { describe('end', function () { it('Test 034 : end', function () { - shell.rm('-rf', temp_dir); + fs.removeSync(temp_dir); }, TIMEOUT); }); diff --git a/spec/plugman/platforms/common.spec.js b/spec/plugman/platforms/common.spec.js index d16c2d513..a5a3daacc 100644 --- a/spec/plugman/platforms/common.spec.js +++ b/spec/plugman/platforms/common.spec.js @@ -18,9 +18,8 @@ var common = require('../../../src/plugman/platforms/common'); var path = require('path'); -var fs = require('fs'); +var fs = require('fs-extra'); var osenv = require('os'); -var shell = require('shelljs'); var test_dir = path.join(osenv.tmpdir(), 'test_plugman'); var project_dir = path.join(test_dir, 'project'); var src = path.join(project_dir, 'src'); @@ -35,19 +34,19 @@ var non_plugin_file = path.join(osenv.tmpdir(), 'non_plugin_file'); describe('common platform handler', function () { describe('resolveSrcPath', function () { it('Test 001 : should not throw if path exists', function () { - shell.mkdir('-p', test_dir); + fs.ensureDirSync(test_dir); var target = path.join(test_dir, 'somefile'); fs.writeFileSync(target, '80085', 'utf-8'); expect(function () { common.resolveSrcPath(test_dir, 'somefile'); }).not.toThrow(); - shell.rm('-rf', test_dir); + fs.removeSync(test_dir); }); }); describe('resolveTargetPath', function () { it('Test 002 : should throw if path exists', function () { - shell.mkdir('-p', test_dir); + fs.ensureDirSync(test_dir); expect(function () { common.resolveTargetPath(test_dir); }).toThrow(); - shell.rm('-rf', test_dir); + fs.removeSync(test_dir); }); it('Test 003 : should not throw if path cannot be resolved', function () { @@ -62,15 +61,15 @@ describe('common platform handler', function () { }); it('Test 005 : should throw if src not in plugin directory', function () { - shell.mkdir('-p', project_dir); + fs.ensureDirSync(project_dir); fs.writeFileSync(non_plugin_file, 'contents', 'utf-8'); expect(function () { common.copyFile(test_dir, '../non_plugin_file', project_dir, dest); }) .toThrow(new Error('"' + non_plugin_file + '" not located within plugin!')); - shell.rm('-rf', test_dir); + fs.removeSync(test_dir); }); it('Test 006 : should allow symlink src, if inside plugin', function () { - shell.mkdir('-p', java_dir); + fs.ensureDirSync(java_dir); fs.writeFileSync(java_file, 'contents', 'utf-8'); // This will fail on windows if not admin - ignore the error in that case. @@ -79,13 +78,13 @@ describe('common platform handler', function () { } common.copyFile(test_dir, symlink_file, project_dir, dest); - shell.rm('-rf', project_dir); + fs.removeSync(project_dir); }); it('Test 007 : should deeply symlink directory tree when src is a directory', function () { var symlink_dir_relative_subdir = path.dirname(symlink_dir_relative_file); - shell.mkdir('-p', path.join(symlink_dir, symlink_dir_relative_subdir)); + fs.ensureDirSync(path.join(symlink_dir, symlink_dir_relative_subdir)); fs.writeFileSync(path.join(symlink_dir, symlink_dir_relative_file), 'contents', 'utf-8'); // This will fail on windows if not admin - ignore the error in that case. @@ -97,11 +96,11 @@ describe('common platform handler', function () { common.copyFile(test_dir, symlink_dir, project_dir, dest, create_symlink); expect(path.resolve(dest, symlink_dir_relative_subdir, fs.readlinkSync(path.join(dest, symlink_dir_relative_file)))).toBe(path.resolve(symlink_dir, symlink_dir_relative_file)); - shell.rm('-rf', project_dir); + fs.removeSync(project_dir); }); it('Test 008 : should throw if symlink is linked to a file outside the plugin', function () { - shell.mkdir('-p', java_dir); + fs.ensureDirSync(java_dir); fs.writeFileSync(non_plugin_file, 'contents', 'utf-8'); // This will fail on windows if not admin - ignore the error in that case. @@ -111,73 +110,73 @@ describe('common platform handler', function () { expect(function () { common.copyFile(test_dir, symlink_file, project_dir, dest); }) .toThrow(new Error('"' + symlink_file + '" not located within plugin!')); - shell.rm('-rf', project_dir); + fs.removeSync(project_dir); }); it('Test 009 : should throw if dest is outside the project directory', function () { - shell.mkdir('-p', java_dir); + fs.ensureDirSync(java_dir); fs.writeFileSync(java_file, 'contents', 'utf-8'); expect(function () { common.copyFile(test_dir, java_file, project_dir, non_plugin_file); }) .toThrow(new Error('"' + non_plugin_file + '" not located within project!')); - shell.rm('-rf', project_dir); + fs.removeSync(project_dir); }); it('Test 010 : should call mkdir -p on target path', function () { - shell.mkdir('-p', java_dir); + fs.ensureDirSync(java_dir); fs.writeFileSync(java_file, 'contents', 'utf-8'); - var s = spyOn(shell, 'mkdir').and.callThrough(); + var s = spyOn(fs, 'ensureDirSync').and.callThrough(); var resolvedDest = common.resolveTargetPath(project_dir, dest); common.copyFile(test_dir, java_file, project_dir, dest); expect(s).toHaveBeenCalled(); - expect(s).toHaveBeenCalledWith('-p', path.dirname(resolvedDest)); - shell.rm('-rf', project_dir); + expect(s).toHaveBeenCalledWith(path.dirname(resolvedDest)); + fs.removeSync(project_dir); }); it('Test 011 : should call cp source/dest paths', function () { - shell.mkdir('-p', java_dir); + fs.ensureDirSync(java_dir); fs.writeFileSync(java_file, 'contents', 'utf-8'); - var s = spyOn(shell, 'cp').and.callThrough(); + var s = spyOn(fs, 'copySync').and.callThrough(); var resolvedDest = common.resolveTargetPath(project_dir, dest); common.copyFile(test_dir, java_file, project_dir, dest); expect(s).toHaveBeenCalled(); - expect(s).toHaveBeenCalledWith('-f', java_file, resolvedDest); + expect(s).toHaveBeenCalledWith(java_file, resolvedDest); - shell.rm('-rf', project_dir); + fs.removeSync(project_dir); }); }); describe('copyNewFile', function () { it('Test 012 : should throw if target path exists', function () { - shell.mkdir('-p', dest); + fs.ensureDirSync(dest); expect(function () { common.copyNewFile(test_dir, src, project_dir, dest); }) .toThrow(new Error('"' + dest + '" already exists!')); - shell.rm('-rf', dest); + fs.removeSync(dest); }); }); describe('deleteJava', function () { it('Test 013 : should call fs.unlinkSync on the provided paths', function () { - shell.mkdir('-p', java_dir); + fs.ensureDirSync(java_dir); fs.writeFileSync(java_file, 'contents', 'utf-8'); - var s = spyOn(fs, 'unlinkSync').and.callThrough(); + var s = spyOn(fs, 'removeSync').and.callThrough(); common.deleteJava(project_dir, java_file); expect(s).toHaveBeenCalled(); expect(s).toHaveBeenCalledWith(path.resolve(project_dir, java_file)); - shell.rm('-rf', java_dir); + fs.removeSync(java_dir); }); it('Test 014 : should delete empty directories after removing source code in a java src path hierarchy', function () { - shell.mkdir('-p', java_dir); + fs.ensureDirSync(java_dir); fs.writeFileSync(java_file, 'contents', 'utf-8'); common.deleteJava(project_dir, java_file); @@ -185,17 +184,17 @@ describe('common platform handler', function () { expect(fs.existsSync(java_dir)).not.toBe(true); expect(fs.existsSync(path.join(src, 'one'))).not.toBe(true); - shell.rm('-rf', java_dir); + fs.removeSync(java_dir); }); it('Test 015 : should never delete the top-level src directory, even if all plugins added were removed', function () { - shell.mkdir('-p', java_dir); + fs.ensureDirSync(java_dir); fs.writeFileSync(java_file, 'contents', 'utf-8'); common.deleteJava(project_dir, java_file); expect(fs.existsSync(src)).toBe(true); - shell.rm('-rf', java_dir); + fs.removeSync(java_dir); }); }); }); diff --git a/src/cordova/config.js b/src/cordova/config.js index 9b369a579..a0846a9e3 100644 --- a/src/cordova/config.js +++ b/src/cordova/config.js @@ -18,9 +18,8 @@ */ var path = require('path'); -var fs = require('fs'); +var fs = require('fs-extra'); var url = require('url'); -var shell = require('shelljs'); // Map of project_root -> JSON var configCache = {}; @@ -67,7 +66,7 @@ config.write = function set_config (project_root, json) { configCache[project_root] = contents; // Don't write the file for an empty config. if (contents !== '{}' || fs.existsSync(configPath)) { - shell.mkdir('-p', path.join(project_root, '.cordova')); + fs.ensureDirSync(path.join(project_root, '.cordova')); fs.writeFileSync(configPath, contents, 'utf-8'); } return json; diff --git a/src/cordova/info.js b/src/cordova/info.js index 8468736de..635e7c7bd 100644 --- a/src/cordova/info.js +++ b/src/cordova/info.js @@ -26,7 +26,7 @@ var cordova_util = require('./util'); var superspawn = require('cordova-common').superspawn; var pkg = require('../../package'); var path = require('path'); -var fs = require('fs'); +var fs = require('fs-extra'); var Q = require('q'); // Execute using a child_process exec, for any async command diff --git a/src/cordova/platform/addHelper.js b/src/cordova/platform/addHelper.js index 87ff75282..036cd916e 100644 --- a/src/cordova/platform/addHelper.js +++ b/src/cordova/platform/addHelper.js @@ -17,8 +17,7 @@ var Q = require('q'); var path = require('path'); -var fs = require('fs'); -var shell = require('shelljs'); +var fs = require('fs-extra'); var semver = require('semver'); var fetch = require('cordova-fetch'); var _ = require('underscore'); @@ -63,7 +62,7 @@ function addHelper (cmd, hooksRunner, projectRoot, targets, opts) { // The "platforms" dir is safe to delete, it's almost equivalent to // cordova platform rm var platformsDir = path.join(projectRoot, 'platforms'); - shell.mkdir('-p', platformsDir); + fs.ensureDirSync(platformsDir); return hooksRunner.fire('before_platform_' + cmd, opts) .then(function () { diff --git a/src/cordova/platform/check.js b/src/cordova/platform/check.js index e190f375b..c6c611d1b 100644 --- a/src/cordova/platform/check.js +++ b/src/cordova/platform/check.js @@ -16,10 +16,10 @@ */ var Q = require('q'); +var fs = require('fs-extra'); var path = require('path'); var os = require('os'); var semver = require('semver'); -var shell = require('shelljs'); var events = require('cordova-common').events; var superspawn = require('cordova-common').superspawn; var cordova_util = require('../util'); @@ -123,7 +123,7 @@ function check (hooksRunner, projectRoot) { var results = ''; var resultQ = Q.defer(); events._events = listeners; - shell.rm('-rf', scratch); + fs.removeSync(scratch); updateCordova.promise.then(function (versions) { var message = ''; if (versions && semver.gt(versions[0], versions[1])) { @@ -145,7 +145,7 @@ function check (hooksRunner, projectRoot) { }).done(); }).catch(function () { events._events = listeners; - shell.rm('-rf', scratch); + fs.removeSync(scratch); }).done(); return result.promise; } diff --git a/src/cordova/platform/remove.js b/src/cordova/platform/remove.js index 1fa5cb400..f171a471c 100644 --- a/src/cordova/platform/remove.js +++ b/src/cordova/platform/remove.js @@ -17,8 +17,7 @@ var Q = require('q'); var path = require('path'); -var fs = require('fs'); -var shell = require('shelljs'); +var fs = require('fs-extra'); var CordovaError = require('cordova-common').CordovaError; var ConfigParser = require('cordova-common').ConfigParser; var events = require('cordova-common').events; @@ -38,7 +37,7 @@ function remove (hooksRunner, projectRoot, targets, opts) { return hooksRunner.fire('before_platform_rm', opts) .then(function () { targets.forEach(function (target) { - shell.rm('-rf', path.join(projectRoot, 'platforms', target)); + fs.removeSync(path.join(projectRoot, 'platforms', target)); cordova_util.removePlatformPluginsJson(projectRoot, target); }); }).then(function () { diff --git a/src/cordova/plugin/add.js b/src/cordova/plugin/add.js index 65a75812c..e838b07f6 100644 --- a/src/cordova/plugin/add.js +++ b/src/cordova/plugin/add.js @@ -30,7 +30,7 @@ var PluginInfoProvider = require('cordova-common').PluginInfoProvider; var events = require('cordova-common').events; var Q = require('q'); var path = require('path'); -var fs = require('fs'); +var fs = require('fs-extra'); var semver = require('semver'); var url = require('url'); var detectIndent = require('detect-indent'); diff --git a/src/cordova/plugin/remove.js b/src/cordova/plugin/remove.js index aee5e44d8..f0045a520 100644 --- a/src/cordova/plugin/remove.js +++ b/src/cordova/plugin/remove.js @@ -27,7 +27,7 @@ var plugman = require('../../plugman/plugman'); var metadata = require('../../plugman/util/metadata'); var Q = require('q'); var path = require('path'); -var fs = require('fs'); +var fs = require('fs-extra'); var PluginInfoProvider = require('cordova-common').PluginInfoProvider; var detectIndent = require('detect-indent'); diff --git a/src/cordova/plugin/save.js b/src/cordova/plugin/save.js index d24ffb5f9..9278d27da 100644 --- a/src/cordova/plugin/save.js +++ b/src/cordova/plugin/save.js @@ -22,7 +22,7 @@ var pluginSpec = require('./plugin_spec_parser'); var ConfigParser = require('cordova-common').ConfigParser; var PluginInfoProvider = require('cordova-common').PluginInfoProvider; var path = require('path'); -var fs = require('fs'); +var fs = require('fs-extra'); var Q = require('q'); var semver = require('semver'); diff --git a/src/cordova/plugin/util.js b/src/cordova/plugin/util.js index ef1f41554..d4346b254 100644 --- a/src/cordova/plugin/util.js +++ b/src/cordova/plugin/util.js @@ -19,7 +19,7 @@ var path = require('path'); var PluginInfoProvider = require('cordova-common').PluginInfoProvider; -var shell = require('shelljs'); +var fs = require('fs-extra'); var events = require('cordova-common').events; var CordovaError = require('cordova-common').CordovaError; var fetch = require('cordova-fetch'); @@ -72,7 +72,7 @@ function mergeVariables (pluginInfo, cfg, opts) { if (missingVariables.length) { events.emit('verbose', 'Removing ' + pluginInfo.dir + ' because mandatory plugin variables were missing.'); - shell.rm('-rf', pluginInfo.dir); + fs.removeSync(pluginInfo.dir); var msg = 'Variable(s) missing (use: --variable ' + missingVariables.join('=value --variable ') + '=value).'; throw new CordovaError(msg); } diff --git a/src/cordova/restore-util.js b/src/cordova/restore-util.js index 2c3f8c998..9a9e0a8e2 100644 --- a/src/cordova/restore-util.js +++ b/src/cordova/restore-util.js @@ -21,7 +21,7 @@ var cordova_util = require('./util'); var ConfigParser = require('cordova-common').ConfigParser; var path = require('path'); var Q = require('q'); -var fs = require('fs'); +var fs = require('fs-extra'); var events = require('cordova-common').events; var cordovaPlatform = require('./platform'); var semver = require('semver'); diff --git a/src/cordova/serve.js b/src/cordova/serve.js index e25beab33..79e4b7b62 100644 --- a/src/cordova/serve.js +++ b/src/cordova/serve.js @@ -26,7 +26,7 @@ var platforms = require('../platforms/platforms'); var ConfigParser = require('cordova-common').ConfigParser; var HooksRunner = require('../hooks/HooksRunner'); var Q = require('q'); -var fs = require('fs'); +var fs = require('fs-extra'); var events = require('cordova-common').events; var serve = require('cordova-serve'); diff --git a/src/cordova/util.js b/src/cordova/util.js index de982b9b1..c5e399ff4 100644 --- a/src/cordova/util.js +++ b/src/cordova/util.js @@ -17,11 +17,10 @@ under the License. */ -var fs = require('fs'); +var fs = require('fs-extra'); var path = require('path'); var events = require('cordova-common').events; var CordovaError = require('cordova-common').CordovaError; -var shell = require('shelljs'); var url = require('url'); var nopt = require('nopt'); var Q = require('q'); @@ -48,7 +47,7 @@ exports.globalConfig = global_config_path; Object.defineProperty(exports, 'libDirectory', { configurable: true, get: function () { - shell.mkdir('-p', lib_path); + fs.ensureDirSync(lib_path); exports.libDirectory = lib_path; return lib_path; } @@ -86,7 +85,7 @@ exports.removePlatformPluginsJson = removePlatformPluginsJson; // Remove .json file from plugins directory. function removePlatformPluginsJson (projectRoot, target) { var plugins_json = path.join(projectRoot, 'plugins', target + '.json'); - shell.rm('-f', plugins_json); + fs.removeSync(plugins_json); } // Used to prevent attempts of installing platforms that are not supported on @@ -214,7 +213,7 @@ function deleteSvnFolders (dir) { var fullpath = path.join(dir, entry); if (isDirectory(fullpath)) { if (entry === '.svn') { - shell.rm('-rf', fullpath); + fs.removeSync(fullpath); } else module.exports.deleteSvnFolders(fullpath); } }); diff --git a/src/hooks/HooksRunner.js b/src/hooks/HooksRunner.js index e05a541b5..41a738e57 100644 --- a/src/hooks/HooksRunner.js +++ b/src/hooks/HooksRunner.js @@ -22,7 +22,7 @@ var scriptsFinder = require('./scriptsFinder'); var Context = require('./Context'); var CordovaError = require('cordova-common').CordovaError; var path = require('path'); -var fs = require('fs'); +var fs = require('fs-extra'); var os = require('os'); var superspawn = require('cordova-common').superspawn; diff --git a/src/hooks/scriptsFinder.js b/src/hooks/scriptsFinder.js index 9481b207b..e8a6d43e6 100644 --- a/src/hooks/scriptsFinder.js +++ b/src/hooks/scriptsFinder.js @@ -18,7 +18,7 @@ */ var path = require('path'); -var fs = require('fs'); +var fs = require('fs-extra'); var cordovaUtil = require('../cordova/util'); var events = require('cordova-common').events; var PluginInfoProvider = require('cordova-common').PluginInfoProvider; diff --git a/src/platforms/platforms.js b/src/platforms/platforms.js index bd50e95b3..10ce3724f 100644 --- a/src/platforms/platforms.js +++ b/src/platforms/platforms.js @@ -18,7 +18,7 @@ */ var path = require('path'); -var fs = require('fs'); +var fs = require('fs-extra'); var util = require('../cordova/util'); var platforms = require('./platformsConfig.json'); var events = require('cordova-common').events; diff --git a/src/plugman/browserify.js b/src/plugman/browserify.js index 1a773711a..6421bfb0a 100644 --- a/src/plugman/browserify.js +++ b/src/plugman/browserify.js @@ -20,7 +20,7 @@ var path = require('path'); var aliasify = require('aliasify'); var common = require('./platforms/common'); -var fs = require('fs'); +var fs = require('fs-extra'); var childProcess = require('child_process'); var events = require('cordova-common').events; var bundle = require('cordova-js/tasks/lib/bundle-browserify'); diff --git a/src/plugman/create.js b/src/plugman/create.js index 5a216fe20..c436843d4 100644 --- a/src/plugman/create.js +++ b/src/plugman/create.js @@ -18,9 +18,8 @@ */ var Q = require('q'); -var fs = require('fs'); +var fs = require('fs-extra'); var path = require('path'); -var shell = require('shelljs'); var et = require('elementtree'); var CordovaError = require('cordova-common').CordovaError; var stripLicense = require('./util/strip-license'); @@ -59,8 +58,8 @@ module.exports = function create (name, id, version, pluginPath, options) { } // Setup the directory structure - shell.mkdir('-p', cwd + 'www'); - shell.mkdir('-p', cwd + 'src'); + fs.ensureDirSync(cwd + 'www'); + fs.ensureDirSync(cwd + 'src'); // Create a base plugin.js file baseJS = stripLicense.fromCode(fs.readFileSync(templatesDir + 'base.js', 'utf-8').replace(/%pluginName%/g, name)); diff --git a/src/plugman/createpackagejson.js b/src/plugman/createpackagejson.js index 7070b3820..330741c68 100644 --- a/src/plugman/createpackagejson.js +++ b/src/plugman/createpackagejson.js @@ -18,7 +18,7 @@ */ var Q = require('q'); -var fs = require('fs'); +var fs = require('fs-extra'); var path = require('path'); var PluginInfo = require('cordova-common').PluginInfo; var events = require('cordova-common').events; diff --git a/src/plugman/fetch.js b/src/plugman/fetch.js index 4d83f69c1..02da8e912 100644 --- a/src/plugman/fetch.js +++ b/src/plugman/fetch.js @@ -17,8 +17,7 @@ under the License. */ -var shell = require('shelljs'); -var fs = require('fs'); +var fs = require('fs-extra'); var url = require('url'); var underscore = require('underscore'); var semver = require('semver'); @@ -42,7 +41,7 @@ var localPlugins = null; module.exports = fetchPlugin; function fetchPlugin (plugin_src, plugins_dir, options) { // Ensure the containing directory exists. - shell.mkdir('-p', plugins_dir); + fs.ensureDirSync(plugins_dir); options = options || {}; options.subdir = options.subdir || '.'; options.searchpath = options.searchpath || []; @@ -292,7 +291,7 @@ function copyPlugin (pinfo, plugins_dir, link) { var plugin_dir = pinfo.dir; var dest = path.join(plugins_dir, pinfo.id); - shell.rm('-rf', dest); + fs.removeSync(dest); if (!link && dest.indexOf(path.resolve(plugin_dir) + path.sep) === 0) { @@ -309,12 +308,12 @@ function copyPlugin (pinfo, plugins_dir, link) { var relPath = path.relative(resolvedSrcPath, dest); var relativeRootFolder = relPath.split('\\')[0]; filenames.splice(filenames.indexOf(relativeRootFolder), 1); - shell.mkdir('-p', dest); + fs.ensureDirSync(dest); events.emit('verbose', 'Copying plugin "' + resolvedSrcPath + '" => "' + dest + '"'); events.emit('verbose', 'Skipping folder "' + relativeRootFolder + '"'); filenames.forEach(function (elem) { - shell.cp('-R', path.join(resolvedSrcPath, elem), dest); + fs.copySync(path.join(resolvedSrcPath, elem), dest); }); return dest; } else { @@ -329,9 +328,8 @@ function copyPlugin (pinfo, plugins_dir, link) { events.emit('verbose', 'Linking "' + dest + '" => "' + fixedPath + '"'); fs.symlinkSync(fixedPath, dest, 'dir'); } else { - shell.mkdir('-p', dest); events.emit('verbose', 'Copying plugin "' + plugin_dir + '" => "' + dest + '"'); - shell.cp('-R', path.join(plugin_dir, '*'), dest); + fs.copySync(plugin_dir, dest); } return dest; } diff --git a/src/plugman/help.js b/src/plugman/help.js index e4718d4bf..4ae6b064a 100644 --- a/src/plugman/help.js +++ b/src/plugman/help.js @@ -16,7 +16,7 @@ specific language governing permissions and limitations under the License. */ -var fs = require('fs'); +var fs = require('fs-extra'); var path = require('path'); var doc_txt = path.join(__dirname, 'help.txt'); diff --git a/src/plugman/init-defaults.js b/src/plugman/init-defaults.js index fbe4e9233..93bbbfe73 100644 --- a/src/plugman/init-defaults.js +++ b/src/plugman/init-defaults.js @@ -25,7 +25,7 @@ /* global prompt */ // PromZard file that is used by createpackagejson and init-package-json module -var fs = require('fs'); +var fs = require('fs-extra'); var path = require('path'); var defaults = require('./defaults.json'); diff --git a/src/plugman/install.js b/src/plugman/install.js index 51c6baf74..8a5a660fb 100644 --- a/src/plugman/install.js +++ b/src/plugman/install.js @@ -18,7 +18,7 @@ */ var path = require('path'); -var fs = require('fs'); +var fs = require('fs-extra'); var action_stack = require('cordova-common').ActionStack; var dep_graph = require('dep-graph'); var child_process = require('child_process'); @@ -29,7 +29,6 @@ var Q = require('q'); var platform_modules = require('../platforms/platforms'); var os = require('os'); var underscore = require('underscore'); -var shell = require('shelljs'); var events = require('cordova-common').events; var HooksRunner = require('../hooks/HooksRunner'); var isWindows = (os.platform().substr(0, 3) === 'win'); @@ -551,7 +550,7 @@ function installDependency (dep, install, options) { return Q() .then(function () { // Remove plugin - return shell.rm('-rf', path.join(install.plugins_dir, install.top_plugin_id)); + return fs.removeSync(path.join(install.plugins_dir, install.top_plugin_id)); }).then(function () { // Return promise chain and finally reject return Q.reject(new CordovaError(msg)); @@ -649,16 +648,16 @@ function isAbsolutePath (_path) { function copyPlugin (plugin_src_dir, plugins_dir, link, pluginInfoProvider) { var pluginInfo = new PluginInfo(plugin_src_dir); var dest = path.join(plugins_dir, pluginInfo.id); - shell.rm('-rf', dest); + fs.removeSync(dest); if (link) { events.emit('verbose', 'Symlinking from location "' + plugin_src_dir + '" to location "' + dest + '"'); - shell.mkdir('-p', path.dirname(dest)); + fs.ensureDirSync(path.dirname(dest)); fs.symlinkSync(plugin_src_dir, dest, 'dir'); } else { - shell.mkdir('-p', dest); + fs.ensureDirSync(dest); events.emit('verbose', 'Copying from location "' + plugin_src_dir + '" to location "' + dest + '"'); - shell.cp('-R', path.join(plugin_src_dir, '*'), dest); + fs.copySync(plugin_src_dir, dest); } pluginInfo.dir = dest; pluginInfoProvider.put(pluginInfo); diff --git a/src/plugman/platform.js b/src/plugman/platform.js index 05c71d24b..cbdfb7beb 100644 --- a/src/plugman/platform.js +++ b/src/plugman/platform.js @@ -19,8 +19,7 @@ var Q = require('q'); var et = require('elementtree'); -var fs = require('fs'); -var shell = require('shelljs'); +var fs = require('fs-extra'); var path = require('path'); var stripLicense = require('./util/strip-license'); @@ -79,7 +78,7 @@ module.exports = { fs.writeFileSync('plugin.xml', pluginxml.write('plugin.xml', {indent: 4}), 'utf-8'); // Remove the src/"platform" - shell.rm('-rf', 'src/' + platformName); + fs.removeSync('src/' + platformName); return Q(); } @@ -140,7 +139,7 @@ function doPlatformBase (templatesDir, platformName, pluginName, pluginID, plugi ); } - shell.mkdir('-p', 'src/' + platformName); + fs.ensureDirSync('src/' + platformName); for (i; i < baseFiles.length; i++) { fs.writeFileSync('src/' + platformName + '/' + pluginName + '.' + baseFiles[ i ].extension, baseFiles[ i ].file, 'utf-8'); diff --git a/src/plugman/platforms/common.js b/src/plugman/platforms/common.js index 4e03b6b4f..102948f65 100644 --- a/src/plugman/platforms/common.js +++ b/src/plugman/platforms/common.js @@ -17,9 +17,8 @@ under the License. */ -var shell = require('shelljs'); var path = require('path'); -var fs = require('fs'); +var fs = require('fs-extra'); var common; var cordovaUtil = require('../../cordova/util'); @@ -79,15 +78,12 @@ module.exports = common = { // check that dest path is located in project directory if (dest.indexOf(project_dir) !== 0) { throw new Error('"' + dest + '" not located within project!'); } - shell.mkdir('-p', path.dirname(dest)); + fs.ensureDirSync(path.dirname(dest)); if (link) { common.symlinkFileOrDirTree(src, dest); - } else if (fs.statSync(src).isDirectory()) { - // XXX shelljs decides to create a directory when -R|-r is used which sucks. http://goo.gl/nbsjq - shell.cp('-Rf', src + '/*', dest); } else { - shell.cp('-f', src, dest); + fs.copySync(src, dest); } }, // Same as copy file but throws error if target exists @@ -99,11 +95,11 @@ module.exports = common = { }, symlinkFileOrDirTree: function symlinkFileOrDirTree (src, dest) { if (fs.existsSync(dest)) { - shell.rm('-Rf', dest); + fs.removeSync(dest); } if (fs.statSync(src).isDirectory()) { - shell.mkdir('-p', dest); + fs.ensureDirSync(dest); fs.readdirSync(src).forEach(function (entry) { symlinkFileOrDirTree(path.join(src, entry), path.join(dest, entry)); }); @@ -114,11 +110,11 @@ module.exports = common = { // checks if file exists and then deletes. Error if doesn't exist removeFile: function (project_dir, src) { var file = module.exports.resolveSrcPath(project_dir, src); - shell.rm('-Rf', file); + fs.removeSync(file); }, // deletes file/directory without checking removeFileF: function (file) { - shell.rm('-Rf', file); + fs.removeSync(file); }, // Sometimes we want to remove some java, and prune any unnecessary empty directories deleteJava: function (project_dir, destFile) { @@ -136,7 +132,7 @@ module.exports = common = { while (curDir !== path.resolve(baseDir, stopper)) { if (fs.existsSync(curDir) && fs.readdirSync(curDir).length === 0) { - fs.rmdirSync(curDir); + fs.removeSync(curDir); curDir = path.resolve(curDir, '..'); } else { // directory not empty...do nothing @@ -183,7 +179,7 @@ module.exports = common = { scriptContent = 'cordova.define("' + moduleName + '", function(require, exports, module) { ' + scriptContent + '\n});\n'; var moduleDestination = path.resolve(www_dir, 'plugins', plugin_id, jsModule.src); - shell.mkdir('-p', path.dirname(moduleDestination)); + fs.ensureDirSync(path.dirname(moduleDestination)); fs.writeFileSync(moduleDestination, scriptContent, 'utf-8'); }, uninstall: function (jsModule, www_dir, plugin_id) { diff --git a/src/plugman/registry/manifest.js b/src/plugman/registry/manifest.js index a57e204f8..6ea450423 100644 --- a/src/plugman/registry/manifest.js +++ b/src/plugman/registry/manifest.js @@ -19,7 +19,7 @@ var path = require('path'); var Q = require('q'); -var fs = require('fs'); +var fs = require('fs-extra'); var whitelist = require('./whitelist'); var PluginInfo = require('cordova-common').PluginInfo; diff --git a/src/plugman/uninstall.js b/src/plugman/uninstall.js index 562636e49..a94f3d00c 100644 --- a/src/plugman/uninstall.js +++ b/src/plugman/uninstall.js @@ -18,9 +18,8 @@ */ var path = require('path'); -var fs = require('fs'); +var fs = require('fs-extra'); var semver = require('semver'); -var shell = require('shelljs'); var action_stack = require('cordova-common').ActionStack; var dependencies = require('./util/dependencies'); var CordovaError = require('cordova-common').CordovaError; @@ -128,7 +127,7 @@ module.exports.uninstallPlugin = function (id, plugins_dir, options) { return Q(); } - shell.rm('-rf', plugin_dir); + fs.removeSync(plugin_dir); events.emit('verbose', 'Deleted "' + id + '"'); if (options.fetch) { diff --git a/src/plugman/util/dependencies.js b/src/plugman/util/dependencies.js index fa3e4c19a..af89c3db1 100644 --- a/src/plugman/util/dependencies.js +++ b/src/plugman/util/dependencies.js @@ -19,7 +19,7 @@ var dep_graph = require('dep-graph'); var path = require('path'); -var fs = require('fs'); +var fs = require('fs-extra'); var underscore = require('underscore'); var events = require('cordova-common').events; var pkg; diff --git a/src/plugman/util/metadata.js b/src/plugman/util/metadata.js index e306bfbd9..75bc08091 100644 --- a/src/plugman/util/metadata.js +++ b/src/plugman/util/metadata.js @@ -17,7 +17,7 @@ under the License. */ -var fs = require('fs'); +var fs = require('fs-extra'); var path = require('path'); var cachedJson = null; diff --git a/src/plugman/util/search-and-replace.js b/src/plugman/util/search-and-replace.js index a27dc05e1..d5ee3092c 100644 --- a/src/plugman/util/search-and-replace.js +++ b/src/plugman/util/search-and-replace.js @@ -19,7 +19,7 @@ */ var glob = require('glob'); -var fs = require('fs'); +var fs = require('fs-extra'); module.exports = searchAndReplace; function searchAndReplace (srcGlob, variables) { diff --git a/src/util/unpack.js b/src/util/unpack.js index 6997fef05..afbf740ee 100644 --- a/src/util/unpack.js +++ b/src/util/unpack.js @@ -21,7 +21,7 @@ // this file is used by lib/cache.js var events = require('cordova-common').events; -var fs = require('fs'); +var fs = require('fs-extra'); var Q = require('q'); var tar = require('tar'); var zlib = require('zlib');