Skip to content

Commit

Permalink
Change to simplegit
Browse files Browse the repository at this point in the history
  • Loading branch information
ilmartyrk committed Oct 10, 2023
2 parents 691ca1b + f3c77ca commit 5d7d0c2
Show file tree
Hide file tree
Showing 3 changed files with 343 additions and 1,094 deletions.
31 changes: 11 additions & 20 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const NodeGit = require('nodegit');
const simpleGit = require('simple-git');
const path = require('path');
const fs = require('fs');

Expand All @@ -10,25 +10,16 @@ let settings = {};
let savePath = path.join(process.cwd(), 'node_modules', 'ep_translations', 'locales');

const cloneOrPull = async (url, options) => {
if (!options.branch) {
options.branch = 'master';
}
try {
fs.accessSync(options.path);
// Cloned already; we need to pull
const repository = await NodeGit.Repository.open(options.path);
await repository.fetchAll();
return repository.mergeBranches(options.branch, `origin/${options.branch}`);
} catch (err) {
// Not yet cloned
console.log('ERR', err);
try {
fs.mkdirSync(savePath, {recursive: true});
return NodeGit.Clone(url, options.path); // eslint-disable-line new-cap
} catch (err) {
console.log('CLONE ERROR', err);
}
}
const git = simpleGit(options.path);
const initialiseRepo = async (git) => {
await git.init();
return git.addRemote('origin', url);
};

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

git.fetch();
};

const loadTranslations = async () => {
Expand Down
Loading

0 comments on commit 5d7d0c2

Please sign in to comment.