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

Commit 07401d4

Browse files
authored
Merge pull request #52 from southworkscom/cleanupCode
Delete unnecessary comments
2 parents 0c0d333 + 8f06be8 commit 07401d4

File tree

13 files changed

+5
-211
lines changed

13 files changed

+5
-211
lines changed

lib/download.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ function download (inputUri, outputFilePath, callback) {
1313
var uri = url.parse(inputUri);
1414

1515
if (inputUri.indexOf('http://') !== 0 && inputUri.indexOf('https://') !== 0) {
16-
// this is to detect scenarios like localhost:8080 where localhost is
17-
// treated as protocol even if it's not.
1816
if (inputUri.indexOf(uri.protocol + '//') !== 0) {
1917
inputUri = 'http://' + inputUri;
2018
uri = url.parse(inputUri);
@@ -55,33 +53,28 @@ function download (inputUri, outputFilePath, callback) {
5553
var deferred = Q.defer();
5654
protocol.get(options, function (res) {
5755

58-
// If Moved Permanently or Found, redirect to new URL
5956
if ([301, 302].indexOf(res.statusCode) > -1) {
6057
return download(res.headers.location, outputFilePath)
6158
.then(function (result) { deferred.resolve(result); })
6259
.catch(function (err) { deferred.reject(err); });
6360
}
6461

65-
// If not OK or Not Modified, throw error
6662
if ([200, 304].indexOf(res.statusCode) === -1) {
6763
var err = new Error('Error downloading \'' + inputUri + '\'. Response was \'' + res.statusCode + ' - ' + res.statusMessage + '\'.');
6864
err.statusCode = res.statusCode;
6965
err.statusMessage = res.statusMessage;
7066
return deferred.reject(err);
7167
}
7268

73-
// If Not Modified, ignore
7469
if (res.statusCode === 304) {
7570
return deferred.resolve({ 'path': outputFilePath, 'statusCode': res.statusCode, 'statusMessage': res.statusMessage, 'contentType': res.headers['content-type'] });
7671
}
7772

78-
// Else save
7973
res.pipe(fs.createWriteStream(outputFilePath))
8074
.on('close', function () {
8175
var lastAccessed = new Date();
8276
var lastModified = res.headers['last-modified'] ? new Date(res.headers['last-modified']) : lastAccessed;
8377

84-
// update the last modified time of the file to match the response header
8578
fs.utimes(outputFilePath, lastAccessed, lastModified, function (err) {
8679
if (err) {
8780
return deferred.reject(err);

lib/fileTools.js

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@ function copyFolder (source, target, options, callback) {
7777
}
7878

7979
return Q.nfcall(ncp, source, target, options || {}).catch(function (err) {
80-
// flatten errors, otherwise it breaks things downstream
81-
// see https://github.com/AvianFlu/ncp/issues/52
8280
if (Array.isArray(err)) {
8381
var msg = err.reduce(function (previous, current) {
8482
return previous += (previous.length ? '\n' : '') + current.message;
@@ -101,11 +99,9 @@ function replaceFileContent (source, replacementFunc, callback) {
10199
}
102100

103101
function mkdirp (filePath, callback) {
104-
// ensure filePath points to a valid drive
105102
var fullPath = path.resolve(filePath);
106103
var rootPath = path.parse(fullPath).root;
107104

108-
// create directory recursively
109105
return stat(rootPath).then(function () {
110106
return Q.nfcall(_mkdirp, filePath);
111107
})
@@ -154,40 +150,30 @@ function searchFile (dir, fileName, callback) {
154150
});
155151
}
156152

157-
// Copies the 'source' file to 'target' if it's missing after creating the
158-
// required directory structure.
159153
function syncFile (source, target, callback) {
160154

161-
// check target file
162155
return stat(target).then(function (info) {
163-
// verify that target is a file and not a directory
164156
if (info.isDirectory()) {
165157
return Q.reject(new Error('Cannot synchronize file \'' + source + '\'. There is already a directory in the target with the same name.'));
166158
}
167159

168-
// skip target if it already exists
169160
return;
170161
})
171162
.catch(function (err) {
172-
// return failure for anything other than 'not found'
173163
if (err.code !== 'ENOENT') {
174164
return Q.reject(err);
175165
}
176166

177-
// copy source to target
178167
var targetDir = path.dirname(target);
179168
return stat(targetDir).catch(function (err) {
180-
// return failure for anything other than 'not found'
181169
if (err.code !== 'ENOENT') {
182170
return Q.reject(err);
183171
}
184172

185-
// create target directory
186173
return mkdirp(targetDir).then(function () {
187174
log.debug('Created target directory at \'' + targetDir + '\'.');
188175
})
189176
.catch(function (err) {
190-
// ignore error if target was already created by a different "thread"
191177
if (err.code !== 'EEXIST') {
192178
return Q.reject(err);
193179
}
@@ -221,37 +207,30 @@ function syncFiles (source, target, options, callback) {
221207
options = {};
222208
}
223209

224-
// read the contents of the source directory
225210
return Q.nfcall(fs.readdir, source).then(function (files) {
226211

227-
// process each file and folder
228212
var tasks = files.map(function (fileOrDir) {
229213
var sourceFile = path.join(source, fileOrDir);
230214
return stat(sourceFile).then(function (info) {
231215

232-
// if fileOrDir is a directory, synchronize it
233216
if (info.isDirectory()) {
234217
return syncFiles(sourceFile, path.join(target, fileOrDir), options);
235218
}
236219

237-
// check to see if file should be skipped
238220
if (options.filter) {
239221
var check = options.filter(fileOrDir);
240222
if (check === false) {
241223
return;
242224
}
243225
}
244226

245-
// synchronize a single file
246227
var targetFile = path.join(target, fileOrDir);
247228
return syncFile(sourceFile, targetFile);
248229
});
249230
});
250231

251-
// wait for all pending tasks to complete
252232
return Q.all(tasks).then(function (values) {
253233

254-
// build a list of the files that were copied
255234
return values.reduce(function (list, value) {
256235
if (value) {
257236
if (Array.isArray(value)) {
@@ -271,17 +250,13 @@ function syncFiles (source, target, options, callback) {
271250
return Q.reject(err);
272251
}
273252

274-
// specified source is a file not a directory
275253
var sourceFile = path.basename(source);
276254
var targetFile = path.basename(target);
277255

278-
// build target file path assuming target is a directory
279-
// unless target already includes the file name
280256
if (sourceFile !== targetFile) {
281257
target = path.join(target, sourceFile);
282258
}
283259

284-
// synchronize the file
285260
return syncFile(source, target).then(function (file) {
286261
return file ? [file] : [];
287262
});

lib/iconTools.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ function getIcon(iconUrl, iconFilePath, callback) {
1717
return fileTools.mkdirp(iconFolder).then(function () {
1818
return download(iconUrl, iconFilePath).then(function (response) {
1919
if (response.statusCode === 200 && !response.contentType.match(/image/)) {
20-
// If not an image, return an error
2120
return Q.reject(new Error('Downloaded file \'' + iconUrl + '\' does not appear to be an image. The content type of the response was \'' + response.contentType + '\'.'));
2221
}
2322

@@ -29,7 +28,6 @@ function getIcon(iconUrl, iconFilePath, callback) {
2928

3029
function copyDefaultIcon(manifest, platformId, iconSize, source, targetPath, callback) {
3130

32-
// platform already contains an icon with this size - skip
3331
if (manifest.icons && manifest.icons[iconSize]) {
3432
return Q.resolve().nodeify(callback);
3533
}

lib/manifestTools/manifestCreator/scrapers/icojs/src/ico.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,12 @@ var imageData = require('./image-data');
66
var Q = require('q');
77

88
var range = function(n) {
9-
// fill() replaced with for ..
109
var array = new Array(n);
1110
for (var i = 0; i < n; i++) {
1211
array[i] = 0;
1312
}
1413

1514
return array.map(function(x, i) { return i; });
16-
17-
// return new Array(n).fill(0).map(function(_, i) { return i });
1815
};
1916

2017
/**
@@ -159,8 +156,6 @@ var factory = function(config) {
159156
return false;
160157
}
161158
var icoDv = new DataView(buffer);
162-
// idReserved = icoDv.getUint16(0, true)
163-
// idType = icoDv.getUint16(0, true)
164159
return icoDv.getUint16(0, true) === 0 && icoDv.getUint16(2, true) === 1;
165160
},
166161
/**

lib/manifestTools/manifestLoader.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@ function processManifestContents (data, manifestFormat, callback) {
7272
detectedFormat = manifestFormat;
7373
} else if (!detectedFormat) {
7474
detectedFormat = 'w3c';
75-
// var availableFormats = listAvailableManifestFormats().join(', ');
76-
//return callback(new Error('Unable to detect the input manifest format. Try specifying the correct format using the -f <format> option. Available formats are: ' + availableFormats + '.'));
7775
}
7876

7977
log.info('Found a ' + detectedFormat + ' manifest...');

lib/manifestTools/manifestValidator.js

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,24 @@ var constants = require('../constants'),
1212

1313
var toStringFunction = Object.prototype.toString;
1414

15-
// load the rule(s) from a folder or file
1615
function loadValidationRules(fileOrDir, platforms, callback) {
1716

1817
var stat = Q.nfbind(fs.stat);
1918

20-
// list contents of the validation rules folder
2119
return Q.nfcall(fs.readdir, fileOrDir).then(function (files) {
2220
return Q.allSettled(files.map(function (file) {
2321
var filePath = path.join(fileOrDir, file);
2422
return stat(filePath).then(function (info) {
25-
// test if file system object is a directory or a file
2623
if (info.isDirectory()) {
27-
// ignore any directory that doesn't match one of the requested platforms
2824
if (platforms.indexOf(file) < 0) {
2925
return Q.resolve();
3026
}
3127

32-
// process the rules in the platform folder
3328
return loadValidationRules(filePath, []);
3429
}
3530

36-
// load the rules defined in the file
3731
var rulePath = path.join(fileOrDir, file);
3832
try {
39-
// load the rule from the file
4033
return require(rulePath);
4134
}
4235
catch (err) {
@@ -45,7 +38,6 @@ function loadValidationRules(fileOrDir, platforms, callback) {
4538
});
4639
}))
4740
.then (function (results) {
48-
// verify the results and consolidate the loaded rules
4941
return results.reduce(function (validationRules, result) {
5042
if (result.state === 'fulfilled') {
5143
if (result.value) {
@@ -70,7 +62,6 @@ function loadValidationRules(fileOrDir, platforms, callback) {
7062
throw err;
7163
}
7264

73-
// fileOrDir is a file
7465
var rules = require(fileOrDir);
7566
return Array.isArray(rules) ? rules : [rules];
7667
})
@@ -114,7 +105,6 @@ function applyValidationRules(w3cManifestInfo, platformModules, platforms) {
114105
var allResults = [];
115106

116107
function validateAllPlatforms() {
117-
// load and run validation rules for "all platforms"
118108
var validationRulesDir = path.join(__dirname, 'validationRules');
119109
return loadValidationRules(validationRulesDir).then(function (rules) {
120110
return runValidationRules(w3cManifestInfo, rules).then(function (results) {
@@ -124,7 +114,6 @@ function applyValidationRules(w3cManifestInfo, platformModules, platforms) {
124114
}
125115

126116
function validatePlatform() {
127-
// run platform-specific validation rules
128117
var platformTasks = platformModules.map(function (platform) {
129118
return platform.getValidationRules(platforms).then(function (rules) {
130119
return runValidationRules(w3cManifestInfo, rules).then(function (results) {
@@ -136,7 +125,6 @@ function applyValidationRules(w3cManifestInfo, platformModules, platforms) {
136125
return Q.allSettled(platformTasks);
137126
}
138127

139-
// Only run the "All Platform" validations for W3C manifests
140128
if (w3cManifestInfo.format === constants.BASE_MANIFEST_FORMAT) {
141129
return validateAllPlatforms()
142130
.then(validatePlatform)
@@ -256,7 +244,6 @@ function validateAndNormalizeStartUrl(siteUrl, manifestInfo, callback) {
256244
var parsedSiteUrl = url.parse(siteUrl);
257245
var parsedManifestStartUrl = url.parse(manifestInfo.content.start_url);
258246
if (parsedManifestStartUrl.hostname && parsedSiteUrl.hostname !== parsedManifestStartUrl.hostname) {
259-
// issue #88 - bis
260247
var subDomainOfManifestStartUrlSplitted = parsedManifestStartUrl.hostname.split('.');
261248
var lengthSubDomain = subDomainOfManifestStartUrlSplitted.length;
262249
var subDomainOfManifestStartUrl = null;

0 commit comments

Comments
 (0)