@@ -117,40 +117,29 @@ class BundleValidator {
117117 /**
118118 * If theme schema exists we need to validate it to make sure it passes all defined checks.
119119 * @private
120- * @param callback
121- * @returns {void }
120+ * @returns {boolean }
122121 */
123- _validateThemeSchema ( callback ) {
122+ async _validateThemeSchema ( ) {
124123 if ( this . themeConfig . schemaExists ( ) ) {
125- try {
126- this . _validateJsonSchema (
127- 'schema' ,
128- themeValidationSchema ,
129- this . themeConfig . getRawSchema ( ) ,
130- ) ;
131- } catch ( error ) {
132- callback ( error ) ;
133- return ;
134- }
124+ const rawSchema = await this . themeConfig . getRawSchema ( ) ;
125+ this . _validateJsonSchema ( 'schema' , themeValidationSchema , rawSchema ) ;
135126 }
136127
137- callback ( null , true ) ;
128+ return true ;
138129 }
139130
140131 /**
141132 * Ensure theme configuration exists and passes the json schema file
142133 * @private
143- * @param callback
144- * @returns {void }
134+ * @returns {boolean }
145135 */
146- _validateThemeConfiguration ( callback ) {
136+ async _validateThemeConfiguration ( ) {
147137 if ( ! this . themeConfig . configExists ( ) ) {
148138 const errMsg =
149139 'You must have a ' . red +
150140 'config.json' . cyan +
151141 ' file in your top level theme directory.' ;
152- callback ( new Error ( errMsg ) ) ;
153- return ;
142+ throw new Error ( errMsg ) ;
154143 }
155144
156145 if ( ! this . isPrivate && ! this . themeConfig . schemaExists ( ) ) {
@@ -161,22 +150,17 @@ class BundleValidator {
161150 const validationSchema = this . isPrivate
162151 ? privateThemeConfigValidationSchema
163152 : themeConfigValidationSchema ;
164- try {
165- this . _validateJsonSchema ( 'config' , validationSchema , this . themeConfig . getRawConfig ( ) ) ;
166- } catch ( error ) {
167- callback ( error ) ;
168- return ;
169- }
153+ const rawConfig = await this . themeConfig . getRawConfig ( ) ;
170154
171- callback ( null , true ) ;
155+ return this . _validateJsonSchema ( 'config' , validationSchema , rawConfig ) ;
172156 }
173157
174158 /**
175159 * @private
176160 * @param type
177161 * @param schema
178162 * @param data
179- * @returns {void }
163+ * @returns {boolean }
180164 */
181165 _validateJsonSchema ( type , schema , data ) {
182166 const validator = new Validator ( this . jsonSchemaValidatorOptions ) ;
@@ -189,33 +173,32 @@ class BundleValidator {
189173 }
190174 throw new Error ( errorMessage . red ) ;
191175 }
176+
177+ return true ;
192178 }
193179
194180 /**
195181 * Ensure that schema translations exists and there are no missing or unused keys.
196182 * @private
197- * @param {function } callback
198- * @returns {void }
183+ * @returns {boolean }
199184 */
200- _validateSchemaTranslations ( callback ) {
185+ async _validateSchemaTranslations ( ) {
201186 const validatorSchemaTranslations = new ValidatorSchemaTranslations ( ) ;
202187 const validator = new Validator ( this . jsonSchemaValidatorOptions ) ;
203188
204189 if ( this . themeConfig . schemaExists ( ) ) {
205- validatorSchemaTranslations . setSchema ( this . themeConfig . getRawSchema ( ) ) ;
190+ validatorSchemaTranslations . setSchema ( await this . themeConfig . getRawSchema ( ) ) ;
206191 }
207192
208193 if ( this . themeConfig . schemaTranslationsExists ( ) ) {
209194 try {
210- validatorSchemaTranslations . setTranslations (
211- this . themeConfig . getRawSchemaTranslations ( ) ,
212- ) ;
195+ const rawSchemaTranslations = await this . themeConfig . getRawSchemaTranslations ( ) ;
196+ validatorSchemaTranslations . setTranslations ( rawSchemaTranslations ) ;
213197 } catch ( e ) {
214198 throw new Error ( 'Corrupted schemaTranslations.json file' . red ) ;
215199 }
216200 } else if ( validatorSchemaTranslations . getSchemaKeys ( ) . length ) {
217- callback ( new Error ( 'Missed schemaTranslations.json file' . red ) ) ;
218- return ;
201+ throw new Error ( 'Missed schemaTranslations.json file' . red ) ;
219202 }
220203
221204 const missedKeys = validatorSchemaTranslations . findMissedKeys ( ) ;
@@ -246,36 +229,32 @@ class BundleValidator {
246229 } ) ;
247230 }
248231
249- callback ( new Error ( errorMessage . red ) ) ;
250- return ;
232+ throw new Error ( errorMessage . red ) ;
251233 }
252234
253- callback ( null , true ) ;
235+ return true ;
254236 }
255237
256238 /**
257239 * Validates images for marketplace themes
258240 * @private
259- * @param callback
260- * @returns {void }
241+ * @returns {boolean[] }
261242 */
262- _validateMetaImages ( callback ) {
263- const { meta, variations } = this . themeConfig . getConfig ( ) ;
243+ async _validateMetaImages ( ) {
244+ const { meta, variations } = await this . themeConfig . getConfig ( ) ;
264245 const composedImagePath = path . resolve ( this . themePath , 'meta' , meta . composed_image ) ;
265246 const imageTasks = [ ] ;
266247
267248 if ( ! this . _isValidImageType ( composedImagePath ) ) {
268- const errorMsg =
249+ throw new Error (
269250 'Invalid file type for "meta.composed_image".' . red +
270- `\r\nValid types (${ VALID_IMAGE_TYPES . join ( ', ' ) } )` . red ;
271- callback ( new Error ( errorMsg ) ) ;
272- return ;
251+ `\r\nValid types (${ VALID_IMAGE_TYPES . join ( ', ' ) } )` . red ,
252+ ) ;
273253 }
274254 if ( ! fs . existsSync ( composedImagePath ) ) {
275- const errorMsg = 'The path you specified for your "meta.composed_image" does not exist.'
276- . red ;
277- callback ( new Error ( errorMsg ) ) ;
278- return ;
255+ throw new Error (
256+ 'The path you specified for your "meta.composed_image" does not exist.' . red ,
257+ ) ;
279258 }
280259 imageTasks . push ( ( cb ) =>
281260 this . _validateImage ( composedImagePath , WIDTH_COMPOSED , HEIGHT_COMPOSED , cb ) ,
@@ -291,17 +270,15 @@ class BundleValidator {
291270 ) ;
292271
293272 if ( ! this . _isValidImageType ( desktopScreenshotPath ) ) {
294- const errorMsg =
273+ throw new Error (
295274 `Invalid file type for ${ id } variation's "desktop_screenshot".` . red +
296- `\r\nValid types (${ VALID_IMAGE_TYPES . join ( ', ' ) } )` . red ;
297- callback ( new Error ( errorMsg ) ) ;
298- return ;
275+ `\r\nValid types (${ VALID_IMAGE_TYPES . join ( ', ' ) } )` . red ,
276+ ) ;
299277 }
300278 if ( ! fs . existsSync ( desktopScreenshotPath ) ) {
301- const errorMsg = `The path you specified for the ${ id } variation's "desktop_screenshot" does not exist.`
302- . red ;
303- callback ( new Error ( errorMsg ) ) ;
304- return ;
279+ throw new Error (
280+ `The path you specified for the ${ id } variation's "desktop_screenshot" does not exist.` . red ,
281+ ) ;
305282 }
306283 imageTasks . push ( ( cb ) =>
307284 this . _validateImage ( desktopScreenshotPath , WIDTH_DESKTOP , HEIGHT_DESKTOP , cb ) ,
@@ -314,26 +291,22 @@ class BundleValidator {
314291 ) ;
315292
316293 if ( ! this . _isValidImageType ( mobileScreenshotPath ) ) {
317- const errorMsg =
294+ throw new Error (
318295 `Invalid file type for ${ id } variation's "mobile_screenshot".` . red +
319- `\r\nValid types (${ VALID_IMAGE_TYPES . join ( ', ' ) } )` . red ;
320- callback ( new Error ( errorMsg ) ) ;
321- return ;
296+ `\r\nValid types (${ VALID_IMAGE_TYPES . join ( ', ' ) } )` . red ,
297+ ) ;
322298 }
323299 if ( ! fs . existsSync ( mobileScreenshotPath ) ) {
324- const errorMsg = `The path you specified for the ${ id } variation's "mobile_screenshot" does not exist.`
325- . red ;
326- callback ( new Error ( errorMsg ) ) ;
327- return ;
300+ throw new Error (
301+ `The path you specified for the ${ id } variation's "mobile_screenshot" does not exist.` . red ,
302+ ) ;
328303 }
329304 imageTasks . push ( ( cb ) =>
330305 this . _validateImage ( mobileScreenshotPath , WIDTH_MOBILE , HEIGHT_MOBILE , cb ) ,
331306 ) ;
332307 }
333308
334- async . parallel ( imageTasks , ( err , result ) => {
335- callback ( err , result ) ;
336- } ) ;
309+ return async . parallel ( imageTasks ) ;
337310 }
338311
339312 /**
0 commit comments