1 | const fs = require('fs')
|
2 | const getPathnameProjectConfigFile = require('./get-pathname-project-config-file')
|
3 |
|
4 | const getAppTypeString = require('./get-app-type-string')
|
5 | const envUpdateAppType = require('../libs/env/update-app-type')
|
6 |
|
7 | const extractType = () => {
|
8 | const pathnameKootJS = getPathnameProjectConfigFile()
|
9 |
|
10 | try {
|
11 | const { type } = require(pathnameKootJS)
|
12 | return type
|
13 | } catch (e) { }
|
14 |
|
15 | const content = fs.readFileSync(pathnameKootJS, 'utf-8')
|
16 | const matches = /type[ ]*=[ ]*['"](.+?)['"]/gm.exec(content)
|
17 | if (Array.isArray(matches) && matches.length > 1)
|
18 | return matches[1]
|
19 |
|
20 | return undefined
|
21 | }
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 | module.exports = async (projectType = process.env.KOOT_PROJECT_TYPE) => {
|
39 | if (!projectType) {
|
40 | projectType = extractType() || ''
|
41 | }
|
42 |
|
43 | envUpdateAppType(getAppTypeString(projectType))
|
44 |
|
45 | return process.env.KOOT_PROJECT_TYPE
|
46 | }
|