What I want to do is to replace doczrc.js
base value from abc to the name I get that from .git/config
. So I do not need to manually change the base in the doczrc. (For those people who fork the repo, they have to change it themselves, and it will has trouble to push and PR to the parent repo.) So I have to write a script to change the name for building the page.
I want to read the repo owner from '.git/config'.
...
[remote "origin"]
url = git@github.test.result/test.git
fetch = +refs/heads/*:refs/remotes/origin/*
...
I have another file which is used to build github doc page. The configuration file export an object.
export default {
...
base: `/pages/abc/test`
...
}
I have used readfilesync
and but I am not allowed to use readfilesync
.
I then tried readfile
, it is async, and I use promise. However, I cannot get the value from promise. From online tutorial, it is all console.log. But I need to get the exact value and return to other file to use.
I have tried the way below, change the export default to an object, and replace base. However, it still export abc instead of the value I want. Is there a way I can solve this problem?
// script.js
const remote = 'origin'
const file = '.git/config'
function readConfig() {
return new Promise((resolve, reject) => {
const regex = /:(\S+)\//gm
try {
fs.readFile(configFile, (err, data) => {
if (err) {
console.log(err.stack)
}
let result = regex.exec(data.toString())
resolve(result[1])
})
}
catch (err) {
console.log(err)
reject(err)
}
})
}
// readConfig could get the value I want. This value is what I want to send to script.js, which is to replace t
readConfig().then(x => console.log(x))
ghPages.publish('.gh-pages', { remote }, err => {
if (err) {
console.error(error .')
console.error(err)
} else {
console.info('success')
}
})
module.exports = {
readConfig,
}
// script.js
// I tried to change script.js in this way instead of just call the function
`/pages/{readConfig()}/test`
import { readConfig } from './doczrc'
const exportObj = {
base: `/pages/abc/test`
}
readConfig().then(res => {
exportObj.base = '/pages/' + res + '/test/'
})
export default exportObj
I want to export '/pages/' + (the value I read from config) + /test/
the command run
npm run docs:build && node script.js
which doczrc.js is the config file for doc build.
script.js is the script that I use to update value in the script.js base. and publish the github page.
change file name more meaningful. doczrc.js ( original is a.js) script.js ( original is b.js)
Or there is other way I can solve my problem.