@openapi-typescript-infra/service 1.1.0 → 1.1.1
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.
- package/Makefile +71 -0
- package/README.md +1 -0
- package/package.json +2 -2
package/Makefile
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# This Makefile is intended to be called by higher level/project Makefiles
|
|
2
|
+
# It bakes in a number of standard practices include the use of the src
|
|
3
|
+
# directory (choose your build dir as appropriate).
|
|
4
|
+
#
|
|
5
|
+
# It also includes database scripts, which technically aren't the concern of this
|
|
6
|
+
# module, but very often services do have a database component but don't need
|
|
7
|
+
# any sort of service-specific database modules (just plain pg). So this Makefile
|
|
8
|
+
# has targets for setting up a database for the service, and generating types
|
|
9
|
+
# using kysely, and using db-migrate for schema managment.
|
|
10
|
+
#
|
|
11
|
+
# With all that, you can have a Makefile that does this:
|
|
12
|
+
#
|
|
13
|
+
# .PHONY: all service dbi ts
|
|
14
|
+
#
|
|
15
|
+
# export DB_NAME ?= cool_db
|
|
16
|
+
# export SERVICE_NAME ?= my-cool-serv
|
|
17
|
+
#
|
|
18
|
+
# include node_modules/@openapi-typescript-infra/service/Makefile
|
|
19
|
+
#
|
|
20
|
+
# all: service dbi ts
|
|
21
|
+
#
|
|
22
|
+
|
|
23
|
+
build_dir := $(node -e "console.log(require('./package.json').main.replace(/^.\//, '').split('/')[0])")
|
|
24
|
+
src_files := $(shell find src -name '*.ts')
|
|
25
|
+
build_files := $(patsubst src/%.ts,$(build_dir)/%.js,$(src_files))
|
|
26
|
+
|
|
27
|
+
# General utilities
|
|
28
|
+
clean:
|
|
29
|
+
yarn dlx rimraf ./$(build_dir) src/generated
|
|
30
|
+
|
|
31
|
+
# Typescript items
|
|
32
|
+
ts: $(word 1, $(build_files))
|
|
33
|
+
|
|
34
|
+
$(word 1, $(build_files)): $(src_files)
|
|
35
|
+
./node_modules/.bin/tsc -p tsconfig.build.json
|
|
36
|
+
|
|
37
|
+
service: src/generated/service/index.ts
|
|
38
|
+
|
|
39
|
+
src/generated/service/index.ts: api/${SERVICE_NAME}.yaml
|
|
40
|
+
echo "Building service interface"
|
|
41
|
+
yarn dlx openapi-typescript-express ./api/${SERVICE_NAME}.yaml \
|
|
42
|
+
--output ./src/generated/service/index.ts
|
|
43
|
+
./node_modules/.bin/prettier ./src/generated/service/index.ts --write
|
|
44
|
+
|
|
45
|
+
# Postgres database things
|
|
46
|
+
export PGUSER ?= postgres
|
|
47
|
+
export PGPASSWORD ?= postgres
|
|
48
|
+
export PGHOST ?= localhost
|
|
49
|
+
|
|
50
|
+
db-ci:
|
|
51
|
+
yarn run-pg-sql -q postgres ./migrations/setup/ci_setup.sql
|
|
52
|
+
yarn run-pg-sql -q postgres ./migrations/setup/db_setup.sql
|
|
53
|
+
yarn migration:apply
|
|
54
|
+
yarn run-pg-sql $(DB_NAME) ./migrations/setup/dev_setup.sql
|
|
55
|
+
|
|
56
|
+
db-drop:
|
|
57
|
+
yarn run-pg-sql -q postgres -e "DROP DATABASE IF EXISTS $(DB_NAME);"
|
|
58
|
+
|
|
59
|
+
db+:
|
|
60
|
+
yarn migration:apply
|
|
61
|
+
|
|
62
|
+
db-:
|
|
63
|
+
yarn migration:undo
|
|
64
|
+
|
|
65
|
+
db-clean: db-drop db-ci
|
|
66
|
+
|
|
67
|
+
dbi:
|
|
68
|
+
echo "Generating database types"
|
|
69
|
+
DATABASE_URL=postgres://$(PGUSER):$(PGPASSWORD)@$(PGHOST)/$(DB_NAME) yarn kysely-codegen \
|
|
70
|
+
--dialect postgres --schema public \
|
|
71
|
+
--out-file src/generated/database.ts
|
package/README.md
CHANGED
|
@@ -38,3 +38,4 @@ This module has the following core functionality:
|
|
|
38
38
|
7. Setup infrastructure for interservice calls with tracing.
|
|
39
39
|
8. Provide a central service runner that handles loading your service and getting to a running state in both development and production environments.
|
|
40
40
|
|
|
41
|
+
Please see the plop-based [project builder](../create) for an easy way to build an example project.
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openapi-typescript-infra/service",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "An opinionated framework for building configuration driven services - web, api, or job. Uses OpenAPI, pino logging, express, confit, Typescript and Jest.",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "jest",
|
|
8
8
|
"lint": "eslint .",
|
|
9
|
-
"build": "tsc -p tsconfig.build.json && yarn dlx
|
|
9
|
+
"build": "tsc -p tsconfig.build.json && yarn dlx glob-chmod 755 build/bin/*",
|
|
10
10
|
"watch": "tsc -p tsconfig.json -w --preserveWatchOutput",
|
|
11
11
|
"clean": "npx rimraf ./build",
|
|
12
12
|
"prepublishOnly": "yarn build",
|