Skip to content

Commit

Permalink
feat: added supersedes option to builtin configs
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobrosenberg committed Sep 28, 2020
1 parent 2e59e54 commit 0d378f4
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 16 deletions.
18 changes: 18 additions & 0 deletions configs/svite-routify.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = {
name: 'Svite / Routify 2',
supersedes: ['routify2', 'routify'],
condition: ({ pkgjson }) => pkgjson.dependencies['@roxi/routify'],
config: () => {
const { readFileSync } = require('fs')
const html = readFileSync('./dist/index.html', 'utf-8')
const script = html.match(/src="\/(_assets\/index.\w+.js)"/)[1]
return {
script: `dist/${script}`,
entrypoint: 'dist/index.html',
inlineDynamicImports: true,
sitemap: '.routify/urlIndex.json',
output: 'dist',
eventName: 'app-loaded',
}
}
}
40 changes: 24 additions & 16 deletions getConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,45 @@ async function getConfig() {
}

async function getFrameworkConfig() {
const matches = []

spinner = ora('Looking for matching config').start()

const pkgjson = existsSync('package.json')
? require(resolve(process.cwd(), 'package.json'))
: { dependencies: {}, devDependencies: {} }
Object.assign(pkgjson.dependencies, pkgjson.devDependencies)

const configFiles = readdirSync(resolve(__dirname, 'configs'))
const configFiles = readdirSync(resolve(__dirname, 'configs'))

const promises = configFiles.map(async file => {
const { condition, config, name } = require(`./configs/${file}`)
const { condition, config, name, supersedes } = require(`./configs/${file}`)
if (condition({ pkgjson })) {
spinner.text = 'Found matching config: ' + chalk.magentaBright(name)
matches.push(name)
return await config()

return await {
config: config(),
supersedes,
name,
file: file.replace(/\.config\..+/, '')
}
}
})

if (matches.length)
spinner.succeed('Found matching config: ' + chalk.magentaBright(matches.join(', ')))
else spinner.info('Found no matching config. While one isn\'t required, We would greatly appreciate if you reach out to us. https://github.com/roxiness/spank')
const allResolvedConfigs = (await Promise.all(promises)).filter(Boolean)
const supersedings = [].concat(...allResolvedConfigs.map(conf => conf.supersedes).filter(Boolean))
const resolvedConfigs = allResolvedConfigs.filter(conf => !supersedings.includes(conf.file))

const configs = await Promise.all(promises)
const config = Object.assign({}, ...configs)

return config
if (resolvedConfigs.length) {
const names = resolvedConfigs.map(conf => conf.name)
const configs = resolvedConfigs.map(conf => conf.config)
const config = Object.assign({}, ...configs)
spinner.succeed('Found matching config: ' + chalk.magentaBright(names.join(', ')))
return config
} else {
spinner.info('Found no matching config. While one isn\'t required, We would greatly appreciate if you reach out to us. https://github.com/roxiness/spank')
return {}
}
}


async function getUserConfig() {
spinner = ora('Looking for user config').start()
if (existsSync(CONFIG)) {
Expand Down

0 comments on commit 0d378f4

Please sign in to comment.