Skip to content

Commit

Permalink
fix: write logs to stderr
Browse files Browse the repository at this point in the history
  • Loading branch information
sastan committed Mar 3, 2021
1 parent de1bf6d commit 802a510
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const cli = (argv = process.argv) =>
.option('-b, --beautify', 'Generate beautified css file', false)
.option('-C, --cwd', 'The current directory to resolve from', '.')
.option('-w, --watch', 'Watch for changes', false)
.option('--color', 'Print colorized output', supportsColor.stdout && supportsColor.stderr)
.option('--color', 'Print colorized output', supportsColor.stderr)
.action(async (globs = '**/*.{htm,html,js,jsx,tsx,svelte,vue,mdx}', {_, ['ignore-file']: ignoreFile, ...options}) => {
try {
await run([globs, ..._], {...options, ignoreFile})
Expand Down
27 changes: 14 additions & 13 deletions src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const tryLoadConfig = (configFile: string): Configuration => {
try {
return importFresh(configFile)
} catch (error) {
console.log(error)
console.error(error)
return {}
}
}
Expand Down Expand Up @@ -88,8 +88,8 @@ const run$ = async (globs: string[], options: RunOptions, esbuild: Service): Pro
let lastCandidates = new Set<string>(['' /* ensure an empty CSS may be generated */])

for await (const changes of watch(configFile ? [configFile, ...globs] : globs, options)) {
// console.log([...changes.keys()])
console.log(
// console.error([...changes.keys()])
console.error(
kleur.cyan(
`Processing ${kleur.bold(changes.size)}${options.watch ? ' changed' : ''} file${
changes.size == 1 ? '' : 's'
Expand All @@ -106,7 +106,7 @@ const run$ = async (globs: string[], options: RunOptions, esbuild: Service): Pro
;({ sheet, tw } = loadConfig())
hasChanged = true
lastCandidates = new Set<string>(['' /* ensure an empty CSS may be generated */])
console.log(
console.error(
kleur.green(
`Loaded configuration from ${kleur.bold(
path.relative(process.cwd(), configFile),
Expand All @@ -123,7 +123,7 @@ const run$ = async (globs: string[], options: RunOptions, esbuild: Service): Pro
) {
pendingDetections.push(
extractRulesFromFile(file).then((candidates) => {
// console.log({file, candidates})
// console.error({file, candidates})
watched.set(file, stats)
candidatesByFile.set(file, candidates)
if (!hasChanged) {
Expand Down Expand Up @@ -154,7 +154,7 @@ const run$ = async (globs: string[], options: RunOptions, esbuild: Service): Pro
candidates.forEach(addCandidate)
})

console.log(
console.error(
kleur.gray(
`Extracted ${kleur.bold(nextCandidates.size)} candidate${
nextCandidates.size == 1 ? '' : 's'
Expand All @@ -168,8 +168,8 @@ const run$ = async (globs: string[], options: RunOptions, esbuild: Service): Pro
const twEndTime = timeSpan()
sheet.reset()
tw([...nextCandidates].filter(ignoreUnknownRules).sort().join(' '))
// console.log([...nextCandidates].sort().join(' '))
console.log(
// console.error([...nextCandidates].sort().join(' '))
console.error(
kleur.gray(
`Generated ${kleur.bold(sheet.target.length)} CSS rule${
sheet.target.length == 1 ? '' : 's'
Expand All @@ -190,7 +190,7 @@ const run$ = async (globs: string[], options: RunOptions, esbuild: Service): Pro
})

css = result.code
console.log(
console.error(
kleur.gray(
`${options.beautify ? 'Beautified' : 'Minimized'} CSS in ${kleur.bold(
cssEndTime.rounded() + ' ms',
Expand All @@ -202,22 +202,23 @@ const run$ = async (globs: string[], options: RunOptions, esbuild: Service): Pro
// Write to file or console
if (outputFile) {
await fs.writeFile(outputFile, css)
console.log(
console.error(
kleur.green(
`Finished ${kleur.bold(path.relative(process.cwd(), outputFile))} in ${kleur.bold(
endTime.rounded() + ' ms',
)}`,
),
)
} else {
// console.log(css)
console.error(kleur.green(`Finished in ${kleur.bold(endTime.rounded() + ' ms')}`))
console.log(css)
}
} else {
console.log(kleur.green().dim(`No new classes detected - skipped generating CSS`))
console.error(kleur.green().dim(`No new classes detected - skipped generating CSS`))
}

if (options.watch) {
console.log('\n' + kleur.dim('Waiting for file changes...'))
console.error('\n' + kleur.dim('Waiting for file changes...'))
}
}
}
Expand Down

0 comments on commit 802a510

Please sign in to comment.