@@ -48,7 +48,7 @@ function fetchManifestUrlFromSite (siteUrl, callback) {
48
48
return deferred . promise . nodeify ( callback ) ;
49
49
}
50
50
51
- function processManifestContents ( data , callback ) {
51
+ function processManifestContents ( data , manifestFormat , callback ) {
52
52
var manifestObj = utils . parseJSON ( data ) ;
53
53
54
54
if ( ! manifestObj ) {
@@ -57,9 +57,12 @@ function processManifestContents (data, callback) {
57
57
58
58
var detectedFormat = manifestTypeDetector . detect ( manifestObj ) ;
59
59
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 + ' .' ) ) ;
63
66
}
64
67
65
68
log . info ( 'Found a ' + detectedFormat + ' manifest...' ) ;
@@ -90,15 +93,15 @@ function processManifestContents (data, callback) {
90
93
} ) ;
91
94
}
92
95
93
- function downloadManifestFromUrl ( manifestUrl , callback ) {
96
+ function downloadManifestFromUrl ( manifestUrl , manifestFormat , callback ) {
94
97
95
98
var deferred = Q . defer ( ) ;
96
99
request ( { uri : manifestUrl } , function ( err , response , data ) {
97
100
if ( err || response . statusCode !== 200 ) {
98
101
return deferred . reject ( new Error ( 'Failed to download manifest data.' ) ) ;
99
102
}
100
103
101
- Q . nfcall ( processManifestContents , data ) . then ( function ( manifestInfo ) {
104
+ Q . nfcall ( processManifestContents , data , manifestFormat ) . then ( function ( manifestInfo ) {
102
105
if ( manifestInfo ) {
103
106
manifestInfo . generatedUrl = manifestUrl ;
104
107
}
@@ -113,11 +116,11 @@ function downloadManifestFromUrl (manifestUrl, callback) {
113
116
return deferred . promise . nodeify ( callback ) ;
114
117
}
115
118
116
- function getManifestFromSite ( siteUrl , callback ) {
119
+ function getManifestFromSite ( siteUrl , manifestFormat , callback ) {
117
120
118
121
return fetchManifestUrlFromSite ( siteUrl ) . then ( function ( manifestUrl ) {
119
122
if ( manifestUrl ) {
120
- return Q . nfcall ( downloadManifestFromUrl , manifestUrl ) ;
123
+ return Q . nfcall ( downloadManifestFromUrl , manifestUrl , manifestFormat ) ;
121
124
} else {
122
125
// TODO: review what to do in this case. (manifest meta tag is not present)
123
126
log . warn ( 'No manifest found. A new manifest will be created.' ) ;
@@ -137,9 +140,9 @@ function getManifestFromSite (siteUrl, callback) {
137
140
. nodeify ( callback ) ;
138
141
}
139
142
140
- function getManifestFromFile ( filePath , callback ) {
143
+ function getManifestFromFile ( filePath , manifestFormat , callback ) {
141
144
return Q . nfcall ( fs . readFile , filePath ) . then ( function ( data ) {
142
- return Q . nfcall ( processManifestContents , data ) ;
145
+ return Q . nfcall ( processManifestContents , data , manifestFormat ) ;
143
146
} )
144
147
. nodeify ( callback ) ;
145
148
}
@@ -153,10 +156,15 @@ function writeToFile (manifestInfo, filePath, callback) {
153
156
return Q . reject ( new Error ( 'Manifest content is empty or invalid.' ) ) . nodeify ( callback ) ;
154
157
}
155
158
159
+ function listAvailableManifestFormats ( ) {
160
+ return [ constants . BASE_MANIFEST_FORMAT , constants . CHROME_MANIFEST_FORMAT ] ;
161
+ }
162
+
156
163
module . exports = {
157
164
getManifestFromSite : getManifestFromSite ,
158
165
getManifestFromFile : getManifestFromFile ,
159
166
writeToFile : writeToFile ,
160
167
fetchManifestUrlFromSite : fetchManifestUrlFromSite ,
161
- downloadManifestFromUrl : downloadManifestFromUrl
168
+ downloadManifestFromUrl : downloadManifestFromUrl ,
169
+ listAvailableManifestFormats : listAvailableManifestFormats
162
170
} ;
0 commit comments