1 | const fs = require('fs')
|
2 | const getPathnameProjectConfigFile = require('./get-pathname-project-config-file')
|
3 |
|
4 |
|
5 | const extractType = () => {
|
6 | const pathnameKootJS = getPathnameProjectConfigFile()
|
7 |
|
8 | try {
|
9 | const { type } = require(pathnameKootJS)
|
10 | return type
|
11 | } catch (e) { }
|
12 |
|
13 | const content = fs.readFileSync(pathnameKootJS, 'utf-8')
|
14 | const matches = /type[ ]*=[ ]*['"](.+?)['"]/gm.exec(content)
|
15 | if (Array.isArray(matches) && matches.length > 1)
|
16 | return matches[1]
|
17 |
|
18 | return undefined
|
19 | }
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 | module.exports = async () => {
|
29 | if (typeof process.env.KOOT_PROJECT_TYPE === 'undefined') {
|
30 | process.env.KOOT_PROJECT_TYPE = extractType() || ''
|
31 | }
|
32 |
|
33 | switch (process.env.KOOT_PROJECT_TYPE.toLowerCase()) {
|
34 | case 'react': {
|
35 |
|
36 | process.env.WEBPACK_BUILD_TYPE = 'isomorphic'
|
37 | process.env.KOOT_PROJECT_TYPE = 'ReactApp'
|
38 |
|
39 | break
|
40 | }
|
41 |
|
42 | case 'react-spa':
|
43 | case 'reactspa': {
|
44 | process.env.WEBPACK_BUILD_TYPE = 'spa'
|
45 | process.env.KOOT_PROJECT_TYPE = 'ReactSPA'
|
46 | break
|
47 | }
|
48 |
|
49 |
|
50 |
|
51 | }
|
52 |
|
53 | return process.env.KOOT_PROJECT_TYPE
|
54 | }
|