Skip to content
Snippets Groups Projects
Commit 9625dbe6 authored by Bekerle, Patrizio's avatar Bekerle, Patrizio :fire:
Browse files

Add demo app scaffold

parent e8779491
No related branches found
No related tags found
No related merge requests found
Pipeline #12607 passed
node_modules node_modules
\ No newline at end of file demo/dist
.idea
\ No newline at end of file
# Frontend Toolkit Demo
## Setup
```bash
yarn install
```
## Local development
```bash
yarn run watch-local
```
You can then open <http://127.0.0.1:8085/>.
{
"name": "toolkit-demo",
"version": "1.0.0",
"main": "src/toolkit-demo.js",
"license": "LGPL-2.1-or-later",
"private": true,
"workspaces": [
"../packages/*"
],
"devDependencies": {
"@babel/core": "^7.10.3",
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
"@babel/plugin-syntax-import-meta": "^7.10.1",
"@babel/plugin-transform-runtime": "^7.10.3",
"@babel/preset-env": "^7.10.3",
"@babel/runtime-corejs3": "^7.10.3",
"@rollup/plugin-babel": "^5.0.4",
"@rollup/plugin-commonjs": "^14.0.0",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^8.1.0",
"@rollup/plugin-replace": "^2.3.3",
"@rollup/plugin-url": "^5.0.1",
"babel-eslint": "^10.0.3",
"chai": "^4.2.0",
"chokidar": "^3.4.0",
"eslint": "^7.3.1",
"eslint-plugin-jsdoc": "^29.2.0",
"glob": "^7.1.6",
"i18next-scanner": "^2.10.3",
"karma": "^5.1.0",
"karma-chai": "^0.1.0",
"karma-chrome-launcher": "^3.1.0",
"karma-firefox-launcher": "^1.3.0",
"karma-mocha": "^2.0.1",
"mocha": "^8.0.1",
"puppeteer": "^2.0.0",
"rollup": "^2.18.1",
"rollup-plugin-consts": "^1.0.2",
"rollup-plugin-copy": "^3.3.0",
"rollup-plugin-delete": "^2.0.0",
"rollup-plugin-emit-ejs": "^3.1.0",
"rollup-plugin-license": "^2.1.0",
"rollup-plugin-serve": "^1.0.1",
"rollup-plugin-terser": "^6.1.0",
"selfsigned": "^1.10.7"
},
"dependencies": {
"@open-wc/scoped-elements": "^1.1.1",
"dbp-app-shell": "^1.0.0",
"dbp-auth": "^1.0.0",
"dbp-common": "^1.0.0",
"dbp-file-handling": "^1.0.0",
"dbp-language-select": "^1.0.0",
"dbp-notification": "^1.0.0",
"dbp-person-profile": "^1.0.0",
"fabric": "^3.6.3",
"file-saver": "^2.0.2",
"i18next": "^19.5.1",
"jszip": "^3.5.0",
"lit-element": "^2.3.1",
"lit-html": "^1.2.1",
"pdfjs-dist": "^2.4.456",
"source-sans-pro": "^2.45.0",
"tabulator-tables": "^4.7.0",
"universal-router": "^9.0.1",
"webdav": "^3.3.0"
},
"scripts": {
"build-dev": "rollup -c --environment BUILD:development",
"build-prod": "rollup -c --environment BUILD:production",
"build-demo": "rollup -c --environment BUILD:demo",
"i18next": "i18next-scanner",
"watch": "rollup -c --watch",
"watch-local": "yarn run watch",
"watch-full": "rollup -c --watch --environment FORCE_FULL",
"test": "rollup -c --environment BUILD:test && karma start --singleRun",
"test-full": "rollup -c --environment FORCE_FULL,BUILD:test && karma start --singleRun",
"lint": "eslint ."
}
}
import path from 'path';
import fs from 'fs';
import url from 'url';
import glob from 'glob';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import copy from 'rollup-plugin-copy';
import {terser} from "rollup-plugin-terser";
import json from '@rollup/plugin-json';
import replace from "@rollup/plugin-replace";
import serve from 'rollup-plugin-serve';
import urlPlugin from "@rollup/plugin-url";
import consts from 'rollup-plugin-consts';
import license from 'rollup-plugin-license';
import del from 'rollup-plugin-delete';
import emitEJS from 'rollup-plugin-emit-ejs'
import babel from '@rollup/plugin-babel'
import selfsigned from 'selfsigned';
// -------------------------------
// Some new web APIs are only available when HTTPS is active.
// Note that this only works with a Non-HTTPS API endpoint with Chrome,
// Firefox will emit CORS errors, see https://bugzilla.mozilla.org/show_bug.cgi?id=1488740
const USE_HTTPS = false;
// -------------------------------
const pkg = require('./package.json');
const build = (typeof process.env.BUILD !== 'undefined') ? process.env.BUILD : 'local';
const watch = process.env.ROLLUP_WATCH === 'true';
const buildFull = (!watch && build !== 'test') || (process.env.FORCE_FULL !== undefined);
console.log("build: " + build);
let basePath = '';
let entryPointURL = '';
let nextcloudBaseURL = 'https://cloud.tugraz.at';
let nextcloudWebAppPasswordURL = nextcloudBaseURL + '/apps/webapppassword';
let nextcloudWebDavURL = nextcloudBaseURL + '/remote.php/dav/files';
let nextcloudName = 'TU Graz cloud';
let keyCloakServer = '';
let keyCloakBaseURL = '';
let keyCloakClientId = '';
let pdfAsQualifiedlySigningServer = '';
let matomoSiteId = 131;
let useTerser = buildFull;
let useBabel = buildFull;
let checkLicenses = buildFull;
switch (build) {
case 'local':
basePath = '/dist/';
entryPointURL = 'http://127.0.0.1:8000';
nextcloudBaseURL = 'http://localhost:8081';
nextcloudWebAppPasswordURL = nextcloudBaseURL + '/index.php/apps/webapppassword';
nextcloudWebDavURL = nextcloudBaseURL + '/remote.php/dav/files';
keyCloakServer = 'auth-dev.tugraz.at';
keyCloakBaseURL = 'https://' + keyCloakServer + '/auth';
keyCloakClientId = 'auth-dev-mw-frontend-local';
pdfAsQualifiedlySigningServer = 'sig-dev.tugraz.at';
break;
case 'development':
basePath = '/apps/toolkit-demo/';
entryPointURL = 'https://mw-dev.tugraz.at';
// "/pers" can't go here because it's not allowed in the "Content-Security-Policy"
nextcloudBaseURL = 'https://nc-dev.tugraz.at';
// "/index.php" is needed to don't get a "This origin is not allowed!" because the "target-origin" get parameter can't be read
nextcloudWebAppPasswordURL = nextcloudBaseURL + '/pers/index.php/apps/webapppassword';
nextcloudWebDavURL = nextcloudBaseURL + '/pers/remote.php/dav/files';
keyCloakServer = 'auth-dev.tugraz.at';
keyCloakBaseURL = 'https://' + keyCloakServer + '/auth';
keyCloakClientId = 'auth-dev-mw-frontend';
pdfAsQualifiedlySigningServer = 'sig-dev.tugraz.at';
break;
default:
console.error('Unknown build environment: ' + build);
process.exit(1);
}
let nextcloudFileURL = nextcloudBaseURL + '/apps/files/?dir=';
/**
* Creates a server certificate and caches it in the .cert directory
*/
function generateTLSConfig() {
fs.mkdirSync('.cert', {recursive: true});
if (!fs.existsSync('.cert/server.key') || !fs.existsSync('.cert/server.cert')) {
const attrs = [{name: 'commonName', value: 'dbp-dev.localhost'}];
const pems = selfsigned.generate(attrs, {algorithm: 'sha256', days: 9999});
fs.writeFileSync('.cert/server.key', pems.private);
fs.writeFileSync('.cert/server.cert', pems.cert);
}
return {
key: fs.readFileSync('.cert/server.key'),
cert: fs.readFileSync('.cert/server.cert')
}
}
function getBuildInfo() {
const child_process = require('child_process');
const url = require('url');
let remote = child_process.execSync('git config --get remote.origin.url').toString().trim();
let commit = child_process.execSync('git rev-parse --short HEAD').toString().trim();
let parsed = url.parse(remote);
// convert git urls
if (parsed.protocol === null) {
parsed = url.parse('git://' + remote.replace(":", "/"));
parsed.protocol = 'https:';
}
let newPath = parsed.path.slice(0, parsed.path.lastIndexOf('.'));
let newUrl = parsed.protocol + '//' + parsed.host + newPath + '/commit/' + commit;
return {
info: commit,
url: newUrl,
time: new Date().toISOString(),
env: build
}
}
export default {
input: (build != 'test') ? [
'src/' + pkg.name + '.js',
] : glob.sync('test/**/*.js'),
output: {
dir: 'dist',
entryFileNames: '[name].js',
chunkFileNames: 'shared/[name].[hash].[format].js',
format: 'esm',
sourcemap: true
},
preserveEntrySignatures: false,
// external: ['zlib', 'http', 'fs', 'https', 'url'],
onwarn: function (warning, warn) {
// ignore "suggestions" warning re "use strict"
if (warning.code === 'MODULE_LEVEL_DIRECTIVE') {
return;
}
// ignore chai warnings
if (warning.code === 'CIRCULAR_DEPENDENCY') {
return;
}
// keycloak bundled code uses eval
if (warning.code === 'EVAL') {
return;
}
warn(warning);
},
watch: {
chokidar: {
usePolling: true
}
},
plugins: [
del({
targets: 'dist/*'
}),
consts({
environment: build,
buildinfo: getBuildInfo(),
nextcloudWebAppPasswordURL: nextcloudWebAppPasswordURL,
nextcloudWebDavURL: nextcloudWebDavURL,
nextcloudBaseURL: nextcloudBaseURL,
nextcloudFileURL: nextcloudFileURL,
nextcloudName: nextcloudName,
}),
emitEJS({
src: 'assets',
include: ['**/*.ejs', '**/.*.ejs'],
data: {
getUrl: (p) => {
return url.resolve(basePath, p);
},
getPrivateUrl: (p) => {
return url.resolve(`${basePath}local/${pkg.name}/`, p);
},
name: pkg.name,
entryPointURL: entryPointURL,
nextcloudBaseURL: nextcloudBaseURL,
keyCloakServer: keyCloakServer,
keyCloakBaseURL: keyCloakBaseURL,
keyCloakClientId: keyCloakClientId,
pdfAsQualifiedlySigningServer: pdfAsQualifiedlySigningServer,
environment: build,
matomoSiteId: matomoSiteId,
buildInfo: getBuildInfo()
}
}),
resolve({
customResolveOptions: {
// ignore node_modules from vendored packages
moduleDirectory: path.join(process.cwd(), 'node_modules')
},
browser: true,
preferBuiltins: true
}),
checkLicenses && license({
banner: {
commentStyle: 'ignored',
content: `
License: <%= pkg.license %>
Dependencies:
<% _.forEach(dependencies, function (dependency) { if (dependency.name) { %>
<%= dependency.name %>: <%= dependency.license %><% }}) %>
`},
thirdParty: {
allow: {
test: '(MIT OR BSD-3-Clause OR Apache-2.0 OR LGPL-2.1-or-later)',
failOnUnlicensed: true,
failOnViolation: true,
},
},
}),
commonjs({
include: 'node_modules/**',
}),
json(),
urlPlugin({
limit: 0,
include: [
"node_modules/suggestions/**/*.css",
"node_modules/select2/**/*.css",
],
emitFiles: true,
fileName: 'shared/[name].[hash][extname]'
}),
replace({
"process.env.BUILD": '"' + build + '"',
}),
useTerser ? terser() : false,
copy({
targets: [
{src: 'assets/silent-check-sso.html', dest:'dist'},
{src: 'assets/htaccess-shared', dest: 'dist/shared/', rename: '.htaccess'},
{src: 'assets/*.css', dest: 'dist/local/' + pkg.name},
{src: 'assets/*.ico', dest: 'dist/local/' + pkg.name},
{src: 'assets/*.svg', dest: 'dist/local/' + pkg.name},
{
src: 'node_modules/pdfjs-dist/build/pdf.worker.min.js',
dest: 'dist/local/' + pkg.name + '/pdfjs',
// enable signatures in pdf preview
transform: (contents) => contents.toString().replace('if("Sig"===a.fieldType){a.fieldValue=null;this.setFlags(r.AnnotationFlag.HIDDEN)}', '')
},
{src: 'node_modules/pdfjs-dist/cmaps/*', dest: 'dist/local/' + pkg.name + '/pdfjs'}, // do we want all map files?
{src: 'node_modules/source-sans-pro/WOFF2/OTF/*', dest: 'dist/local/' + pkg.name + '/fonts'},
{src: 'node_modules/dbp-common/src/spinner.js', dest: 'dist/local/' + pkg.name, rename: 'spinner.js'},
{src: 'node_modules/dbp-common/misc/browser-check.js', dest: 'dist/local/' + pkg.name, rename: 'browser-check.js'},
{src: 'assets/icon-*.png', dest: 'dist/local/' + pkg.name},
{src: 'assets/*-placeholder.png', dest: 'dist/local/' + pkg.name},
{src: 'assets/manifest.json', dest: 'dist', rename: pkg.name + '.manifest.json'},
{src: 'assets/*.metadata.json', dest: 'dist'},
{src: 'node_modules/dbp-common/assets/icons/*.svg', dest: 'dist/local/dbp-common/icons'},
{src: 'node_modules/tabulator-tables/dist/css', dest: 'dist/local/dbp-file-source/tabulator-tables'},
],
}),
useBabel && babel({
include: [
'src/**',
'node_modules/pdfjs-dist/**', // uses Promise.allSettled
],
babelHelpers: 'runtime',
babelrc: false,
presets: [[
'@babel/preset-env', {
loose: true,
bugfixes: true,
targets: {
esmodules: true
}
}
]],
plugins: [[
'@babel/plugin-transform-runtime', {
corejs: 3,
useESModules: true
}
],
'@babel/plugin-syntax-dynamic-import',
'@babel/plugin-syntax-import-meta']
}),
watch ? serve({
contentBase: '.',
host: '127.0.0.1',
port: 8085,
historyApiFallback: basePath + pkg.name + '.html',
https: USE_HTTPS ? generateTLSConfig() : false,
headers: {
'Content-Security-Policy': `default-src 'self' 'unsafe-eval' 'unsafe-inline' analytics.tugraz.at ${keyCloakServer} ${entryPointURL} httpbin.org ${nextcloudBaseURL} www.handy-signatur.at ${pdfAsQualifiedlySigningServer} ; img-src * blob: data:`
},
}) : false
]
};
import {AppShell} from 'dbp-app-shell';
import * as commonUtils from 'dbp-common/utils';
commonUtils.defineCustomElement('dbp-signature', AppShell);
\ No newline at end of file
Source diff could not be displayed: it is too large. Options to address this: view the blob.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment