wishthis/semantic/tasks/build/assets.js

67 lines
1.7 KiB
JavaScript
Raw Normal View History

2022-01-13 13:00:31 +00:00
/*******************************
Build Task
*******************************/
2023-08-17 09:47:40 +00:00
const
gulp = require('gulp'),
2022-01-13 13:00:31 +00:00
2023-08-17 09:47:40 +00:00
// gulp dependencies
chmod = require('gulp-chmod'),
gulpif = require('gulp-if'),
normalize = require('normalize-path'),
print = require('gulp-print').default,
2022-01-13 13:00:31 +00:00
2023-08-17 09:47:40 +00:00
// config
config = require('../config/user'),
tasks = require('../config/tasks'),
install = require('../config/project/install'),
2022-01-13 13:00:31 +00:00
2023-08-17 09:47:40 +00:00
log = tasks.log
2022-01-13 13:00:31 +00:00
;
function build(src, config) {
2023-08-17 09:47:40 +00:00
return gulp.src(src, { base: config.paths.source.themes })
.pipe(gulpif(config.hasPermissions, chmod(config.parsedPermissions)))
.pipe(gulp.dest(config.paths.output.themes))
.pipe(print(log.created))
2022-01-13 13:00:31 +00:00
;
}
function buildAssets(src, config, callback) {
2023-08-17 09:47:40 +00:00
if (!install.isSetup()) {
console.error('Cannot build assets. Run "gulp install" to set-up Fomantic');
callback();
return;
}
if (callback === undefined) {
callback = config;
config = src;
src = config.paths.source.themes + '/**/assets/**/*.*';
}
// copy assets
let assets = () => build(src, config);
assets.displayName = 'Building Assets';
gulp.series(assets)(callback);
2022-01-13 13:00:31 +00:00
}
module.exports = function (callback) {
2023-08-17 09:47:40 +00:00
buildAssets(config, callback);
2022-01-13 13:00:31 +00:00
};
module.exports.watch = function (type, config) {
2023-08-17 09:47:40 +00:00
gulp
.watch([normalize(config.paths.source.themes + '/**/assets/**/*.*')])
.on('all', function (event, path) {
console.log('Change in assets detected');
return gulp.series((callback) => buildAssets(path, config, callback))();
})
;
2022-01-13 13:00:31 +00:00
};
2022-08-05 09:25:53 +00:00
module.exports.buildAssets = buildAssets;