2016-07-20 15:45:04 +02:00
|
|
|
'use strict';
|
2016-03-30 14:29:59 +02:00
|
|
|
|
2014-02-12 22:47:42 +00:00
|
|
|
var gulp = require('gulp');
|
|
|
|
|
var concat = require('gulp-concat');
|
2016-07-20 15:45:04 +02:00
|
|
|
var eslint = require('gulp-eslint');
|
2014-09-12 23:04:35 +01:00
|
|
|
var Dgeni = require('dgeni');
|
2014-02-12 22:47:42 +00:00
|
|
|
var merge = require('event-stream').merge;
|
2014-02-17 14:01:30 +00:00
|
|
|
var path = require('canonical-path');
|
2014-09-24 15:01:20 +01:00
|
|
|
var foreach = require('gulp-foreach');
|
|
|
|
|
var uglify = require('gulp-uglify');
|
|
|
|
|
var sourcemaps = require('gulp-sourcemaps');
|
|
|
|
|
var rename = require('gulp-rename');
|
2014-02-12 22:47:42 +00:00
|
|
|
|
|
|
|
|
// We indicate to gulp that tasks are async by returning the stream.
|
|
|
|
|
// Gulp can then wait for the stream to close before starting dependent tasks.
|
2017-12-27 19:16:46 +01:00
|
|
|
// See clean for an async task, and see assets and doc-gen for dependent tasks below.
|
2014-02-12 22:47:42 +00:00
|
|
|
|
|
|
|
|
var outputFolder = '../build/docs';
|
|
|
|
|
|
2014-09-23 18:43:08 +01:00
|
|
|
var src = 'app/src/**/*.js';
|
2015-08-11 17:20:04 -07:00
|
|
|
var ignoredFiles = '!src/angular.bind.js';
|
2014-09-23 18:43:08 +01:00
|
|
|
var assets = 'app/assets/**/*';
|
2014-02-17 14:01:30 +00:00
|
|
|
|
2014-09-24 15:01:20 +01:00
|
|
|
|
2016-07-20 15:45:04 +02:00
|
|
|
var getMergedEslintConfig = function(filepath) {
|
|
|
|
|
return {
|
|
|
|
|
configFile: filepath,
|
|
|
|
|
baseConfig: '../.eslintrc.json',
|
|
|
|
|
rules: {
|
|
|
|
|
// Examples don't run in strict mode; accept that for now.
|
|
|
|
|
strict: 'off',
|
|
|
|
|
// Generated examples may miss the final EOL; ignore that.
|
|
|
|
|
'eol-last': 'off',
|
2016-08-06 18:24:14 +03:00
|
|
|
// Generated files use the system's default linebreak style (e.g. CRLF on Windows)
|
|
|
|
|
'linebreak-style': 'off',
|
2016-07-20 15:45:04 +02:00
|
|
|
// While alerts would be bad to have in the library or test code,
|
|
|
|
|
// they're perfectly fine in examples.
|
|
|
|
|
'no-alert': 'off',
|
2016-08-10 12:13:14 +02:00
|
|
|
|
|
|
|
|
// The following rules have to be disabled or tweaked because dgeni template wrappers
|
|
|
|
|
// don't follow them and we have no way to validate only the parts taken
|
|
|
|
|
// from ngdoc.
|
|
|
|
|
|
2016-07-20 15:45:04 +02:00
|
|
|
// some dgeni-packages templates generate whitespace-only lines
|
2016-08-10 12:13:14 +02:00
|
|
|
'no-trailing-spaces': ['error', { 'skipBlankLines': true }],
|
|
|
|
|
|
|
|
|
|
// dgeni templates use double quotes as string delimiters
|
|
|
|
|
quotes: 'off'
|
2016-07-20 15:45:04 +02:00
|
|
|
},
|
|
|
|
|
ignore: false,
|
|
|
|
|
useEslintrc: false
|
|
|
|
|
};
|
2016-03-30 14:29:59 +02:00
|
|
|
};
|
|
|
|
|
|
2017-07-21 13:35:40 +02:00
|
|
|
var copyComponent = function(component, pattern, base, sourceFolder, packageFile) {
|
2014-02-17 14:01:30 +00:00
|
|
|
pattern = pattern || '/**/*';
|
2017-07-21 13:35:40 +02:00
|
|
|
base = base || '';
|
2016-12-01 13:26:51 +00:00
|
|
|
sourceFolder = sourceFolder || '../node_modules';
|
|
|
|
|
packageFile = packageFile || 'package.json';
|
2016-07-20 15:45:04 +02:00
|
|
|
var version = require(path.resolve(sourceFolder, component, packageFile)).version;
|
2014-02-17 14:01:30 +00:00
|
|
|
return gulp
|
2017-07-21 13:35:40 +02:00
|
|
|
.src(sourceFolder + '/' + component + pattern, {base: sourceFolder + '/' + component + '/' + base})
|
2014-02-17 14:01:30 +00:00
|
|
|
.pipe(gulp.dest(outputFolder + '/components/' + component + '-' + version));
|
|
|
|
|
};
|
|
|
|
|
|
2016-05-25 05:53:45 -07:00
|
|
|
|
2014-02-12 22:47:42 +00:00
|
|
|
gulp.task('build-app', function() {
|
2014-09-24 15:01:20 +01:00
|
|
|
var file = 'docs.js';
|
|
|
|
|
var minFile = 'docs.min.js';
|
|
|
|
|
var folder = outputFolder + '/js/';
|
|
|
|
|
|
2015-08-11 17:20:04 -07:00
|
|
|
return gulp.src([src, ignoredFiles])
|
2014-09-24 15:01:20 +01:00
|
|
|
.pipe(sourcemaps.init())
|
|
|
|
|
.pipe(concat(file))
|
|
|
|
|
.pipe(gulp.dest(folder))
|
|
|
|
|
.pipe(rename(minFile))
|
|
|
|
|
.pipe(uglify())
|
|
|
|
|
.pipe(sourcemaps.write('.'))
|
|
|
|
|
.pipe(gulp.dest(folder));
|
2014-02-12 22:47:42 +00:00
|
|
|
});
|
|
|
|
|
|
2016-05-25 05:53:45 -07:00
|
|
|
|
2016-12-01 13:26:51 +00:00
|
|
|
gulp.task('assets', function() {
|
2014-09-24 15:01:20 +01:00
|
|
|
var JS_EXT = /\.js$/;
|
2014-02-12 22:47:42 +00:00
|
|
|
return merge(
|
2014-10-19 11:51:09 +01:00
|
|
|
gulp.src(['img/**/*']).pipe(gulp.dest(outputFolder + '/img')),
|
|
|
|
|
gulp.src([assets]).pipe(gulp.dest(outputFolder)),
|
2014-09-24 15:01:20 +01:00
|
|
|
gulp.src([assets])
|
|
|
|
|
.pipe(foreach(function(stream, file) {
|
|
|
|
|
if (JS_EXT.test(file.relative)) {
|
|
|
|
|
var minFile = file.relative.replace(JS_EXT, '.min.js');
|
|
|
|
|
return stream
|
|
|
|
|
.pipe(sourcemaps.init())
|
|
|
|
|
.pipe(concat(minFile))
|
|
|
|
|
.pipe(uglify())
|
|
|
|
|
.pipe(sourcemaps.write('.'))
|
|
|
|
|
.pipe(gulp.dest(outputFolder));
|
|
|
|
|
}
|
|
|
|
|
})),
|
2017-07-21 13:35:40 +02:00
|
|
|
copyComponent('bootstrap', '/dist/css/bootstrap?(.min).css', 'dist'),
|
|
|
|
|
copyComponent('bootstrap', '/dist/fonts/*', 'dist'),
|
|
|
|
|
copyComponent('open-sans-fontface', '/fonts/{Regular,Semibold,Bold}/*'),
|
|
|
|
|
copyComponent('lunr', '/lunr?(.min).js'),
|
|
|
|
|
copyComponent('google-code-prettify', '/**/{lang-css,prettify}.js'),
|
|
|
|
|
copyComponent('jquery', '/dist/jquery.js', 'dist'),
|
|
|
|
|
copyComponent('marked', '/lib/marked.js'),
|
|
|
|
|
copyComponent('marked', '/marked.min.js')
|
2014-02-12 22:47:42 +00:00
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
2016-12-01 13:26:51 +00:00
|
|
|
gulp.task('doc-gen', function() {
|
2014-09-12 23:04:35 +01:00
|
|
|
var dgeni = new Dgeni([require('./config')]);
|
2016-03-30 14:29:59 +02:00
|
|
|
return dgeni.generate().catch(function() {
|
2014-09-12 23:04:35 +01:00
|
|
|
process.exit(1);
|
|
|
|
|
});
|
2014-02-12 22:47:42 +00:00
|
|
|
});
|
|
|
|
|
|
2016-05-25 05:53:45 -07:00
|
|
|
|
2016-07-20 15:45:04 +02:00
|
|
|
// Lint the example and protractor test files
|
|
|
|
|
gulp.task('eslint', ['doc-gen'], function() {
|
|
|
|
|
var examplesConfig = getMergedEslintConfig('../docs/app/test/.eslintrc.json');
|
|
|
|
|
// While in source we don't want to assume the browser environment so that we're
|
|
|
|
|
// compatible with non-browser window implementations like jsdom, it's not necessary
|
|
|
|
|
// in examples and may look weird to casual readers.
|
|
|
|
|
examplesConfig.envs = ['browser'];
|
2016-03-30 14:29:59 +02:00
|
|
|
|
2016-07-20 15:45:04 +02:00
|
|
|
var protractorConfig = getMergedEslintConfig('../docs/app/e2e/.eslintrc.json');
|
|
|
|
|
protractorConfig.rules['no-unused-vars'] = ['error', {
|
|
|
|
|
vars: 'local',
|
|
|
|
|
args: 'none',
|
|
|
|
|
// This variable is declared in code generated by dgeni-packages
|
|
|
|
|
// and not always used.
|
|
|
|
|
varsIgnorePattern: '^rootEl$'
|
|
|
|
|
}];
|
2016-03-30 14:29:59 +02:00
|
|
|
|
|
|
|
|
return merge(
|
|
|
|
|
gulp.src([
|
|
|
|
|
outputFolder + '/examples/**/*.js',
|
2016-07-20 15:45:04 +02:00
|
|
|
'!' + outputFolder + '/examples/**/protractor.js'
|
2016-03-30 14:29:59 +02:00
|
|
|
])
|
2016-07-20 15:45:04 +02:00
|
|
|
// eslint() attaches the lint output to the "eslint" property
|
|
|
|
|
// of the file object so it can be used by other modules.
|
|
|
|
|
.pipe(eslint(examplesConfig))
|
|
|
|
|
// eslint.format() outputs the lint results to the console.
|
|
|
|
|
// Alternatively use eslint.formatEach() (see Docs).
|
|
|
|
|
.pipe(eslint.format())
|
|
|
|
|
// To have the process exit with an error code (1) on
|
|
|
|
|
// lint error, return the stream and pipe to failAfterError last.
|
|
|
|
|
.pipe(eslint.failAfterError()),
|
2016-03-30 14:29:59 +02:00
|
|
|
gulp.src([
|
|
|
|
|
outputFolder + '/ptore2e/**/*.js',
|
2016-07-20 15:45:04 +02:00
|
|
|
outputFolder + '/examples/**/protractor.js'
|
2016-03-30 14:29:59 +02:00
|
|
|
])
|
2016-07-20 15:45:04 +02:00
|
|
|
.pipe(eslint(protractorConfig))
|
|
|
|
|
.pipe(eslint.format())
|
|
|
|
|
.pipe(eslint.failAfterError())
|
2016-03-30 14:29:59 +02:00
|
|
|
);
|
2014-02-15 20:46:30 +00:00
|
|
|
});
|
|
|
|
|
|
2014-02-12 22:47:42 +00:00
|
|
|
|
|
|
|
|
// The default task that will be run if no task is supplied
|
2016-07-20 15:45:04 +02:00
|
|
|
gulp.task('default', ['assets', 'doc-gen', 'build-app', 'eslint']);
|
2014-02-12 22:47:42 +00:00
|
|
|
|
2014-09-23 18:43:08 +01:00
|
|
|
gulp.task('watch', function() {
|
2015-08-11 17:20:04 -07:00
|
|
|
gulp.watch([src, ignoredFiles, assets], ['assets', 'build-app']);
|
2014-09-23 18:43:08 +01:00
|
|
|
});
|