carp-streamer
Advanced tools
Comparing version 0.2.3 to 0.2.4
@@ -71,9 +71,6 @@ "use strict"; | ||
if (pretend) | ||
Promise.resolve(); | ||
return; | ||
const { dir, base } = path_1.default.parse(this.relativePath); | ||
const dirs = dir === '' ? [] : dir.split(path_1.default.sep); | ||
debug('Finding `%s`...', dir); | ||
const foundFolder = yield findRemoteFolderByPath(dirs, this.remoteRoot, client); | ||
try { | ||
const folder = foundFolder || (yield createRemoteFolderByPath(dirs, this.remoteRoot, client)); | ||
const folder = yield createRemoteFolderUnlessItExists(dir, this.remoteRoot, client); | ||
debug('Uploading `%s`...', this.relativePath); | ||
@@ -94,8 +91,8 @@ return client.files.uploadFile(folder.id, base, this.createReadStream()); | ||
else { | ||
Promise.resolve().then(() => { | ||
Promise.resolve().then(() => __awaiter(this, void 0, void 0, function* () { | ||
if (pretend) | ||
Promise.resolve(); | ||
return; | ||
debug('Upgrading `%s`...', this.relativePath); | ||
return client.files.uploadNewFileVersion(this.remoteFile.id, this.createReadStream()); | ||
}).then(() => resolve(ResultStatus.UPGRADED)).catch(reject); | ||
})).then(() => resolve(ResultStatus.UPGRADED)).catch(reject); | ||
} | ||
@@ -139,3 +136,3 @@ }); | ||
if (folderPath.length === 0 || rootFolder === undefined) { | ||
return rootFolder === undefined || isFolder(rootFolder) ? Promise.resolve(rootFolder) : client.folders.get(rootFolder.id); | ||
return rootFolder === undefined || isFolder(rootFolder) ? rootFolder : yield client.folders.get(rootFolder.id); | ||
} | ||
@@ -152,3 +149,3 @@ const folderName = lodash_1.default.first(folderPath); | ||
if (folderPath.length === 0) { | ||
return isFolder(rootFolder) ? Promise.resolve(rootFolder) : client.folders.get(rootFolder.id); | ||
return isFolder(rootFolder) ? rootFolder : yield client.folders.get(rootFolder.id); | ||
} | ||
@@ -161,2 +158,10 @@ const folderName = lodash_1.default.first(folderPath) || ''; | ||
}); | ||
function createRemoteFolderUnlessItExists(relativePath, rootFolder, client) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const dirs = !relativePath ? [] : relativePath.split(path_1.default.sep); | ||
const foundFolder = yield findRemoteFolderByPath(dirs, rootFolder, client); | ||
return foundFolder || (yield createRemoteFolderByPath(dirs, rootFolder, client)); | ||
}); | ||
} | ||
exports.createRemoteFolderUnlessItExists = createRemoteFolderUnlessItExists; | ||
const readdir = util_1.default.promisify(fs_1.default.readdir); | ||
@@ -167,6 +172,6 @@ function listDirectoryEntriesRecursively(root) { | ||
const entryPath = path_1.default.join(root, dirent.name); | ||
yield yield __await(({ path: entryPath, dirent })); | ||
if (dirent.isDirectory()) { | ||
yield __await(yield* __asyncDelegator(__asyncValues(listDirectoryEntriesRecursively(entryPath)))); | ||
} | ||
yield yield __await(({ path: entryPath, dirent })); | ||
} | ||
@@ -173,0 +178,0 @@ }); |
@@ -66,4 +66,7 @@ #!/usr/bin/env node | ||
const relativePath = path_1.default.relative(rootPath, absolutePath); | ||
if (dirent.isDirectory()) | ||
if (dirent.isDirectory()) { | ||
if (!pretend) | ||
yield app_1.createRemoteFolderUnlessItExists(relativePath, rootFolder, client); | ||
continue; | ||
} | ||
promises.push(app_1.findRemoteFileByPath(relativePath, rootFolder, client).then((remoteFile) => __awaiter(this, void 0, void 0, function* () { | ||
@@ -70,0 +73,0 @@ debug('%o', { relativePath, dirent, remoteFile }); |
{ | ||
"name": "carp-streamer", | ||
"version": "0.2.3", | ||
"version": "0.2.4", | ||
"description": "Carp streamer", | ||
@@ -5,0 +5,0 @@ "bin": "dist/index.js", |
@@ -33,10 +33,7 @@ import BoxSDK from 'box-node-sdk'; | ||
Promise.resolve().then(async () => { | ||
if (pretend) Promise.resolve(); | ||
if (pretend) return; | ||
const { dir, base } = path.parse(this.relativePath); | ||
const dirs = dir === '' ? [] : dir.split(path.sep); | ||
debug('Finding `%s`...', dir); | ||
const foundFolder = await findRemoteFolderByPath(dirs, this.remoteRoot, client); | ||
try { | ||
const folder = foundFolder || await createRemoteFolderByPath(dirs, this.remoteRoot, client); | ||
const folder = await createRemoteFolderUnlessItExists(dir, this.remoteRoot, client); | ||
debug('Uploading `%s`...', this.relativePath); | ||
@@ -54,4 +51,4 @@ return client.files.uploadFile(folder.id, base, this.createReadStream()); | ||
} else { | ||
Promise.resolve().then(() => { | ||
if (pretend) Promise.resolve(); | ||
Promise.resolve().then(async () => { | ||
if (pretend) return; | ||
@@ -99,3 +96,3 @@ debug('Upgrading `%s`...', this.relativePath); | ||
if (folderPath.length === 0 || rootFolder === undefined) { | ||
return rootFolder === undefined || isFolder(rootFolder) ? Promise.resolve(rootFolder) : client.folders.get(rootFolder.id); | ||
return rootFolder === undefined || isFolder(rootFolder) ? rootFolder : await client.folders.get(rootFolder.id); | ||
} | ||
@@ -111,3 +108,3 @@ | ||
if (folderPath.length === 0) { | ||
return isFolder(rootFolder) ? Promise.resolve(rootFolder) : client.folders.get(rootFolder.id); | ||
return isFolder(rootFolder) ? rootFolder : await client.folders.get(rootFolder.id); | ||
} | ||
@@ -122,2 +119,8 @@ | ||
export async function createRemoteFolderUnlessItExists(relativePath: string, rootFolder: BoxSDK.MiniFolder, client: BoxSDK.BoxClient): Promise<BoxSDK.Folder> { | ||
const dirs = !relativePath ? [] : relativePath.split(path.sep); | ||
const foundFolder = await findRemoteFolderByPath(dirs, rootFolder, client); | ||
return foundFolder || await createRemoteFolderByPath(dirs, rootFolder, client) | ||
} | ||
const readdir = util.promisify(fs.readdir); | ||
@@ -127,7 +130,7 @@ export async function* listDirectoryEntriesRecursively(root: string): AsyncIterableIterator<{path: string, dirent: fs.Dirent}> { | ||
const entryPath = path.join(root, dirent.name); | ||
yield ({ path: entryPath, dirent }); | ||
if (dirent.isDirectory()) { | ||
yield* listDirectoryEntriesRecursively(entryPath); | ||
} | ||
yield ({ path: entryPath, dirent }); | ||
} | ||
} |
@@ -9,3 +9,3 @@ #!/usr/bin/env node | ||
import util from 'util'; | ||
import {File, ResultStatus, listDirectoryEntriesRecursively, findRemoteFileByPath} from './app' | ||
import {File, ResultStatus, listDirectoryEntriesRecursively, findRemoteFileByPath, createRemoteFolderUnlessItExists} from './app' | ||
@@ -54,3 +54,6 @@ const npmPackage = require('../package.json'); | ||
const relativePath = path.relative(rootPath, absolutePath); | ||
if (dirent.isDirectory()) continue; | ||
if (dirent.isDirectory()) { | ||
if (!pretend) await createRemoteFolderUnlessItExists(relativePath, rootFolder, client); | ||
continue; | ||
} | ||
promises.push(findRemoteFileByPath(relativePath, rootFolder, client).then(async (remoteFile) => { | ||
@@ -57,0 +60,0 @@ debug('%o', { relativePath, dirent, remoteFile }); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
48634
773