3.3.1 • Published 2 years ago

@springernature/util-package-renderer v3.3.1

Weekly downloads
16
License
MIT
Repository
github
Last release
2 years ago

Package Renderer

Renders an Elements-compatible package into HTML with all resources inlined.
Optionally write the result to disk as index.html.

NOTE: As of v3.0.0 this package works with dart-sass, for node-sass support please continue using v2.2.2

Usage

const renderer = require('@springernature/util-package-renderer');
await renderer(config);

Config

ParameterDefault ValueTypeRequiredDescription
config.demoCodeFolderdemoStringYesName of demo code folder within your package
config.brandContext@springernature/brand-contextStringYesName of the brand-context package on NPM
config.reportingLeveltitleStringYesAmount of reporting for util-cli-reporter
config.dynamicTemplateLocation.StringYesWhere to start looking for dynamic handlebars templates
config.minifyfalseBooleanYesMinify the JS and CSS output
config.packageRoot.StringYesPath to the package to render
config.distFolderPathnullStringNoPath to where index.html should be written

Full examples

A working implementation can also be found in runner.js.

Using default config

'use strict';
const renderer = require('@springernature/util-package-renderer');

// By default no distFolder is defined and the result is returned as a String
(async () => {
	try {
		const result = await renderer();
		console.log(result);
	} catch (error) {
		console.error(error);
	}
})();

Return result as String, with config

const path = require('path');
const renderer = require('@springernature/util-package-renderer');

const fulldir = path.resolve(__dirname, 'apackage');
const demoFolderName = 'demo';
const brandContext = '@springernature/brand-context';

(async () => {
	try {
		const result = await renderer({
			demoCodeFolder: demoFolderName,
			reportingLevel: 'title',
			dynamicTemplateLocation: './path/to/location'
			minify: true,
			packageRoot: fulldir,
			brandContext: brandContext
		});
		console.log(result);
	} catch (error) {
		console.error(error);
	}
})();

Write result to disk, with config

const path = require('path');
const renderer = require('@springernature/util-package-renderer');

const fulldir = path.resolve(__dirname, 'apackage');
const demoFolderName = 'demo';
const brandContext = '@springernature/brand-context';
const distFolder = path.join(fulldir, 'dist');

(async () => {
	try {
		await renderer({
			demoCodeFolder: demoFolderName,
			reportingLevel: 'title',
			dynamicTemplateLocation: './path/to/location'
			minify: true,
			packageRoot: fulldir,
			brandContext: brandContext,
			distFolderPath: distFolder
		});
	} catch (error) {
		console.error(error);
	}
})();