forked from quasarframework/quasar
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
types-feature-flags.js
46 lines (42 loc) · 1.51 KB
/
types-feature-flags.js
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
const path = require('path')
const fs = require('fs')
const fse = require('fs-extra')
const { warn } = require('./logger')
const getMode = require('../mode/index')
const appPaths = require('../app-paths')
function getStoreFlagPath(storeIndexPath) {
return path.join(path.parse(storeIndexPath).dir, 'store-flag.d.ts')
}
module.exports = function regenerateTypesFeatureFlags(quasarConf) {
// Flags must be available even in pure JS codebases,
// because boot and configure wrappers functions files will
// provide autocomplete based on them also to JS users
// Flags files should be copied over, for every enabled mode,
// every time `quasar dev` and `quasar build` are run:
// this automatize the upgrade for existing codebases
for (const feature of [
'pwa',
'cordova',
'capacitor',
'electron',
'ssr',
'store',
'bex'
]) {
const [isFeatureInstalled, sourceFlagPath, destFlagPath] = feature === 'store'
? [
quasarConf.store,
appPaths.resolve.cli('templates/store/ts/store-flag.d.ts'),
appPaths.resolve.app(getStoreFlagPath(quasarConf.sourceFiles.store))
]
: [
getMode(feature).isInstalled,
appPaths.resolve.cli(`templates/${feature}/${feature}-flag.d.ts`),
appPaths.resolve[feature](`${feature}-flag.d.ts`)
]
if (isFeatureInstalled && !fs.existsSync(destFlagPath)) {
fse.copySync(sourceFlagPath, destFlagPath)
warn(`'${feature}' feature flag was missing and has been regenerated`)
}
}
}