Files
configure-pages/src/set-pages-path.js
T

51 lines
1.8 KiB
JavaScript
Raw Normal View History

const core = require('@actions/core')
2022-07-18 15:06:14 -07:00
const {ConfigParser} = require('./config-parser')
2022-07-19 11:47:29 -07:00
// Return the settings to be passed to a {ConfigParser} for a given
// static site generator and a Pages path value to inject
function getConfigParserSettings(staticSiteGenerator, path) {
2022-07-18 16:42:45 -07:00
switch (staticSiteGenerator) {
case 'nuxt':
return {
configurationFile: './nuxt.config.js',
propertyName: 'router.base',
propertyValue: path,
2022-07-19 11:47:29 -07:00
blankConfigurationFile: `${__dirname}/blank-configurations/nuxt.js`
2022-07-18 16:42:45 -07:00
}
case 'next':
return {
configurationFile: './next.config.js',
propertyName: 'basePath',
propertyValue: path,
2022-07-19 11:47:29 -07:00
blankConfigurationFile: `${__dirname}/blank-configurations/next.js`
2022-07-18 16:42:45 -07:00
}
case 'gatsby':
return {
configurationFile: './gatsby-config.js',
propertyName: 'pathPrefix',
propertyValue: path,
2022-07-19 11:47:29 -07:00
blankConfigurationFile: `${__dirname}/blank-configurations/gatsby.js`
2022-07-18 16:42:45 -07:00
}
default:
throw `Unsupported static site generator: ${staticSiteGenerator}`
}
}
2022-07-19 11:47:29 -07:00
// Inject Pages configuration in a given static site generator's configuration file
function setPagesPath({staticSiteGenerator, path}) {
try {
2022-07-19 11:47:29 -07:00
// Parse the configuration file and try to inject the Pages configuration in it
new ConfigParser(
getConfigParserSettings(staticSiteGenerator, path)
).inject()
} catch (error) {
2022-07-19 11:47:29 -07:00
// Logging
2022-07-18 15:06:14 -07:00
core.warning(
`We were unable to determine how to inject the site metadata into your config. Generated URLs may be incorrect. The base URL for this site should be ${path}. Please ensure your framework is configured to generate relative links appropriately.`,
error
)
}
}
2022-07-19 11:47:29 -07:00
module.exports = {getConfigParserSettings, setPagesPath}