|
| 1 | +const logger = require('./logger') |
| 2 | +const path = require('path') |
| 3 | +const warn = logger('app:mode', 'yellow') |
| 4 | +const fs = require('fs') |
| 5 | +const fse = require('fs-extra') |
| 6 | +const getMode = require('../mode/index') |
| 7 | +const appPaths = require('../app-paths') |
| 8 | + |
| 9 | +function getStoreFlagPath(storeIndexPath) { |
| 10 | + return path.join(path.parse(storeIndexPath).dir, 'store-flag.d.ts') |
| 11 | +} |
| 12 | + |
| 13 | +module.exports = function regenerateTypesFeatureFlags(buildConfig) { |
| 14 | + const storeFeatureData = [ |
| 15 | + buildConfig.store, |
| 16 | + appPaths.resolve.cli('templates/app/store/store-flag.d.ts'), |
| 17 | + appPaths.resolve.app(getStoreFlagPath(buildConfig.sourceFiles.store)) |
| 18 | + ] |
| 19 | + |
| 20 | + // Flags must be available even in pure JS codebases, |
| 21 | + // because boot and configure wrappers functions files will |
| 22 | + // provide autocomplete based on them also to JS users |
| 23 | + // Flags files should be copied over, for every enabled mode, |
| 24 | + // every time `quasar dev` and `quasar build` are run: |
| 25 | + // this automatize the upgrade for existing codebases |
| 26 | + for (const feature of [ |
| 27 | + 'pwa', |
| 28 | + 'cordova', |
| 29 | + 'capacitor', |
| 30 | + 'electron', |
| 31 | + 'ssr', |
| 32 | + 'store' |
| 33 | + ]) { |
| 34 | + const [isFeatureInstalled, sourceFlagPath, destFlagPath] = feature === 'store' |
| 35 | + ? storeFeatureData |
| 36 | + : [ |
| 37 | + getMode(feature).isInstalled, |
| 38 | + appPaths.resolve.cli(`templates/${feature}/${feature}-flag.d.ts`), |
| 39 | + appPaths.resolve[feature](`${feature}-flag.d.ts`) |
| 40 | + ] |
| 41 | + |
| 42 | + if (isFeatureInstalled && !fs.existsSync(destFlagPath)) { |
| 43 | + fse.copySync(sourceFlagPath, destFlagPath) |
| 44 | + warn(`'${feature}' feature flag was missing and has been regenerated`) |
| 45 | + } |
| 46 | + } |
| 47 | +} |
0 commit comments