mirror of
https://github.com/actions/configure-pages.git
synced 2026-03-30 18:14:51 +00:00
Compare commits
40 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9a141972ca | ||
|
|
7d9bb68583 | ||
|
|
ec022f4ae9 | ||
|
|
f71d3d08f0 | ||
|
|
9ff7f29195 | ||
|
|
9b7553ef7f | ||
|
|
42451665cc | ||
|
|
adc528a6d8 | ||
|
|
789c331a21 | ||
|
|
ff1182a56a | ||
|
|
c872edcdfb | ||
|
|
c61e34fb27 | ||
|
|
a220556ffe | ||
|
|
491169de17 | ||
|
|
f19391002a | ||
|
|
742be05113 | ||
|
|
90b7c04b80 | ||
|
|
15f519fab9 | ||
|
|
f5b4063a62 | ||
|
|
d06799dbbe | ||
|
|
fad78054b6 | ||
|
|
64fa685553 | ||
|
|
891eba7f6e | ||
|
|
9f6ed02477 | ||
|
|
68595d0746 | ||
|
|
4f27d51853 | ||
|
|
1395534a78 | ||
|
|
7c3932ff89 | ||
|
|
404d23c4a6 | ||
|
|
06406d74b2 | ||
|
|
cc95980c79 | ||
|
|
4f84ed2a14 | ||
|
|
f19d25133d | ||
|
|
f24e879a69 | ||
|
|
da85ca493f | ||
|
|
d949e1515f | ||
|
|
c69bbc2c2c | ||
|
|
8441c1b1dc | ||
|
|
4036d0f035 | ||
|
|
5c1535b807 |
5
.github/workflows/check-dist.yml
vendored
5
.github/workflows/check-dist.yml
vendored
@@ -18,6 +18,11 @@ on:
|
|||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
|
|
||||||
|
# This allows a subsequently queued workflow run to interrupt previous runs
|
||||||
|
concurrency:
|
||||||
|
group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}'
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
check-dist:
|
check-dist:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|||||||
34
.github/workflows/check-formatting.yml
vendored
Normal file
34
.github/workflows/check-formatting.yml
vendored
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
name: Checking formatting
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
pull_request:
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
|
# This allows a subsequently queued workflow run to interrupt previous runs
|
||||||
|
concurrency:
|
||||||
|
group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}'
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Setup Node.JS
|
||||||
|
uses: actions/setup-node@v3
|
||||||
|
with:
|
||||||
|
node-version: 16.x
|
||||||
|
cache: 'npm'
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: npm ci
|
||||||
|
|
||||||
|
- name: Verify formatting
|
||||||
|
run: npm run format:check
|
||||||
3
.github/workflows/draft-release.yml
vendored
3
.github/workflows/draft-release.yml
vendored
@@ -4,6 +4,9 @@ on:
|
|||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
draft-release:
|
draft-release:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|||||||
8
.github/workflows/test.yml
vendored
8
.github/workflows/test.yml
vendored
@@ -6,6 +6,14 @@ on:
|
|||||||
- main
|
- main
|
||||||
pull_request:
|
pull_request:
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
|
# This allows a subsequently queued workflow run to interrupt previous runs
|
||||||
|
concurrency:
|
||||||
|
group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}'
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
test:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
# Prettier (formatter) configuration
|
# Prettier (formatter) configuration
|
||||||
---
|
---
|
||||||
printWidth: 80
|
printWidth: 120
|
||||||
tabWidth: 2
|
tabWidth: 2
|
||||||
useTabs: false
|
useTabs: false
|
||||||
semi: false
|
semi: false
|
||||||
singleQuote: true
|
singleQuote: true
|
||||||
trailingComma: none
|
trailingComma: none
|
||||||
bracketSpacing: false
|
bracketSpacing: true
|
||||||
arrowParens: avoid
|
arrowParens: avoid
|
||||||
21
README.md
21
README.md
@@ -1,8 +1,8 @@
|
|||||||
# Configure-Pages
|
# configure-pages
|
||||||
|
|
||||||
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].
|
A GitHub 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.
|
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
|
# Usage
|
||||||
|
|
||||||
@@ -12,18 +12,13 @@ See [action.yml](action.yml) and the [Pages starter workflows][starter-workflows
|
|||||||
|
|
||||||
In order to release a new version of this Action:
|
In order to release a new version of this Action:
|
||||||
|
|
||||||
1. Locate the semantic version of the upcoming release (a draft is maintained by the [`draft-release` workflow][draft-release])
|
1. Locate the semantic version of the [upcoming release][release-list] (a draft is maintained by the [`draft-release` workflow][draft-release]).
|
||||||
|
|
||||||
2. Push a matching tag, for instance for `v0.1.0`:
|
2. Publish the draft release from the `main` branch with semantic version as the tag name, _with_ the checkbox to publish to the GitHub Marketplace checked. :ballot_box_with_check:
|
||||||
|
|
||||||
```bash
|
3. After publishing the release, the [`release` workflow][release] will automatically run to create/update the corresponding the major version tag such as `v0`.
|
||||||
git tag v0.1.0
|
|
||||||
git push origin v0.1.0
|
|
||||||
```
|
|
||||||
|
|
||||||
3. Publish the draft release (the major tag such as `v0` will be created/updated by the [`release` workflow][release])
|
⚠️ Environment approval is required. Check the [Release workflow run list][release-workflow-runs].
|
||||||
|
|
||||||
⚠️ Environment approval is required.
|
|
||||||
|
|
||||||
# License
|
# License
|
||||||
|
|
||||||
@@ -31,5 +26,7 @@ The scripts and documentation in this project are released under the [MIT Licens
|
|||||||
|
|
||||||
<!-- references -->
|
<!-- references -->
|
||||||
[starter-workflows]: https://github.com/actions/starter-workflows/tree/main/pages
|
[starter-workflows]: https://github.com/actions/starter-workflows/tree/main/pages
|
||||||
|
[release-list]: /releases
|
||||||
[draft-release]: .github/workflows/draft-release.yml
|
[draft-release]: .github/workflows/draft-release.yml
|
||||||
[release]: .github/workflows/release.yml
|
[release]: .github/workflows/release.yml
|
||||||
|
[release-workflow-runs]: /actions/workflows/release.yml
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
name: 'Configure Pages'
|
name: 'Configure GitHub Pages'
|
||||||
description: 'A GitHub Action to enable Pages, extract various metadata about a site, and configure some supported static site generators.'
|
description: 'A GitHub Action to enable Pages, extract various metadata about a site, and configure some supported static site generators.'
|
||||||
author: 'GitHub'
|
author: 'GitHub'
|
||||||
runs:
|
runs:
|
||||||
@@ -6,7 +6,10 @@ runs:
|
|||||||
main: 'dist/index.js'
|
main: 'dist/index.js'
|
||||||
inputs:
|
inputs:
|
||||||
static_site_generator:
|
static_site_generator:
|
||||||
description: 'Optional static site generator to attempt to configure (nuxt, next or gatsby)'
|
description: 'Optional static site generator to attempt to configure: "nuxt", "next", "gatsby", or "sveltekit"'
|
||||||
|
required: false
|
||||||
|
generator_config_file:
|
||||||
|
description: 'Optional file path to static site generator configuration file'
|
||||||
required: false
|
required: false
|
||||||
token:
|
token:
|
||||||
description: 'GitHub token'
|
description: 'GitHub token'
|
||||||
|
|||||||
842
dist/index.js
vendored
842
dist/index.js
vendored
File diff suppressed because it is too large
Load Diff
2
dist/index.js.map
vendored
2
dist/index.js.map
vendored
File diff suppressed because one or more lines are too long
13
dist/licenses.txt
vendored
13
dist/licenses.txt
vendored
@@ -608,3 +608,16 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
THE SOFTWARE.
|
THE SOFTWARE.
|
||||||
|
|
||||||
|
|
||||||
|
uuid
|
||||||
|
MIT
|
||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2010-2020 Robert Kieffer and other contributors
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|||||||
8
dist/sveltekit.js
vendored
Normal file
8
dist/sveltekit.js
vendored
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
// Default Pages configuration for SvelteKit
|
||||||
|
import adapter from '@sveltejs/adapter-auto'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
kit: {
|
||||||
|
adapter: adapter()
|
||||||
|
}
|
||||||
|
}
|
||||||
33
package-lock.json
generated
33
package-lock.json
generated
@@ -9,7 +9,7 @@
|
|||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.8.2",
|
"@actions/core": "^1.9.1",
|
||||||
"axios": "^0.27.2",
|
"axios": "^0.27.2",
|
||||||
"axios-retry": "^3.2.5",
|
"axios-retry": "^3.2.5",
|
||||||
"espree": "^9.3.2",
|
"espree": "^9.3.2",
|
||||||
@@ -22,11 +22,12 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@actions/core": {
|
"node_modules/@actions/core": {
|
||||||
"version": "1.8.2",
|
"version": "1.9.1",
|
||||||
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.8.2.tgz",
|
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.9.1.tgz",
|
||||||
"integrity": "sha512-FXcBL7nyik8K5ODeCKlxi+vts7torOkoDAKfeh61EAkAy1HAvwn9uVzZBY0f15YcQTcZZ2/iSGBFHEuioZWfDA==",
|
"integrity": "sha512-5ad+U2YGrmmiw6du20AQW5XuWo7UKN2052FjSV7MX+Wfjf8sCqcsZe62NfgHys4QI4/Y+vQvLKYL8jWtA1ZBTA==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/http-client": "^2.0.1"
|
"@actions/http-client": "^2.0.1",
|
||||||
|
"uuid": "^8.3.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@actions/http-client": {
|
"node_modules/@actions/http-client": {
|
||||||
@@ -3476,6 +3477,14 @@
|
|||||||
"url": "https://github.com/sponsors/sindresorhus"
|
"url": "https://github.com/sponsors/sindresorhus"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/uuid": {
|
||||||
|
"version": "8.3.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz",
|
||||||
|
"integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==",
|
||||||
|
"bin": {
|
||||||
|
"uuid": "dist/bin/uuid"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/v8-to-istanbul": {
|
"node_modules/v8-to-istanbul": {
|
||||||
"version": "9.0.0",
|
"version": "9.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/v8-to-istanbul/-/v8-to-istanbul-9.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/v8-to-istanbul/-/v8-to-istanbul-9.0.0.tgz",
|
||||||
@@ -3595,11 +3604,12 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": {
|
"@actions/core": {
|
||||||
"version": "1.8.2",
|
"version": "1.9.1",
|
||||||
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.8.2.tgz",
|
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.9.1.tgz",
|
||||||
"integrity": "sha512-FXcBL7nyik8K5ODeCKlxi+vts7torOkoDAKfeh61EAkAy1HAvwn9uVzZBY0f15YcQTcZZ2/iSGBFHEuioZWfDA==",
|
"integrity": "sha512-5ad+U2YGrmmiw6du20AQW5XuWo7UKN2052FjSV7MX+Wfjf8sCqcsZe62NfgHys4QI4/Y+vQvLKYL8jWtA1ZBTA==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"@actions/http-client": "^2.0.1"
|
"@actions/http-client": "^2.0.1",
|
||||||
|
"uuid": "^8.3.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@actions/http-client": {
|
"@actions/http-client": {
|
||||||
@@ -6207,6 +6217,11 @@
|
|||||||
"integrity": "sha512-t0rzBq87m3fVcduHDUFhKmyyX+9eo6WQjZvf51Ea/M0Q7+T374Jp1aUiyUl0GKxp8M/OETVHSDvmkyPgvX+X2w==",
|
"integrity": "sha512-t0rzBq87m3fVcduHDUFhKmyyX+9eo6WQjZvf51Ea/M0Q7+T374Jp1aUiyUl0GKxp8M/OETVHSDvmkyPgvX+X2w==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"uuid": {
|
||||||
|
"version": "8.3.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz",
|
||||||
|
"integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg=="
|
||||||
|
},
|
||||||
"v8-to-istanbul": {
|
"v8-to-istanbul": {
|
||||||
"version": "9.0.0",
|
"version": "9.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/v8-to-istanbul/-/v8-to-istanbul-9.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/v8-to-istanbul/-/v8-to-istanbul-9.0.0.tgz",
|
||||||
|
|||||||
@@ -5,7 +5,9 @@
|
|||||||
"description": "A GitHub 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.",
|
"description": "A GitHub 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.",
|
||||||
"main": "./dist/index.js",
|
"main": "./dist/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"prepare": "ncc build src/index.js -o dist --source-map --license licenses.txt",
|
"format": "prettier --write 'src/**/*.js'",
|
||||||
|
"format:check": "prettier --check 'src/**/*.js'",
|
||||||
|
"prepare": "npm run format && ncc build src/index.js -o dist --source-map --license licenses.txt",
|
||||||
"test": "jest"
|
"test": "jest"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
@@ -19,7 +21,7 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/actions/configure-pages#readme",
|
"homepage": "https://github.com/actions/configure-pages#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.8.2",
|
"@actions/core": "^1.9.1",
|
||||||
"axios": "^0.27.2",
|
"axios": "^0.27.2",
|
||||||
"axios-retry": "^3.2.5",
|
"axios-retry": "^3.2.5",
|
||||||
"espree": "^9.3.2",
|
"espree": "^9.3.2",
|
||||||
|
|||||||
@@ -53,9 +53,7 @@ describe('apiClient', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('handles a 409 response when the page already exists', async () => {
|
it('handles a 409 response when the page already exists', async () => {
|
||||||
jest
|
jest.spyOn(axios, 'post').mockImplementationOnce(() => Promise.reject({ response: { status: 409 } }))
|
||||||
.spyOn(axios, 'post')
|
|
||||||
.mockImplementationOnce(() => Promise.reject({ response: { status: 409 } }))
|
|
||||||
|
|
||||||
// Simply assert that no error is raised
|
// Simply assert that no error is raised
|
||||||
const result = await apiClient.enablePagesSite({
|
const result = await apiClient.enablePagesSite({
|
||||||
@@ -67,9 +65,7 @@ describe('apiClient', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('re-raises errors on failure status codes', async () => {
|
it('re-raises errors on failure status codes', async () => {
|
||||||
jest
|
jest.spyOn(axios, 'post').mockImplementationOnce(() => Promise.reject({ response: { status: 404 } }))
|
||||||
.spyOn(axios, 'post')
|
|
||||||
.mockImplementationOnce(() => Promise.reject({ response: { status: 404 } }))
|
|
||||||
|
|
||||||
let erred = false
|
let erred = false
|
||||||
try {
|
try {
|
||||||
@@ -98,9 +94,7 @@ describe('apiClient', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('re-raises errors on failure status codes', async () => {
|
it('re-raises errors on failure status codes', async () => {
|
||||||
jest
|
jest.spyOn(axios, 'get').mockImplementationOnce(() => Promise.reject({ response: { status: 404 } }))
|
||||||
.spyOn(axios, 'get')
|
|
||||||
.mockImplementationOnce(() => Promise.reject({ response: { status: 404 } }))
|
|
||||||
|
|
||||||
let erred = false
|
let erred = false
|
||||||
try {
|
try {
|
||||||
@@ -203,7 +197,8 @@ describe('apiClient', () => {
|
|||||||
|
|
||||||
it('makes second request to get page if create fails because of existence', async () => {
|
it('makes second request to get page if create fails because of existence', async () => {
|
||||||
const PAGE_OBJECT = { html_url: 'https://actions.github.io/is-awesome/' }
|
const PAGE_OBJECT = { html_url: 'https://actions.github.io/is-awesome/' }
|
||||||
jest.spyOn(axios, 'get')
|
jest
|
||||||
|
.spyOn(axios, 'get')
|
||||||
.mockImplementationOnce(() => Promise.reject({ response: { status: 404 } }))
|
.mockImplementationOnce(() => Promise.reject({ response: { status: 404 } }))
|
||||||
.mockImplementationOnce(() => Promise.resolve({ status: 200, data: PAGE_OBJECT }))
|
.mockImplementationOnce(() => Promise.resolve({ status: 200, data: PAGE_OBJECT }))
|
||||||
jest.spyOn(axios, 'post').mockImplementationOnce(() => Promise.reject({ response: { status: 409 } }))
|
jest.spyOn(axios, 'post').mockImplementationOnce(() => Promise.reject({ response: { status: 409 } }))
|
||||||
@@ -217,5 +212,4 @@ describe('apiClient', () => {
|
|||||||
expect(axios.post).toHaveBeenCalledTimes(1)
|
expect(axios.post).toHaveBeenCalledTimes(1)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|||||||
8
src/blank-configurations/sveltekit.js
Normal file
8
src/blank-configurations/sveltekit.js
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
// Default Pages configuration for SvelteKit
|
||||||
|
import adapter from '@sveltejs/adapter-auto'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
kit: {
|
||||||
|
adapter: adapter()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -31,7 +31,7 @@ class ConfigParser {
|
|||||||
// Ctor
|
// Ctor
|
||||||
// - configurationFile: path to the configuration file
|
// - configurationFile: path to the configuration file
|
||||||
// - blankConfigurationFile: a blank configuration file to use if non was previously found
|
// - blankConfigurationFile: a blank configuration file to use if non was previously found
|
||||||
constructor({configurationFile, blankConfigurationFile, properties}) {
|
constructor({ configurationFile, blankConfigurationFile, properties }) {
|
||||||
// Save field
|
// Save field
|
||||||
this.configurationFile = configurationFile
|
this.configurationFile = configurationFile
|
||||||
this.properties = properties
|
this.properties = properties
|
||||||
@@ -56,16 +56,32 @@ class ConfigParser {
|
|||||||
// Return the configuration object or null.
|
// Return the configuration object or null.
|
||||||
findConfigurationObject(ast) {
|
findConfigurationObject(ast) {
|
||||||
// Try to find a default export
|
// Try to find a default export
|
||||||
var defaultExport = ast.body.find(
|
var defaultExport = ast.body.find(node => node.type === 'ExportDefaultDeclaration')
|
||||||
node =>
|
|
||||||
node.type === 'ExportDefaultDeclaration' &&
|
// Direct default export
|
||||||
node.declaration.type === 'ObjectExpression'
|
if (defaultExport && defaultExport.declaration.type === 'ObjectExpression') {
|
||||||
)
|
core.info('Found configuration object in direct default export declaration')
|
||||||
if (defaultExport) {
|
|
||||||
core.info('Found configuration object in default export declaration')
|
|
||||||
return defaultExport.declaration
|
return defaultExport.declaration
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Indirect default export
|
||||||
|
else if (defaultExport && defaultExport.declaration.type === 'Identifier') {
|
||||||
|
const identifierName = defaultExport.declaration.name
|
||||||
|
const identifierDefinition = ast.body.find(
|
||||||
|
node =>
|
||||||
|
node.type === 'VariableDeclaration' &&
|
||||||
|
node.declarations.length == 1 &&
|
||||||
|
node.declarations[0].type === 'VariableDeclarator' &&
|
||||||
|
node.declarations[0].id.type === 'Identifier' &&
|
||||||
|
node.declarations[0].id.name === identifierName &&
|
||||||
|
node.declarations[0].init.type === 'ObjectExpression'
|
||||||
|
)
|
||||||
|
if (identifierDefinition) {
|
||||||
|
core.info('Found configuration object in indirect default export declaration')
|
||||||
|
return identifierDefinition.declarations[0].init
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Try to find a module export
|
// Try to find a module export
|
||||||
var moduleExport = ast.body.find(
|
var moduleExport = ast.body.find(
|
||||||
node =>
|
node =>
|
||||||
@@ -80,19 +96,13 @@ class ConfigParser {
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Direct module export
|
// Direct module export
|
||||||
if (
|
if (moduleExport && moduleExport.expression.right.type === 'ObjectExpression') {
|
||||||
moduleExport &&
|
|
||||||
moduleExport.expression.right.type === 'ObjectExpression'
|
|
||||||
) {
|
|
||||||
core.info('Found configuration object in direct module export')
|
core.info('Found configuration object in direct module export')
|
||||||
return moduleExport.expression.right
|
return moduleExport.expression.right
|
||||||
}
|
}
|
||||||
|
|
||||||
// Indirect module export
|
// Indirect module export
|
||||||
else if (
|
else if (moduleExport && moduleExport.expression.right.type === 'Identifier') {
|
||||||
moduleExport &&
|
|
||||||
moduleExport.expression.right.type === 'Identifier'
|
|
||||||
) {
|
|
||||||
const identifierName = moduleExport && moduleExport.expression.right.name
|
const identifierName = moduleExport && moduleExport.expression.right.name
|
||||||
const identifierDefinition = ast.body.find(
|
const identifierDefinition = ast.body.find(
|
||||||
node =>
|
node =>
|
||||||
@@ -120,9 +130,7 @@ class ConfigParser {
|
|||||||
// Try to find a property matching a given name
|
// Try to find a property matching a given name
|
||||||
const property =
|
const property =
|
||||||
object.type === 'ObjectExpression' &&
|
object.type === 'ObjectExpression' &&
|
||||||
object.properties.find(
|
object.properties.find(node => node.key.type === 'Identifier' && node.key.name === name)
|
||||||
node => node.key.type === 'Identifier' && node.key.name === name
|
|
||||||
)
|
|
||||||
|
|
||||||
// Return the property's value (if found) or null
|
// Return the property's value (if found) or null
|
||||||
if (property) {
|
if (property) {
|
||||||
@@ -142,9 +150,7 @@ class ConfigParser {
|
|||||||
return `${properties[startIndex]}: ${JSON.stringify(propertyValue)}`
|
return `${properties[startIndex]}: ${JSON.stringify(propertyValue)}`
|
||||||
} else {
|
} else {
|
||||||
return (
|
return (
|
||||||
`${properties[startIndex]}: {` +
|
`${properties[startIndex]}: {` + this.getPropertyDeclaration(properties, startIndex + 1, propertyValue) + '}'
|
||||||
this.getPropertyDeclaration(properties, startIndex + 1, propertyValue) +
|
|
||||||
'}'
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -183,7 +189,7 @@ class ConfigParser {
|
|||||||
var depth = 0
|
var depth = 0
|
||||||
const properties = propertyName.split('.')
|
const properties = propertyName.split('.')
|
||||||
var lastNode = configurationObject
|
var lastNode = configurationObject
|
||||||
while (1) {
|
while (true) {
|
||||||
// Find the node for the current property
|
// Find the node for the current property
|
||||||
var propertyNode = this.findProperty(lastNode, properties[depth])
|
var propertyNode = this.findProperty(lastNode, properties[depth])
|
||||||
|
|
||||||
@@ -222,11 +228,7 @@ class ConfigParser {
|
|||||||
// Create nested properties in the configuration file
|
// Create nested properties in the configuration file
|
||||||
else {
|
else {
|
||||||
// Build the declaration to inject
|
// Build the declaration to inject
|
||||||
const declaration = this.getPropertyDeclaration(
|
const declaration = this.getPropertyDeclaration(properties, depth, propertyValue)
|
||||||
properties,
|
|
||||||
depth,
|
|
||||||
propertyValue
|
|
||||||
)
|
|
||||||
|
|
||||||
// The last node identified is an object expression, so do the assignment
|
// The last node identified is an object expression, so do the assignment
|
||||||
if (lastNode.type === 'ObjectExpression') {
|
if (lastNode.type === 'ObjectExpression') {
|
||||||
@@ -273,4 +275,4 @@ class ConfigParser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {ConfigParser}
|
module.exports = { ConfigParser }
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
|
const core = require('@actions/core')
|
||||||
|
|
||||||
const {ConfigParser} = require('./config-parser')
|
const { ConfigParser } = require('./config-parser')
|
||||||
const {getTempFolder, compareFiles} = require('./test-helpers')
|
const { getTempFolder, compareFiles } = require('./test-helpers')
|
||||||
|
|
||||||
// Get the temp folder
|
// Get the temp folder
|
||||||
const tempFolder = getTempFolder()
|
const tempFolder = getTempFolder()
|
||||||
@@ -11,7 +12,6 @@ const cases = [
|
|||||||
//
|
//
|
||||||
// Default export
|
// Default export
|
||||||
//
|
//
|
||||||
|
|
||||||
{
|
{
|
||||||
property: 'property',
|
property: 'property',
|
||||||
source: `export default {}`,
|
source: `export default {}`,
|
||||||
@@ -89,6 +89,30 @@ const cases = [
|
|||||||
expected: `export default { a2: false, a1: { a2: "value", a3: [12]}}`
|
expected: `export default { a2: false, a1: { a2: "value", a3: [12]}}`
|
||||||
},
|
},
|
||||||
|
|
||||||
|
//
|
||||||
|
// Indirect default export
|
||||||
|
//
|
||||||
|
{
|
||||||
|
property: 'property',
|
||||||
|
source: `const config = {}; export default config`,
|
||||||
|
expected: `const config = { property: "value"}; export default config`
|
||||||
|
},
|
||||||
|
{
|
||||||
|
property: 'property',
|
||||||
|
source: `var config = {}; export default config`,
|
||||||
|
expected: `var config = { property: "value"}; export default config`
|
||||||
|
},
|
||||||
|
{
|
||||||
|
property: 'a.b.c',
|
||||||
|
source: `var config = {}; export default config`,
|
||||||
|
expected: `var config = { a: { b: { c: "value"}}}; export default config`
|
||||||
|
},
|
||||||
|
{
|
||||||
|
property: 'a.b.c',
|
||||||
|
source: `var config = { a: { b: [], c: "hello"}}; export default config`,
|
||||||
|
expected: `var config = { a: { b: { c: "value"}, c: "hello"}}; export default config`
|
||||||
|
},
|
||||||
|
|
||||||
//
|
//
|
||||||
// Direct module exports
|
// Direct module exports
|
||||||
//
|
//
|
||||||
@@ -134,15 +158,25 @@ const cases = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
describe('config-parser', () => {
|
describe('config-parser', () => {
|
||||||
cases.forEach(({property, source, expected}, index) => {
|
beforeEach(() => {
|
||||||
it(`Inject path properly for case #${index}`, () => {
|
jest.restoreAllMocks()
|
||||||
|
|
||||||
|
// Mock error/warning/info/debug to silence their output
|
||||||
|
jest.spyOn(core, 'error').mockImplementation(jest.fn())
|
||||||
|
jest.spyOn(core, 'warning').mockImplementation(jest.fn())
|
||||||
|
jest.spyOn(core, 'info').mockImplementation(jest.fn())
|
||||||
|
jest.spyOn(core, 'debug').mockImplementation(jest.fn())
|
||||||
|
})
|
||||||
|
|
||||||
|
cases.forEach(({ property, source, expected }, index) => {
|
||||||
|
it(`injects path properly for case #${index}`, () => {
|
||||||
// Write the source file
|
// Write the source file
|
||||||
const sourceFile = `${tempFolder}/source.js`
|
const sourceFile = `${tempFolder}/source.js`
|
||||||
fs.writeFileSync(sourceFile, source, {encoding: 'utf8'})
|
fs.writeFileSync(sourceFile, source, { encoding: 'utf8' })
|
||||||
|
|
||||||
// Write the expected file
|
// Write the expected file
|
||||||
const expectedFile = `${tempFolder}/expected.js`
|
const expectedFile = `${tempFolder}/expected.js`
|
||||||
fs.writeFileSync(expectedFile, expected, {encoding: 'utf8'})
|
fs.writeFileSync(expectedFile, expected, { encoding: 'utf8' })
|
||||||
|
|
||||||
// Update the settings and do the injection
|
// Update the settings and do the injection
|
||||||
new ConfigParser({
|
new ConfigParser({
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ function getRequiredVars() {
|
|||||||
repositoryNwo: process.env.GITHUB_REPOSITORY,
|
repositoryNwo: process.env.GITHUB_REPOSITORY,
|
||||||
githubToken: core.getInput('token'),
|
githubToken: core.getInput('token'),
|
||||||
staticSiteGenerator: core.getInput('static_site_generator'),
|
staticSiteGenerator: core.getInput('static_site_generator'),
|
||||||
|
generatorConfigFile: core.getInput('generator_config_file'),
|
||||||
enablement: core.getInput('enablement') !== 'false'
|
enablement: core.getInput('enablement') !== 'false'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -22,4 +23,4 @@ function getContext() {
|
|||||||
return requiredVars
|
return requiredVars
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {getContext}
|
module.exports = { getContext }
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
// Default Pages configuration for Gatsby
|
// Default Pages configuration for Gatsby
|
||||||
module.exports = { pathPrefix: "/docs/" }
|
module.exports = { pathPrefix: '/docs/' }
|
||||||
|
|||||||
7
src/fixtures/gatsby/default.cjs
Normal file
7
src/fixtures/gatsby/default.cjs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
module.exports = {
|
||||||
|
siteMetadata: {
|
||||||
|
title: `My Gatsby Site`,
|
||||||
|
siteUrl: `https://www.yourdomain.tld`,
|
||||||
|
},
|
||||||
|
plugins: [],
|
||||||
|
}
|
||||||
8
src/fixtures/gatsby/default.expected.cjs
Normal file
8
src/fixtures/gatsby/default.expected.cjs
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
module.exports = {
|
||||||
|
pathPrefix: "/docs/",
|
||||||
|
siteMetadata: {
|
||||||
|
title: `My Gatsby Site`,
|
||||||
|
siteUrl: `https://www.yourdomain.tld`,
|
||||||
|
},
|
||||||
|
plugins: [],
|
||||||
|
}
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
pathPrefix: "/docs/",
|
pathPrefix: '/docs/',
|
||||||
siteMetadata: {
|
siteMetadata: {
|
||||||
title: `My Gatsby Site`,
|
title: `My Gatsby Site`,
|
||||||
siteUrl: `https://www.yourdomain.tld`,
|
siteUrl: `https://www.yourdomain.tld`
|
||||||
},
|
},
|
||||||
plugins: [],
|
plugins: []
|
||||||
}
|
}
|
||||||
8
src/fixtures/gatsby/default.expected.mjs
Normal file
8
src/fixtures/gatsby/default.expected.mjs
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
export default {
|
||||||
|
pathPrefix: "/docs/",
|
||||||
|
siteMetadata: {
|
||||||
|
title: `My Gatsby Site`,
|
||||||
|
siteUrl: `https://www.yourdomain.tld`,
|
||||||
|
},
|
||||||
|
plugins: [],
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
siteMetadata: {
|
siteMetadata: {
|
||||||
title: `My Gatsby Site`,
|
title: `My Gatsby Site`,
|
||||||
siteUrl: `https://www.yourdomain.tld`,
|
siteUrl: `https://www.yourdomain.tld`
|
||||||
},
|
},
|
||||||
plugins: [],
|
plugins: []
|
||||||
}
|
}
|
||||||
7
src/fixtures/gatsby/default.mjs
Normal file
7
src/fixtures/gatsby/default.mjs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
export default {
|
||||||
|
siteMetadata: {
|
||||||
|
title: `My Gatsby Site`,
|
||||||
|
siteUrl: `https://www.yourdomain.tld`,
|
||||||
|
},
|
||||||
|
plugins: [],
|
||||||
|
}
|
||||||
@@ -1,6 +1,3 @@
|
|||||||
// Default Pages configuration for Next
|
// Default Pages configuration for Next
|
||||||
const nextConfig = {
|
const nextConfig = { experimental: { images: { unoptimized: true } }, basePath: '/docs' }
|
||||||
experimental: {images: {unoptimized: true}},
|
|
||||||
basePath: '/docs'
|
|
||||||
}
|
|
||||||
module.exports = nextConfig
|
module.exports = nextConfig
|
||||||
|
|||||||
7
src/fixtures/next/default.cjs
Normal file
7
src/fixtures/next/default.cjs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
/** @type {import('next').NextConfig} */
|
||||||
|
const nextConfig = {
|
||||||
|
reactStrictMode: true,
|
||||||
|
swcMinify: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = nextConfig
|
||||||
9
src/fixtures/next/default.expected.cjs
Normal file
9
src/fixtures/next/default.expected.cjs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
/** @type {import('next').NextConfig} */
|
||||||
|
const nextConfig = {
|
||||||
|
experimental: {images: {unoptimized: true}},
|
||||||
|
basePath: '/docs',
|
||||||
|
reactStrictMode: true,
|
||||||
|
swcMinify: true
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = nextConfig
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
/** @type {import('next').NextConfig} */
|
/** @type {import('next').NextConfig} */
|
||||||
const nextConfig = {
|
const nextConfig = {
|
||||||
experimental: {images: {unoptimized: true}},
|
experimental: { images: { unoptimized: true } },
|
||||||
basePath: '/docs',
|
basePath: '/docs',
|
||||||
reactStrictMode: true,
|
reactStrictMode: true,
|
||||||
swcMinify: true
|
swcMinify: true
|
||||||
|
|||||||
9
src/fixtures/next/default.expected.mjs
Normal file
9
src/fixtures/next/default.expected.mjs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
/** @type {import('next').NextConfig} */
|
||||||
|
const nextConfig = {
|
||||||
|
experimental: {images: {unoptimized: true}},
|
||||||
|
basePath: '/docs',
|
||||||
|
reactStrictMode: true,
|
||||||
|
swcMinify: true
|
||||||
|
}
|
||||||
|
|
||||||
|
export default nextConfig
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
/** @type {import('next').NextConfig} */
|
/** @type {import('next').NextConfig} */
|
||||||
const nextConfig = {
|
const nextConfig = {
|
||||||
reactStrictMode: true,
|
reactStrictMode: true,
|
||||||
swcMinify: true,
|
swcMinify: true
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = nextConfig
|
module.exports = nextConfig
|
||||||
7
src/fixtures/next/default.mjs
Normal file
7
src/fixtures/next/default.mjs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
/** @type {import('next').NextConfig} */
|
||||||
|
const nextConfig = {
|
||||||
|
reactStrictMode: true,
|
||||||
|
swcMinify: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
export default nextConfig
|
||||||
15
src/fixtures/nuxt/async.cjs
Normal file
15
src/fixtures/nuxt/async.cjs
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
const getAllDynamicRoute = async function() {
|
||||||
|
const routes = await (async () => {
|
||||||
|
return ['/posts/hello-world', '/posts/hello-again'];
|
||||||
|
})();
|
||||||
|
return routes;
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
mode: 'universal',
|
||||||
|
generate: {
|
||||||
|
async routes () {
|
||||||
|
return getAllDynamicRoute();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
17
src/fixtures/nuxt/async.expected.cjs
Normal file
17
src/fixtures/nuxt/async.expected.cjs
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
const getAllDynamicRoute = async function() {
|
||||||
|
const routes = await (async () => {
|
||||||
|
return ['/posts/hello-world', '/posts/hello-again'];
|
||||||
|
})();
|
||||||
|
return routes;
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
target: 'static',
|
||||||
|
router: {base: '/docs/'},
|
||||||
|
mode: 'universal',
|
||||||
|
generate: {
|
||||||
|
async routes () {
|
||||||
|
return getAllDynamicRoute();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -1,17 +1,17 @@
|
|||||||
const getAllDynamicRoute = async function() {
|
const getAllDynamicRoute = async function () {
|
||||||
const routes = await (async () => {
|
const routes = await (async () => {
|
||||||
return ['/posts/hello-world', '/posts/hello-again'];
|
return ['/posts/hello-world', '/posts/hello-again']
|
||||||
})();
|
})()
|
||||||
return routes;
|
return routes
|
||||||
};
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
target: 'static',
|
target: 'static',
|
||||||
router: {base: '/docs/'},
|
router: { base: '/docs/' },
|
||||||
mode: 'universal',
|
mode: 'universal',
|
||||||
generate: {
|
generate: {
|
||||||
async routes () {
|
async routes() {
|
||||||
return getAllDynamicRoute();
|
return getAllDynamicRoute()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|||||||
17
src/fixtures/nuxt/async.expected.mjs
Normal file
17
src/fixtures/nuxt/async.expected.mjs
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
const getAllDynamicRoute = async function() {
|
||||||
|
const routes = await (async () => {
|
||||||
|
return ['/posts/hello-world', '/posts/hello-again'];
|
||||||
|
})();
|
||||||
|
return routes;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default {
|
||||||
|
target: 'static',
|
||||||
|
router: {base: '/docs/'},
|
||||||
|
mode: 'universal',
|
||||||
|
generate: {
|
||||||
|
async routes () {
|
||||||
|
return getAllDynamicRoute();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -1,15 +1,15 @@
|
|||||||
const getAllDynamicRoute = async function() {
|
const getAllDynamicRoute = async function () {
|
||||||
const routes = await (async () => {
|
const routes = await (async () => {
|
||||||
return ['/posts/hello-world', '/posts/hello-again'];
|
return ['/posts/hello-world', '/posts/hello-again']
|
||||||
})();
|
})()
|
||||||
return routes;
|
return routes
|
||||||
};
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
mode: 'universal',
|
mode: 'universal',
|
||||||
generate: {
|
generate: {
|
||||||
async routes () {
|
async routes() {
|
||||||
return getAllDynamicRoute();
|
return getAllDynamicRoute()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|||||||
15
src/fixtures/nuxt/async.mjs
Normal file
15
src/fixtures/nuxt/async.mjs
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
const getAllDynamicRoute = async function() {
|
||||||
|
const routes = await (async () => {
|
||||||
|
return ['/posts/hello-world', '/posts/hello-again'];
|
||||||
|
})();
|
||||||
|
return routes;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default {
|
||||||
|
mode: 'universal',
|
||||||
|
generate: {
|
||||||
|
async routes () {
|
||||||
|
return getAllDynamicRoute();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -1,2 +1,2 @@
|
|||||||
// Default Pages configuration for Nuxt
|
// Default Pages configuration for Nuxt
|
||||||
export default {target: 'static', router: {base: '/docs/'}}
|
export default { target: 'static', router: { base: '/docs/' } }
|
||||||
|
|||||||
44
src/fixtures/nuxt/default.cjs
Normal file
44
src/fixtures/nuxt/default.cjs
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
module.exports = {
|
||||||
|
// Disable server-side rendering: https://go.nuxtjs.dev/ssr-mode
|
||||||
|
ssr: false,
|
||||||
|
|
||||||
|
// Global page headers: https://go.nuxtjs.dev/config-head
|
||||||
|
head: {
|
||||||
|
title: 'nuxt',
|
||||||
|
htmlAttrs: {
|
||||||
|
lang: 'en'
|
||||||
|
},
|
||||||
|
meta: [
|
||||||
|
{ charset: 'utf-8' },
|
||||||
|
{ name: 'viewport', content: 'width=device-width, initial-scale=1' },
|
||||||
|
{ hid: 'description', name: 'description', content: '' },
|
||||||
|
{ name: 'format-detection', content: 'telephone=no' }
|
||||||
|
],
|
||||||
|
link: [
|
||||||
|
{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
// Global CSS: https://go.nuxtjs.dev/config-css
|
||||||
|
css: [
|
||||||
|
],
|
||||||
|
|
||||||
|
// Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins
|
||||||
|
plugins: [
|
||||||
|
],
|
||||||
|
|
||||||
|
// Auto import components: https://go.nuxtjs.dev/config-components
|
||||||
|
components: true,
|
||||||
|
|
||||||
|
// Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules
|
||||||
|
buildModules: [
|
||||||
|
],
|
||||||
|
|
||||||
|
// Modules: https://go.nuxtjs.dev/config-modules
|
||||||
|
modules: [
|
||||||
|
],
|
||||||
|
|
||||||
|
// Build Configuration: https://go.nuxtjs.dev/config-build
|
||||||
|
build: {
|
||||||
|
}
|
||||||
|
}
|
||||||
46
src/fixtures/nuxt/default.expected.cjs
Normal file
46
src/fixtures/nuxt/default.expected.cjs
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
module.exports = {
|
||||||
|
// Disable server-side rendering: https://go.nuxtjs.dev/ssr-mode
|
||||||
|
target: 'static',
|
||||||
|
router: { base: "/docs/" },
|
||||||
|
ssr: false,
|
||||||
|
|
||||||
|
// Global page headers: https://go.nuxtjs.dev/config-head
|
||||||
|
head: {
|
||||||
|
title: 'nuxt',
|
||||||
|
htmlAttrs: {
|
||||||
|
lang: 'en'
|
||||||
|
},
|
||||||
|
meta: [
|
||||||
|
{ charset: 'utf-8' },
|
||||||
|
{ name: 'viewport', content: 'width=device-width, initial-scale=1' },
|
||||||
|
{ hid: 'description', name: 'description', content: '' },
|
||||||
|
{ name: 'format-detection', content: 'telephone=no' }
|
||||||
|
],
|
||||||
|
link: [
|
||||||
|
{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
// Global CSS: https://go.nuxtjs.dev/config-css
|
||||||
|
css: [
|
||||||
|
],
|
||||||
|
|
||||||
|
// Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins
|
||||||
|
plugins: [
|
||||||
|
],
|
||||||
|
|
||||||
|
// Auto import components: https://go.nuxtjs.dev/config-components
|
||||||
|
components: true,
|
||||||
|
|
||||||
|
// Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules
|
||||||
|
buildModules: [
|
||||||
|
],
|
||||||
|
|
||||||
|
// Modules: https://go.nuxtjs.dev/config-modules
|
||||||
|
modules: [
|
||||||
|
],
|
||||||
|
|
||||||
|
// Build Configuration: https://go.nuxtjs.dev/config-build
|
||||||
|
build: {
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
export default {
|
export default {
|
||||||
// Disable server-side rendering: https://go.nuxtjs.dev/ssr-mode
|
// Disable server-side rendering: https://go.nuxtjs.dev/ssr-mode
|
||||||
target: 'static',
|
target: 'static',
|
||||||
router: { base: "/docs/" },
|
router: { base: '/docs/' },
|
||||||
ssr: false,
|
ssr: false,
|
||||||
|
|
||||||
// Global page headers: https://go.nuxtjs.dev/config-head
|
// Global page headers: https://go.nuxtjs.dev/config-head
|
||||||
@@ -16,31 +16,24 @@ export default {
|
|||||||
{ hid: 'description', name: 'description', content: '' },
|
{ hid: 'description', name: 'description', content: '' },
|
||||||
{ name: 'format-detection', content: 'telephone=no' }
|
{ name: 'format-detection', content: 'telephone=no' }
|
||||||
],
|
],
|
||||||
link: [
|
link: [{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }]
|
||||||
{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// Global CSS: https://go.nuxtjs.dev/config-css
|
// Global CSS: https://go.nuxtjs.dev/config-css
|
||||||
css: [
|
css: [],
|
||||||
],
|
|
||||||
|
|
||||||
// Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins
|
// Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins
|
||||||
plugins: [
|
plugins: [],
|
||||||
],
|
|
||||||
|
|
||||||
// Auto import components: https://go.nuxtjs.dev/config-components
|
// Auto import components: https://go.nuxtjs.dev/config-components
|
||||||
components: true,
|
components: true,
|
||||||
|
|
||||||
// Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules
|
// Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules
|
||||||
buildModules: [
|
buildModules: [],
|
||||||
],
|
|
||||||
|
|
||||||
// Modules: https://go.nuxtjs.dev/config-modules
|
// Modules: https://go.nuxtjs.dev/config-modules
|
||||||
modules: [
|
modules: [],
|
||||||
],
|
|
||||||
|
|
||||||
// Build Configuration: https://go.nuxtjs.dev/config-build
|
// Build Configuration: https://go.nuxtjs.dev/config-build
|
||||||
build: {
|
build: {}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
46
src/fixtures/nuxt/default.expected.mjs
Normal file
46
src/fixtures/nuxt/default.expected.mjs
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
export default {
|
||||||
|
// Disable server-side rendering: https://go.nuxtjs.dev/ssr-mode
|
||||||
|
target: 'static',
|
||||||
|
router: { base: "/docs/" },
|
||||||
|
ssr: false,
|
||||||
|
|
||||||
|
// Global page headers: https://go.nuxtjs.dev/config-head
|
||||||
|
head: {
|
||||||
|
title: 'nuxt',
|
||||||
|
htmlAttrs: {
|
||||||
|
lang: 'en'
|
||||||
|
},
|
||||||
|
meta: [
|
||||||
|
{ charset: 'utf-8' },
|
||||||
|
{ name: 'viewport', content: 'width=device-width, initial-scale=1' },
|
||||||
|
{ hid: 'description', name: 'description', content: '' },
|
||||||
|
{ name: 'format-detection', content: 'telephone=no' }
|
||||||
|
],
|
||||||
|
link: [
|
||||||
|
{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
// Global CSS: https://go.nuxtjs.dev/config-css
|
||||||
|
css: [
|
||||||
|
],
|
||||||
|
|
||||||
|
// Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins
|
||||||
|
plugins: [
|
||||||
|
],
|
||||||
|
|
||||||
|
// Auto import components: https://go.nuxtjs.dev/config-components
|
||||||
|
components: true,
|
||||||
|
|
||||||
|
// Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules
|
||||||
|
buildModules: [
|
||||||
|
],
|
||||||
|
|
||||||
|
// Modules: https://go.nuxtjs.dev/config-modules
|
||||||
|
modules: [
|
||||||
|
],
|
||||||
|
|
||||||
|
// Build Configuration: https://go.nuxtjs.dev/config-build
|
||||||
|
build: {
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,31 +14,24 @@ export default {
|
|||||||
{ hid: 'description', name: 'description', content: '' },
|
{ hid: 'description', name: 'description', content: '' },
|
||||||
{ name: 'format-detection', content: 'telephone=no' }
|
{ name: 'format-detection', content: 'telephone=no' }
|
||||||
],
|
],
|
||||||
link: [
|
link: [{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }]
|
||||||
{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// Global CSS: https://go.nuxtjs.dev/config-css
|
// Global CSS: https://go.nuxtjs.dev/config-css
|
||||||
css: [
|
css: [],
|
||||||
],
|
|
||||||
|
|
||||||
// Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins
|
// Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins
|
||||||
plugins: [
|
plugins: [],
|
||||||
],
|
|
||||||
|
|
||||||
// Auto import components: https://go.nuxtjs.dev/config-components
|
// Auto import components: https://go.nuxtjs.dev/config-components
|
||||||
components: true,
|
components: true,
|
||||||
|
|
||||||
// Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules
|
// Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules
|
||||||
buildModules: [
|
buildModules: [],
|
||||||
],
|
|
||||||
|
|
||||||
// Modules: https://go.nuxtjs.dev/config-modules
|
// Modules: https://go.nuxtjs.dev/config-modules
|
||||||
modules: [
|
modules: [],
|
||||||
],
|
|
||||||
|
|
||||||
// Build Configuration: https://go.nuxtjs.dev/config-build
|
// Build Configuration: https://go.nuxtjs.dev/config-build
|
||||||
build: {
|
build: {}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
44
src/fixtures/nuxt/default.mjs
Normal file
44
src/fixtures/nuxt/default.mjs
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
export default {
|
||||||
|
// Disable server-side rendering: https://go.nuxtjs.dev/ssr-mode
|
||||||
|
ssr: false,
|
||||||
|
|
||||||
|
// Global page headers: https://go.nuxtjs.dev/config-head
|
||||||
|
head: {
|
||||||
|
title: 'nuxt',
|
||||||
|
htmlAttrs: {
|
||||||
|
lang: 'en'
|
||||||
|
},
|
||||||
|
meta: [
|
||||||
|
{ charset: 'utf-8' },
|
||||||
|
{ name: 'viewport', content: 'width=device-width, initial-scale=1' },
|
||||||
|
{ hid: 'description', name: 'description', content: '' },
|
||||||
|
{ name: 'format-detection', content: 'telephone=no' }
|
||||||
|
],
|
||||||
|
link: [
|
||||||
|
{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
// Global CSS: https://go.nuxtjs.dev/config-css
|
||||||
|
css: [
|
||||||
|
],
|
||||||
|
|
||||||
|
// Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins
|
||||||
|
plugins: [
|
||||||
|
],
|
||||||
|
|
||||||
|
// Auto import components: https://go.nuxtjs.dev/config-components
|
||||||
|
components: true,
|
||||||
|
|
||||||
|
// Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules
|
||||||
|
buildModules: [
|
||||||
|
],
|
||||||
|
|
||||||
|
// Modules: https://go.nuxtjs.dev/config-modules
|
||||||
|
modules: [
|
||||||
|
],
|
||||||
|
|
||||||
|
// Build Configuration: https://go.nuxtjs.dev/config-build
|
||||||
|
build: {
|
||||||
|
}
|
||||||
|
}
|
||||||
9
src/fixtures/sveltekit/blank.expected.js
Normal file
9
src/fixtures/sveltekit/blank.expected.js
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
// Default Pages configuration for SvelteKit
|
||||||
|
import adapter from '@sveltejs/adapter-auto'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
kit: {
|
||||||
|
paths: { base: '/docs' },
|
||||||
|
adapter: adapter()
|
||||||
|
}
|
||||||
|
}
|
||||||
1
src/fixtures/sveltekit/blank.js
Normal file
1
src/fixtures/sveltekit/blank.js
Normal file
@@ -0,0 +1 @@
|
|||||||
|
// This file is not read by the test suite
|
||||||
11
src/fixtures/sveltekit/default.expected.js
Normal file
11
src/fixtures/sveltekit/default.expected.js
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import adapter from '@sveltejs/adapter-auto'
|
||||||
|
|
||||||
|
/** @type {import('@sveltejs/kit').Config} */
|
||||||
|
const config = {
|
||||||
|
kit: {
|
||||||
|
paths: { base: '/docs' },
|
||||||
|
adapter: adapter()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default config
|
||||||
10
src/fixtures/sveltekit/default.js
Normal file
10
src/fixtures/sveltekit/default.js
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import adapter from '@sveltejs/adapter-auto'
|
||||||
|
|
||||||
|
/** @type {import('@sveltejs/kit').Config} */
|
||||||
|
const config = {
|
||||||
|
kit: {
|
||||||
|
adapter: adapter()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default config
|
||||||
@@ -9,15 +9,16 @@ const outputPagesBaseUrl = require('./output-pages-base-url')
|
|||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
try {
|
try {
|
||||||
const { repositoryNwo, githubToken, enablement, staticSiteGenerator } = getContext()
|
const { repositoryNwo, githubToken, enablement, staticSiteGenerator, generatorConfigFile } = getContext()
|
||||||
|
|
||||||
const pageObject = await findOrCreatePagesSite({ repositoryNwo, githubToken, enablement })
|
const pageObject = await findOrCreatePagesSite({ repositoryNwo, githubToken, enablement })
|
||||||
const siteUrl = new URL(pageObject.html_url)
|
const siteUrl = new URL(pageObject.html_url)
|
||||||
|
|
||||||
if (staticSiteGenerator) {
|
if (staticSiteGenerator) {
|
||||||
setPagesPath({ staticSiteGenerator, path: siteUrl.pathname })
|
setPagesPath({ staticSiteGenerator, generatorConfigFile, path: siteUrl.pathname })
|
||||||
}
|
}
|
||||||
outputPagesBaseUrl(siteUrl)
|
outputPagesBaseUrl(siteUrl)
|
||||||
|
core.exportVariable('GITHUB_PAGES', 'true')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
core.setFailed(error)
|
core.setFailed(error)
|
||||||
process.exit(1)
|
process.exit(1)
|
||||||
|
|||||||
@@ -24,10 +24,7 @@ describe('outputPagesBaseUrl', () => {
|
|||||||
outputPagesBaseUrl(new URL(baseUrl))
|
outputPagesBaseUrl(new URL(baseUrl))
|
||||||
|
|
||||||
expect(core.setOutput).toHaveBeenCalledWith('base_url', baseUrl)
|
expect(core.setOutput).toHaveBeenCalledWith('base_url', baseUrl)
|
||||||
expect(core.setOutput).toHaveBeenCalledWith(
|
expect(core.setOutput).toHaveBeenCalledWith('origin', 'https://octocat.github.io')
|
||||||
'origin',
|
|
||||||
'https://octocat.github.io'
|
|
||||||
)
|
|
||||||
expect(core.setOutput).toHaveBeenCalledWith('host', 'octocat.github.io')
|
expect(core.setOutput).toHaveBeenCalledWith('host', 'octocat.github.io')
|
||||||
expect(core.setOutput).toHaveBeenCalledWith('base_path', '/')
|
expect(core.setOutput).toHaveBeenCalledWith('base_path', '/')
|
||||||
})
|
})
|
||||||
@@ -38,10 +35,7 @@ describe('outputPagesBaseUrl', () => {
|
|||||||
outputPagesBaseUrl(new URL(baseUrl))
|
outputPagesBaseUrl(new URL(baseUrl))
|
||||||
|
|
||||||
expect(core.setOutput).toHaveBeenCalledWith('base_url', baseUrl)
|
expect(core.setOutput).toHaveBeenCalledWith('base_url', baseUrl)
|
||||||
expect(core.setOutput).toHaveBeenCalledWith(
|
expect(core.setOutput).toHaveBeenCalledWith('origin', 'https://octocat.github.io')
|
||||||
'origin',
|
|
||||||
'https://octocat.github.io'
|
|
||||||
)
|
|
||||||
expect(core.setOutput).toHaveBeenCalledWith('host', 'octocat.github.io')
|
expect(core.setOutput).toHaveBeenCalledWith('host', 'octocat.github.io')
|
||||||
expect(core.setOutput).toHaveBeenCalledWith('base_path', '/my-repo/')
|
expect(core.setOutput).toHaveBeenCalledWith('base_path', '/my-repo/')
|
||||||
})
|
})
|
||||||
@@ -52,10 +46,7 @@ describe('outputPagesBaseUrl', () => {
|
|||||||
outputPagesBaseUrl(new URL(baseUrl))
|
outputPagesBaseUrl(new URL(baseUrl))
|
||||||
|
|
||||||
expect(core.setOutput).toHaveBeenCalledWith('base_url', baseUrl)
|
expect(core.setOutput).toHaveBeenCalledWith('base_url', baseUrl)
|
||||||
expect(core.setOutput).toHaveBeenCalledWith(
|
expect(core.setOutput).toHaveBeenCalledWith('origin', 'https://www.example.com')
|
||||||
'origin',
|
|
||||||
'https://www.example.com'
|
|
||||||
)
|
|
||||||
expect(core.setOutput).toHaveBeenCalledWith('host', 'www.example.com')
|
expect(core.setOutput).toHaveBeenCalledWith('host', 'www.example.com')
|
||||||
expect(core.setOutput).toHaveBeenCalledWith('base_path', '/')
|
expect(core.setOutput).toHaveBeenCalledWith('base_path', '/')
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
const core = require('@actions/core')
|
const core = require('@actions/core')
|
||||||
const {ConfigParser} = require('./config-parser')
|
const { ConfigParser } = require('./config-parser')
|
||||||
|
|
||||||
// Return the settings to be passed to a {ConfigParser} for a given
|
// Return the settings to be passed to a {ConfigParser} for a given static site generator,
|
||||||
// static site generator and a Pages path value to inject
|
// optional configuration file path, and a Pages path value to inject
|
||||||
function getConfigParserSettings(staticSiteGenerator, path) {
|
function getConfigParserSettings({ staticSiteGenerator, generatorConfigFile, path }) {
|
||||||
switch (staticSiteGenerator) {
|
switch (staticSiteGenerator) {
|
||||||
case 'nuxt':
|
case 'nuxt':
|
||||||
return {
|
return {
|
||||||
configurationFile: './nuxt.config.js',
|
configurationFile: generatorConfigFile || './nuxt.config.js',
|
||||||
blankConfigurationFile: `${__dirname}/blank-configurations/nuxt.js`,
|
blankConfigurationFile: `${__dirname}/blank-configurations/nuxt.js`,
|
||||||
properties: {
|
properties: {
|
||||||
// Configure a base path on the router
|
// Configure a base path on the router
|
||||||
@@ -25,7 +25,7 @@ function getConfigParserSettings(staticSiteGenerator, path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
configurationFile: './next.config.js',
|
configurationFile: generatorConfigFile || './next.config.js',
|
||||||
blankConfigurationFile: `${__dirname}/blank-configurations/next.js`,
|
blankConfigurationFile: `${__dirname}/blank-configurations/next.js`,
|
||||||
properties: {
|
properties: {
|
||||||
// Configure a base path
|
// Configure a base path
|
||||||
@@ -38,23 +38,37 @@ function getConfigParserSettings(staticSiteGenerator, path) {
|
|||||||
}
|
}
|
||||||
case 'gatsby':
|
case 'gatsby':
|
||||||
return {
|
return {
|
||||||
configurationFile: './gatsby-config.js',
|
configurationFile: generatorConfigFile || './gatsby-config.js',
|
||||||
blankConfigurationFile: `${__dirname}/blank-configurations/gatsby.js`,
|
blankConfigurationFile: `${__dirname}/blank-configurations/gatsby.js`,
|
||||||
properties: {
|
properties: {
|
||||||
// Configure a path prefix
|
// Configure a path prefix
|
||||||
pathPrefix: path
|
pathPrefix: path
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
case 'sveltekit':
|
||||||
|
// SvelteKit does not want a trailing slash
|
||||||
|
if (path.endsWith('/')) {
|
||||||
|
path = path.slice(0, -1)
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
configurationFile: generatorConfigFile || './svelte.config.js',
|
||||||
|
blankConfigurationFile: `${__dirname}/blank-configurations/sveltekit.js`,
|
||||||
|
properties: {
|
||||||
|
// Configure a base path
|
||||||
|
'kit.paths.base': path
|
||||||
|
}
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
throw `Unsupported static site generator: ${staticSiteGenerator}`
|
throw `Unsupported static site generator: ${staticSiteGenerator}`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inject Pages configuration in a given static site generator's configuration file
|
// Inject Pages configuration in a given static site generator's configuration file
|
||||||
function setPagesPath({staticSiteGenerator, path}) {
|
function setPagesPath({ staticSiteGenerator, generatorConfigFile, path }) {
|
||||||
try {
|
try {
|
||||||
// Parse the configuration file and try to inject the Pages configuration in it
|
// Parse the configuration file and try to inject the Pages configuration in it
|
||||||
const settings = getConfigParserSettings(staticSiteGenerator, path)
|
const settings = getConfigParserSettings({ staticSiteGenerator, generatorConfigFile, path })
|
||||||
new ConfigParser(settings).injectAll()
|
new ConfigParser(settings).injectAll()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// Logging
|
// Logging
|
||||||
@@ -65,4 +79,4 @@ function setPagesPath({staticSiteGenerator, path}) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {getConfigParserSettings, setPagesPath}
|
module.exports = { getConfigParserSettings, setPagesPath }
|
||||||
|
|||||||
@@ -1,53 +1,105 @@
|
|||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
|
const core = require('@actions/core')
|
||||||
|
|
||||||
const {getConfigParserSettings} = require('./set-pages-path')
|
const { getConfigParserSettings } = require('./set-pages-path')
|
||||||
const {ConfigParser} = require('./config-parser')
|
const { ConfigParser } = require('./config-parser')
|
||||||
const {getTempFolder, compareFiles} = require('./test-helpers')
|
const { getTempFolder, compareFiles } = require('./test-helpers')
|
||||||
|
|
||||||
// Get the temp folder
|
// Get the temp folder
|
||||||
const tempFolder = getTempFolder()
|
const tempFolder = getTempFolder()
|
||||||
|
|
||||||
|
const SUPPORTED_GENERATORS = ['next', 'nuxt', 'gatsby', 'sveltekit']
|
||||||
|
const SUPPORTED_FILE_EXTENSIONS = ['.js', '.cjs', '.mjs']
|
||||||
|
|
||||||
// Test suite
|
// Test suite
|
||||||
describe('configParser', () => {
|
describe('configParser', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
jest.restoreAllMocks()
|
||||||
|
|
||||||
|
// Mock error/warning/info/debug to silence their output
|
||||||
|
jest.spyOn(core, 'error').mockImplementation(jest.fn())
|
||||||
|
jest.spyOn(core, 'warning').mockImplementation(jest.fn())
|
||||||
|
jest.spyOn(core, 'info').mockImplementation(jest.fn())
|
||||||
|
jest.spyOn(core, 'debug').mockImplementation(jest.fn())
|
||||||
|
})
|
||||||
|
|
||||||
// Iterate over the static site generators
|
// Iterate over the static site generators
|
||||||
;['next', 'nuxt', 'gatsby'].forEach(staticSiteGenerator => {
|
SUPPORTED_GENERATORS.forEach(staticSiteGenerator => {
|
||||||
// Folder containing the fixtures for a given static site generator
|
// Folder containing the fixtures for a given static site generator
|
||||||
const fixtureFolder = `${__dirname}/fixtures/${staticSiteGenerator}`
|
const fixtureFolder = `${__dirname}/fixtures/${staticSiteGenerator}`
|
||||||
|
|
||||||
// Iterate over the fixtures
|
// Get fixture files, excluding expected results
|
||||||
fs.readdirSync(fixtureFolder).forEach(configurationFile => {
|
const configurationFiles = fs.readdirSync(fixtureFolder).filter(filename => !filename.includes('.expected.'))
|
||||||
// Ignore expectation
|
|
||||||
if (configurationFile.endsWith('.expected.js')) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
it(`Inject path properly for ${staticSiteGenerator} in ${configurationFile}`, async () => {
|
// Iterate over the fixtures, outputting to default configuration file path
|
||||||
// Get settings for the static site generator
|
const defaultFileExtension = '.js'
|
||||||
const settings = getConfigParserSettings(staticSiteGenerator, '/docs/')
|
configurationFiles
|
||||||
|
.filter(filename => filename.endsWith(defaultFileExtension))
|
||||||
|
.forEach(configurationFile => {
|
||||||
|
it(`injects path properly for ${staticSiteGenerator} in ${configurationFile} to default configuration file`, async () => {
|
||||||
|
// Copy the source fixture to a temp file
|
||||||
|
const fixtureSourceFile = `${fixtureFolder}/${configurationFile}`
|
||||||
|
const fixtureTargetFile = `${tempFolder}/${configurationFile}`
|
||||||
|
if (configurationFile !== 'blank.js') {
|
||||||
|
fs.copyFileSync(fixtureSourceFile, fixtureTargetFile)
|
||||||
|
} else if (fs.existsSync(fixtureTargetFile)) {
|
||||||
|
fs.rmSync(fixtureTargetFile)
|
||||||
|
}
|
||||||
|
|
||||||
// Copy the source fixture to a temp file
|
// Get settings for the static site generator
|
||||||
const fixtureSourceFile = `${fixtureFolder}/${configurationFile}`
|
const settings = getConfigParserSettings({ staticSiteGenerator, path: '/docs/' })
|
||||||
const fixtureTargetFile = `${tempFolder}/${configurationFile}`
|
// Update the settings
|
||||||
if (configurationFile != 'blank.js') {
|
settings.configurationFile = fixtureTargetFile
|
||||||
fs.copyFileSync(fixtureSourceFile, fixtureTargetFile)
|
// Do the injection
|
||||||
} else if (fs.existsSync(fixtureTargetFile)) {
|
new ConfigParser(settings).injectAll()
|
||||||
fs.rmSync(fixtureTargetFile)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update the settings and do the injection
|
// Read the expected file
|
||||||
settings.configurationFile = fixtureTargetFile
|
const expectedFile = `${fixtureFolder}/${path.basename(
|
||||||
new ConfigParser(settings).injectAll()
|
configurationFile,
|
||||||
|
defaultFileExtension
|
||||||
|
)}.expected${defaultFileExtension}`
|
||||||
|
|
||||||
// Read the expected file
|
// Compare the actual and expected files
|
||||||
const expectedFile = `${fixtureFolder}/${path.basename(
|
compareFiles(settings.configurationFile, expectedFile)
|
||||||
configurationFile,
|
})
|
||||||
'.js'
|
|
||||||
)}.expected.js`
|
|
||||||
|
|
||||||
// Compare the actual and expected files
|
|
||||||
compareFiles(settings.configurationFile, expectedFile)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
SUPPORTED_FILE_EXTENSIONS.forEach(fileExtension => {
|
||||||
|
// Iterate over the fixtures, outputting to specified configuration file path
|
||||||
|
configurationFiles
|
||||||
|
.filter(filename => filename.endsWith(fileExtension))
|
||||||
|
.forEach(configurationFile => {
|
||||||
|
it(`injects path properly for ${staticSiteGenerator} in ${configurationFile} to specified *${fileExtension} configuration file`, async () => {
|
||||||
|
// Copy the source fixture to a temp file
|
||||||
|
const fixtureSourceFile = `${fixtureFolder}/${configurationFile}`
|
||||||
|
const fixtureTargetFile = `${tempFolder}/${configurationFile}`
|
||||||
|
if (configurationFile !== 'blank.js') {
|
||||||
|
fs.copyFileSync(fixtureSourceFile, fixtureTargetFile)
|
||||||
|
} else if (fs.existsSync(fixtureTargetFile)) {
|
||||||
|
fs.rmSync(fixtureTargetFile)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get settings for the static site generator
|
||||||
|
const settings = getConfigParserSettings({
|
||||||
|
staticSiteGenerator,
|
||||||
|
generatorConfigFile: fixtureTargetFile,
|
||||||
|
path: '/docs/'
|
||||||
|
})
|
||||||
|
|
||||||
|
// Do the injection
|
||||||
|
new ConfigParser(settings).injectAll()
|
||||||
|
|
||||||
|
// Read the expected file
|
||||||
|
const expectedFile = `${fixtureFolder}/${path.basename(
|
||||||
|
configurationFile,
|
||||||
|
fileExtension
|
||||||
|
)}.expected${fileExtension}`
|
||||||
|
|
||||||
|
// Compare the actual and expected files
|
||||||
|
compareFiles(settings.configurationFile, expectedFile)
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ const assert = require('assert')
|
|||||||
function getTempFolder() {
|
function getTempFolder() {
|
||||||
const tmpFolder = `${__dirname}/fixtures/tmp`
|
const tmpFolder = `${__dirname}/fixtures/tmp`
|
||||||
if (!fs.existsSync(tmpFolder)) {
|
if (!fs.existsSync(tmpFolder)) {
|
||||||
fs.mkdirSync(tmpFolder, {recursive: true})
|
fs.mkdirSync(tmpFolder, { recursive: true })
|
||||||
}
|
}
|
||||||
return tmpFolder
|
return tmpFolder
|
||||||
}
|
}
|
||||||
@@ -14,19 +14,21 @@ function getTempFolder() {
|
|||||||
// Read a JavaScript file and return it formatted
|
// Read a JavaScript file and return it formatted
|
||||||
function formatFile(file) {
|
function formatFile(file) {
|
||||||
const fileContent = fs.readFileSync(file, 'utf8')
|
const fileContent = fs.readFileSync(file, 'utf8')
|
||||||
return prettier.format(fileContent, {
|
return prettier
|
||||||
parser: 'espree',
|
.format(fileContent, {
|
||||||
|
parser: 'espree',
|
||||||
|
|
||||||
// Prettier options
|
// Prettier options
|
||||||
printWidth: 80,
|
printWidth: 120,
|
||||||
tabWidth: 2,
|
tabWidth: 2,
|
||||||
useTabs: false,
|
useTabs: false,
|
||||||
semi: false,
|
semi: false,
|
||||||
singleQuote: true,
|
singleQuote: true,
|
||||||
trailingComma: 'none',
|
trailingComma: 'none',
|
||||||
bracketSpacing: false,
|
bracketSpacing: true,
|
||||||
arrowParens: 'avoid'
|
arrowParens: 'avoid'
|
||||||
}).trim()
|
})
|
||||||
|
.trim()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compare two JavaScript files
|
// Compare two JavaScript files
|
||||||
@@ -34,4 +36,4 @@ function compareFiles(actualFile, expectedFile) {
|
|||||||
assert.equal(formatFile(actualFile), formatFile(expectedFile))
|
assert.equal(formatFile(actualFile), formatFile(expectedFile))
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {getTempFolder, formatFile, compareFiles}
|
module.exports = { getTempFolder, formatFile, compareFiles }
|
||||||
|
|||||||
Reference in New Issue
Block a user