forked from redwoodjs/graphql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject.ts
More file actions
57 lines (46 loc) · 1.4 KB
/
project.ts
File metadata and controls
57 lines (46 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import fs from 'fs'
import path from 'path'
import { parseConfigFileTextToJson } from 'typescript'
import { getPaths } from '@redwoodjs/project-config'
export const getTsConfigs = () => {
const rwPaths = getPaths()
const apiTsConfigPath = path.join(rwPaths.api.base, 'tsconfig.json')
const webTsConfigPath = path.join(rwPaths.web.base, 'tsconfig.json')
const apiTsConfig = fs.existsSync(apiTsConfigPath)
? parseConfigFileTextToJson(
apiTsConfigPath,
fs.readFileSync(apiTsConfigPath, 'utf-8')
)
: null
const webTsConfig = fs.existsSync(webTsConfigPath)
? parseConfigFileTextToJson(
webTsConfigPath,
fs.readFileSync(webTsConfigPath, 'utf-8')
)
: null
return {
api: apiTsConfig?.config ?? null,
web: webTsConfig?.config ?? null,
}
}
export const isTypeScriptProject = () => {
const paths = getPaths()
return (
fs.existsSync(path.join(paths.web.base, 'tsconfig.json')) ||
fs.existsSync(path.join(paths.api.base, 'tsconfig.json'))
)
}
export const isServerFileSetup = () => {
const serverFilePath = path.join(
getPaths().api.src,
`server.${isTypeScriptProject() ? 'ts' : 'js'}`
)
return fs.existsSync(serverFilePath)
}
export const isRealtimeSetup = () => {
const realtimePath = path.join(
getPaths().api.lib,
`realtime.${isTypeScriptProject() ? 'ts' : 'js'}`
)
return fs.existsSync(realtimePath)
}