Skip to content

Commit

Permalink
Merge pull request #1 from makebrainwaves/dano-pyodide-install
Browse files Browse the repository at this point in the history
Automatic pyodide installation
  • Loading branch information
teonbrooks authored Jul 8, 2019
2 parents 4f3a341 + 99fa39f commit 0bf341c
Show file tree
Hide file tree
Showing 4 changed files with 310 additions and 514 deletions.
10 changes: 5 additions & 5 deletions app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

66 changes: 66 additions & 0 deletions internals/scripts/InstallPyodide.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// mkdir app/utils/pyodide/src
// && cd app/utils/pyodide/src
// curl -LJO https://github.com/iodide-project/pyodide/releases/download/0.12.0/pyodide-build-0.12.0.tar.bz2
// tar xjf pyodide-build-0.12.0.tar.bz2
// rm pyodide-build-0.12.0.tar.bz2",

import chalk from 'chalk';
import fs from 'fs';
import https from 'https';
import mkdirp from 'mkdirp';
import tar from 'tar-fs';
import url from 'url';
import bz2 from 'unbzip2-stream';

const PYODIDE_VERSION = '0.12.0';
const TAR_NAME = `pyodide-build-${PYODIDE_VERSION}.tar.bz2`;
const TAR_URL = `https://github.com/iodide-project/pyodide/releases/download/${PYODIDE_VERSION}/pyodide-build-${PYODIDE_VERSION}.tar.bz2`;
const PYODIDE_DIR = 'app/utils/pyodide/src/';

const writeAndUnzipFile = response => {
const filePath = `${PYODIDE_DIR}${TAR_NAME}`;
const writeStream = fs.createWriteStream(filePath);
response.pipe(writeStream);

writeStream.on('finish', () => {
console.log(`${chalk.green.bold(`Unzipping pyodide`)}`);

const readStream = fs.createReadStream(filePath);
try {
readStream.pipe(bz2()).pipe(tar.extract(PYODIDE_DIR));
} catch (e) {
throw new Error('Error in unzip:', e);
}

readStream.on('end', () => {
console.log(`${chalk.green.bold(`Unzip successful`)}`);
});
});
};

const downloadFile = response => {
if (
response.statusCode > 300 &&
response.statusCode < 400 &&
response.headers.location
) {
if (url.parse(response.headers.location).hostname) {
https.get(response.headers.location, writeAndUnzipFile);
} else {
https.get(
url.resolve(url.parse(TAR_URL).hostname, response.headers.location),
writeAndUnzipFile
);
}
} else {
writeAndUnzipFile(response);
}
};

(() => {
console.log(
`${chalk.green.bold(`Downloading pyodide ${PYODIDE_VERSION}...`)}`
);
mkdirp.sync(`app/utils/pyodide/src`);
https.get(TAR_URL, downloadFile);
})();
Loading

0 comments on commit 0bf341c

Please sign in to comment.