Closed caneta closed 7 years ago
Hey @caneta,
Yes you can. You can use the hookFn and programmatically invoke the config generator before the build task.
We're also current working on this hook for the theme tasks that will transpile es2015 code and run the config generator.
Can you tell me about your use case? It might be a good idea to create a hook that just has the config generator without the es2015 transpilation.
Hi @Robert-Frampton, I made it work using gulp-shell with hookFn as you suggested.
My use case follows.
Inside my Liferay 7 CE GA3, I've created with Yeoman and generator-liferay-theme a theme named ga3-theme
.
Next I've installed locally inside my theme directory the liferay-amd-loader and the liferay-module-config-generator:
npm install --save liferay-amd-loader
npm install --save liferay-module-config-generator
Here you are the list of my files dealing with module load (starting from directory myLiferayWorkspace/themes/ga3-theme
):
gulpfile.js
:
'use strict';
var gulp = require('gulp');
var liferayThemeTasks = require('liferay-theme-tasks');
var shell = require('gulp-shell');
liferayThemeTasks.registerTasks({
gulp: gulp,
hookFn: function(gulp) {
gulp.hook('before:build:base', function(done) {
gulp.src('src/config/config-base.js')
.pipe(
shell(
'liferay-cfgen -b <%= file.path %> -i -o src/config/config.js src/js/modules'
)
);
done();
});
} // hookFn()
});
src/WEB-INF/liferay-plugin-package.properties
:
# ...default settings...
Liferay-JS-Config=/config/config.js
src/js/modules/modNoDeps.js
:
define('mod-no-deps', [], function() {
return {
log: function log(text) {
console.log('modNoDeps says', text);
}
};
});
src/config/config-base.js
:
__CONFIG__.maps.modNoDeps = 'mod-no-deps';
__CONFIG__.paths['mod-no-deps'] = '/o/ga3-theme/js/modules/modNoDeps';
Loader.addModule({
name : 'modNoDeps',
exports : 'modNoDeps',
dependencies: []
});
src/js/main.js
:
AUI().ready(
function() {
'use strict';
require(['modNoDeps'],
function(modNoDeps) {
modNoDeps.log("I'm loaded!");
},
function(error) {
console.error(error);
}
);
}
); // output: "modNoDeps says I'm loaded!"
Regarding liferay-theme-es2015-hook, it seems really nice, but if I try to install it with npm it says that it doesn't exists in the registry:
user@host:/home/user/liferay/ga3/themes/ga3-theme$ npm install --save liferay-theme-es2015-hook
npm ERR! Linux 4.4.0-38-generic
npm ERR! argv "/home/user/.nvm/versions/node/v6.6.0/bin/node" "/home/user/.nvm/versions/node/v6.6.0/bin/npm" "install" "--save" "liferay-theme-es2015-hook"
npm ERR! node v6.6.0
npm ERR! npm v3.10.3
npm ERR! code E404
npm ERR! 404 Registry returned 404 for GET on http://registry.npmjs.org/liferay-theme-es2015-hook
npm ERR! 404
npm ERR! 404 'liferay-theme-es2015-hook' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.
npm ERR! Please include the following file with any support request:
npm ERR! /home/candini/liferay/progetti/inpeco/ga3/themes/ga3-theme/npm-debug.log
The es2015 hook hasn't yet been published to npm, but we will once a few things are finalized. In the meantime if you'd like to try it out to see if it fits your use case, you can install it by running
npm i --save robert-frampton/liferay-theme-es2015-hook
Once we have published the hook I'll let you know and close this issue.
Hey @caneta
We published the hook. Give it a shot and let me know if it suits your use case. We may still break it out into smaller pieces.
@caneta
I'm going to go ahead and close this issue, if there is anything wrong with the liferay-theme-es2015-hook please feel free to open a github issue on that repo. Thanks!
Ok @Robert-Frampton , no problem. Unfortunately not so much time to try this hook in these days. I'll keep you up to date.
Hi @Robert-Frampton, is there a way to run the liferay-module-config-generator before performing a deploy? I usually run
before a
gulp deploy
, but it would be great to have it included inside a task.