Skip to content

Instantly share code, notes, and snippets.

@ryohey
Last active January 6, 2016 00:48
Show Gist options
  • Save ryohey/8000a4840090c448082b to your computer and use it in GitHub Desktop.
Save ryohey/8000a4840090c448082b to your computer and use it in GitHub Desktop.
Export Github wiki to esa.io
fs = require "fs"
req = require "request"
## config
teamName = "your esa.io team name"
accessToken = "your esa.io personal access token"
# the directory markdown files saved (git clone [email protected]:USERNAME/REPONAME.wiki.git)
dir = "path/to/reponame.wiki"
##
url = "https://api.esa.io/v1/teams/#{teamName}/posts"
params = (for file in fs.readdirSync dir
path = "#{dir}/#{file}"
continue if fs.statSync(path).isDirectory()
console.log path
text = fs.readFileSync path, "UTF-8"
obj =
post:
name: file.replace /\.md$/, ""
body_md: text
wip: false
message: "import from github wiki"
{
url: url
method: "POST"
headers:
"Content-Type": "application/json"
"Authorization": "Bearer #{accessToken}"
json: true
form: obj
}
)
uploadNext = () ->
param = params.pop()
return unless param?
file = param.form.post.name
console.log "uploading #{file}.."
req param, (err, res, body) ->
if err?
console.error "failed to upload #{file}"
console.error err
return
if res.body.error?
console.error "#{res.statusCode} error"
console.log res.body.error, res.body.message
return
console.log "success to upload #{file}"
uploadNext()
uploadNext()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment