@skriptfabrik/elements-cli 0.4.1 → 0.5.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,39 @@
1
+ version: 2
2
+
3
+ registries:
4
+ dockerhub:
5
+ type: 'docker-registry'
6
+ url: 'https://registry.hub.docker.com'
7
+ username: '${{ secrets.DOCKERHUB_USERNAME }}'
8
+ password: '${{ secrets.DOCKERHUB_TOKEN }}'
9
+ replaces-base: true
10
+
11
+ updates:
12
+ - package-ecosystem: 'github-actions'
13
+ directory: '/'
14
+ reviewers:
15
+ - 'skriptfabrik/developers'
16
+ schedule:
17
+ interval: 'weekly'
18
+ time: '08:00'
19
+ timezone: 'Europe/Berlin'
20
+
21
+ - package-ecosystem: 'npm'
22
+ directory: '/'
23
+ reviewers:
24
+ - 'skriptfabrik/developers'
25
+ schedule:
26
+ interval: 'weekly'
27
+ time: '08:00'
28
+ timezone: 'Europe/Berlin'
29
+
30
+ - package-ecosystem: 'docker'
31
+ directory: '/'
32
+ reviewers:
33
+ - 'skriptfabrik/developers'
34
+ registries:
35
+ - 'dockerhub'
36
+ schedule:
37
+ interval: 'weekly'
38
+ time: '08:00'
39
+ timezone: 'Europe/Berlin'
@@ -0,0 +1,12 @@
1
+ ## Describe your changes
2
+
3
+ - [ ] Bug fix (non-breaking change which fixes an issue)
4
+ - [ ] New feature (non-breaking change which adds functionality)
5
+ - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
6
+
7
+ ## Checklist before requesting a review
8
+
9
+ - [ ] I have included the ticket number of the issue at the beginning of the title of this pull request.
10
+ - [ ] I have updated the docs and/or specs to reflect this change.
11
+ - [ ] I have performed a self-review of my code.
12
+ - [ ] I have added thorough tests.
package/Dockerfile CHANGED
@@ -1,4 +1,4 @@
1
- FROM node:18.2.0-alpine
1
+ FROM node:18.14.0-alpine
2
2
 
3
3
  LABEL maintainer="Daniel Schröder <daniel.schroeder@skriptfabrik.com>"
4
4
 
@@ -12,7 +12,7 @@ COPY . /opt/elements-cli-${ELEMENTS_CLI_VERSION}
12
12
  RUN set -eux; \
13
13
  npm --prefix /opt/elements-cli-${ELEMENTS_CLI_VERSION} install; \
14
14
  rm -Rf ~/.npm; \
15
- ln -s /opt/elements-cli-${ELEMENTS_CLI_VERSION}/elements-cli.js /usr/local/bin/elements
15
+ ln -s /opt/elements-cli-${ELEMENTS_CLI_VERSION}/elements-cli.mjs /usr/local/bin/elements
16
16
 
17
17
  WORKDIR /data
