let asyncThrows = Q.async(function* (fn, name, fp1, msgRe) { let throwAgain = false, doesMatch = true, msg; yield fs.rename(fp1, 'metadata.json'); try { yield fn(); throwAgain = true; } catch (err) { if (msgRe) { doesMatch = msgRe.test(err.message); msg = err.message; } } finally { yield fs.rename('metadata.json', fp1); if (throwAgain) { throw new Error(`expected ${name} to throw an error`); } else if (!doesMatch) { let errMsg = `error message doesn\'t match the pattern ${msgRe}\nError: ${msg}`; throw new Error(errMsg); } } });
let createNewElement = Q.async(function* (el) { let repo = 'polymerelements/seed-element'; // download and extrac the seed-element let repoPath = yield utils.extractGhRepo(repo, '.', el.name); el.install = repoPath; yield fs.removeTree(path.resolve(repoPath, '.github')); let replacePaths = yield globby([`${repoPath}/**`], {nodir: true}); // replace the text `seed-element` with the name of the new element yield Promise.all(replacePaths.map(Q.async(function*(p) { let content = yield fs.read(p); let ccName = utils.toCamelCase(el.name); content = content.replace(/seedElement/g, ccName); content = content.replace(/seed-element/g, el.name); yield fs.write(p, content); }))); let fromPath = path.resolve(repoPath, 'seed-element.html'); let toPath = path.resolve(repoPath, `${el.name}.html`); // rename the paths to the new name yield fs.rename(fromPath, toPath); return el; });
.then(dirExists=> { if (dirExists) { this.logger.warn(`Due to recording split in LIVE_BACKUP, renaming [${unknownEntry}] recording content dir to [${backupRecordedEntryId}], archive path [${targetArchivePath}]`); return qio.rename(unknownRecordedEntryIdPath, targetArchivePath); } })
return qio.exists(jsonPath).then((isExist)=>{ if (isExist && options.useSameJson == false){ let jsonPathNew = path.join(jsonPath + "_"+ new Date().getTime().toString()) logger.info("Found playlist json exist, rename it to %s", jsonPathNew) return qio.rename(jsonPath, jsonPathNew) } })
return qio.isDirectory(targetPath).then(function (res) { if (res) { logger.debug("Removing directory " + targetPath); var renamedFolderName = path.join(config.get("oldContentFolderPath"), newName + '_' + (new Date()).getTime().toString()); return qio.rename(targetPath, renamedFolderName); } }).then(function () {
let asyncDoesNotThrow = Q.async(function* (fn, name, fp1) { let throwAgain = false; yield fs.rename(fp1, 'metadata.json'); try { yield fn(); } catch (err) { throwAgain = true; } finally { yield fs.rename('metadata.json', fp1); if (throwAgain) { throw new Error(`expected ${name} to not throw an error`); } } });
function renameOldLog ( o ) { var newLogPath = path.join( logDir, logInfoToName(o) ); return QFS.rename(oldLogPath, newLogPath) }
.then(({fullPath}) => { let renamedFolderName = path.join(fullPath, newName + '_' + (new Date()).getTime().toString()); return qio.rename(targetPath, renamedFolderName); });
.then( () => { return FS.rename(path.join(tempIpaPath, 'zipped.ipa'), ipaPath); });
.then( () => { // Backup the original .ipa var origIpaPath = path.join(path.dirname(ipaPath), path.basename(ipaPath,'.ipa') + "-orig.ipa"); return FS.rename(ipaPath, origIpaPath); })
var remove = function remove(){ return qio.rename(manifestFullPath, manifestFullPath + '.removed'); }
}).then(function() { return FS.rename(tmpFilePath, filePath); });