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

feat(command): improve integration with vite #239

Merged
merged 1 commit into from
Dec 28, 2024
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": "5.4.0",
"version": "5.5.0",
"description": "One foundation for multiple applications.",
"license": "MIT",
"author": "João Lenon <[email protected]>",
Expand Down
24 changes: 11 additions & 13 deletions src/commands/BuildCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

import { rimraf } from 'rimraf'
import { tsc } from '@athenna/tsconfig/tsc'
import { Path, Color } from '@athenna/common'
import { isAbsolute, join, parse } from 'node:path'
import { Path, Color, Module } from '@athenna/common'
import { BaseCommand, Option } from '@athenna/artisan'
import { copyfiles } from '@athenna/tsconfig/copyfiles'
import { UndefinedOutDirException } from '#src/exceptions/UndefinedOutDirException'
Expand Down Expand Up @@ -61,15 +61,8 @@ export class BuildCommand extends BaseCommand {
() => tsc(tsConfigPath)
)

if (include.length) {
tasks.addPromise(
`Copying included paths to ${outDirName} folder: ${includedPaths}`,
() => copyfiles(include, outDir)
)
}

if (this.vite) {
const vite = this.getVite()
const vite = await this.getVite()

tasks.addPromise(
`Compiling static files using ${Color.yellow.bold('vite')}`,
Expand All @@ -81,6 +74,13 @@ export class BuildCommand extends BaseCommand {
)
}

if (include.length) {
tasks.addPromise(
`Copying included paths to ${outDirName} folder: ${includedPaths}`,
() => copyfiles(include, outDir)
)
}

await tasks.run()

console.log()
Expand All @@ -105,10 +105,8 @@ export class BuildCommand extends BaseCommand {
return Path.pwd(Config.get('rc.commands.build.outDir'))
}

public getVite() {
const require = Module.createRequire(import.meta.url)

return require('vite')
public async getVite() {
return import('vite')
}

public async getViteConfig(vite: any) {
Expand Down
19 changes: 5 additions & 14 deletions src/commands/ServeCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ import { BaseCommand, Option } from '@athenna/artisan'
export class ServeCommand extends BaseCommand {
@Option({
signature: '-w, --watch',
description:
'Use nodemon to watch the application and restart on changes (also turn on vite --watch if using it).',
description: 'Use nodemon to watch the application and restart on changes.',
default: false
})
public watch: boolean
Expand Down Expand Up @@ -131,24 +130,16 @@ export class ServeCommand extends BaseCommand {
await Module.resolve(entrypoint, Config.get('rc.parentURL'))
}

public getVite() {
const require = Module.createRequire(import.meta.url)

return require('vite')
}

public getVitePluginRestart() {
const require = Module.createRequire(import.meta.url)

return require('vite-plugin-restart')
}

public getNodemon() {
const require = Module.createRequire(import.meta.url)

return require('nodemon')
}

public async getVite() {
return import('vite')
}

public async getViteConfig(vite: any) {
const defaultConfig = {
root: Path.pwd(),
Expand Down
Loading