Skip to content

Commit 732c208

Browse files
authored
Merge pull request #13 from stacksjs/chore/add-clarity
chore: add clarity
2 parents 980a6c3 + 7b74e66 commit 732c208

File tree

9 files changed

+88
-60
lines changed

9 files changed

+88
-60
lines changed

bun.lock

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55
"name": "bun-ts-starter",
66
"devDependencies": {
77
"@stacksjs/bumpx": "^0.1.17",
8+
"@stacksjs/clarity": "^0.3.23",
89
"@stacksjs/docs": "^0.70.23",
910
"@stacksjs/eslint-config": "^4.14.0-beta.3",
1011
"@stacksjs/gitlint": "^0.1.5",
1112
"@stacksjs/logsmith": "^0.1.8",
1213
"@types/bun": "^1.2.15",
1314
"buddy-bot": "^0.8.9",
1415
"bun-git-hooks": "^0.2.19",
15-
"bun-plugin-dtsx": "^0.21.12",
16+
"bun-plugin-dtsx": "0.9.5",
1617
"bunfig": "^0.10.0",
1718
"typescript": "^5.8.3",
1819
},
@@ -492,11 +493,13 @@
492493

493494
"@stacksjs/clapp": ["@stacksjs/clapp@0.1.16", "", { "bin": { "clapp": "dist/bin/cli.js", "@stacksjs/clapp": "dist/bin/cli.js" } }, "sha512-BDmYu9Rk/HHIVc4vQjgQO6MzXNMJvPG6ZGiiEAPQT8EAidx3/6S6O7kyY2UdfJSksiCd5SKFK+WYd1uAs88BrQ=="],
494495

496+
"@stacksjs/clarity": ["@stacksjs/clarity@0.3.23", "", { "bin": { "clarity": "dist/bin/cli.js" } }, "sha512-qrQjjcXWueBSM1vr1i0OmEMGYtCICVBtNvpVtoMLXIqR+jKAGRUqvguEOwg9vKth6VKMBqJ0FDpukJVJZhKGcg=="],
497+
495498
"@stacksjs/cli": ["@stacksjs/cli@0.70.23", "", {}, "sha512-pbu6xESAtRIppcEQlhmRq0yZa1lnYAwtQHh7DmfDcUgVjvahQGe7PXoX+m2dhdFDRthFIVuLeHvrAf1JYv/JOQ=="],
496499

497500
"@stacksjs/docs": ["@stacksjs/docs@0.70.23", "", { "dependencies": { "@iconify-json/carbon": "^1.2.8", "@shikijs/vitepress-twoslash": "^3.2.1", "@vite-pwa/assets-generator": "^1.0.0", "@vite-pwa/vitepress": "^1.0.0", "unocss": "^66.0.0", "unplugin-icons": "^22.1.0", "unplugin-vue-components": "^28.4.1", "vite-plugin-pwa": "^1.0.0", "vitepress": "1.6.3" } }, "sha512-kRk/aza/wQAAgF0fhUhG8bUHhqk3RnjBkZyoRW0fvYs3dLaAArJYX/uVquZixlQnqgizGeGZT986tEFjs5Ly+A=="],
498501

499-
"@stacksjs/dtsx": ["@stacksjs/dtsx@0.8.3", "", { "bin": { "dtsx": "dist/cli.js" } }, "sha512-+u/PEp478qHM8s7xT0AOZowd93mZ/5ptHFyiz0B/gcxmdrdNdM6bLIK5si5Uzy1cR5TOVN4oAB3+WMKDnJ3n1w=="],
502+
"@stacksjs/dtsx": ["@stacksjs/dtsx@0.9.4", "", { "bin": { "dtsx": "dist/bin/cli.js" } }, "sha512-nvAnS/xtYfFTStFfKJXvnzv6IJSUvY4c/o7RltUvnQqIVyZjHX3a0R0Gp2J5m7gkYO+6sneQs1WcY7e9NQyAsg=="],
500503

