From ea7e67e0777e7264076d4bc7afbfdc0076d2f0b6 Mon Sep 17 00:00:00 2001 From: CJ Cenizal Date: Tue, 1 Aug 2017 08:09:36 -0700 Subject: [PATCH] Use promisify. --- tasks/ui_framework.js | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/tasks/ui_framework.js b/tasks/ui_framework.js index 497f647ca9d71..1b427a21ba8fc 100644 --- a/tasks/ui_framework.js +++ b/tasks/ui_framework.js @@ -3,9 +3,13 @@ import postcss from 'postcss'; import postcssConfig from '../src/optimize/postcss.config'; import chokidar from 'chokidar'; import debounce from 'lodash/function/debounce'; +import { promisify } from 'bluebird'; + const platform = require('os').platform(); const isPlatformWindows = /^win/.test(platform); +const renderSass = promisify(sass.render); + module.exports = function (grunt) { grunt.registerTask('uiFramework:build', function () { const done = this.async(); @@ -82,26 +86,23 @@ module.exports = function (grunt) { } function uiFrameworkCompile() { - return new Promise(resolve => { - sass.render({ - file: 'ui_framework/components/index.scss' - }, function (error, result) { - if (error) { - grunt.log.error(error); - } - - postcss([postcssConfig]) - .process(result.css, { from: 'ui_framework/components/index.scss', to: 'ui_framework/dist/ui_framework.css' }) - .then(result => { - grunt.file.write('ui_framework/dist/ui_framework.css', result.css); - - if (result.map) { - grunt.file.write('ui_framework/dist/ui_framework.css.map', result.map); - } - - resolve(); - }); - }); + const src = 'ui_framework/components/index.scss'; + const dest = 'ui_framework/dist/ui_framework.css'; + + return renderSass({ + file: src + }).then(result => { + postcss([postcssConfig]) + .process(result.css, { from: src, to: dest }) + .then(result => { + grunt.file.write(dest, result.css); + + if (result.map) { + grunt.file.write(`${dest}.map`, result.map); + } + }); + }).catch(error => { + grunt.log.error(error); }); }