Skip to content
This repository has been archived by the owner on Dec 1, 2022. It is now read-only.

Commit

Permalink
Kludgy fixes for embedding thick bundles (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
itowlson authored Dec 10, 2018
1 parent 6142011 commit e1240ef
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/components/Bundle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default class Bundle extends React.Component<Properties, State, {}> {
const embeddedBundle = await embedded.bundle;
const duffleBin = await findDuffleBinary(shell);
const bundleManifest = map(embeddedBundle, (b) => b.manifest);
const hasFullBundle = embedded.hasFullBundle();
const hasFullBundle = await embedded.hasFullBundle();
this.setState({
bundleManifest: { ready: true, result: bundleManifest },
duffle: { ready: true, result: duffleBin },
Expand Down
23 changes: 19 additions & 4 deletions app/utils/embedded.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import * as path from 'path';
import * as request from 'request-promise-native';

import { withTempFile, withBinaryTempFile } from "./tempfile";
import { BundleManifest } from './duffle.objectmodel';
import { failed, Errorable } from './errorable';
import { fs } from './fs';
import { extractTextFileFromTar } from './tar';

interface LoadedBundle {
Expand Down Expand Up @@ -36,7 +38,20 @@ function loadCNAB(): string | undefined {
}
}

function fullBundleURL(): string | undefined {
async function fullBundleURL(): Promise<string | undefined> {
const relPath = 'data/bundle.tgz';

if (!process.resourcesPath) {
return undefined;
}

const fullPath = path.join(process.resourcesPath, relPath);
if (await fs.exists(fullPath)) {
return fullPath;
}

// TODO: make above work in dev environment - or make the following work
// in package environment
try {
return require('../../data/bundle.tgz');
} catch {
Expand All @@ -45,16 +60,16 @@ function fullBundleURL(): string | undefined {
}

async function loadFullBundle(): Promise<{} | undefined> {
const bundleUrl = fullBundleURL();
const bundleUrl = await fullBundleURL();
if (!bundleUrl) {
return undefined;
}
const bundleContent = await request.get(bundleUrl, { encoding: null });
return bundleContent;
}

export function hasFullBundle(): boolean {
const url = fullBundleURL();
export async function hasFullBundle(): Promise<boolean> {
const url = await fullBundleURL();
return url !== undefined && url.length > 0;
}

Expand Down
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@
"buildResources": "resources",
"output": "release"
},
"extraResources": [
{
"from": "./data",
"to": "data"
}
],
"mac": {
"extraResources": [
{
Expand Down

0 comments on commit e1240ef

Please sign in to comment.