Skip to content
This repository was archived by the owner on Jan 23, 2025. It is now read-only.

Commit 8968c75

Browse files
committed
refactor: improvement to logs output
1 parent 2461654 commit 8968c75

13 files changed

+35
-30
lines changed

index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
import getops from 'getopts'
1111
import { isAbsolute, join } from 'path'
1212
import { isEmptyDir } from '@adonisjs/sink'
13-
import fancyLogs from '@poppinss/fancy-logs'
1413
import { Application } from '@poppinss/application'
1514
import { ensureDirSync, removeSync } from 'fs-extra'
1615

1716
import { tasks } from './tasks'
1817
import { CliState } from './src/contracts'
18+
import { error } from './src/logger'
1919

2020
/**
2121
* Running all the tasks to create a new project.
@@ -29,7 +29,7 @@ export async function runTasks () {
2929
* Ensure project name is defined
3030
*/
3131
if (!argv._.length) {
32-
fancyLogs.error('Project name is required to create a new app')
32+
error('Project name is required to create a new app')
3333
return
3434
}
3535

@@ -57,7 +57,7 @@ export async function runTasks () {
5757
'Make sure to define path to an empty directory',
5858
]
5959

60-
fancyLogs.error(errors.join(' '))
60+
error(errors.join(' '))
6161
return
6262
}
6363

@@ -70,7 +70,7 @@ export async function runTasks () {
7070
try {
7171
await task(absPath, application, state)
7272
} catch (error) {
73-
fancyLogs.error('Unable to create new project. Rolling back')
73+
error('Unable to create new project. Rolling back')
7474
removeSync(absPath)
7575
}
7676
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@
6666
},
6767
"dependencies": {
6868
"@adonisjs/fold": "^6.2.1",
69-
"@adonisjs/sink": "^2.2.2",
69+
"@adonisjs/sink": "^2.2.3",
7070
"@poppinss/application": "^1.0.10",
71-
"@poppinss/fancy-logs": "^1.1.0",
71+
"@poppinss/fancy-logs": "^1.1.1",
7272
"cli-width": "^2.2.0",
7373
"fs-extra": "^8.1.0",
7474
"getopts": "^2.2.5",

src/contracts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export type TaskFn = (
1212
absPath: string,
1313
application: ApplicationContract,
1414
state: CliState,
15-
) => void
15+
) => void | Promise<void>
1616

1717
export type CliState = {
1818
boilerplate: 'web' | 'api',

src/logger.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@
99

1010
import { Ora } from 'ora'
1111
import cliWidth from 'cli-width'
12-
import { yellow, dim, underline } from 'kleur'
12+
import { yellow, dim } from 'kleur'
13+
import { Logger } from '@poppinss/fancy-logs'
1314

1415
/**
1516
* Getting width of the stdout to put log messages
1617
* in one line
1718
*/
1819
const width = cliWidth()
20+
const logger = new Logger({ icon: false, underline: false, color: true })
1921

2022
/**
2123
* Log installing dependencies message
@@ -51,8 +53,13 @@ export function logInstall (list: string[], spinner: Ora, dev: boolean) {
5153
namedDependencies.push(`and ${outOfBounds} other${outOfBounds !== 1 ? 's' : ''}`)
5254
}
5355

54-
spinner.text = ` ${yellow(underline('install'))} ${namedDependencies.join(', ')} ${dim(`${dev ? '[dev]' : '[prod]'}`)}`
56+
spinner.text = ` ${yellow('install')} ${namedDependencies.join(', ')} ${dim(`${dev ? '[dev]' : '[prod]'}`)}`
5557
spinner.spinner = 'dots'
5658
spinner.color = 'gray'
5759
spinner.start()
5860
}
61+
62+
export const success: typeof logger.success = logger.success.bind(logger)
63+
export const error: typeof logger.error = logger.error.bind(logger)
64+
export const fatal: typeof logger.fatal = logger.fatal.bind(logger)
65+
export const create: typeof logger.create = logger.create.bind(logger)

tasks/copyTemplates.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
*/
99

1010
import { join } from 'path'
11-
import fancyLogs from '@poppinss/fancy-logs'
1211
import { TemplateFile } from '@adonisjs/sink'
1312

13+
import { create } from '../src/logger'
1414
import { TaskFn } from '../src/contracts'
1515
import { packages } from '../src/boilerplate/packages'
1616

@@ -53,7 +53,7 @@ const task: TaskFn = (absPath, _app, state) => {
5353
.apply(data)
5454
.commit()
5555

56-
fancyLogs.create({ message: template, icon: false })
56+
create(template)
5757
})
5858
}
5959

