diff --git a/src/common/utils.ts b/src/common/utils.ts index 1db881f..d253be4 100644 --- a/src/common/utils.ts +++ b/src/common/utils.ts @@ -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); } diff --git a/src/renderer/components/Loader.tsx b/src/renderer/components/Loader.tsx index 42f4697..d5c44e4 100644 --- a/src/renderer/components/Loader.tsx +++ b/src/renderer/components/Loader.tsx @@ -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>(null); @@ -24,7 +24,7 @@ const Loader: FunctionComponent = () => { }; React.useEffect(() => { - //openDevTools(); + openDevTools(); const init = async () => { setLoadingText("Initializing Storage"); await initStore(); diff --git a/src/renderer/services/build.ts b/src/renderer/services/build.ts index 2a50ca8..f5e7f32 100644 --- a/src/renderer/services/build.ts +++ b/src/renderer/services/build.ts @@ -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()"); @@ -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 @@ -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; @@ -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 => { const site = typeof siteUUIDOrSite === "string" @@ -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 || "") + diff --git a/src/renderer/services/providers/github.ts b/src/renderer/services/providers/github.ts index a5a1fee..e01e40e 100644 --- a/src/renderer/services/providers/github.ts +++ b/src/renderer/services/providers/github.ts @@ -213,7 +213,8 @@ class GithubProvider { onUpdate, itemIdToDeploy, !clearRemote, - generateSiteMap + generateSiteMap, + "deploy" ); if (!buildRes) { @@ -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);