Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'use strict';
import fs from 'fs-extra';
import path from 'path-extra';
import ospath from 'ospath';
// constant
const TEMP_IMPORT_PATH = path.join(ospath.home(), 'translationCore', 'imports', 'temp');
class AdmZip {
constructor(sourcePath) {
this.sourcePath = sourcePath;
}
// mocking unzipping a file using fs-extra mock
extractAllTo(destinationPath, options) {
// using fs to mock saving the files in file system.
const fileName = this.sourcePath.split(path.sep).pop();
const fileDestinationPath = path.join(destinationPath, fileName);
// fileDestinationPath is the path and the array is the files in the path
fs.__setMockFS({
[TEMP_IMPORT_PATH]: ['id_tit_text_ulb', 'manifest.json', '.DS_Store'],
[fileDestinationPath]: ['01', '02', '03', 'front', 'LICENSE.md', 'manifest.json']
});
/* eslint-disable no-console */
import path from 'path-extra';
import ospath from 'ospath';
import fs from 'fs-extra';
// constants
const DEFAULT_SAVE = path.join(ospath.home(), 'translationCore', 'projects');
/**
* Loads a json file.
* @param {string} directory - Directorty of the file to load, not the file name.
* @param {string} file - The file name to load.
*/
export function loadFile(directory, file) {
if (!directory) {
return null;
}
const pathLocation = path.join(directory, file);
if (fs.existsSync(pathLocation)) {
return fs.readJsonSync(pathLocation);
} else {
import fs from 'fs-extra';
import path from 'path-extra';
import ospath from 'ospath';
import consts from './ActionTypes';
// constants
const DEFAULT_SAVE = path.join(ospath.home(), 'translationCore', 'projects');
/**
* Reads projects from the fs in ~/translationCore/
*/
export function getProjectsFromFolder() {
const recentProjects = fs.readdirSync(DEFAULT_SAVE);
return {
type: consts.GET_RECENT_PROJECTS,
recentProjects: recentProjects,
};
}
// actions
// helpers
import * as ResourcesHelpers from '../helpers/ResourcesHelpers';
import * as SettingsHelpers from '../helpers/SettingsHelpers';
import * as BibleHelpers from '../helpers/bibleHelpers';
import * as Bible from '../common/BooksOfTheBible';
import {
ORIGINAL_LANGUAGE,
TARGET_BIBLE,
TARGET_LANGUAGE,
} from '../common/constants';
import * as SettingsActions from './SettingsActions';
import consts from './ActionTypes';
// constants
const USER_RESOURCES_PATH = path.join(ospath.home(), 'translationCore/resources');
const bookCache = new SimpleCache();
/**
* Adds a bible to the resources reducer.
* @param {String} languageId - language id: en, hi, el-x-koine, he.
* @param {String} bibleId - name/label for bible: ult, udt, ust, ugnt.
* @param {object} bibleData - data being saved in the bible property.
*/
export function addNewBible(languageId, bibleId, bibleData) {
return ((dispatch) => {
if (BibleHelpers.isOriginalLanguage(languageId)) {
languageId = ORIGINAL_LANGUAGE;
}
dispatch({
type: consts.ADD_NEW_BIBLE_TO_RESOURCES,
languageId: languageId,
it('should return the deployments path', () => {
const expected = path.join(ospath.data(), 'polkadot-deployer', 'deployments');
const subject = new Files();
subject.deploymentsPath().should.equal(expected);
});
});
export function getGroupsIndex(gatewayLanguageId, toolName) {
try {
const toolResourceDirectory = path.join(ospath.home(), 'translationCore', 'resources', gatewayLanguageId, TRANSLATION_HELPS, toolName);
const versionDirectory = ResourceAPI.getLatestVersion(toolResourceDirectory) || toolResourceDirectory;
const dataDirectory = path.join(versionDirectory, 'kt');
const groupIndexDataDirectory = path.join(dataDirectory, 'index.json');
return fs.readJsonSync(groupIndexDataDirectory);
} catch (error) {
console.error(error);
}
}
export const getDefaultPath = (csvSaveLocation, projectName) => {
let defaultPath;
const OSX_DOCUMENTS_PATH = path.join(ospath.home(), 'Documents');
const WIN_DOCUMENTS_PATH = path.join(ospath.home(), 'My Documents');
if (csvSaveLocation) {
defaultPath = path.join(csvSaveLocation, projectName + '.zip');
} else if (fs.existsSync(OSX_DOCUMENTS_PATH)) {
defaultPath = path.join(OSX_DOCUMENTS_PATH, projectName + '.zip');
} else if (fs.existsSync(WIN_DOCUMENTS_PATH)) {
defaultPath = path.join(WIN_DOCUMENTS_PATH, projectName + '.zip');
} else {
defaultPath = path.join(ospath.home(), projectName + '.zip');
}
return defaultPath;
};
const getDirectoryList = (options, callback) => {
const sourcePath = (options.path || '/').replace(/^~/, ospath.home());
try {
const directories = [];
const files = [];
fs.readdirSync(sourcePath).forEach(item => {
const joinedPath = path.join(sourcePath, item);
if (fs.existsSync(joinedPath)) {
if (fs.statSync(joinedPath).isDirectory()) {
directories.push(item);
} else {
files.push(item);
}
}
});
setTimeout(() => {
/**Path to save the usfm file @type {string}*/
let defaultPath;
if (lastSaveLocation) {
/**trys default save location first then trys different OS's */
defaultPath = path.join(lastSaveLocation, projectName + `.${ext}`);
}
else if (fs.existsSync(OSX_DOCUMENTS_PATH)) {
defaultPath = path.join(OSX_DOCUMENTS_PATH, projectName + `.${ext}`);
} else if (fs.existsSync(WIN_DOCUMENTS_PATH)) {
defaultPath = path.join(WIN_DOCUMENTS_PATH, projectName + `.${ext}`);
}
else {
defaultPath = path.join(ospath.home(), projectName + `.${ext}`);
}
const filePath = ipcRenderer.sendSync('save-as', { options: { defaultPath: defaultPath, filters: [{ extensions: [ext] }], title: 'Save Export As' } });
if (filePath) resolve(filePath);
else reject();
}, 200);
});
componentWillMount() {
const tCDir = path.join(ospath.home(), 'translationCore', 'projects');
fs.ensureDirSync(tCDir);
}