liferay / liferay-theme-tasks

A set of tasks for building and deploying Liferay Portal themes.
18 stars 24 forks source link

Preprocess for liferay-look-and-feel.xml in build:war #33

Closed crisp2u closed 7 years ago

crisp2u commented 7 years ago

Hi guys,

I've managed to migrate to the new theme sdk and integrate it in our maven build flow using frontend-maven-plugin. In the old maven flow I was using a combination of maven-war-plugin and buildnumber-maven-plugin to inject versions and build numbers in liferay-look-and-feel.xml. I'm not sure where to do that using gulp.

It seems that the gulp equivalent of filtering resources in the maven war plugin would be a gulp-preprocess or gulp-token-replace used in the plugin:war task.

Any ideas ?

natecavanaugh commented 7 years ago

Hi Cristian, Depending on how you want to integrate it into the work flow, you could probably use the hookFn option to leverage either of those plugins, or, if you really wanted to keep it insanely simple, you could even just read/write the contents. But if you want to leverage gulp, you could probably do something like:

var gulp = require('gulp');
var liferayThemeTasks = require('liferay-theme-tasks');
var replace = require('gulp-replace');

liferayThemeTasks.registerTasks({
    gulp: gulp,
    hookFn: function(gulp) {
        gulp.hook('before:build:war', function(done) {
            gulp.src('build/WEB-INF/liferay-look-and-feel.xml')
               .pipe(replace('{version}'))
               .pipe(gulp.dest('build/WEB-INF/liferay-look-and-feel.xml'));
        });
    }
});

Would something like that work?

Thanks Cristian,

crisp2u commented 7 years ago

@natecavanaugh we went with the hookFn and gulp-replace-task, something like this:

    gulp: gulp,
    hookFn: function (gulp) {
        gulp.hook('before:build:war', function (done) {
            gulp.src('build/WEB-INF/liferay-look-and-feel.xml')
                    .pipe(replace({
                        patterns: [
                            {
                                match: /\$\{(.*)\}/g,
                                replacement: function () {
                                    return process.env[arguments[1]] ? process.env[arguments[1]] : "unavailable at the moment"
                                }
                            }
                        ]
                    }))
                    .pipe(gulp.dest('build/WEB-INF/'));
            done();
        });
    }
});

My original question was more in the direction if the war plugin should not support this out of the box since it's kind of a client side replacement for the maven-war-plugin and that functionality was lost.

Thanks for the hints