mirror of
https://github.com/elastic/kibana.git
synced 2025-04-20 07:48:52 -04:00
Backports PR #9934
**Commit 1:**
fixes windows path un ui-framework startup
* Original sha: 33e3d3e390
* Authored by Jim Unger <bigfunger@gmail.com> on 2017-01-18T20:56:36Z
78 lines
2.2 KiB
JavaScript
78 lines
2.2 KiB
JavaScript
const sass = require('node-sass');
|
|
const postcss = require('postcss');
|
|
const postcssConfig = require('../src/optimize/postcss.config');
|
|
const chokidar = require('chokidar');
|
|
const debounce = require('lodash/function/debounce');
|
|
const platform = require('os').platform();
|
|
|
|
module.exports = function (grunt) {
|
|
grunt.registerTask('uiFramework:start', function () {
|
|
const done = this.async();
|
|
Promise.all([uiFrameworkWatch(), uiFrameworkServerStart()]).then(done);
|
|
});
|
|
|
|
function uiFrameworkServerStart() {
|
|
const serverCmd = {
|
|
cmd: /^win/.test(platform) ? '.\\node_modules\\.bin\\webpack-dev-server.cmd' : './node_modules/.bin/webpack-dev-server',
|
|
args: [
|
|
'--config=ui_framework/doc_site/webpack.config.js',
|
|
'--hot ',
|
|
'--inline',
|
|
'--content-base=ui_framework/doc_site/build',
|
|
'--host=0.0.0.0',
|
|
'--port=8020',
|
|
],
|
|
opts: { stdio: 'inherit' }
|
|
};
|
|
|
|
return new Promise((resolve, reject) => {
|
|
grunt.util.spawn(serverCmd, (error, result, code) => {
|
|
if (error || code !== 0) {
|
|
const message = result.stderr || result.stdout;
|
|
|
|
grunt.log.error(message);
|
|
|
|
return reject();
|
|
}
|
|
|
|
grunt.log.writeln(result);
|
|
|
|
resolve();
|
|
});
|
|
|
|
});
|
|
}
|
|
|
|
function uiFrameworkCompile() {
|
|
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);
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
function uiFrameworkWatch() {
|
|
const debouncedCompile = debounce(uiFrameworkCompile, 400, { leading: true });
|
|
|
|
return new Promise((resolve, reject) => {
|
|
debouncedCompile();
|
|
|
|
chokidar.watch('ui_framework/components', { ignoreInitial: true }).on('all', (event, path) => {
|
|
grunt.log.writeln(event, path);
|
|
debouncedCompile();
|
|
});
|
|
});
|
|
}
|
|
};
|