mdb-ui-kit/gulpfile.babel.js

202 lines
5.8 KiB
JavaScript
Raw Normal View History

2016-03-02 23:35:46 +03:00
import {Preset, Clean, Copy, MinifyCss, Sass, RollupEs, RollupUmd, RollupIife, ScssLint, EsLint, TaskSeries, Uglify} from 'gulp-pipeline/src/index'
2016-03-01 19:49:36 +03:00
// debug the project source - remove for repo
//import {Clean, CleanDigest, Images, MinifyCss, Sass, RollupIife, ScssLint, EsLint, Rev, TaskSeries} from 'gulp-pipeline'
//import Preset from '../../../gulp-pipeline/src/preset'
import extend from 'extend'
import stringify from 'stringify-object'
import gulp from 'gulp'
import findup from 'findup-sync'
const node_modules = findup('node_modules')
2016-03-02 01:57:24 +03:00
import pkg from './package.json'
import moment from 'moment'
2016-03-01 19:49:36 +03:00
let preset = Preset.baseline({
javascripts: {
source: {options: {cwd: 'js/src'}},
2016-03-01 19:49:36 +03:00
watch: {options: {cwd: 'js/src'}},
test: {options: {cwd: 'js/tests'}}
},
stylesheets: {
source: {options: {cwd: 'scss'}},
watch: {options: {cwd: 'scss'}}
},
images: {
source: {options: {cwd: 'images'}},
watch: {options: {cwd: 'images'}}
}
})
// When converting non-modular dependencies into usable ones using rollup-plugin-commonjs, if they don't have properly read exports add them here.
let namedExports = {}
//namedExports[`${node_modules}/corejs-typeahead/dist/bloodhound.js`] = ['Bloodhound']
//namedExports[`${node_modules}/anchor-js/anchor.js`] = ['AnchorJS']
2016-03-01 19:49:36 +03:00
let rollupConfig = {
2016-03-02 01:43:08 +03:00
//debug: true,
options: {
external: [
'anchor-js',
'clipboard'
],
globals: {
'anchor-js': 'anchors',
clipboard: 'Clipboard'
2016-03-02 01:57:24 +03:00
},
2016-03-02 23:35:46 +03:00
banner: `/*!
2016-03-02 01:57:24 +03:00
* Bootstrap Material Design v${pkg.version} (${pkg.homepage})
* Copyright 2014-${moment().format("YYYY")} ${pkg.author}
* Licensed under MIT (https://github.com/FezVrasta/bootstrap-material-design/blob/master/LICENSE)
*/`
},
2016-03-01 19:49:36 +03:00
commonjs: {
options: {
namedExports: namedExports,
2016-03-01 19:49:36 +03:00
}
}
}
let rollups = [
new RollupEs(gulp, preset, extend(true, {}, rollupConfig, {options: {dest: 'bootstrap-material-design.es.js'}})),
new RollupUmd(gulp, preset, extend(true, {}, rollupConfig, {
options: {
dest: 'bootstrap-material-design.umd.js',
moduleName: 'bootstrapMaterialDesign'
}
})),
new RollupIife(gulp, preset, extend(true, {}, rollupConfig, {
options: {
dest: 'bootstrap-material-design.iife.js',
moduleName: 'bootstrapMaterialDesign'
}
})),
2016-03-01 19:49:36 +03:00
]
let eslint = new EsLint(gulp, preset)
let scsslint = new ScssLint(gulp, preset)
let sass = new Sass(gulp, preset)
2016-03-01 19:49:36 +03:00
let lint = [scsslint, eslint]
// instantiate ordered array of recipes (for each instantiation the tasks will be created e.g. sass and sass:watch)
let recipes = [
new Clean(gulp, preset),
lint,
[
sass,
rollups
],
new MinifyCss(gulp, preset)
2016-03-01 19:49:36 +03:00
]
// Simple helper to create the default and watch tasks as a sequence of the recipes already defined
new TaskSeries(gulp, 'default', recipes)
new TaskSeries(gulp, 'lint', lint)
new TaskSeries(gulp, 'js', [eslint, rollups])
new TaskSeries(gulp, 'css', [scsslint, sass])
2016-03-02 01:57:24 +03:00
/**
* DOCS
*/
const referenceDocNotice =
2016-03-02 23:35:46 +03:00
`$1\n
2016-03-02 01:57:24 +03:00
[//]: # DO NOT EDIT IT WILL BE OVERWRITTEN - copy of bootstrap documentation generated by grunt docs-copy-bootstrap-docs\n
{% callout info %}\n**Bootstrap Reference Documentation**
This is a part of the reference documentation from <a href="http://getbootstrap.com">Bootstrap</a>.
It is included here to demonstrate rendering with Material Design for Bootstrap default styling.
See the <a href="/material-design/buttons">Material Design</a> section for more elements and customization options.
{% endcallout %}
\n\n$2`
let docsPreset = Preset.baseline({
javascripts: {
source: {options: {cwd: 'docs/assets/js/src'}},
watch: {options: {cwd: 'docs/assets/js/src'}},
test: {options: {cwd: 'docs/assets/js/tests'}},
dest: 'docs/dist'
},
stylesheets: {
source: {options: {cwd: 'docs/assets/scss'}},
watch: {options: {cwd: 'docs/assets/scss'}},
dest: 'docs/dist'
}
})
const docsConfig = {task: {prefix: 'docs:'}}
let docs = [
2016-03-02 01:43:08 +03:00
[
2016-03-02 23:35:46 +03:00
new ScssLint(gulp, docsPreset, docsConfig, {
2016-03-02 01:43:08 +03:00
source: {glob: ['**/*.scss', '!docs.scss']},
watch: {glob: ['**/*.scss', '!docs.scss']}
2016-03-02 23:35:46 +03:00
}),
2016-03-02 01:43:08 +03:00
new EsLint(gulp, docsPreset, docsConfig)
],
[
2016-03-02 23:35:46 +03:00
new RollupIife(gulp, docsPreset, docsConfig, rollupConfig, {
2016-03-02 01:43:08 +03:00
options: {
dest: 'docs.iife.js',
moduleName: 'docs'
}
2016-03-02 23:35:46 +03:00
}),
new Uglify(gulp, docsPreset, docsConfig, {
2016-03-02 01:43:08 +03:00
task: {name: 'vendor:uglify'},
source: {options: {cwd: 'docs/assets/js/vendor'}},
options: {dest: 'docs-vendor.min.js'}
2016-03-02 23:35:46 +03:00
}),
2016-03-02 01:43:08 +03:00
new Sass(gulp, docsPreset, docsConfig)
]
]
2016-03-02 23:35:46 +03:00
2016-03-09 19:23:01 +03:00
const docsProcess = (content, srcpath) => { // https://regex101.com/r/cZ7aO8/2
return content
.replace(/(---[\s\S]+?---)([\s\S]+)/mg, referenceDocNotice) // insert docs reference
.replace(/Fancy display heading/, 'Fancy heading') // remove sample text 'display' as this is a particular MD style and is confusing
}
2016-03-02 23:35:46 +03:00
let bsDocs = [
new Copy(gulp, docsPreset, docsConfig, {
task: {name: 'copy:bs-docs-content'},
source: {
options: {cwd: '../bootstrap/docs/content'},
glob: ['**/*']
},
dest: 'docs/content/',
2016-03-09 19:23:01 +03:00
process: docsProcess
}),
new Copy(gulp, docsPreset, docsConfig, {
task: {name: 'copy:bs-docs-components'},
source: {
options: {cwd: '../bootstrap/docs/components'},
glob: ['**/*']
},
dest: 'docs/components/',
process: docsProcess
}),
2016-03-09 19:50:09 +03:00
new Copy(gulp, docsPreset, docsConfig, {
task: {name: 'copy:bs-docs-scss'},
source: {
options: {cwd: '../bootstrap/docs/assets/scss'},
glob: [
'**/*',
'!docs.scss' // keep variable customizations
]
},
dest: 'docs/assets/scss/',
process: (content, srcpath) => {
return content.replace(/([\s\S]+)/mg, '// DO NOT EDIT IT WILL BE OVERWRITTEN - copy of bootstrap documentation generated by gulp docs:copy-bs\n\n$1');
}
}),
2016-03-02 23:35:46 +03:00
]
2016-03-09 19:23:01 +03:00
2016-03-09 19:50:09 +03:00
new TaskSeries(gulp, 'docs:copy-bs', bsDocs)