mirror of
https://github.com/actions/configure-pages.git
synced 2026-03-30 10:04:52 +00:00
fix compling error
This commit is contained in:
7733
dist/index.js
vendored
7733
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
@@ -1,6 +1,6 @@
|
|||||||
import * as fs from "fs";
|
const fs = require("fs")
|
||||||
import * as espree from "espree";
|
const espree = require("espree")
|
||||||
import format from "string-format"
|
const format = require("string-format")
|
||||||
|
|
||||||
// Parse the AST
|
// Parse the AST
|
||||||
const espreeOptions = {
|
const espreeOptions = {
|
||||||
@@ -9,16 +9,15 @@ const espreeOptions = {
|
|||||||
range: true,
|
range: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class ConfigParser {
|
class ConfigParser {
|
||||||
|
constructor(staticSiteConfig) {
|
||||||
constructor(staticSiteConfig){
|
|
||||||
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()
|
||||||
}
|
}
|
||||||
|
|
||||||
validate(){
|
validate() {
|
||||||
if(!this.config){
|
if (!this.config) {
|
||||||
// Create the config file if it doesn't exist
|
// Create the config file if it doesn't exist
|
||||||
fs.writeFile(this.staticSiteConfig.filePath, this.generateConfigFile(), (err) => {
|
fs.writeFile(this.staticSiteConfig.filePath, this.generateConfigFile(), (err) => {
|
||||||
|
|
||||||
@@ -33,8 +32,8 @@ export default class ConfigParser {
|
|||||||
pathPropertyGatsby = `pathPrefix: '{0}'`
|
pathPropertyGatsby = `pathPrefix: '{0}'`
|
||||||
configskeleton = `export default {\n {0}\n}`
|
configskeleton = `export default {\n {0}\n}`
|
||||||
|
|
||||||
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
|
||||||
@@ -49,8 +48,8 @@ export default class ConfigParser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
||||||
@@ -65,7 +64,7 @@ export default class ConfigParser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
parse(){
|
parse() {
|
||||||
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
|
||||||
@@ -79,8 +78,8 @@ export default class ConfigParser {
|
|||||||
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
|
||||||
@@ -94,38 +93,38 @@ export default 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) {
|
||||||
|
|
||||||
console.log( "Unable to find property, insert it : " + this.staticSiteConfig.pathName)
|
console.log("Unable to find property, insert it : " + this.staticSiteConfig.pathName)
|
||||||
if(exportNode.expression.right.properties.length > 0){
|
if (exportNode.expression.right.properties.length > 0) {
|
||||||
const newConfig = this.config.slice(0, exportNode.expression.right.properties[0].range[0]) + this.generateConfigProperty() + ',\n' + this.config.slice(exportNode.expression.right.properties[0].range[0])
|
const newConfig = this.config.slice(0, exportNode.expression.right.properties[0].range[0]) + this.generateConfigProperty() + ',\n' + this.config.slice(exportNode.expression.right.properties[0].range[0])
|
||||||
console.log("new config = \n" + newConfig)
|
console.log("new config = \n" + newConfig)
|
||||||
} else {
|
} else {
|
||||||
const newConfig = this.config.slice(0, exportNode.expression.right.range[0]+1) + '\n '+ this.generateConfigProperty() + '\n' + this.config.slice(exportNode.expression.right.range[1]-1)
|
const newConfig = this.config.slice(0, exportNode.expression.right.range[0] + 1) + '\n ' + this.generateConfigProperty() + '\n' + this.config.slice(exportNode.expression.right.range[1] - 1)
|
||||||
console.log("new config = \n" + newConfig)
|
console.log("new config = \n" + newConfig)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return propertyNode
|
return propertyNode
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
|
|
||||||
console.log( "Unable to find property, insert it " + this.staticSiteConfig.pathName)
|
console.log("Unable to find property, insert it " + this.staticSiteConfig.pathName)
|
||||||
if(exportNode.declaration.properties.length > 0){
|
if (exportNode.declaration.properties.length > 0) {
|
||||||
const newConfig = this.config.slice(0, exportNode.declaration.properties[0].range[0]) + this.generateConfigProperty() + ',\n' + this.config.slice(exportNode.declaration.properties[0].range[0])
|
const newConfig = this.config.slice(0, exportNode.declaration.properties[0].range[0]) + this.generateConfigProperty() + ',\n' + this.config.slice(exportNode.declaration.properties[0].range[0])
|
||||||
console.log("new config = \n" + newConfig)
|
console.log("new config = \n" + newConfig)
|
||||||
} else {
|
} else {
|
||||||
const newConfig = this.config.slice(0, exportNode.declaration.range[0]+1) + '\n '+ this.generateConfigProperty() + '\n' + this.config.slice(exportNode.declaration.range[1]-1)
|
const newConfig = this.config.slice(0, exportNode.declaration.range[0] + 1) + '\n ' + this.generateConfigProperty() + '\n' + this.config.slice(exportNode.declaration.range[1] - 1)
|
||||||
console.log("new config = \n" + newConfig)
|
console.log("new config = \n" + newConfig)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -133,7 +132,7 @@ export default class ConfigParser {
|
|||||||
return propertyNode
|
return propertyNode
|
||||||
}
|
}
|
||||||
|
|
||||||
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')
|
||||||
@@ -147,7 +146,7 @@ export default class ConfigParser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
parseNextGatsby(pathNode){
|
parseNextGatsby(pathNode) {
|
||||||
if (pathNode) {
|
if (pathNode) {
|
||||||
console.log("base node = " + JSON.stringify(pathNode.value))
|
console.log("base node = " + JSON.stringify(pathNode.value))
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
const core = require('@actions/core')
|
const core = require('@actions/core')
|
||||||
const axios = require('axios')
|
const axios = require('axios')
|
||||||
import ConfigParser from './config-parser.js'
|
const ConfigParser = require('./config-parser')
|
||||||
|
|
||||||
async function setPagesPath({staticSiteGenerator, baseUrl}) {
|
async function setPagesPath({staticSiteGenerator, baseUrl}) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user