Last active
January 6, 2016 00:48
-
-
Save ryohey/8000a4840090c448082b to your computer and use it in GitHub Desktop.
Export Github wiki to esa.io
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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