Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🪐 Improve thebe bundling #123

Merged
merged 11 commits into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/quick-sheep-prove.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@myst-theme/jupyter': patch
'@myst-theme/site': patch
---

upgraded to thebe 0.2.2
60 changes: 60 additions & 0 deletions bin/copy-thebe-assets.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
const fs = require('fs');
const path = require('path');
const { globSync } = require('glob');

if (process.argv.length < 3) {
console.error('Usage: node copyThebeAssets.cjs <output_dir>');
process.exit(1);
}

const outputDir = process.argv[2];

if (!fs.existsSync(outputDir)) {
console.log(`Output directory ${outputDir} does not exist, creating...`);
fs.mkdirSync(outputDir, { recursive: true });
}

console.log('Copying thebe assets...');

try {
require.resolve('thebe-core');
} catch (err) {
console.error('thebe-core not found, please run `npm install` in the theme directory.');
process.exit(1);
}

try {
require.resolve('thebe-lite');
} catch (err) {
console.error('thebe-lite not found, please run `npm install` in the theme directory.');
process.exit(1);
}

const pathToThebeCoreLibFolder = path.resolve(
path.dirname(require.resolve('thebe-core')),
'..',
'lib',
);
const thebeCoreFiles = globSync(path.join(pathToThebeCoreLibFolder, '*.js'));

const pathToThebeLite = path.dirname(require.resolve('thebe-lite'));
const thebeLiteFiles = globSync(path.join(pathToThebeLite, '*.js'));

const assets = [
...thebeCoreFiles,
path.join(pathToThebeCoreLibFolder, 'thebe-core.css'),
...thebeLiteFiles,
];

console.log('Found thebe assets:');
console.log(assets);
console.log(`Copying assets to ${outputDir} now...`);

for (const asset of assets) {
const basename = path.basename(asset);
const dest = path.join(outputDir, basename);
fs.copyFileSync(asset, dest);
console.log(`Copied ${basename} to ${dest}`);
}

console.log('Done.');
Loading