Skip to content
Permalink
Browse files
Lint (almost) all JS files (#191)
* Lint (almost) all commited JS files

* Fix all new ESLint violations
  • Loading branch information
raphinesse committed Apr 3, 2019
1 parent bca23bc commit a3d735b7d36cc1d653ffe30f01d5330d643192e3
Showing 14 changed files with 151 additions and 164 deletions.
@@ -1 +1,2 @@
pkg/**
pkg/**
tasks/vendor
@@ -16,20 +16,20 @@
* specific language governing permissions and limitations
* under the License.
*/
module.exports = function(grunt) {
module.exports = function (grunt) {

grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
compile: {
"android": {},
"ios": {},
"osx": {},
"test": {},
"windows": { useWindowsLineEndings: true },
"browser": {},
"electron": {}
'android': {},
'ios': {},
'osx': {},
'test': {},
'windows': { useWindowsLineEndings: true },
'browser': {},
'electron': {}
},
clean: ['pkg'],
clean: ['pkg']
});

// external tasks
@@ -15,7 +15,7 @@
"url": "https://issues.apache.org/jira/browse/CB"
},
"scripts": {
"eslint": "eslint src test pkg",
"eslint": "eslint .",
"pretest": "grunt compile:test",
"test": "npm run eslint && karma start",
"build": "grunt compile"
@@ -21,48 +21,48 @@ var fs = require('fs');
var path = require('path');
var pkgJson = require('../package.json');

module.exports = function(grunt) {
grunt.registerMultiTask('compile', 'Packages cordova.js', function() {
module.exports = function (grunt) {
grunt.registerMultiTask('compile', 'Packages cordova.js', function () {
var done = this.async();
var platformName = this.target;
var useWindowsLineEndings = this.data.useWindowsLineEndings;
//grabs --platformVersion flag

// grabs --platformVersion flag
var flags = grunt.option.flags();
var platformVersion;
var platformPath = undefined;
flags.forEach(function(flag) {
//see if --platformVersion was passed in
var platformPath;
flags.forEach(function (flag) {
// see if --platformVersion was passed in
if (flag.indexOf('platformVersion') > -1) {
var equalIndex = flag.indexOf('=');
let equalIndex = flag.indexOf('=');
platformVersion = flag.slice(equalIndex + 1);
}
//see if flags for platforms were passed in
//followed by custom paths

// see if flags for platforms were passed in
// followed by custom paths
if (flag.indexOf(platformName) > -1) {
var equalIndex = flag.indexOf('=');
let equalIndex = flag.indexOf('=');
platformPath = flag.slice(equalIndex + 1);
}
});
//Use platformPath from package.json, no custom platform path
if(platformPath === undefined) {
platformPath = pkgJson['cordova-platforms']['cordova-'+platformName];
// Use platformPath from package.json, no custom platform path
if (platformPath === undefined) {
platformPath = pkgJson['cordova-platforms']['cordova-' + platformName];
}
//Get absolute path to platform
if(platformPath) {
// Get absolute path to platform
if (platformPath) {
platformPath = path.resolve(platformPath);
}
if(!platformVersion) {
if (!platformVersion) {
var platformPkgJson;

if(platformPath && fs.existsSync(platformPath)) {
platformPkgJson = require(platformPath +'/package.json');
if (platformPath && fs.existsSync(platformPath)) {
platformPkgJson = require(platformPath + '/package.json');
platformVersion = platformPkgJson.version;
} else {
platformVersion="N/A";
platformVersion = 'N/A';
}
}
generate(platformName, useWindowsLineEndings, platformVersion, platformPath, done);
});
}
};
@@ -16,41 +16,40 @@
* specific language governing permissions and limitations
* under the License.
*/
var fs = require('fs');
var path = require('path');
var fs = require('fs');
var path = require('path');
var collectFiles = require('./collect-files');
var copyProps = require('./copy-props');
var writeModule = require('./write-module');
var writeScript = require('./write-script');
var licensePath = path.join(__dirname, '..', 'templates', 'LICENSE-for-js-file.txt');
var pkgJson = require('../../package.json');
var copyProps = require('./copy-props');
var writeModule = require('./write-module');
var writeScript = require('./write-script');
var licensePath = path.join(__dirname, '..', 'templates', 'LICENSE-for-js-file.txt');
var pkgJson = require('../../package.json');

module.exports = function bundle(platform, debug, commitId, platformVersion, platformPath) {
module.exports = function bundle (platform, debug, commitId, platformVersion, platformPath) {
var modules = collectFiles(path.join('src', 'common'));
var scripts = collectFiles(path.join('src', 'scripts'));
var platformDep;
modules[''] = path.join('src', 'cordova.js');
//check to see if platform has cordova-js-src directory
if(fs.existsSync(platformPath) && fs.existsSync(path.join(platformPath, 'cordova-js-src'))) {

// check to see if platform has cordova-js-src directory
if (fs.existsSync(platformPath) && fs.existsSync(path.join(platformPath, 'cordova-js-src'))) {
copyProps(modules, collectFiles(path.join(platformPath, 'cordova-js-src')));
} else {
// for platforms that don't have a release with cordova-js-src yet
// or if platform === test
if(platform === 'test') {
if (platform === 'test') {
copyProps(modules, collectFiles(path.join('src', 'legacy-exec', platform)));
} else {
console.log('Your version of ' + platform + ' does not contain cordova-js-src. Update to a newer version of ' + platform + '.');
console.log('Your version of ' + platform + ' does not contain cordova-js-src. Update to a newer version of ' + platform + '.');
throw 'Stopped process';
}
}
//test doesn't support custom paths
// test doesn't support custom paths
if (platform === 'test') {
var androidPath = path.resolve(pkgJson['cordova-platforms']['cordova-android']);
var iosPath = path.resolve(pkgJson['cordova-platforms']['cordova-ios']);
var testFilesPath = path.resolve(androidPath, 'cordova-js-src', 'android');
// Add android platform-specific modules that have tests to the test bundle.
if(fs.existsSync(androidPath)) {
if (fs.existsSync(androidPath)) {
modules['android/exec'] = path.resolve(androidPath, 'cordova-js-src', 'exec.js');
} else {
// testFilesPath = path.resolve('src', 'legacy-exec', 'android', 'android');
@@ -60,26 +59,26 @@ module.exports = function bundle(platform, debug, commitId, platformVersion, pla
}
copyProps(modules, collectFiles(testFilesPath, 'android'));

//Add iOS platform-specific modules that have tests for the test bundle.
if(fs.existsSync(iosPath)) {
// Add iOS platform-specific modules that have tests for the test bundle.
if (fs.existsSync(iosPath)) {
modules['ios/exec'] = path.join(iosPath, 'cordova-js-src', 'exec.js');
} else {
//modules['ios/exec'] = path.join('src', 'legacy-exec', 'ios', 'exec.js');
// modules['ios/exec'] = path.join('src', 'legacy-exec', 'ios', 'exec.js');
console.log('Couldn\'t add iOS test files.');
throw 'Stopped process';
}
}

var output = [];

output.push("// Platform: " + platform);
output.push("// " + commitId);
output.push('// Platform: ' + platform);
output.push('// ' + commitId);

// write header
output.push('/*', fs.readFileSync(licensePath, 'utf8'), '*/');
output.push(';(function() {');

output.push("var PLATFORM_VERSION_BUILD_LABEL = '" + platformVersion + "';");
output.push("var PLATFORM_VERSION_BUILD_LABEL = '" + platformVersion + "';");

// write initial scripts
if (!scripts['require']) {
@@ -92,7 +91,7 @@ module.exports = function bundle(platform, debug, commitId, platformVersion, pla
var moduleIds = Object.keys(modules);
moduleIds.sort();

for (var i=0; i<moduleIds.length; i++) {
for (var i = 0; i < moduleIds.length; i++) {
var moduleId = moduleIds[i];

writeModule(output, modules[moduleId], moduleId, debug);
@@ -117,4 +116,3 @@ module.exports = function bundle(platform, debug, commitId, platformVersion, pla

return output.join('\n');
};

@@ -9,49 +9,45 @@
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to
* Unless required by applicable law or agreed to
* software distributed under the License is distr
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
* KIND, either express or implied. See the Licen
* specific language governing permissions and lim
* under the License.
*/
var fs = require('fs');
var path = require('path');
var copyProps = require('./copy-props');
var fs = require('fs');
var path = require('path');
var copyProps = require('./copy-props');
var getModuleId = require('./get-module-id');

function collectFiles (dir, id) {
if (!id) id = '';

function collectFiles(dir, id) {
if (!id) id = ''
var result = {};
var entries = fs.readdirSync(dir);

var result = {}
var entries = fs.readdirSync(dir)
entries = entries.filter(function (entry) {
if (entry.match(/\.js$/)) { return true; }

entries = entries.filter(function(entry) {
if (entry.match(/\.js$/))
return true

var stat = fs.statSync(path.join(dir, entry))
var stat = fs.statSync(path.join(dir, entry));

if (stat.isDirectory())
return true
})
if (stat.isDirectory()) { return true; }
});

entries.forEach(function(entry) {
entries.forEach(function (entry) {
var moduleId = (id ? id + '/' : '') + entry;
var fileName = path.join(dir, entry)
var stat = fs.statSync(fileName)
var fileName = path.join(dir, entry);

var stat = fs.statSync(fileName);
if (stat.isDirectory()) {
copyProps(result, collectFiles(fileName, moduleId))
}
else {
moduleId = getModuleId(moduleId)
result[moduleId] = fileName
copyProps(result, collectFiles(fileName, moduleId));
} else {
moduleId = getModuleId(moduleId);
result[moduleId] = fileName;
}
})
return copyProps({}, result)
});
return copyProps({}, result);
}

module.exports = collectFiles;
@@ -17,28 +17,27 @@
* under the License.
*/
var childProcess = require('child_process');
var fs = require('fs');
var path = require('path');
var fs = require('fs');
var path = require('path');


module.exports = function computeCommitId(callback, cachedGitVersion) {
module.exports = function computeCommitId (callback, cachedGitVersion) {

if (cachedGitVersion) {
callback(cachedGitVersion);
return;
}

var cordovaJSDir = path.join(__dirname, '../../');
//make sure .git directory exists in cordova.js repo

// make sure .git directory exists in cordova.js repo
if (fs.existsSync(path.join(__dirname, '../../.git'))) {
var gitPath = 'git';
var args = 'rev-list HEAD --max-count=1';
childProcess.exec(gitPath + ' ' + args, {cwd:cordovaJSDir}, function(err, stdout, stderr) {
var isWindows = process.platform.slice(0, 3) == 'win';
childProcess.exec(gitPath + ' ' + args, {cwd: cordovaJSDir}, function (err, stdout, stderr) {
var isWindows = process.platform.slice(0, 3) === 'win';
if (err && isWindows) {
gitPath = '"' + path.join(process.env['ProgramFiles'], 'Git', 'bin', 'git.exe') + '"';
childProcess.exec(gitPath + ' ' + args, function(err, stdout, stderr) {
childProcess.exec(gitPath + ' ' + args, function (err, stdout, stderr) {
if (err) {
console.warn('Error during git describe: ' + err);
done('???');
@@ -54,14 +53,14 @@ module.exports = function computeCommitId(callback, cachedGitVersion) {
}
});
} else {
//console.log('no git');
//Can't compute commit ID
// console.log('no git');
// Can't compute commit ID
done('???');
}
}

function done(stdout) {
function done (stdout) {
var version = stdout.trim();
cachedGitVersion = version;
callback(version);
};
}
}
};
@@ -9,20 +9,20 @@
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to
* Unless required by applicable law or agreed to
* software distributed under the License is distr
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
* KIND, either express or implied. See the Licen
* specific language governing permissions and lim
* under the License.
*/
// FIXME should just use underscore or lodash for this
module.exports = function copyProps(target, source) {
module.exports = function copyProps (target, source) {

for (var key in source) {
if (!source.hasOwnProperty(key)) continue
target[key] = source[key]
if (!source.hasOwnProperty(key)) continue;
target[key] = source[key];
}
return target
}

return target;
};
@@ -9,14 +9,14 @@
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to
* Unless required by applicable law or agreed to
* software distributed under the License is distr
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
* KIND, either express or implied. See the Licen
* specific language governing permissions and lim
* under the License.
*/

module.exports = function getModuleId(filename) {
return filename.match(/(.*)\.js$/)[1]
}
module.exports = function getModuleId (filename) {
return filename.match(/(.*)\.js$/)[1];
};

0 comments on commit a3d735b

Please sign in to comment.