Skip to content

Commit acb3752

Browse files
committed
Add github workflows, docker support, rollup build
1 parent e2a9e27 commit acb3752

16 files changed

+133
-15
lines changed

.docker/Dockerfile.test

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM node:14.17-alpine
2+
3+
WORKDIR /usr/src/app
4+
COPY package*.json ./
5+
RUN npm i
6+
COPY . .

.docker/docker-compose.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
version: '3.1'
2+
3+
services:
4+
redis-cache-manager:
5+
container_name: redis-cache-manager
6+
build:
7+
context: .
8+
dockerfile: Dockerfile.test
9+
volumes:
10+
- ../:/usr/src/app
11+
depends_on:
12+
- redis
13+
command: npm run test
14+
15+
redis: # Redis
16+
image: redis
17+
logging:
18+
driver: none
19+
healthcheck:
20+
test: [ "CMD", "redis-cli", "--raw", "incr", "ping" ]
21+
interval: 20s
22+
timeout: 5s
23+
retries: 3

.github/workflows/npm-publish.yml

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages
3+
4+
name: Publish package
5+
6+
on:
7+
release:
8+
types: [published]
9+
10+
jobs:
11+
publish-package:
12+
name: Publish package redis-caching-manager
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v2
18+
19+
- name: Install Node.js 14.x
20+
uses: actions/setup-node@v2
21+
with:
22+
node-version: 14.x
23+
registry-url: 'https://registry.npmjs.org'
24+
25+
- name: Install Redis 6
26+
uses: supercharge/[email protected]
27+
with:
28+
redis-version: 6
29+
30+
- name: Install dependency
31+
run: npm install
32+
33+
- name: Format package
34+
run: npm run format
35+
36+
- name: Build Package
37+
run: npm run build
38+
39+
- name: Test Package
40+
run: npm run test
41+
env:
42+
REDIS_URL: redis://localhost:6379
43+
44+
- name: Publish into npm registry
45+
run: npm publish
46+
env:
47+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.gitignore

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
.idea
22
node_modules/
33
lib/
4-
Dockerfile.test
5-
docker-compose.yml
4+
pnpm-lock.yaml

.npmignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,7 @@ src/
55
tsconfig.json
66
tslint.json
77
.prettierrc
8-
.docker
8+
.docker
9+
examples/
10+
rollup.config.ts
11+
pnpm-lock.yaml

package.json

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
{
22
"name": "redis-caching-manager",
3-
"version": "2.0.0",
3+
"version": "2.1.0",
44
"description": "A cache manager for redis",
55
"main": "lib/index.js",
66
"types": "lib/index.d.ts",
7+
"module": "lib/index.mjs",
78
"scripts": {
8-
"build": "tsc",
9+
"clean": "rm -rf lib/",
10+
"build": "npm run clean && rollup -c",
911
"format": "prettier --write \"src/**/*.ts\"",
1012
"lint": "tslint -p tsconfig.json",
1113
"test": "jest --config jestconfig.json --detectOpenHandles --unhandled-rejections=strict",
1214
"test:docker": "docker-compose --file ./.docker/docker-compose.yml up --abort-on-container-exit --exit-code-from redis-cache-manager",
1315
"posttest:docker": "docker-compose --file ./.docker/docker-compose.yml down --volumes --remove-orphans",
1416
"prepare": "npm run build",
15-
"prepublishOnly": "npm run test:docker && npm run lint",
1617
"preversion": "npm run lint",
1718
"version": "npm run format && git add -A src",
1819
"postversion": "git push && git push --tags"
@@ -24,8 +25,12 @@
2425
},
2526
"devDependencies": {
2627
"@types/jest": "^27.4.0",
28+
"esbuild": "^0.14.27",
2729
"jest": "^27.4.7",
2830
"prettier": "^2.5.1",
31+
"rollup": "^2.70.1",
32+
"rollup-plugin-dts": "^4.2.0",
33+
"rollup-plugin-esbuild": "^4.8.2",
2934
"ts-jest": "^27.1.3",
3035
"tslint": "^6.1.3",
3136
"tslint-config-prettier": "^1.18.0",

rollup.config.js

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import dts from 'rollup-plugin-dts'
2+
import esbuild from 'rollup-plugin-esbuild'
3+
4+
const name = require('./package.json').main.replace(/\.js$/, '')
5+
6+
const bundle = config => ({
7+
...config,
8+
input: 'src/index.ts',
9+
external: id => !/^[./]/.test(id),
10+
})
11+
12+
export default [
13+
bundle({
14+
plugins: [esbuild()],
15+
output: [
16+
{
17+
file: `${name}.js`,
18+
format: 'cjs',
19+
sourcemap: true,
20+
},
21+
{
22+
file: `${name}.mjs`,
23+
format: 'es',
24+
sourcemap: true,
25+
},
26+
],
27+
}),
28+
bundle({
29+
plugins: [dts()],
30+
output: {
31+
file: `${name}.d.ts`,
32+
format: 'es',
33+
},
34+
}),
35+
]

tests/destroy.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ beforeEach(async () => {
88

99
beforeAll(async () => {
1010
await cacheManager.connect({
11-
url: 'redis://redis:6379',
11+
url: process.env.REDIS_URL ?? 'redis://redis:6379',
1212
});
1313
});
1414

tests/enable.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ beforeEach(async () => {
88

99
beforeAll(async () => {
1010
await cacheManager.connect({
11-
url: 'redis://redis:6379',
11+
url: process.env.REDIS_URL ?? 'redis://redis:6379',
1212
prefix: 'dorik',
1313
});
1414
});

tests/get.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ beforeEach(async () => {
99
beforeAll(async () => {
1010
await cacheManager.connect({
1111
prefix: 'prefix_',
12-
url: 'redis://redis:6379',
12+
url: process.env.REDIS_URL ?? 'redis://redis:6379',
1313
});
1414
});
1515

tests/has.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ beforeEach(async () => {
88

99
beforeAll(async () => {
1010
await cacheManager.connect({
11-
url: 'redis://redis:6379',
11+
url: process.env.REDIS_URL ?? 'redis://redis:6379',
1212
});
1313
});
1414

tests/pull.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ beforeEach(async () => {
88

99
beforeAll(async () => {
1010
await cacheManager.connect({
11-
url: 'redis://redis:6379',
11+
url: process.env.REDIS_URL ?? 'redis://redis:6379',
1212
});
1313
});
1414

tests/put.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ beforeEach(async () => {
88

99
beforeAll(async () => {
1010
await cacheManager.connect({
11-
url: 'redis://redis:6379',
11+
url: process.env.REDIS_URL ?? 'redis://redis:6379',
1212
});
1313
});
1414

tests/remember.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ beforeEach(async () => {
88

99
beforeAll(async () => {
1010
await cacheManager.connect({
11-
url: 'redis://redis:6379',
11+
url: process.env.REDIS_URL ?? 'redis://redis:6379',
1212
});
1313
});
1414

tests/set.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ beforeEach(async () => {
88

99
beforeAll(async () => {
1010
await cacheManager.connect({
11-
url: 'redis://redis:6379',
11+
url: process.env.REDIS_URL ?? 'redis://redis:6379',
1212
});
1313
});
1414

tests/tags.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ beforeEach(async () => {
88

99
beforeAll(async () => {
1010
await cacheManager.connect({
11-
url: 'redis://redis:6379',
11+
url: process.env.REDIS_URL ?? 'redis://redis:6379',
1212
});
1313
});
1414

0 commit comments

Comments
 (0)