You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by au...@apache.org on 2017/07/18 16:43:00 UTC
cordova-browser git commit: CB-12895 : set up eslint and remove jshint
Repository: cordova-browser
Updated Branches:
refs/heads/master b7ac532a0 -> 804f37b71
CB-12895 : set up eslint and remove jshint
Project: http://git-wip-us.apache.org/repos/asf/cordova-browser/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-browser/commit/804f37b7
Tree: http://git-wip-us.apache.org/repos/asf/cordova-browser/tree/804f37b7
Diff: http://git-wip-us.apache.org/repos/asf/cordova-browser/diff/804f37b7
Branch: refs/heads/master
Commit: 804f37b7139772a466f56c8d8e366b183d93010d
Parents: b7ac532
Author: Audrey So <au...@apache.org>
Authored: Fri Jun 9 11:32:38 2017 -0700
Committer: Audrey So <au...@apache.org>
Committed: Fri Jul 14 16:06:47 2017 -0700
----------------------------------------------------------------------
.eslintrc.yml | 10 +
bin/lib/check_reqs.js | 4 +-
bin/lib/create.js | 49 ++--
bin/lib/update.js | 27 ++-
bin/template/cordova/Api.js | 327 +++++++++++++--------------
bin/template/cordova/browser_handler.js | 49 ++--
bin/template/cordova/browser_parser.js | 44 ++--
bin/template/cordova/lib/build.js | 32 +--
bin/template/cordova/lib/clean.js | 21 +-
bin/template/cordova/lib/run.js | 58 +++--
bin/template/www/cordova-sw.js | 24 +-
bin/template/www/js/index.js | 8 +-
cordova-lib/cordova.js | 3 -
package.json | 12 +-
spec/.eslintrc.yml | 2 +
spec/create.spec.js | 43 ++--
spec/manifest.spec.js | 19 +-
spec/projectApi.spec.js | 49 ++--
18 files changed, 380 insertions(+), 401 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-browser/blob/804f37b7/.eslintrc.yml
----------------------------------------------------------------------
diff --git a/.eslintrc.yml b/.eslintrc.yml
new file mode 100644
index 0000000..0cccb8c
--- /dev/null
+++ b/.eslintrc.yml
@@ -0,0 +1,10 @@
+root: true
+extends: semistandard
+rules:
+ indent:
+ - error
+ - 4
+ camelcase: off
+ padded-blocks: off
+ operator-linebreak: off
+ no-throw-literal: off
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-browser/blob/804f37b7/bin/lib/check_reqs.js
----------------------------------------------------------------------
diff --git a/bin/lib/check_reqs.js b/bin/lib/check_reqs.js
index 2743683..172aa38 100644
--- a/bin/lib/check_reqs.js
+++ b/bin/lib/check_reqs.js
@@ -19,8 +19,8 @@ specific language governing permissions and limitations
under the License.
*/
-//add methods as we determine what are the requirements
+// add methods as we determine what are the requirements
-module.exports.run = function() {
+module.exports.run = function () {
return Promise.resolve();
};
http://git-wip-us.apache.org/repos/asf/cordova-browser/blob/804f37b7/bin/lib/create.js
----------------------------------------------------------------------
diff --git a/bin/lib/create.js b/bin/lib/create.js
index fa6b5c9..647dc0f 100644
--- a/bin/lib/create.js
+++ b/bin/lib/create.js
@@ -21,16 +21,13 @@
var fs = require('fs');
var shell = require('shelljs');
-var args = process.argv;
var path = require('path');
-var ROOT = path.join(__dirname, '..', '..');
-var ConfigParser = require('cordova-common').ConfigParser;
+var ROOT = path.join(__dirname, '..', '..');
var events = require('cordova-common').events;
var check_reqs = require('./check_reqs');
-
// exported method to create a project, returns a promise that resolves with null
-module.exports.createProject = function(project_path,package_name,project_name){
+module.exports.createProject = function (project_path, package_name, project_name) {
/*
// create the dest and the standard place for our api to live
// platforms/platformName/cordova/Api.js
@@ -40,56 +37,54 @@ module.exports.createProject = function(project_path,package_name,project_name){
events.emit('log', '\tPath: ' + project_path);
events.emit('log', '\tName: ' + project_name);
- var VERSION = fs.readFileSync(path.join(ROOT, 'VERSION'), 'utf-8');
-
// Set default values for path, package and name
- project_path = project_path || "CordovaExample";
+ project_path = project_path || 'CordovaExample';
// Check if project already exists
if (fs.existsSync(project_path)) {
- events.emit('error','Oops, destination already exists! Delete it and try again');
+ events.emit('error', 'Oops, destination already exists! Delete it and try again');
}
// Check that requirements are met and proper targets are installed
if (!check_reqs.run()) {
// TODO: use events.emit
- events.emit('error','Please make sure you meet the software requirements in order to build a browser cordova project');
+ events.emit('error', 'Please make sure you meet the software requirements in order to build a browser cordova project');
}
- //copy template/cordova directory ( recursive )
- shell.cp('-r', path.join(ROOT, 'bin/template/cordova'), project_path);
+ // copy template/cordova directory ( recursive )
+ shell.cp('-r', path.join(ROOT, 'bin/template/cordova'), project_path);
- //copy template/www directory ( recursive )
- shell.cp('-r', path.join(ROOT, 'bin/template/www'), project_path);
+ // copy template/www directory ( recursive )
+ shell.cp('-r', path.join(ROOT, 'bin/template/www'), project_path);
// recreate our node_modules structure in the new project
shell.cp('-r', path.join(ROOT, 'node_modules'),
- path.join(project_path,'cordova'));
+ path.join(project_path, 'cordova'));
- //copy check_reqs file
+ // copy check_reqs file
shell.cp(path.join(ROOT, 'bin/lib/check_reqs.js'),
- path.join(project_path,'cordova/lib'));
+ path.join(project_path, 'cordova/lib'));
- var platform_www = path.join(project_path,'platform_www');
+ var platform_www = path.join(project_path, 'platform_www');
- //copy cordova-js-src directory
- shell.cp('-rf', path.join(ROOT, 'cordova-js-src'),platform_www);
+ // copy cordova-js-src directory
+ shell.cp('-rf', path.join(ROOT, 'cordova-js-src'), platform_www);
- //copy cordova js file to platform_www
- shell.cp(path.join(ROOT, 'cordova-lib', 'cordova.js'),platform_www);
+ // copy cordova js file to platform_www
+ shell.cp(path.join(ROOT, 'cordova-lib', 'cordova.js'), platform_www);
- //copy favicon file to platform_www
- shell.cp(path.join(ROOT, 'bin/template/www/favicon.ico'),platform_www);
+ // copy favicon file to platform_www
+ shell.cp(path.join(ROOT, 'bin/template/www/favicon.ico'), platform_www);
// load manifest to write name/shortname
var manifest = require(path.join(ROOT, 'bin/template/www', 'manifest.json'));
manifest.name = project_name;
manifest.short_name = project_name;
// copy manifest file to platform_www
- fs.writeFileSync(path.join(platform_www,'manifest.json'),
- JSON.stringify(manifest, null, 2), 'utf-8');
+ fs.writeFileSync(path.join(platform_www, 'manifest.json'),
+ JSON.stringify(manifest, null, 2), 'utf-8');
// copy service worker
- shell.cp(path.join(ROOT, 'bin/template/www', 'cordova-sw.js'),platform_www);
+ shell.cp(path.join(ROOT, 'bin/template/www', 'cordova-sw.js'), platform_www);
return Promise.resolve();
};
http://git-wip-us.apache.org/repos/asf/cordova-browser/blob/804f37b7/bin/lib/update.js
----------------------------------------------------------------------
diff --git a/bin/lib/update.js b/bin/lib/update.js
index 47b57d7..62e37e1 100644
--- a/bin/lib/update.js
+++ b/bin/lib/update.js
@@ -17,40 +17,39 @@
under the License.
*/
-var Q = require('q'),
- create = require('./create'),
- fs = require('fs'),
- shell = require('shelljs');
+var Q = require('q');
+var create = require('./create');
+var fs = require('fs');
+var shell = require('shelljs');
module.exports.help = function () {
- console.log("WARNING : Make sure to back up your project before updating!");
- console.log("Usage: update PathToProject ");
- console.log(" PathToProject : The path the project you would like to update.");
- console.log("examples:");
- console.log(" update C:\\Users\\anonymous\\Desktop\\MyProject");
+ console.log('WARNING : Make sure to back up your project before updating!');
+ console.log('Usage: update PathToProject ');
+ console.log(' PathToProject : The path the project you would like to update.');
+ console.log('examples:');
+ console.log(' update C:\\Users\\anonymous\\Desktop\\MyProject');
};
module.exports.run = function (argv) {
var projectPath = argv[2];
if (!fs.existsSync(projectPath)) {
// if specified project path is not valid then reject promise
- Q.reject("Browser platform does not exist here: " + projectPath);
+ Q.reject('Browser platform does not exist here: ' + projectPath);
}
return Q().then(function () {
- console.log("Removing existing browser platform.");
+ console.log('Removing existing browser platform.');
shellfatal(shell.rm, '-rf', projectPath);
create.createProject(projectPath);
});
};
-function shellfatal(shellFunc) {
+function shellfatal (shellFunc) {
var slicedArgs = Array.prototype.slice.call(arguments, 1);
var returnVal = null;
try {
shell.config.fatal = true;
returnVal = shellFunc.apply(shell, slicedArgs);
- }
- finally {
+ } finally {
shell.config.fatal = false;
}
return returnVal;
http://git-wip-us.apache.org/repos/asf/cordova-browser/blob/804f37b7/bin/template/cordova/Api.js
----------------------------------------------------------------------
diff --git a/bin/template/cordova/Api.js b/bin/template/cordova/Api.js
index 9858366..91624dd 100644
--- a/bin/template/cordova/Api.js
+++ b/bin/template/cordova/Api.js
@@ -3,8 +3,6 @@
'cordova platform add PATH' where path is this repo.
*/
-/*jslint node: true */
-
var shell = require('shelljs');
var path = require('path');
var fs = require('fs');
@@ -13,7 +11,6 @@ var cdvcmn = require('cordova-common');
var CordovaLogger = cdvcmn.CordovaLogger;
var ConfigParser = cdvcmn.ConfigParser;
var ActionStack = cdvcmn.ActionStack;
-var PluginInfo = cdvcmn.PluginInfo;
var selfEvents = cdvcmn.events;
var xmlHelpers = cdvcmn.xmlHelpers;
var PlatformJson = cdvcmn.PlatformJson;
@@ -23,7 +20,7 @@ var PluginInfoProvider = cdvcmn.PluginInfoProvider;
var BrowserParser = require('./browser_parser');
var PLATFORM_NAME = 'browser';
-function setupEvents(externalEventEmitter) {
+function setupEvents (externalEventEmitter) {
if (externalEventEmitter) {
// This will make the platform internal events visible outside
selfEvents.forwardEventsTo(externalEventEmitter);
@@ -36,7 +33,7 @@ function setupEvents(externalEventEmitter) {
return selfEvents;
}
-function Api(platform, platformRootDir, events) {
+function Api (platform, platformRootDir, events) {
this.platform = platform || PLATFORM_NAME;
@@ -70,9 +67,9 @@ Api.createPlatform = function (dest, config, options, events) {
var creator = require('../../lib/create');
events = setupEvents(events);
- var name = "HelloCordova";
- var id = "io.cordova.hellocordova";
- if(config) {
+ var name = 'HelloCordova';
+ var id = 'io.cordova.hellocordova';
+ if (config) {
name = config.name();
id = config.packageName();
}
@@ -81,22 +78,20 @@ Api.createPlatform = function (dest, config, options, events) {
try {
// we create the project using our scripts in this platform
result = creator.createProject(dest, id, name, options)
- .then(function () {
- // after platform is created we return Api instance based on new Api.js location
- // Api.js has been copied to the new project
- // This is required to correctly resolve paths in the future api calls
- var PlatformApi = require(path.resolve(dest, 'cordova/Api'));
- return new PlatformApi('browser', dest, events);
- });
- }
- catch(e) {
- events.emit('error','createPlatform is not callable from the browser project API.');
- throw(e);
+ .then(function () {
+ // after platform is created we return Api instance based on new Api.js location
+ // Api.js has been copied to the new project
+ // This is required to correctly resolve paths in the future api calls
+ var PlatformApi = require(path.resolve(dest, 'cordova/Api'));
+ return new PlatformApi('browser', dest, events);
+ });
+ } catch (e) {
+ events.emit('error', 'createPlatform is not callable from the browser project API.');
+ throw (e);
}
return result;
};
-
Api.updatePlatform = function (dest, options, events) {
// console.log("test-platform:Api:updatePlatform");
// todo?: create projectInstance and fulfill promise with it.
@@ -107,19 +102,19 @@ Api.prototype.getPlatformInfo = function () {
// console.log("browser-platform:Api:getPlatformInfo");
// return PlatformInfo object
return {
- "locations":this.locations,
- "root": this.root,
- "name": this.platform,
- "version": { "version" : "1.0.0" }, // um, todo!
- "projectConfig": this.config
+ 'locations': this.locations,
+ 'root': this.root,
+ 'name': this.platform,
+ 'version': { 'version': '1.0.0' }, // um, todo!
+ 'projectConfig': this.config
};
};
-Api.prototype.prepare = function (cordovaProject,options) {
+Api.prototype.prepare = function (cordovaProject, options) {
// First cleanup current config and merge project's one into own
- var defaultConfigPath = path.join(this.locations.platformRootDir,'cordova',
- 'defaults.xml');
+ var defaultConfigPath = path.join(this.locations.platformRootDir, 'cordova',
+ 'defaults.xml');
var ownConfigPath = this.locations.configXml;
var sourceCfg = cordovaProject.projectConfig;
@@ -129,12 +124,10 @@ Api.prototype.prepare = function (cordovaProject,options) {
if (fs.existsSync(defaultConfigPath)) {
this.events.emit('verbose', 'Generating config.xml from defaults for platform "' + this.platform + '"');
shell.cp('-f', defaultConfigPath, ownConfigPath);
- }
- else if (fs.existsSync(ownConfigPath)) {
+ } else if (fs.existsSync(ownConfigPath)) {
this.events.emit('verbose', 'Generating defaults.xml from own config.xml for platform "' + this.platform + '"');
shell.cp('-f', ownConfigPath, defaultConfigPath);
- }
- else {
+ } else {
this.events.emit('verbose', 'case 3"' + this.platform + '"');
shell.cp('-f', sourceCfg.path, ownConfigPath);
}
@@ -142,8 +135,8 @@ Api.prototype.prepare = function (cordovaProject,options) {
// merge our configs
this.config = new ConfigParser(ownConfigPath);
xmlHelpers.mergeXml(cordovaProject.projectConfig.doc.getroot(),
- this.config.doc.getroot(),
- this.platform, true);
+ this.config.doc.getroot(),
+ this.platform, true);
this.config.write();
// Update own www dir with project's www assets and plugins' assets and js-files
@@ -152,38 +145,37 @@ Api.prototype.prepare = function (cordovaProject,options) {
// Copy or Create manifest.json
// todo: move this to a manifest helper module
// output path
- var manifestPath = path.join(this.locations.www,'manifest.json');
- var srcManifestPath =path.join(cordovaProject.locations.www,'manifest.json');
- if(fs.existsSync(srcManifestPath)) {
+ var manifestPath = path.join(this.locations.www, 'manifest.json');
+ var srcManifestPath = path.join(cordovaProject.locations.www, 'manifest.json');
+ if (fs.existsSync(srcManifestPath)) {
// just blindly copy it to our output/www
// todo: validate it? ensure all properties we expect exist?
- this.events.emit('verbose','copying ' + srcManifestPath + ' => ' + manifestPath);
- shell.cp('-f',srcManifestPath,manifestPath);
- }
- else {
+ this.events.emit('verbose', 'copying ' + srcManifestPath + ' => ' + manifestPath);
+ shell.cp('-f', srcManifestPath, manifestPath);
+ } else {
var manifestJson = {
- "background_color": "#FFF",
- "display": "standalone"
+ 'background_color': '#FFF',
+ 'display': 'standalone'
};
- if(this.config){
- if(this.config.name()) {
+ if (this.config) {
+ if (this.config.name()) {
manifestJson.name = this.config.name();
}
- if(this.config.shortName()) {
+ if (this.config.shortName()) {
manifestJson.short_name = this.config.shortName();
}
- if(this.config.packageName()) {
+ if (this.config.packageName()) {
manifestJson.version = this.config.packageName();
}
- if(this.config.description()) {
+ if (this.config.description()) {
manifestJson.description = this.config.description();
}
- if(this.config.author()) {
+ if (this.config.author()) {
manifestJson.author = this.config.author();
}
// icons
- var icons = this.config.getStaticResources('browser','icon');
- var manifestIcons = icons.map(function(icon) {
+ var icons = this.config.getStaticResources('browser', 'icon');
+ var manifestIcons = icons.map(function (icon) {
// given a tag like this :
// <icon src="res/ios/icon.png" width="57" height="57" density="mdpi" />
/* configParser returns icons that look like this :
@@ -200,44 +192,43 @@ Api.prototype.prepare = function (cordovaProject,options) {
"sizes": "128x128"
} ******/
// ?Is it worth looking at file extentions?
- return {"src":icon.src, "type":"image/png",
- "sizes":(icon.width + "x" + icon.height)};
+ return {'src': icon.src,
+ 'type': 'image/png',
+ 'sizes': (icon.width + 'x' + icon.height)};
});
manifestJson.icons = manifestIcons;
// orientation
// <preference name="Orientation" value="landscape" />
var oriPref = this.config.getGlobalPreference('Orientation');
- if(oriPref) {
+ if (oriPref) {
// if it's a supported value, use it
- if(["landscape","portrait"].indexOf(oriPref) > -1) {
+ if (['landscape', 'portrait'].indexOf(oriPref) > -1) {
manifestJson.orientation = oriPref;
- }
- else { // anything else maps to 'any'
+ } else { // anything else maps to 'any'
manifestJson.orientation = 'any';
}
}
// get start_url
- var contentNode = this.config.doc.find('content') || {'attrib':{'src':'index.html'}}; // sensible default
+ var contentNode = this.config.doc.find('content') || {'attrib': {'src': 'index.html'}}; // sensible default
manifestJson.start_url = contentNode.attrib.src;
// now we get some values from start_url page ...
- var startUrlPath = path.join(cordovaProject.locations.www,manifestJson.start_url);
- if(fs.existsSync(startUrlPath)) {
+ var startUrlPath = path.join(cordovaProject.locations.www, manifestJson.start_url);
+ if (fs.existsSync(startUrlPath)) {
var contents = fs.readFileSync(startUrlPath, 'utf-8');
// matches <meta name="theme-color" content="#FF0044">
var themeColorRegex = /<meta(?=[^>]*name="theme-color")\s[^>]*content="([^>]*)"/i;
var result = themeColorRegex.exec(contents);
var themeColor;
- if(result && result.length>=2) {
+ if (result && result.length >= 2) {
themeColor = result[1];
- }
- else { // see if there is a preference in config.xml
+ } else { // see if there is a preference in config.xml
// <preference name="StatusBarBackgroundColor" value="#000000" />
themeColor = this.config.getGlobalPreference('StatusBarBackgroundColor');
}
- if(themeColor) {
+ if (themeColor) {
manifestJson.theme_color = themeColor;
}
}
@@ -253,8 +244,8 @@ Api.prototype.addPlugin = function (pluginInfo, installOptions) {
// console.log(new Error().stack);
if (!pluginInfo) {
- return Promise.reject('The parameter is incorrect. The first parameter ' +
- 'should be valid PluginInfo instance');
+ return Promise.reject(new Error('The parameter is incorrect. The first parameter ' +
+ 'should be valid PluginInfo instance'));
}
installOptions = installOptions || {};
@@ -271,42 +262,42 @@ Api.prototype.addPlugin = function (pluginInfo, installOptions) {
pluginInfo.getFilesAndFrameworks(this.platform)
.concat(pluginInfo.getAssets(this.platform))
.concat(pluginInfo.getJsModules(this.platform))
- .forEach(function(item) {
- actions.push(actions.createAction(
- self._getInstaller(item.itemType),
- [item, pluginInfo.dir, pluginInfo.id, installOptions, projectFile],
- self._getUninstaller(item.itemType),
- [item, pluginInfo.dir, pluginInfo.id, installOptions, projectFile]));
- });
+ .forEach(function (item) {
+ actions.push(actions.createAction(
+ self._getInstaller(item.itemType),
+ [item, pluginInfo.dir, pluginInfo.id, installOptions, projectFile],
+ self._getUninstaller(item.itemType),
+ [item, pluginInfo.dir, pluginInfo.id, installOptions, projectFile]));
+ });
// run through the action stack
return actions.process(this.platform, this.root)
- .then(function () {
- if (projectFile) {
- projectFile.write();
- }
+ .then(function () {
+ if (projectFile) {
+ projectFile.write();
+ }
- // Add PACKAGE_NAME variable into vars
- if (!installOptions.variables.PACKAGE_NAME) {
- installOptions.variables.PACKAGE_NAME = self._handler.package_name(self.root);
- }
+ // Add PACKAGE_NAME variable into vars
+ if (!installOptions.variables.PACKAGE_NAME) {
+ installOptions.variables.PACKAGE_NAME = self._handler.package_name(self.root);
+ }
- self._munger
- // Ignore passed `is_top_level` option since platform itself doesn't know
- // anything about managing dependencies - it's responsibility of caller.
- .add_plugin_changes(pluginInfo, installOptions.variables, /*is_top_level=*/true, /*should_increment=*/true)
- .save_all();
+ self._munger
+ // Ignore passed `is_top_level` option since platform itself doesn't know
+ // anything about managing dependencies - it's responsibility of caller.
+ .add_plugin_changes(pluginInfo, installOptions.variables, /* is_top_level= */true, /* should_increment= */true)
+ .save_all();
- var targetDir = installOptions.usePlatformWww ?
- self.getPlatformInfo().locations.platformWww :
- self.getPlatformInfo().locations.www;
+ var targetDir = installOptions.usePlatformWww ?
+ self.getPlatformInfo().locations.platformWww :
+ self.getPlatformInfo().locations.www;
- self._addModulesInfo(pluginInfo, targetDir);
- });
+ self._addModulesInfo(pluginInfo, targetDir);
+ });
};
Api.prototype.removePlugin = function (plugin, uninstallOptions) {
- //console.log("NotImplemented :: browser-platform:Api:removePlugin ",plugin, uninstallOptions);
+ // console.log("NotImplemented :: browser-platform:Api:removePlugin ",plugin, uninstallOptions);
uninstallOptions = uninstallOptions || {};
// CB-10108 platformVersion option is required for proper plugin installation
@@ -321,81 +312,76 @@ Api.prototype.removePlugin = function (plugin, uninstallOptions) {
plugin.getFilesAndFrameworks(this.platform)
.concat(plugin.getAssets(this.platform))
.concat(plugin.getJsModules(this.platform))
- .forEach(function(item) {
- actions.push(actions.createAction(
- self._getUninstaller(item.itemType), [item, plugin.dir, plugin.id, uninstallOptions, projectFile],
- self._getInstaller(item.itemType), [item, plugin.dir, plugin.id, uninstallOptions, projectFile]));
- });
+ .forEach(function (item) {
+ actions.push(actions.createAction(
+ self._getUninstaller(item.itemType), [item, plugin.dir, plugin.id, uninstallOptions, projectFile],
+ self._getInstaller(item.itemType), [item, plugin.dir, plugin.id, uninstallOptions, projectFile]));
+ });
// run through the action stack
return actions.process(this.platform, this.root)
- .then(function() {
- if (projectFile) {
- projectFile.write();
- }
+ .then(function () {
+ if (projectFile) {
+ projectFile.write();
+ }
- self._munger
- // Ignore passed `is_top_level` option since platform itself doesn't know
- // anything about managing dependencies - it's responsibility of caller.
- .remove_plugin_changes(plugin, /*is_top_level=*/true)
- .save_all();
+ self._munger
+ // Ignore passed `is_top_level` option since platform itself doesn't know
+ // anything about managing dependencies - it's responsibility of caller.
+ .remove_plugin_changes(plugin, /* is_top_level= */true)
+ .save_all();
- var targetDir = uninstallOptions.usePlatformWww ?
- self.getPlatformInfo().locations.platformWww :
- self.getPlatformInfo().locations.www;
+ var targetDir = uninstallOptions.usePlatformWww ?
+ self.getPlatformInfo().locations.platformWww :
+ self.getPlatformInfo().locations.www;
- self._removeModulesInfo(plugin, targetDir);
- // Remove stale plugin directory
- // TODO: this should be done by plugin files uninstaller
- shell.rm('-rf', path.resolve(self.root, 'Plugins', plugin.id));
- });
+ self._removeModulesInfo(plugin, targetDir);
+ // Remove stale plugin directory
+ // TODO: this should be done by plugin files uninstaller
+ shell.rm('-rf', path.resolve(self.root, 'Plugins', plugin.id));
+ });
};
-Api.prototype._getInstaller = function(type) {
+Api.prototype._getInstaller = function (type) {
var self = this;
return function (item, plugin_dir, plugin_id, options, project) {
var installer = self._handler[type];
- if(!installer) {
- console.log("unrecognized type " + type);
- return;
- }
- else {
+ if (!installer) {
+ console.log('unrecognized type ' + type);
+
+ } else {
var wwwDest = options.usePlatformWww ?
- self.getPlatformInfo().locations.platformWww :
- self._handler.www_dir(self.root);
+ self.getPlatformInfo().locations.platformWww :
+ self._handler.www_dir(self.root);
- if(type === 'asset') {
+ if (type === 'asset') {
installer.install(item, plugin_dir, wwwDest);
- }
- else if(type === 'js-module') {
+ } else if (type === 'js-module') {
installer.install(item, plugin_dir, plugin_id, wwwDest);
- }
- else {
+ } else {
installer.install(item, plugin_dir, self.root, plugin_id, options, project);
}
}
};
};
-Api.prototype._getUninstaller = function(type) {
+Api.prototype._getUninstaller = function (type) {
var self = this;
return function (item, plugin_dir, plugin_id, options, project) {
var installer = self._handler[type];
- if(!installer) {
- console.log("browser plugin uninstall: unrecognized type, skipping : " + type);
- return;
- }
- else {
+ if (!installer) {
+ console.log('browser plugin uninstall: unrecognized type, skipping : ' + type);
+
+ } else {
var wwwDest = options.usePlatformWww ?
self.getPlatformInfo().locations.platformWww :
self._handler.www_dir(self.root);
- if(['asset','js-module'].indexOf(type) > -1) {
+ if (['asset', 'js-module'].indexOf(type) > -1) {
return installer.uninstall(item, wwwDest, plugin_id);
- }
- else {
+ } else {
return installer.uninstall(item, self.root, plugin_id, options, project);
}
@@ -412,7 +398,7 @@ Api.prototype._getUninstaller = function(type) {
* @param {String} targetDir The directory, where updated cordova_plugins.js
* should be written to.
*/
-Api.prototype._addModulesInfo = function(plugin, targetDir) {
+Api.prototype._addModulesInfo = function (plugin, targetDir) {
var installedModules = this._platformJson.root.modules || [];
var installedPaths = installedModules.map(function (installedModule) {
@@ -420,27 +406,27 @@ Api.prototype._addModulesInfo = function(plugin, targetDir) {
});
var modulesToInstall = plugin.getJsModules(this.platform)
- .filter(function (moduleToInstall) {
- return installedPaths.indexOf(moduleToInstall.file) === -1;
- }).map(function (moduleToInstall) {
- var moduleName = plugin.id + '.' + ( moduleToInstall.name || moduleToInstall.src.match(/([^\/]+)\.js/)[1] );
- var obj = {
- file: ['plugins', plugin.id, moduleToInstall.src].join('/'),
- id: moduleName,
- pluginId: plugin.id
- };
- if (moduleToInstall.clobbers.length > 0) {
- obj.clobbers = moduleToInstall.clobbers.map(function(o) { return o.target; });
- }
- if (moduleToInstall.merges.length > 0) {
- obj.merges = moduleToInstall.merges.map(function(o) { return o.target; });
- }
- if (moduleToInstall.runs) {
- obj.runs = true;
- }
+ .filter(function (moduleToInstall) {
+ return installedPaths.indexOf(moduleToInstall.file) === -1;
+ }).map(function (moduleToInstall) {
+ var moduleName = plugin.id + '.' + (moduleToInstall.name || moduleToInstall.src.match(/([^\/]+)\.js/)[1]);
+ var obj = {
+ file: ['plugins', plugin.id, moduleToInstall.src].join('/'), /* eslint no-useless-escape : 0 */
+ id: moduleName,
+ pluginId: plugin.id
+ };
+ if (moduleToInstall.clobbers.length > 0) {
+ obj.clobbers = moduleToInstall.clobbers.map(function (o) { return o.target; });
+ }
+ if (moduleToInstall.merges.length > 0) {
+ obj.merges = moduleToInstall.merges.map(function (o) { return o.target; });
+ }
+ if (moduleToInstall.runs) {
+ obj.runs = true;
+ }
- return obj;
- });
+ return obj;
+ });
this._platformJson.root.modules = installedModules.concat(modulesToInstall);
if (!this._platformJson.root.plugin_metadata) {
@@ -473,7 +459,6 @@ Api.prototype._writePluginModules = function (targetDir) {
fs.writeFileSync(path.join(targetDir, 'cordova_plugins.js'), final_contents, 'utf-8');
};
-
/**
* Removes the specified modules from list of installed modules and updates
* platform_json and cordova_plugins.js on disk.
@@ -483,17 +468,17 @@ Api.prototype._writePluginModules = function (targetDir) {
* @param {String} targetDir The directory, where updated cordova_plugins.js
* should be written to.
*/
-Api.prototype._removeModulesInfo = function(plugin, targetDir) {
+Api.prototype._removeModulesInfo = function (plugin, targetDir) {
var installedModules = this._platformJson.root.modules || [];
var modulesToRemove = plugin.getJsModules(this.platform)
- .map(function (jsModule) {
- return ['plugins', plugin.id, jsModule.src].join('/');
- });
+ .map(function (jsModule) {
+ return ['plugins', plugin.id, jsModule.src].join('/');
+ });
var updatedModules = installedModules
- .filter(function (installedModule) {
- return (modulesToRemove.indexOf(installedModule.file) === -1);
- });
+ .filter(function (installedModule) {
+ return (modulesToRemove.indexOf(installedModule.file) === -1);
+ });
this._platformJson.root.modules = updatedModules;
if (this._platformJson.root.plugin_metadata) {
@@ -507,20 +492,20 @@ Api.prototype._removeModulesInfo = function(plugin, targetDir) {
Api.prototype.build = function (buildOptions) {
var self = this;
return require('./lib/check_reqs').run()
- .then(function () {
- return require('./lib/build').run.call(self, buildOptions);
- });
+ .then(function () {
+ return require('./lib/build').run.call(self, buildOptions);
+ });
};
-Api.prototype.run = function(runOptions) {
+Api.prototype.run = function (runOptions) {
return require('./lib/run').run(runOptions);
};
-Api.prototype.clean = function(cleanOptions) {
+Api.prototype.clean = function (cleanOptions) {
return require('./lib/clean').run(cleanOptions);
};
-Api.prototype.requirements = function() {
+Api.prototype.requirements = function () {
return require('./lib/check_reqs').run();
};
http://git-wip-us.apache.org/repos/asf/cordova-browser/blob/804f37b7/bin/template/cordova/browser_handler.js
----------------------------------------------------------------------
diff --git a/bin/template/cordova/browser_handler.js b/bin/template/cordova/browser_handler.js
index 2eecaaf..cd20489 100644
--- a/bin/template/cordova/browser_handler.js
+++ b/bin/template/cordova/browser_handler.js
@@ -17,28 +17,27 @@
under the License.
*/
-
var path = require('path');
var fs = require('fs');
var shell = require('shelljs');
var events = require('cordova-common').events;
module.exports = {
- www_dir: function(project_dir) {
+ www_dir: function (project_dir) {
return path.join(project_dir, 'www');
},
- package_name:function(project_dir) {
+ package_name: function (project_dir) {
// this method should the id from root config.xml => <widget id=xxx
- //return common.package_name(project_dir, this.www_dir(project_dir));
+ // return common.package_name(project_dir, this.www_dir(project_dir));
// console.log('package_name called with ' + project_dir);
- var pkgName = "io.cordova.hellocordova";
+ var pkgName = 'io.cordova.hellocordova';
var widget_id_regex = /(?:<widget\s+id=['"])(\S+)(?:['"])/;
- var configPath = path.join(project_dir,'config.xml');
- if(fs.existsSync(configPath)) {
- var configStr = fs.readFileSync(configPath,'utf8');
+ var configPath = path.join(project_dir, 'config.xml');
+ if (fs.existsSync(configPath)) {
+ var configStr = fs.readFileSync(configPath, 'utf8');
var res = configStr.match(widget_id_regex);
- if(res && res.length > 1) {
+ if (res && res.length > 1) {
pkgName = res[1];
}
}
@@ -50,7 +49,7 @@ module.exports = {
var moduleSource = path.resolve(plugin_dir, jsModule.src);
// Get module name based on existing 'name' attribute or filename
// Must use path.extname/path.basename instead of path.parse due to CB-9981
- var moduleName = plugin_id + '.' + (jsModule.name || path.basename(jsModule.src, path.extname (jsModule.src)));
+ var moduleName = plugin_id + '.' + (jsModule.name || path.basename(jsModule.src, path.extname(jsModule.src)));
// Read in the file, prepend the cordova.define, and write it back out.
var scriptContent = fs.readFileSync(moduleSource, 'utf-8').replace(/^\ufeff/, ''); // Window BOM
@@ -66,50 +65,50 @@ module.exports = {
uninstall: function (jsModule, www_dir, plugin_id) {
var pluginRelativePath = path.join('plugins', plugin_id, jsModule.src);
// common.removeFileAndParents(www_dir, pluginRelativePath);
- console.log("js-module uninstall called : " + pluginRelativePath);
+ console.log('js-module uninstall called : ' + pluginRelativePath);
}
},
- 'source-file':{
- install:function(obj, plugin_dir, project_dir, plugin_id, options) {
+ 'source-file': {
+ install: function (obj, plugin_dir, project_dir, plugin_id, options) {
// var dest = path.join(obj.targetDir, path.basename(obj.src));
// common.copyFile(plugin_dir, obj.src, project_dir, dest);
- console.log("install called");
+ console.log('install called');
},
- uninstall:function(obj, project_dir, plugin_id, options) {
+ uninstall: function (obj, project_dir, plugin_id, options) {
// var dest = path.join(obj.targetDir, path.basename(obj.src));
// common.removeFile(project_dir, dest);
- console.log("uninstall called");
+ console.log('uninstall called');
}
},
'header-file': {
- install:function(obj, plugin_dir, project_dir, plugin_id, options) {
+ install: function (obj, plugin_dir, project_dir, plugin_id, options) {
events.emit('verbose', 'header-fileinstall is not supported for browser');
},
- uninstall:function(obj, project_dir, plugin_id, options) {
+ uninstall: function (obj, project_dir, plugin_id, options) {
events.emit('verbose', 'header-file.uninstall is not supported for browser');
}
},
- 'resource-file':{
- install:function(obj, plugin_dir, project_dir, plugin_id, options) {
+ 'resource-file': {
+ install: function (obj, plugin_dir, project_dir, plugin_id, options) {
events.emit('verbose', 'resource-file.install is not supported for browser');
},
- uninstall:function(obj, project_dir, plugin_id, options) {
+ uninstall: function (obj, project_dir, plugin_id, options) {
events.emit('verbose', 'resource-file.uninstall is not supported for browser');
}
},
'framework': {
- install:function(obj, plugin_dir, project_dir, plugin_id, options) {
+ install: function (obj, plugin_dir, project_dir, plugin_id, options) {
events.emit('verbose', 'framework.install is not supported for browser');
},
- uninstall:function(obj, project_dir, plugin_id, options) {
+ uninstall: function (obj, project_dir, plugin_id, options) {
events.emit('verbose', 'framework.uninstall is not supported for browser');
}
},
'lib-file': {
- install:function(obj, plugin_dir, project_dir, plugin_id, options) {
+ install: function (obj, plugin_dir, project_dir, plugin_id, options) {
events.emit('verbose', 'lib-file.install is not supported for browser');
},
- uninstall:function(obj, project_dir, plugin_id, options) {
+ uninstall: function (obj, project_dir, plugin_id, options) {
events.emit('verbose', 'lib-file.uninstall is not supported for browser');
}
}
http://git-wip-us.apache.org/repos/asf/cordova-browser/blob/804f37b7/bin/template/cordova/browser_parser.js
----------------------------------------------------------------------
diff --git a/bin/template/cordova/browser_parser.js b/bin/template/cordova/browser_parser.js
index 84dc400..a6270c8 100644
--- a/bin/template/cordova/browser_parser.js
+++ b/bin/template/cordova/browser_parser.js
@@ -17,18 +17,16 @@
under the License.
*/
-/* jshint sub:true */
+var fs = require('fs');
+var path = require('path');
+var shell = require('shelljs');
+var CordovaError = require('cordova-common').CordovaError;
-var fs = require('fs'),
- path = require('path'),
- shell = require('shelljs'),
- CordovaError = require('cordova-common').CordovaError;
-
-function dirExists(dir) {
+function dirExists (dir) {
return fs.existsSync(dir) && fs.statSync(dir).isDirectory();
}
-function browser_parser(project) {
+function browser_parser (project) {
if (!dirExists(project) || !dirExists(path.join(project, 'cordova'))) {
throw new CordovaError('The provided path "' + project + '" is not a valid browser project.');
}
@@ -38,30 +36,30 @@ function browser_parser(project) {
module.exports = browser_parser;
// Returns a promise.
-browser_parser.prototype.update_from_config = function() {
+browser_parser.prototype.update_from_config = function () {
return Promise.resolve();
};
-browser_parser.prototype.www_dir = function() {
+browser_parser.prototype.www_dir = function () {
return path.join(this.path, 'www');
};
// Used for creating platform_www in projects created by older versions.
-browser_parser.prototype.cordovajs_path = function(libDir) {
+browser_parser.prototype.cordovajs_path = function (libDir) {
var jsPath = path.join(libDir, 'cordova-lib', 'cordova.js');
return path.resolve(jsPath);
};
-browser_parser.prototype.cordovajs_src_path = function(libDir) {
- //console.log("cordovajs_src_path");
+browser_parser.prototype.cordovajs_src_path = function (libDir) {
+ // console.log("cordovajs_src_path");
var jsPath = path.join(libDir, 'cordova-js-src');
return path.resolve(jsPath);
};
// Replace the www dir with contents of platform_www and app www.
-browser_parser.prototype.update_www = function() {
- var projectRoot = this.path;
- var app_www = path.join(this.path,"../../www");
+browser_parser.prototype.update_www = function () {
+ var projectRoot = this.path; /* eslint no-unused-vars : 0 */
+ var app_www = path.join(this.path, '../../www');
var platform_www = path.join(this.path, 'platform_www');
var my_www = this.www_dir();
@@ -73,12 +71,12 @@ browser_parser.prototype.update_www = function() {
shell.cp('-rf', path.join(platform_www, '*'), my_www);
// Copy over all app www assets ( overwriting stock )
- shell.cp('-rf', path.join(app_www,'*'), my_www);
+ shell.cp('-rf', path.join(app_www, '*'), my_www);
};
-browser_parser.prototype.update_overrides = function() {
+browser_parser.prototype.update_overrides = function () {
// console.log("update_overrides");
- return;
+
// TODO: ?
// var projectRoot = util.isCordova(this.path);
// var mergesPath = path.join(util.appDir(projectRoot), 'merges', 'browser');
@@ -88,17 +86,17 @@ browser_parser.prototype.update_overrides = function() {
// }
};
-browser_parser.prototype.config_xml = function(){
+browser_parser.prototype.config_xml = function () {
return path.join(this.path, 'config.xml');
};
// Returns a promise.
-browser_parser.prototype.update_project = function(cfg) {
- //console.log("update_project ",cfg);
+browser_parser.prototype.update_project = function (cfg) {
+ // console.log("update_project ",cfg);
var defer = this.update_from_config();
var self = this;
var www_dir = self.www_dir();
- defer.then(function(){
+ defer.then(function () {
self.update_overrides();
// Copy munged config.xml to platform www dir
shell.cp('-rf', path.join(www_dir, '..', 'config.xml'), www_dir);
http://git-wip-us.apache.org/repos/asf/cordova-browser/blob/804f37b7/bin/template/cordova/lib/build.js
----------------------------------------------------------------------
diff --git a/bin/template/cordova/lib/build.js b/bin/template/cordova/lib/build.js
index fef90f6..5430925 100644
--- a/bin/template/cordova/lib/build.js
+++ b/bin/template/cordova/lib/build.js
@@ -19,49 +19,49 @@
* under the License.
*/
-var fs = require('fs'),
- path = require('path'),
- shell = require('shelljs'),
- clean = require('./clean'),
- check_reqs = require('./check_reqs');
+var fs = require('fs');
+var path = require('path');
+var shell = require('shelljs');
+var clean = require('./clean');
+var check_reqs = require('./check_reqs');
/**
* run
* Creates a zip file int platform/build folder
*/
-module.exports.run = function(){
+module.exports.run = function () {
var resultP = check_reqs.run();
- resultP.then(function(){
+ resultP.then(function () {
return clean.run();
});
- resultP.then(function() {
- var wwwPath = path.join(__dirname,'../../www');
+ resultP.then(function () {
+ var wwwPath = path.join(__dirname, '../../www');
// generate a generic service worker
var lsdir = shell.find(wwwPath);
var pathLength = wwwPath.length;
- var cleanedFileList = lsdir.filter(function(elem) {
+ var cleanedFileList = lsdir.filter(function (elem) {
// skip directory names, and cordova-js-src
return !fs.statSync(elem).isDirectory() &&
elem.indexOf('cordova-js-src') < 0;
- }).map(function(elem) {
+ }).map(function (elem) {
return elem.substr(pathLength);
});
- var swJSPath = path.join(wwwPath,'cordova-sw.js');
+ var swJSPath = path.join(wwwPath, 'cordova-sw.js');
var swJS = fs.readFileSync(swJSPath, 'utf8');
- swJS = swJS.replace('%CACHE_VERSION%',Date.now());
- swJS = swJS.replace("['CACHE_VALUES']",JSON.stringify(cleanedFileList,null,4));
+ swJS = swJS.replace('%CACHE_VERSION%', Date.now());
+ swJS = swJS.replace("['CACHE_VALUES']", JSON.stringify(cleanedFileList, null, 4));
fs.writeFileSync(swJSPath, swJS, 'utf8');
});
return resultP;
};
-module.exports.help = function() {
+module.exports.help = function () {
console.log('Usage: cordova build browser');
- var wwwPath = path.resolve(path.join(__dirname,'../../www'));
+ var wwwPath = path.resolve(path.join(__dirname, '../../www'));
console.log("Build will create the packaged app in '" + wwwPath + "'.");
};
http://git-wip-us.apache.org/repos/asf/cordova-browser/blob/804f37b7/bin/template/cordova/lib/clean.js
----------------------------------------------------------------------
diff --git a/bin/template/cordova/lib/clean.js b/bin/template/cordova/lib/clean.js
index 13ab316..6ee7675 100644
--- a/bin/template/cordova/lib/clean.js
+++ b/bin/template/cordova/lib/clean.js
@@ -19,13 +19,13 @@
* under the License.
*/
-var fs = require('fs'),
- shell = require('shelljs'),
- path = require('path'),
- check_reqs = require('./check_reqs'),
- platformBuildDir = path.join('platforms', 'browser', 'www');
+var fs = require('fs');
+var shell = require('shelljs');
+var path = require('path');
+var check_reqs = require('./check_reqs');
+var platformBuildDir = path.join('platforms', 'browser', 'www');
-var run = function(){
+var run = function () {
// TODO: everything calls check_reqs ... why?
// Check that requirements are (still) met
@@ -38,15 +38,14 @@ var run = function(){
if (fs.existsSync(platformBuildDir)) {
shell.rm('-r', platformBuildDir);
}
- }
- catch(err) {
- console.log('could not remove '+platformBuildDir+' : '+err.message);
+ } catch (err) {
+ console.log('could not remove ' + platformBuildDir + ' : ' + err.message);
}
};
module.exports.run = run;
// just on the off chance something is still calling cleanProject, we will leave this here for a while
-module.exports.cleanProject = function(){
- console.log("lib/clean will soon only export a `run` command, please update to not call `cleanProject`.");
+module.exports.cleanProject = function () {
+ console.log('lib/clean will soon only export a `run` command, please update to not call `cleanProject`.');
return run();
};
http://git-wip-us.apache.org/repos/asf/cordova-browser/blob/804f37b7/bin/template/cordova/lib/run.js
----------------------------------------------------------------------
diff --git a/bin/template/cordova/lib/run.js b/bin/template/cordova/lib/run.js
index 81e628c..cfce743 100644
--- a/bin/template/cordova/lib/run.js
+++ b/bin/template/cordova/lib/run.js
@@ -19,49 +19,47 @@
* under the License.
*/
-var fs = require('fs'),
- path = require('path'),
- url = require('url'),
- shell = require('shelljs'),
- cordovaServe = require('cordova-serve');
+var fs = require('fs');
+var path = require('path');
+var url = require('url');
+var cordovaServe = require('cordova-serve');
-module.exports.run = function(args) {
+module.exports.run = function (args) {
// defaults
- args.port = args.port || 8000;
- args.target = args.target || "chrome"; // make default the system browser
+ args.port = args.port || 8000;
+ args.target = args.target || 'chrome'; // make default the system browser
- var wwwPath = path.join(__dirname,'../../www');
- var manifestFilePath = path.resolve(path.join(wwwPath,'manifest.json'));
+ var wwwPath = path.join(__dirname, '../../www');
+ var manifestFilePath = path.resolve(path.join(wwwPath, 'manifest.json'));
var startPage;
// get start page from manifest
- if(fs.existsSync(manifestFilePath)) {
+ if (fs.existsSync(manifestFilePath)) {
try {
var manifest = require(manifestFilePath);
startPage = manifest.start_url;
- }
- catch(err) {
- console.log("failed to require manifest ... " + err);
+ } catch (err) {
+ console.log('failed to require manifest ... ' + err);
}
}
var server = cordovaServe();
server.servePlatform('browser', {port: args.port, noServerInfo: true})
- .then(function () {
- if(!startPage) {
- // failing all else, set the default
- startPage = 'index.html';
- }
- var projectUrl = url.resolve('http://localhost:' + server.port + '/', startPage);
- console.log('startPage = ' + startPage);
- console.log('Static file server running @ ' + projectUrl + '\nCTRL + C to shut down');
- return cordovaServe.launchBrowser({"target": args.target, "url": projectUrl});
- })
- .catch(function (error) {
- console.log(error.message || error.toString());
- if (server.server) {
- server.server.close();
- }
- });
+ .then(function () {
+ if (!startPage) {
+ // failing all else, set the default
+ startPage = 'index.html';
+ }
+ var projectUrl = url.resolve('http://localhost:' + server.port + '/', startPage);
+ console.log('startPage = ' + startPage);
+ console.log('Static file server running @ ' + projectUrl + '\nCTRL + C to shut down');
+ return cordovaServe.launchBrowser({'target': args.target, 'url': projectUrl});
+ })
+ .catch(function (error) {
+ console.log(error.message || error.toString());
+ if (server.server) {
+ server.server.close();
+ }
+ });
};
http://git-wip-us.apache.org/repos/asf/cordova-browser/blob/804f37b7/bin/template/www/cordova-sw.js
----------------------------------------------------------------------
diff --git a/bin/template/www/cordova-sw.js b/bin/template/www/cordova-sw.js
index 72a926a..15a96f3 100644
--- a/bin/template/www/cordova-sw.js
+++ b/bin/template/www/cordova-sw.js
@@ -3,25 +3,25 @@
var CACHE_VERSION = '%CACHE_VERSION%';
var CACHE_LIST = ['CACHE_VALUES'];
-this.addEventListener('install', function(event) {
+this.addEventListener('install', function (event) {
// Perform install steps
- console.log("cordova service worker is installing.");
- event.waitUntil(caches.open(CACHE_VERSION)
- .then(function(cache) {
- return cache.addAll(CACHE_LIST);
- }));
+ console.log('cordova service worker is installing.');
+ event.waitUntil(caches.open(CACHE_VERSION) /* eslint no-undef : 0 */
+ .then(function (cache) {
+ return cache.addAll(CACHE_LIST);
+ }));
});
-this.addEventListener('activate', function(event) {
+this.addEventListener('activate', function (event) {
// Perform activate steps
- console.log("cordova service worker is activated.");
+ console.log('cordova service worker is activated.');
});
-this.addEventListener('fetch', function(event) {
- console.log("cordova service worker : fetch : " + event.request.url);
+this.addEventListener('fetch', function (event) {
+ console.log('cordova service worker : fetch : ' + event.request.url);
- event.respondWith(caches.match(event.request).then(function(response) {
+ event.respondWith(caches.match(event.request).then(function (response) { /* eslint no-undef : 0 */
// Cache hit? return response else fetch it
- return response || fetch(event.request);
+ return response || fetch(event.request); /* eslint no-undef : 0 */
}));
});
http://git-wip-us.apache.org/repos/asf/cordova-browser/blob/804f37b7/bin/template/www/js/index.js
----------------------------------------------------------------------
diff --git a/bin/template/www/js/index.js b/bin/template/www/js/index.js
index 31d9064..1750a54 100644
--- a/bin/template/www/js/index.js
+++ b/bin/template/www/js/index.js
@@ -18,25 +18,25 @@
*/
var app = {
// Application Constructor
- initialize: function() {
+ initialize: function () {
this.bindEvents();
},
// Bind Event Listeners
//
// Bind any events that are required on startup. Common events are:
// 'load', 'deviceready', 'offline', and 'online'.
- bindEvents: function() {
+ bindEvents: function () {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
// deviceready Event Handler
//
// The scope of 'this' is the event. In order to call the 'receivedEvent'
// function, we must explicity call 'app.receivedEvent(...);'
- onDeviceReady: function() {
+ onDeviceReady: function () {
app.receivedEvent('deviceready');
},
// Update DOM on a Received Event
- receivedEvent: function(id) {
+ receivedEvent: function (id) {
var parentElement = document.getElementById(id);
var listeningElement = parentElement.querySelector('.listening');
var receivedElement = parentElement.querySelector('.received');
http://git-wip-us.apache.org/repos/asf/cordova-browser/blob/804f37b7/cordova-lib/cordova.js
----------------------------------------------------------------------
diff --git a/cordova-lib/cordova.js b/cordova-lib/cordova.js
index 5b68b46..07c91f6 100644
--- a/cordova-lib/cordova.js
+++ b/cordova-lib/cordova.js
@@ -22,9 +22,6 @@
var PLATFORM_VERSION_BUILD_LABEL = '4.2.0-dev';
// file: src/scripts/require.js
-/*jshint -W079 */
-/*jshint -W020 */
-
var require,
define;
http://git-wip-us.apache.org/repos/asf/cordova-browser/blob/804f37b7/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index 56e0b16..359154a 100644
--- a/package.json
+++ b/package.json
@@ -17,9 +17,9 @@
"apache"
],
"scripts": {
- "jshint": "jshint bin && jshint spec",
+ "eslint": "eslint bin && eslint spec",
"jasmine": "jasmine",
- "test": "npm run jshint && npm run jasmine"
+ "test": "npm run eslint && npm run jasmine"
},
"dependencies": {
"cordova-common": "^2.0.1",
@@ -28,8 +28,14 @@
"shelljs": "^0.5.3"
},
"devDependencies": {
+ "eslint": "^4.0.0",
+ "eslint-config-semistandard": "^11.0.0",
+ "eslint-config-standard": "^10.2.1",
+ "eslint-plugin-import": "^2.3.0",
+ "eslint-plugin-node": "^5.0.0",
+ "eslint-plugin-promise": "^3.5.0",
+ "eslint-plugin-standard": "^3.0.1",
"jasmine": "^2.5.3",
- "jshint": "^2.6.0",
"tmp": "^0.0.26"
},
"bundledDependencies": [
http://git-wip-us.apache.org/repos/asf/cordova-browser/blob/804f37b7/spec/.eslintrc.yml
----------------------------------------------------------------------
diff --git a/spec/.eslintrc.yml b/spec/.eslintrc.yml
new file mode 100644
index 0000000..6afba65
--- /dev/null
+++ b/spec/.eslintrc.yml
@@ -0,0 +1,2 @@
+env:
+ jasmine: true
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-browser/blob/804f37b7/spec/create.spec.js
----------------------------------------------------------------------
diff --git a/spec/create.spec.js b/spec/create.spec.js
index b920417..ed92a11 100644
--- a/spec/create.spec.js
+++ b/spec/create.spec.js
@@ -24,9 +24,9 @@ var util = require('util');
var cordova_bin = path.join(__dirname, '../bin');// is this the same on all platforms?
var tmpDir = path.join(__dirname, '../temp');
-var createScriptPath = path.join(cordova_bin,'create');
+var createScriptPath = path.join(cordova_bin, 'create');
-function createAndBuild(projectname, projectid) {
+function createAndBuild (projectname, projectid) {
var return_code = 0;
var command;
@@ -37,27 +37,25 @@ function createAndBuild(projectname, projectid) {
// create the project
command = util.format('"%s" "%s/%s" "%s" "%s"', createScriptPath, tmpDir, projectname, projectid, projectname);
- //shell.echo(command);
+ // shell.echo(command);
return_code = shell.exec(command).code;
expect(return_code).toBe(0);
+ var tempCordovaScriptsPath = path.join(tmpDir, projectname, 'cordova');
- var tempCordovaScriptsPath = path.join(tmpDir,projectname,"cordova");
-
- console.log("tempCordovaScriptsPath = " + tempCordovaScriptsPath);
+ console.log('tempCordovaScriptsPath = ' + tempCordovaScriptsPath);
// created project has scripts in the cordova folder
// build, clean, log, run, version
- expect(fs.existsSync(path.join(tempCordovaScriptsPath,'build'))).toBe(true);
- expect(fs.existsSync(path.join(tempCordovaScriptsPath,'clean'))).toBe(true);
- expect(fs.existsSync(path.join(tempCordovaScriptsPath,'log'))).toBe(true);
- expect(fs.existsSync(path.join(tempCordovaScriptsPath,'run'))).toBe(true);
- expect(fs.existsSync(path.join(tempCordovaScriptsPath,'version'))).toBe(true);
-
+ expect(fs.existsSync(path.join(tempCordovaScriptsPath, 'build'))).toBe(true);
+ expect(fs.existsSync(path.join(tempCordovaScriptsPath, 'clean'))).toBe(true);
+ expect(fs.existsSync(path.join(tempCordovaScriptsPath, 'log'))).toBe(true);
+ expect(fs.existsSync(path.join(tempCordovaScriptsPath, 'run'))).toBe(true);
+ expect(fs.existsSync(path.join(tempCordovaScriptsPath, 'version'))).toBe(true);
// // build the project
command = util.format('"%s/cordova/build"', path.join(tmpDir, projectname));
- //shell.echo(command);
+ // shell.echo(command);
return_code = shell.exec(command, { silent: true }).code;
expect(return_code).toBe(0);
@@ -65,50 +63,48 @@ function createAndBuild(projectname, projectid) {
shell.rm('-rf', tmpDir);
}
+describe('create', function () {
-describe('create', function() {
-
- it('has a create script in bin/cordova',function(){
+ it('has a create script in bin/cordova', function () {
expect(fs.existsSync(createScriptPath)).toBe(true);
});
-
- it('create project with ascii name, no spaces', function() {
+ it('create project with ascii name, no spaces', function () {
var projectname = 'testcreate';
var projectid = 'com.test.app1';
createAndBuild(projectname, projectid);
});
- it('create project with ascii name, and spaces', function() {
+ it('create project with ascii name, and spaces', function () {
var projectname = 'test create';
var projectid = 'com.test.app2';
createAndBuild(projectname, projectid);
});
- it('create project with unicode name, no spaces', function() {
+ it('create project with unicode name, no spaces', function () {
var projectname = '応応応応用用用用';
var projectid = 'com.test.app3';
createAndBuild(projectname, projectid);
});
- it('create project with unicode name, and spaces', function() {
+ it('create project with unicode name, and spaces', function () {
var projectname = '応応応応 用用用用';
var projectid = 'com.test.app4';
createAndBuild(projectname, projectid);
});
- it('create project with ascii+unicode name, no spaces', function() {
+ it('create project with ascii+unicode name, no spaces', function () {
var projectname = '応応応応hello用用用用';
var projectid = 'com.test.app5';
createAndBuild(projectname, projectid);
});
- it('create project with ascii+unicode name, and spaces', function() {
+ it('create project with ascii+unicode name, and spaces', function () {
var projectname = '応応応応 hello 用用用用';
var projectid = 'com.test.app6';
@@ -116,4 +112,3 @@ describe('create', function() {
});
});
-
http://git-wip-us.apache.org/repos/asf/cordova-browser/blob/804f37b7/spec/manifest.spec.js
----------------------------------------------------------------------
diff --git a/spec/manifest.spec.js b/spec/manifest.spec.js
index e00db85..8bc144f 100644
--- a/spec/manifest.spec.js
+++ b/spec/manifest.spec.js
@@ -24,9 +24,9 @@ var util = require('util');
var cordova_bin = path.join(__dirname, '../bin');// is this the same on all platforms?
var tmpDir = path.join(__dirname, '../temp');
-var createScriptPath = path.join(cordova_bin,'create');
+var createScriptPath = path.join(cordova_bin, 'create');
-function createAndBuild(projectname, projectid) {
+function createAndBuild (projectname, projectid) {
var return_code = 0;
var command;
@@ -41,17 +41,17 @@ function createAndBuild(projectname, projectid) {
return_code = shell.exec(command).code;
expect(return_code).toBe(0);
- var platWwwPath = path.join(tmpDir,projectname,"platform_www");
+ var platWwwPath = path.join(tmpDir, projectname, 'platform_www');
- var manifestPath = path.join(platWwwPath,'manifest.json');
+ var manifestPath = path.join(platWwwPath, 'manifest.json');
expect(fs.existsSync(manifestPath)).toBe(true);
var manifestObj = require(manifestPath);
expect(manifestObj.name).toBe(projectname);
// start_url
- expect(manifestObj.start_url).toBe("index.html");
+ expect(manifestObj.start_url).toBe('index.html');
// display
- expect(manifestObj.display).toBe("standalone");
+ expect(manifestObj.display).toBe('standalone');
// description
expect(manifestObj.description).toBeDefined();
// background_color
@@ -74,13 +74,12 @@ function createAndBuild(projectname, projectid) {
shell.rm('-rf', tmpDir);
}
+describe('create', function () {
-describe('create', function() {
-
- it('create project with manifest.json', function() {
+ it('create project with manifest.json', function () {
var projectname = 'testcreate';
var projectid = 'com.test.app1';
createAndBuild(projectname, projectid);
});
-});
\ No newline at end of file
+});
http://git-wip-us.apache.org/repos/asf/cordova-browser/blob/804f37b7/spec/projectApi.spec.js
----------------------------------------------------------------------
diff --git a/spec/projectApi.spec.js b/spec/projectApi.spec.js
index cbe56fc..072a1d8 100644
--- a/spec/projectApi.spec.js
+++ b/spec/projectApi.spec.js
@@ -19,87 +19,86 @@
var Api = require('../bin/template/cordova/Api');
var shell = require('shelljs');
-var fs = require('fs');
var path = require('path');
var tmpDir = path.join(__dirname, './temp');
-describe('can get the Api', function() {
+describe('can get the Api', function () {
- it('should be defined', function() {
+ it('should be defined', function () {
expect(Api).toBeDefined();
});
- it('should export static createPlatform function', function(done) {
+ it('should export static createPlatform function', function (done) {
expect(Api.createPlatform).toBeDefined();
expect(typeof Api.createPlatform).toBe('function');
-// TODO: make this do something real
+ // TODO: make this do something real
var promise = Api.createPlatform(tmpDir);
expect(promise).toBeDefined();
expect(promise.then).toBeDefined();
- promise.then(function(res) {
+ promise.then(function (res) {
console.log('result = ' + res);
shell.rm('-rf', tmpDir);
done();
},
- function(err) {
- console.log("spec-error " + err);
+ function (err) {
+ console.log('spec-error ' + err);
shell.rm('-rf', tmpDir);
done();
});
});
- it('should export static updatePlatform function', function() {
+ it('should export static updatePlatform function', function () {
expect(Api.updatePlatform).toBeDefined();
expect(typeof Api.updatePlatform).toBe('function');
});
});
-describe('project level Api',function() {
+describe('project level Api', function () {
var testApi = new Api();
- it('can be created', function() {
+ it('can be created', function () {
expect(testApi).toBeDefined();
});
- it('has a requirements method', function() {
+ it('has a requirements method', function () {
expect(testApi.requirements).toBeDefined();
expect(typeof testApi.requirements).toBe('function');
});
- it('has a clean method', function() {
+ it('has a clean method', function () {
expect(testApi.clean).toBeDefined();
expect(typeof testApi.clean).toBe('function');
});
- it('has a run method', function() {
+ it('has a run method', function () {
expect(testApi.run).toBeDefined();
expect(typeof testApi.run).toBe('function');
});
- it('has a build method', function() {
+ it('has a build method', function () {
expect(testApi.build).toBeDefined();
expect(typeof testApi.build).toBe('function');
});
- it('has a removePlugin method', function() {
+ it('has a removePlugin method', function () {
expect(testApi.removePlugin).toBeDefined();
expect(typeof testApi.removePlugin).toBe('function');
});
- it('has a addPlugin method', function() {
+ it('has a addPlugin method', function () {
expect(testApi.addPlugin).toBeDefined();
expect(typeof testApi.addPlugin).toBe('function');
});
- it('has a prepare method', function() {
+ it('has a prepare method', function () {
expect(testApi.prepare).toBeDefined();
expect(typeof testApi.prepare).toBe('function');
});
- it('has a getPlatformInfo method', function() {
+ it('has a getPlatformInfo method', function () {
expect(testApi.getPlatformInfo).toBeDefined();
expect(typeof testApi.getPlatformInfo).toBe('function');
});
@@ -108,14 +107,12 @@ describe('project level Api',function() {
// Static methods
// Static method: createPlatform
- // returns promise fulfilled with Api
- // emits error using provided emmitter on error
+// returns promise fulfilled with Api
+// emits error using provided emmitter on error
// Static method: updatePlatform
- // returns a promise fulfilled with an Api
- // emits error using provided emmitter on error
- //
+// returns a promise fulfilled with an Api
+// emits error using provided emmitter on error
// Instance methods
- // requirements, clean, run, build, removePlugin, addPlugin, prepare, getPlatformInfo
-
+// requirements, clean, run, build, removePlugin, addPlugin, prepare, getPlatformInfo
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org