18
18
 
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  [![NPM Version](https://img.shields.io/npm/v/@skriptfabrik/elements-cli)](https://www.npmjs.com/package/@skriptfabrik/elements-cli)
2
2
  [![NPM Downloads](https://img.shields.io/npm/dt/@skriptfabrik/elements-cli)](https://www.npmjs.com/package/@skriptfabrik/elements-cli)
3
- [![Continuous Integration](https://img.shields.io/github/workflow/status/skriptfabrik/elements-cli/Continuous%20Integration)](https://github.com/skriptfabrik/elements-cli/actions/workflows/ci.yml)
3
+ [![Continuous Integration](https://img.shields.io/github/actions/workflow/status/skriptfabrik/elements-cli/ci.yml)](https://github.com/skriptfabrik/elements-cli/actions/workflows/ci.yml)
4
4
 
5
5
  # Elements CLI
6
6
 
@@ -1,19 +1,29 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- const chalk = require('chalk');
4
- const chokidar = require('chokidar');
5
- const { compile } = require('handlebars');
6
- const corsAnywhere = require('cors-anywhere');
7
- const express = require('express');
8
- const fs = require('fs');
9
- const gracefulShutdown = require('http-graceful-shutdown');
10
- const handlebars = require('express-handlebars');
11
- const minimist = require('minimist');
12
- const path = require('path');
13
- const pkg = require('./package.json');
14
- const send = require('send');
15
- const { Server } = require('ws');
16
- const { URL } = require('url');
3
+ import chalk from 'chalk';
4
+ import chokidar from 'chokidar';
5
+ import corsAnywhere from 'cors-anywhere';
6
+ import express from 'express';
7
+ import { engine } from 'express-handlebars';
8
+ import { readFile } from 'fs/promises';
9
+ import handlebars from 'handlebars';
10
+ import gracefulShutdown from 'http-graceful-shutdown';
11
+ import minimist from 'minimist';
12
+ import { createRequire } from 'module';
13
+ import path from 'path';
14
+ import send from 'send';
15
+ import { WebSocketServer } from 'ws';
16
+ import { fileURLToPath, URL } from 'url';
17
+
18
+ // Compat
19
+
20
+ const __filename = fileURLToPath(import.meta.url);
21
+ const __dirname = path.dirname(__filename);
22
+ const require = createRequire(import.meta.url);
23
+
24
+ // Package info
25
+
26
+ const pkg = JSON.parse(await readFile(path.join(__dirname, 'package.json')));
17
27
 
18
28
  // Argument defaults
19
29
 
@@ -171,10 +181,10 @@ function sanitize(str, suffix = '') {
171
181
  *
172
182
  * @param {http.Server} server The HTTP server instance
173
183
  *
174
- * @returns {ws.Server}
184
+ * @returns {ws.WebSocketServer}
175
185
  */
176
186
  function upgrade(server) {
177
- const wss = new Server({ server });
187
+ const wss = new WebSocketServer({ server });
178
188
 
179
189
  return wss.on('connection', (socket) => {
180
190
  socket.on('message', (message) => {
@@ -202,8 +212,8 @@ function upgrade(server) {
202
212
  /**
203
213
  * Create file system watcher and broatcast all file changes to every client
204
214
  *
205
- * @param {sting} filePath The file path to watch
206
- * @param {ws.Server} server The web socket server instance
215
+ * @param {string} filePath The file path to watch
216
+ * @param {ws.WebSocketServer} server The web socket server instance
207
217
  *
208
218
  * @returns {chokidar.FSWatcher}
209
219
  */
@@ -239,8 +249,8 @@ const delimiters = { open: '{{', close: '}}' },
239
249
  // Export rendered API docs
240
250
 
241
251
  if (argv._[0] === 'export') {
242
- const input = fs.readFileSync(path.resolve(__dirname, 'views', 'index.handlebars')).toString('utf8');
243
- const template = compile(input);
252
+ const input = (await readFile(path.resolve(__dirname, 'views', 'index.handlebars'))).toString('utf8');
253
+ const template = handlebars.compile(input);
244
254
  const version = pkg.dependencies['@stoplight/elements'];
245
255
 
246
256
  let tryItCorsProxy;
@@ -281,7 +291,7 @@ const app = express();
281
291
 
282
292
  // Enable Handlebars view engine
283
293
 
284
- app.engine('handlebars', handlebars.engine());
294
+ app.engine('handlebars', engine());
285
295
  app.set('view engine', 'handlebars');
286
296
  app.set('views', path.join(__dirname, 'views'));
287
297
 
@@ -378,15 +388,22 @@ const server = app.listen(argv.port, argv.hostname, () => {
378
388
 
379
389
  // Watch files in working directory and launch web socket server
380
390
 
381
- if (argv.watch) {
382
- watch(
391
+ const watcher = argv.watch
392
+ ? watch(
383
393
  argv['working-dir'],
384
394
  upgrade(server).on('error', (err) => console.error(err))
385
395
  )
386
396
  .once('ready', () => console.error(`Watching ${path.resolve(argv['working-dir'])}`))
387
- .on('error', (err) => console.error(err));
388
- }
397
+ .on('error', (err) => console.error(err))
398
+ : undefined;
389
399
 
390
400
  // Enable the graceful shutdown
391
401
 
392
- gracefulShutdown(server);
402
+ gracefulShutdown(server, {
403
+ onShutdown: () => new Promise((resolve) => {
404
+ if (watcher) {
405
+ watcher.close();
406
+ }
407
+ resolve();
408
+ })
409
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skriptfabrik/elements-cli",
3
- "version": "0.4.1",
3
+ "version": "0.5.0",
4
4
  "description": "The missing CLI for beautiful, interactive API docs powered by with Stoplight Elements",
5
5
  "keywords": [
6
6
  "stoplight",
@@ -21,20 +21,20 @@
21
21
  },
22
22
  "license": "MIT",
23
23
  "dependencies": {
24
- "@stoplight/elements": "7.7.3",
25
- "chalk": "^4.0.0",
24
+ "@stoplight/elements": "7.7.10",
25
+ "chalk": "^5.2.0",
26
26
  "chokidar": "^3.5.3",
27
27
  "cors-anywhere": "~0.4.4",
28
28
  "express": "^4.18.2",
29
- "express-handlebars": "^6.0.6",
29
+ "express-handlebars": "^6.0.7",
30
30
  "handlebars": "^4.7.7",
31
- "http-graceful-shutdown": "^3.1.9",
31
+ "http-graceful-shutdown": "^3.1.12",
32
32
  "livereload-js": "3.4.1",
33
33
  "minimist": "^1.2.7",
34
34
  "send": "~0.18.0",
35
- "ws": "^8.10.0"
35
+ "ws": "^8.12.0"
36
36
  },
37
37
  "bin": {
38
- "elements": "./elements-cli.js"
38
+ "elements": "./elements-cli.mjs"
39
39
  }
40
40
  }