Skip to content

Commit

Permalink
fix(Deploy): fix deploy for runtime languages with code in custom scr…
Browse files Browse the repository at this point in the history
…ipt block (use single file)
  • Loading branch information
hatemhosny committed Mar 22, 2024
1 parent c13944e commit 6caf303
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/livecodes/UI/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import type { createEventsManager } from '../events';
import type { createModal } from '../modal';
import type { createNotifications } from '../notifications';
import type { Config, ContentConfig, Cache, User } from '../models';
import type { getLanguageExtension as getLanguageExtensionFn } from '../languages';
import type {
getLanguageCompiler as getLanguageCompilerFn,
getLanguageExtension as getLanguageExtensionFn,
} from '../languages';
import { deployScreen, resultTemplate } from '../html';
import { autoCompleteUrl } from '../vendors';
import { deploy, deployFile, deployedConfirmation } from '../deploy';
Expand Down Expand Up @@ -84,6 +87,7 @@ export const createDeployUI = async ({
getConfig: () => Config;
getContentConfig: (config: Config | ContentConfig) => ContentConfig;
getLanguageExtension: typeof getLanguageExtensionFn;
getLanguageCompiler: typeof getLanguageCompilerFn;
setProjectDeployRepo: (repo: string) => Promise<void>;
};
}) => {
Expand All @@ -109,7 +113,8 @@ export const createDeployUI = async ({
newRepo: boolean,
) => {
const forExport = true;
const singleFile = false;
const scriptType = deps.getLanguageCompiler(deps.getConfig().script.language)?.scriptType;
const singleFile = scriptType != null && scriptType !== 'module';
newRepoNameError.innerHTML = '';

const resultHtml = await deps.getResultPage({
Expand Down
5 changes: 5 additions & 0 deletions src/livecodes/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,10 @@ const getResultPage = async ({
},
};

if (scriptType != null && scriptType !== 'module') {
singleFile = true;
}

const result = await createResultPage({
code: compiledCode,
config,
Expand Down Expand Up @@ -2764,6 +2768,7 @@ const handleDeploy = () => {
getConfig,
getContentConfig,
getLanguageExtension,
getLanguageCompiler,
setProjectDeployRepo,
},
});
Expand Down
3 changes: 3 additions & 0 deletions src/livecodes/result/result-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ export const createResultPage = async ({
// if export => clean, else => add utils
if (forExport) {
dom.querySelector('script')?.remove();
const utilsScript = dom.createElement('script');
utilsScript.innerHTML = 'window.livecodes = window.livecodes || {};';
dom.head.appendChild(utilsScript);
} else {
const utilsScript = dom.createElement('script');
utilsScript.src = absoluteBaseUrl + '{{hash:result-utils.js}}';
Expand Down

0 comments on commit 6caf303

Please sign in to comment.