Update distribution

This commit is contained in:
Yoann Chaudet
2022-07-18 15:08:08 -07:00
parent 61e591d3b5
commit df54bc901b
2 changed files with 127 additions and 75 deletions

200
dist/index.js vendored
View File

@@ -14537,8 +14537,8 @@ const core = __nccwpck_require__(2186)
// Parse the AST // Parse the AST
const espreeOptions = { const espreeOptions = {
ecmaVersion: 6, ecmaVersion: 6,
sourceType: "module", sourceType: 'module',
range: true, range: true
} }
class ConfigParser { class ConfigParser {
@@ -14548,7 +14548,9 @@ class ConfigParser {
this.pathPropertyGatsby = `pathPrefix: '{0}'` this.pathPropertyGatsby = `pathPrefix: '{0}'`
this.configskeleton = `export default {\n {0}\n}` this.configskeleton = `export default {\n {0}\n}`
this.staticSiteConfig = staticSiteConfig this.staticSiteConfig = staticSiteConfig
this.config = fs.existsSync(this.staticSiteConfig.filePath) ? fs.readFileSync(this.staticSiteConfig.filePath, "utf8") : null this.config = fs.existsSync(this.staticSiteConfig.filePath)
? fs.readFileSync(this.staticSiteConfig.filePath, 'utf8')
: null
this.validate() this.validate()
} }
@@ -14564,62 +14566,72 @@ class ConfigParser {
generateConfigFile() { generateConfigFile() {
switch (this.staticSiteConfig.type) { switch (this.staticSiteConfig.type) {
case "nuxt": case 'nuxt':
return format(this.configskeleton, format(this.pathPropertyNuxt, this.staticSiteConfig.newPath)) return format(
this.configskeleton,
format(this.pathPropertyNuxt, this.staticSiteConfig.newPath)
)
break break
case "next": case 'next':
return format(this.configskeleton, format(this.pathPropertyNext, this.staticSiteConfig.newPath)) return format(
this.configskeleton,
format(this.pathPropertyNext, this.staticSiteConfig.newPath)
)
break break
case "gatsby": case 'gatsby':
return format(this.configskeleton, format(this.pathPropertyGatsby, this.staticSiteConfig.newPath)) return format(
this.configskeleton,
format(this.pathPropertyGatsby, this.staticSiteConfig.newPath)
)
break break
default: default:
throw "Unknown config type" throw 'Unknown config type'
} }
} }
generateConfigProperty() { generateConfigProperty() {
switch (this.staticSiteConfig.type) { switch (this.staticSiteConfig.type) {
case "nuxt": case 'nuxt':
return format(this.pathPropertyNuxt, this.staticSiteConfig.newPath) return format(this.pathPropertyNuxt, this.staticSiteConfig.newPath)
break break
case "next": case 'next':
return format(this.pathPropertyNext, this.staticSiteConfig.newPath) return format(this.pathPropertyNext, this.staticSiteConfig.newPath)
break break
case "gatsby": case 'gatsby':
return format(this.pathPropertyGatsby, this.staticSiteConfig.newPath) return format(this.pathPropertyGatsby, this.staticSiteConfig.newPath)
break break
default: default:
throw "Unknown config type" throw 'Unknown config type'
} }
} }
parse() { parse() {
core.info(`original configuration:\n${this.config}`) core.info(`original configuration:\n${this.config}`)
const ast = espree.parse(this.config, espreeOptions); const ast = espree.parse(this.config, espreeOptions)
// Find the default export declaration node // Find the default export declaration node
var exportNode = ast.body.find(node => node.type === 'ExpressionStatement') var exportNode = ast.body.find(node => node.type === 'ExpressionStatement')
if (exportNode) { if (exportNode) {
var property = this.getPropertyModuleExport(exportNode) var property = this.getPropertyModuleExport(exportNode)
} else { } else {
exportNode = ast.body.find(node => node.type === 'ExportDefaultDeclaration') exportNode = ast.body.find(
if (!exportNode) throw "Unable to find default export" node => node.type === 'ExportDefaultDeclaration'
)
if (!exportNode) throw 'Unable to find default export'
var property = this.getPropertyExportDefault(exportNode) var property = this.getPropertyExportDefault(exportNode)
} }
if (property) { if (property) {
switch (this.staticSiteConfig.type) { switch (this.staticSiteConfig.type) {
case "nuxt": case 'nuxt':
this.parseNuxt(property) this.parseNuxt(property)
break break
case "next": case 'next':
case "gatsby": case 'gatsby':
this.parseNextGatsby(property) this.parseNextGatsby(property)
break break
default: default:
throw "Unknown config type" throw 'Unknown config type'
} }
} }
core.info(`parsed configuration:\n${this.config}`) core.info(`parsed configuration:\n${this.config}`)
@@ -14629,18 +14641,34 @@ class ConfigParser {
getPropertyModuleExport(exportNode) { getPropertyModuleExport(exportNode) {
var propertyNode = exportNode.expression.right.properties.find( var propertyNode = exportNode.expression.right.properties.find(
node => node.key.type === 'Identifier' && node.key.name === this.staticSiteConfig.pathName node =>
node.key.type === 'Identifier' &&
node.key.name === this.staticSiteConfig.pathName
) )
if (!propertyNode) { if (!propertyNode) {
core.info(
core.info("Unable to find property, insert it : " + this.staticSiteConfig.pathName) 'Unable to find property, insert it : ' +
this.staticSiteConfig.pathName
)
if (exportNode.expression.right.properties.length > 0) { if (exportNode.expression.right.properties.length > 0) {
this.config = this.config.slice(0, exportNode.expression.right.properties[0].range[0]) + this.generateConfigProperty() + ',\n' + this.config.slice(exportNode.expression.right.properties[0].range[0]) this.config =
core.info("new config = \n" + this.config) this.config.slice(
0,
exportNode.expression.right.properties[0].range[0]
) +
this.generateConfigProperty() +
',\n' +
this.config.slice(exportNode.expression.right.properties[0].range[0])
core.info('new config = \n' + this.config)
} else { } else {
this.config = this.config.slice(0, exportNode.expression.right.range[0] + 1) + '\n ' + this.generateConfigProperty() + '\n' + this.config.slice(exportNode.expression.right.range[1] - 1) this.config =
core.info("new config = \n" + this.config) this.config.slice(0, exportNode.expression.right.range[0] + 1) +
'\n ' +
this.generateConfigProperty() +
'\n' +
this.config.slice(exportNode.expression.right.range[1] - 1)
core.info('new config = \n' + this.config)
} }
} }
return propertyNode return propertyNode
@@ -14648,18 +14676,30 @@ class ConfigParser {
getPropertyExportDefault(exportNode) { getPropertyExportDefault(exportNode) {
var propertyNode = exportNode.declaration.properties.find( var propertyNode = exportNode.declaration.properties.find(
node => node.key.type === 'Identifier' && node.key.name === this.staticSiteConfig.pathName node =>
node.key.type === 'Identifier' &&
node.key.name === this.staticSiteConfig.pathName
) )
if (!propertyNode) { if (!propertyNode) {
core.info(
core.info("Unable to find property, insert it " + this.staticSiteConfig.pathName) 'Unable to find property, insert it ' + this.staticSiteConfig.pathName
)
if (exportNode.declaration.properties.length > 0) { if (exportNode.declaration.properties.length > 0) {
this.config = this.config.slice(0, exportNode.declaration.properties[0].range[0]) + this.generateConfigProperty() + ',\n' + this.config.slice(exportNode.declaration.properties[0].range[0]) this.config =
core.info("new config = \n" + this.config) this.config.slice(0, exportNode.declaration.properties[0].range[0]) +
this.generateConfigProperty() +
',\n' +
this.config.slice(exportNode.declaration.properties[0].range[0])
core.info('new config = \n' + this.config)
} else { } else {
this.config = this.config.slice(0, exportNode.declaration.range[0] + 1) + '\n ' + this.generateConfigProperty() + '\n' + this.config.slice(exportNode.declaration.range[1] - 1) this.config =
core.info("new config = \n" + this.config) this.config.slice(0, exportNode.declaration.range[0] + 1) +
'\n ' +
this.generateConfigProperty() +
'\n' +
this.config.slice(exportNode.declaration.range[1] - 1)
core.info('new config = \n' + this.config)
} }
} }
@@ -14669,23 +14709,34 @@ class ConfigParser {
parseNuxt(propertyNode) { parseNuxt(propertyNode) {
// Find the base node // Find the base node
if (propertyNode && propertyNode.value.type === 'ObjectExpression') { if (propertyNode && propertyNode.value.type === 'ObjectExpression') {
var baseNode = propertyNode.value.properties.find(node => node.key.type === 'Identifier' && node.key.name === this.staticSiteConfig.subPathName)//'base') var baseNode = propertyNode.value.properties.find(
node =>
node.key.type === 'Identifier' &&
node.key.name === this.staticSiteConfig.subPathName
) //'base')
if (baseNode) { if (baseNode) {
// Swap the base value by a hardcoded string and print it // Swap the base value by a hardcoded string and print it
this.config = this.config.slice(0, baseNode.value.range[0]) + `'${this.staticSiteConfig.newPath}'` + this.config.slice(baseNode.value.range[1]) this.config =
this.config.slice(0, baseNode.value.range[0]) +
`'${this.staticSiteConfig.newPath}'` +
this.config.slice(baseNode.value.range[1])
} }
} }
} }
parseNextGatsby(pathNode) { parseNextGatsby(pathNode) {
if (pathNode) { if (pathNode) {
this.config = this.config.slice(0, pathNode.value.range[0]) + `'${this.staticSiteConfig.newPath}'` + this.config.slice(pathNode.value.range[1]) this.config =
this.config.slice(0, pathNode.value.range[0]) +
`'${this.staticSiteConfig.newPath}'` +
this.config.slice(pathNode.value.range[1])
} }
} }
} }
module.exports = {ConfigParser} module.exports = {ConfigParser}
/***/ }), /***/ }),
/***/ 1319: /***/ 1319:
@@ -14722,19 +14773,19 @@ module.exports = function getContext() {
const core = __nccwpck_require__(2186) const core = __nccwpck_require__(2186)
const axios = __nccwpck_require__(6545) const axios = __nccwpck_require__(6545)
async function enablePages({ repositoryNwo, githubToken }) { async function enablePages({repositoryNwo, githubToken}) {
const pagesEndpoint = `https://api.github.com/repos/${repositoryNwo}/pages` const pagesEndpoint = `https://api.github.com/repos/${repositoryNwo}/pages`
try { try {
const response = await axios.post( const response = await axios.post(
pagesEndpoint, pagesEndpoint,
{ build_type: 'workflow' }, {build_type: 'workflow'},
{ {
headers: { headers: {
Accept: 'application/vnd.github.v3+json', Accept: 'application/vnd.github.v3+json',
Authorization: `Bearer ${githubToken}`, Authorization: `Bearer ${githubToken}`,
'Content-type': 'application/json', 'Content-type': 'application/json'
}, }
} }
) )
core.info('Created pages site') core.info('Created pages site')
@@ -14744,7 +14795,7 @@ async function enablePages({ repositoryNwo, githubToken }) {
return return
} }
core.error('Couldn\'t create pages site', error) core.error("Couldn't create pages site", error)
throw error throw error
} }
} }
@@ -14761,26 +14812,27 @@ const core = __nccwpck_require__(2186)
const axios = __nccwpck_require__(6545) const axios = __nccwpck_require__(6545)
const setPagesPath = __nccwpck_require__(4770) const setPagesPath = __nccwpck_require__(4770)
async function getPagesBaseUrl({ repositoryNwo, githubToken, staticSiteGenerator}) { async function getPagesBaseUrl({
repositoryNwo,
githubToken,
staticSiteGenerator
}) {
try { try {
const pagesEndpoint = `https://api.github.com/repos/${repositoryNwo}/pages` const pagesEndpoint = `https://api.github.com/repos/${repositoryNwo}/pages`
core.info(`Get the Base URL to the page with endpoint ${pagesEndpoint}`) core.info(`Get the Base URL to the page with endpoint ${pagesEndpoint}`)
const response = await axios.get( const response = await axios.get(pagesEndpoint, {
pagesEndpoint, headers: {
{ Accept: 'application/vnd.github.v3+json',
headers: { Authorization: `Bearer ${githubToken}`
Accept: 'application/vnd.github.v3+json',
Authorization: `Bearer ${githubToken}`
}
} }
) })
pageObject = response.data pageObject = response.data
core.info(JSON.stringify(pageObject)) core.info(JSON.stringify(pageObject))
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, path: siteUrl.pathname})
} }
core.setOutput('base_url', siteUrl.href) core.setOutput('base_url', siteUrl.href)
@@ -14803,46 +14855,47 @@ module.exports = getPagesBaseUrl
const core = __nccwpck_require__(2186) const core = __nccwpck_require__(2186)
const axios = __nccwpck_require__(6545) const axios = __nccwpck_require__(6545)
const { ConfigParser } = __nccwpck_require__(8395) const {ConfigParser} = __nccwpck_require__(8395)
async function setPagesPath({staticSiteGenerator, path}) { async function setPagesPath({staticSiteGenerator, path}) {
try { try {
switch(staticSiteGenerator) switch (staticSiteGenerator) {
{
case 'nuxt': case 'nuxt':
var ssConfig = { var ssConfig = {
filePath:"./nuxt.config.js", filePath: './nuxt.config.js',
type: "nuxt", type: 'nuxt',
pathName: "router", pathName: 'router',
subPathName: "base", subPathName: 'base',
newPath: path newPath: path
} }
break; break
case 'next': case 'next':
var ssConfig = { var ssConfig = {
filePath:"./next.config.js", filePath: './next.config.js',
type: "next", type: 'next',
pathName: "basePath", pathName: 'basePath',
newPath: path newPath: path
} }
break; break
case 'gatsby': case 'gatsby':
var ssConfig = { var ssConfig = {
filePath: "./gatsby-config.js", filePath: './gatsby-config.js',
type: "gatsby", type: 'gatsby',
pathName: "pathPrefix", pathName: 'pathPrefix',
newPath: path newPath: path
} }
break; break
default: default:
throw "Unknown config type" throw 'Unknown config type'
} }
let configParser = new ConfigParser(ssConfig) let configParser = new ConfigParser(ssConfig)
configParser.parse() configParser.parse()
} catch (error) { } catch (error) {
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) 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
)
} }
} }
@@ -16346,7 +16399,6 @@ async function main() {
} }
} }
// Main // Main
main() main()

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long