Skip to content

Commit

Permalink
NXP-29783: add rollup based build
Browse files Browse the repository at this point in the history
  • Loading branch information
nelsonsilva authored and Nuno Cunha committed Nov 5, 2020
1 parent a020639 commit 584ed7d
Show file tree
Hide file tree
Showing 15 changed files with 271 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ bin

# build artifacts
target/
node_modules/
nashorn_code_cache/
chromedriver.log
*.log
Expand Down
4 changes: 4 additions & 0 deletions nuxeo-coldstorage-package/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
<groupId>org.nuxeo</groupId>
<artifactId>nuxeo-coldstorage</artifactId>
</dependency>
<dependency>
<groupId>org.nuxeo</groupId>
<artifactId>nuxeo-coldstorage-web</artifactId>
</dependency>

<dependency>
<groupId>org.nuxeo.ecm.distribution</groupId>
Expand Down
1 change: 1 addition & 0 deletions nuxeo-coldstorage-web/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@nuxeo:registry=https://packages.nuxeo.com/repository/npm-public/
54 changes: 54 additions & 0 deletions nuxeo-coldstorage-web/build.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?xml version="1.0"?>
<!--
(C) Copyright Nuxeo Corp. (http://nuxeo.com/)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project name="Nuxeo Cold Storage Web" default="build" basedir=".">

<!-- set executable names based on OS family -->
<condition property="cmd.npm" value="npm.cmd" else="npm">
<os family="windows"/>
</condition>

<!-- set npm script names based on OS family -->
<condition property="lint.script" value="win-lint" else="lint">
<os family="windows"/>
</condition>

<target name="clean" description="Clean npm dependencies">
<delete dir="node_modules" />
</target>

<target name="install" description="Install npm dependencies" unless="skipInstall">
<exec executable="${cmd.npm}" failonerror="true">
<arg value="install" />
</exec>
</target>

<target name="build" depends="install" unless="skipBuild">
<npm-run script="build" />
</target>

<macrodef name="npm-run">
<attribute name="script"/>
<sequential>
<exec executable="${cmd.npm}" failonerror="true">
<env key="NODE_ENV" value="production"/>
<arg value="run" />
<arg value="@{script}" />
</exec>
</sequential>
</macrodef>

</project>
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/**
@license
(C) Copyright Nuxeo Corp. (http://nuxeo.com/)
Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/**
@license
(C) Copyright Nuxeo Corp. (http://nuxeo.com/)
Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
19 changes: 19 additions & 0 deletions nuxeo-coldstorage-web/i18n/messages-fr.json
Original file line number Diff line number Diff line change
@@ -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"
}
19 changes: 19 additions & 0 deletions nuxeo-coldstorage-web/i18n/messages.json
Original file line number Diff line number Diff line change
@@ -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"
}
6 changes: 1 addition & 5 deletions nuxeo-coldstorage-web/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
22 changes: 22 additions & 0 deletions nuxeo-coldstorage-web/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
44 changes: 44 additions & 0 deletions nuxeo-coldstorage-web/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.nuxeo</groupId>
<artifactId>nuxeo-coldstorage-parent</artifactId>
<version>11.0.0-SNAPSHOT</version>
</parent>
<artifactId>nuxeo-coldstorage-web</artifactId>
<name>Nuxeo Cold Storage WebUI integration</name>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>clean</id>
<phase>clean</phase>
<configuration>
<target>
<ant antfile="${basedir}/build.xml" dir="${basedir}" target="clean"></ant>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
<execution>
<id>npm-build</id>
<phase>process-resources</phase>
<configuration>
<target>
<ant antfile="${basedir}/build.xml" dir="${basedir}"></ant>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
64 changes: 64 additions & 0 deletions nuxeo-coldstorage-web/rollup.config.js
Original file line number Diff line number Diff line change
@@ -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()] : []),
],
};
8 changes: 8 additions & 0 deletions nuxeo-coldstorage-web/src/main/resources/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0"?>
<fragment version="1">

<require>org.nuxeo.web.ui</require>

<install>

<unzip from="${bundle.fileName}" to="/" prefix="web">
<include>web/nuxeo.war/**</include>
<exclude>web/nuxeo.war/ui/i18n/**</exclude>
</unzip>

<!-- create a temporary folder -->
<delete path="${bundle.fileName}.tmp" />
<mkdir path="${bundle.fileName}.tmp" />
<unzip from="${bundle.fileName}" to="${bundle.fileName}.tmp" />

<!-- append the translations -->
<append from="${bundle.fileName}.tmp/web/nuxeo.war/ui/i18n/messages.json"
to="nuxeo.war/ui/i18n/messages.json" />
<append from="${bundle.fileName}.tmp/web/nuxeo.war/ui/i18n/messages-fr.json"
to="nuxeo.war/ui/i18n/messages-fr.json" />

<delete path="${bundle.fileName}.tmp" />

</install>

</fragment>
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<modules>
<module>nuxeo-coldstorage</module>
<module>nuxeo-coldstorage-package</module>
<module>nuxeo-coldstorage-web</module>
</modules>

<dependencyManagement>
Expand All @@ -34,6 +35,11 @@
<version>${project.version}</version>
<type>zip</type>
</dependency>
<dependency>
<groupId>org.nuxeo</groupId>
<artifactId>nuxeo-coldstorage-web</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down

0 comments on commit 584ed7d

Please sign in to comment.