You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
AdminLTE/gulpfile.js

316 lines
8.1 KiB

3 years ago
/* eslint-env node */
4 years ago
const autoprefix = require('autoprefixer')
4 years ago
const browserSync = require('browser-sync').create()
const del = require('del')
const { src, dest, lastRun, watch, series, parallel } = require('gulp')
const cleanCss = require('gulp-clean-css')
const eslint = require('gulp-eslint-new')
4 years ago
const fileinclude = require('gulp-file-include')
const validator = require('gulp-html')
const gulpIf = require('gulp-if')
4 years ago
const postcss = require('gulp-postcss')
4 years ago
const rename = require('gulp-rename')
const sass = require('gulp-sass')(require('sass'))
4 years ago
const gulpStylelint = require('gulp-stylelint')
const terser = require('gulp-terser')
const rollup = require('rollup')
const rollupTypescript = require('@rollup/plugin-typescript')
const rtlcss = require('rtlcss')
4 years ago
4 years ago
const pkg = require('./package')
const year = new Date().getFullYear()
const banner = `/*!
* AdminLTE v${pkg.version} (${pkg.homepage})
* Copyright 2014-${year} ${pkg.author}
* Licensed under MIT (https://github.com/ColorlibHQ/AdminLTE/blob/master/LICENSE)
*/`
4 years ago
// Define paths
const paths = {
dist: {
base: './dist/',
css: './dist/css',
js: './dist/js',
4 years ago
html: './dist/pages',
assets: './dist/assets'
4 years ago
},
src: {
base: './src/',
html: './src/pages/**/*.html',
assets: './src/assets/**/*.*',
partials: './src/partials/**/*.html',
scss: './src/scss',
ts: './src/ts'
4 years ago
},
temp: {
base: './.temp/',
css: './.temp/css',
4 years ago
js: './.temp/js',
4 years ago
html: './.temp/pages',
assets: './.temp/assets'
3 years ago
}
4 years ago
}
4 years ago
const sassOptions = {
outputStyle: 'expanded',
3 years ago
includePaths: ['./node_modules/']
4 years ago
}
const postcssOptions = [
3 years ago
autoprefix({ cascade: false })
]
4 years ago
const postcssRtlOptions = [
autoprefix({ cascade: false }),
3 years ago
rtlcss({})
]
// From here Dev mode will Start
4 years ago
// Lint SCSS
const lintScss = () => src([paths.src.scss + '/**/*.scss'], { since: lastRun(lintScss) })
.pipe(gulpStylelint({
failAfterError: false,
reporters: [
{ formatter: 'string', console: true }
]
}))
4 years ago
// Compile SCSS
const scss = () => src(paths.src.scss + '/adminlte.scss', { sourcemaps: true })
.pipe(sass(sassOptions).on('error', sass.logError))
.pipe(postcss(postcssOptions))
.pipe(dest(paths.temp.css, { sourcemaps: '.' }))
.pipe(browserSync.stream())
// Compile SCSS Dark
const scssDark = () => src(paths.src.scss + '/dark/adminlte-dark-addon.scss', { sourcemaps: true })
4 years ago
.pipe(sass(sassOptions).on('error', sass.logError))
.pipe(postcss(postcssOptions))
.pipe(dest(paths.temp.css + '/dark', { sourcemaps: '.' }))
4 years ago
.pipe(browserSync.stream())
// Lint TS
function isFixed(file) {
// Has ESLint fixed the file contents?
return file.eslint !== null && file.eslint.fixed
}
4 years ago
const lintTs = () => src([paths.src.ts + '/**/*.ts'], { since: lastRun(lintTs) })
.pipe(eslint({ fix: true }))
.pipe(eslint.format())
.pipe(gulpIf(isFixed, dest(paths.src.ts)))
.pipe(eslint.failAfterError())
// Compile TS
const tsCompile = () =>
rollup.rollup({
input: paths.src.ts + '/adminlte.ts',
output: {
3 years ago
banner
4 years ago
},
plugins: [
3 years ago
rollupTypescript()
]
}).then(bundle => bundle.write({
file: paths.temp.js + '/adminlte.js',
format: 'umd',
name: 'adminlte',
3 years ago
sourcemap: true
}))
4 years ago
const assets = () => src([paths.src.assets])
.pipe(dest(paths.temp.assets))
.pipe(browserSync.stream())
4 years ago
const index = () => src([paths.src.base + '*.html'])
4 years ago
.pipe(fileinclude({
prefix: '@@',
basepath: './src/partials/',
context: {
3 years ago
environment: 'development'
}
4 years ago
}))
.pipe(dest(paths.temp.base))
.pipe(browserSync.stream())
4 years ago
const html = () => src([paths.src.html])
4 years ago
.pipe(fileinclude({
prefix: '@@',
basepath: './src/partials/',
context: {
3 years ago
environment: 'development'
}
4 years ago
}))
.pipe(dest(paths.temp.html))
.pipe(browserSync.stream())
4 years ago
3 years ago
const lintHtml = () => src([paths.temp.html + '/**/*.html', paths.temp.base + '*.html'], { since: lastRun(lintHtml) })
.pipe(validator())
4 years ago
4 years ago
const serve = () => {
4 years ago
browserSync.init({
3 years ago
server: paths.temp.base
4 years ago
})
watch([paths.src.scss], series(lintScss))
watch([paths.src.scss + '/**/*.scss', '!' + paths.src.scss + '/bootstrap-dark/**/*.scss', '!' + paths.src.scss + '/dark/**/*.scss'], series(scss))
watch([paths.src.scss + '/bootstrap-dark/', paths.src.scss + '/dark/'], series(scssDark))
watch([paths.src.ts], series(lintTs, tsCompile))
watch([paths.src.html, paths.src.base + '*.html', paths.src.partials], series(html, index, lintHtml))
watch([paths.src.assets], series(assets))
}
// From here Dist will Start
4 years ago
// Clean
const cleanDist = () => del([paths.dist.base])
4 years ago
const lintDistScss = () => src([paths.src.scss + '/**/*.scss'])
.pipe(gulpStylelint({
failAfterError: false,
reporters: [
{ formatter: 'string', console: true }
]
}))
// Compile and copy all scss/css
const copyDistCssAll = () => src([paths.src.scss + '/**/*.scss'], {
base: paths.src.scss,
3 years ago
sourcemaps: true
})
4 years ago
.pipe(sass(sassOptions).on('error', sass.logError))
.pipe(postcss(postcssOptions))
.pipe(dest(paths.dist.css, { sourcemaps: '.' }))
4 years ago
const copyDistCssRtl = () => src(paths.dist.css + '/*.css', { sourcemaps: true })
4 years ago
.pipe(postcss(postcssRtlOptions))
.pipe(rename({ suffix: '.rtl' }))
.pipe(dest(paths.dist.css + '/rtl', { sourcemaps: '.' }))
4 years ago
// Minify CSS
const minifyDistCss = () => src([
paths.dist.css + '/**/*.css'
], {
base: paths.dist.css,
sourcemaps: true
})
.pipe(cleanCss({ format: { breakWith: 'lf' } }))
.pipe(rename({ suffix: '.min' }))
.pipe(dest(paths.dist.css, { sourcemaps: '.' }))
const lintDistTs = () => src([paths.src.ts + '/**/*.ts'])
.pipe(eslint())
.pipe(eslint.failAfterError())
4 years ago
// Compile and copy ts/js
const copyDistJs = () =>
rollup.rollup({
input: paths.src.ts + '/adminlte.ts',
output: {
3 years ago
banner
4 years ago
},
plugins: [
3 years ago
rollupTypescript()
]
}).then(bundle => bundle.write({
file: paths.dist.js + '/adminlte.js',
format: 'umd',
name: 'adminlte',
3 years ago
sourcemap: true
}))
4 years ago
// Minify JS
// Need to add terser
const minifyDistJs = () =>
src(paths.dist.js + '/adminlte.js', { sourcemaps: true })
.pipe(terser({
compress: {
passes: 2
3 years ago
}
}))
.pipe(dest(paths.dist.js + '/adminlte.min.js'))
// Copy assets
const copyDistAssets = () => src(paths.src.assets)
.pipe(dest(paths.dist.assets))
// Copy index
const copyDistHtmlIndex = () => src([paths.src.base + '*.html'])
4 years ago
.pipe(fileinclude({
prefix: '@@',
basepath: './src/partials/',
context: {
3 years ago
environment: 'production'
}
4 years ago
}))
.pipe(dest(paths.dist.base))
4 years ago
// Copy Html
const copyDistHtml = () => src([paths.src.html])
4 years ago
.pipe(fileinclude({
prefix: '@@',
basepath: './src/partials/',
context: {
3 years ago
environment: 'production'
}
4 years ago
}))
.pipe(dest(paths.dist.html))
// HTML Lint
// Copy index for Lint
const copyDistHtmlIndexForLint = () => src([paths.src.base + '*.html'])
.pipe(fileinclude({
prefix: '@@',
basepath: './src/partials/',
context: {
environment: 'production'
}
}))
.pipe(dest(paths.temp.base))
// Copy Html for Lint
const copyDistHtmlForLint = () => src([paths.src.html])
.pipe(fileinclude({
prefix: '@@',
basepath: './src/partials/',
context: {
environment: 'production'
}
}))
.pipe(dest(paths.temp.html))
// Now Lint
const lintDistHtmlCopied = () => src([paths.temp.html + '/**/*.html', paths.temp.base + '*.html'])
.pipe(validator())
4 years ago
const lintDistHtml = series(copyDistHtmlIndexForLint, copyDistHtmlForLint, lintDistHtmlCopied)
4 years ago
const lint = parallel(
lintDistScss,
lintDistTs,
lintDistHtml
)
exports.lint = lint
const compile = series(
cleanDist,
parallel(
series(
parallel(copyDistCssAll, copyDistCssRtl),
minifyDistCss
),
series(copyDistJs, minifyDistJs),
copyDistAssets,
copyDistHtmlIndex,
copyDistHtml
)
)
exports.compile = compile
// For Production Release
exports.production = series(lint, compile)
4 years ago
// Default - Only for light mode AdminLTE
exports.default = series(scss, scssDark, tsCompile, html, index, assets, serve)