Skip to content
Snippets Groups Projects
Commit 1bf53554 authored by Reiter, Christoph's avatar Reiter, Christoph :snake:
Browse files

Reuse some rollup helper functions from the toolkit

parent 8bf5bc16
No related branches found
No related tags found
No related merge requests found
import path from 'path'; import path from 'path';
import fs from 'fs';
import url from 'url'; import url from 'url';
import glob from 'glob'; import glob from 'glob';
import resolve from '@rollup/plugin-node-resolve'; import resolve from '@rollup/plugin-node-resolve';
...@@ -14,8 +13,9 @@ import license from 'rollup-plugin-license'; ...@@ -14,8 +13,9 @@ import license from 'rollup-plugin-license';
import del from 'rollup-plugin-delete'; import del from 'rollup-plugin-delete';
import emitEJS from 'rollup-plugin-emit-ejs' import emitEJS from 'rollup-plugin-emit-ejs'
import {getBabelOutputPlugin} from '@rollup/plugin-babel'; import {getBabelOutputPlugin} from '@rollup/plugin-babel';
import selfsigned from 'selfsigned';
import appConfig from './app.config.js'; import appConfig from './app.config.js';
import {getPackagePath, getBuildInfo} from './vendor/toolkit/rollup.utils.js';
import {generateTLSConfig} from './rollup.utils.js';
// ------------------------------- // -------------------------------
...@@ -70,64 +70,6 @@ if (config.nextcloudBaseURL) { ...@@ -70,64 +70,6 @@ if (config.nextcloudBaseURL) {
config.nextcloudWebDavURL = ''; config.nextcloudWebDavURL = '';
} }
/**
* 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: appEnv
}
}
export async function getPackagePath(packageName, assetPath) {
const r = resolve();
const resolved = await r.resolveId(packageName);
let packageRoot;
if (resolved !== null) {
const id = (await r.resolveId(packageName)).id;
const packageInfo = r.getPackageInfoForId(id);
packageRoot = packageInfo.root;
} else {
// Non JS packages
packageRoot = path.dirname(require.resolve(packageName + '/package.json'));
}
return path.relative(process.cwd(), path.join(packageRoot, assetPath));
}
export default (async () => {return { export default (async () => {return {
input: (appEnv != 'test') ? [ input: (appEnv != 'test') ? [
'src/' + pkg.name + '.js', 'src/' + pkg.name + '.js',
...@@ -167,7 +109,7 @@ export default (async () => {return { ...@@ -167,7 +109,7 @@ export default (async () => {return {
}), }),
consts({ consts({
environment: appEnv, environment: appEnv,
buildinfo: getBuildInfo(), buildinfo: getBuildInfo(appEnv),
nextcloudBaseURL: config.nextcloudBaseURL, nextcloudBaseURL: config.nextcloudBaseURL,
}), }),
emitEJS({ emitEJS({
...@@ -194,7 +136,7 @@ export default (async () => {return { ...@@ -194,7 +136,7 @@ export default (async () => {return {
environment: appEnv, environment: appEnv,
matomoUrl: config.matomoUrl, matomoUrl: config.matomoUrl,
matomoSiteId: config.matomoSiteId, matomoSiteId: config.matomoSiteId,
buildInfo: getBuildInfo() buildInfo: getBuildInfo(appEnv)
} }
}), }),
resolve({ resolve({
......
import fs from 'fs';
import selfsigned from 'selfsigned';
/**
* Creates a server certificate and caches it in the .cert directory
*/
export 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')
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment