1 | import fs from 'fs-extra'
|
2 | import path from 'path'
|
3 | import globSync from 'tiny-glob/sync'
|
4 |
|
5 | import * as logger from './log'
|
6 | import { Presta } from './types'
|
7 |
|
8 | export function isDynamic(file: string) {
|
9 | return /export\s.+\sroute\s+\=/.test(fs.readFileSync(file, 'utf-8'))
|
10 | }
|
11 |
|
12 | export function isStatic(file: string) {
|
13 | return /export\s.+\sgetStaticPaths/.test(fs.readFileSync(file, 'utf-8'))
|
14 | }
|
15 |
|
16 | export function isPrestaFile(file: string) {
|
17 | return isStatic(file) || isDynamic(file)
|
18 | }
|
19 |
|
20 | export 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))
|
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 | }
|