Skip to content

Commit

Permalink
Code to download iris jsapi (#79) (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmingles committed Aug 6, 2024
1 parent dbae513 commit 4476297
Show file tree
Hide file tree
Showing 6 changed files with 1,455 additions and 12 deletions.
17 changes: 7 additions & 10 deletions src/dh/dhc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
getTempDir,
NoConsoleTypesError,
polyfillDh,
urlToDirectoryName,
} from '../util';
import { ConnectionAndSession } from '../common';

Expand All @@ -32,12 +33,7 @@ export function getEmbedWidgetUrl(

export async function initDhcApi(serverUrl: string): Promise<typeof DhType> {
polyfillDh();

const tempDir = getTempDir();

const dhc = await getDhc(serverUrl, tempDir, true);

return dhc;
return getDhc(serverUrl, true);
}

export async function initDhcSession(
Expand Down Expand Up @@ -71,16 +67,17 @@ export async function initDhcSession(
*/
async function getDhc(
serverUrl: string,
outDir: string,
download: boolean
): Promise<typeof DhType> {
const tmpDir = getTempDir(false, urlToDirectoryName(serverUrl));

if (download) {
const dhInternal = await downloadFromURL(
path.join(serverUrl, 'jsapi/dh-internal.js')
);
// Convert to .cjs
fs.writeFileSync(
path.join(outDir, 'dh-internal.cjs'),
path.join(tmpDir, 'dh-internal.cjs'),
dhInternal.replace(
`export{__webpack_exports__dhinternal as dhinternal};`,
`module.exports={dhinternal:__webpack_exports__dhinternal};`
Expand All @@ -91,7 +88,7 @@ async function getDhc(
path.join(serverUrl, 'jsapi/dh-core.js')
);
fs.writeFileSync(
path.join(outDir, 'dh-core.cjs'),
path.join(tmpDir, 'dh-core.cjs'),
// Convert to .cjs
dhCore
.replace(
Expand All @@ -102,5 +99,5 @@ async function getDhc(
);
}

return require(path.join(outDir, 'dh-core.cjs'));
return require(path.join(tmpDir, 'dh-core.cjs'));
}
Loading

0 comments on commit 4476297

Please sign in to comment.