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

Commit 8fab880

Browse files
committedApr 26, 2016
fix(eslint): correct eslint issues in hooks, index, and add task to package.json.
1 parent 1bbde39 commit 8fab880

File tree

8 files changed

+72
-74
lines changed

8 files changed

+72
-74
lines changed
 

‎index.js

+11-15
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
1-
var fs = require('fs'),
2-
IonicAppLib = module.exports,
3-
path = require('path');
1+
var fs = require('fs');
2+
var IonicAppLib = module.exports;
3+
var path = require('path');
44

5-
var capitalize = function capitalize(str) {
6-
return str && str[0].toUpperCase() + str.slice(1);
7-
};
8-
9-
var camelCase = function camelCase(input) {
10-
return input.toLowerCase().replace(/-(.)/g, function(match, group1) {
11-
return group1.toUpperCase();
12-
});
13-
};
5+
function camelCase(input) {
6+
return input.toLowerCase().replace(/-(.)/g, function(match, group1) {
7+
return group1.toUpperCase();
8+
});
9+
}
1410

1511
//
1612
// Setup all modules as lazy-loaded getters.
1713
//
18-
fs.readdirSync(path.join(__dirname, 'lib')).forEach(function (file) {
14+
fs.readdirSync(path.join(__dirname, 'lib')).forEach(function(file) {
1915
file = file.replace('.js', '');
2016
var command;
2117

@@ -25,11 +21,11 @@ fs.readdirSync(path.join(__dirname, 'lib')).forEach(function (file) {
2521
command = file;
2622
}
2723

28-
IonicAppLib.__defineGetter__(command, function () {
24+
IonicAppLib.__defineGetter__(command, function() { // eslint-disable-line no-underscore-dangle
2925
return require('./lib/' + file);
3026
});
3127
});
3228

33-
IonicAppLib.__defineGetter__('semver', function () {
29+
IonicAppLib.__defineGetter__('semver', function() { // eslint-disable-line no-underscore-dangle
3430
return require('semver');
3531
});

‎lib/hooks/after_platform_add/010_install_plugins.js

+5-9
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,21 @@
55
* https://raw.githubusercontent.com/diegonetto/generator-ionic/master/templates/hooks/after_platform_add/install_plugins.js
66
*/
77
var exec = require('child_process').exec;
8-
var path = require('path');
98
var sys = require('sys');
109

1110
var packageJSON = null;
1211

1312
try {
1413
packageJSON = require('../../package.json');
15-
} catch(ex) {
16-
console.log('\nThere was an error fetching your package.json file.')
17-
console.log('\nPlease ensure a valid package.json is in the root of this project\n')
14+
} catch (ex) {
15+
console.log('\nThere was an error fetching your package.json file.');
16+
console.log('\nPlease ensure a valid package.json is in the root of this project\n');
1817
return;
1918
}
2019

21-
var cmd = process.platform === 'win32' ? 'cordova.cmd' : 'cordova';
22-
// var script = path.resolve(__dirname, '../../node_modules/cordova/bin', cmd);
23-
2420
packageJSON.cordovaPlugins = packageJSON.cordovaPlugins || [];
25-
packageJSON.cordovaPlugins.forEach(function (plugin) {
26-
exec('cordova plugin add ' + plugin, function (error, stdout, stderr) {
21+
packageJSON.cordovaPlugins.forEach(function(plugin) {
22+
exec('cordova plugin add ' + plugin, function(error, stdout) {
2723
sys.puts(stdout);
2824
});
2925
});

‎lib/hooks/after_plugin_add/010_register_plugin.js

+20-20
Original file line numberDiff line numberDiff line change
@@ -3,52 +3,52 @@
33
/**
44
* Push plugins to cordovaPlugins array after_plugin_add
55
*/
6-
var fs = require('fs'),
7-
packageJSON = require('../../package.json'),
8-
path = require('path');
6+
var fs = require('fs');
7+
var packageJSON = require('../../package.json');
8+
var path = require('path');
99

1010
packageJSON.cordovaPlugins = packageJSON.cordovaPlugins || [];
11-
process.env.CORDOVA_PLUGINS.split(',').forEach(function (plugin) {
12-
var configString,
13-
idRegEx,
14-
id,
15-
pluginXmlPath,
16-
pluginToAdd;
11+
process.env.CORDOVA_PLUGINS.split(',').forEach(function(plugin) {
12+
var configString;
13+
var idRegEx;
14+
var id;
15+
var pluginXmlPath;
16+
var pluginToAdd;
1717

18-
if(plugin.indexOf('https') != -1 || plugin.indexOf('git') != -1) {
18+
if (plugin.indexOf('https') !== -1 || plugin.indexOf('git') !== -1) {
1919
console.log('Installing plugin from url');
2020
}
2121

22-
if(plugin.indexOf('/') != -1) {
22+
if (plugin.indexOf('/') !== -1) {
2323
try {
2424
pluginXmlPath = path.resolve(plugin, 'plugin.xml');
2525
console.log('got pluginXmlPath:', pluginXmlPath);
2626
if (!fs.existsSync(pluginXmlPath)) {
27-
var errorMessage = ['There was no plugin.xml file found for path: ', pluginXmlPath].join('');
27+
['There was no plugin.xml file found for path: ', pluginXmlPath].join('');
2828
return;
2929
}
3030

31-
configString = fs.readFileSync(pluginXmlPath,{encoding: 'utf8'});
31+
configString = fs.readFileSync(pluginXmlPath, { encoding: 'utf8' });
3232
idRegEx = new RegExp('<plugin[^>]*id="(.*)"', 'i');
33-
id = idRegEx.exec(configString)[1]
34-
pluginToAdd = {id: id, locator: plugin};
35-
} catch(ex) {
33+
id = idRegEx.exec(configString)[1];
34+
pluginToAdd = { id: id, locator: plugin };
35+
} catch (ex) {
3636
console.log('There was an error retrieving the plugin.xml filr from the 010_register_plugin.js hook', ex);
3737
}
3838
} else {
3939
pluginToAdd = plugin;
4040
}
4141

42-
if(typeof pluginToAdd == 'string' && packageJSON.cordovaPlugins.indexOf(pluginToAdd) == -1) {
42+
if (typeof pluginToAdd == 'string' && packageJSON.cordovaPlugins.indexOf(pluginToAdd) === -1) {
4343
packageJSON.cordovaPlugins.push(pluginToAdd);
4444
} else if (typeof pluginToAdd == 'object') {
4545
var pluginExists = false;
4646
packageJSON.cordovaPlugins.forEach(function(checkPlugin) {
47-
if(typeof checkPlugin == 'object' && checkPlugin.id == pluginToAdd.id) {
47+
if (typeof checkPlugin == 'object' && checkPlugin.id === pluginToAdd.id) {
4848
pluginExists = true;
4949
}
50-
})
51-
if(!pluginExists) {
50+
});
51+
if (!pluginExists) {
5252
packageJSON.cordovaPlugins.push(pluginToAdd);
5353
}
5454
}

‎lib/hooks/after_plugin_rm/010_deregister_plugin.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@ var packageJSON = require('../../package.json');
88

99
packageJSON.cordovaPlugins = packageJSON.cordovaPlugins || [];
1010

11-
process.env.CORDOVA_PLUGINS.split(',').forEach(function (plugin) {
11+
process.env.CORDOVA_PLUGINS.split(',').forEach(function(plugin) {
1212
var index = packageJSON.cordovaPlugins.indexOf(plugin);
1313
if (index > -1) {
1414
packageJSON.cordovaPlugins.splice(index, 1);
1515
} else {
16-
//If it didnt find a match, it may be listed as {id,locator}
17-
for(var i = 0, j = packageJSON.cordovaPlugins.length; i < j; i++) {
16+
17+
// If it didnt find a match, it may be listed as {id,locator}
18+
for (var i = 0, j = packageJSON.cordovaPlugins.length; i < j; i += 1) {
1819
var packagePlugin = packageJSON.cordovaPlugins[i];
19-
if(typeof packagePlugin == 'object' && packagePlugin.id == plugin) {
20+
if (typeof packagePlugin == 'object' && packagePlugin.id === plugin) {
2021
packageJSON.cordovaPlugins.splice(index, 1);
2122
break;
2223
}

‎lib/hooks/after_prepare/010_add_platform_class.js

+20-15
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ var path = require('path');
1414
var rootdir = process.argv[2];
1515

1616
function addPlatformBodyTag(indexPath, platform) {
17+
1718
// add the platform class to the body tag
1819
try {
1920
var platformClass = 'platform-' + platform;
@@ -22,21 +23,23 @@ function addPlatformBodyTag(indexPath, platform) {
2223
var html = fs.readFileSync(indexPath, 'utf8');
2324

2425
var bodyTag = findBodyTag(html);
25-
if(!bodyTag) return; // no opening body tag, something's wrong
26+
if (!bodyTag) return; // no opening body tag, something's wrong
2627

27-
if(bodyTag.indexOf(platformClass) > -1) return; // already added
28+
if (bodyTag.indexOf(platformClass) > -1) return; // already added
2829

2930
var newBodyTag = bodyTag;
3031

3132
var classAttr = findClassAttr(bodyTag);
32-
if(classAttr) {
33+
if (classAttr) {
34+
3335
// body tag has existing class attribute, add the classname
34-
var endingQuote = classAttr.substring(classAttr.length-1);
35-
var newClassAttr = classAttr.substring(0, classAttr.length-1);
36+
var endingQuote = classAttr.substring(classAttr.length - 1);
37+
var newClassAttr = classAttr.substring(0, classAttr.length - 1);
3638
newClassAttr += ' ' + platformClass + ' ' + cordovaClass + endingQuote;
3739
newBodyTag = bodyTag.replace(classAttr, newClassAttr);
3840

3941
} else {
42+
4043
// add class attribute to the body tag
4144
newBodyTag = bodyTag.replace('>', ' class="' + platformClass + ' ' + cordovaClass + '">');
4245
}
@@ -46,49 +49,51 @@ function addPlatformBodyTag(indexPath, platform) {
4649
fs.writeFileSync(indexPath, html, 'utf8');
4750

4851
process.stdout.write('add to body class: ' + platformClass + '\n');
49-
} catch(e) {
52+
} catch (e) {
5053
process.stdout.write(e);
5154
}
5255
}
5356

5457
function findBodyTag(html) {
58+
5559
// get the body tag
56-
try{
60+
try {
5761
return html.match(/<body(?=[\s>])(.*?)>/gi)[0];
58-
}catch(e){}
62+
} catch (e) {} // eslint-disable-line no-empty
5963
}
6064

6165
function findClassAttr(bodyTag) {
66+
6267
// get the body tag's class attribute
63-
try{
68+
try {
6469
return bodyTag.match(/ class=["|'](.*?)["|']/gi)[0];
65-
}catch(e){}
70+
} catch (e) {} // eslint-disable-line no-empty
6671
}
6772

6873
if (rootdir) {
6974

7075
// go through each of the platform directories that have been prepared
7176
var platforms = (process.env.CORDOVA_PLATFORMS ? process.env.CORDOVA_PLATFORMS.split(',') : []);
7277

73-
for(var x=0; x<platforms.length; x++) {
78+
for (var x = 0; x < platforms.length; x += 1) {
79+
7480
// open up the index.html file at the www root
7581
try {
7682
var platform = platforms[x].trim().toLowerCase();
7783
var indexPath;
7884

79-
if(platform == 'android') {
85+
if (platform === 'android') {
8086
indexPath = path.join('platforms', platform, 'assets', 'www', 'index.html');
8187
} else {
8288
indexPath = path.join('platforms', platform, 'www', 'index.html');
8389
}
8490

85-
if(fs.existsSync(indexPath)) {
91+
if (fs.existsSync(indexPath)) {
8692
addPlatformBodyTag(indexPath, platform);
8793
}
8894

89-
} catch(e) {
95+
} catch (e) {
9096
process.stdout.write(e);
9197
}
9298
}
93-
9499
}

‎lib/hooks/after_prepare/020_remove_sass_from_platforms.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@
77
var fs = require('fs');
88
var path = require('path');
99

10-
var deleteFolderRecursive = function(removePath) {
11-
if( fs.existsSync(removePath) ) {
12-
fs.readdirSync(removePath).forEach(function(file,index){
10+
function deleteFolderRecursive(removePath) {
11+
if (fs.existsSync(removePath)) {
12+
fs.readdirSync(removePath).forEach(function(file) {
1313
var curPath = path.join(removePath, file);
14-
if(fs.lstatSync(curPath).isDirectory()) { // recurse
14+
if (fs.lstatSync(curPath).isDirectory()) { // recurse
1515
deleteFolderRecursive(curPath);
1616
} else { // delete file
1717
fs.unlinkSync(curPath);
1818
}
1919
});
2020
fs.rmdirSync(removePath);
2121
}
22-
};
22+
}
2323

2424
var iosPlatformsDir = path.resolve(__dirname, '../../platforms/ios/www/lib/ionic/scss');
2525
var androidPlatformsDir = path.resolve(__dirname, '../../platforms/android/assets/www/lib/ionic/scss');

‎lib/hooks/before_platform_add/init_directories.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ var platformsDir = path.resolve(__dirname, '../../platforms');
1111
var pluginsDir = path.resolve(__dirname, '../../plugins');
1212

1313
try {
14-
fs.mkdirSync(platformsDir, function (err) {
14+
fs.mkdirSync(platformsDir, function(err) {
1515
if (err) { console.error(err); }
1616
});
17-
} catch(ex) {}
17+
} catch (ex) {} // eslint-disable-line no-empty
1818

1919
try {
20-
fs.mkdirSync(pluginsDir, function (err) {
20+
fs.mkdirSync(pluginsDir, function(err) {
2121
if (err) { console.error(err); }
2222
});
23-
} catch(ex) {}
23+
} catch (ex) {} // eslint-disable-line no-empty

‎package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,15 @@
7070
},
7171
"devDependencies": {
7272
"coveralls": "^2.11.9",
73+
"eslint": "^2.8.0",
7374
"istanbul": "^0.4.3",
7475
"jasmine-node": "1.14.5",
75-
"jshint": "^2.9.1",
7676
"rewire": "2.5.1"
7777
},
7878
"scripts": {
7979
"test": "npm run jasmine",
80-
"jshint": "jshint lib spec --exclude lib/assets",
8180
"jasmine": "jasmine-node --captureExceptions spec/",
81+
"lint": "eslint .",
8282
"coveralls": "istanbul cover node_modules/jasmine-node/bin/jasmine-node --captureExceptions spec/ && cat coverage/lcov.info | node_modules/coveralls/bin/coveralls.js && rm -rf coverage"
8383
}
8484
}

0 commit comments

Comments
 (0)
This repository has been archived.