generated from AthennaIO/Template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #154 from AthennaIO/develop
Add build command
- Loading branch information
Showing
12 changed files
with
179 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -137,3 +137,6 @@ out | |
|
||
# MacOS folder mapper file | ||
.DS_Store | ||
|
||
# Temp folder | ||
tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@athenna/core", | ||
"version": "3.1.7", | ||
"version": "3.1.8", | ||
"description": "The plug and play Node.js framework.", | ||
"license": "MIT", | ||
"author": "João Lenon <[email protected]>", | ||
|
@@ -44,6 +44,7 @@ | |
"./commands/MakeServiceCommand": "./src/Commands/MakeServiceCommand.js", | ||
"./commands/MakeTestCommand": "./src/Commands/MakeTestCommand.js", | ||
"./commands/ReplCommand": "./src/Commands/ReplCommand.js", | ||
"./commands/BuildCommand": "./src/Commands/BuildCommand.js", | ||
"./commands/ServeCommand": "./src/Commands/ServeCommand.js", | ||
"./commands/TestCommand": "./src/Commands/TestCommand.js" | ||
}, | ||
|
@@ -60,9 +61,9 @@ | |
"semver": "^7.3.8" | ||
}, | ||
"devDependencies": { | ||
"@athenna/artisan": "^3.3.6", | ||
"@athenna/common": "^3.4.4", | ||
"@athenna/config": "^3.2.3", | ||
"@athenna/artisan": "^3.3.7", | ||
"@athenna/common": "^3.4.5", | ||
"@athenna/config": "^3.2.5", | ||
"@athenna/http": "^3.4.3", | ||
"@athenna/ioc": "^3.1.8", | ||
"@athenna/logger": "^3.1.7", | ||
|
@@ -235,6 +236,7 @@ | |
"#src/Commands/MakeServiceCommand", | ||
"#src/Commands/MakeTestCommand", | ||
"#src/Commands/ServeCommand", | ||
"#src/Commands/BuildCommand", | ||
"#src/Commands/TestCommand", | ||
"#src/Commands/ReplCommand" | ||
], | ||
|
@@ -244,6 +246,7 @@ | |
"make:provider": "#src/Commands/MakeProviderCommand", | ||
"make:service": "#src/Commands/MakeServiceCommand", | ||
"make:test": "#src/Commands/MakeTestCommand", | ||
"build": "#src/Commands/BuildCommand", | ||
"serve": { | ||
"entrypoint": "#bin/http", | ||
"path": "#src/Commands/ServeCommand" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/** | ||
* @athenna/core | ||
* | ||
* (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 { Exec, File, Folder } from '@athenna/common' | ||
import { BaseCommand, Option } from '@athenna/artisan' | ||
|
||
export class BuildCommand extends BaseCommand { | ||
@Option({ | ||
signature: '--clean', | ||
description: 'Clean all .js and .d.ts files instead of building your code.', | ||
default: false, | ||
}) | ||
public clean: boolean | ||
|
||
@Option({ | ||
signature: '--ignore-on-clean [folders]', | ||
description: 'Ignore the given folders when cleaning the application.', | ||
default: 'tests|node_modules', | ||
}) | ||
public ignoreOnClean: string | ||
|
||
public static signature(): string { | ||
return 'build' | ||
} | ||
|
||
public static description(): string { | ||
return 'Compile your application code to JavaScript.' | ||
} | ||
|
||
public async handle(): Promise<void> { | ||
if (this.clean) { | ||
const folder = await new Folder(Path.pwd()).load() | ||
const files = folder.getFilesByPattern( | ||
`!(${this.ignoreOnClean})/**/*.@(js|d.ts)`, | ||
) | ||
|
||
await Exec.concurrently(files, file => file.remove()).then(() => | ||
this.logger.success('Application successfully cleaned.'), | ||
) | ||
|
||
return | ||
} | ||
|
||
const tsConfig = await this.getTsConfig() | ||
|
||
await Exec.command(`${Path.bin('tsc')} --project ${tsConfig.path}`).then( | ||
() => this.logger.success('Application successfully compiled.'), | ||
) | ||
} | ||
|
||
private getTsConfig(): Promise<File> { | ||
const path = Config.get( | ||
'rc.commandsManifest.build.tsconfig', | ||
'../../tmp/tsconfig.build.json', | ||
) | ||
|
||
const content = { | ||
extends: this.toPosix(Path.pwd('tsconfig.json')), | ||
include: [this.toPosix(Path.pwd('**/*'))], | ||
exclude: [this.toPosix(Path.tests()), this.toPosix(Path.nodeModules())], | ||
} | ||
|
||
return new File(path, JSON.stringify(content, null, 2)).load() | ||
} | ||
|
||
private toPosix(path: string): string { | ||
if (process.platform === 'win32') { | ||
return path.replace(/\\/g, '/').slice(2) | ||
} | ||
|
||
return path | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** | ||
* @athenna/core | ||
* | ||
* (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 { Artisan } from '@athenna/artisan' | ||
import { Exec, File, Folder } from '@athenna/common' | ||
import { Test, TestContext, Timeout } from '@athenna/test' | ||
import { BaseCommandTest } from '#tests/Helpers/BaseCommandTest' | ||
|
||
export default class BuildCommandTest extends BaseCommandTest { | ||
@Test() | ||
@Timeout(60000) | ||
public async shouldBeAbleToBuildTheApplication({ assert }: TestContext) { | ||
const { stdout, stderr } = await Artisan.callInChild('build', this.artisan) | ||
|
||
assert.deepEqual(stderr, '') | ||
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'))) | ||
assert.isFalse(await File.exists(Path.tests('Unit/Applications/ArtisanTest.js'))) | ||
assert.isFalse(await File.exists(Path.tests('Unit/Applications/ArtisanTest.d.ts'))) | ||
} | ||
|
||
@Test() | ||
@Timeout(60000) | ||
public async shouldBeAbleToBuildTheApplicationEvenIfTsConfigAlreadyExistsInTmp({ assert }: TestContext) { | ||
await Artisan.callInChild('build', this.artisan) | ||
|
||
await Folder.safeRemove(Path.pwd('tmp')) | ||
await Exec.command(`cd ${Path.pwd()} && sh scripts/clean`) | ||
|
||
const { stdout, stderr } = await Artisan.callInChild('build', this.artisan) | ||
|
||
assert.deepEqual(stderr, '') | ||
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'))) | ||
assert.isFalse(await File.exists(Path.tests('Unit/Applications/ArtisanTest.js'))) | ||
assert.isFalse(await File.exists(Path.tests('Unit/Applications/ArtisanTest.d.ts'))) | ||
} | ||
|
||
@Test() | ||
@Timeout(60000) | ||
public async shouldBeAbleToCleanAllJsAndDTsFilesFromTheApplication({ assert }: TestContext) { | ||
const { stdout, stderr } = await Artisan.callInChild('build --clean', this.artisan) | ||
|
||
assert.deepEqual(stderr, '') | ||
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'))) | ||
assert.isTrue(await File.exists(Path.stubs('main.js'))) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters