carp-streamer
Advanced tools
Comparing version
@@ -69,8 +69,19 @@ "use strict"; | ||
else if (!this.remoteFile) { | ||
const { dir, base } = path_1.default.parse(this.relativePath); | ||
const dirs = dir === '' ? [] : dir.split(path_1.default.sep); | ||
(pretend ? Promise.resolve({}) | ||
: findRemoteFolderByPath(dirs, this.remoteRoot, client) | ||
.then(folder => folder || createRemoteFolderByPath(dirs, this.remoteRoot, client)) | ||
.then(folder => client.files.uploadFile(folder.id, base, this.createReadStream()))).then(() => resolve(ResultStatus.UPLOADED)).catch(reject); | ||
Promise.resolve().then(() => __awaiter(this, void 0, void 0, function* () { | ||
if (pretend) | ||
Promise.resolve(); | ||
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)); | ||
debug('Uploading `%s`...', this.relativePath); | ||
return client.files.uploadFile(folder.id, base, this.createReadStream()); | ||
} | ||
catch (error) { | ||
debug("Failed to create '%s' folder.", dir); | ||
throw error; | ||
} | ||
})).then(() => resolve(ResultStatus.UPLOADED)).catch(reject); | ||
} | ||
@@ -83,4 +94,8 @@ else { | ||
else { | ||
(pretend ? Promise.resolve({}) | ||
: client.files.uploadNewFileVersion(this.remoteFile.id, this.createReadStream())).then(() => resolve(ResultStatus.UPGRADED)).catch(reject); | ||
Promise.resolve().then(() => { | ||
if (pretend) | ||
Promise.resolve(); | ||
debug('Upgrading `%s`...', this.relativePath); | ||
return client.files.uploadNewFileVersion(this.remoteFile.id, this.createReadStream()); | ||
}).then(() => resolve(ResultStatus.UPGRADED)).catch(reject); | ||
} | ||
@@ -141,5 +156,3 @@ }); | ||
const subFolder = lodash_1.default.first(items.entries.filter(isMiniFolder).filter(item => item.name === folderName)); | ||
const folder = yield new Promise((resolve, reject) => { | ||
return subFolder ? resolve(subFolder) : client.folders.create(rootFolder.id, folderName).then(resolve); | ||
}); | ||
const folder = subFolder || (yield client.folders.create(rootFolder.id, folderName)); | ||
return yield createRemoteFolderByPath(folderPath.slice(1), folder, client); | ||
@@ -146,0 +159,0 @@ }); |
@@ -29,3 +29,3 @@ #!/usr/bin/env node | ||
const npmPackage = require('../package.json'); | ||
const debug = util_1.default.debuglog(npmPackage.name); | ||
const debug = util_1.default.debuglog(`${npmPackage.name}:index`); | ||
const argsOption = { | ||
@@ -70,21 +70,28 @@ 'alias': { t: 'token', v: 'version' }, | ||
promises.push(app_1.findRemoteFileByPath(relativePath, rootFolder, client).then((remoteFile) => __awaiter(this, void 0, void 0, function* () { | ||
debug('%o', { relativePath, dirent, remoteFile }); | ||
const file = new app_1.File(rootPath, relativePath, dirent, rootFolder, remoteFile); | ||
debug('%o', file); | ||
const status = yield file.synchronize(client, pretend); | ||
switch (status) { | ||
case app_1.ResultStatus.DOWNLOADED: | ||
console.log(`'${file.relativePath}' only exists remotely.`); | ||
break; | ||
case app_1.ResultStatus.SYNCHRONIZED: | ||
console.log(`'${file.relativePath}' is synchronized.`); | ||
break; | ||
case app_1.ResultStatus.UPLOADED: | ||
console.log(`'${file.relativePath}' is newly uploaded.`); | ||
break; | ||
case app_1.ResultStatus.UPGRADED: | ||
console.log(`A new version of '${file.relativePath}' has been uploaded.`); | ||
break; | ||
default: | ||
throw new Error('unknown result status'); | ||
try { | ||
const status = yield file.synchronize(client, pretend); | ||
switch (status) { | ||
case app_1.ResultStatus.DOWNLOADED: | ||
console.log(`'${file.relativePath}' only exists remotely.`); | ||
break; | ||
case app_1.ResultStatus.SYNCHRONIZED: | ||
console.log(`'${file.relativePath}' is synchronized.`); | ||
break; | ||
case app_1.ResultStatus.UPLOADED: | ||
console.log(`'${file.relativePath}' is newly uploaded.`); | ||
break; | ||
case app_1.ResultStatus.UPGRADED: | ||
console.log(`A new version of '${file.relativePath}' has been uploaded.`); | ||
break; | ||
default: | ||
throw new Error('unknown result status'); | ||
} | ||
} | ||
catch (error) { | ||
debug('%s\n%s', error.message, error.stack); | ||
console.log(`Failed to synchronize '${file.relativePath}'.`); | ||
throw error; | ||
} | ||
}))); | ||
@@ -102,3 +109,10 @@ } | ||
return Promise.all(promises); | ||
})).then(() => console.log('successful!')); | ||
})).then(() => { | ||
console.log('successful!'); | ||
process.exit(0); | ||
}).catch(reason => { | ||
console.log(reason.message); | ||
console.log(`failure!`); | ||
process.exit(1); | ||
}); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "carp-streamer", | ||
"version": "0.2.2", | ||
"version": "0.2.3", | ||
"description": "Carp streamer", | ||
@@ -5,0 +5,0 @@ "bin": "dist/index.js", |
@@ -32,9 +32,18 @@ import BoxSDK from 'box-node-sdk'; | ||
} else if (!this.remoteFile) { | ||
const { dir, base } = path.parse(this.relativePath); | ||
const dirs = dir === '' ? [] : dir.split(path.sep); | ||
(pretend ? Promise.resolve({}) | ||
: findRemoteFolderByPath(dirs, this.remoteRoot, client) | ||
.then(folder => folder || createRemoteFolderByPath(dirs, this.remoteRoot, client)) | ||
.then(folder => client.files.uploadFile(folder.id, base, this.createReadStream())) | ||
).then(() => resolve(ResultStatus.UPLOADED)).catch(reject); | ||
Promise.resolve().then(async () => { | ||
if (pretend) Promise.resolve(); | ||
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); | ||
debug('Uploading `%s`...', this.relativePath); | ||
return client.files.uploadFile(folder.id, base, this.createReadStream()); | ||
} catch (error) { | ||
debug("Failed to create '%s' folder.", dir); | ||
throw error; | ||
} | ||
}).then(() => resolve(ResultStatus.UPLOADED)).catch(reject); | ||
} else { | ||
@@ -45,5 +54,8 @@ this.digest().then(sha1 => { | ||
} else { | ||
(pretend ? Promise.resolve({}) | ||
: client.files.uploadNewFileVersion(this.remoteFile!.id, this.createReadStream()) | ||
).then(() => resolve(ResultStatus.UPGRADED)).catch(reject); | ||
Promise.resolve().then(() => { | ||
if (pretend) Promise.resolve(); | ||
debug('Upgrading `%s`...', this.relativePath); | ||
return client.files.uploadNewFileVersion(this.remoteFile!.id, this.createReadStream()); | ||
}).then(() => resolve(ResultStatus.UPGRADED)).catch(reject); | ||
} | ||
@@ -104,5 +116,3 @@ }); | ||
const subFolder = _.first(items.entries.filter(isMiniFolder).filter(item => item.name === folderName)); | ||
const folder = await new Promise<BoxSDK.MiniFolder>((resolve, reject) => { | ||
return subFolder ? resolve(subFolder) : client.folders.create(rootFolder.id, folderName).then(resolve); | ||
}); | ||
const folder = subFolder || await client.folders.create(rootFolder.id, folderName); | ||
return await createRemoteFolderByPath(folderPath.slice(1), folder, client); | ||
@@ -109,0 +119,0 @@ }; |
@@ -12,3 +12,3 @@ #!/usr/bin/env node | ||
const npmPackage = require('../package.json'); | ||
const debug = util.debuglog(npmPackage.name); | ||
const debug = util.debuglog(`${npmPackage.name}:index`); | ||
@@ -56,20 +56,26 @@ const argsOption = { | ||
promises.push(findRemoteFileByPath(relativePath, rootFolder, client).then(async (remoteFile) => { | ||
debug('%o', { relativePath, dirent, remoteFile }); | ||
const file = new File(rootPath, relativePath, dirent, rootFolder, remoteFile) | ||
debug('%o', file); | ||
const status = await file.synchronize(client, pretend); | ||
switch (status) { | ||
case ResultStatus.DOWNLOADED: | ||
console.log(`'${file.relativePath}' only exists remotely.`); | ||
break; | ||
case ResultStatus.SYNCHRONIZED: | ||
console.log(`'${file.relativePath}' is synchronized.`); | ||
break; | ||
case ResultStatus.UPLOADED: | ||
console.log(`'${file.relativePath}' is newly uploaded.`); | ||
break; | ||
case ResultStatus.UPGRADED: | ||
console.log(`A new version of '${file.relativePath}' has been uploaded.`); | ||
break; | ||
default: | ||
throw new Error('unknown result status'); | ||
try { | ||
const status = await file.synchronize(client, pretend); | ||
switch (status) { | ||
case ResultStatus.DOWNLOADED: | ||
console.log(`'${file.relativePath}' only exists remotely.`); | ||
break; | ||
case ResultStatus.SYNCHRONIZED: | ||
console.log(`'${file.relativePath}' is synchronized.`); | ||
break; | ||
case ResultStatus.UPLOADED: | ||
console.log(`'${file.relativePath}' is newly uploaded.`); | ||
break; | ||
case ResultStatus.UPGRADED: | ||
console.log(`A new version of '${file.relativePath}' has been uploaded.`); | ||
break; | ||
default: | ||
throw new Error('unknown result status'); | ||
} | ||
} catch(error) { | ||
debug('%s\n%s', error.message, error.stack); | ||
console.log(`Failed to synchronize '${file.relativePath}'.`); | ||
throw error; | ||
} | ||
@@ -80,2 +86,9 @@ })) | ||
return Promise.all(promises); | ||
}).then(() => console.log('successful!')); | ||
}).then(() => { | ||
console.log('successful!'); | ||
process.exit(0); | ||
}).catch(reason => { | ||
console.log(reason.message); | ||
console.log(`failure!`); | ||
process.exit(1); | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
47865
5.6%760
6.74%