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

Commit dd6c90d

Browse files
author
estebanlopez
committed
Merge branch 'force-manifest-format' into v1.0.0
2 parents e25e0f1 + 74719e9 commit dd6c90d

File tree

3 files changed

+29
-13
lines changed

3 files changed

+29
-13
lines changed

lib/manifestTools/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module.exports = {
1010
writeToFile: manifestLoader.writeToFile,
1111
fetchManifestUrlFromSite: manifestLoader.fetchManifestUrlFromSite,
1212
downloadManifestFromUrl: manifestLoader.downloadManifestFromUrl,
13+
listAvailableManifestFormats: manifestLoader.listAvailableManifestFormats,
1314
convertTo: manifestConverter.convertTo,
1415
validateManifest: manifestValidator.validateManifest,
1516
loadValidationRules: manifestValidator.loadValidationRules,

lib/manifestTools/manifestLoader.js

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function fetchManifestUrlFromSite (siteUrl, callback) {
4848
return deferred.promise.nodeify(callback);
4949
}
5050

51-
function processManifestContents (data, callback) {
51+
function processManifestContents (data, manifestFormat, callback) {
5252
var manifestObj = utils.parseJSON(data);
5353

5454
if (!manifestObj) {
@@ -57,9 +57,12 @@ function processManifestContents (data, callback) {
5757

5858
var detectedFormat = manifestTypeDetector.detect(manifestObj);
5959

60-
if (!detectedFormat) {
61-
log.debug('Unable to detect the input manifest format.');
62-
return callback(new Error('Invalid manifest format.'));
60+
if (manifestFormat) {
61+
log.warn('Forcing to format ' + manifestFormat + '...');
62+
detectedFormat = manifestFormat;
63+
} else if (!detectedFormat) {
64+
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 + ' .'));
6366
}
6467

6568
log.info('Found a ' + detectedFormat + ' manifest...');
@@ -90,15 +93,15 @@ function processManifestContents (data, callback) {
9093
});
9194
}
9295

93-
function downloadManifestFromUrl (manifestUrl, callback) {
96+
function downloadManifestFromUrl (manifestUrl, manifestFormat, callback) {
9497

9598
var deferred = Q.defer();
9699
request({ uri: manifestUrl }, function (err, response, data) {
97100
if (err || response.statusCode !== 200) {
98101
return deferred.reject(new Error('Failed to download manifest data.'));
99102
}
100103

101-
Q.nfcall(processManifestContents, data).then(function (manifestInfo) {
104+
Q.nfcall(processManifestContents, data, manifestFormat).then(function (manifestInfo) {
102105
if (manifestInfo) {
103106
manifestInfo.generatedUrl = manifestUrl;
104107
}
@@ -113,11 +116,11 @@ function downloadManifestFromUrl (manifestUrl, callback) {
113116
return deferred.promise.nodeify(callback);
114117
}
115118

116-
function getManifestFromSite (siteUrl, callback) {
119+
function getManifestFromSite (siteUrl, manifestFormat, callback) {
117120

118121
return fetchManifestUrlFromSite(siteUrl).then(function (manifestUrl) {
119122
if (manifestUrl) {
120-
return Q.nfcall(downloadManifestFromUrl, manifestUrl);
123+
return Q.nfcall(downloadManifestFromUrl, manifestUrl, manifestFormat);
121124
} else {
122125
// TODO: review what to do in this case. (manifest meta tag is not present)
123126
log.warn('No manifest found. A new manifest will be created.');
@@ -137,9 +140,9 @@ function getManifestFromSite (siteUrl, callback) {
137140
.nodeify(callback);
138141
}
139142

140-
function getManifestFromFile (filePath, callback) {
143+
function getManifestFromFile (filePath, manifestFormat, callback) {
141144
return Q.nfcall(fs.readFile, filePath).then(function (data) {
142-
return Q.nfcall(processManifestContents, data);
145+
return Q.nfcall(processManifestContents, data, manifestFormat);
143146
})
144147
.nodeify(callback);
145148
}
@@ -153,10 +156,15 @@ function writeToFile (manifestInfo, filePath, callback) {
153156
return Q.reject(new Error('Manifest content is empty or invalid.')).nodeify(callback);
154157
}
155158

159+
function listAvailableManifestFormats() {
160+
return [constants.BASE_MANIFEST_FORMAT, constants.CHROME_MANIFEST_FORMAT];
161+
}
162+
156163
module.exports = {
157164
getManifestFromSite: getManifestFromSite,
158165
getManifestFromFile: getManifestFromFile,
159166
writeToFile: writeToFile,
160167
fetchManifestUrlFromSite: fetchManifestUrlFromSite,
161-
downloadManifestFromUrl: downloadManifestFromUrl
168+
downloadManifestFromUrl: downloadManifestFromUrl,
169+
listAvailableManifestFormats: listAvailableManifestFormats
162170
};

lib/validations.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

3-
var platformTools = require('./platformTools');
3+
var platformTools = require('./platformTools'),
4+
manifestTools = require('./manifestTools');
45

56
function platformsValid(platforms) {
67
var availablePlatforms = platformTools.listPlatforms();
@@ -29,8 +30,14 @@ function logLevelValid(level) {
2930
return availableLevels.indexOf(level.toLowerCase()) >= 0;
3031
}
3132

33+
function manifestFormatValid(format) {
34+
var availableFormats = manifestTools.listAvailableManifestFormats();
35+
return availableFormats.indexOf(format.toLowerCase()) >= 0;
36+
}
37+
3238
module.exports = {
3339
platformsValid: platformsValid,
3440
platformToRunValid: platformToRunValid,
35-
logLevelValid: logLevelValid
41+
logLevelValid: logLevelValid,
42+
manifestFormatValid: manifestFormatValid
3643
};

0 commit comments

Comments
 (0)