Skip to content

Commit

Permalink
remove dependency on fs-extra and now target >= 10.12
Browse files Browse the repository at this point in the history
  • Loading branch information
ajmas committed Oct 18, 2022
1 parent 0695c3e commit 5733517
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 47 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ export GOOGLE_PRIVATE_KEY="xxxxxx"
./node_modules/.bin/sync-gdrive "filefolderid" "dest_folder"
```

### Targeted environments

This project will not work in the browser, due to dependencies on the
file system.

Targeted node.js versions are 10.12+

## Contributions & Feedback

Contributions and feedback is welcome. Please open
Expand Down
31 changes: 1 addition & 30 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"sync-gdrive": "dist/cli.js"
},
"engines": {
"node": ">=10.0.0"
"node": ">=10.12.0"
},
"scripts": {
"sync-gdrive": "ts-node src/cli.ts",
Expand All @@ -26,7 +26,6 @@
"author": "Andre John Mas",
"license": "MIT",
"dependencies": {
"fs-extra": "^10.1.0",
"googleapis": "^108.0.0",
"mime": "^3.0.0"
},
Expand Down
18 changes: 7 additions & 11 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/* eslint-disable no-console */
import fs from 'fs-extra';
import { utimesSync, createWriteStream, promises as fs} from 'fs';
import path from 'path';
import { promisify } from 'util';

import { google, drive_v3 } from 'googleapis';
import mime from 'mime';
Expand All @@ -13,8 +11,6 @@ import ISyncState from './interfaces/ISyncState';
type Drive = drive_v3.Drive;
type File = drive_v3.Schema$File;

const fsStat = promisify(fs.stat);

function sleep(timeout: number = 1000, value?: any) {
return new Promise(function (resolve, reject) {
setTimeout(function() {
Expand Down Expand Up @@ -120,7 +116,7 @@ function timeAsSeconds(datetime: string | number | Date): number {
*/
async function isGDriveFileNewer(gDriveFile: File, filePath: string) {
try {
const stats = await fsStat(filePath);
const stats = await fs.stat(filePath);
const fsModifiedTime = timeAsSeconds(stats.mtime);
const driveModifiedTime = timeAsSeconds(gDriveFile.modifiedTime);
return (driveModifiedTime > fsModifiedTime);
Expand All @@ -140,7 +136,7 @@ async function downloadFile (drive: Drive, file, destFolder: string, options: IO
options.logger.debug('downloading newer: ', filePath);
options.logger.debug('creating file: ', filePath);
}
const dest = fs.createWriteStream(filePath);
const dest = createWriteStream(filePath);

let fileId = file.id;
if (file.shortcutDetails) {
Expand All @@ -161,7 +157,7 @@ async function downloadFile (drive: Drive, file, destFolder: string, options: IO
.on('error', reject)
.on('finish', () => {
// apply time stamp from the drive
fs.utimesSync(
utimesSync(
filePath,
timeAsSeconds(file.createdTime),
timeAsSeconds(file.modifiedTime)
Expand Down Expand Up @@ -190,7 +186,7 @@ async function exportFile (drive: Drive, file: File, destFolder: string, mimeTyp
options.logger.debug('exporting to file: ', filePath);
}

const dest = fs.createWriteStream(filePath);
const dest = createWriteStream(filePath);

let fileId = file.id;
if (file.shortcutDetails) {
Expand All @@ -211,7 +207,7 @@ async function exportFile (drive: Drive, file: File, destFolder: string, mimeTyp
.on('error', reject)
.on('finish', () => {
// apply time stamp from the drive
fs.utimesSync(
utimesSync(
filePath,
timeAsSeconds(file.createdTime),
timeAsSeconds(file.modifiedTime)
Expand Down Expand Up @@ -293,7 +289,7 @@ async function visitDirectory (drive: Drive, fileId: string, folderPath: string,
options.logger.debug('DIR', file.id, childFolderPath, file.name)
}

await fs.mkdirp(childFolderPath);
await fs.mkdir(childFolderPath, { recursive: true });
if (options.sleepTime) {
await sleep(options.sleepTime);
}
Expand Down
2 changes: 1 addition & 1 deletion test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import syncGDrive, { IKeyConfig } from '../src';
interface BasicFileInfo {
path: string,
size: number
};
}

const fsMkdtemp = promisify(fs.mkdtemp);
const fsReaddir = promisify(fs.readdir);
Expand Down
5 changes: 2 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"typeRoots": [
"node_modules/@types"
],
"rootDir": "src",
"rootDirs": ["src"],
"outDir": "dist",
"esModuleInterop": true,
"resolveJsonModule": true
Expand All @@ -28,7 +28,6 @@
]
},
"include": [
"src/",
"test/"
"src/"
]
}

0 comments on commit 5733517

Please sign in to comment.