UNPKG

883 BPlain TextView Raw
1import fs from 'fs-extra'
2import path from 'path'
3import globSync from 'tiny-glob/sync'
4
5import * as logger from './log'
6import { Presta } from './types'
7
8export function isDynamic(file: string) {
9 return /export\s.+\sroute\s+\=/.test(fs.readFileSync(file, 'utf-8'))
10}
11
12export function isStatic(file: string) {
13 return /export\s.+\sgetStaticPaths/.test(fs.readFileSync(file, 'utf-8'))
14}
15
16export function isPrestaFile(file: string) {
17 return isStatic(file) || isDynamic(file)
18}
19
20export function getFiles(config: Presta): string[] {
21 try {
22 return ([] as string[])
23 .concat(config.files)
24 .map((file) => globSync(file, { cwd: config.cwd }))
25 .flat()
26 .map((file) => path.resolve(config.cwd, file)) // make absolute
27 } catch (e) {
28 logger.error({
29 label: 'paths',
30 message: `no files found`,
31 error: e as Error,
32 })
33
34 return []
35 }
36}