Skip to content

Commit

Permalink
'Page details updated: Home (item-f794dae4-5cbd-4764-974a-f3cdce060ae3)'
Browse files Browse the repository at this point in the history
  • Loading branch information
btopro committed Nov 15, 2024
1 parent ea3cf05 commit c219613
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 12 deletions.
23 changes: 23 additions & 0 deletions src/lib/GitPlus.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
const { Git } = require('git-interface');
const util = require('node:util');
const child_process = require('child_process');
const exec = util.promisify(child_process.exec);
class GitPlus extends Git {
constructor(options) {
super(options);
console.log(options);
this.cliVersion = options.cliVersion || null;
this.gitTest();
}
async gitTest() {
try {
const { stdout, stderr } = await exec('git --version');
this.cliVersion = stdout;
} catch (e) {
this.cliVersion = null;
}
}
async revert(count) {
let counter = 0;
// sanity check
Expand All @@ -12,5 +29,11 @@ class GitPlus extends Git {
}
return true;
}
gitExec(cmd) {
console.log(this.cliVersion);
if (this.cliVersion) {
return super.gitExec(cmd);
}
}
}
module.exports = GitPlus;
46 changes: 38 additions & 8 deletions src/lib/HAXCMS.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ const json_encode = require('locutus/php/json/json_encode');
const strtr = require('locutus/php/strings/strtr');
const usort = require('locutus/php/array/usort');
const sharp = require('sharp');
const util = require('node:util');
const child_process = require('child_process');
const exec = util.promisify(child_process.exec);
// a site object
class HAXCMSSite
{
Expand Down Expand Up @@ -324,7 +327,8 @@ class HAXCMSSite
try {
// put this in version control :) :) :)
const git = new GitPlus({
dir: directory + '/' + tmpname
dir: directory + '/' + tmpname,
cliVersion: await this.gitTest()
});
// initalize git repo
await git.init();
Expand Down Expand Up @@ -362,6 +366,16 @@ class HAXCMSSite
}
return false;
}
async gitTest() {
console.log('?dfdsfsdfsfsdf');
try {
const { stdout, stderr } = await exec('git --version');
return stdout;
} catch (e) {
console.log(e);
return null;
}
}
/**
* Return an array of files we care about rebuilding on managed file operations
* @return array keyed array of files we wish to pull from the boilerplate and keep in sync
Expand Down Expand Up @@ -566,10 +580,13 @@ class HAXCMSSite
*/
async gitCommit(msg = 'Committed changes')
{
console.log(await this.gitTest());
try {
console.log(this.siteDirectory);
// commit, true flag will attempt to make this a git repo if it currently isn't
const git = new GitPlus({
dir: this.siteDirectory
dir: this.siteDirectory,
cliVersion: await this.gitTest()
});
await git.add();
await git.commit(msg);
Expand All @@ -589,7 +606,8 @@ class HAXCMSSite
{
try {
const git = new GitPlus({
dir: this.siteDirectory
dir: this.siteDirectory,
cliVersion: await this.gitTest()
});
await git.revert(count);
}
Expand All @@ -603,7 +621,8 @@ class HAXCMSSite
{
try {
const git = new GitPlus({
dir: this.siteDirectory
dir: this.siteDirectory,
cliVersion: await this.gitTest()
});
await git.add();
await git.commit("commit forced");
Expand All @@ -622,7 +641,8 @@ class HAXCMSSite
{
try {
const git = new GitPlus({
dir: this.siteDirectory
dir: this.siteDirectory,
cliVersion: await this.gitTest()
});
await repo.setRemote("origin", gitDetails.url);
}
Expand Down Expand Up @@ -1568,6 +1588,16 @@ class HAXCMSSite
}
// HAXcms core
class HAXCMSClass {
async gitTest() {
console.log("?");
try {
const { stdout, stderr } = await exec('git --version');
console.log(stdout);
return stdout;
} catch (e) {
return null;
}
}
constructor() {
this.developerMode = false;
this.developerModeAdminOnly = false;
Expand Down Expand Up @@ -2277,7 +2307,7 @@ class HAXCMSClass {
/**
* Set and validate config
*/
setConfig(values)
async setConfig(values)
{
if ((values.apis)) {
for (var key in values.apis) {
Expand Down Expand Up @@ -2337,9 +2367,9 @@ class HAXCMSClass {
try {
// set global config for username / email if we can
const gitRepo = new GitPlus({
dir: this.siteDirectory
dir: this.siteDirectory,
cliVersion: await this.gitTest()
});
new GitPlus({});
gitRepo.gitExec(
'config --global user.name "' +
this.config.site.git.user +
Expand Down
3 changes: 2 additions & 1 deletion src/routes/createSite.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ async function createSite(req, res) {

try {
const git = new GitPlus({
dir: site.siteDirectory
dir: site.siteDirectory,
cliVersion: await HAXCMS.gitTest()
});
git.setDir(site.siteDirectory);
await git.init();
Expand Down
6 changes: 5 additions & 1 deletion src/routes/gitImportSite.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ const GitPlus = require('../lib/GitPlus.js');
// @todo check if this fails
directory = HAXCMS.HAXCMS_ROOT + HAXCMS.sitesDirectory + '/' + repo_path;
try {
let git = new GitPlus();
let git = new GitPlus({
dir: directory,
cliVersion: await HAXCMS.gitTest()
});
git.setDir(directory);
let repo = git.create(directory);
repo = git.open(directory, true);
repo.set_remote("origin", repoUrl);
Expand Down
6 changes: 5 additions & 1 deletion src/routes/publishSite.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ const GitPlus = require('../lib/GitPlus.js');
}
if ((gitSettings)) {
try {
let git = new GitPlus();
let git = new GitPlus({
dir: site.siteDirectory,
cliVersion: await HAXCMS.gitTest()
});
git.setDir(site.siteDirectory);
let repo = git.open(site.siteDirectory, true);
// ensure we're on master and everything is added
await repo.checkout('master');
Expand Down
6 changes: 5 additions & 1 deletion src/routes/syncSite.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ const GitPlus = require('../lib/GitPlus.js');
}
if ((gitSettings)) {
try {
let git = new GitPlus();
let git = new GitPlus({
dir: site.siteDirectory,
cliVersion: await HAXCMS.gitTest()
});
git.setDir(site.siteDirectory);
let repo = git.open(site.siteDirectory, true);
// ensure we're on branch, most likley master
await repo.checkout(gitSettings.branch);
Expand Down

0 comments on commit c219613

Please sign in to comment.