From 584ed7d469fb8f144212d3d52d449b01765aec10 Mon Sep 17 00:00:00 2001 From: Nelson Silva Date: Fri, 30 Oct 2020 14:59:42 +0000 Subject: [PATCH] NXP-29783: add rollup based build --- .gitignore | 1 + nuxeo-coldstorage-package/pom.xml | 4 ++ nuxeo-coldstorage-web/.npmrc | 1 + nuxeo-coldstorage-web/build.xml | 54 ++++++++++++++++ ...uxeo-move-content-to-coldstorage-button.js | 1 - ...xeo-move-contents-to-coldstorage-button.js | 1 - nuxeo-coldstorage-web/i18n/messages-fr.json | 19 ++++++ nuxeo-coldstorage-web/i18n/messages.json | 19 ++++++ nuxeo-coldstorage-web/index.js | 6 +- nuxeo-coldstorage-web/package.json | 22 +++++++ nuxeo-coldstorage-web/pom.xml | 44 +++++++++++++ nuxeo-coldstorage-web/rollup.config.js | 64 +++++++++++++++++++ .../src/main/resources/META-INF/MANIFEST.MF | 8 +++ .../OSGI-INF/deployment-fragment.xml | 28 ++++++++ pom.xml | 6 ++ 15 files changed, 271 insertions(+), 7 deletions(-) create mode 100644 nuxeo-coldstorage-web/.npmrc create mode 100644 nuxeo-coldstorage-web/build.xml create mode 100644 nuxeo-coldstorage-web/i18n/messages-fr.json create mode 100644 nuxeo-coldstorage-web/i18n/messages.json create mode 100644 nuxeo-coldstorage-web/package.json create mode 100644 nuxeo-coldstorage-web/pom.xml create mode 100644 nuxeo-coldstorage-web/rollup.config.js create mode 100644 nuxeo-coldstorage-web/src/main/resources/META-INF/MANIFEST.MF create mode 100644 nuxeo-coldstorage-web/src/main/resources/OSGI-INF/deployment-fragment.xml diff --git a/.gitignore b/.gitignore index 16f57b67..26d39683 100644 --- a/.gitignore +++ b/.gitignore @@ -27,6 +27,7 @@ bin # build artifacts target/ +node_modules/ nashorn_code_cache/ chromedriver.log *.log diff --git a/nuxeo-coldstorage-package/pom.xml b/nuxeo-coldstorage-package/pom.xml index 8bd5e1d2..d43169ba 100644 --- a/nuxeo-coldstorage-package/pom.xml +++ b/nuxeo-coldstorage-package/pom.xml @@ -16,6 +16,10 @@ org.nuxeo nuxeo-coldstorage + + org.nuxeo + nuxeo-coldstorage-web + org.nuxeo.ecm.distribution diff --git a/nuxeo-coldstorage-web/.npmrc b/nuxeo-coldstorage-web/.npmrc new file mode 100644 index 00000000..7517fe15 --- /dev/null +++ b/nuxeo-coldstorage-web/.npmrc @@ -0,0 +1 @@ +@nuxeo:registry=https://packages.nuxeo.com/repository/npm-public/ diff --git a/nuxeo-coldstorage-web/build.xml b/nuxeo-coldstorage-web/build.xml new file mode 100644 index 00000000..f4c18680 --- /dev/null +++ b/nuxeo-coldstorage-web/build.xml @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/nuxeo-coldstorage-web/elements/nuxeo-move-content-to-coldstorage-button.js b/nuxeo-coldstorage-web/elements/nuxeo-move-content-to-coldstorage-button.js index e71881d6..e096dbe1 100644 --- a/nuxeo-coldstorage-web/elements/nuxeo-move-content-to-coldstorage-button.js +++ b/nuxeo-coldstorage-web/elements/nuxeo-move-content-to-coldstorage-button.js @@ -1,5 +1,4 @@ /** -@license (C) Copyright Nuxeo Corp. (http://nuxeo.com/) Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/nuxeo-coldstorage-web/elements/nuxeo-move-contents-to-coldstorage-button.js b/nuxeo-coldstorage-web/elements/nuxeo-move-contents-to-coldstorage-button.js index 847c8dad..3514420e 100644 --- a/nuxeo-coldstorage-web/elements/nuxeo-move-contents-to-coldstorage-button.js +++ b/nuxeo-coldstorage-web/elements/nuxeo-move-contents-to-coldstorage-button.js @@ -1,5 +1,4 @@ /** -@license (C) Copyright Nuxeo Corp. (http://nuxeo.com/) Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/nuxeo-coldstorage-web/i18n/messages-fr.json b/nuxeo-coldstorage-web/i18n/messages-fr.json new file mode 100644 index 00000000..bc73fc0b --- /dev/null +++ b/nuxeo-coldstorage-web/i18n/messages-fr.json @@ -0,0 +1,19 @@ +{ + "documentContentView.moveToColdStorage.ask.confirmation": "Send the document content to cold storage?", + "documentContentView.moveToColdStorage.cancel": "Annuler", + "documentContentView.moveToColdStorage.confirm": "Confirmer", + "documentContentView.moveToColdStorage.error": "Error moving the document content to cold storage.", + "documentContentView.moveToColdStorage.label": "Send to cold storage", + "documentContentView.moveToColdStorage.ok": "Ok", + "documentContentView.moveToColdStorage.description": "This will result in increased file retrieval times and a low resolution preview.", + "documentContentView.moveToColdStorage.success": "Document content moved to cold storage successfully.", + "documentContentView.moveToColdStorage.tooltip": "Send to cold storage", + "documentPage.content.storedInColdStorage": "The master file is stored in cold storage.", + "moveDocumentsContentsToColdStorage.ask.confirmation": "Send the documents contents to cold storage?", + "moveDocumentsContentsToColdStorage.description": "This will result in increased file retrieval times and a low resolution preview.", + "moveDocumentsContentsToColdStorage.cancel": "Annuler", + "moveDocumentsContentsToColdStorage.confirm": "Confirmer", + "moveDocumentsContentsToColdStorage.error": "Error moving the documents contents to cold storage.", + "moveDocumentsContentsToColdStorage.success": "Documents contents moved to cold storage successfully.", + "moveDocumentsContentsToColdStorage.tooltip": "Send the selected items to cold storage" +} diff --git a/nuxeo-coldstorage-web/i18n/messages.json b/nuxeo-coldstorage-web/i18n/messages.json new file mode 100644 index 00000000..45957a6d --- /dev/null +++ b/nuxeo-coldstorage-web/i18n/messages.json @@ -0,0 +1,19 @@ +{ + "documentContentView.moveToColdStorage.ask.confirmation": "Send the document content to cold storage?", + "documentContentView.moveToColdStorage.cancel": "Cancel", + "documentContentView.moveToColdStorage.confirm": "Confirm", + "documentContentView.moveToColdStorage.error": "Error moving the document content to cold storage.", + "documentContentView.moveToColdStorage.label": "Send to cold storage", + "documentContentView.moveToColdStorage.ok": "OK", + "documentContentView.moveToColdStorage.description": "This will result in increased file retrieval times and a low resolution preview.", + "documentContentView.moveToColdStorage.success": "Document content moved to cold storage successfully.", + "documentContentView.moveToColdStorage.tooltip": "Send to cold storage", + "documentPage.content.storedInColdStorage": "The master file is stored in cold storage.", + "moveDocumentsContentsToColdStorage.ask.confirmation": "Send the documents contents to cold storage?", + "moveDocumentsContentsToColdStorage.description": "This will result in increased file retrieval times and a low resolution preview.", + "moveDocumentsContentsToColdStorage.cancel": "Cancel", + "moveDocumentsContentsToColdStorage.confirm": "Confirm", + "moveDocumentsContentsToColdStorage.error": "Error moving the documents contents to cold storage.", + "moveDocumentsContentsToColdStorage.success": "Documents contents moved to cold storage successfully.", + "moveDocumentsContentsToColdStorage.tooltip": "Send the selected items to cold storage" +} diff --git a/nuxeo-coldstorage-web/index.js b/nuxeo-coldstorage-web/index.js index c3efe2af..afa96996 100644 --- a/nuxeo-coldstorage-web/index.js +++ b/nuxeo-coldstorage-web/index.js @@ -17,8 +17,4 @@ limitations under the License. import './elements/nuxeo-move-content-to-coldstorage-button.js'; import './elements/nuxeo-move-contents-to-coldstorage-button.js'; -import html from './nuxeo-coldstorage.html'; - -const tmpl = document.createElement('template'); -tmpl.innerHTML = html; -document.head.appendChild(tmpl.content); +import './nuxeo-coldstorage.html'; diff --git a/nuxeo-coldstorage-web/package.json b/nuxeo-coldstorage-web/package.json new file mode 100644 index 00000000..42576475 --- /dev/null +++ b/nuxeo-coldstorage-web/package.json @@ -0,0 +1,22 @@ +{ + "name": "nuxeo-coldstorage-web", + "version": "0.1.0", + "description": "Nuxeo Cold Storage WebUI integration", + "scripts": { + "build": "rollup -c" + }, + "author": "Nuxeo", + "license": "Apache-2.0", + "devDependencies": { + "@rollup/plugin-node-resolve": "^7.1.3", + "rollup": "^2.33.1", + "rollup-plugin-copy": "^3.3.0", + "rollup-plugin-minify-html-literals": "^1.2.5", + "rollup-plugin-terser": "^7.0.2" + }, + "dependencies": { + "@nuxeo/nuxeo-elements": "~3.0.2-rc.0", + "@nuxeo/nuxeo-ui-elements": "~3.0.2-rc.0", + "@polymer/polymer": "3.3.1" + } +} diff --git a/nuxeo-coldstorage-web/pom.xml b/nuxeo-coldstorage-web/pom.xml new file mode 100644 index 00000000..ee28aabd --- /dev/null +++ b/nuxeo-coldstorage-web/pom.xml @@ -0,0 +1,44 @@ + + 4.0.0 + + org.nuxeo + nuxeo-coldstorage-parent + 11.0.0-SNAPSHOT + + nuxeo-coldstorage-web + Nuxeo Cold Storage WebUI integration + + + + org.apache.maven.plugins + maven-antrun-plugin + + + clean + clean + + + + + + + run + + + + npm-build + process-resources + + + + + + + run + + + + + + + diff --git a/nuxeo-coldstorage-web/rollup.config.js b/nuxeo-coldstorage-web/rollup.config.js new file mode 100644 index 00000000..6e3b682d --- /dev/null +++ b/nuxeo-coldstorage-web/rollup.config.js @@ -0,0 +1,64 @@ +import { terser } from 'rollup-plugin-terser'; +import copy from 'rollup-plugin-copy'; +import minifyHTML from 'rollup-plugin-minify-html-literals'; +import resolve from '@rollup/plugin-node-resolve'; +import path from 'path'; + +// Replace imports by an export of existing globals in Web UI +// https://github.com/nuxeo/nuxeo-web-ui/blob/master/index.js#L7 +const GLOBALS = { + '@polymer/polymer/lib/legacy/class.js': 'const { mixinBehaviors } = Polymer; export { mixinBehaviors };', + '@polymer/polymer/lib/legacy/polymer.dom.js': 'const { dom, matchesSelector } = Polymer; export { dom, matchesSelector };', + '@polymer/polymer/polymer-element.js': 'const { PolymerElement} = window; export { PolymerElement };', + '@polymer/polymer/lib/elements/dom-module.js': 'const { DomModule} = window; export { DomModule };', + '@polymer/polymer/lib/legacy/polymer.dom.js': 'const { dom, html, matchesSelector } = Polymer; export { dom, html, atchesSelector };', + '@polymer/polymer/lib/utils/html-tag.js': 'const { html } = Polymer; export { html };', + '@polymer/polymer/lib/utils/debounce.js': 'const { enqueueDebouncer, flushDebouncers, Debouncer } = Polymer; export { enqueueDebouncer, flushDebouncers, Debouncer };', + '@nuxeo/nuxeo-ui-elements/nuxeo-i18n-behavior.js': 'const { I18nBehavior } = Nuxeo; export { I18nBehavior };', + '@nuxeo/nuxeo-ui-elements/nuxeo-filters-behavior.js': 'const { FiltersBehavior } = Nuxeo; export { FiltersBehavior };', + '@nuxeo/nuxeo-ui-elements/nuxeo-format-behavior.js': 'const { FormatBehavior } = Nuxeo; export { FormatBehavior };', +} + +// Ignore these imports since they should just be all about custom element definitions which are done already by Web UI +const IGNORES = [ /^\@(nuxeo|polymer)\//]; + +const TARGET = 'target/classes/web/nuxeo.war/ui'; + +export default { + input: "index.js", + output: { + file: `${TARGET}/nuxeo-coldstorage.bundle.js`, + format: "es", + }, + plugins: [ + copy({ + targets: [{ src: "i18n", dest: TARGET }], + }), + resolve(), + { + transform(code, id) { + // HTML imports + if (path.extname(id) === ".html") { + return `const tmpl = document.createElement('template');tmpl.innerHTML = ${JSON.stringify( + code + )};document.head.appendChild(tmpl.content);`; + } + + const dep = path.relative("./node_modules", id); + + // Rewrite imports + if (GLOBALS[dep]) { + return GLOBALS[dep]; + } + + // Ignore bundled imports + if (IGNORES.some((r) => r.test(dep))) { + return "export default undefined;"; + } + + return code; + }, + }, + ...(process.env.NODE_ENV === "production" ? [minifyHTML(), terser()] : []), + ], +}; \ No newline at end of file diff --git a/nuxeo-coldstorage-web/src/main/resources/META-INF/MANIFEST.MF b/nuxeo-coldstorage-web/src/main/resources/META-INF/MANIFEST.MF new file mode 100644 index 00000000..c89f7afa --- /dev/null +++ b/nuxeo-coldstorage-web/src/main/resources/META-INF/MANIFEST.MF @@ -0,0 +1,8 @@ +Bundle-ActivationPolicy: lazy +Bundle-ClassPath: . +Manifest-Version: 1.0 +Bundle-Vendor: Nuxeo +Bundle-Version: 1.0.0 +Bundle-Name: nuxeo-coldstorage-web +Bundle-ManifestVersion: 2 +Bundle-SymbolicName: nuxeo-coldstorage-web;singleton=true diff --git a/nuxeo-coldstorage-web/src/main/resources/OSGI-INF/deployment-fragment.xml b/nuxeo-coldstorage-web/src/main/resources/OSGI-INF/deployment-fragment.xml new file mode 100644 index 00000000..f5467486 --- /dev/null +++ b/nuxeo-coldstorage-web/src/main/resources/OSGI-INF/deployment-fragment.xml @@ -0,0 +1,28 @@ + + + + org.nuxeo.web.ui + + + + + web/nuxeo.war/** + web/nuxeo.war/ui/i18n/** + + + + + + + + + + + + + + + + diff --git a/pom.xml b/pom.xml index c518dbbc..12bcb3b4 100644 --- a/pom.xml +++ b/pom.xml @@ -19,6 +19,7 @@ nuxeo-coldstorage nuxeo-coldstorage-package + nuxeo-coldstorage-web @@ -34,6 +35,11 @@ ${project.version} zip + + org.nuxeo + nuxeo-coldstorage-web + ${project.version} +