Skip to content

Commit

Permalink
[fetch-forms-from-google-drive] update for new googleapis
Browse files Browse the repository at this point in the history
  • Loading branch information
alxndrsn committed Oct 22, 2018
1 parent ad325e8 commit 2c6ac89
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## v1.18.2
* [fetch-forms-from-google-drive] update for new googleapis

## v1.18.1
* Update googleapis require statements
* Update package-lock.json
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "medic-conf",
"version": "1.18.1",
"version": "1.18.2",
"description": "Configure Medic Mobile deployments",
"main": "index.js",
"scripts": {
Expand Down
23 changes: 12 additions & 11 deletions src/fn/fetch-forms-from-google-drive.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ const info = require('../lib/log').info;
module.exports = projectDir => {
return googleAuth()
.then(auth => {
const drive = google.drive({
version: 'v3',
auth: auth,
});
const drive = google.drive({ auth, version:'v3' });

const forms = fs.readJson(`${projectDir}/forms-on-google-drive.json`);

Expand All @@ -22,7 +19,7 @@ module.exports = projectDir => {
const remoteName = forms[localName];

const fetchOpts = {
auth: auth,
auth,
fileId: forms[localName],
mimeType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
};
Expand All @@ -33,13 +30,17 @@ module.exports = projectDir => {

info(`Exporting ${remoteName} from google drive to ${target}…`);

drive.files.export(fetchOpts)
.on('end', () => {
info(`Successfully wrote ${target}.`);
resolve();
drive.files.export(fetchOpts, { responseType:'stream' })
.then(res => {
res.data
.on('end', () => {
info(`Successfully wrote ${target}.`);
resolve();
})
.on('error', reject)
.pipe(fs.fs.createWriteStream(target));
})
.on('error', err => reject(err))
.pipe(fs.fs.createWriteStream(target));
.catch(reject);
}));
}
});
Expand Down

0 comments on commit 2c6ac89

Please sign in to comment.