You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ra...@apache.org on 2018/06/17 13:26:42 UTC
[cordova-create] branch master updated: CB-14140 Use fs-extra
instead of shelljs (#19)
This is an automated email from the ASF dual-hosted git repository.
raphinesse pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cordova-create.git
The following commit(s) were added to refs/heads/master by this push:
new 71e66fe CB-14140 Use fs-extra instead of shelljs (#19)
71e66fe is described below
commit 71e66fe6af4035cfa5d22dcd96670151758b36b5
Author: Raphael von der Grün <ra...@gmail.com>
AuthorDate: Sun Jun 17 15:26:38 2018 +0200
CB-14140 Use fs-extra instead of shelljs (#19)
Co-authored-by: Christopher J. Brody <br...@litehelpers.net>
Co-authored-by: Raphael von der Grün <ra...@gmail.com>
---
index.js | 31 ++++++++++++++-----------------
package.json | 2 +-
spec/create.spec.js | 13 ++++++-------
spec/helpers.js | 5 ++---
4 files changed, 23 insertions(+), 28 deletions(-)
diff --git a/index.js b/index.js
index ec88303..22cc582 100644
--- a/index.js
+++ b/index.js
@@ -17,13 +17,13 @@
under the License.
*/
-var fs = require('fs');
+const fs = require('fs-extra');
+
var os = require('os');
var path = require('path');
var Promise = require('q');
var isUrl = require('is-url');
-var shell = require('shelljs');
var isObject = require('isobject');
var requireFresh = require('import-fresh');
var validateIdentifier = require('valid-identifier');
@@ -201,11 +201,11 @@ module.exports = function (dir, optionalId, optionalName, cfg, extEvents) {
copyIfNotExists(stockAssetPath('hooks'), path.join(dir, 'hooks'));
var configXmlExists = projectConfig(dir); // moves config to root if in www
if (!configXmlExists) {
- shell.cp(stockAssetPath('config.xml'), path.join(dir, 'config.xml'));
+ fs.copySync(stockAssetPath('config.xml'), path.join(dir, 'config.xml'));
}
} catch (e) {
if (!dirAlreadyExisted) {
- shell.rm('-rf', dir);
+ fs.removeSync(dir);
}
if (process.platform.slice(0, 3) === 'win' && e.code === 'EPERM') {
throw new CordovaError('Symlinks on Windows require Administrator privileges');
@@ -235,8 +235,8 @@ module.exports = function (dir, optionalId, optionalName, cfg, extEvents) {
}
// Create basic project structure.
- shell.mkdir('-p', path.join(dir, 'platforms'));
- shell.mkdir('-p', path.join(dir, 'plugins'));
+ fs.ensureDirSync(path.join(dir, 'platforms'));
+ fs.ensureDirSync(path.join(dir, 'plugins'));
var configPath = path.join(dir, 'config.xml');
// only update config.xml if not a symlink
@@ -259,8 +259,7 @@ module.exports = function (dir, optionalId, optionalName, cfg, extEvents) {
*/
function copyIfNotExists (src, dst) {
if (!fs.existsSync(dst) && src) {
- shell.mkdir(dst);
- shell.cp('-R', path.join(src, '*'), dst);
+ fs.copySync(src, dst);
}
}
@@ -279,7 +278,7 @@ function copyTemplateFiles (templateDir, projectDir, isSubDir) {
// if template is a www dir
if (path.basename(templateDir) === 'www') {
copyPath = path.resolve(templateDir);
- shell.cp('-R', copyPath, projectDir);
+ fs.copySync(copyPath, path.resolve(projectDir, 'www'));
} else {
var templateFiles = fs.readdirSync(templateDir);
// Remove directories, and files that are unwanted
@@ -290,10 +289,10 @@ function copyTemplateFiles (templateDir, projectDir, isSubDir) {
});
}
// Copy each template file after filter
- for (var i = 0; i < templateFiles.length; i++) {
- copyPath = path.resolve(templateDir, templateFiles[i]);
- shell.cp('-R', copyPath, projectDir);
- }
+ templateFiles.forEach(f => {
+ copyPath = path.resolve(templateDir, f);
+ fs.copySync(copyPath, path.resolve(projectDir, f));
+ });
}
}
@@ -325,9 +324,7 @@ function linkFromTemplate (templateDir, projectDir) {
var linkSrc, linkDst, linkFolders, copySrc, copyDst;
function rmlinkSync (src, dst, type) {
if (src && dst) {
- if (fs.existsSync(dst)) {
- shell.rm('-rf', dst);
- }
+ fs.removeSync(dst);
if (fs.existsSync(src)) {
fs.symlinkSync(src, dst, type);
}
@@ -355,7 +352,7 @@ function linkFromTemplate (templateDir, projectDir) {
// if template/www/config.xml then copy to project/config.xml
copyDst = path.join(projectDir, 'config.xml');
if (!fs.existsSync(copyDst) && fs.existsSync(copySrc)) {
- shell.cp(copySrc, projectDir);
+ fs.copySync(copySrc, copyDst);
}
}
diff --git a/package.json b/package.json
index 3cacb07..6893db8 100644
--- a/package.json
+++ b/package.json
@@ -28,11 +28,11 @@
"cordova-app-hello-world": "^3.11.0",
"cordova-common": "^2.2.0",
"cordova-fetch": "^1.3.0",
+ "fs-extra": "^6.0.1",
"import-fresh": "^2.0.0",
"is-url": "^1.2.4",
"isobject": "^3.0.1",
"q": "^1.5.1",
- "shelljs": "^0.8.2",
"valid-identifier": "0.0.1"
},
"devDependencies": {
diff --git a/spec/create.spec.js b/spec/create.spec.js
index 8ab5b41..c4fc241 100644
--- a/spec/create.spec.js
+++ b/spec/create.spec.js
@@ -17,10 +17,10 @@
under the License.
*/
-var fs = require('fs');
+const fs = require('fs-extra');
+
var path = require('path');
-var shell = require('shelljs');
var requireFresh = require('import-fresh');
var create = require('..');
@@ -36,12 +36,11 @@ const project = path.join(tmpDir, appName);
// Setup and teardown test dirs
beforeEach(function () {
- shell.rm('-rf', project);
- shell.mkdir('-p', tmpDir);
+ fs.emptyDirSync(tmpDir);
});
-afterEach(function () {
+afterAll(function () {
process.chdir(path.join(__dirname, '..')); // Needed to rm the dir on Windows.
- shell.rm('-rf', tmpDir);
+ fs.removeSync(tmpDir);
});
describe('cordova create checks for valid-identifier', function () {
@@ -272,7 +271,7 @@ describe('create end-to-end', function () {
});
it('should successfully run with existing, empty destination', function () {
- shell.mkdir('-p', project);
+ fs.ensureDirSync(project);
return create(project, appId, appName, {}, events)
.then(checkProjectCreatedWithDefaultTemplate);
});
diff --git a/spec/helpers.js b/spec/helpers.js
index b15486c..bc48248 100644
--- a/spec/helpers.js
+++ b/spec/helpers.js
@@ -17,12 +17,11 @@
under the License.
*/
-const fs = require('fs');
+const fs = require('fs-extra');
const os = require('os');
const path = require('path');
const rewire = require('rewire');
-const shell = require('shelljs');
// Disable regular console output during tests
const CordovaLogger = require('cordova-common').CordovaLogger;
@@ -44,7 +43,7 @@ function createWithMockFetch (dir, id, name, cfg, events) {
const fetchSpy = jasmine.createSpy('fetchSpy')
.and.callFake(() => Promise.resolve(mockFetchDest));
- shell.cp('-R', templateDir, mockFetchDest);
+ fs.copySync(templateDir, mockFetchDest);
return createWith({fetch: fetchSpy})(dir, id, name, cfg, events)
.then(() => fetchSpy);
}
--
To stop receiving notification emails like this one, please contact
raphinesse@apache.org.
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org