-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add socio theme * Add generator package and theme script * Add support for themes in Logger * Add getTheme function to retrieve logger options from a theme
- Loading branch information
1 parent
c26bc13
commit 857b49c
Showing
9 changed files
with
131 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { generate } from '@socio-development/generator' | ||
import { existsSync, readdirSync } from 'fs' | ||
import { resolve } from 'path' | ||
|
||
const rootPath = resolve('.') | ||
const themesPath = resolve(rootPath, 'src', 'themes') | ||
|
||
if (!existsSync(themesPath)) { | ||
throw new Error(`Themes path does not exist: ${themesPath}`) | ||
} | ||
|
||
const themeFiles = readdirSync(themesPath) | ||
const themeNames = themeFiles | ||
.filter((file) => file.endsWith('.ts')) | ||
.map((file) => file.replace('.ts', '')) | ||
|
||
const code = ` | ||
export const themeNames = ['${themeNames.join("', '")}'] as const | ||
export type ThemeName = (typeof themeNames)[number] | ||
` | ||
|
||
console.log(code) | ||
|
||
generate({ | ||
code, | ||
file: 'theme.ts', | ||
path: 'src', | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const themeNames = ['socio'] as const | ||
|
||
export type ThemeName = (typeof themeNames)[number] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,19 @@ | ||
import { ThemeName } from './_generated/theme' | ||
import { LoggerOptions } from './types' | ||
|
||
export { default as Logger } from './classes/Logger' | ||
|
||
/** | ||
* Gets the logger options from a theme. | ||
* @param theme The theme name. | ||
* @returns The logger options. | ||
*/ | ||
export function getTheme(theme: ThemeName): LoggerOptions { | ||
const options = require(`./themes/${theme}`).default | ||
|
||
if (!options) { | ||
throw new Error(`Theme "${theme}" does not contain a valid configuration.`) | ||
} | ||
|
||
return options | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { LoggerConfig } from 'src/types' | ||
|
||
export default { | ||
composition: { | ||
default: [ | ||
'timestamp', | ||
'color:socio', | ||
'prefix', | ||
'color:reset', | ||
'indent', | ||
'message', | ||
], | ||
error: [ | ||
'timestamp', | ||
'color:socio', | ||
'prefix', | ||
'color:red', | ||
'indent', | ||
'message', | ||
], | ||
info: [ | ||
'timestamp', | ||
'color:socio', | ||
'prefix', | ||
'color:blue', | ||
'indent', | ||
'message', | ||
], | ||
warn: [ | ||
'timestamp', | ||
'color:socio', | ||
'prefix', | ||
'color:yellow', | ||
'indent', | ||
'message', | ||
], | ||
}, | ||
indentSize: 2, | ||
prefix: '[SOCIO]', | ||
separator: ' ', | ||
timestampFormat: 'HH:mm:ss', | ||
} satisfies LoggerConfig |