Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-23948] Remove wrench in favor of fs-extra #120

Merged
merged 3 commits into from
Mar 3, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion android/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@
<delete dir="${basedir}/plugins/hyperloop/node_modules/findit/example"/>
<delete dir="${basedir}/plugins/hyperloop/node_modules/findit/test"/>
<delete dir="${basedir}/plugins/hyperloop/node_modules/node-appc/test"/>
<delete dir="${basedir}/plugins/hyperloop/node_modules/wrench/tests"/>

<!-- Include hyperloop wrappers into module zip -->
<zip destfile="${dist}/${module.id}-android-${manifest.version}.zip" update="true">
Expand Down
21 changes: 10 additions & 11 deletions android/plugins/hyperloop/hooks/android/hyperloop.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ exports.cliVersion = '>=3.2';
(function () {
var path = require('path'),
findit = require('findit'),
fs = require('fs'),
chalk = require('chalk'),
wrench = require('wrench'),
fs = require('fs-extra'),
appc = require('node-appc'),
DOMParser = require('xmldom').DOMParser,
async = require('async'),
Expand Down Expand Up @@ -86,20 +85,20 @@ exports.cliVersion = '>=3.2';
fs.mkdirSync(buildDir);
}
else if (afs.exists(buildPlatform)) {
wrench.rmdirSyncRecursive(buildPlatform);
fs.removeSync(buildPlatform);
}
if (!afs.exists(resourcesDir)) {
fs.mkdirSync(resourcesDir);
}
// Wipe hyperloop resources each time, we will re-generate
if (afs.exists(hyperloopResources)) {
wrench.rmdirSyncRecursive(hyperloopResources);
fs.removeSync(hyperloopResources);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocks like this can be replaced with emptyDirSync

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

emptyDirSync only empties the directory, it doesn't delete it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah you are right, i didn't check it will only get created if needed. Just ignore this comment.

}

// create a temporary hyperloop directory
hyperloopBuildDir = path.join(buildDir, 'hyperloop', 'android');
if (!afs.exists(hyperloopBuildDir)) {
wrench.mkdirSyncRecursive(hyperloopBuildDir);
fs.mkdirsSync(hyperloopBuildDir);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocks like this can be replaced with ensureDirSync

}

// check to make sure the hyperloop module is actually configured
Expand Down Expand Up @@ -167,7 +166,7 @@ exports.cliVersion = '>=3.2';
fs.unlinkSync(fn);
});

wrench.rmdirSyncRecursive(filesDir);
fs.removeSync(filesDir);
finished();
}
});
Expand Down Expand Up @@ -351,10 +350,10 @@ exports.cliVersion = '>=3.2';
foundJars = [path.join(extractedDir, 'classes.jar')];

if (afs.exists(extractedDir)) {
wrench.rmdirSyncRecursive(extractedDir);
fs.removeSync(extractedDir);
}
// Create destination dir
wrench.mkdirSyncRecursive(extractedDir);
fs.mkdirsSync(extractedDir);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace if block above and mkdirSync with emptyDirSync


