-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add pretty address printer to userland
- Loading branch information
1 parent
6722d49
commit 89cac9f
Showing
9 changed files
with
61 additions
and
71 deletions.
There are no files selected for viewing
26 changes: 17 additions & 9 deletions
26
integration/__fixtures__/server-express/dist_expected/server/server.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
integration/__fixtures__/server-express/dist_expected/server/server.js.map
Large diffs are not rendered by default.
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
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,29 +1,32 @@ | ||
// NOTE: Util. to pretty print for user provided server. | ||
|
||
// import { logger } from '@gracile/internal-utils/logger'; | ||
// import { DEV } from 'esm-env'; | ||
// import type { Server } from 'http'; | ||
// import c from 'picocolors'; | ||
import { logger } from '@gracile/internal-utils/logger'; | ||
import { DEV } from 'esm-env'; | ||
import type { Server } from 'http'; | ||
import c from 'picocolors'; | ||
|
||
// export function printNodeHttpServerAddressInfos( | ||
// instance: Server, | ||
// expose: boolean = true, | ||
// ) { | ||
// const infos = instance.address(); | ||
// logger.info(c.green(`${DEV ? 'development' : 'production'} server started`), { | ||
// timestamp: true, | ||
// }); | ||
import { IP_EXPOSED } from './env.js'; | ||
|
||
// if (typeof infos === 'object' && infos && infos.port && infos.address) { | ||
// logger.info( | ||
// ` | ||
// ${c.dim('┃')} Local ${c.cyan(`http://localhost:${infos.port}/`)} | ||
// ${c.dim('┃')} Network ${expose ? c.cyan(`http://${infos.address}:${infos.port}/`) : c.dim(`use ${c.bold('--host')} to expose`)} | ||
// `, | ||
// ); | ||
export function printNodeHttpServerAddressInfos(instance: Server) { | ||
const infos = instance.address(); | ||
logger.info(c.green(`${DEV ? 'development' : 'production'} server started`), { | ||
timestamp: true, | ||
}); | ||
|
||
// return infos; | ||
// } | ||
if (typeof infos === 'object' && infos && infos.port && infos.address) { | ||
logger.info( | ||
` | ||
${c.dim('┃')} Local ${c.cyan(`http://localhost:${infos.port}/`)}` + | ||
`${ | ||
infos.address === IP_EXPOSED | ||
? `${c.dim('┃')} Network ${c.cyan(`http://${infos.address}:${infos.port}/`)}` | ||
: '' | ||
} | ||
`, | ||
); | ||
|
||
// throw Error('Invalid address/port.'); | ||
// } | ||
return infos; | ||
} | ||
|
||
throw Error('Invalid address/port.'); | ||
} |
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
15 changes: 9 additions & 6 deletions
15
packages/internal/utils/src/logger.prod.ts → packages/internal/utils/src/logger.build.ts
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,28 +1,31 @@ | ||
/* eslint-disable no-console */ | ||
/* eslint-disable @typescript-eslint/no-unused-vars */ | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-nocheck TODO: Implement stubs | ||
|
||
import type { Logger } from 'vite'; | ||
|
||
const NOT_PROD = process.env.NODE_ENV !== 'production'; | ||
|
||
export const logger: Logger = { | ||
info(msg: string, options?: LogOptions): void { | ||
// throw new Error('Function not implemented.'); | ||
if (NOT_PROD) console.info(msg); | ||
}, | ||
warn(msg: string, options?: LogOptions): void { | ||
// throw new Error('Function not implemented.'); | ||
if (NOT_PROD) console.warn(msg); | ||
}, | ||
warnOnce(msg: string, options?: LogOptions): void { | ||
// throw new Error('Function not implemented.'); | ||
if (NOT_PROD) console.warn(msg); | ||
}, | ||
error(msg: string, options?: LogErrorOptions): void { | ||
// throw new Error('Function not implemented.'); | ||
if (NOT_PROD) console.error(msg); | ||
}, | ||
clearScreen(type: LogType): void { | ||
// throw new Error('Function not implemented.'); | ||
if (NOT_PROD) console.clear(); | ||
}, | ||
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents | ||
hasErrorLogged(error: Error | RollupError): boolean { | ||
// throw new Error('Function not implemented.'); | ||
if (NOT_PROD) console.error(error); | ||
}, | ||
hasWarned: false, | ||
}; |
File renamed without changes.
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,29 +1 @@ | ||
/* eslint-disable no-console */ | ||
/* eslint-disable @typescript-eslint/no-unused-vars */ | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-nocheck TODO: Implement stubs | ||
|
||
import type { Logger } from 'vite'; | ||
|
||
export const logger: Logger = { | ||
info(msg: string, options?: LogOptions): void { | ||
console.info(msg, options); | ||
}, | ||
warn(msg: string, options?: LogOptions): void { | ||
console.warn(msg, options); | ||
}, | ||
warnOnce(msg: string, options?: LogOptions): void { | ||
console.warn(msg, options); | ||
}, | ||
error(msg: string, options?: LogErrorOptions): void { | ||
console.error(msg, options); | ||
}, | ||
clearScreen(type: LogType): void { | ||
console.clear(); | ||
}, | ||
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents | ||
hasErrorLogged(error: Error | RollupError): boolean { | ||
console.error(error); | ||
}, | ||
hasWarned: false, | ||
}; | ||
// TODO: Separate from prod. and make prod. empty/customizable. |