tasks/createEditorConfig.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88
*/
99

1010
import { IniFile } from '@adonisjs/sink'
11-
import fancyLogs from '@poppinss/fancy-logs'
12-
1311
import { TaskFn } from '../src/contracts'
12+
import { create } from '../src/logger'
1413

1514
/**
1615
* Creates `.editorconfig` inside the project root.
@@ -36,7 +35,7 @@ const task: TaskFn = (absPath) => {
3635
})
3736

3837
editorConfig.commit()
39-
fancyLogs.create({ message: '.editorconfig', icon: false })
38+
create('.editorconfig')
4039
}
4140

4241
export default task

tasks/createEnvFile.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99

1010
import randomstring from 'randomstring'
1111
import { EnvFile } from '@adonisjs/sink'
12-
import fancyLogs from '@poppinss/fancy-logs'
1312

1413
import { TaskFn } from '../src/contracts'
14+
import { create } from '../src/logger'
1515

1616
/**
1717
* Creates the `.env` file inside the project root. Also
@@ -27,7 +27,7 @@ const task: TaskFn = (absPath) => {
2727
env.set('APP_KEY', randomstring.generate(32))
2828

2929
env.commit()
30-
fancyLogs.create({ message: '.env, .env.example', icon: false })
30+
create('.env, .env.example')
3131
}
3232

3333
export default task

tasks/createGitIgnore.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
*/
99

1010
import { LinesFile } from '@adonisjs/sink'
11-
import fancyLogs from '@poppinss/fancy-logs'
1211

1312
import { TaskFn } from '../src/contracts'
13+
import { create } from '../src/logger'
1414

1515
/**
1616
* Creates `.gitignore` file inside the project root.
@@ -25,7 +25,7 @@ const task: TaskFn = (absPath) => {
2525
gitignore.add('.DS_STORE')
2626

2727
gitignore.commit()
28-
fancyLogs.create({ message: '.gitignore', icon: false })
28+
create('.gitignore')
2929
}
3030

3131
export default task

tasks/createPackageFile.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@
1010
import ora from 'ora'
1111
import { basename } from 'path'
1212
import { PackageFile } from '@adonisjs/sink'
13-
import fancyLogs from '@poppinss/fancy-logs'
1413

1514
import { TaskFn } from '../src/contracts'
16-
import { logInstall } from '../src/logger'
1715
import { packages } from '../src/boilerplate/packages'
16+
import { logInstall, create, fatal } from '../src/logger'
1817

1918
/**
2019
* Creates the `package.json` file in the project root and installs
@@ -85,10 +84,10 @@ const task: TaskFn = async (absPath, _app, state) => {
8584

8685
if (response && response.status === 1) {
8786
const errorMessage = useYarn ? 'yarn install failed' : 'npm install failed'
88-
fancyLogs.fatal({ message: errorMessage, stack: response.stderr.toString() })
87+
fatal({ message: errorMessage, stack: response.stderr.toString() })
8988
throw new Error('Installation failed')
9089
} else {
91-
fancyLogs.create({ message: 'package.json', icon: false })
90+
create('package.json')
9291
}
9392
}
9493

tasks/createRcFile.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
*/
99

1010
import { RcFile } from '@adonisjs/sink'
11-
import fancyLogs from '@poppinss/fancy-logs'
1211

12+
import { create } from '../src/logger'
1313
import { TaskFn } from '../src/contracts'
1414

1515
/**
@@ -38,7 +38,7 @@ const task: TaskFn = (absPath, _app, state) => {
3838
}
3939

4040
rcFile.commit()
41-
fancyLogs.create({ message: '.adonisrc.json', icon: false })
41+
create('.adonisrc.json')
4242
}
4343

4444
export default task

0 commit comments

Comments
 (0)