Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function preserveNeededOrigLangVersions(languageId, resourceId, resourcePath) {
let deleteOldResources = true; // by default we do not keep old versions of resources
if (BibleHelpers.isOriginalLanguageBible(languageId, resourceId)) {
const requiredVersions = getOtherTnsOLVersions(resourceId).sort((a, b) =>
-ResourceAPI.compareVersions(a, b) // do inverted sort
);
console.log('preserveNeededOrigLangVersions: requiredVersions', requiredVersions);
// see if we need to keep old versions of original language
if (requiredVersions && requiredVersions.length) {
deleteOldResources = false;
const highestRequired = requiredVersions[0];
const versions = ResourceAPI.listVersions(resourcePath);
console.log('preserveNeededOrigLangVersions: versions', versions);
for (let version of versions) {
if (!requiredVersions.includes(version)) {
const newerResource = ResourceAPI.compareVersions(version, highestRequired) > 0;
if (!newerResource) { // don't delete if newer version
import sourceContentUpdater from 'tc-source-content-updater';
import {
getTranslate, getContext, getSelectedToolName, getProjectSaveLocation, getProjectBookId,
} from '../selectors';
// helpers
import { getLocalResourceList } from '../helpers/sourceContentUpdatesHelpers';
import { copyGroupDataToProject, updateSourceContentUpdaterManifest } from '../helpers/ResourcesHelpers';
import { getOrigLangforBook } from '../helpers/bibleHelpers';
import * as Bible from '../common/BooksOfTheBible';
import { loadBookTranslations } from './ResourcesActions';
import {
openAlertDialog, closeAlertDialog, openOptionDialog,
} from './AlertModalActions';
import consts from './ActionTypes';
// constants
const SourceContentUpdater = new sourceContentUpdater();
const USER_RESOURCES_PATH = path.join(ospath.home(), 'translationCore/resources');
/**
* Resets the state of the source content updates reducer.
*/
export const resetSourceContentUpdatesReducer = () => ({ type: consts.RESET_LIST_OF_SOURCE_CONTENT_TO_UPDATE });
export const updateSourceContentUpdatesReducer = () => ({ type: consts.SOURCE_CONTENT_UPDATED });
const failedAlertAndRetry = (closeSourceContentDialog, retryCallback, failAlertMessage) => ((dispatch, getState) => {
const translate = getTranslate(getState());
dispatch(
openOptionDialog(
translate(failAlertMessage),
() => dispatch(retryCallback()),
const updateResources = async (languages, resourcesPath) => {
const SourceContentUpdater = new sourceContentUpdater();
const localResourceList = updateResourcesHelpers.getLocalResourceList(resourcesPath);
await SourceContentUpdater.getLatestResources(localResourceList)
.then(async () => {
await SourceContentUpdater.downloadResources(languages, resourcesPath)
.then(resources => {
resources.forEach(resource => {
console.log("Updated resource '" + resource.resourceId + "' for language '" + resource.languageId + "' to v" + resource.version);
});
})
.catch(err => {
console.error(err);
});
});
};