html-express-js 1.1.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,6 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: npm
4
+ directory: '/'
5
+ schedule:
6
+ interval: monthly
@@ -0,0 +1,17 @@
1
+ name: Dependabot auto-merge
2
+ on: pull_request
3
+
4
+ permissions:
5
+ pull-requests: write
6
+ contents: write
7
+
8
+ jobs:
9
+ dependabot:
10
+ runs-on: ubuntu-latest
11
+ if: ${{ github.actor == 'dependabot[bot]' }}
12
+ steps:
13
+ - name: Enable auto-merge for Dependabot PRs
14
+ run: gh pr merge --auto --squash "$PR_URL"
15
+ env:
16
+ PR_URL: ${{github.event.pull_request.html_url}}
17
+ GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env sh
2
+ . "$(dirname -- "$0")/_/husky.sh"
3
+
4
+ npm run format
package/.nvmrc ADDED
@@ -0,0 +1 @@
1
+ 16
package/.prettierignore CHANGED
@@ -1,2 +1,8 @@
1
1
  package*.json
2
- node_modules
2
+ node_modules
3
+ .husky
4
+ LICENSE
5
+ .gitignore
6
+ .npmrc
7
+ .prettierignore
8
+ .nvmrc
package/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: node_js
2
+ node_js:
3
+ - '16'
4
+ branches:
5
+ only:
6
+ - master
7
+ script:
8
+ - npm test
package/README.md CHANGED
@@ -1,3 +1,7 @@
1
+ ![build](https://img.shields.io/travis/markcellus/html-express-js)
2
+ ![npm](https://img.shields.io/npm/v/html-express-js)
3
+ ![node](https://img.shields.io/node/v/html-express-js)
4
+
1
5
  # html-express-js
2
6
 
3
7
  ## Features
@@ -28,7 +32,7 @@ app.engine(
28
32
  'js',
29
33
  htmlExpress({
30
34
  includesDir: 'includes', // where all includes reside
31
- })
35
+ }),
32
36
  );
33
37
  // use engine
34
38
  app.set('view engine', 'js');
@@ -36,7 +40,7 @@ app.set('view engine', 'js');
36
40
  // set directory where all index.js pages are served
37
41
  app.set('views', `${__dirname}/public`);
38
42
 
39
- // render HTML in public/dashboard.js with data
43
+ // render HTML in public/homepage.js with data
40
44
  app.get('/', function (req, res, next) {
41
45
  res.render('homepage', {
42
46
  title: 'Awesome Homepage',
@@ -51,7 +55,7 @@ app.use(
51
55
  staticIndexHandler({
52
56
  viewsDir: `${__dirname}/public`, // root views directory to serve all index.js files
53
57
  notFoundView: '404/index', // relative to viewsDir above
54
- })
58
+ }),
55
59
  );
56
60
  ```
57
61
 
@@ -76,7 +80,7 @@ export const view = () => html`
76
80
  import { html } from 'html-express-js';
77
81
 
78
82
  export const view = (data, state) => html`
79
- <!DOCTYPE html>
83
+ <!doctype html>
80
84
  <html lang="en">
81
85
  <head>
82
86
  ${state.includes.head}
@@ -84,7 +88,7 @@ export const view = (data, state) => html`
84
88
  </head>
85
89
 
86
90
  <body>
87
- <h1>This is the homepage</h1>
91
+ <h1>This is the homepage for ${data.name}</h1>
88
92
  </body>
89
93
  </html>
90
94
  `;
package/example/app.js CHANGED
@@ -10,7 +10,7 @@ app.engine(
10
10
  'js',
11
11
  htmlExpress({
12
12
  includesDir: 'includes',
13
- })
13
+ }),
14
14
  );
15
15
 
16
16
  app.set('view engine', 'js');
@@ -30,7 +30,7 @@ app.use(
30
30
  staticIndexHandler({
31
31
  viewsDir: `${__dirname}/example/public`,
32
32
  notFoundView: 'not-found', // OPTIONAL: defaults to `404/index`
33
- })
33
+ }),
34
34
  );
35
35
 
36
36
  export default app;
@@ -1,7 +1,7 @@
1
1
  import { html } from '../../../src/index.js';
2
2
 
3
3
  export const view = (data, state) => html`
4
- <!DOCTYPE html>
4
+ <!doctype html>
5
5
  <html lang="en">
6
6
  <head>
7
7
  ${state.includes.head}
@@ -1,7 +1,7 @@
1
1
  import { html } from '../../src/index.js';
2
2
 
3
3
  export const view = (data, state) => html`
4
- <!DOCTYPE html>
4
+ <!doctype html>
5
5
  <html lang="en">
6
6
  <head>
7
7
  ${state.includes.head}
@@ -1,7 +1,7 @@
1
1
  import { html } from '../../src/index.js';
2
2
 
3
3
  export const view = (data, state) => html`
4
- <!DOCTYPE html>
4
+ <!doctype html>
5
5
  <html lang="en">
6
6
  <head>
7
7
  ${state.includes.head}
package/jsconfig.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "compilerOptions": {
3
+ "checkJs": true,
4
+ "maxNodeModuleJsDepth": 1,
5
+ "moduleResolution": "nodenext",
6
+ "module": "nodenext",
7
+ "target": "es2022"
8
+ }
9
+ }
package/package.json CHANGED
@@ -1,13 +1,17 @@
1
1
  {
2
2
  "name": "html-express-js",
3
- "version": "1.1.0",
3
+ "version": "2.0.0",
4
4
  "description": "An Express template engine to render HTML views using native JavaScript",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
7
+ "engines": {
8
+ "node": ">=16"
9
+ },
7
10
  "scripts": {
8
11
  "format": "prettier --write '**/*'",
9
12
  "test": "prettier --check '**/*'",
10
- "start": "node ./example/server.js"
13
+ "start": "node ./example/server.js",
14
+ "prepare": "husky install"
11
15
  },
12
16
  "repository": {
13
17
  "type": "git",
@@ -27,13 +31,15 @@
27
31
  },
28
32
  "homepage": "https://github.com/markcellus/html-express-js#readme",
29
33
  "dependencies": {
30
- "glob": "^8.0.3"
34
+ "glob": "^10.2.2"
31
35
  },
32
36
  "devDependencies": {
37
+ "@types/glob": "^8.1.0",
33
38
  "chokidar": "^3.5.3",
34
39
  "express": "^4.18.1",
35
- "prettier": "^2.7.1",
36
- "release-it": "^15.0.0",
40
+ "husky": "^9.0.7",
41
+ "prettier": "^3.0.3",
42
+ "release-it": "^17.0.0",
37
43
  "reload": "^3.2.0"
38
44
  }
39
45
  }
package/src/index.js CHANGED
@@ -1,10 +1,7 @@
1
1
  import { basename, extname } from 'path';
2
- import { promisify } from 'util';
3
- import g from 'glob';
2
+ import { glob } from 'glob';
4
3
  import { stat } from 'fs/promises';
5
4
 
6
- const glob = promisify(g);
7
-
8
5
  /**
9
6
  * Renders an HTML template in a file.
10
7
  *
@@ -12,7 +9,7 @@ const glob = promisify(g);
12
9
  * @param {string} path - The path to html file
13
10
  * @param {object} [data]
14
11
  * @param {object} [state] - Page-level attributes
15
- * @returns {string} HTML
12
+ * @returns {Promise<string>} HTML
16
13
  */
17
14
  async function renderHtmlFileTemplate(path, data, state) {
18
15
  const { view } = await import(path);
@@ -30,7 +27,7 @@ async function renderHtmlFileTemplate(path, data, state) {
30
27
  * @param {string} filePath - The path to html file
31
28
  * @param {object} data - Data to be made available in view
32
29
  * @param {object} instanceOptions - Options passed to original instantiation
33
- * @returns {string} HTML with includes available (appended to state)
30
+ * @returns {Promise<string>} HTML with includes available (appended to state)
34
31
  */
35
32
  async function renderHtmlFile(filePath, data = {}, instanceOptions = {}) {
36
33
  const state = {
@@ -44,7 +41,7 @@ async function renderHtmlFile(filePath, data = {}, instanceOptions = {}) {
44
41
  state.includes[key] = await renderHtmlFileTemplate(
45
42
  includePath,
46
43
  data,
47
- state
44
+ state,
48
45
  );
49
46
  }
50
47
  return await renderHtmlFileTemplate(filePath, data, state);
@@ -74,9 +71,9 @@ export function html(strings, ...data) {
74
71
  * @param {object} options.viewsDir - The directory that houses any potential index files
75
72
  * @param {string} [options.notFoundView] - The path of a file relative to the views
76
73
  * directory that should be served as 404 when no matching index page exists. Defaults to `404/index`.
77
- * @returns {function} - Middleware function
74
+ * @returns {import('express').RequestHandler} - Middleware function
78
75
  */
79
- export function staticIndexHandler(options = {}) {
76
+ export function staticIndexHandler(options) {
80
77
  const notFoundView = options.notFoundView || `404/index`;
81
78
 
82
79
  return async function (req, res, next) {
@@ -105,7 +102,7 @@ export function staticIndexHandler(options = {}) {
105
102
  *
106
103
  * @param {object} [opts]
107
104
  * @param {object} [opts.includesDir]
108
- * @returns {Function}
105
+ * @returns {(path: string, options: object, callback: (e: any, rendered?: string) => void) => void}
109
106
  */
110
107
  export default function (opts = {}) {
111
108
  return async (filePath, data, callback) => {