1
+ const fs = require ( 'fs' )
1
2
const core = require ( '@actions/core' )
2
3
const { ConfigParser } = require ( './config-parser' )
3
4
const removeTrailingSlash = require ( './remove-trailing-slash' )
4
5
const { convertErrorToAnnotationProperties } = require ( './error-utils' )
5
6
6
7
const SUPPORTED_FILE_EXTENSIONS = [ '.js' , '.cjs' , '.mjs' ]
7
8
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
+
8
20
// Return the settings to be passed to a {ConfigParser} for a given static site generator,
9
21
// optional configuration file path, and a Pages siteUrl value to inject
10
22
function getConfigParserSettings ( { staticSiteGenerator, generatorConfigFile, siteUrl } ) {
@@ -13,7 +25,7 @@ function getConfigParserSettings({ staticSiteGenerator, generatorConfigFile, sit
13
25
switch ( staticSiteGenerator ) {
14
26
case 'nuxt' :
15
27
return {
16
- configurationFile : generatorConfigFile || './ nuxt.config.js' ,
28
+ configurationFile : generatorConfigFile || detectOrDefaultConfigFile ( ' nuxt.config' ) ,
17
29
blankConfigurationFile : `${ __dirname } /blank-configurations/nuxt.js` ,
18
30
properties : {
19
31
// Configure a base path on the router
@@ -29,7 +41,7 @@ function getConfigParserSettings({ staticSiteGenerator, generatorConfigFile, sit
29
41
path = removeTrailingSlash ( path )
30
42
31
43
return {
32
- configurationFile : generatorConfigFile || './ next.config.js' ,
44
+ configurationFile : generatorConfigFile || detectOrDefaultConfigFile ( ' next.config' ) ,
33
45
blankConfigurationFile : `${ __dirname } /blank-configurations/next.js` ,
34
46
properties : {
35
47
// Static export
@@ -47,7 +59,7 @@ function getConfigParserSettings({ staticSiteGenerator, generatorConfigFile, sit
47
59
}
48
60
case 'gatsby' :
49
61
return {
50
- configurationFile : generatorConfigFile || './ gatsby-config.js' ,
62
+ configurationFile : generatorConfigFile || detectOrDefaultConfigFile ( ' gatsby-config' ) ,
51
63
blankConfigurationFile : `${ __dirname } /blank-configurations/gatsby.js` ,
52
64
properties : {
53
65
// Configure a path prefix
@@ -61,7 +73,7 @@ function getConfigParserSettings({ staticSiteGenerator, generatorConfigFile, sit
61
73
path = removeTrailingSlash ( path )
62
74
63
75
return {
64
- configurationFile : generatorConfigFile || './ svelte.config.js' ,
76
+ configurationFile : generatorConfigFile || detectOrDefaultConfigFile ( ' svelte.config' ) ,
65
77
blankConfigurationFile : `${ __dirname } /blank-configurations/sveltekit.js` ,
66
78
properties : {
67
79
// Configure a base path
0 commit comments