liferay-theme-tasks
Version:
A set of tasks for building and deploying Liferay Portal themes.
86 lines (73 loc) • 1.86 kB
JavaScript
/**
* SPDX-FileCopyrightText: © 2017 Liferay, Inc. <https://liferay.com>
* SPDX-License-Identifier: MIT
*/
;
const colors = require('ansi-colors');
const log = require('fancy-log');
const fs = require('fs-extra');
const {
default: FilePath,
} = require('liferay-npm-build-tools-common/lib/file-path');
const _ = require('lodash');
const path = require('path');
const project = require('../../lib/project');
const KickstartPrompt = require('../prompts/kickstart_prompt');
function registerTasks() {
const {gulp} = project;
const {pathSrc} = project.options;
gulp.task('kickstart', (callback) => {
log(
colors.yellow('Warning:'),
'the',
colors.cyan('kickstart'),
'task will potentially overwrite files in your src directory'
);
KickstartPrompt.prompt(
{
themeConfig: project.themeConfig.config,
},
(answers) => {
let tempNodeModulesPath;
let themeSrcPath;
if (answers.modulePath) {
themeSrcPath = new FilePath(answers.modulePath);
}
else if (answers.module) {
tempNodeModulesPath = new FilePath(
path.join(project.dir, '.temp_node_modules')
);
themeSrcPath = tempNodeModulesPath.join(
'node_modules',
answers.module,
'src'
);
}
if (themeSrcPath) {
const globs = _.map(
['css', 'images', 'js', 'templates'],
(folder) => themeSrcPath.join(folder, '**', '*').asPosix
);
gulp.src(globs, {
base: themeSrcPath.asNative,
})
.pipe(gulp.dest(pathSrc.asNative))
.on('end', () => {
if (tempNodeModulesPath) {
fs.removeSync(tempNodeModulesPath.asNative);
callback();
}
else {
callback();
}
});
}
else {
log(colors.yellow('Theme not selected'));
callback();
}
}
);
});
}
module.exports = registerTasks;