UNPKG

1.43 kBJavaScriptView Raw
1import { ensureFontsDirectory } from './fonts.js'
2import getFiles from './get-files.js'
3import chalk from 'chalk'
4import makeMorpher from './make-morpher.js'
5import maybePrintWarnings from './maybe-print-warnings.js'
6import path from 'path'
7import watchFiles from './watch-files.js'
8
9export default async function watch(options) {
10 let morpher = makeMorpher(options)
11
12 await ensureFontsDirectory(morpher.src)
13
14 await morpher.processFiles(await getFiles(morpher.src))
15
16 if (options.verbose) {
17 if (morpher.customFonts.size > 0) {
18 console.log(chalk.yellow(`\nCustom fonts detected:`))
19 console.log([...morpher.customFonts.keys()].sort().join('\n'))
20 }
21
22 let views = [...morpher.viewsToFiles.values()]
23 console.log(
24 views
25 .map(view => {
26 let msg = view.id
27 if (view.custom) {
28 msg = `${view.id} ${chalk.dim('(is custom)')}`
29 } else if (view.logic) {
30 msg = `${view.id} ${chalk.dim('(has logic)')}`
31 }
32 return `${chalk.yellow('A')} ${chalk.green('M')} ${msg} ${chalk.dim(
33 path.relative(process.cwd(), view.file)
34 )}`
35 })
36 .sort()
37 .join('\n')
38 )
39
40 views.forEach(maybePrintWarnings)
41 }
42
43 if (options.once) return
44
45 let watcher = watchFiles({ morpher })
46
47 process.on('beforeExit', () => {
48 console.log('Stopping Views morpher file watcher...')
49 watcher.close()
50 })
51}