Skip to content
Permalink
Browse files
Drop support for reading from .cordova/config.json (#18)
Resolves §2 from apache/cordova-discuss#89
  • Loading branch information
raphinesse committed Jun 17, 2018
1 parent 3d21f05 commit e9532316e55e9e8c8bdf0e9c68076142f9dca938
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 53 deletions.
@@ -24,6 +24,7 @@ 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');

@@ -75,28 +76,9 @@ module.exports = function (dir, optionalId, optionalName, cfg, extEvents) {
throw new CordovaError('Directory not specified. See `cordova help`.');
}

// read projects .cordova/config.json file for project settings
var configFile = dotCordovaConfig(dir);

// if data exists in the configFile, lets combine it with cfg
// cfg values take priority over config file
if (configFile) {
var finalConfig = {};
for (var key1 in configFile) {
finalConfig[key1] = configFile[key1];
}

for (var key2 in cfg) {
finalConfig[key2] = cfg[key2];
}

cfg = finalConfig;
}

if (!cfg) {
throw new CordovaError('Must provide a project configuration.');
} else if (typeof cfg === 'string') {
cfg = JSON.parse(cfg);
cfg = cfg || {};
if (!isObject(cfg)) {
throw new CordovaError('If given, cfg must be an object');
}

if (optionalId) cfg.id = optionalId;
@@ -105,20 +87,7 @@ module.exports = function (dir, optionalId, optionalName, cfg, extEvents) {
// Make absolute.
dir = path.resolve(dir);

// dir must be either empty except for .cordova config file or not exist at all..
var sanedircontents = function (d) {
var contents = fs.readdirSync(d);
if (contents.length === 0) {
return true;
} else if (contents.length === 1) {
if (contents[0] === '.cordova') {
return true;
}
}
return false;
};

if (fs.existsSync(dir) && !sanedircontents(dir)) {
if (fs.existsSync(dir) && fs.readdirSync(dir).length > 0) {
throw new CordovaError('Path already exists and is not empty: ' + dir);
}

@@ -346,23 +315,6 @@ function projectConfig (projectDir) {
return false;
}

/**
* Retrieve and read the .cordova/config file of a cordova project
*
* @param {String} project directory
* @return {JSON data} config file's contents
*/
function dotCordovaConfig (project_root) {
var configPath = path.join(project_root, '.cordova', 'config.json');
var data;
if (!fs.existsSync(configPath)) {
data = '{}';
} else {
data = fs.readFileSync(configPath, 'utf-8');
}
return JSON.parse(data);
}

/**
* Removes existing files and symlinks them if they exist.
* Symlinks folders: www, merges, hooks
@@ -30,6 +30,7 @@
"cordova-fetch": "^1.3.0",
"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"

0 comments on commit e953231

Please sign in to comment.