Skip to content

Commit

Permalink
add option to pass template renderers as an array for compiling
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardo-devis-agullo committed Jan 6, 2024
1 parent 84a0d36 commit 9585ba1
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
17 changes: 16 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
type Callback<T> = (err: NodeJS.ErrnoException | null, data: T) => void;

interface TemplateRenderer {
getInfo: () => {
externals: Array<{
name: string;
global: string | string[];
url: string;
devUrl?: string;
}>;
type: string;
version: string;
};
}

type Template = {
externals: Array<{ global: string | string[]; url: string }>;
};
type CompileOptions = { templates?: Record<string, Template> };
type CompileOptions = {
templates?: Record<string, Template> | TemplateRenderer[];
};
type Compiled = { code: string; map: string };

declare const ocClient: {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "oc-client-browser",
"version": "1.7.3",
"version": "1.7.4",
"description": "OC browser client",
"main": "index.js",
"types": "index.d.ts",
Expand Down
25 changes: 24 additions & 1 deletion tasks/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,31 @@ const baseTemplates = {
'oc-template-es6': { externals: [] }
};

function transformTemplates(templates = {}) {
if (Array.isArray(templates)) {
const templatesObj = {};
for (const template of templates) {
if (typeof template.getInfo !== 'function') {
throw new Error(
`Template ${
template.type || 'unknown'
} does not have a getInfo function`
);
}
const { externals, type } = template.getInfo();
templatesObj[type] = { externals };
}
return templatesObj;
}

return templates;
}

function getFiles({ sync = false, conf = {} }) {
const registeredTemplates = { ...baseTemplates, ...conf.templates };
const registeredTemplates = {
...baseTemplates,
...transformTemplates(conf.templates)
};
const srcPath = '../src/';
const vendorPath = '../vendor/';

Expand Down

0 comments on commit 9585ba1

Please sign in to comment.