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

Commit b97570a

Browse files
author
estebanlopez
committed
Validate if manifest format has been passed in the arguments
1 parent f022db9 commit b97570a

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

lib/manifestTools/manifestLoader.js

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ function processManifestContents (data, manifestFormat, callback) {
6262
detectedFormat = manifestFormat;
6363
} else if (!detectedFormat) {
6464
var availableFormats = listAvailableManifestFormats().join(', ');
65-
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 + ' .'));
65+
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 + '.'));
6666
}
6767

6868
log.info('Found a ' + detectedFormat + ' manifest...');
@@ -94,7 +94,14 @@ function processManifestContents (data, manifestFormat, callback) {
9494
}
9595

9696
function downloadManifestFromUrl (manifestUrl, manifestFormat, callback) {
97-
97+
98+
if (arguments.length < 3) {
99+
if (utils.isFunction(manifestFormat)) {
100+
callback = manifestFormat;
101+
manifestFormat = undefined;
102+
}
103+
}
104+
98105
var deferred = Q.defer();
99106
request({ uri: manifestUrl }, function (err, response, data) {
100107
if (err || response.statusCode !== 200) {
@@ -117,7 +124,14 @@ function downloadManifestFromUrl (manifestUrl, manifestFormat, callback) {
117124
}
118125

119126
function getManifestFromSite (siteUrl, manifestFormat, callback) {
120-
127+
128+
if (arguments.length < 3) {
129+
if (utils.isFunction(manifestFormat)) {
130+
callback = manifestFormat;
131+
manifestFormat = undefined;
132+
}
133+
}
134+
121135
return fetchManifestUrlFromSite(siteUrl).then(function (manifestUrl) {
122136
if (manifestUrl) {
123137
return Q.nfcall(downloadManifestFromUrl, manifestUrl, manifestFormat);
@@ -141,6 +155,14 @@ function getManifestFromSite (siteUrl, manifestFormat, callback) {
141155
}
142156

143157
function getManifestFromFile (filePath, manifestFormat, callback) {
158+
159+
if (arguments.length < 3) {
160+
if (utils.isFunction(manifestFormat)) {
161+
callback = manifestFormat;
162+
manifestFormat = undefined;
163+
}
164+
}
165+
144166
return Q.nfcall(fs.readFile, filePath).then(function (data) {
145167
return Q.nfcall(processManifestContents, data, manifestFormat);
146168
})

test/manifestTools.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ describe('Manifest Tools', function () {
6262
it('Should return an Error if manifest format is invalid', function (done) {
6363
manifestTools.getManifestFromFile(inputFiles.invalidManifestFormat, function (err){
6464
should.exist(err);
65-
err.should.have.property('message', 'Invalid manifest format.');
65+
err.should.have.property('message', 'Unable to detect the input manifest format. Try specifying the correct format using the -f <format> option. Available formats are: w3c, chromeos, edgeextension.');
6666
done();
6767
});
6868
});

0 commit comments

Comments
 (0)