Skip to content

Commit

Permalink
Merge pull request #156 from AthennaIO/develop
Browse files Browse the repository at this point in the history
Better logs when building/cleaning code and register signals on Ignite load and TS v5
  • Loading branch information
jlenon7 authored Mar 24, 2023
2 parents fc353d7 + c7f7afb commit 0cace2c
Show file tree
Hide file tree
Showing 9 changed files with 329 additions and 237 deletions.
2 changes: 1 addition & 1 deletion bin/artisan.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env node
#!/usr/bin/env node --input-type=module --experimental-import-meta-resolve

/**
* @athenna/core
Expand Down
483 changes: 280 additions & 203 deletions package-lock.json

Large diffs are not rendered by default.

30 changes: 15 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@athenna/core",
"version": "3.1.9",
"version": "3.2.0",
"description": "The plug and play Node.js framework.",
"license": "MIT",
"author": "João Lenon <[email protected]>",
Expand Down Expand Up @@ -62,14 +62,14 @@
"semver": "^7.3.8"
},
"devDependencies": {
"@athenna/artisan": "^3.3.8",
"@athenna/common": "^3.4.6",
"@athenna/config": "^3.2.5",
"@athenna/http": "^3.4.4",
"@athenna/ioc": "^3.1.8",
"@athenna/logger": "^3.1.7",
"@athenna/test": "^3.2.3",
"@athenna/view": "^3.0.7",
"@athenna/artisan": "^3.4.0",
"@athenna/common": "^3.5.0",
"@athenna/config": "^3.3.0",
"@athenna/http": "^3.5.0",
"@athenna/ioc": "^3.2.0",
"@athenna/logger": "^3.2.0",
"@athenna/test": "^3.3.0",
"@athenna/view": "^3.1.0",
"@japa/assert": "^1.3.6",
"@japa/run-failed-tests": "^1.1.0",
"@japa/runner": "^2.2.2",
Expand All @@ -87,15 +87,15 @@
"@types/pluralize": "^0.0.29",
"@types/sinon": "^10.0.13",
"@types/uuid": "^9.0.0",
"@typescript-eslint/eslint-plugin": "^5.48.1",
"@typescript-eslint/parser": "^5.48.1",
"@typescript-eslint/eslint-plugin": "^5.56.0",
"@typescript-eslint/parser": "^5.56.0",
"c8": "^7.12.0",
"cls-rtracer": "^2.6.2",
"commitizen": "^4.2.6",
"cross-env": "^7.0.3",
"cz-conventional-changelog": "^3.3.0",
"eslint": "^8.32.0",
"eslint-config-prettier": "^8.6.0",
"eslint": "^8.36.0",
"eslint-config-prettier": "^8.8.0",
"eslint-config-standard": "^17.0.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-n": "^15.6.1",
Expand All @@ -106,12 +106,12 @@
"lint-staged": "^12.5.0",
"minimist": "^1.2.7",
"nodemon": "^2.0.21",
"prettier": "^2.8.3",
"prettier": "^2.8.7",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"sinon": "^15.0.2",
"ts-node": "^10.9.1",
"typescript": "^4.9.4"
"typescript": "^5.0.2"
},
"c8": {
"all": true,
Expand Down
2 changes: 1 addition & 1 deletion scripts/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../tsconfig.json",
"include": ["../**/*"],
"exclude": ["../bin", "../build", "../tests", "../scripts", "../node_modules"]
"exclude": ["../bin", "../tests", "../scripts", "../node_modules"]
}
26 changes: 21 additions & 5 deletions src/Commands/BuildCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,38 @@ export class BuildCommand extends BaseCommand {

public async handle(): Promise<void> {
if (this.clean) {
this.logger.simple('({bold,green} [ CLEANING APPLICATION ])\n')

const folder = await new Folder(Path.pwd()).load()
const files = folder.getFilesByPattern(
`!(${this.ignoreOnClean})/**/*.@(js|d.ts)`,
`!(${this.ignoreOnClean})/**/*.@(js|d.ts|js.map)`,
)

await Exec.concurrently(files, file => file.remove()).then(() =>
this.logger.success('Application successfully cleaned.'),
await this.logger.promiseSpinner(
() => Exec.concurrently(files, file => file.remove()),
{
stream: process.stdout,
text: 'Cleaning all .js, .d.ts and .js.map files from your application',
successText: 'Application successfully cleaned',
failText: 'Failed to clean your application:',
},
)

return
}

this.logger.simple('({bold,green} [ BUILDING APPLICATION ])\n')

const tsConfig = await this.getTsConfig()

await Exec.command(`${Path.bin('tsc')} --project ${tsConfig.path}`).then(
() => this.logger.success('Application successfully compiled.'),
await this.logger.promiseSpinner(
() => Exec.command(`${Path.bin('tsc')} --project ${tsConfig.path}`),
{
stream: process.stdout,
text: 'Compiling all .ts files from your application',
successText: 'Application successfully compiled',
failText: 'Failed to compile your application:',
},
)
}

Expand Down
3 changes: 1 addition & 2 deletions src/Ignite/Ignite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export class Ignite {
await this.setRcContentAndAppVars()
this.verifyNodeEngineVersion()
this.registerItselfToTheContainer()
this.setApplicationSignals()

return this
} catch (err) {
Expand Down Expand Up @@ -136,8 +137,6 @@ export class Ignite {

await LoadHelper.regootProviders()
await LoadHelper.preloadFiles()

this.setApplicationSignals()
} catch (err) {
await this.handleError(err)
}
Expand Down
6 changes: 6 additions & 0 deletions tests/Unit/Commands/BuildCommandTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export default class BuildCommandTest extends BaseCommandTest {
const { stdout, stderr } = await Artisan.callInChild('build', this.artisan)

assert.deepEqual(stderr, '')
assert.isTrue(stdout.includes('[ BUILDING APPLICATION ]'))
assert.isTrue(stdout.includes('Compiling all .ts files from your application'))
assert.isTrue(stdout.includes('Application successfully compiled'))
assert.isTrue(await File.exists(Path.src('Applications/Artisan.js')))
assert.isTrue(await File.exists(Path.src('Applications/Artisan.d.ts')))
Expand All @@ -37,6 +39,8 @@ export default class BuildCommandTest extends BaseCommandTest {
const { stdout, stderr } = await Artisan.callInChild('build', this.artisan)

assert.deepEqual(stderr, '')
assert.isTrue(stdout.includes('[ BUILDING APPLICATION ]'))
assert.isTrue(stdout.includes('Compiling all .ts files from your application'))
assert.isTrue(stdout.includes('Application successfully compiled'))
assert.isTrue(await File.exists(Path.src('Applications/Artisan.js')))
assert.isTrue(await File.exists(Path.src('Applications/Artisan.d.ts')))
Expand All @@ -50,6 +54,8 @@ export default class BuildCommandTest extends BaseCommandTest {
const { stdout, stderr } = await Artisan.callInChild('build --clean', this.artisan)

assert.deepEqual(stderr, '')
assert.isTrue(stdout.includes('[ CLEANING APPLICATION ]'))
assert.isTrue(stdout.includes('Cleaning all .js, .d.ts and .js.map files from your application'))
assert.isTrue(stdout.includes('Application successfully cleaned'))
assert.isFalse(await File.exists(Path.src('Applications/Artisan.js')))
assert.isFalse(await File.exists(Path.src('Applications/Artisan.d.ts')))
Expand Down
12 changes: 3 additions & 9 deletions tests/Unit/Ignite/IgniteTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,7 @@ export default class IgniteTest extends BaseTest {
SIGTERM: () => (SIGTERM = true),
})

const ignite = await new Ignite().load(Config.get('meta'))

await ignite.fire(['console'])
await new Ignite().load(Config.get('meta'))

process.emit('SIGINT')
process.emit('SIGTERM')
Expand All @@ -199,14 +197,12 @@ export default class IgniteTest extends BaseTest {

const ignite = await new Ignite().load(Config.get('meta'))

await ignite.fire(['console'])

Config.set('app.signals', {
SIGINT: () => (SIGINT = false),
SIGTERM: () => (SIGTERM = false),
})

await ignite.fire(['console'])
await ignite.load(Config.get('meta'))

process.emit('SIGINT')
process.emit('SIGTERM')
Expand Down Expand Up @@ -252,9 +248,7 @@ export default class IgniteTest extends BaseTest {
SIGTERM: undefined, // will set the default signal
})

const ignite = await new Ignite().load(Config.get('meta'))

await ignite.fire(['console'])
await new Ignite().load(Config.get('meta'))

const events = process.eventNames()

Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@
}
},
"include": ["./**/*", "hello/node_modules"],
"exclude": ["build", "node_modules"]
"exclude": ["node_modules"]
}

0 comments on commit 0cace2c

Please sign in to comment.