Skip to content

Commit

Permalink
Move copy build step to js script
Browse files Browse the repository at this point in the history
  • Loading branch information
danyeaw committed Jan 28, 2025
1 parent 0491c01 commit 6a2443d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
"url": "https://github.com/jupyter/nbclassic.git"
},
"scripts": {
"bower:cp-umd": "cp nbclassic/static/components/marked/lib/marked.umd.js nbclassic/static/components/marked/lib/marked.js",
"bower:copy-umd": "copy nbclassic/static/components/marked/lib/marked.umd.js nbclassic/static/components/marked/lib/marked.js",
"bower": "bower install && (npm run bower:cp-umd || npm run bower:copy-umd)",
"bower:copy-marked": "node tools/copy-marked.js",
"bower": "bower install && npm run bower:copy-marked",
"build:webpack": "webpack --mode production",
"build:notebook": "node tools/build-main.js notebook",
"build:tree": "node tools/build-main.js tree",
Expand Down
28 changes: 28 additions & 0 deletions tools/copy-marked.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const fs = require('fs');
const path = require('path');

const sourceFile = path.join('nbclassic', 'static', 'components', 'marked', 'lib', 'marked.umd.js');
const destFile = path.join('nbclassic', 'static', 'components', 'marked', 'lib', 'marked.js');

// Check file existence
const sourceExists = fs.existsSync(sourceFile);
const destExists = fs.existsSync(destFile);

if (!sourceExists && !destExists) {
// Both files missing - critical error
console.error(`Error: ${destFile} is required but cannot be created (${sourceFile} not found)`);
process.exit(1);
} else if (!sourceExists) {
// Source missing but dest exists - skip copy
console.log(`Copy skipped: ${sourceFile} not found (using existing ${destFile})`);
process.exit(0);
}

// Source exists, attempt copy
try {
fs.copyFileSync(sourceFile, destFile);
console.log(`Successfully copied ${sourceFile} to ${destFile}`);
} catch (err) {
console.error(`Error copying file: ${err.message}`);
process.exit(1);
}

0 comments on commit 6a2443d

Please sign in to comment.