Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(build): copy files to pwd #192

Merged
merged 1 commit into from
Oct 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@athenna/core",
"version": "4.10.0",
"version": "4.10.1",
"description": "The plug and play Node.js framework.",
"license": "MIT",
"author": "João Lenon <[email protected]>",
Expand Down
10 changes: 4 additions & 6 deletions src/commands/BuildCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import { rimraf } from 'rimraf'
import { tsc } from '@athenna/tsconfig/tsc'
import { Path, Color } from '@athenna/common'
import { BaseCommand } from '@athenna/artisan'
import { isAbsolute, join, parse } from 'node:path'
import { copyfiles } from '@athenna/tsconfig/copyfiles'
import { isAbsolute, join, parse, sep } from 'node:path'
import { UndefinedOutDirException } from '#src/exceptions/UndefinedOutDirException'

export class BuildCommand extends BaseCommand {
Expand Down Expand Up @@ -42,7 +42,7 @@ export class BuildCommand extends BaseCommand {
const compiler = Color.yellow.bold('tsc')
const includedFiles = Color.gray(include.join(', '))

const outDir = this.getOutDir(tsConfigPath)
const outDir = this.getOutDir()
const outDirName = Color.yellow.bold(parse(outDir).name)

const tasks = this.logger.task()
Expand All @@ -68,13 +68,11 @@ export class BuildCommand extends BaseCommand {
this.logger.success('Application successfully compiled')
}

private getOutDir(tsConfigPath: string): string {
private getOutDir(): string {
if (!Config.exists('rc.commands.build.outDir')) {
throw new UndefinedOutDirException()
}

return (
parse(tsConfigPath).dir + sep + Config.get('rc.commands.build.outDir')
)
return Path.pwd(Config.get('rc.commands.build.outDir'))
}
}
2 changes: 1 addition & 1 deletion tests/fixtures/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"strict": false,
"rootDir": ".",
"baseUrl": ".",
"outDir": "./build-relative",
"outDir": "../../build-relative",
"module": "NodeNext",
"target": "ESNext",
"moduleResolution": "NodeNext",
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"strict": false,
"rootDir": ".",
"baseUrl": ".",
"outDir": "./build",
"outDir": "../../build",
"module": "NodeNext",
"target": "ESNext",
"moduleResolution": "NodeNext",
Expand Down
4 changes: 0 additions & 4 deletions tests/helpers/BaseCommandTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ export class BaseCommandTest {
await Folder.safeRemove(Path.pwd('build'))
await Folder.safeRemove(Path.pwd('build-relative'))
await Folder.safeRemove(Path.tests('e2e'))
await Folder.safeRemove(Path.fixtures('dist'))
await Folder.safeRemove(Path.fixtures('build'))
await Folder.safeRemove(Path.fixtures('storage'))
await Folder.safeRemove(Path.fixtures('build-relative'))

await new File(Path.pwd('package.json')).setContent(this.originalPJson)
}
Expand Down
78 changes: 39 additions & 39 deletions tests/unit/commands/BuildCommandTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ export default class BuildCommandTest extends BaseCommandTest {
output.assertSucceeded()
output.assertLogged('Application successfully compiled')

assert.isTrue(Folder.existsSync(Path.fixtures('build')))
assert.isTrue(File.existsSync(Path.fixtures('build/app/hello.js')))
assert.isTrue(File.existsSync(Path.fixtures('build/app/hello.d.ts')))
assert.isTrue(Folder.existsSync(Path.pwd('build')))
assert.isTrue(File.existsSync(Path.pwd('build/app/hello.js')))
assert.isTrue(File.existsSync(Path.pwd('build/app/hello.d.ts')))
}

@Test()
Expand All @@ -33,27 +33,27 @@ export default class BuildCommandTest extends BaseCommandTest {
output.assertSucceeded()
output.assertLogged('Application successfully compiled')

assert.isTrue(Folder.existsSync(Path.fixtures('build-relative')))
assert.isTrue(File.existsSync(Path.fixtures('build-relative/app/hello.js')))
assert.isTrue(File.existsSync(Path.fixtures('build-relative/app/hello.d.ts')))
assert.isTrue(Folder.existsSync(Path.pwd('build-relative')))
assert.isTrue(File.existsSync(Path.pwd('build-relative/app/hello.js')))
assert.isTrue(File.existsSync(Path.pwd('build-relative/app/hello.d.ts')))
}

@Test()
public async shouldDeleteTheOldOutDirBeforeCompilingTheApplicationAgain({ assert, command }: Context) {
await command.run('build')

assert.isTrue(Folder.existsSync(Path.fixtures('build')))
assert.isTrue(File.existsSync(Path.fixtures('build/app/hello.js')))
assert.isTrue(File.existsSync(Path.fixtures('build/app/hello.d.ts')))
assert.isTrue(Folder.existsSync(Path.pwd('build')))
assert.isTrue(File.existsSync(Path.pwd('build/app/hello.js')))
assert.isTrue(File.existsSync(Path.pwd('build/app/hello.d.ts')))

const output = await command.run('build')

output.assertSucceeded()
output.assertLogged('Application successfully compiled')

assert.isTrue(Folder.existsSync(Path.fixtures('build')))
assert.isTrue(File.existsSync(Path.fixtures('build/app/hello.js')))
assert.isTrue(File.existsSync(Path.fixtures('build/app/hello.d.ts')))
assert.isTrue(Folder.existsSync(Path.pwd('build')))
assert.isTrue(File.existsSync(Path.pwd('build/app/hello.js')))
assert.isTrue(File.existsSync(Path.pwd('build/app/hello.d.ts')))
}

@Test()
Expand All @@ -66,11 +66,11 @@ export default class BuildCommandTest extends BaseCommandTest {
output.assertLogged('Copying included paths to build folder: README.md, LICENSE.md')
output.assertLogged('Application successfully compiled')

assert.isTrue(Folder.existsSync(Path.fixtures('build')))
assert.isTrue(File.existsSync(Path.fixtures('build/LICENSE.md')))
assert.isTrue(File.existsSync(Path.fixtures('build/README.md')))
assert.isTrue(File.existsSync(Path.fixtures('build/app/hello.js')))
assert.isTrue(File.existsSync(Path.fixtures('build/app/hello.d.ts')))
assert.isTrue(Folder.existsSync(Path.pwd('build')))
assert.isTrue(File.existsSync(Path.pwd('build/LICENSE.md')))
assert.isTrue(File.existsSync(Path.pwd('build/README.md')))
assert.isTrue(File.existsSync(Path.pwd('build/app/hello.js')))
assert.isTrue(File.existsSync(Path.pwd('build/app/hello.d.ts')))
}

@Test()
Expand All @@ -83,11 +83,11 @@ export default class BuildCommandTest extends BaseCommandTest {
output.assertLogged('Copying included paths to build folder: src/*, templates/*')
output.assertLogged('Application successfully compiled')

assert.isTrue(Folder.existsSync(Path.fixtures('build')))
assert.isTrue(File.existsSync(Path.fixtures('build/src/index.ts')))
assert.isTrue(File.existsSync(Path.fixtures('build/templates/exception.edge')))
assert.isTrue(File.existsSync(Path.fixtures('build/app/hello.js')))
assert.isTrue(File.existsSync(Path.fixtures('build/app/hello.d.ts')))
assert.isTrue(Folder.existsSync(Path.pwd('build')))
assert.isTrue(File.existsSync(Path.pwd('build/src/index.ts')))
assert.isTrue(File.existsSync(Path.pwd('build/templates/exception.edge')))
assert.isTrue(File.existsSync(Path.pwd('build/app/hello.js')))
assert.isTrue(File.existsSync(Path.pwd('build/app/hello.d.ts')))
}

@Test()
Expand All @@ -103,11 +103,11 @@ export default class BuildCommandTest extends BaseCommandTest {
output.assertLogged('Copying included paths to build folder: src/**/*Command.ts')
output.assertLogged('Application successfully compiled')

assert.isTrue(Folder.existsSync(Path.fixtures('build')))
assert.isTrue(File.existsSync(Path.fixtures('build/app/hello.js')))
assert.isTrue(File.existsSync(Path.fixtures('build/app/hello.d.ts')))
assert.isTrue(File.existsSync(Path.fixtures('build/src/commands/BuildCommand.ts')))
assert.isTrue(File.existsSync(Path.fixtures('build/src/commands/MakeServiceCommand.ts')))
assert.isTrue(Folder.existsSync(Path.pwd('build')))
assert.isTrue(File.existsSync(Path.pwd('build/app/hello.js')))
assert.isTrue(File.existsSync(Path.pwd('build/app/hello.d.ts')))
assert.isTrue(File.existsSync(Path.pwd('build/src/commands/BuildCommand.ts')))
assert.isTrue(File.existsSync(Path.pwd('build/src/commands/MakeServiceCommand.ts')))
}

@Test()
Expand All @@ -123,11 +123,11 @@ export default class BuildCommandTest extends BaseCommandTest {
output.assertLogged('Copying included paths to build folder: templates/**/*.edge')
output.assertLogged('Application successfully compiled')

assert.isTrue(Folder.existsSync(Path.fixtures('build')))
assert.isTrue(File.existsSync(Path.fixtures('build/templates/exception.edge')))
assert.isTrue(File.existsSync(Path.fixtures('build/templates/provider.edge')))
assert.isTrue(File.existsSync(Path.fixtures('build/app/hello.js')))
assert.isTrue(File.existsSync(Path.fixtures('build/app/hello.d.ts')))
assert.isTrue(Folder.existsSync(Path.pwd('build')))
assert.isTrue(File.existsSync(Path.pwd('build/templates/exception.edge')))
assert.isTrue(File.existsSync(Path.pwd('build/templates/provider.edge')))
assert.isTrue(File.existsSync(Path.pwd('build/app/hello.js')))
assert.isTrue(File.existsSync(Path.pwd('build/app/hello.d.ts')))
}

@Test()
Expand All @@ -139,9 +139,9 @@ export default class BuildCommandTest extends BaseCommandTest {
output.assertSucceeded()
output.assertLogged('Application successfully compiled')

assert.isTrue(Folder.existsSync(Path.fixtures('build-relative')))
assert.isTrue(File.existsSync(Path.fixtures('build-relative/app/hello.js')))
assert.isTrue(File.existsSync(Path.fixtures('build-relative/app/hello.d.ts')))
assert.isTrue(Folder.existsSync(Path.pwd('build-relative')))
assert.isTrue(File.existsSync(Path.pwd('build-relative/app/hello.js')))
assert.isTrue(File.existsSync(Path.pwd('build-relative/app/hello.d.ts')))
}

@Test()
Expand All @@ -165,9 +165,9 @@ export default class BuildCommandTest extends BaseCommandTest {
output.assertSucceeded()
output.assertLogged('Application successfully compiled')

assert.isTrue(Folder.existsSync(Path.fixtures('build')))
assert.isTrue(File.existsSync(Path.fixtures('build/app/hello.js')))
assert.isFalse(File.existsSync(Path.fixtures('build/.env')))
assert.isTrue(File.existsSync(Path.fixtures('build/app/hello.d.ts')))
assert.isTrue(Folder.existsSync(Path.pwd('build')))
assert.isTrue(File.existsSync(Path.pwd('build/app/hello.js')))
assert.isFalse(File.existsSync(Path.pwd('build/.env')))
assert.isTrue(File.existsSync(Path.pwd('build/app/hello.d.ts')))
}
}
Loading