UNPKG

1.18 kBJavaScriptView Raw
1const fs = require('fs')
2const path = require('path')
3// const readBuildConfigFile = require('../utils/read-build-config-file')
4
5const extractType = () => {
6 const pathnameSuperJS = path.resolve(__dirname, '../../../super.js')
7
8 try {
9 const { type } = require(pathnameSuperJS)
10 return type
11 } catch (e) { }
12
13 const content = fs.readFileSync(pathnameSuperJS, '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
21module.exports = async () => {
22 const type = typeof process.env.SUPER_PROJECT_TYPE !== 'undefined'
23 ? process.env.SUPER_PROJECT_TYPE
24 : extractType() || ''
25
26 switch (type.toLowerCase()) {
27 case 'react': {
28 // if ((await readBuildConfigFile()).server)
29 process.env.WEBPACK_BUILD_TYPE = 'isomorphic'
30 return 'ReactApp'
31 // return 'ReactSPA'
32 }
33
34 case 'react-spa':
35 case 'reactspa': {
36 process.env.WEBPACK_BUILD_TYPE = 'spa'
37 return 'ReactSPA'
38 }
39
40 default:
41 return type
42 }
43}