2022-06-16 14:28:43 -07:00
const core = require ( '@actions/core' )
2022-07-18 15:06:14 -07:00
const { ConfigParser } = require ( './config-parser' )
2022-06-16 14:28:43 -07:00
2022-07-18 16:42:45 -07:00
function getParserConfiguration ( staticSiteGenerator , path ) {
switch ( staticSiteGenerator ) {
case 'nuxt' :
return {
configurationFile : './nuxt.config.js' ,
propertyName : 'router.base' ,
propertyValue : path ,
blankConfigurationFile : ` ${ process . cwd () } /blank-configurations/nuxt.js`
}
case 'next' :
return {
configurationFile : './next.config.js' ,
propertyName : 'basePath' ,
propertyValue : path ,
blankConfigurationFile : ` ${ process . cwd () } /blank-configurations/next.js`
}
case 'gatsby' :
return {
configurationFile : './gatsby-config.js' ,
propertyName : 'pathPrefix' ,
propertyValue : path ,
blankConfigurationFile : ` ${ process . cwd () } /blank-configurations/gatsby.js`
}
default :
throw `Unsupported static site generator: ${ staticSiteGenerator } `
}
}
2022-06-17 18:36:26 -07:00
async function setPagesPath ({ staticSiteGenerator , path }) {
2022-06-16 14:28:43 -07:00
try {
2022-07-18 16:42:45 -07:00
// Parse/mutate the configuration file
new ConfigParser ( getParserConfiguration ( staticSiteGenerator , path )). parse ()
2022-06-16 14:28:43 -07:00
} catch ( error ) {
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-06-16 14:28:43 -07:00
}
}
module . exports = setPagesPath