Skip to content

Commit

Permalink
Switch from tsimp to swc (#180)
Browse files Browse the repository at this point in the history
* Switch from tsimp to swc

* Fix dependencies

* Fix depcheck

* Fix some tests

* Add swcrc to build stages of dockerfile

* Updating version to 0.11.0

* Kind of fix dev

* Updating version to 0.11.0

* Add missing dep

* Readme updates

* Updating version to 0.11.0

* Updating version to 0.11.0

---------

Co-authored-by: dc-autobot[bot] <181364585+dc-autobot[bot]@users.noreply.github.com>
  • Loading branch information
mattdean-digicatapult and dc-autobot[bot] authored Sep 30, 2024
1 parent 0a617e8 commit f4e3b15
Show file tree
Hide file tree
Showing 14 changed files with 2,433 additions and 336 deletions.
7 changes: 5 additions & 2 deletions .depcheckrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"ignores": [
"@digicatapult/tsimp",
"prettier-plugin-organize-imports"
"@swc-node/register",
"concurrently",
"pino-colada",
"prettier-plugin-organize-imports",
"rimraf"
]
}
33 changes: 8 additions & 25 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@ jobs:
echo "REPO_NAME=$REPO_NAME" >> $GITHUB_OUTPUT
echo "ORG_NAME=$ORG_NAME" >> $GITHUB_OUTPUT
lint:
name: Run lint
static-checks:
name: Run Static Analysis Checks
strategy:
fail-fast: false
matrix:
command: [lint, depcheck, check]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -48,28 +52,7 @@ jobs:
- name: Install Packages
run: npm install # maybe this should be changed to npm ci
- name: Lint
run: npm run lint

dependency-check:
name: Run dependency check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20.x
- name: Cache Node.js modules
uses: actions/cache@v4
with:
path: ~/.npm # npm cache files are stored in `~/.npm` on Linux/macOS
key: ${{ runner.OS }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-node-
${{ runner.OS }}-
- name: Install Packages
run: npm install # maybe this should be changed to npm ci
- name: Dependency Check
run: npm run depcheck
run: npm run ${{ matrix.command }}

tests:
name: Run tests
Expand Down Expand Up @@ -113,7 +96,7 @@ jobs:

publish:
name: 'Publish package'
needs: [preconditions, lint, dependency-check, tests, check-version]
needs: [preconditions, static-checks, tests, check-version]
runs-on: ubuntu-latest
# comment the line above to force publish
if: ${{ needs.check-version.outputs.is_new_version == 'true' }}
Expand Down
41 changes: 8 additions & 33 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,18 @@ jobs:
echo "REPO_NAME=$REPO_NAME" >> $GITHUB_OUTPUT
echo "ORG_NAME=$ORG_NAME" >> $GITHUB_OUTPUT
lint:
name: Run lint
static-checks:
name: Run Static Analysis Checks
strategy:
fail-fast: false
matrix:
command: [lint, depcheck, check]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: 20.x

- name: Cache Node.js modules
uses: actions/cache@v4
with:
Expand All @@ -57,37 +59,10 @@ jobs:
restore-keys: |
${{ runner.OS }}-node-
${{ runner.OS }}-
- name: Install Packages
run: npm install # maybe this should be changed to npm ci

- name: Lint
run: npm run lint

dependency-check:
name: Run dependency check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: 20.x

- name: Cache Node.js modules
uses: actions/cache@v4
with:
path: ~/.npm # npm cache files are stored in `~/.npm` on Linux/macOS
key: ${{ runner.OS }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-node-
${{ runner.OS }}-
- name: Install Packages
run: npm install # maybe this should be changed to npm ci

- name: Dependency Check
run: npm run depcheck
- name: ${{ matrix.command }}
run: npm run ${{ matrix.command }}

tests:
name: Run tests
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ config/local.json

node_modules/
build
src/routes/swagger.json
src/routes/routes.ts
dist
coverage
Expand Down
29 changes: 29 additions & 0 deletions .swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"$schema": "https://swc.rs/schema.json",
"jsc": {
"parser": {
"syntax": "typescript",
"decorators": true,
"topLevelAwait": true,
"importMeta": true
},
"transform": {
"legacyDecorator": true,
"decoratorMetadata": true,
"useDefineForClassFields": true
},
"minify": {
"compress": {
"unused": true
},
"mangle": true
},
"target": "esnext"
},
"exclude": [
"/__tests__/"
],
"sourceMaps": true,
"isModule": true,
"minify": true
}
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci && npm cache clean --force

COPY tsoa.json tsconfig.json ./
COPY tsoa.json tsconfig.json .swcrc ./
COPY src ./src
RUN npm run build

Expand All @@ -21,7 +21,7 @@ WORKDIR /app
ARG NODE_ENV=test
ENV NODE_ENV=${NODE_ENV}

COPY .mocharc.json .eslint* ./
COPY .swcrc .eslint* ./
COPY tests ./tests

CMD ["npm", "run", "test"]
Expand All @@ -48,4 +48,4 @@ EXPOSE 3000 5002 5003
HEALTHCHECK --interval=5s --timeout=3s \
CMD curl -f http://localhost:3000/ || exit 1

ENTRYPOINT [ "node", "./build/index.js" ]
ENTRYPOINT [ "node", "./build/index.js" ]
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,26 @@ Network name: `testnet`

#### Starting Own Server

## Building and running

The following lifecycle commands can be run using `npm`

| command | description |
| ------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `depcheck` | Runs dependency analysis to ensure all package.json dependencies are used and included |
| `lint` | Static linting check with eslint |
| `lint:fix` | Static linting check with eslint fixing issues where possible |
| `check` | Check types are valid according to Typescript language words |
| `clean` | Remove build artefacts |
| `build` | Compile build artefacts including tsoa artefacts. Note this does not perform type checking |
| `tsoa:build` | Build tsoa artefacts `routes.ts` and `swagger.json` |
| `tsoa:watch` | Build tsoa artefacts `routes.ts` and `swagger.json` and watches for changes. Rebuilds on changes |
| `dev` | Runs `tsoa:watch` and a development server concurrently in watch mode. Can be used for live debugging. Configure with [environment variables](#environment-variables) |
| `start` | Start production server from build |
| `test` | Run unit tests. Configure with [environment variables](#environment-variables) |
| `test:integration` | Run integration tests |
| `test-watch` | Run unit tests and re-run on changes |

## Environment variables

The Envs are defined under `src > env.ts ` They are used to start up a container. They mostly have defaults and if you wish to overwrite these, provide them under `environment` in docker compose. For any envs that are an array of strings please provide them coma-separated like so: `- ENDPOINT=http://charlie:5002,ws://charlie:5003`.
Expand Down
Loading

0 comments on commit f4e3b15

Please sign in to comment.