cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agri...@apache.org
Subject [05/11] android commit: [CB-3542] Delete custom replaceInFile with shelljs.sed().
Date Sat, 14 Sep 2013 03:08:25 GMT
[CB-3542] Delete custom replaceInFile with shelljs.sed().


Project: http://git-wip-us.apache.org/repos/asf/cordova-android/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-android/commit/70cc711e
Tree: http://git-wip-us.apache.org/repos/asf/cordova-android/tree/70cc711e
Diff: http://git-wip-us.apache.org/repos/asf/cordova-android/diff/70cc711e

Branch: refs/heads/master
Commit: 70cc711ec191f7acce8c8ebabb607e40cab45405
Parents: 485f2ee
Author: Andrew Grieve <agrieve@chromium.org>
Authored: Fri Sep 13 16:30:26 2013 -0400
Committer: Andrew Grieve <agrieve@chromium.org>
Committed: Fri Sep 13 22:07:38 2013 -0400

----------------------------------------------------------------------
 bin/lib/create.js | 78 ++++++++++++++++++--------------------------------
 1 file changed, 28 insertions(+), 50 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-android/blob/70cc711e/bin/lib/create.js
----------------------------------------------------------------------
diff --git a/bin/lib/create.js b/bin/lib/create.js
index 44b9b0f..c419c73 100755
--- a/bin/lib/create.js
+++ b/bin/lib/create.js
@@ -25,6 +25,28 @@ var shell = require('shelljs'),
     ROOT    = path.join(__dirname, '..', '..');
 
 
+/*
+ * HELPER FUNCTIONS
+ */
+
+function exec(command) {
+    var result;
+    try {
+        result = shell.exec(command, {silent:false, async:false});
+    } catch(e) {
+        console.error('Command error on execuation : ' + command);
+        console.error(e);
+        process.exit(2);
+    }
+    if(result && result.code > 0) {
+        console.error('Command failed to execute : ' + command);
+        console.error(result.output);
+        process.exit(2);
+    } else {
+        return result;
+    }
+}
+
 /**
  * $ create [options]
  *
@@ -120,16 +142,16 @@ module.exports.run = function(project_path, package_name, project_name,
project_
     // interpolate the activity name and package
     shell.mkdir('-p', activity_dir);
     shell.cp('-f', path.join(project_template_dir, 'Activity.java'), activity_path);
-    replaceInFile(activity_path, /__ACTIVITY__/, safe_activity_name);
-    replaceInFile(activity_path, /__ID__/, package_name);
+    shell.sed('-i', /__ACTIVITY__/, safe_activity_name, activity_path);
+    shell.sed('-i', /__ID__/, package_name, activity_path);
 
     // interpolate the app name into strings.xml
-    replaceInFile(strings_path, />Cordova</, '>' + project_name + '<');
+    shell.sed('-i', />Cordova</, '>' + project_name + '<', strings_path);
 
     shell.cp('-f', path.join(project_template_dir, 'AndroidManifest.xml'), manifest_path);
-    replaceInFile(manifest_path, /__ACTIVITY__/, safe_activity_name);
-    replaceInFile(manifest_path, /__PACKAGE__/, package_name);
-    replaceInFile(manifest_path, /__APILEVEL__/, target_api.split('-')[1]);
+    shell.sed('-i', /__ACTIVITY__/, safe_activity_name, manifest_path);
+    shell.sed('-i', /__PACKAGE__/, package_name, manifest_path);
+    shell.sed('-i', /__APILEVEL__/, target_api.split('-')[1], manifest_path);
 
     var cordova_path = path.join(ROOT, 'bin', 'templates', 'cordova');
     // creating cordova folder and copying run/build/log/launch/check_reqs scripts
@@ -193,50 +215,6 @@ module.exports.run = function(project_path, package_name, project_name,
project_
     // copy node related files
     shell.cp(path.join(ROOT, 'bin', 'package.json'), path.join(project_path, 'cordova', 'package.json'));
     shell.cp('-r', path.join(ROOT, 'bin', 'node_modules'), path.join(project_path, 'cordova'));
-
-    /*
-     * HELPER FUNCTIONS
-     */
-
-    function exec(command) {
-        var result;
-        try {
-            result = shell.exec(command, {silent:false, async:false});
-        } catch(e) {
-            console.error('Command error on execuation : ' + command);
-            console.error(e);
-            process.exit(2);
-        }
-        if(result && result.code > 0) {
-            console.error('Command failed to execute : ' + command);
-            console.error(result.output);
-            process.exit(2);
-        } else {
-            return result;
-        }
-    }
-
-    function replaceInFile(filename, regex, replacement) {
-        write(filename, read(filename).replace(regex, replacement));
-    }
-
-    function read(filename) {
-        if(fs.existsSync(filename)) {
-            if(fs.lstatSync(filename).isFile()) {
-                return fs.readFileSync(filename, 'utf-8');
-            } else {
-                console.error('Uanble to read directory : ' + filename);
-                process.exit(1);
-            }
-        } else {
-            console.error('Uanble to read file, not found : ' + filename);
-            process.exit(1);
-        }
-    }
-
-    function write(filename, content) {
-        fs.writeFileSync(filename, content, 'utf-8');
-    }
 }
 
 /**


Mime
View raw message