You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by bh...@apache.org on 2014/04/22 16:03:55 UTC

webworks commit: CB-6440 Move config logic to its own module

Repository: cordova-blackberry
Updated Branches:
  refs/heads/master c686aa4e5 -> b456aa156


CB-6440 Move config logic to its own module


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

Branch: refs/heads/master
Commit: b456aa156e7c135e361b2c000535347bc3ccfdac
Parents: c686aa4
Author: Bryan Higgins <bh...@blackberry.com>
Authored: Tue Apr 22 10:02:36 2014 -0400
Committer: Bryan Higgins <bh...@blackberry.com>
Committed: Tue Apr 22 10:03:48 2014 -0400

----------------------------------------------------------------------
 blackberry10/bin/lib/config.js | 50 +++++++++++++++++++++++++++++++++++++
 blackberry10/bin/lib/create.js |  1 +
 blackberry10/bin/lib/target.js |  8 +++---
 3 files changed, 54 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/b456aa15/blackberry10/bin/lib/config.js
----------------------------------------------------------------------
diff --git a/blackberry10/bin/lib/config.js b/blackberry10/bin/lib/config.js
new file mode 100644
index 0000000..c21a09f
--- /dev/null
+++ b/blackberry10/bin/lib/config.js
@@ -0,0 +1,50 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+var fs = require('fs'),
+    path = require('path'),
+    PROPERTY_FILE_NAME = 'blackberry10.json',
+    CORDOVA_DIR = '.cordova',
+    DEFAULT_PROPERTY_FILE = {
+        targets: {
+        }
+    },
+    getCordovaDir = function () {
+        var homePath = process.env[(process.platform === 'win32') ? 'USERPROFILE' : 'HOME'],
+            cordovaPath = path.join(homePath, CORDOVA_DIR);
+        if (!fs.existsSync(cordovaPath)) {
+            fs.mkdirSync(cordovaPath);
+        }
+        return cordovaPath;
+    };
+
+module.exports = {
+    getProperties: function () {
+        var props, 
+            propertiesPath = path.join(getCordovaDir(), PROPERTY_FILE_NAME);
+        if (!fs.existsSync(propertiesPath)) {
+            this.writeProperties(DEFAULT_PROPERTY_FILE);
+        }
+        props = require(propertiesPath);
+        if (!props.targets) {
+            props.targets = {};
+        }
+        return props;
+    },
+    writeProperties: function (data) {
+        var contents = JSON.stringify(data, null, 4) + "\n",
+            propertiesPath = path.join(getCordovaDir(), PROPERTY_FILE_NAME);
+        fs.writeFileSync(propertiesPath, contents, 'utf-8');
+    }
+};

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/b456aa15/blackberry10/bin/lib/create.js
----------------------------------------------------------------------
diff --git a/blackberry10/bin/lib/create.js b/blackberry10/bin/lib/create.js
index f870f8d..7765082 100644
--- a/blackberry10/bin/lib/create.js
+++ b/blackberry10/bin/lib/create.js
@@ -124,6 +124,7 @@ function copyFilesToProject() {
     shell.cp(path.join(BIN_DIR, "target"), path.join(project_path, "cordova"));
     shell.cp(path.join(BIN_DIR, "target.bat"), path.join(project_path, "cordova"));
     shell.cp(path.join(BIN_DIR, "lib", "target.js"), path.join(project_path, "cordova", "lib"));
+    shell.cp(path.join(BIN_DIR, "lib", "config.js"), path.join(project_path, "cordova", "lib"));
 
     // copy repo level init script to project
     shell.cp(path.join(BIN_DIR, "whereis.cmd"), path.join(project_path, "cordova"));

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/b456aa15/blackberry10/bin/lib/target.js
----------------------------------------------------------------------
diff --git a/blackberry10/bin/lib/target.js b/blackberry10/bin/lib/target.js
index e199762..0f12643 100644
--- a/blackberry10/bin/lib/target.js
+++ b/blackberry10/bin/lib/target.js
@@ -1,7 +1,5 @@
 #!/usr/bin/env node
 /*
- *  Copyright 2013 Research In Motion Limited.
- *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
@@ -18,9 +16,9 @@
 var path = require('path'),
     exit = require('exit'),
     fs = require('fs'),
-    utils = require('./utils'),
+    config = require('./config'),
     commander = require('commander'),
-    properties = utils.getProperties(),
+    properties = config.getProperties(),
     ERROR_VALUE = 2,
     NOTIMPLEMENTED_VALUE = 1,
     command,
@@ -148,7 +146,7 @@ try {
         exit();
     }
 
-    utils.writeToPropertiesFile(properties);
+    config.writeProperties(properties);
 } catch (e) {
     console.log(e);
     exit();