-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from ajmas/issue-5-basic-cli
Fixes #5 CLI support and deal with paging
- Loading branch information
Showing
7 changed files
with
174 additions
and
69 deletions.
There are no files selected for viewing
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#! /usr/bin/env node | ||
/* eslint-disable no-console */ | ||
import fs from 'fs'; | ||
import syncGDrive, { IKeyConfig } from '../'; | ||
|
||
async function main () { | ||
try { | ||
let okay = true; | ||
const clientEmail = process.env.GOOGLE_CLIENT_EMAIL; | ||
if (!clientEmail) { | ||
console.log('No client email specified. Be sure to set GOOGLE_CLIENT_EMAIL env variable.'); | ||
okay = false; | ||
} | ||
|
||
let privateKey = process.env.GOOGLE_PRIVATE_KEY; | ||
if (!privateKey) { | ||
console.log('No Google API private key specified. Be sure to set GOOGLE_PRIVATE_KEY env variable.'); | ||
okay = false; | ||
} | ||
|
||
if (!okay) { | ||
process.exit(1); | ||
} | ||
|
||
// Unescape new lines | ||
privateKey = privateKey.replace(/\\n/g, '\n'); | ||
|
||
if (process.argv.length < 4) { | ||
console.log('usage: sync-gdrive <drive_file_folder_id> <dest_path>'); | ||
process.exit(1); | ||
} | ||
|
||
const fileFolderId = process.argv[2]; | ||
const destFolder = process.argv[3]; | ||
|
||
try { | ||
fs.accessSync(destFolder, fs.constants.R_OK | fs.constants.W_OK); | ||
} catch (error) { | ||
console.log(`Destination folder '${destFolder}' does not exist or is not writable by current user`); | ||
process.exit(1); | ||
} | ||
|
||
const keyConfig: IKeyConfig = { | ||
clientEmail: clientEmail, | ||
privateKey: privateKey | ||
}; | ||
|
||
console.log(`Syncing Google Drive file/folder of id '${fileFolderId}' to '${destFolder}'`); | ||
await syncGDrive(fileFolderId, destFolder, keyConfig); | ||
} catch (error) { | ||
console.log(error); | ||
} | ||
} | ||
|
||
if (require.main === module) { | ||
main(); | ||
} |
This file contains 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
This file contains 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