Skip to content

Commit

Permalink
Merge pull request #241 from AthennaIO/develop
Browse files Browse the repository at this point in the history
chore(npm): update dependencies
  • Loading branch information
jlenon7 authored Dec 31, 2024
2 parents d996a27 + 65a520e commit c111c76
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 292 deletions.
223 changes: 106 additions & 117 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@athenna/core",
"version": "5.6.0",
"version": "5.7.0",
"description": "One foundation for multiple applications.",
"license": "MIT",
"author": "João Lenon <lenon@athenna.io>",
Expand Down Expand Up @@ -82,10 +82,10 @@
},
"devDependencies": {
"@athenna/artisan": "^5.3.0",
"@athenna/common": "^5.3.0",
"@athenna/common": "^5.5.0",
"@athenna/config": "^5.1.0",
"@athenna/cron": "^5.4.0",
"@athenna/http": "^5.6.0",
"@athenna/http": "^5.10.0",
"@athenna/ioc": "^5.0.0",
"@athenna/logger": "^5.1.0",
"@athenna/test": "^5.2.0",
Expand Down
5 changes: 5 additions & 0 deletions src/applications/Http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ export class Http {

ioc.safeUse('Athenna/Core/HttpRoute').register()

if (process.argv.includes('--vite')) {
await server.viteReady()
}

await server.listen({ host: options.host, port: options.port })

if (Config.notExists('rc.bootLogs') || Config.is('rc.bootLogs', false)) {
Expand Down Expand Up @@ -79,6 +83,7 @@ export class Http {
await kernel.registerHelmet()
await kernel.registerStatic()
await kernel.registerSwagger()
await kernel.registerVite()
await kernel.registerRateLimit()
await kernel.registerRTracer(options.trace)
await kernel.registerLoggerTerminator()
Expand Down
35 changes: 2 additions & 33 deletions src/commands/BuildCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,46 +110,15 @@ export class BuildCommand extends BaseCommand {
}

public async getViteConfig(vite: any) {
const defaultConfig = {
root: Path.pwd(),
assetsUrl: '/assets',
buildDirectory: 'public/assets',
logLevel: 'silent',
css: {
preprocessorOptions: {
scss: {
api: 'modern'
}
}
},
build: {
assetsDir: '',
manifest: true,
emptyOutDir: true,
outDir: 'public/assets',
assetsInlineLimit: 0,
rollupOptions: {
output: {
entryFileNames: '[name].js',
chunkFileNames: '[name].js',
assetFileNames: '[name].[ext]'
}
}
}
}

const { config: fileConfig } = await vite.loadConfigFromFile(
const { config } = await vite.loadConfigFromFile(
{
command: 'build',
mode: 'development'
mode: 'production'
},
undefined,
Path.pwd()
)

const config = vite.mergeConfig(defaultConfig, fileConfig)
await vite.build(config)

return config
}
}
87 changes: 2 additions & 85 deletions src/commands/ServeCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ export class ServeCommand extends BaseCommand {

@Option({
signature: '-v, --vite',
description: 'Use vite to build your application static files.',
description:
'Turn on vite dev server for HMR and static files compilation.',
default: false
})
public vite: boolean
Expand All @@ -41,24 +42,6 @@ export class ServeCommand extends BaseCommand {
Path.bin(`main.${Path.ext()}`)
)

if (this.vite) {
const formerNodeEnv = Env('NODE_ENV')

const vite = await this.getVite()
const config = await this.getViteConfig(vite)

await vite.build(config)

Log.channelOrVanilla('application').success(
'Static files successfully compiled with ({yellow} vite)'
)

/**
* Vite changes NODE_ENV when building which we need to avoid.
*/
process.env.NODE_ENV = formerNodeEnv
}

if (this.watch) {
const nodemon = this.getNodemon()

Expand Down Expand Up @@ -98,24 +81,6 @@ export class ServeCommand extends BaseCommand {

console.clear()

if (this.vite) {
const formerNodeEnv = Env('NODE_ENV')

const vite = await this.getVite()
const config = await this.getViteConfig(vite)

await vite.build(config)

Log.channelOrVanilla('application').success(
'Static files successfully recompiled with ({yellow} vite)'
)

/**
* Vite changes NODE_ENV when building which we need to avoid.
*/
process.env.NODE_ENV = formerNodeEnv
}

Log.channelOrVanilla('application').success(
'Application successfully restarted'
)
Expand All @@ -135,52 +100,4 @@ export class ServeCommand extends BaseCommand {

return require('nodemon')
}

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

public async getViteConfig(vite: any) {
const defaultConfig = {
root: Path.pwd(),
assetsUrl: '/assets',
buildDirectory: 'public/assets',
logLevel: 'silent',
css: {
preprocessorOptions: {
scss: {
api: 'modern'
}
}
},
build: {
assetsDir: '',
manifest: true,
emptyOutDir: true,
outDir: 'public/assets',
assetsInlineLimit: 0,
rollupOptions: {
output: {
entryFileNames: '[name].js',
chunkFileNames: '[name].js',
assetFileNames: '[name].[ext]'
}
}
}
}

const { config: fileConfig } = await vite.loadConfigFromFile(
{
command: 'build',
mode: 'development'
},
undefined,
Path.pwd()
)

const config = vite.mergeConfig(defaultConfig, fileConfig)
await vite.build(config)

return config
}
}
4 changes: 0 additions & 4 deletions tests/fixtures/consoles/build-vite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ vite.loadConfigFromFile = function () {
return { config: {} }
}

vite.mergeConfig = function () {
return {}
}

vite.build = function () {
return this
}
Expand Down
25 changes: 0 additions & 25 deletions tests/fixtures/consoles/serve-vite-with-logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@
* file that was distributed with this source code.
*/

import { Mock } from '@athenna/test'
import { Path } from '@athenna/common'
import { ViewProvider } from '@athenna/view'
import { Rc, Config } from '@athenna/config'
import { LoggerProvider } from '@athenna/logger'
import { ServeCommand } from '#src/commands/ServeCommand'
import { Artisan, ConsoleKernel, ArtisanProvider } from '@athenna/artisan'

new ViewProvider().register()
Expand All @@ -27,29 +25,6 @@ Path.mergeDirs(Config.get('rc.directories', {}))

await new ConsoleKernel().registerCommands()

const vite = function () {
return Mock.fake()
}

vite.loadConfigFromFile = function () {
return { config: {} }
}

vite.mergeConfig = function () {
return {}
}

vite.build = function () {
return this
}

const vitePluginRestart = function () {
return Mock.fake()
}

Config.set('rc.bootLogs', true)

Mock.when(ServeCommand.prototype, 'getVite').return(vite)
Mock.when(ServeCommand.prototype, 'getVitePluginRestart').return(vitePluginRestart)

await Artisan.parse(process.argv)
25 changes: 0 additions & 25 deletions tests/fixtures/consoles/serve-vite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@
* file that was distributed with this source code.
*/

import { Mock } from '@athenna/test'
import { Path } from '@athenna/common'
import { ViewProvider } from '@athenna/view'
import { Rc, Config } from '@athenna/config'
import { LoggerProvider } from '@athenna/logger'
import { ServeCommand } from '#src/commands/ServeCommand'
import { Artisan, ConsoleKernel, ArtisanProvider } from '@athenna/artisan'

new ViewProvider().register()
Expand All @@ -27,27 +25,4 @@ Path.mergeDirs(Config.get('rc.directories', {}))

await new ConsoleKernel().registerCommands()

const vite = function () {
return Mock.fake()
}

vite.loadConfigFromFile = function () {
return { config: {} }
}

vite.mergeConfig = function () {
return {}
}

vite.build = function () {
return this
}

const vitePluginRestart = function () {
return Mock.fake()
}

Mock.when(ServeCommand.prototype, 'getVite').return(vite)
Mock.when(ServeCommand.prototype, 'getVitePluginRestart').return(vitePluginRestart)

await Artisan.parse(process.argv)

0 comments on commit c111c76

Please sign in to comment.