Skip to content

Commit

Permalink
Merge pull request #15 from paper-spa/server-static
Browse files Browse the repository at this point in the history
  • Loading branch information
Yoann Chaudet authored and GitHub committed Jul 21, 2022
2 parents 398adf7 + 7875e4a commit 8981dbc
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 12 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

An action to enable Pages and extract various metadata about a site. It can also be used to configure various static site generators we support as [starter workflows][starter-workflows].

See [`set-pages-path.js`](./src/set-pages-path.js) for more details on how we configure static site generators to work "out of the box" with GitHub Pages.

# Usage

See [action.yml](action.yml) and the [Pages starter workflows][starter-workflows].
Expand Down
18 changes: 13 additions & 5 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14468,15 +14468,14 @@ class ConfigParser {

// If the configuration file does not exist, initialize it with the blank configuration file
if (!fs.existsSync(this.configurationFile)) {
core.info('Use default blank configuration')
core.info('Using default blank configuration')
const blankConfiguration = fs.readFileSync(blankConfigurationFile, 'utf8')
fs.writeFileSync(this.configurationFile, blankConfiguration, {
encoding: 'utf8'
})
}

// Read the configuration file
core.info('Read existing configuration')
this.configuration = fs.readFileSync(this.configurationFile, 'utf8')
}

Expand Down Expand Up @@ -14592,7 +14591,8 @@ class ConfigParser {
// - propertyValue: the value of the property
inject(propertyName, propertyValue) {
// Logging
core.info(`Parsing configuration:\n${this.configuration}`)
core.info(`Injecting property=${propertyName} and value=${propertyValue} in:`)
core.info(this.configuration)

// Parse the AST out of the configuration file
const espreeOptions = {
Expand Down Expand Up @@ -14693,7 +14693,8 @@ class ConfigParser {
}

// Logging
core.info(`Writing new configuration:\n${this.configuration}`)
core.info(`Injection successful, new configuration:`)
core.info(this.configuration)

// Finally write the new configuration in the file
fs.writeFileSync(this.configurationFile, this.configuration, {
Expand Down Expand Up @@ -14836,7 +14837,12 @@ function getConfigParserSettings(staticSiteGenerator, path) {
configurationFile: './nuxt.config.js',
blankConfigurationFile: __nccwpck_require__.ab + "nuxt.js",
properties: {
'router.base': path
// Configure a base path on the router
'router.base': path,

// Set the target to static too
// https://nuxtjs.org/docs/configuration-glossary/configuration-target/
target: 'static'
}
}
case 'next':
Expand All @@ -14849,6 +14855,7 @@ function getConfigParserSettings(staticSiteGenerator, path) {
configurationFile: './next.config.js',
blankConfigurationFile: __nccwpck_require__.ab + "next.js",
properties: {
// Configure a base path
basePath: path,

// Disable server side image optimization too
Expand All @@ -14861,6 +14868,7 @@ function getConfigParserSettings(staticSiteGenerator, path) {
configurationFile: './gatsby-config.js',
blankConfigurationFile: __nccwpck_require__.ab + "gatsby.js",
properties: {
// Configure a path prefix
pathPrefix: path
}
}
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions src/config-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,14 @@ class ConfigParser {

// If the configuration file does not exist, initialize it with the blank configuration file
if (!fs.existsSync(this.configurationFile)) {
core.info('Use default blank configuration')
core.info('Using default blank configuration')
const blankConfiguration = fs.readFileSync(blankConfigurationFile, 'utf8')
fs.writeFileSync(this.configurationFile, blankConfiguration, {
encoding: 'utf8'
})
}

// Read the configuration file
core.info('Read existing configuration')
this.configuration = fs.readFileSync(this.configurationFile, 'utf8')
}

Expand Down Expand Up @@ -162,7 +161,8 @@ class ConfigParser {
// - propertyValue: the value of the property
inject(propertyName, propertyValue) {
// Logging
core.info(`Parsing configuration:\n${this.configuration}`)
core.info(`Injecting property=${propertyName} and value=${propertyValue} in:`)
core.info(this.configuration)

// Parse the AST out of the configuration file
const espreeOptions = {
Expand Down Expand Up @@ -263,7 +263,8 @@ class ConfigParser {
}

// Logging
core.info(`Writing new configuration:\n${this.configuration}`)
core.info(`Injection successful, new configuration:`)
core.info(this.configuration)

// Finally write the new configuration in the file
fs.writeFileSync(this.configurationFile, this.configuration, {
Expand Down
2 changes: 1 addition & 1 deletion src/fixtures/nuxt/blank.expected.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// Default Pages configuration for Nuxt
export default {router: {base: '/docs/'}}
export default {target: 'static', router: {base: '/docs/'}}
1 change: 1 addition & 0 deletions src/fixtures/nuxt/default.expected.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export default {
// Disable server-side rendering: https://go.nuxtjs.dev/ssr-mode
target: 'static',
router: { base: "/docs/" },
ssr: false,

Expand Down
9 changes: 8 additions & 1 deletion src/set-pages-path.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ function getConfigParserSettings(staticSiteGenerator, path) {
configurationFile: './nuxt.config.js',
blankConfigurationFile: `${__dirname}/blank-configurations/nuxt.js`,
properties: {
'router.base': path
// Configure a base path on the router
'router.base': path,

// Set the target to static too
// https://nuxtjs.org/docs/configuration-glossary/configuration-target/
target: 'static'
}
}
case 'next':
Expand All @@ -23,6 +28,7 @@ function getConfigParserSettings(staticSiteGenerator, path) {
configurationFile: './next.config.js',
blankConfigurationFile: `${__dirname}/blank-configurations/next.js`,
properties: {
// Configure a base path
basePath: path,

// Disable server side image optimization too
Expand All @@ -35,6 +41,7 @@ function getConfigParserSettings(staticSiteGenerator, path) {
configurationFile: './gatsby-config.js',
blankConfigurationFile: `${__dirname}/blank-configurations/gatsby.js`,
properties: {
// Configure a path prefix
pathPrefix: path
}
}
Expand Down

0 comments on commit 8981dbc

Please sign in to comment.