Skip to content

Commit 6e40507

Browse files
committed
feat: add build command, fix bugs and update package versions.
1 parent 9417746 commit 6e40507

16 files changed

Lines changed: 106 additions & 11 deletions

File tree

packages/cache/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@h3ravel/cache",
3-
"version": "11.0.2",
3+
"version": "11.0.3",
44
"description": "Cache system with multiple drivers for H3ravel.",
55
"type": "module",
66
"main": "./dist/index.js",

packages/console/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@h3ravel/console",
3-
"version": "11.3.9",
3+
"version": "11.4.0",
44
"description": "CLI utilities for scaffolding, running migrations, tasks and for H3ravel.",
55
"type": "module",
66
"exports": {
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import { Logger, TaskManager } from '@h3ravel/shared'
2+
3+
import { ConsoleCommand } from '@h3ravel/core'
4+
import { execa } from 'execa'
5+
import preferredPM from 'preferred-pm'
6+
7+
export class BuildCommand extends ConsoleCommand {
8+
9+
/**
10+
* The name and signature of the console command.
11+
*
12+
* @var string
13+
*/
14+
protected signature: string = `build:
15+
{--m|minify=false : Minify your bundle output}
16+
`
17+
18+
/**
19+
* The console command description.
20+
*
21+
* @var string
22+
*/
23+
protected description: string = 'Build the app for production'
24+
25+
public async handle () {
26+
try {
27+
await this.fire()
28+
} catch (e) {
29+
Logger.error(e as any)
30+
}
31+
}
32+
33+
protected async fire () {
34+
const outDir = env('DIST_DIR', 'dist')
35+
36+
const pm = (await preferredPM(base_path()))?.name ?? 'pnpm'
37+
const minify = this.option('minify')
38+
const debug = Number(this.option('verbose', 0)) > 0
39+
const LOG_LEVELS = [
40+
'silent',
41+
'info',
42+
'warn',
43+
'error',
44+
]
45+
46+
const ENV_VARS = {
47+
EXTENDED_DEBUG: debug ? 'true' : 'false',
48+
CLI_BUILD: 'true',
49+
NODE_ENV: 'production',
50+
DIST_DIR: outDir,
51+
DIST_MINIFY: minify,
52+
LOG_LEVEL: LOG_LEVELS[Number(this.option('verbose', 0))]
53+
}
54+
55+
const silent = ENV_VARS.LOG_LEVEL === 'silent' ? '--silent' : null
56+
57+
Logger.log([['\n INFO ', 'bgBlue'], [' Creating Production Bundle', 'white']], '')
58+
console.log('')
59+
60+
await TaskManager.taskRunner(Logger.log([[' SUCCESS ', 'bgGreen'], [' Production Bundle Created', 'white']], '', false), async () => {
61+
await execa(
62+
pm,
63+
['tsdown', silent, '--config-loader', 'unconfig', '-c', 'tsdown.default.config.ts'].filter(e => e !== null),
64+
{ stdout: 'inherit', stderr: 'inherit', cwd: base_path(), env: Object.assign({}, process.env, ENV_VARS) }
65+
)
66+
console.log('')
67+
})
68+
}
69+
}

packages/console/src/Commands/MakeCommand.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ export class MakeCommand extends Command {
3030
| {--t|table : The table to migrate}
3131
| {--c|create : The table to be created}
3232
}
33+
{command : Create a new Musket command.
34+
| {--command : The terminal command that will be used to invoke the class}
35+
| {--force : Create the class even if the console command already exists}
36+
}
3337
{factory : Create a new model factory.}
3438
{seeder : Create a new seeder class.}
3539
{view : Create a new view.
@@ -70,6 +74,7 @@ export class MakeCommand extends Command {
7074
seeder: 'makeSeeder',
7175
model: 'makeModel',
7276
view: 'makeView',
77+
command: 'makeCommand',
7378
} as const
7479

7580
try {
@@ -157,6 +162,13 @@ export class MakeCommand extends Command {
157162
Logger.success('Factory support is not yet available')
158163
}
159164

165+
/**
166+
* Create a new Musket command
167+
*/
168+
protected makeCommand () {
169+
Logger.success('Musket command creation is not yet available')
170+
}
171+
160172
/**
161173
* Create a new seeder class
162174
*/

packages/console/src/Musket.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { build } from 'tsdown'
1414
import { glob } from 'node:fs/promises'
1515
import path from 'node:path'
1616
import { PostinstallCommand } from './Commands/PostinstallCommand'
17+
import { BuildCommand } from './Commands/BuildCommand'
1718

1819
/**
1920
* Musket is H3ravel's CLI tool
@@ -34,6 +35,7 @@ export class Musket {
3435
new MakeCommand(this.app, this.kernel),
3536
new ListCommand(this.app, this.kernel),
3637
new PostinstallCommand(this.app, this.kernel),
38+
new BuildCommand(this.app, this.kernel),
3739
]
3840

3941
commands.forEach(e => this.addCommand(e))

packages/console/src/TsdownConfig.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export const TsDownConfig: Options = {
1616
format: ['esm'],//, 'cjs'],
1717
target: 'node22',
1818
sourcemap: env === 'development',
19+
minify: !!process.env.DIST_MINIFY,
1920
clean: true,
2021
shims: true,
2122
copy: [{ from: 'public', to: outDir }, 'src/resources', 'src/database'],

packages/console/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
export * from './Commands/BuildCommand'
12
export * from './Commands/Command'
23
export * from './Commands/ListCommand'
34
export * from './Commands/MakeCommand'

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@h3ravel/core",
3-
"version": "1.9.7",
3+
"version": "1.10.0",
44
"description": "Core application container, lifecycle management and service providers for H3ravel.",
55
"type": "module",
66
"main": "./dist/index.js",

packages/database/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@h3ravel/database",
3-
"version": "11.2.4",
3+
"version": "11.2.5",
44
"description": "Modeling data and migration system for H3ravel.",
55
"type": "module",
66
"main": "./dist/index.js",

packages/filesystem/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@h3ravel/filesystem",
3-
"version": "0.2.2",
3+
"version": "0.3.0",
44
"description": "Filesystem manager for H3ravel.",
55
"type": "module",
66
"main": "./dist/index.js",

0 commit comments

Comments
 (0)