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 #184 from AthennaIO/develop
Move build command to core
- Loading branch information
Showing
11 changed files
with
706 additions
and
57 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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": "4.3.0", | ||
"version": "4.4.0", | ||
"description": "The plug and play Node.js framework.", | ||
"license": "MIT", | ||
"author": "João Lenon <[email protected]>", | ||
|
@@ -49,7 +49,8 @@ | |
"./commands/MakeTestCommand": "./src/commands/MakeTestCommand.js", | ||
"./commands/ReplCommand": "./src/commands/ReplCommand.js", | ||
"./commands/ServeCommand": "./src/commands/ServeCommand.js", | ||
"./commands/TestCommand": "./src/commands/TestCommand.js" | ||
"./commands/TestCommand": "./src/commands/TestCommand.js", | ||
"./commands/BuildCommand": "./src/commands/BuildCommand.js" | ||
}, | ||
"imports": { | ||
"#bin/*": "./bin/*.js", | ||
|
@@ -64,7 +65,7 @@ | |
}, | ||
"dependencies": { | ||
"pretty-repl": "^3.1.2", | ||
"semver": "^7.5.3" | ||
"semver": "^7.5.4" | ||
}, | ||
"devDependencies": { | ||
"@athenna/artisan": "^4.2.0", | ||
|
@@ -79,6 +80,7 @@ | |
"@typescript-eslint/parser": "^5.56.0", | ||
"c8": "^7.12.0", | ||
"commitizen": "^4.2.6", | ||
"copyfiles": "^2.4.1", | ||
"cross-env": "^7.0.3", | ||
"cz-conventional-changelog": "^3.3.0", | ||
"eslint": "^8.36.0", | ||
|
@@ -92,6 +94,7 @@ | |
"lint-staged": "^12.5.0", | ||
"prettier": "^2.8.7", | ||
"reflect-metadata": "^0.1.13", | ||
"rimraf": "^5.0.1", | ||
"ts-node": "^10.9.1", | ||
"typescript": "^5.0.2" | ||
}, | ||
|
@@ -225,6 +228,15 @@ | |
"stayAlive": true, | ||
"entrypoint": "#bin/repl", | ||
"path": "#src/commands/ReplCommand" | ||
}, | ||
"build": { | ||
"path": "#src/commands/BuildCommand", | ||
"tsconfig": "./tests/stubs/tsconfig.json", | ||
"metaFiles": [ | ||
"app/hello.edge", | ||
"LICENSE.md", | ||
".env" | ||
] | ||
} | ||
}, | ||
"services": [ | ||
|
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,85 @@ | ||
/** | ||
* @athenna/artisan | ||
* | ||
* (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 { BaseCommand } from '@athenna/artisan' | ||
import { isAbsolute, join, parse, sep } from 'node:path' | ||
import { Exec, Path, File, Color } from '@athenna/common' | ||
|
||
export class BuildCommand extends BaseCommand { | ||
public static signature(): string { | ||
return 'build' | ||
} | ||
|
||
public static description(): string { | ||
return 'Compile your application code from TypeScript to JavaScript.' | ||
} | ||
|
||
public async handle(): Promise<void> { | ||
this.logger.simple('({bold,green} [ BUILD APPLICATION ])\n') | ||
|
||
let tsConfigPath = Config.get('rc.commands.build.tsconfig') | ||
|
||
if (!isAbsolute(tsConfigPath)) { | ||
tsConfigPath = join(Path.pwd(), tsConfigPath) | ||
} | ||
|
||
const tsConfig = await new File(tsConfigPath).getContentAsJson() | ||
const metaFiles = Config.get('rc.commands.build.metaFiles', []).join(' ') | ||
const buildDir = | ||
parse(tsConfigPath).dir + sep + tsConfig.compilerOptions.outDir | ||
|
||
if (metaFiles.includes(' .env ')) { | ||
metaFiles.replace(' .env ', '') | ||
} | ||
|
||
const tasks = this.logger.task() | ||
|
||
tasks.add( | ||
`Delete old ${Color.yellow.bold(parse(buildDir).name)} folder`, | ||
async task => { | ||
await Exec.command(`${Path.nodeModulesBin('rimraf')} ${buildDir}`) | ||
.then(() => task.complete()) | ||
.catch(error => { | ||
task.fail() | ||
throw error | ||
}) | ||
}, | ||
) | ||
|
||
tasks.add('Compile the application', async task => { | ||
await Exec.command( | ||
`${Path.nodeModulesBin('tsc')} --project ${tsConfigPath}`, | ||
) | ||
.then(() => task.complete()) | ||
.catch(error => { | ||
task.fail() | ||
throw error | ||
}) | ||
}) | ||
|
||
if (metaFiles.length) { | ||
tasks.add(`Copy meta files: ${Color.gray(metaFiles)}`, async task => { | ||
await Exec.command( | ||
`${Path.nodeModulesBin('copyfiles')} ${metaFiles} ${buildDir}`, | ||
) | ||
.then(() => task.complete()) | ||
.catch(error => { | ||
task.fail() | ||
throw error | ||
}) | ||
}) | ||
} | ||
|
||
await tasks.run() | ||
|
||
console.log() | ||
|
||
this.logger.success('Application successfully compiled') | ||
} | ||
} |
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 @@ | ||
hello |
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 @@ | ||
hello |
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 @@ | ||
console.log('hello world!') |
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,27 @@ | ||
{ | ||
"ts-node": { | ||
"esm": true, | ||
"transpileOnly": true, | ||
"ignoreDiagnostics": [5104] | ||
}, | ||
"compilerOptions": { | ||
"strict": false, | ||
"rootDir": ".", | ||
"baseUrl": ".", | ||
"outDir": "build", | ||
"module": "NodeNext", | ||
"target": "ESNext", | ||
"moduleResolution": "NodeNext", | ||
"declaration": true, | ||
"skipLibCheck": true, | ||
"esModuleInterop": true, | ||
"removeComments": false, | ||
"resolveJsonModule": true, | ||
"experimentalDecorators": true, | ||
"useDefineForClassFields": false, | ||
"verbatimModuleSyntax": true, | ||
"forceConsistentCasingInFileNames": true | ||
}, | ||
"include": ["app"], | ||
"exclude": ["build", "node_modules"] | ||
} |
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,28 @@ | ||
/** | ||
* @athenna/artisan | ||
* | ||
* (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 { File, Folder } from '@athenna/common' | ||
import { Test, type Context } from '@athenna/test' | ||
import { BaseCommandTest } from '#tests/helpers/BaseCommandTest' | ||
|
||
export default class BuildCommandTest extends BaseCommandTest { | ||
@Test() | ||
public async shouldBeAbleToCompileTheApplication({ assert }: Context) { | ||
const { stdout, stderr } = await Artisan.callInChild('build', this.artisan) | ||
|
||
console.log(stderr) | ||
assert.isTrue(stdout.includes('Application successfully compiled')) | ||
assert.isTrue(Folder.existsSync(Path.stubs('build'))) | ||
assert.isFalse(File.existsSync(Path.stubs('build/.env'))) | ||
assert.isTrue(File.existsSync(Path.stubs('build/LICENSE.md'))) | ||
assert.isTrue(File.existsSync(Path.stubs('build/app/index.js'))) | ||
assert.isTrue(File.existsSync(Path.stubs('build/app/index.d.ts'))) | ||
} | ||
} |