add test cases
This commit is contained in:
+16
-15
@@ -64,6 +64,7 @@ class ConfigParser {
|
||||
}
|
||||
|
||||
parse() {
|
||||
console.log(`original configuration:\n${this.config}`)
|
||||
const ast = espree.parse(this.config, espreeOptions);
|
||||
|
||||
// Find the default export declaration node
|
||||
@@ -90,6 +91,9 @@ class ConfigParser {
|
||||
throw "Unknown config type"
|
||||
}
|
||||
}
|
||||
console.log(`parsed configuration:\n${this.config}`)
|
||||
fs.writeFileSync(this.staticSiteConfig.filePath, this.config)
|
||||
return this.config
|
||||
}
|
||||
|
||||
getPropertyModuleExport(exportNode) {
|
||||
@@ -101,11 +105,11 @@ class ConfigParser {
|
||||
|
||||
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)
|
||||
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])
|
||||
console.log("new config = \n" + this.config)
|
||||
} 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)
|
||||
console.log("new config = \n" + newConfig)
|
||||
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)
|
||||
console.log("new config = \n" + this.config)
|
||||
}
|
||||
}
|
||||
return propertyNode
|
||||
@@ -120,11 +124,11 @@ class ConfigParser {
|
||||
|
||||
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)
|
||||
this.config = 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" + this.config)
|
||||
} else {
|
||||
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)
|
||||
this.config = 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" + this.config)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,20 +140,17 @@ class ConfigParser {
|
||||
if (propertyNode && propertyNode.value.type === 'ObjectExpression') {
|
||||
var baseNode = propertyNode.value.properties.find(node => node.key.type === 'Identifier' && node.key.name === this.staticSiteConfig.subPathName)//'base')
|
||||
if (baseNode) {
|
||||
console.log("base node = " + JSON.stringify(baseNode.value))
|
||||
|
||||
// Swap the base value by a hardcoded string and print it
|
||||
const newConfig = this.config.slice(0, baseNode.value.range[0]) + `'${this.staticSiteConfig.newPath}'` + this.config.slice(baseNode.value.range[1])
|
||||
console.log("new config = \n" + newConfig)
|
||||
this.config = this.config.slice(0, baseNode.value.range[0]) + `'${this.staticSiteConfig.newPath}'` + this.config.slice(baseNode.value.range[1])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
parseNextGatsby(pathNode) {
|
||||
if (pathNode) {
|
||||
console.log("base node = " + JSON.stringify(pathNode.value))
|
||||
const newConfig = this.config.slice(0, pathNode.value.range[0]) + `'${this.staticSiteConfig.newPath}'` + this.config.slice(pathNode.value.range[1])
|
||||
console.log("new config = \n" + newConfig)
|
||||
this.config = this.config.slice(0, pathNode.value.range[0]) + `'${this.staticSiteConfig.newPath}'` + this.config.slice(pathNode.value.range[1])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {ConfigParser}
|
||||
Reference in New Issue
Block a user