carp-streamer
Advanced tools
Comparing version 0.2.0 to 0.2.1
@@ -103,4 +103,12 @@ "use strict"; | ||
const isMiniFile = (item) => item.type === 'file'; | ||
function findRemoteFileByPath(folderPath, filename, rootFolder, client) { | ||
function findRemoteFileByPath(relativePath, rootFolder, client) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const { dir, base } = path_1.default.parse(relativePath); | ||
const dirs = dir === '' ? [] : dir.split(path_1.default.sep); | ||
return _findRemoteFileByPath(dirs, base, rootFolder, client); | ||
}); | ||
} | ||
exports.findRemoteFileByPath = findRemoteFileByPath; | ||
function _findRemoteFileByPath(folderPath, filename, rootFolder, client) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const folder = yield findRemoteFolderByPath(folderPath, rootFolder, client); | ||
@@ -110,3 +118,2 @@ return folder && client.folders.getItems(folder.id).then(items => lodash_1.default.first(items.entries.filter(isMiniFile).filter(item => item.name.normalize() === filename.normalize()))); | ||
} | ||
exports.findRemoteFileByPath = findRemoteFileByPath; | ||
const isFolder = (item) => item.size !== undefined; | ||
@@ -140,8 +147,8 @@ const isMiniFolder = (item) => item.type === 'folder'; | ||
const readdir = util_1.default.promisify(fs_1.default.readdir); | ||
function list(root) { | ||
return __asyncGenerator(this, arguments, function* list_1() { | ||
function listDirectoryEntriesRecursively(root) { | ||
return __asyncGenerator(this, arguments, function* listDirectoryEntriesRecursively_1() { | ||
for (let dirent of yield __await(readdir(root, { withFileTypes: true }))) { | ||
const entryPath = path_1.default.join(root, dirent.name); | ||
if (dirent.isDirectory()) { | ||
yield __await(yield* __asyncDelegator(__asyncValues(list(entryPath)))); | ||
yield __await(yield* __asyncDelegator(__asyncValues(listDirectoryEntriesRecursively(entryPath)))); | ||
} | ||
@@ -152,3 +159,3 @@ yield yield __await(({ path: entryPath, dirent })); | ||
} | ||
exports.list = list; | ||
exports.listDirectoryEntriesRecursively = listDirectoryEntriesRecursively; | ||
//# sourceMappingURL=app.js.map |
@@ -50,2 +50,3 @@ #!/usr/bin/env node | ||
}; | ||
const rootPath = path_1.default.resolve(process.cwd(), source); | ||
const client = createBoxClient({ appConfig, token: args.token }); | ||
@@ -59,11 +60,9 @@ if (args['as-user']) { | ||
try { | ||
for (var _b = __asyncValues(app_1.list(source)), _c; _c = yield _b.next(), !_c.done;) { | ||
for (var _b = __asyncValues(app_1.listDirectoryEntriesRecursively(rootPath)), _c; _c = yield _b.next(), !_c.done;) { | ||
let { path: absolutePath, dirent } = _c.value; | ||
const relativePath = path_1.default.relative(source, absolutePath); | ||
const relativePath = path_1.default.relative(rootPath, absolutePath); | ||
if (dirent.isDirectory()) | ||
continue; | ||
const { dir, base } = path_1.default.parse(relativePath); | ||
const dirs = dir === '' ? [] : dir.split(path_1.default.sep); | ||
promises.push(app_1.findRemoteFileByPath(dirs, base, rootFolder, client).then((remoteFile) => __awaiter(this, void 0, void 0, function* () { | ||
const file = new app_1.File(source, relativePath, dirent, rootFolder, remoteFile); | ||
promises.push(app_1.findRemoteFileByPath(relativePath, rootFolder, client).then((remoteFile) => __awaiter(this, void 0, void 0, function* () { | ||
const file = new app_1.File(rootPath, relativePath, dirent, rootFolder, remoteFile); | ||
debug('%o', file); | ||
@@ -97,4 +96,5 @@ const status = yield file.synchronize(client, pretend); | ||
} | ||
console.log(`${promises.length} entries were found.`); | ||
return Promise.all(promises); | ||
})).then(() => console.log('successful!')); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "carp-streamer", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "Carp streamer", | ||
@@ -5,0 +5,0 @@ "bin": "dist/index.js", |
@@ -1,1 +0,40 @@ | ||
# carp-streamer | ||
# carp-streamer | ||
[![npm version](https://badge.fury.io/js/carp-streamer.svg)](https://badge.fury.io/js/carp-streamer) | ||
[![Known Vulnerabilities](https://snyk.io//test/github/naokikimura/carp-streamer/badge.svg?targetFile=package.json)](https://snyk.io//test/github/naokikimura/carp-streamer?targetFile=package.json) | ||
## Installation | ||
```bash | ||
npm install -g carp-streamer | ||
``` | ||
## Configuration | ||
### Set an Application Config File | ||
```bash | ||
export BOX_APP_CONFIG=~/Downloads/211349463_aagtkjaz_config.json | ||
``` | ||
## Usage | ||
Execute the command with the following arguments. | ||
- Source: directory path of local computer | ||
- Sink: Folder ID of Box | ||
If you want to backup the desktop folder of the local computer to the root folder of Box, execute as follows. | ||
```bash | ||
carp-streamer ~/Desktop 0 | ||
``` | ||
There is also a `--dry-run` option. | ||
```bash | ||
carp-streamer --dry-run ~/Desktop 0 | ||
``` | ||
## Contributing | ||
Bug reports and pull requests are welcome on GitHub at https://github.com/naokikimura/carp-streamer. |
@@ -69,3 +69,9 @@ import BoxSDK from 'box-node-sdk'; | ||
export async function findRemoteFileByPath(folderPath: string[], filename: string, rootFolder: BoxSDK.MiniFolder, client: BoxSDK.BoxClient): Promise<BoxSDK.File | undefined> { | ||
export async function findRemoteFileByPath(relativePath: string, rootFolder: BoxSDK.MiniFolder, client: BoxSDK.BoxClient): Promise<BoxSDK.File | undefined> { | ||
const { dir, base } = path.parse(relativePath); | ||
const dirs = dir === '' ? [] : dir.split(path.sep); | ||
return _findRemoteFileByPath(dirs, base, rootFolder, client); | ||
} | ||
async function _findRemoteFileByPath(folderPath: string[], filename: string, rootFolder: BoxSDK.MiniFolder, client: BoxSDK.BoxClient): Promise<BoxSDK.File | undefined> { | ||
const folder = await findRemoteFolderByPath(folderPath, rootFolder, client); | ||
@@ -104,7 +110,7 @@ return folder && client.folders.getItems(folder.id).then(items => _.first(items.entries.filter(isMiniFile).filter(item => item.name.normalize() === filename.normalize()))) | ||
const readdir = util.promisify(fs.readdir); | ||
export async function* list(root: string): AsyncIterableIterator<{path: string, dirent: fs.Dirent}> { | ||
export async function* listDirectoryEntriesRecursively(root: string): AsyncIterableIterator<{path: string, dirent: fs.Dirent}> { | ||
for(let dirent of await readdir(root, { withFileTypes: true })) { | ||
const entryPath = path.join(root, dirent.name); | ||
if (dirent.isDirectory()) { | ||
yield* list(entryPath); | ||
yield* listDirectoryEntriesRecursively(entryPath); | ||
} | ||
@@ -111,0 +117,0 @@ yield ({ path: entryPath, dirent }); |
@@ -9,3 +9,3 @@ #!/usr/bin/env node | ||
import util from 'util'; | ||
import {File, ResultStatus, list, findRemoteFileByPath, findRemoteFolderByPath} from './app' | ||
import {File, ResultStatus, listDirectoryEntriesRecursively, findRemoteFileByPath} from './app' | ||
@@ -39,2 +39,3 @@ const npmPackage = require('../package.json'); | ||
const rootPath = path.resolve(process.cwd(), source); | ||
const client = createBoxClient({ appConfig, token: args.token }); | ||
@@ -46,9 +47,7 @@ if (args['as-user']) { | ||
const promises = []; | ||
for await (let { path: absolutePath, dirent } of list(source)) { | ||
const relativePath = path.relative(source, absolutePath); | ||
for await (let { path: absolutePath, dirent } of listDirectoryEntriesRecursively(rootPath)) { | ||
const relativePath = path.relative(rootPath, absolutePath); | ||
if (dirent.isDirectory()) continue; | ||
const { dir, base } = path.parse(relativePath); | ||
const dirs = dir === '' ? [] : dir.split(path.sep); | ||
promises.push(findRemoteFileByPath(dirs, base, rootFolder, client).then(async (remoteFile) => { | ||
const file = new File(source, relativePath, dirent, rootFolder, remoteFile) | ||
promises.push(findRemoteFileByPath(relativePath, rootFolder, client).then(async (remoteFile) => { | ||
const file = new File(rootPath, relativePath, dirent, rootFolder, remoteFile) | ||
debug('%o', file); | ||
@@ -74,3 +73,4 @@ const status = await file.synchronize(client, pretend); | ||
} | ||
console.log(`${promises.length} entries were found.`); | ||
return Promise.all(promises); | ||
}).then(() => console.log('successful!')); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
44855
704
41