Skip to content

Commit

Permalink
feat: mime npm package (#34)
Browse files Browse the repository at this point in the history
* feat: mime npm package

* fix: pipeline
  • Loading branch information
BCsabaEngine authored Dec 6, 2024
1 parent 67be273 commit c7ff187
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 51 deletions.
24 changes: 18 additions & 6 deletions .github/workflows/ci-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,28 @@ on:

jobs:
check:
name: Source revision
name: Source Revision
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [22.x, 20.x, 18.x]

steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: '20.17.0'
node-version: ${{ matrix.node-version }}
cache: 'npm'

- name: Install Dependencies
run: npm ci

- name: Run Format Check
run: npm run format:check

- name: Run Lint Check
run: npm run lint:check

- run: npm ci
- run: npm run format:check
- run: npm run lint:check
- run: npm run build
- name: Build
run: npm run build
40 changes: 29 additions & 11 deletions .github/workflows/ci-full.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,31 @@ on:

jobs:
check:
name: Source revision
name: Source Revision
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [22.x, 20.x, 18.x]

steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: '20.17.0'
node-version: ${{ matrix.node-version }}
cache: 'npm'

- name: Install Dependencies
run: npm ci

- name: Run Format Check
run: npm run format:check

- name: Run Lint Check
run: npm run lint:check

- run: npm ci
- run: npm run format:check
- run: npm run lint:check
- run: npm run build
- name: Build
run: npm run build

tag:
name: Version tag
Expand Down Expand Up @@ -47,10 +59,16 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20.16.0'
registry-url: 'https://registry.npmjs.org'
- run: npm ci
- run: npm run build
- run: npm publish
node-version: '22'
cache: 'npm'

- name: Install Dependencies
run: npm ci

- name: Build
run: npm run build

- name: Publish
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change log

## 1.6

### 1.6.0

- Using mime npm package instead of mime-types: I prefer to use standard text/javascript. It better meets today's requirements.

## 1.5

### 1.5.2
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ In order to be able to easily update OTA, it is important - from the users' poin

This npm package provides a solution for **inserting any JS client application into the ESP web server** (PsychicHttp and also ESPAsyncWebServer available, PsychicHttp is the default). For this, JS, html, css, font, assets, etc. files must be converted to binary byte array. Npm mode is easy to use and easy to **integrate into your CI/CD pipeline**.

> Starting with version v1.6.0, mime npm package is used instead of mime-types (application/javascript -> text/javascript)
> Starting with version v1.5.0, PsychicHttp v2 is also supported.
> Version v1.4.0 has a breaking change! --no-gzip changed to --gzip. Starting with this version c++ compiler directives are available to setup operation in project level.
Expand Down
40 changes: 13 additions & 27 deletions package-lock.json

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

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "svelteesp32",
"version": "1.5.2",
"version": "1.6.0",
"description": "Convert Svelte (or any frontend) JS application to serve it from ESP32 webserver (PsychicHttp)",
"author": "BCsabaEngine",
"license": "ISC",
Expand Down Expand Up @@ -54,7 +54,6 @@
"espasyncwebserver"
],
"devDependencies": {
"@types/mime-types": "^2.1.4",
"@types/node": "^22.10.1",
"@typescript-eslint/eslint-plugin": "^8.17.0",
"@typescript-eslint/parser": "^8.17.0",
Expand All @@ -71,7 +70,7 @@
"dependencies": {
"glob": "^11.0.0",
"handlebars": "^4.7.8",
"mime-types": "^2.1.35",
"mime": "^4.0.4",
"ts-command-line-args": "^2.5.1"
}
}
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { mkdirSync, writeFileSync } from 'node:fs';
import path from 'node:path';
import { gzipSync } from 'node:zlib';

import { lookup } from 'mime-types';
import mime from 'mime';

import { cmdLine } from './commandLine';
import { greenLog, yellowLog } from './consoleColor';
Expand All @@ -31,7 +31,7 @@ console.log();
console.log('Translation to header file');
const longestFilename = [...files.keys()].reduce((p, c) => Math.max(c.length, p), 0);
for (const [originalFilename, content] of files) {
const mime = lookup(originalFilename) || 'text/plain';
const mimeType = mime.getType(originalFilename) || 'text/plain';
summary.filecount++;

const filename = originalFilename.replace(/\\/g, '/');
Expand All @@ -56,7 +56,7 @@ for (const [originalFilename, content] of files) {
content,
contentGzip: zipContent,
isGzip: true,
mime,
mime: mimeType,
md5
});
console.log(
Expand All @@ -72,7 +72,7 @@ for (const [originalFilename, content] of files) {
content,
contentGzip: content,
isGzip: false,
mime,
mime: mimeType,
md5
});
console.log(
Expand Down

0 comments on commit c7ff187

Please sign in to comment.