Skip to content

Commit

Permalink
feat(ts): move project to TS and add configurer
Browse files Browse the repository at this point in the history
  • Loading branch information
jlenon7 committed Mar 20, 2023
1 parent 5dd6fce commit 70ac9dd
Show file tree
Hide file tree
Showing 41 changed files with 5,448 additions and 3,534 deletions.
13 changes: 12 additions & 1 deletion .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:

jobs:
build:
runs-on: ubuntu-18.04
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
Expand All @@ -20,9 +20,20 @@ jobs:

- name: Install dependencies
run: npm install

- name: Transpile code
run: npm run build

- name: Install jq
run: sudo apt-get -y install jq

- name: Change import aliases to build
run: jq '.imports."#src"="./build/index.js" | .imports."#src/*"="./build/*.js"' package.json > tmp.json && mv tmp.json package.json

- name: Automatic GitHub Release
uses: justincy/[email protected]
id: release

- name: Publish to NPM Registry
run: npm publish --access public
if: steps.release.outputs.released == 'true'
Expand Down
46 changes: 45 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@ on:
- develop

jobs:
qodana:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: 'Qodana Scan'
uses: JetBrains/qodana-action@main
env:
QODANA_TOKEN: ${{ secrets.QODANA_TOKEN }}

linux:
runs-on: ubuntu-latest
services:
Expand All @@ -20,7 +31,7 @@ jobs:
strategy:
matrix:
node-version:
- 14.15.4
- 16.13.1
- 18.x
steps:
- uses: actions/checkout@v2
Expand All @@ -33,5 +44,38 @@ jobs:

- name: Install dependencies
run: npm install

- name: Run tests
run: npm run test:coverage

- name: Test code transpilation
run: npm run build

windows:
runs-on: windows-latest
services:
fake-smtp:
image: kurzdigital/fake-smtp
ports:
- "5025:5025"
- "5080:5080"
strategy:
matrix:
node-version:
- 16.13.1
- 18.x
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}

- name: Install dependencies
run: npm install

- name: Run tests
run: npm run test:coverage

- name: Test code transpilation
run: npm run build
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,13 @@ out
.yarn/install-state.gz
.pnp.*

# Transpiled code path
dist
build

# IDE
.idea
.fleet
.vscode

# Environment variables file
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Mail ✉️

> The Athenna email handler
> The Athenna email handler. Built on top of nodemailer.
[![GitHub followers](https://img.shields.io/github/followers/athennaio.svg?style=social&label=Follow&maxAge=2592000)](https://github.com/athennaio?tab=followers)
[![GitHub stars](https://img.shields.io/github/stars/AthennaIO/Mail.svg?style=social&label=Star&maxAge=2592000)](https://github.com/AthennaIO/Mail/stargazers/)
Expand Down
52 changes: 52 additions & 0 deletions bin/build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* @athenna/mail
*
* (c) João Lenon <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

import { Path, File, Exec } from '@athenna/common'

/*
|--------------------------------------------------------------------------
| TypeScript build file path
|--------------------------------------------------------------------------
|
| Where the TypeScript build file will be saved.
*/

const path = Path.nodeModules('@athenna/tsconfig.build.json')

/*
|--------------------------------------------------------------------------
| TypeScript Config
|--------------------------------------------------------------------------
|
| Create the tsconfig file for building the project.
*/

const tsconfig = await new File('../tsconfig.json').getContentAsJson()

delete tsconfig['ts-node']

tsconfig.compilerOptions.rootDir = '../../src'
tsconfig.compilerOptions.outDir = '../../build'

tsconfig.include = ['../../src']
tsconfig.exclude = ['../../bin', '../../node_modules', '../../tests']

/*
|--------------------------------------------------------------------------
| Compilation
|--------------------------------------------------------------------------
|
| Saving the file in some path, deleting old "build" folder, executing
| compilation and deleting the tsconfig file generated.
*/

const file = new File(path, '')
await file.setContent(JSON.stringify(tsconfig))
await Exec.command(`rimraf ../build && tsc --project ${path}`)
await file.remove()
23 changes: 17 additions & 6 deletions tests/index.js → bin/test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
/**
* @athenna/mail
*
* (c) Victor Tesoura Júnior <txsoura@athenna.io>
* (c) João Lenon <lenon@athenna.io>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

import { pathToFileURL } from 'node:url'

import { assert } from '@japa/assert'
import { Importer } from '@athenna/test'
import { specReporter } from '@japa/spec-reporter'
import { processCliArgs, configure, run } from '@japa/runner'
import { configure, processCliArgs, run } from '@japa/runner'

/*
|--------------------------------------------------------------------------
| Set IS_TS env.
|--------------------------------------------------------------------------
|
| Set the IS_TS environement variable to true. Very useful when using the
| Path helper.
*/

process.env.IS_TS = 'true'

/*
|--------------------------------------------------------------------------
Expand All @@ -30,11 +40,12 @@ import { processCliArgs, configure, run } from '@japa/runner'
configure({
...processCliArgs(process.argv.slice(2)),
...{
files: ['tests/**/*Test.js'],
files: ['tests/Unit/**/*Test.ts'],
plugins: [assert()],
reporters: [specReporter()],
importer: filePath => import(pathToFileURL(filePath).href),
importer: Importer.import,
},
timeout: 10000,
})

/*
Expand Down
9 changes: 5 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
version: '2.1'

version: '3.1'
services:
smtp:
container_name: athenna_smtp
image: kurzdigital/fake-smtp
ports:
- "5025:5025"
- "5080:5080"
- '5025:5025'
- '5080:5080'

Loading

0 comments on commit 70ac9dd

Please sign in to comment.