501504
"@stacksjs/error-handling": ["@stacksjs/error-handling@0.70.23", "", {}, "sha512-rQcgyum8eZnVjaF+eb6ip/IHK4GuOidwy1GcbAOqXeDwbc7oUxWFlpT7pKMeYbYa+DWZjV1WdolLxSL/orQeCw=="],
502505

@@ -782,7 +785,7 @@
782785

783786
"bun-git-hooks": ["bun-git-hooks@0.2.19", "", { "bin": { "git-hooks": "dist/bin/cli.js", "bun-git-hooks": "dist/bin/cli.js" } }, "sha512-h+YfI+/hCojKadnC9kfk71suZsjdgKShv82+bHp6UiHwH+XDyqavfAUt4NQTGRcIq7dSo2Mfh0QgCiAkCJOl8w=="],
784787

785-
"bun-plugin-dtsx": ["bun-plugin-dtsx@0.21.12", "", { "dependencies": { "@stacksjs/dtsx": "^0.8.1" } }, "sha512-VqGDRoTKEnkD508k9jRlcwFoEEJXtjqLMGN+brRP4/3vH0wfLZkZiWG5jc490roZOmphrQlo5NgfFB/j71+Qtg=="],
788+
"bun-plugin-dtsx": ["bun-plugin-dtsx@0.9.5", "", { "dependencies": { "@stacksjs/dtsx": "0.9.4" } }, "sha512-PMGr8kna2C7rbN5NFKW+nqj8TyXjs05Yh2QM7Xjp9PN1/cJMyZML3JJAJT0Ne/6eOYCcubmLM91r+Rix/cqn8Q=="],
786789

787790
"bun-types": ["bun-types@1.2.15", "", { "dependencies": { "@types/node": "*" } }, "sha512-NarRIaS+iOaQU1JPfyKhZm4AsUOrwUOqRNHY0XxI8GI8jYxiLXLcdjYMG9UKS+fwWasc1uw1htV9AX24dD+p4w=="],
788791

clarity.config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import type { ClarityOptions } from '@stacksjs/clarity'
2+
3+
const config: ClarityOptions = {
4+
verbose: false,
5+
}
6+
7+
export default config

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,15 @@
7070
},
7171
"devDependencies": {
7272
"@stacksjs/bumpx": "^0.1.17",
73+
"@stacksjs/clarity": "^0.3.23",
7374
"@stacksjs/docs": "^0.70.23",
7475
"@stacksjs/eslint-config": "^4.14.0-beta.3",
7576
"@stacksjs/gitlint": "^0.1.5",
7677
"@stacksjs/logsmith": "^0.1.8",
7778
"@types/bun": "^1.2.15",
7879
"buddy-bot": "^0.8.9",
7980
"bun-git-hooks": "^0.2.19",
80-
"bun-plugin-dtsx": "^0.21.12",
81+
"bun-plugin-dtsx": "0.9.5",
8182
"bunfig": "^0.10.0",
8283
"typescript": "^5.8.3"
8384
},

src/backups/directory.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import { mkdir, readdir, readFile, stat } from 'node:fs/promises'
55
import { dirname, join, relative } from 'node:path'
66
import { createGzip } from 'node:zlib'
77
import { BackupType } from '../types'
8+
import { Logger } from '@stacksjs/clarity'
9+
10+
const logger = new Logger('backupx:directory')
811

