Skip to content
Permalink
Browse files

Merge branch 'release/2.1.0'

  • Loading branch information...
jormar committed Jan 26, 2019
2 parents 97b4198 + 11089c3 commit 62a7d0bf3c2f189f06b312d4c15bda96ac6aee3f
Showing with 181 additions and 127 deletions.
  1. +85 −58 dist/index.js
  2. +95 −68 lib/index.js
  3. +1 −1 package.json
@@ -88,75 +88,102 @@ inquirer.prompt(prompts).then(function (_answers) {
mdWikiData = '{info}' + prefix + '{info}\n\n' + mdWikiData;
}

// 3. Transform the Markdown Wiki to Storage (confluence scripting)
return rp({
method: 'POST',
uri: config.baseUrl + '/contentbody/convert/storage',
headers: {
'Content-Type': 'application/json'
},
body: {
value: mdWikiData,
representation: 'wiki'
},
auth: {
user: answers.user,
pass: answers.pass,
sendImmediately: true
},
json: true // Automatically stringifies the body to JSON
})
// 4. Get current data of the confluence page
.then(function (data) {
newContent = data;

return rp({
method: 'GET',
uri: config.baseUrl + '/content/' + pageData.pageid,
body: {
some: 'payload'
},
auth: {
user: answers.user,
pass: answers.pass,
sendImmediately: true
},
json: true // Automatically stringifies the body to JSON
});
})

// 5. Update the page in confluence
.then(function (data) {
currentPage = data;
currentPage.title = pageData.title;
currentPage.body = {
storage: {
value: newContent.value,
representation: 'storage'
}
};
currentPage.version.number = parseInt(currentPage.version.number, 10) + 1;

return rp({
method: 'PUT',
uri: config.baseUrl + '/content/' + pageData.pageid,
var dir = './tmp';

if (!fs.existsSync(dir)) {
fs.mkdirSync(dir);
}

var tempFile = dir + '/' + pageData.pageid;

var needsContentUpdate = true;
if (fs.existsSync(tempFile)) {
var fileContent = fs.readFileSync(tempFile, 'utf-8');

if (fileContent === mdWikiData) {
needsContentUpdate = false;
}
}

fs.writeFileSync(tempFile, mdWikiData, 'utf-8');

var promise = void 0;

if (needsContentUpdate) {
// 3. Transform the Markdown Wiki to Storage (confluence scripting)
promise = rp({
method: 'POST',
uri: config.baseUrl + '/contentbody/convert/storage',
headers: {
'Content-Type': 'application/json'
},
body: currentPage,
body: {
value: mdWikiData,
representation: 'wiki'
},
auth: {
user: answers.user,
pass: answers.pass,
sendImmediately: true
},
json: true // Automatically stringifies the body to JSON
})
// 4. Get current data of the confluence page
.then(function (data) {
newContent = data;

return rp({
method: 'GET',
uri: config.baseUrl + '/content/' + pageData.pageid,
body: {
some: 'payload'
},
auth: {
user: answers.user,
pass: answers.pass,
sendImmediately: true
},
json: true // Automatically stringifies the body to JSON
});
})

// 5. Update the page in confluence
.then(function (data) {
currentPage = data;
currentPage.title = pageData.title;
currentPage.body = {
storage: {
value: newContent.value,
representation: 'storage'
}
};
currentPage.version.number = parseInt(currentPage.version.number, 10) + 1;

return rp({
method: 'PUT',
uri: config.baseUrl + '/content/' + pageData.pageid,
headers: {
'Content-Type': 'application/json'
},
body: currentPage,
auth: {
user: answers.user,
pass: answers.pass,
sendImmediately: true
},
json: true // Automatically stringifies the body to JSON
});
})

// everything is saved
.then(function () {
logger.info('"' + currentPage.title + '" saved in confluence.');
});
})
} else {
logger.info('No content update necessary for "' + pageData.mdfile + '"');
}

// everything is saved
.then(function () {
logger.info('"' + currentPage.title + '" saved in confluence.');
});
return promise;
}).catch(function (err) {
logger.error(err);
});
@@ -81,77 +81,104 @@ inquirer.prompt(prompts).then((_answers) => {
mdWikiData = `{info}${prefix}{info}\n\n${mdWikiData}`;
}

// 3. Transform the Markdown Wiki to Storage (confluence scripting)
return (
rp({
method: 'POST',
uri: `${config.baseUrl}/contentbody/convert/storage`,
headers: {
'Content-Type': 'application/json',
},
body: {
value: mdWikiData,
representation: 'wiki',
},
auth: {
user: answers.user,
pass: answers.pass,
sendImmediately: true,
},
json: true, // Automatically stringifies the body to JSON
})
// 4. Get current data of the confluence page
.then((data) => {
newContent = data;

return rp({
method: 'GET',
uri: `${config.baseUrl}/content/${pageData.pageid}`,
body: {
some: 'payload',
},
auth: {
user: answers.user,
pass: answers.pass,
sendImmediately: true,
},
json: true, // Automatically stringifies the body to JSON
});
})
const dir = './tmp';

// 5. Update the page in confluence
.then((data) => {
currentPage = data;
currentPage.title = pageData.title;
currentPage.body = {
storage: {
value: newContent.value,
representation: 'storage',
},
};
currentPage.version.number = parseInt(currentPage.version.number, 10) + 1;

return rp({
method: 'PUT',
uri: `${config.baseUrl}/content/${pageData.pageid}`,
headers: {
'Content-Type': 'application/json',
},
body: currentPage,
auth: {
user: answers.user,
pass: answers.pass,
sendImmediately: true,
},
json: true, // Automatically stringifies the body to JSON
});
})
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir);
}

const tempFile = `${dir}/${pageData.pageid}`;

let needsContentUpdate = true;
if (fs.existsSync(tempFile)) {
const fileContent = fs.readFileSync(tempFile, 'utf-8');

// everything is saved
.then(() => {
logger.info(`"${currentPage.title}" saved in confluence.`);
if (fileContent === mdWikiData) {
needsContentUpdate = false;
}
}

fs.writeFileSync(tempFile, mdWikiData, 'utf-8');

let promise;

if (needsContentUpdate) {
// 3. Transform the Markdown Wiki to Storage (confluence scripting)
promise = (
rp({
method: 'POST',
uri: `${config.baseUrl}/contentbody/convert/storage`,
headers: {
'Content-Type': 'application/json',
},
body: {
value: mdWikiData,
representation: 'wiki',
},
auth: {
user: answers.user,
pass: answers.pass,
sendImmediately: true,
},
json: true, // Automatically stringifies the body to JSON
})
);
// 4. Get current data of the confluence page
.then((data) => {
newContent = data;

return rp({
method: 'GET',
uri: `${config.baseUrl}/content/${pageData.pageid}`,
body: {
some: 'payload',
},
auth: {
user: answers.user,
pass: answers.pass,
sendImmediately: true,
},
json: true, // Automatically stringifies the body to JSON
});
})

// 5. Update the page in confluence
.then((data) => {
currentPage = data;
currentPage.title = pageData.title;
currentPage.body = {
storage: {
value: newContent.value,
representation: 'storage',
},
};
currentPage.version.number = parseInt(currentPage.version.number, 10) + 1;

return rp({
method: 'PUT',
uri: `${config.baseUrl}/content/${pageData.pageid}`,
headers: {
'Content-Type': 'application/json',
},
body: currentPage,
auth: {
user: answers.user,
pass: answers.pass,
sendImmediately: true,
},
json: true, // Automatically stringifies the body to JSON
});
})

// everything is saved
.then(() => {
logger.info(`"${currentPage.title}" saved in confluence.`);
})
);
} else {
logger.info(`No content update necessary for "${pageData.mdfile}"`);
}

return promise;
})
.catch((err) => {
logger.error(err);
@@ -1,6 +1,6 @@
{
"name": "md2confluence",
"version": "2.0.0",
"version": "2.1.0",
"description": "Update confluence pages from your markdown files (like a README.md)",
"main": "dist/index.js",
"bin": {

0 comments on commit 62a7d0b

Please sign in to comment.
You can’t perform that action at this time.