Skip to content

Commit

Permalink
feat(dependencies)!: replaced ejs with more light-weight and faster…
Browse files Browse the repository at this point in the history
… `eta`

BREAKING CHANGE: Views now have to be written using `eta`
  • Loading branch information
pklaschka committed Jan 7, 2021
1 parent ec219b2 commit cbd5ea1
Show file tree
Hide file tree
Showing 17 changed files with 194 additions and 287 deletions.
89 changes: 5 additions & 84 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
"license": "MIT",
"devDependencies": {
"@types/cosmiconfig": "^6.0.0",
"@types/ejs": "^3.0.5",
"@types/express": "^4.17.9",
"@types/markdown-it": "^12.0.1",
"@types/node": "^14.14.20",
Expand All @@ -73,7 +72,7 @@
"dependencies": {
"colorette": "^1.2.1",
"cosmiconfig": "^7.0.0",
"ejs": "^3.1.5",
"eta": "^1.12.1",
"express": "^4.17.1",
"markdown-it": "^12.0.4",
"ts-morph": "^9.1.0",
Expand Down
9 changes: 5 additions & 4 deletions src/builders/build-static.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import MarkdownIt from 'markdown-it';
import * as fs from 'fs/promises';
import * as path from 'path';
import ejs from 'ejs';
import { renderFile } from 'eta';
import { DEFAULT_CONFIG, FliegdocConfig, Tree } from '../model';

const origMd = new MarkdownIt({ linkify: true });
Expand Down Expand Up @@ -39,9 +39,10 @@ async function render(
await fs.mkdir(path.dirname(outPath), { recursive: true });
await fs.writeFile(
outPath,
await ejs.renderFile(path.resolve(viewFolder, view + '.ejs'), data, {
root: viewFolder
})
await (renderFile(path.resolve(viewFolder, view + '.eta'), data, {
root: viewFolder,
views: viewFolder
}) || Promise.reject('Error rendering view ' + view))
);
}

Expand Down
4 changes: 3 additions & 1 deletion src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import MarkdownIt from 'markdown-it';
import * as fs from 'fs';
import { DEFAULT_CONFIG, FliegdocConfig, Tree } from '../model';
import * as path from 'path';
import { renderFile } from 'eta';
const origMd = new MarkdownIt({ linkify: true });

const md = {
Expand Down Expand Up @@ -36,8 +37,9 @@ export function serveDynamic(
};
const app = Express();

app.engine('eta', renderFile);
app.set('view engine', 'eta');
app.set('views', path.join(__dirname, '..', '..', 'views'));
app.set('view engine', 'ejs');

app.get(`${finalConfig.baseUrl}`, (req, res) => {
res.render('plain', {
Expand Down
10 changes: 5 additions & 5 deletions views/layout/footer.ejs → views/layout/footer.eta
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
</div>
</div>
</div>
</body>
</footer>
</div>
</div>
</div>
</body>
</footer>
28 changes: 12 additions & 16 deletions views/layout/header.ejs → views/layout/header.eta
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
<%
/**
* @name config
*/
/**
* @name modules
*/
const {config, modules} = it;
%>
<html lang="en">
<head>
Expand All @@ -15,6 +10,7 @@
font-size: 1.2rem;
font-weight: bold;
}

code {
line-height: inherit;
}
Expand All @@ -27,23 +23,23 @@
</head>
<body>
<header>
<a href="<%=config.baseUrl %>" class="logo">fliegdoc Documentation</a>
<a href="<%= config.baseUrl %>" class="logo">fliegdoc Documentation</a>
</header>
<div class="container">
<div class="row">
<aside class="col-sm-12 col-md-4 col-lg-3">
<nav class="fixed">
<a href="<%=config.baseUrl %>">Project README</a>
<a href="<%= config.baseUrl %>">Project README</a>
<span>Modules</span>
<%modules.forEach(function(module) {
%>
<a href="<%=config.baseUrl %><%=module%>">
<code>
<%=module%>
</code>
</a>
<% modules.forEach(function(module) {
%>
<a href="<%= config.baseUrl %><%= module %>">
<code>
<%= module %>
</code>
</a>
<%
})%>
}) %>
</nav>
</aside>
<div class="col-sm-12 col-md-8 col-lg-6">
49 changes: 0 additions & 49 deletions views/module.ejs

This file was deleted.

40 changes: 40 additions & 0 deletions views/module.eta
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<%
/**
* @name it
*/
%>
<%~ includeFile('layout/header', it) %>
<h1><code><%~ it.moduleName %></code></h1>

<p>
Install using
</p>
<pre><code>npm install <%~ it.moduleName %></code></pre>

<h2>Exported Members</h2>
<p>You can access these members by importing the module:</p>
<pre><code>import { <i>member</i> } from '<%~ it.moduleName %>';</code></pre>

<!-- Members -->
<% it.members.forEach(function(member) { %>
<div class="card fluid">
<!-- Name with anchor link -->
<a id="<%= member.name %>" href="#<%= member.name %>">
<h3><code><%~ member.name %></code></h3></a>

<!-- Description, based on type -->
<% member.declarations.forEach(function(declaration) { %>
<% if (declaration.type === 'function') { %>
<%~ includeFile('partials/function', {...it, declaration: declaration.declarations[0]}) %>
<% } else if (declaration.type === 'class-interface') { %>
<%~ includeFile('partials/class', {...it, declaration: declaration.declarations[0]}) %>
<% } else if (declaration.type === 'variable') { %>
<%~ includeFile('partials/variable', {...it, declaration: declaration.declarations[0]}) %>
<% } else if (declaration.type === 'type') { %>
<%~ includeFile('partials/type', {...it, declaration: declaration.declarations[0]}) %>
<% } else { %>
<!-- UNRESOLVED TYPE: <%~ declaration.type %> with <%~ JSON.stringify(declaration) %>-->
<% } %>
<% }) %>
</div>
<% }) %>
14 changes: 6 additions & 8 deletions views/partials/class.ejs → views/partials/class.eta
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<%
/**
* @name declaration
*/
const {declaration, md} = it;
%>
<!-- Signature -->
<p>
Expand All @@ -14,7 +12,7 @@
<%= declaration.name %>

<!-- Type Parameters -->
<%- include('type-params', {typeParameters: declaration.typeParameters}) %>
<%~ includeFile('partials/type-params', {typeParameters: declaration.typeParameters}) %>

<!-- Extends -->
<% if (declaration.extends && declaration.extends.length) { %>
Expand All @@ -25,13 +23,13 @@
</p>

<!-- Docs -->
<%- include('docs', {docs: declaration.docs, md}) %>
<%~ includeFile('docs', {docs: declaration.docs, md}) %>

<!-- Constructors -->
<% if (declaration.ctors) { %>
<h4>Constructors</h4>
<% declaration.ctors.forEach((ctor) => { %>
<%- include('function', {declaration: ctor, md}) %>
<%~ includeFile('function', {declaration: ctor, md}) %>
<% }) %>
<% } %>

Expand All @@ -41,7 +39,7 @@
<a id="<%= declaration.name %>.<%= property.name %>" href="#<%= declaration.name %>.<%= property.name %>">
<h5><code><%= declaration.name %>.<%= property.name %></code></h5>
</a>
<%- include('property', {declaration: property, md}) %>
<%~ includeFile('property', {declaration: property, md}) %>
<% }) %>

<!-- Methods -->
Expand All @@ -51,6 +49,6 @@
<a id="<%= declaration.name %>.<%= method.name %>" href="#<%= declaration.name %>.<%= method.name %>">
<h5><code><%= declaration.name %>.<%= method.name %></code></h5>
</a>
<%- include('function', {declaration: method, md}) %>
<%~ includeFile('function', {declaration: method, md}) %>
<% }) %>
<% } %>
Loading

0 comments on commit cbd5ea1

Please sign in to comment.