Return-Path: X-Original-To: apmail-cordova-commits-archive@www.apache.org Delivered-To: apmail-cordova-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 412C811294 for ; Tue, 22 Apr 2014 14:03:58 +0000 (UTC) Received: (qmail 79023 invoked by uid 500); 22 Apr 2014 14:03:57 -0000 Delivered-To: apmail-cordova-commits-archive@cordova.apache.org Received: (qmail 78998 invoked by uid 500); 22 Apr 2014 14:03:57 -0000 Mailing-List: contact commits-help@cordova.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cordova.apache.org Delivered-To: mailing list commits@cordova.apache.org Received: (qmail 78896 invoked by uid 99); 22 Apr 2014 14:03:55 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 22 Apr 2014 14:03:55 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id A9B73839EC6; Tue, 22 Apr 2014 14:03:55 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: bhiggins@apache.org To: commits@cordova.apache.org Message-Id: <2e0b383633c84548b3932453b5570888@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: webworks commit: CB-6440 Move config logic to its own module Date: Tue, 22 Apr 2014 14:03:55 +0000 (UTC) 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 Authored: Tue Apr 22 10:02:36 2014 -0400 Committer: Bryan Higgins 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();