fix compling error

This commit is contained in:
yimysty
2022-06-17 15:13:00 -07:00
parent a90c52f126
commit 9a28a8d8ad
4 changed files with 1210 additions and 6818 deletions

7733
dist/index.js vendored

File diff suppressed because it is too large Load Diff

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View File

@@ -1,6 +1,6 @@
import * as fs from "fs";
import * as espree from "espree";
import format from "string-format"
const fs = require("fs")
const espree = require("espree")
const format = require("string-format")
// Parse the AST
const espreeOptions = {
@@ -9,16 +9,15 @@ const espreeOptions = {
range: true,
}
export default class ConfigParser {
constructor(staticSiteConfig){
class ConfigParser {
constructor(staticSiteConfig) {
this.staticSiteConfig = staticSiteConfig
this.config = fs.existsSync(this.staticSiteConfig.filePath) ? fs.readFileSync(this.staticSiteConfig.filePath, "utf8") : null
this.validate()
}
validate(){
if(!this.config){
validate() {
if (!this.config) {
// Create the config file if it doesn't exist
fs.writeFile(this.staticSiteConfig.filePath, this.generateConfigFile(), (err) => {
@@ -33,8 +32,8 @@ export default class ConfigParser {
pathPropertyGatsby = `pathPrefix: '{0}'`
configskeleton = `export default {\n {0}\n}`
generateConfigFile(){
switch(this.staticSiteConfig.type){
generateConfigFile() {
switch (this.staticSiteConfig.type) {
case "nuxt":
return format(this.configskeleton, format(this.pathPropertyNuxt, this.staticSiteConfig.newPath))
break
@@ -49,8 +48,8 @@ export default class ConfigParser {
}
}
generateConfigProperty(){
switch(this.staticSiteConfig.type){
generateConfigProperty() {
switch (this.staticSiteConfig.type) {
case "nuxt":
return format(this.pathPropertyNuxt, this.staticSiteConfig.newPath)
break
@@ -65,7 +64,7 @@ export default class ConfigParser {
}
}
parse(){
parse() {
const ast = espree.parse(this.config, espreeOptions);
// Find the default export declaration node
@@ -79,8 +78,8 @@ export default class ConfigParser {
var property = this.getPropertyExportDefault(exportNode)
}
if(property){
switch(this.staticSiteConfig.type){
if (property) {
switch (this.staticSiteConfig.type) {
case "nuxt":
this.parseNuxt(property)
break
@@ -94,38 +93,38 @@ export default class ConfigParser {
}
}
getPropertyModuleExport(exportNode){
getPropertyModuleExport(exportNode) {
var propertyNode = exportNode.expression.right.properties.find(
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)
if(exportNode.expression.right.properties.length > 0){
console.log("Unable to find property, insert it : " + this.staticSiteConfig.pathName)
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])
console.log("new config = \n" + newConfig)
} 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)
}
}
return propertyNode
}
getPropertyExportDefault(exportNode){
getPropertyExportDefault(exportNode) {
var propertyNode = exportNode.declaration.properties.find(
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)
if(exportNode.declaration.properties.length > 0){
console.log("Unable to find property, insert it " + this.staticSiteConfig.pathName)
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])
console.log("new config = \n" + newConfig)
} 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)
}
}
@@ -133,7 +132,7 @@ export default class ConfigParser {
return propertyNode
}
parseNuxt(propertyNode){
parseNuxt(propertyNode) {
// Find the base node
if (propertyNode && propertyNode.value.type === 'ObjectExpression') {
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) {
console.log("base node = " + JSON.stringify(pathNode.value))

View File

@@ -1,6 +1,6 @@
const core = require('@actions/core')
const axios = require('axios')
import ConfigParser from './config-parser.js'
const ConfigParser = require('./config-parser')
async function setPagesPath({staticSiteGenerator, baseUrl}) {
try {