async.series([
// Unzip aar file to destination
Expand Down Expand Up @@ -417,7 +416,7 @@ exports.cliVersion = '>=3.2';
}
var dest = path.join(buildLibs, path.relative(jniDir, file));
// make dest dir
wrench.mkdirSyncRecursive(path.dirname(dest));
fs.mkdirsSync(path.dirname(dest));
// copy .so over
afs.copyFileSync(file, dest, {logger: logger});
})
Expand All @@ -438,7 +437,7 @@ exports.cliVersion = '>=3.2';
var keys = Object.keys(references);
// only if we found references, otherwise, skip
if (keys.length) {
wrench.mkdirSyncRecursive(hyperloopResources);
fs.mkdirsSync(hyperloopResources);
afs.copyDirRecursive(filesDir, hyperloopResources, function (err) {
logger.info('Finished ' + HL + ' assembly');
if (err) {
Expand Down Expand Up @@ -551,7 +550,7 @@ exports.cliVersion = '>=3.2';

filesDir = path.join(hyperloopBuildDir, 'js');
if (!afs.exists(filesDir)) {
wrench.mkdirSyncRecursive(filesDir);
fs.mkdirsSync(filesDir);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace if block with ensureDirSync


// drop hyperloop/ from each entry in references to get just the class names
Expand Down
5 changes: 2 additions & 3 deletions android/plugins/hyperloop/hooks/android/metabase/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
* Android hyperloop JS proxy generation.
*/
var metabase = require('./metabase'),
fs = require('fs'),
wrench = require('wrench'),
fs = require('fs-extra'),
path = require('path'),
async = require('async'),
ejs = require('ejs'),
Expand Down Expand Up @@ -170,7 +169,7 @@ function generateFromJSON(dir, metabaseJSON, classes, callback) {
packages = {};

if (fs.existsSync(dir)) {
wrench.rmdirSyncRecursive(dir);
fs.removeSync(dir);
}
fs.mkdirSync(dir);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace this and the if block with emptyDirSync


Expand Down
4 changes: 2 additions & 2 deletions android/plugins/hyperloop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"findit": "^2.0.0",
"node-appc": "^0.2.33",
"underscore": "^1.8.3",
"wrench": "^1.5.8",
"fs-extra": "^2.0.0",
"xmldom": "^0.1.19"
}
}
}
13 changes: 6 additions & 7 deletions iphone/plugin/hyperloop.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@ var coreLib = {
var path = require('path'),
exec = require('child_process').exec,
hm = require('hyperloop-metabase'),
fs = require('fs'),
fs = require('fs-extra'),
crypto = require('crypto'),
chalk = hm.chalk,
async = hm.async,
wrench = hm.wrench,
HL = chalk.magenta.inverse('Hyperloop');

/**
Expand Down Expand Up @@ -178,7 +177,7 @@ HyperloopiOSBuilder.prototype.validate = function validate() {
HyperloopiOSBuilder.prototype.setup = function setup() {
// create a temporary hyperloop directory
if (!fs.existsSync(this.hyperloopBuildDir)) {
wrench.mkdirSyncRecursive(this.hyperloopBuildDir);
fs.mkdirsSync(this.hyperloopBuildDir);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace with ensureDirSync


// update to use the correct libhyperloop based on which JS engine is configured
Expand Down Expand Up @@ -473,7 +472,7 @@ HyperloopiOSBuilder.prototype.generateSourceFiles = function generateSourceFiles
return callback();
}

fs.existsSync(this.hyperloopJSDir) || wrench.mkdirSyncRecursive(this.hyperloopJSDir);
fs.existsSync(this.hyperloopJSDir) || fs.mkdirsSync(this.hyperloopJSDir);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace this with ensureDirSync like you did in line 654


if (this.builder.forceCleanBuild || this.forceMetabase) {
this.logger.trace('Forcing a metabase rebuild');
Expand Down Expand Up @@ -652,7 +651,7 @@ HyperloopiOSBuilder.prototype.copyHyperloopJSFiles = function copyHyperloopJSFil

if (changed) {
logger.debug('Writing ' + chalk.cyan(destFile));
fs.existsSync(destDir) || wrench.mkdirSyncRecursive(destDir);
fs.ensureDirSync(destDir);
fs.writeFileSync(destFile, contents || fs.readFileSync(srcFile).toString());
} else {
logger.trace('No change, skipping ' + chalk.cyan(destFile));
Expand Down Expand Up @@ -1044,7 +1043,7 @@ HyperloopiOSBuilder.prototype.updateXcodeProject = function updateXcodeProject()
this.forceRebuild = true;
}
this.logger.debug(__('Writing %s', dest.cyan));
fs.existsSync(parent) || wrench.mkdirSyncRecursive(parent);
fs.ensureDirSync(parent);
fs.writeFileSync(dest, contents);
} else {
this.logger.trace(__('No change, skipping %s', dest.cyan));
Expand Down Expand Up @@ -1113,7 +1112,7 @@ HyperloopiOSBuilder.prototype.hookRemoveFiles = function hookRemoveFiles(data) {
// remove empty Framework directory that might have been created by cocoapods
var frameworksDir = path.join(this.builder.xcodeAppDir, 'Frameworks');
if (fs.existsSync(frameworksDir) && fs.readdirSync(frameworksDir).length === 0) {
wrench.rmdirSyncRecursive(frameworksDir);
fs.removeSync(frameworksDir);
}
if (this.hasCocoaPods) {
var productsDirectory = path.resolve(this.builder.xcodeAppDir, '..');
Expand Down
2 changes: 1 addition & 1 deletion metabase/ios/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
module.exports = require('./lib');

// map these so that the plugin can use them
['chalk', 'wrench', 'async'].forEach(function (k) {
['chalk', 'async'].forEach(function (k) {
Object.defineProperty(module.exports, k, {
get: function () {
return require(k);
Expand Down
7 changes: 2 additions & 5 deletions metabase/ios/lib/generate/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
* Hyperloop Metabase Generator
* Copyright (c) 2015 by Appcelerator, Inc.
*/
var fs = require('fs'),
var fs = require('fs-extra'),
path = require('path'),
async = require('async'),
wrench = require('wrench'),
genclass = require('./class'),
genmodule = require('./module'),
genstruct = require('./struct'),
Expand Down Expand Up @@ -76,9 +75,7 @@ function generateFromJSON (name, dir, json, state, callback, includes) {

json.classes = json.classes || {};

if (!fs.existsSync(dir)) {
wrench.mkdirSyncRecursive(dir);
}
fs.ensureDirSync(dir);

generateBuiltins(json, function (err) {
if (err) { return callback(err); }
Expand Down
15 changes: 7 additions & 8 deletions metabase/ios/lib/metabase.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
var spawn = require('child_process').spawn,
exec = require('child_process').exec,
path = require('path'),
fs = require('fs'),
fs = require('fs-extra'),
plist = require('plist'),
async = require('async'),
semver = require('semver'),
crypto = require('crypto'),
wrench = require('wrench'),
chalk = require('chalk'),
util = require('./generate/util'),
swiftlilb = require('./swift'),
Expand Down Expand Up @@ -504,10 +503,10 @@ function compileResources (dir, sdk, appDir, wildcard, callback) {
var buf = fs.readFileSync(file);
var out = path.join(appDir, rel);
var d = path.dirname(out);
if (!fs.existsSync(d)) {
wrench.mkdirSyncRecursive(d);
}

fs.ensureDirSync(d);
util.logger.trace('Copying Resource', chalk.cyan(file), 'to', chalk.cyan(out));

return fs.writeFile(out, buf, cb);
}
}
Expand Down Expand Up @@ -668,9 +667,9 @@ function runPodInstallIfRequired(basedir, callback) {
Podfile = path.join(basedir, 'Podfile'),
cacheToken = crypto.createHash('md5').update(fs.readFileSync(Podfile)).digest('hex'),
cacheFile = path.join(basedir, 'build', '.podcache');
if (!fs.existsSync(path.dirname(cacheFile))) {
wrench.mkdirSyncRecursive(path.dirname(cacheFile));
}

fs.ensureDirSync(path.dirname(cacheFile));

if (!fs.existsSync(Pods) || !fs.existsSync(cacheFile) || (fs.existsSync(cacheFile) && fs.readFileSync(cacheFile).toString() !== cacheToken)) {
async.waterfall([
isPodInstalled,
Expand Down
2 changes: 1 addition & 1 deletion metabase/ios/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@
"plist": "^1.1.0",
"semver": "^5.0.3",
"walk-ast": "0.0.2",
"wrench": "^1.5.8"
"fs-extra": "^2.0.0"
}
}
7 changes: 3 additions & 4 deletions metabase/ios/test/generate_test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
var should = require('should'),
helper = require('./helper'),
utillib = require('util'),
fs = require('fs'),
fs = require('fs-extra'),
metabase = require('../lib/metabase'),
generator = require('../lib/generate/index'),
util = require('../lib/generate/util'),
nodePath = require('path'),
wrench = require('wrench'),
buildDir = nodePath.join(__dirname, '..', 'build', 'hyperloop');

function Hyperloop () {
Expand Down Expand Up @@ -74,9 +73,9 @@ describe('generate', function () {
global.HyperloopObject = HyperloopObject;

if (fs.existsSync(buildDir)) {
wrench.rmdirSyncRecursive(buildDir);
fs.removeSync(buildDir);
}
wrench.mkdirSyncRecursive(buildDir);
fs.mkdirsSync(buildDir);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can replace this block with emptyDirSync

});

before(function () {
Expand Down
5 changes: 2 additions & 3 deletions metabase/ios/test/helper.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
var spawn = require('child_process').spawn,
plist = require('plist'),
path = require('path'),
wrench = require('wrench'),
fs = require('fs'),
fs = require('fs-extra'),
tmpdirs = [],
settings;

Expand Down Expand Up @@ -118,7 +117,7 @@ function getFixture (name) {
process.on('exit', function () {
if (tmpdirs) {
tmpdirs.forEach(function (tmp) {
wrench.rmdirSyncRecursive(tmp);
fs.removeSync(tmp);
});
tmpdirs = null;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@
"semver": "^5.1.0",
"temp": "~0.6.0",
"titanium": "git://github.com/appcelerator/titanium.git#master",
"wrench": "~1.5.8"
"fs-extra": "~2.0.0"
}
}
11 changes: 5 additions & 6 deletions tools/ci.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
* Copyright (c) 2015 by Appcelerator, Inc. All Rights Reserved.
*/
var path = require('path'),
fs = require('fs'),
fs = require('fs-extra'),
async = require('async'),
http = require('http'),
request = require('request'),
colors = require('colors'),
wrench = require('wrench'),
temp = require('temp'),
appc = require('node-appc'),
exec = require('child_process').exec,
Expand All @@ -30,7 +29,7 @@ function downloadURL(url, callback) {

var tempName = temp.path({ suffix: '.zip' }),
tempDir = path.dirname(tempName);
fs.existsSync(tempDir) || wrench.mkdirSyncRecursive(tempDir);
fs.existsSync(tempDir) || fs.removeSync(tempDir);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess you accidentally replaced mkdirSyncRecursive with removeSync? Also ensureDirSync is probably a good use here.


var tempStream = fs.createWriteStream(tempName),
req = request({ url: url });
Expand Down Expand Up @@ -414,9 +413,9 @@ function build(branch, callback) {
async.series([
function (next) {
if (fs.existsSync(buildTempDir)) {
wrench.rmdirSyncRecursive(buildTempDir);
fs.removeSync(buildTempDir);
}
wrench.mkdirSyncRecursive(buildTempDir);
fs.mkdirsSync(buildTempDir);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace this block with emptyDirSync

next();
},
// Install latest Titanium SDK
Expand Down Expand Up @@ -510,7 +509,7 @@ function build(branch, callback) {
writeAndroidPluginPackage,
runBuildScript,
function (next) {
wrench.rmdirSyncRecursive(buildTempDir);
fs.removeSync(buildTempDir);
next();
},
// TODO Remove the Titanium SDK we installed to avoid cluttering up HDD?
Expand Down