Skip to content

Commit

Permalink
Merge pull request #150 from AthennaIO/develop
Browse files Browse the repository at this point in the history
chore(npm): update dependencies
  • Loading branch information
jlenon7 authored Mar 21, 2023
2 parents a92a58c + 5609008 commit 8a4ad6b
Show file tree
Hide file tree
Showing 9 changed files with 155 additions and 198 deletions.
67 changes: 43 additions & 24 deletions bin/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,55 +7,74 @@
* file that was distributed with this source code.
*/

import { Path, File, Exec } from '@athenna/common'
/* eslint-disable no-ex-assign */

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

/*
|--------------------------------------------------------------------------
| TypeScript build file path
| The tsconfig.build.json path and the compile command.
|--------------------------------------------------------------------------
|
| Where the TypeScript build file will be saved.
| The path where tsconfig.build.json will be created and the compilation
| command that will be used to compile the files.
*/

const path = Path.nodeModules('@athenna/tsconfig.build.json')
const compileCommand = `node_modules/.bin/tsc --project ${path}`

/*
|--------------------------------------------------------------------------
| TypeScript Config
| Before all hook.
|--------------------------------------------------------------------------
|
| Create the tsconfig file for building the project.
| This function will be executed before the compilation starts. Briefly,
| this function will create a tsconfig.build.json file with the correct
| configurations to compile the files such as rootDir, outDir, etc and
| also delete the old build folder if it exists.
*/

const tsconfig = JSON.parse(
new File('../tsconfig.json').getContentSync().toString(),
)

delete tsconfig['ts-node']
async function beforeAll() {
const tsconfig = await new File('../tsconfig.json').getContentAsBuilder()

tsconfig.compilerOptions.rootDir = '../../src'
tsconfig.compilerOptions.outDir = '../../build'
tsconfig.delete('ts-node')
tsconfig.set('include', ['../../src'])
tsconfig.set('compilerOptions.rootDir', '../../src')
tsconfig.set('compilerOptions.outDir', '../../build')
tsconfig.set('exclude', ['../../bin', '../../node_modules', '../../tests'])

tsconfig.include = ['../../src']
tsconfig.exclude = ['../../bin', '../../node_modules', '../../tests']
const oldBuild = new Folder(Path.pwd('/build'))
await new File(path, JSON.stringify(tsconfig.get())).load()

const tsconfigBuild = JSON.stringify(tsconfig)
if (oldBuild.folderExists) await oldBuild.remove()
}

/*
|--------------------------------------------------------------------------
| Compilation
| After all hook.
|--------------------------------------------------------------------------
|
| Saving the file in some path, deleting old "build" folder, executing
| compilation and deleting the tsconfig file generated.
| This function will be executed after some error occurs or after the compi
| lation finishes. This function just delete the tsconfig.build.json file if
| it exists.
*/

const file = new File(path, Buffer.from(tsconfigBuild))
async function afterAll() {
const tsConfigBuild = await new File(path).load()

if (file.fileExists) {
await file.remove()
if (tsConfigBuild.fileExists) await tsConfigBuild.remove()
}

await file.load()
await Exec.command(`rimraf ../build && tsc --project ${path}`)
await file.remove()
try {
await beforeAll()

const { stdout } = await Exec.command(compileCommand)

if (stdout) console.log(stdout)
} catch (error) {
if (!Is.Exception(error)) error = error.toAthennaException()

console.error(await error.prettify())
} finally {
await afterAll()
}
6 changes: 6 additions & 0 deletions node
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

# Node.js executable with all arguments required to run the application.
node="node --loader ts-node/esm --experimental-import-meta-resolve --no-warnings"

$node $@
Loading

0 comments on commit 8a4ad6b

Please sign in to comment.