Skip to content

Commit

Permalink
chore(*) add gulp build --with-docs
Browse files Browse the repository at this point in the history
Now, gulp build task with the flag --with-docs will:
* generate docs in build/docs by running npm run yuidoc
* copy build/docs to build/dist/docs
  • Loading branch information
topheman committed Sep 14, 2015
1 parent 07aa3de commit 5277862
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 3 deletions.
3 changes: 2 additions & 1 deletion gulp/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ const paths = {
fonts: `${root}/build/dist/fonts/`,
images: `${root}/build/dist/images/`,
styles: `${root}/build/dist/styles/`,
scripts: `${root}/build/dist/scripts/`
scripts: `${root}/build/dist/scripts/`,
docs: `${root}/build/dist/docs/`
},
docs: `${root}/build/docs/`
},
Expand Down
34 changes: 32 additions & 2 deletions gulp/tasks/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import inject from 'gulp-inject';
import runSequence from 'run-sequence';

import {BANNER, BANNER_HTML} from '../const';
import {LOG, COLORS} from '../utils';
import {LOG, COLORS, WITH_DOCS} from '../utils';
import paths from '../paths';

//=============================================
Expand Down Expand Up @@ -51,7 +51,7 @@ function bytediffFormatter(data) {
//=============================================

/**
* The 'clean' task delete 'build' and '.tmp' directories.
* The 'clean' task delete 'build/dist' and '.tmp' directories.
* But keeps build/dist/.git (if you git init this folder to deploy via git)
*/
gulp.task('clean', (cb) => {
Expand All @@ -75,6 +75,35 @@ gulp.task('extras', () => {
.pipe(gulp.dest(paths.build.dist.basePath));
});

/**
* This task generates doc to `build/docs` and copies it to `build/dist/docs`
* It only does it if run with correct flag: `gulp build --with-docs`
*
* If no flag, does nothing.
*/
gulp.task('extras-docs', (cb) => {
if(WITH_DOCS){
runSequence(
['generate-docs'],
['copy-generated-docs'],
(err) => {
if (err) {
let exitCode = 3;
LOG('[ERROR] gulp build task failed (docs generation step)', err);
LOG('[FAIL] gulp build task failed (docs generation step) - exiting with code ' + exitCode);
return process.exit(exitCode);
}
else {
return cb();
}
}
);
}
else{
return cb();
}
});

/**
* The 'compile' task compile all js, css and html files.
*
Expand Down Expand Up @@ -132,6 +161,7 @@ gulp.task('build', (cb) => {
runSequence(
['clean'],
['compile', 'extras', 'images'],
['extras-docs'],
(err) => {
if (err) {
let exitCode = 2;
Expand Down
30 changes: 30 additions & 0 deletions gulp/tasks/docs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'use strict';

import gulp from 'gulp';
import {exec} from 'child_process';

import paths from '../paths';

/**
* This task simply encapsulate the npm task `npm run yuidoc`
* so that it could be integrated in the `gulp build --with-docs` workflow
*/
gulp.task('generate-docs', (cb) => {
return exec('npm run yuidoc', (error, stdout, stderr) => {
console.log('stdout: ' + stdout);
console.log('stderr: ' + stderr);
if (error !== null) {
console.log('exec error: ' + error);
}
cb();
});
});

/**
* This task simply copies generated docs from `build/docs` to `build/dist/docs`
* `build/docs` must have been generated before
*/
gulp.task('copy-generated-docs', () => {
return gulp.src(paths.build.docs + '**/*')
.pipe(gulp.dest(paths.build.dist.docs));
});
2 changes: 2 additions & 0 deletions gulp/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ LOG(COLORS.yellow('### Running in ' + environment + ' ###'));

export const ENV = environment;

export const WITH_DOCS = util.env['with-docs'];

/**
* @warn this is still in progress
*
Expand Down

0 comments on commit 5277862

Please sign in to comment.