Skip to content

Commit

Permalink
Build update
Browse files Browse the repository at this point in the history
  • Loading branch information
hodgef committed Apr 28, 2024
1 parent 1b69c0d commit b88d5c5
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 18 deletions.
3 changes: 2 additions & 1 deletion src/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ export const runCommand = (dir, cmd) => {
if (!dir) throw new Error("Working dir must be provided.");

try {
const res = execSync(`cd ${dir} && ${cmd}`).toString();
execSync(`cd ${dir}`);
const res = execSync(cmd).toString();
if (isDevelopment) {
console.log("runCommand", cmd, res);
}
Expand Down
8 changes: 4 additions & 4 deletions src/renderer/components/Loader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import React, { FunctionComponent, useRef } from "react";
import { initConfig, initStore, initDb, initExpress } 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 win = remote.getCurrentWindow();
const openDevTools = remote.getGlobal("openDevTools");

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

React.useEffect(() => {
//openDevTools();
openDevTools();
const init = async () => {
setLoadingText("Initializing Storage");
await initStore();
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
13 changes: 7 additions & 6 deletions src/renderer/services/providers/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ class GithubProvider {
onUpdate,
itemIdToDeploy,
!clearRemote,
generateSiteMap
generateSiteMap,
"deploy"
);

if (!buildRes) {
Expand All @@ -225,11 +226,11 @@ class GithubProvider {

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

runCommand(bufferDir, "git config --global core.safecrlf false");
runCommand(bufferDir, "git add --all");
runCommand(bufferDir, `git commit -m "${commitMessage}"`);
const { res: e, error: commitError } = runCommand(bufferDir, "git push --force");
if (commitError) {
modal.alert(e.message, null, null, null, `commit_error: ${repositoryUrl}`);
console.error(e);
Expand Down

0 comments on commit b88d5c5

Please sign in to comment.