Skip to content

Commit

Permalink
Update loading
Browse files Browse the repository at this point in the history
  • Loading branch information
ilmartyrk committed Oct 10, 2023
1 parent 5d7d0c2 commit afd0869
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,38 @@

const simpleGit = require('simple-git');
const path = require('path');
const fs = require('fs');
const fs = require('fs/promises');

const languages = {};
let settings = {};
// defaults to node_module folder
let savePath = path.join(process.cwd(), 'node_modules', 'ep_translations', 'locales');

const cloneOrPull = async (url, options) => {
const git = simpleGit(options.path);
try {
await fs.access(savePath);
} catch (err) {
console.info('ep_translate no translations directory', err);
try {
await fs.mkdir(savePath, {recursive: true});
} catch (err) {
console.error('ep_translate PATH ERROR', err);
}
}

const git = simpleGit(savePath);
const initialiseRepo = async (git) => {
await git.init();
return git.addRemote('origin', url);
};

const isRepo = await git.checkIsRepo();
if (!isRepo) await initialiseRepo(git);

git.fetch();
await git.pull(options.remote || 'origin', options.branch || 'master');
};

const loadTranslations = async () => {
const files = fs.readdirSync(savePath);
const files = await fs.readdir(savePath);
if (!files || !files.length) {
return;
}
Expand All @@ -36,7 +46,7 @@ const loadTranslations = async () => {
let called = false;
filtered.forEach(async (file) => {
const lang = file.split('.')[0];
const data = await fs.readFileSync(path.join(savePath, file));
const data = await fs.readFile(path.join(savePath, file));
try {
const languageData = JSON.parse(data);
Object.keys(languageData).forEach((key) => {
Expand Down

0 comments on commit afd0869

Please sign in to comment.