UNPKG

@elora-cloud/elora-cli

Version:
52 lines (49 loc) 2 kB
import path from 'node:path'; import chalk from 'chalk'; import consola from 'consola'; import { src, dest, parallel } from 'gulp'; import autoprefixer from 'gulp-autoprefixer'; import cleanCSS from 'gulp-clean-css'; import replace from 'gulp-replace'; import gulpSass from 'gulp-sass'; import dartSass from 'sass'; import { withTaskName } from '../utils/gulp.mjs'; import '../utils/paths.mjs'; import '../utils/pkg.mjs'; import '../utils/process.mjs'; /** * compile theme-chalk scss & minify * not use sass.sync().on('error', sass.logError) to throw exception * @return */ function buildThemeChalk(srcDir, themeFileDir, distDir) { const sass = gulpSass(dartSass); return (src(path.resolve(srcDir, themeFileDir)) .pipe(sass.sync({ loadPaths: ['node_modules', 'node_modules/animate.css/animate.min.css'], })) .pipe(autoprefixer({ cascade: false })) .pipe(cleanCSS({}, (details) => { consola.success(`${chalk.cyan(details.name)}: ${chalk.yellow(details.stats.originalSize / 1000)} KB -> ${chalk.green(details.stats.minifiedSize / 1000)} KB`); })) // .pipe( // rename((path) => { // if (!noElPrefixFile.test(path.basename)) { // path.basename = `elora-${path.basename}`; // } // }) // ) .pipe(dest(distDir))); } /** * copy source file to packages */ function copyThemeChalkSource(srcDir, themeSourceDir, distDir) { return src(path.resolve(srcDir, themeSourceDir)) .pipe(replace('assets/images', '../assets/images')) .pipe(dest(path.resolve(distDir, 'src'))); } function EloraBuildTheme(options) { return parallel(withTaskName('copyThemeChalkSource', () => copyThemeChalkSource(options.srcDir, options.themeSourceDir, options.distDir)), withTaskName('buildThemeChalk', () => buildThemeChalk(options.srcDir, options.themeFileDir, options.distDir))); } export { EloraBuildTheme, copyThemeChalkSource, EloraBuildTheme as default };