912
export async function backupDirectory(config: FileConfig, outputPath: string): Promise<BackupResult> {
1013
const startTime = Date.now()
@@ -15,8 +18,8 @@ export async function backupDirectory(config: FileConfig, outputPath: string): P
1518
const fullPath = join(outputPath, filename)
1619

1720
if (config.verbose) {
18-
console.warn(`📁 Starting directory backup for: ${config.path}`)
19-
console.warn(` Output: ${fullPath}`)
21+
logger.warn(`📁 Starting directory backup for: ${config.path}`)
22+
logger.warn(` Output: ${fullPath}`)
2023
}
2124

2225
try {
@@ -32,7 +35,7 @@ export async function backupDirectory(config: FileConfig, outputPath: string): P
3235
const filesToBackup = await getFilesToBackup(config)
3336

3437
if (config.verbose) {
35-
console.warn(` Found ${filesToBackup.length} files to backup`)
38+
logger.warn(` Found ${filesToBackup.length} files to backup`)
3639
}
3740

3841
// Create backup archive
@@ -41,9 +44,9 @@ export async function backupDirectory(config: FileConfig, outputPath: string): P
4144
const duration = Date.now() - startTime
4245

4346
if (config.verbose) {
44-
console.warn(`✅ Directory backup completed in ${duration}ms`)
45-
console.warn(` Size: ${formatBytes(size)}`)
46-
console.warn(` Files: ${filesToBackup.length}`)
47+
logger.warn(`✅ Directory backup completed in ${duration}ms`)
48+
logger.warn(` Size: ${formatBytes(size)}`)
49+
logger.warn(` Files: ${filesToBackup.length}`)
4750
}
4851

4952
return {
@@ -61,7 +64,7 @@ export async function backupDirectory(config: FileConfig, outputPath: string): P
6164
const errorMessage = error instanceof Error ? error.message : String(error)
6265

6366
if (config.verbose) {
64-
console.warn(`❌ Directory backup failed: ${errorMessage}`)
67+
logger.error(`❌ Directory backup failed: ${errorMessage}`)
6568
}
6669

6770
return {

src/backups/file.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import { copyFile, mkdir, stat, writeFile } from 'node:fs/promises'
44
import { dirname, extname, join } from 'node:path'
55
import { createGzip } from 'node:zlib'
66
import { BackupType } from '../types'
7+
import { Logger } from '@stacksjs/clarity'
8+
9+
const logger = new Logger('backupx:file')
710

811
export async function backupFile(config: FileConfig, outputPath: string): Promise<BackupResult> {
912
const startTime = Date.now()
@@ -15,8 +18,8 @@ export async function backupFile(config: FileConfig, outputPath: string): Promis
1518
const fullPath = join(outputPath, filename)
1619

1720
if (config.verbose) {
18-
console.warn(`📄 Starting file backup for: ${config.path}`)
19-
console.warn(` Output: ${fullPath}`)
21+
logger.warn(`📄 Starting file backup for: ${config.path}`)
22+
logger.warn(` Output: ${fullPath}`)
2023
}
2124

2225
try {
@@ -32,7 +35,7 @@ export async function backupFile(config: FileConfig, outputPath: string): Promis
3235
const fileStats = await stat(config.path)
3336

3437
if (config.verbose) {
35-
console.warn(` File size: ${formatBytes(fileStats.size)}`)
38+
logger.warn(` File size: ${formatBytes(fileStats.size)}`)
3639
}
3740

3841
let actualSize: number
@@ -53,11 +56,11 @@ export async function backupFile(config: FileConfig, outputPath: string): Promis
5356
const duration = Date.now() - startTime
5457

5558
if (config.verbose) {
56-
console.warn(`✅ File backup completed in ${duration}ms`)
57-
console.warn(` Size: ${formatBytes(actualSize)}`)
59+
logger.warn(`✅ File backup completed in ${duration}ms`)
60+
logger.warn(` Size: ${formatBytes(actualSize)}`)
5861
if (config.compress) {
5962
const compressionRatio = ((fileStats.size - actualSize) / fileStats.size * 100).toFixed(1)
60-
console.warn(` Compression: ${compressionRatio}% reduction`)
63+
logger.warn(` Compression: ${compressionRatio}% reduction`)
6164
}
6265
}
6366

@@ -76,7 +79,7 @@ export async function backupFile(config: FileConfig, outputPath: string): Promis
7679
const errorMessage = error instanceof Error ? error.message : String(error)
7780

7881
if (config.verbose) {
79-
console.warn(`❌ File backup failed: ${errorMessage}`)
82+
logger.warn(`❌ File backup failed: ${errorMessage}`)
8083
}
8184

8285
return {

src/backups/index.ts

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { BackupConfig, BackupResult, BackupSummary, DatabaseConfig, FileConfig } from '../types'
22
import { mkdir, readdir, stat, unlink } from 'node:fs/promises'
33
import { join } from 'node:path'
4+
import { Logger } from '@stacksjs/clarity'
45
import { BackupType } from '../types'
56
import { backupDirectory } from './directory'
67
import { backupFile } from './file'
@@ -13,9 +14,10 @@ export class BackupManager {
1314

1415
async createBackup(): Promise<BackupSummary> {
1516
const startTime = performance.now()
17+
const logger = new Logger('backupx:manager')
1618

1719
if (this.config.verbose) {
18-
console.warn('🚀 Starting backup process...')
20+
logger.warn('🚀 Starting backup process...')
1921
}
2022

2123
// Ensure output directory exists
@@ -28,7 +30,7 @@ export class BackupManager {
2830
// Process database backups
2931
for (const dbConfig of this.config.databases) {
3032
if (this.config.verbose) {
31-
console.warn(`\n📋 Processing database: ${dbConfig.name} (${dbConfig.type})`)
33+
logger.warn(`\n📋 Processing database: ${dbConfig.name} (${dbConfig.type})`)
3234
}
3335

3436
try {
@@ -49,7 +51,7 @@ export class BackupManager {
4951
})
5052

5153
if (this.config.verbose) {
52-
console.error(`❌ Failed to backup ${dbConfig.name}: ${errorMessage}`)
54+
logger.error(`❌ Failed to backup ${dbConfig.name}: ${errorMessage}`)
5355
}
5456
}
5557
}
@@ -68,7 +70,7 @@ export class BackupManager {
6870
}
6971

7072
if (this.config.verbose) {
71-
console.warn(`\n📁 Processing ${fileType}: ${fileConfig.name}`)
73+
logger.warn(`\n📁 Processing ${fileType}: ${fileConfig.name}`)
7274
}
7375

7476
try {
@@ -89,7 +91,7 @@ export class BackupManager {
8991
})
9092

9193
if (this.config.verbose) {
92-
console.error(`❌ Failed to backup ${fileConfig.name}: ${errorMessage}`)
94+
logger.error(`❌ Failed to backup ${fileConfig.name}: ${errorMessage}`)
9395
}
9496
}
9597
}
@@ -179,6 +181,7 @@ export class BackupManager {
179181
if (!this.config.retention)
180182
return
181183

184+
const logger = new Logger('backupx:retention')
182185
try {
183186
const files = await readdir(outputPath)
184187
const backupFiles: Array<{ name: string, path: string, stats: any, age: number }> = []
@@ -241,60 +244,59 @@ export class BackupManager {
241244
// Delete the files
242245
for (const filePath of filesToDelete) {
243246
await unlink(filePath)
244-
if (this.config.verbose) {
245-
console.warn(`🗑️ Removed old backup: ${filePath}`)
246-
}
247+
logger.warn(`🗑️ Removed old backup: ${filePath}`)
247248
}
248249

249-
if (filesToDelete.length > 0 && this.config.verbose) {
250-
console.warn(`🧹 Cleaned up ${filesToDelete.length} old backup files`)
250+
if (filesToDelete.length > 0) {
251+
logger.warn(`🧹 Cleaned up ${filesToDelete.length} old backup files`)
251252
}
252253
}
253254
catch (error) {
254255
if (this.config.verbose) {
255-
console.error(`⚠️ Failed to cleanup old backups: ${error}`)
256+
logger.error(`⚠️ Failed to cleanup old backups: ${error}`)
256257
}
257258
}
258259
}
259260

260261
private printSummary(summary: BackupSummary): void {
261-
console.warn('\n📊 Backup Summary:')
262-
console.warn(`⏱️ Total duration: ${summary.totalDuration.toFixed(2)}ms`)
263-
console.warn(`✅ Successful: ${summary.successCount}`)
264-
console.warn(`❌ Failed: ${summary.failureCount}`)
262+
const logger = new Logger('backupx:summary')
263+
logger.warn('\n📊 Backup Summary:')
264+
logger.warn(`⏱️ Total duration: ${summary.totalDuration.toFixed(2)}ms`)
265+
logger.warn(`✅ Successful: ${summary.successCount}`)
266+
logger.warn(`❌ Failed: ${summary.failureCount}`)
265267

266268
if (summary.databaseBackups.length > 0) {
267-
console.warn('\n🗄️ Database Backups:')
269+
logger.warn('\n🗄️ Database Backups:')
268270
for (const result of summary.databaseBackups) {
269271
const status = result.success ? '✅' : '❌'
270272
const size = result.success ? `${(result.size / 1024 / 1024).toFixed(2)} MB` : 'N/A'
271273
const duration = `${result.duration.toFixed(2)}ms`
272274

273-
console.warn(`${status} ${result.name} (${result.type}): ${size} in ${duration}`)
275+
logger.warn(`${status} ${result.name} (${result.type}): ${size} in ${duration}`)
274276

275277
if (!result.success && result.error) {
276-
console.warn(` Error: ${result.error}`)
278+
logger.warn(` Error: ${result.error}`)
277279
}
278280
}
279281
}
280282

281283
if (summary.fileBackups.length > 0) {
282-
console.warn('\n📁 File Backups:')
284+
logger.warn('\n📁 File Backups:')
283285
for (const result of summary.fileBackups) {
284286
const status = result.success ? '✅' : '❌'
285287
const size = result.success ? `${(result.size / 1024 / 1024).toFixed(2)} MB` : 'N/A'
286288
const duration = `${result.duration.toFixed(2)}ms`
287289
const fileCount = result.fileCount ? ` (${result.fileCount} files)` : ''
288290

289-
console.warn(`${status} ${result.name} (${result.type}): ${size} in ${duration}${fileCount}`)
291+
logger.warn(`${status} ${result.name} (${result.type}): ${size} in ${duration}${fileCount}`)
290292

291293
if (!result.success && result.error) {
292-
console.warn(` Error: ${result.error}`)
294+
logger.warn(` Error: ${result.error}`)
293295
}
294296
}
295297
}
296298

297-
console.warn('')
299+
logger.warn('')
298300
}
299301
}
300302

src/backups/mysql.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import type { BackupResult, MySQLConfig } from '../types'
22
import { writeFile } from 'node:fs/promises'
33
import { join } from 'node:path'
44
import { BackupType } from '../types'
5+
import { Logger } from '@stacksjs/clarity'
6+
7+
const logger = new Logger('backupx:mysql')
58

69
// Note: Bun's MySQL support is still in development
710
// For now, we'll use a placeholder implementation that shows the structure
@@ -42,9 +45,9 @@ export async function backupMySQL(
4245
const outputFile = join(outputPath, filename)
4346

4447
if (config.verbose) {
45-
console.warn(`📦 Starting MySQL backup for: ${config.name}`)
46-
console.warn(`💾 Output: ${outputFile}`)
47-
console.warn(`⚠️ MySQL support is coming soon to Bun!`)
48+
logger.warn(`📦 Starting MySQL backup for: ${config.name}`)
49+
logger.warn(`💾 Output: ${outputFile}`)
50+
logger.warn(`⚠️ MySQL support is coming soon to Bun!`)
4851
}
4952

5053
// Placeholder SQL dump
@@ -70,8 +73,8 @@ export async function backupMySQL(
7073
const stats = await Bun.file(outputFile).stat()
7174

7275
if (config.verbose) {
73-
console.warn(`⚠️ MySQL backup placeholder completed in ${duration.toFixed(2)}ms`)
74-
console.warn(`📊 File size: ${(stats.size / 1024).toFixed(2)} KB`)
76+
logger.warn(`⚠️ MySQL backup placeholder completed in ${duration.toFixed(2)}ms`)
77+
logger.warn(`📊 File size: ${(stats.size / 1024).toFixed(2)} KB`)
7578
}
7679

7780
return {
@@ -90,7 +93,7 @@ export async function backupMySQL(
9093
const errorMessage = error instanceof Error ? error.message : String(error)
9194

9295
if (config.verbose) {
93-
console.error(`❌ MySQL backup failed: ${errorMessage}`)
96+
logger.error(`❌ MySQL backup failed: ${errorMessage}`)
9497
}
9598

9699
return {

0 commit comments

Comments
 (0)