From 7cf5442e0e66ec6120544be7ee94b7afedfef069 Mon Sep 17 00:00:00 2001 From: Raruto Date: Thu, 15 Feb 2024 15:27:25 +0100 Subject: [PATCH 1/4] Hide branch name on for stable versions --- gulpfile.js | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index cdec1c420..dcaab6f2d 100755 --- a/gulpfile.js +++ b/gulpfile.js @@ -64,7 +64,7 @@ function setNODE_ENV() { outputFolder = production ? g3w.admin_plugins_folder + '/client' : g3w.admin_overrides_folder; console.log('[G3W-CLIENT] environment:', process.env.NODE_ENV); console.log('[G3W-CLIENT] output folder:', outputFolder); - console.log(`[G3W-CLIENT] loaded plugins: {\n ${Object.entries(loaded_plugins).map(([pluginName, p]) => (GREEN__ + pluginName + __RESET + ': '+ p.version())).join('\n ')}\n}\n`); + console.log(`[G3W-CLIENT] loaded plugins: {\n ${dev_plugins.map(pluginName => (GREEN__ + pluginName + __RESET + ': '+ get_version(pluginName))).join('\n ')}\n}\n`); } // Retrieve project dependencies ("g3w-client") @@ -83,12 +83,6 @@ const dev_plugins = Array.from( new Set(default_plugins.concat(g3w.plugins instanceof Array ? plugins : Object.keys(g3w.plugins))) ); -// Helper info about locally developed client plugins (Object) -const loaded_plugins = Object.fromEntries(dev_plugins.map(pluginName => { return [pluginName, { version: get_version.bind(null, pluginName), hash: get_hash.bind(null, pluginName), branch: get_branch.bind(null, pluginName) }]})); - -// List all plugins within the `g3w.pluginsFolder` -const local_plugins = fs.readdirSync(g3w.pluginsFolder).filter(file => file !== 'client' && file.indexOf('_templates') === -1 && fs.statSync(`${g3w.pluginsFolder}/${file}`).isDirectory() && fs.statSync(`${g3w.pluginsFolder}/${file}/plugin.js`).isFile()); - /** * @param { string } pluginName * @@ -154,7 +148,18 @@ function set_version(pluginName) { data.splice(0, 1, pluginName ? `# g3w-client-plugin-${pluginName} v${version}` : `# G3W-CLIENT v${version}`); fs.writeFile(`${src}/README.md`, data.join("\n"), 'utf8', (err) => { if (err) return console.log(err); }); }); -}; +} + +/** + * @param { string } branchName + * + * @returns { boolean } whether is a stable branch (eg. v3.9.x) + * + * @since 3.10.0 + */ +function is_prod_branch(branchName) { + return production || ['dev', 'main', 'master'].includes(branchName) || /^v\d+\.\d+\.x$/.test(branchName); +} setNODE_ENV(); @@ -196,9 +201,9 @@ const browserify_plugin = (pluginName, watch = true) => { del([`${src}/plugin.js.map`]); const rebundle = () => { - const version = loaded_plugins[pluginName].version(); - const hash = loaded_plugins[pluginName].hash(); - const branch = loaded_plugins[pluginName].branch(); + const version = get_version(pluginName); + const hash = get_hash(pluginName); + const branch = get_branch(pluginName); return merge( gulp @@ -212,7 +217,7 @@ const browserify_plugin = (pluginName, watch = true) => { ) .pipe(concat('plugin.js')) .pipe(replace('process.env.g3w_plugin_name', `"${pluginName}"`)) - .pipe(replace('process.env.g3w_plugin_version', `"${production ? version : version.split('-')[0] + '-' + branch }"`)) + .pipe(replace('process.env.g3w_plugin_version', `"${is_prod_branch(branch) ? version : version.split('-')[0] + '-' + branch }"`)) .pipe(replace('process.env.g3w_plugin_hash', `"${hash}"`)) .pipe(replace('process.env.g3w_plugin_branch', `"${branch}"`)) .pipe(gulpif(production, sourcemaps.init())) @@ -355,7 +360,11 @@ gulp.task('browserify:app', function() { .on('update', () => !production && rebundle()) .on('log', (info) => !production && gutil.log(GREEN__ + '[client]' + __RESET + ' → ', info)); - const rebundle = () => bundler.bundle() + const rebundle = () => { + const version = get_version(); + const branch = get_branch(); + + return bundler.bundle() .on('error', err => { console.log('ERROR: running gulp task "browserify:app"', err); this.emit('end'); @@ -366,7 +375,7 @@ gulp.task('browserify:app', function() { // ]).then(() => process.exit()); }) .pipe(source('build.js')) - .pipe(replace('process.env.g3w_client_rev', `"${ production ? get_version() : get_version().split('-')[0] + '-' + get_branch() }"`)) + .pipe(replace('process.env.g3w_client_rev', `"${ is_prod_branch(branch) ? version : version.split('-')[0] + '-' + branch }"`)) .pipe(buffer()) .pipe(gulpif(production, sourcemaps.init())) .pipe(gulpif(production, uglify({ compress: { drop_console: true } }).on('error', gutil.log))) @@ -374,6 +383,7 @@ gulp.task('browserify:app', function() { .pipe(gulpif(production, sourcemaps.write('.'))) .pipe(gulp.dest(outputFolder + '/static/client/js/')) .pipe(gulpif(!production, browserSync.reload({ stream: true }))); // refresh browser after changing local files (dev mode) + }; return rebundle(); }); @@ -653,7 +663,7 @@ gulp.task('test', function() { */ gulp.task('version', function() { set_version(); // client - Object.entries(loaded_plugins).forEach(([pluginName]) => set_version(pluginName)); // plugins + dev_plugins.forEach(pluginName => set_version(pluginName)); // plugins }); /** From 3d23331643e097182db135aed099fdbfb11a25fb Mon Sep 17 00:00:00 2001 From: volterra79 Date: Mon, 19 Feb 2024 17:29:00 +0100 Subject: [PATCH 2/4] Clean code --- src/app/core/plugin/pluginservice.js | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/app/core/plugin/pluginservice.js b/src/app/core/plugin/pluginservice.js index d450dd68e..4ef1b5f34 100644 --- a/src/app/core/plugin/pluginservice.js +++ b/src/app/core/plugin/pluginservice.js @@ -1,8 +1,8 @@ -import ApplicationState from 'store/application-state'; +import ApplicationState from 'store/application-state'; import ApplicationService from 'services/application'; const { base, inherit } = require('utils'); -const G3WObject = require('core/g3wobject'); +const G3WObject = require('core/g3wobject'); function PluginService(options={}) { base(this, options); @@ -16,8 +16,7 @@ function PluginService(options={}) { this.currentLayout = ApplicationService.getCurrentLayoutName(); this.vm = new Vue(); this.unwatch = this.vm.$watch(()=> ApplicationState.gui.layout.__current, - currentLayoutName => this.currentLayout = currentLayoutName !== this.getPlugin().getName() ? currentLayoutName : this.currentLayout); - + currentLayoutName => this.currentLayout = currentLayoutName !== this.getPlugin().getName() ? currentLayoutName : this.currentLayout); } inherit(PluginService, G3WObject); @@ -32,21 +31,21 @@ proto.init = function(config={}) { this.config = config; }; -proto.setCurrentLayout = function(){ +proto.setCurrentLayout = function() { ApplicationService.setCurrentLayout(this.getPlugin().getName()); }; -proto.resetCurrentLayout = function(){ +proto.resetCurrentLayout = function() { ApplicationService.setCurrentLayout(this.currentLayout); }; // set owner plugin of the service -proto.setPlugin = function(plugin){ +proto.setPlugin = function(plugin) { this.plugin = plugin; }; // return the instance of the plugin owner of the service -proto.getPlugin = function(){ +proto.getPlugin = function() { return this.plugin; }; @@ -57,12 +56,12 @@ proto.isIframe = function() { /** * Get Current Project */ -proto.getCurrentProject = function(){ +proto.getCurrentProject = function() { return ApplicationService.getCurrentProject(); }; -proto.getGid = function(){ - const {gid} = this.config; +proto.getGid = function() { + const { gid } = this.config; return gid && gid.split(':')[1]; }; @@ -135,12 +134,12 @@ proto.clearAllEvents = function() { }; // to owerwrite if we need some condition to load or not the plugin -proto.loadPlugin = function(){ +proto.loadPlugin = function() { return true }; //Called when plugin is removed to clear events and memory -proto.clear = function(){ +proto.clear = function() { // to overwrite }; From 5c4ea925e1c578ccaa886f2cd349c74cf2b7bda6 Mon Sep 17 00:00:00 2001 From: volterra79 Date: Mon, 19 Feb 2024 17:29:32 +0100 Subject: [PATCH 3/4] Clean code --- src/plugins/_version.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/plugins/_version.js b/src/plugins/_version.js index a0c0dfa69..88d42eb3f 100644 --- a/src/plugins/_version.js +++ b/src/plugins/_version.js @@ -1,10 +1,13 @@ /** START: g3w-client/src/plugins/_version.js */ (function() { const plugins = window && window.initConfig && window.initConfig.group && window.initConfig.group.plugins; - if (plugins) plugins[process.env.g3w_plugin_name] = Object.assign(plugins[process.env.g3w_plugin_name] || {}, { - version: process.env.g3w_plugin_version, - hash: process.env.g3w_plugin_hash, - branch: process.env.g3w_plugin_branch, - }); + if (plugins) { + plugins[process.env.g3w_plugin_name] = Object.assign(plugins[process.env.g3w_plugin_name] || {}, + { + version : process.env.g3w_plugin_version, + hash : process.env.g3w_plugin_hash, + branch : process.env.g3w_plugin_branch, + }); + } })(); /** END: g3w-client/src/plugins/_version.js */ \ No newline at end of file From cc16879fa525e12cc6965a6348435ea71a588982 Mon Sep 17 00:00:00 2001 From: volterra79 Date: Mon, 19 Feb 2024 17:29:54 +0100 Subject: [PATCH 4/4] Clean code --- src/store/plugins.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/store/plugins.js b/src/store/plugins.js index d2d94537b..677c8381b 100644 --- a/src/store/plugins.js +++ b/src/store/plugins.js @@ -3,11 +3,11 @@ * @since v3.6 */ -import ProjectsRegistry from 'store/projects'; +import ProjectsRegistry from 'store/projects'; import ApplicationService from 'services/application'; const { base, inherit } = require('utils'); -const G3WObject = require('core/g3wobject'); +const G3WObject = require('core/g3wobject'); /** * 'law' project configuration on project is handle as plugin