Skip to content
This repository was archived by the owner on Jan 6, 2023. It is now read-only.

App Lib Refactor #108

Open
wants to merge 1 commit into
base: v2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
208 changes: 0 additions & 208 deletions .eslintrc.json

This file was deleted.

20 changes: 12 additions & 8 deletions lib/config-xml.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ var Q = require('q');
var xml2js = require('xml2js');
var log = require('./logging').logger;

var ConfigXml = module.exports;

ConfigXml.loadToJson = function(appDirectory) {
function loadToJson(appDirectory) {
var d = Q.defer();

if (!appDirectory) {
Expand All @@ -26,17 +24,17 @@ ConfigXml.loadToJson = function(appDirectory) {
});

return d.promise;
};
}

ConfigXml.loadToStream = function(appDirectory) {
function loadToStream(appDirectory) {
if (!appDirectory) {
appDirectory = process.cwd();
}

return fs.createReadStream(path.join(appDirectory, 'config.xml'));
};
}

ConfigXml.setConfigXml = function setConfigXml(appDirectory, options) {
function setConfigXml(appDirectory, options) {
var madeChange = false;

if (!appDirectory) {
Expand All @@ -56,7 +54,7 @@ ConfigXml.setConfigXml = function setConfigXml(appDirectory, options) {
}
}

return ConfigXml.loadToJson(appDirectory, options)
return loadToJson(appDirectory, options)
.then(function(configJson) {
if (!configJson.widget) {
throw new Error('\nYour config.xml file is invalid. You must have a <widget> element.');
Expand Down Expand Up @@ -90,4 +88,10 @@ ConfigXml.setConfigXml = function setConfigXml(appDirectory, options) {
fs.writeFileSync(configXmlPath, configString);
}
});
}

module.exports = {
loadToJson: loadToJson,
loadToStream: loadToStream,
setConfigXml: setConfigXml
};
50 changes: 31 additions & 19 deletions lib/cordova.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ var State = require('./state');
var Q = require('q');
var log = require('./logging').logger;

var Cordova = module.exports;

Cordova.Lib = require('cordova-lib');
var Lib = require('cordova-lib');

Cordova.runCordova = function runCordova(cmdName) {
function runCordova(cmdName) {
var deferred = Q.defer();
var self = this;
var cmdArgs = (process.argv.length > 3 ? process.argv.slice(3) : []);
Expand Down Expand Up @@ -138,9 +137,9 @@ Cordova.runCordova = function runCordova(cmdName) {
}

return deferred.promise;
};
}

Cordova.setupLiveReload = function() {
function setupLiveReload() {
var d = Q.defer();

log.info('Setup Live Reload');
Expand Down Expand Up @@ -183,10 +182,10 @@ Cordova.setupLiveReload = function() {
});

return d.promise;
};
}


Cordova.addPlatform = function addPlatform(projectRoot, platform, savePlatform) {
function addPlatform(projectRoot, platform, savePlatform) {
log.debug('Cordova.addPlatform: ', projectRoot, platform, savePlatform);

// var opts = {
Expand Down Expand Up @@ -216,9 +215,9 @@ Cordova.addPlatform = function addPlatform(projectRoot, platform, savePlatform)
return State.savePlatform(projectRoot, platform);
}
});
};
}

Cordova.removePlatform = function removePlatform(projectRoot, platform, savePlatform) {
function removePlatform(projectRoot, platform, savePlatform) {
var options = {};
var originalPwd = process.env.PWD;
process.env.PWD = projectRoot;
Expand All @@ -230,9 +229,9 @@ Cordova.removePlatform = function removePlatform(projectRoot, platform, savePlat
return State.removePlatform(projectRoot, platform);
}
});
};
}

Cordova.runPlatform = function runPlatform(projectRoot, platform) {
function runPlatform(projectRoot, platform) {
var options = {
platforms: [],
options: [],
Expand All @@ -253,10 +252,10 @@ Cordova.runPlatform = function runPlatform(projectRoot, platform) {
.catch(function(error) {
throw error;
});
};
}


Cordova.addPlugin = function addPlugin(projectRoot, pluginId, pluginVariables, savePlugin) {
function addPlugin(projectRoot, pluginId, pluginVariables, savePlugin) {
log.debug('Cordova.addPlugin: projectRoot', projectRoot, 'pluginId', pluginId,
'pluginVariables', pluginVariables, 'savePlugin', savePlugin);
var originalPwd = process.env.PWD;
Expand All @@ -276,9 +275,9 @@ Cordova.addPlugin = function addPlugin(projectRoot, pluginId, pluginVariables, s
log.error('Error occurred while adding plugin: ', error);
throw error;
});
};
}

Cordova.removePlugin = function removePlugin(projectRoot, pluginId) {
function removePlugin(projectRoot, pluginId) {
var originalPwd = process.env.PWD;
process.env.PWD = projectRoot;

Expand All @@ -289,9 +288,9 @@ Cordova.removePlugin = function removePlugin(projectRoot, pluginId) {
.catch(function(error) {
throw error;
});
};
}

Cordova.buildPlatform = function buildPlatform(projectRoot, platform) {
function buildPlatform(projectRoot, platform) {
var options = {
platforms: [],
options: [],
Expand All @@ -312,9 +311,9 @@ Cordova.buildPlatform = function buildPlatform(projectRoot, platform) {
.catch(function(error) {
throw error;
});
};
}

Cordova.preparePlatform = function preparePlatform(projectRoot, platform) {
function preparePlatform(projectRoot, platform) {
var options = {
platforms: [],
options: [],
Expand All @@ -335,4 +334,17 @@ Cordova.preparePlatform = function preparePlatform(projectRoot, platform) {
.catch(function(error) {
throw error;
});
}

module.exports = {
Lib: Lib,
runCordova: runCordova,
setupLiveReload: setupLiveReload,
addPlatform: addPlatform,
removePlatform: removePlatform,
runPlatform: runPlatform,
addPlugin: addPlugin,
removePlugin: removePlugin,
buildPlatform: buildPlatform,
preparePlatform: preparePlatform
};
Loading