Skip to content

Commit

Permalink
Explicitly declare each build task
Browse files Browse the repository at this point in the history
  • Loading branch information
danyeaw committed Feb 11, 2025
1 parent 95c074e commit 1c876b0
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 22 deletions.
29 changes: 18 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,24 @@
"type": "git",
"url": "https://github.com/jupyter/nbclassic.git"
},
"scripts": {
"bower:copy-marked": "node tools/copy-marked.js",
"bower": "bower install && npm run bower:copy-marked",
"build": "npm run bower && node tools/build.js",
"build:clean": "node tools/build.js clean",
"build:webpack": "node tools/build.js webpack",
"build:notebook": "node tools/build.js notebook",
"build:css": "node tools/build.js ipythonCss && node tools/build.js styleCss",
"build:translations": "node tools/build.js translations",
"watch": "npm-run-all --parallel watch:*"
},
"scripts": {
"bower:copy-marked": "node tools/copy-marked.js",
"bower": "bower install && npm run bower:copy-marked",
"build:webpack": "node tools/build.js webpack",
"build:notebook": "node tools/build.js notebook",
"build:tree": "node tools/build.js tree",
"build:edit": "node tools/build.js edit",
"build:terminal": "node tools/build.js terminal",
"build:auth": "node tools/build.js auth",
"build:translations": "node tools/build.js translations",
"build:js": "npm run build:notebook && npm run build:tree && npm run build:edit && npm run build:terminal && npm run build:auth && npm run build:translations",
"build:css": "node tools/build.js ipythonCss && node tools/build.js styleCss",
"build": "npm run bower && npm run build:webpack && npm run build:js && npm run build:css",
"build:clean": "node tools/build.js clean",
"watch:css": "onchange 'nbclassic/static/**/*.less' -- npm run build:css",
"watch:js": "onchange 'nbclassic/static/**/!(*.min).js' 'bower.json' -- npm run build:js",
"watch": "npm-run-all --parallel watch:*"
},
"devDependencies": {
"@babel/core": "^7.15.0",
"@babel/preset-env": "^7.15.0",
Expand Down
46 changes: 35 additions & 11 deletions tools/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,22 @@ const tasks = {
output: 'nbclassic/static/notebook/js/main.min.js',
command: ['node', 'tools/build-main.js', 'notebook'],
},
tree: {
output: 'nbclassic/static/tree/js/main.min.js',
command: ['node', 'tools/build-main.js', 'tree'],
},
edit: {
output: 'nbclassic/static/edit/js/main.min.js',
command: ['node', 'tools/build-main.js', 'edit'],
},
terminal: {
output: 'nbclassic/static/terminal/js/main.min.js',
command: ['node', 'tools/build-main.js', 'terminal'],
},
auth: {
output: 'nbclassic/static/auth/js/main.min.js',
command: ['node', 'tools/build-main.js', 'auth'],
},
ipythonCss: {
output: 'nbclassic/static/style/ipython.min.css',
command: ['lessc', '--source-map', '--include-path=nbclassic/static/style',
Expand All @@ -31,13 +47,11 @@ const tasks = {
const langPath = lang.includes('_') ? lang : lang;
const input = `nbclassic/i18n/${langPath}/LC_MESSAGES/nbjs.po`;
const output = `nbclassic/i18n/${langPath}/LC_MESSAGES/nbjs.json`;

console.log(`Building translation for ${lang}...`);
const proc = spawn('po2json', [
'-p', '-F', '-f', 'jed1.x', '-d', 'nbjs',
input, output
], { stdio: 'inherit' });

await new Promise((resolve, reject) => {
proc.on('close', code => {
if (code === 0) resolve();
Expand All @@ -54,7 +68,6 @@ async function runTask(taskName) {
if (!task) {
throw new Error(`Unknown task: ${taskName}`);
}

console.log(`Building ${taskName}...`);
if (task.buildFn) {
await task.buildFn();
Expand Down Expand Up @@ -87,15 +100,26 @@ async function clean() {
}
}

// Define the build order explicitly
const buildOrder = [
'webpack',
'notebook',
'tree',
'edit',
'terminal',
'auth',
'translations',
'ipythonCss',
'styleCss'
];

async function runAll() {
for (const taskName of Object.keys(tasks)) {
if (taskName !== 'bower') {
try {
await runTask(taskName);
} catch (err) {
console.error(`Error in task ${taskName}:`, err);
process.exit(1);
}
for (const taskName of buildOrder) {
try {
await runTask(taskName);
} catch (err) {
console.error(`Error in task ${taskName}:`, err);
process.exit(1);
}
}
}
Expand Down

0 comments on commit 1c876b0

Please sign in to comment.