* Reorganize documentation styles so they all live in doc_site/components directory. (#12809) - Remove global styles, e.g. body and html element selectors. * Create global_styles dir with sub-directories. (#12833) * Add SCSS style guide. (#12850) * Refactor UI Framework directory structure to house everything in a src directory. (#12880) - Add components/index.js and services/index.js files to continue to export JS modules from the root. * Add KUI Yeoman generator. * Support creation of components. * Add documentation generator for main page, demo, and sandbox. - Add additional documentation snippets to KUI generator. (#13076) - Fix incorrect use of double quotes in KUI generator snippet. (#13086) - Remove infrequently used imports from the KUI generator test template. (#13110) * Mock assets files for Jest. (#13060) * Fix broken coverage report paths in Jest config. (#13082) * Update eslint config to lint the new UI Framework directory structure. (#13102) * Fix positioning of doc site pagination buttons. (#13203) * Support hasReact prop for sandboxes. (#13270) * Remove deprecated used of component mixin from KUI generator's SCSS template. (#13377) * Fix rebasing errors. - Add dashboard back to Jest config. - Add missing form and tool_bar variables. * Rename tasks to createComponent and documentComponent. * Reference correct src paths in README. * Add children and className to templates' propTypes. * Add default folder name for page demo. * Add suffix to sandbox routes. * Specify testPathIgnorePatterns more clearly. * Rename component.test.js to test.js so that Jenkins won't try to run it. * Update npm scripts to depend on local yo dependency, not global. * Add ui_framework/src to copy task. * Simplify npm scripts and remove requirement for installing Yeoman from README. * Add services to moduleNameMapper in jest config. * Clean up Button and Gallery examples.
140 lines
3.7 KiB
JavaScript
140 lines
3.7 KiB
JavaScript
import sass from 'node-sass';
|
|
import postcss from 'postcss';
|
|
import postcssConfig from '../src/optimize/postcss.config';
|
|
import chokidar from 'chokidar';
|
|
import debounce from 'lodash/function/debounce';
|
|
|
|
const platform = require('os').platform();
|
|
const isPlatformWindows = /^win/.test(platform);
|
|
|
|
module.exports = function (grunt) {
|
|
grunt.registerTask('uiFramework:build', function () {
|
|
const done = this.async();
|
|
|
|
const serverCmd = {
|
|
cmd: isPlatformWindows ? '.\\node_modules\\.bin\\webpack.cmd' : './node_modules/.bin/webpack',
|
|
args: [
|
|
'-p',
|
|
'--config=ui_framework/doc_site/webpack.config.js',
|
|
'--devtool', // Prevent the source map from being generated
|
|
],
|
|
opts: { stdio: 'inherit' }
|
|
};
|
|
|
|
const uiFrameworkServerBuild = 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();
|
|
});
|
|
});
|
|
|
|
uiFrameworkServerBuild.then(done);
|
|
});
|
|
|
|
grunt.registerTask('uiFramework:start', function () {
|
|
const done = this.async();
|
|
Promise.all([uiFrameworkWatch(), uiFrameworkServerStart()]).then(done);
|
|
});
|
|
|
|
grunt.registerTask('uiFramework:compileCss', function () {
|
|
const done = this.async();
|
|
uiFrameworkCompile().then(done);
|
|
});
|
|
|
|
function uiFrameworkServerStart() {
|
|
const serverCmd = {
|
|
cmd: isPlatformWindows ? '.\\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() {
|
|
const src = 'ui_framework/src/index.scss';
|
|
const dest = 'ui_framework/dist/ui_framework.css';
|
|
|
|
return new Promise(resolve => {
|
|
sass.render({
|
|
file: src,
|
|
}, function (error, result) {
|
|
if (error) {
|
|
grunt.log.error(error);
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
resolve();
|
|
});
|
|
});
|
|
});
|
|
}
|
|
|
|
function uiFrameworkWatch() {
|
|
const debouncedCompile = debounce(() => {
|
|
// Compile the SCSS in a separate process because node-sass throws a fatal error if it fails
|
|
// to compile.
|
|
grunt.util.spawn({
|
|
cmd: isPlatformWindows ? '.\\node_modules\\.bin\\grunt.cmd' : './node_modules/.bin/grunt',
|
|
args: [
|
|
'uiFramework:compileCss',
|
|
],
|
|
}, (error, result) => {
|
|
if (error) {
|
|
grunt.log.error(result.stdout);
|
|
} else {
|
|
grunt.log.writeln(result);
|
|
}
|
|
});
|
|
}, 400, { leading: true });
|
|
|
|
return new Promise(() => {
|
|
debouncedCompile();
|
|
|
|
chokidar.watch('ui_framework/src', { ignoreInitial: true }).on('all', (event, path) => {
|
|
grunt.log.writeln(event, path);
|
|
debouncedCompile();
|
|
});
|
|
});
|
|
}
|
|
};
|