From 28d898da9fb7692740abe20cd61dba0a31fa9f61 Mon Sep 17 00:00:00 2001 From: devezhao Date: Sun, 6 Dec 2020 17:46:19 +0800 Subject: [PATCH] @rbv js/css compile --- .deploy/gulpfile.js | 125 +++++++----------- .../core/service/trigger/ActionFactory.java | 41 ++++-- .../core/service/trigger/ActionType.java | 2 +- 3 files changed, 79 insertions(+), 89 deletions(-) diff --git a/.deploy/gulpfile.js b/.deploy/gulpfile.js index 7981d26cc..2b5fb1c95 100644 --- a/.deploy/gulpfile.js +++ b/.deploy/gulpfile.js @@ -1,9 +1,11 @@ -const { - src, - dest, - series, - parallel -} = require('gulp') +/* +Copyright (c) REBUILD and/or its owners. All rights reserved. + +rebuild is dual-licensed under commercial and open source licenses (GPLv3). +See LICENSE and COMMERCIAL in the project root for license information. +*/ + +const { src, dest, series, parallel } = require('gulp') const babel = require('gulp-babel') const babelCore = require('@babel/core') const cleanCSS = require('gulp-clean-css') @@ -18,49 +20,42 @@ const filter = require('gulp-filter') const BABEL_OPTIONS = { presets: ['@babel/preset-env', '@babel/preset-react'], plugins: ['@babel/plugin-proposal-class-properties'], - minified: true + minified: true, } const WEB_ROOT = '../src/main/resources/web' +const RBV_ROOT = '../@rbv/main/resources/web' const OUT_ROOT = '../target/classes/web' -function compileJs(cb) { - return src(`${WEB_ROOT}/assets/js/**/*.js`) - .pipe( - babel(BABEL_OPTIONS) - ) +function compileJs(m) { + return src(`${m || WEB_ROOT}/assets/js/**/*.js`) + .pipe(babel(BABEL_OPTIONS)) .pipe( debug({ - title: 'Compiled : ' + title: 'Compiled : ', }) ) - .pipe( - dest(`${OUT_ROOT}/assets/js`) - ) + .pipe(dest(`${OUT_ROOT}/assets/js`)) } -function compileCss(cb) { - return src(`${WEB_ROOT}/assets/css/**/*.css`) - .pipe( - cleanCSS() - ) +function compileCss(m) { + return src(`${m || WEB_ROOT}/assets/css/**/*.css`) + .pipe(cleanCSS()) .pipe( debug({ - title: 'Compiled : ' + title: 'Compiled : ', }) ) - .pipe( - dest(`${OUT_ROOT}/assets/css`) - ) + .pipe(dest(`${OUT_ROOT}/assets/css`)) } const _assetsHexCached = {} -function _assetsHex(file) { +function _assetsHex(file, m) { let hex = _assetsHexCached[file] if (!hex) { try { - hex = revHash(fs.readFileSync(`${WEB_ROOT}${file}`)) + hex = revHash(fs.readFileSync(`${WEB_ROOT || m}${file}`)) } catch (err) { console.log('Cannot #revHash : ' + file, err) // Use date @@ -72,68 +67,62 @@ function _assetsHex(file) { return hex } -function compileHtml(cb) { - return src(`${WEB_ROOT}/**/*.html`) - .pipe(filter(file => !/node_modules/.test(file.path))) +function compileHtml(m) { + return src(`${WEB_ROOT || m}/**/*.html`) + .pipe(filter((file) => !/node_modules/.test(file.path))) .pipe( - replace(/' + const jsmin = babelCore.transformSync(p, BABEL_OPTIONS).code + return '' }) ) + .pipe(replace(/ type="text\/babel"/gi, '')) .pipe( - replace(/ type="text\/babel"/ig, '') - ) - .pipe( - replace(/' } else { - file += '?v=' + _assetsHex(file.split('?')[0]) + file += '?v=' + _assetsHex(file.split('?')[0], m) return '' } }) ) .pipe( - replace(/' + const cssmin = new cleanCSS2({}).minify(p).styles + return '' }) ) .pipe( - replace(//ig, (m, p) => { + replace(//gi, (m, p) => { let file = p if (file.includes('/lib/')) { return '' } else { - file += '?v=' + _assetsHex(file.split('?')[0]) + file += '?v=' + _assetsHex(file.split('?')[0], m) return '' } }) ) .pipe( debug({ - title: 'Compiled : ' + title: 'Compiled : ', }) ) - .pipe( - dest(OUT_ROOT) - ) + .pipe(dest(OUT_ROOT)) } function maven(cb) { const pomfile = `${__dirname}/../pom.xml` console.log('Using pom.xml : ' + pomfile) - const mvn = require('child_process').spawnSync( - process.platform === 'win32' ? 'mvn.cmd' : 'mvn', - ['clean', 'package', '-f', pomfile], { - stdio: 'inherit' + const mvn = require('child_process').spawnSync(process.platform === 'win32' ? 'mvn.cmd' : 'mvn', ['clean', 'package', '-f', pomfile], { + stdio: 'inherit', }) if (mvn.status !== 0) { @@ -143,29 +132,15 @@ function maven(cb) { cb() } -// const RELEASE_HOME = 'D:/GitHub/for-production/rebuild-standalone/REBUILD' +exports.default = series( + parallel( + () => compileJs(WEB_ROOT), + () => compileCss(WEB_ROOT), + () => compileJs(RBV_ROOT), + () => compileCss(RBV_ROOT) + ), + () => compileHtml(WEB_ROOT), + () => compileHtml(RBV_ROOT) +) -// function release(cb) { -// return src('../target/rebuild/**') -// .pipe( -// filter((file) => { -// const m = /\.jsx/.test(file.path) || /\.development\./.test(file.path) || /babel\./.test(file.path) || -// /rebel\.xml/.test(file.path) -// m && console.log('Filtered : ' + file.path) -// return !m -// }) -// ) -// .pipe( -// dest(RELEASE_HOME) -// ) -// .on('end', () => { -// src('build/**') -// .pipe( -// dest(RELEASE_HOME) -// ) -// }) -// } - -exports.default = series(parallel(compileJs, compileCss), compileHtml) exports.mvn = maven -// exports.p = series(maven, parallel(compileJs, compileCss), compileHtml, release) \ No newline at end of file diff --git a/src/main/java/com/rebuild/core/service/trigger/ActionFactory.java b/src/main/java/com/rebuild/core/service/trigger/ActionFactory.java index 4e59741fe..2ed40acb2 100644 --- a/src/main/java/com/rebuild/core/service/trigger/ActionFactory.java +++ b/src/main/java/com/rebuild/core/service/trigger/ActionFactory.java @@ -17,17 +17,6 @@ import lombok.extern.slf4j.Slf4j; @Slf4j public class ActionFactory { - private static final TriggerAction NORBV_FOUND = new TriggerAction() { - @Override - public ActionType getType() { - throw new UnsupportedOperationException(); - } - @Override - public void execute(OperatingContext operatingContext) throws TriggerException { - throw new UnsupportedOperationException(); - } - }; - /** * @return */ @@ -49,16 +38,42 @@ public class ActionFactory { * @return */ public static TriggerAction createAction(String type, ActionContext context) { + ActionType actionType = null; try { - return ActionType.valueOf(type).newInstance(context); + actionType = ActionType.valueOf(type); + return actionType.newInstance(context); } catch (ClassNotFoundException rbv) { + if (rbv.getLocalizedMessage().contains(".rbv.")) { - return NORBV_FOUND; + return new NoRbv(actionType); } else { throw new TriggerException("Unknown trigger type : " + type, rbv); } + } catch (ReflectiveOperationException ex) { throw new TriggerException("Unknown trigger type : " + type, ex); } } + + /** + * RBV 功能 + */ + private static class NoRbv implements TriggerAction { + + private ActionType actionType; + NoRbv(ActionType actionType) { + this.actionType = actionType; + } + + @Override + public ActionType getType() { + if (actionType == null) throw new UnsupportedOperationException(); + else return actionType; + } + + @Override + public void execute(OperatingContext operatingContext) throws TriggerException { + log.warn("Unsupportted @rbv feature"); + } + } } diff --git a/src/main/java/com/rebuild/core/service/trigger/ActionType.java b/src/main/java/com/rebuild/core/service/trigger/ActionType.java index d4762d8d4..18c759a29 100644 --- a/src/main/java/com/rebuild/core/service/trigger/ActionType.java +++ b/src/main/java/com/rebuild/core/service/trigger/ActionType.java @@ -64,7 +64,7 @@ public enum ActionType { * @return * @throws ReflectiveOperationException */ - public TriggerAction newInstance(ActionContext context) throws ReflectiveOperationException { + protected TriggerAction newInstance(ActionContext context) throws ReflectiveOperationException { Class clazz = ClassUtils.getClass(getActionClass()); Constructor c = ReflectionUtils.accessibleConstructor(clazz, ActionContext.class); return (TriggerAction) c.newInstance(context);