Skip to content

Commit

Permalink
Fix assets url & commit error
Browse files Browse the repository at this point in the history
  • Loading branch information
hodgef committed Apr 28, 2024
1 parent 1b69c0d commit 59e954e
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 24 deletions.
14 changes: 9 additions & 5 deletions src/renderer/components/Loader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ import "./styles/App.css";
import "react-toastify/dist/ReactToastify.css";

import React, { FunctionComponent, useRef } from "react";
import { initConfig, initStore, initDb, initExpress } from "../../common/bootstrap";
import { initConfig, initStore, initDb, initExpress, storeInt } from "../../common/bootstrap";
import { checkDirs } from "../services/utils";

// const remote = require("@electron/remote");
// const win = remote.getCurrentWindow();
// const openDevTools = remote.getGlobal("openDevTools");
const remote = require("@electron/remote");
const openDevTools = remote.getGlobal("openDevTools");

const Loader: FunctionComponent = () => {
const App = useRef<React.FunctionComponent<{}>>(null);
Expand All @@ -24,11 +23,16 @@ const Loader: FunctionComponent = () => {
};

React.useEffect(() => {
//openDevTools();
const init = async () => {
setLoadingText("Initializing Storage");
await initStore();

const devToolsEnabled = storeInt.get("_devToolsEnabled");

if(devToolsEnabled){
openDevTools();
}

setLoadingText("Initializing Configuration");
await initConfig();

Expand Down
37 changes: 30 additions & 7 deletions src/renderer/services/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ export const build = async (
onUpdate = (a?) => {},
itemIdToLoad?,
skipClear?,
generateSiteMap = false
generateSiteMap = false,
mode: "build" | "deploy" = "build"
) => {
if (!siteUUID) {
console.error("No UUID was provided to build()");
Expand Down Expand Up @@ -73,7 +74,7 @@ export const build = async (
* Buffer items
*/
const { itemsToLoad, mainBufferItem, bufferItems } =
await getFilteredBufferItems(siteUUID, itemIdToLoad);
await getFilteredBufferItems(siteUUID, itemIdToLoad, mode);

/**
* Load buffer
Expand Down Expand Up @@ -221,10 +222,11 @@ export const getParentIds = (itemUUID: string, nodes: IStructureItem[]) => {

export const getFilteredBufferItems = async (
siteUUID: string,
itemIdToLoad?: string
itemIdToLoad?: string,
mode: "build" | "deploy" = "build"
) => {
const site = await getSite(siteUUID);
const bufferItems = await getBufferItems(site);
const bufferItems = await getBufferItems(site, mode);
let itemsToLoad = bufferItems;
let mainBufferItem;

Expand Down Expand Up @@ -356,8 +358,29 @@ export const buildBufferItem = async (bufferItem: IBufferItem) => {
return true;
};

const processVars = (site: ISite, vars, mode) => {
if(mode === "deploy" && site?.url && vars){
const processedVars = {...vars};

Object.keys(processedVars).forEach(varName => {
if (varName) {
let value = processedVars[varName] as string;
const varNameLowercase = varName.toLowerCase();

if(value?.startsWith("/assets/") && (varNameLowercase.includes("image") || varNameLowercase.includes("url"))){
processedVars[varName] = site.url+value.substring(1);
}
}
});
return processedVars;
} else {
return vars;
}
}

export const getBufferItems = async (
siteUUIDOrSite
siteUUIDOrSite,
mode: "build" | "deploy" = "build"
): Promise<IBufferItem[]> => {
const site =
typeof siteUUIDOrSite === "string"
Expand Down Expand Up @@ -397,12 +420,12 @@ export const getBufferItems = async (
/**
* Aggregate data
*/
const vars = {
const vars = processVars(site, {
...(site.vars || {}),
...(getAggregateItemPropValues("item.vars", parentIds, bufferItems) ||
{}),
...(post.vars || {}),
};
}, mode);

const headHtml =
(site.headHtml || "") +
Expand Down
34 changes: 22 additions & 12 deletions src/renderer/services/providers/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,13 @@ class GithubProvider {
*/
try {
const bufferDir = storeInt.get("paths.buffer");
runCommand(bufferDir, `git clone "${repositoryUrl}" .`);
const cloneRes = runCommand(bufferDir, `git clone "${repositoryUrl}" .`);

if (cloneRes.error) {
modal.alert(cloneRes.res.message, null, null, null, `deploy_clone_error: ${repositoryUrl}`);
console.error(cloneRes);
return;
}

console.log("repositoryUrl", repositoryUrl);
console.log("bufferDir", bufferDir);
Expand All @@ -213,7 +219,8 @@ class GithubProvider {
onUpdate,
itemIdToDeploy,
!clearRemote,
generateSiteMap
generateSiteMap,
"deploy"
);

if (!buildRes) {
Expand All @@ -225,15 +232,18 @@ class GithubProvider {

await new Promise((resolve) => {
setTimeout(() => {
const { res: e, error: commitError } = runCommand(
bufferDir,
`git add --all && git commit -m "${commitMessage}" && git push`
);

if (commitError) {
modal.alert(e.message, null, null, null, `commit_error: ${repositoryUrl}`);
console.error(e);
}
[
runCommand(bufferDir, "git config --global core.safecrlf false"),
runCommand(bufferDir, "git add --all"),
runCommand(bufferDir, `git commit -m "${commitMessage}"`),
runCommand(bufferDir, "git push --force")
].forEach((data) => {
// If working space is empty, git commit exits with "1"
if (data.error && !data.res.message?.includes("git commit")) {
modal.alert(data.res.message, null, null, null, `commit_error: ${repositoryUrl}`);
console.error(data);
}
});
resolve(null);
}, 1000);
});
Expand All @@ -243,7 +253,7 @@ class GithubProvider {
}

// TODO: Re-enable if it's needed
//await clearBuffer(true);
// await clearBuffer(true);
await del([path.join(bufferDir, ".git")], { force: true });

return true;
Expand Down

0 comments on commit 59e954e

Please sign in to comment.