1+ const fs = require ( 'fs' )
12const core = require ( '@actions/core' )
23const { ConfigParser } = require ( './config-parser' )
34const removeTrailingSlash = require ( './remove-trailing-slash' )
45const { convertErrorToAnnotationProperties } = require ( './error-utils' )
56
67const SUPPORTED_FILE_EXTENSIONS = [ '.js' , '.cjs' , '.mjs' ]
78
9+ function detectOrDefaultConfigFile ( fileBaseName , defaultExt = '.js' ) {
10+ for ( const ext of SUPPORTED_FILE_EXTENSIONS ) {
11+ const potentialConfigFile = `./${ fileBaseName } ${ ext } `
12+ if ( fs . existsSync ( potentialConfigFile ) ) {
13+ return potentialConfigFile
14+ }
15+ }
16+ // If none of them exist yet, default to returning the filename with the defaultExt extension
17+ return `./${ fileBaseName } ${ defaultExt } `
18+ }
19+
820// Return the settings to be passed to a{ConfigParser} for a given static site generator,
921// optional configuration file path, and a Pages siteUrl value to inject
1022function getConfigParserSettings ( { staticSiteGenerator, generatorConfigFile, siteUrl } ) {
@@ -13,7 +25,7 @@ function getConfigParserSettings({staticSiteGenerator, generatorConfigFile, sit
1325switch ( staticSiteGenerator ) {
1426case 'nuxt' :
1527return {
16- configurationFile : generatorConfigFile || './ nuxt.config.js' ,
28+ configurationFile : generatorConfigFile || detectOrDefaultConfigFile ( ' nuxt.config' ) ,
1729blankConfigurationFile : `${ __dirname } /blank-configurations/nuxt.js` ,
1830properties : {
1931// Configure a base path on the router
@@ -29,7 +41,7 @@ function getConfigParserSettings({staticSiteGenerator, generatorConfigFile, sit
2941path = removeTrailingSlash ( path )
3042
3143return {
32- configurationFile : generatorConfigFile || './ next.config.js' ,
44+ configurationFile : generatorConfigFile || detectOrDefaultConfigFile ( ' next.config' ) ,
3345blankConfigurationFile : `${ __dirname } /blank-configurations/next.js` ,
3446properties : {
3547// Static export
@@ -47,7 +59,7 @@ function getConfigParserSettings({staticSiteGenerator, generatorConfigFile, sit
4759}
4860case 'gatsby' :
4961return {
50- configurationFile : generatorConfigFile || './ gatsby-config.js' ,
62+ configurationFile : generatorConfigFile || detectOrDefaultConfigFile ( ' gatsby-config' ) ,
5163blankConfigurationFile : `${ __dirname } /blank-configurations/gatsby.js` ,
5264properties : {
5365// Configure a path prefix
@@ -61,7 +73,7 @@ function getConfigParserSettings({staticSiteGenerator, generatorConfigFile, sit
6173path = removeTrailingSlash ( path )
6274
6375return {
64- configurationFile : generatorConfigFile || './ svelte.config.js' ,
76+ configurationFile : generatorConfigFile || detectOrDefaultConfigFile ( ' svelte.config' ) ,
6577blankConfigurationFile : `${ __dirname } /blank-configurations/sveltekit.js` ,
6678properties : {
6779// Configure a base path
0 commit comments