From d1dbf6f65a3b95d875a09af0d7c27e9c9118b7eb Mon Sep 17 00:00:00 2001 From: Glenn Rice Date: Wed, 10 Jan 2024 22:23:44 -0600 Subject: [PATCH] Apply prettier to all JavaScript, style, and HTML files in htdocs. --- htdocs/css/rtl.css | 1 - htdocs/generate-assets.js | 85 +- htdocs/index.dist.html | 8 +- htdocs/js/DatePicker/datepicker.js | 10 +- htdocs/js/GatewayQuiz/gateway.js | 60 +- htdocs/js/InstructorTools/instructortools.js | 22 +- htdocs/js/LocalStorage/localstorage.js | 5 +- htdocs/js/MathJaxConfig/mathjax-config.js | 144 +- htdocs/js/PGCodeMirror/PG.js | 2322 +++++++++-------- htdocs/js/PGCodeMirror/comment.js | 172 +- htdocs/js/PGCodeMirror/pgeditor.js | 28 +- htdocs/js/PGProblemEditor/pgproblemeditor.js | 288 +- htdocs/js/Problem/problem.js | 4 +- htdocs/js/ProblemGrader/problemgrader.js | 16 +- .../js/ProblemSetDetail/problemsetdetail.js | 345 ++- htdocs/js/RenderProblem/renderproblem.js | 148 +- htdocs/js/SampleProblemViewer/viewer.js | 4 +- htdocs/js/SelectAll/selectall.js | 20 +- htdocs/js/SetMaker/setmaker.js | 143 +- htdocs/js/UserDetail/userdetail.js | 40 +- htdocs/themes/math4-green/_theme-colors.scss | 2 +- htdocs/themes/math4-red/_theme-colors.scss | 2 +- htdocs/themes/math4-red/_theme-overrides.scss | 3 +- htdocs/themes/math4-yellow/_theme-colors.scss | 12 +- .../themes/math4-yellow/_theme-overrides.scss | 36 +- htdocs/themes/math4/_theme-colors.scss | 4 +- htdocs/themes/math4/achievements.scss | 4 +- htdocs/themes/math4/bootstrap.scss | 82 +- htdocs/themes/math4/gateway.scss | 20 +- htdocs/themes/math4/math4.js | 45 +- htdocs/themes/math4/math4.scss | 92 +- 31 files changed, 2300 insertions(+), 1867 deletions(-) diff --git a/htdocs/css/rtl.css b/htdocs/css/rtl.css index 95691f2401..8a2379a99c 100644 --- a/htdocs/css/rtl.css +++ b/htdocs/css/rtl.css @@ -17,4 +17,3 @@ /* The changes which were needed here in WeBWorK 2.16 are no * longer needed in WeBWorK 2.17. The file is being retained * for potential future use. */ - diff --git a/htdocs/generate-assets.js b/htdocs/generate-assets.js index 5f275e266f..81ee6c7b10 100755 --- a/htdocs/generate-assets.js +++ b/htdocs/generate-assets.js @@ -15,7 +15,10 @@ const rtlcss = require('rtlcss'); const cssMinify = require('cssnano'); const argv = yargs - .usage('$0 Options').version(false).alias('help', 'h').wrap(100) + .usage('$0 Options') + .version(false) + .alias('help', 'h') + .wrap(100) .option('enable-sourcemaps', { alias: 's', description: 'Generate source maps. (Not for use in production!)', @@ -30,8 +33,7 @@ const argv = yargs alias: 'd', description: 'Delete all generated files.', type: 'boolean' - }) - .argv; + }).argv; const assetFile = path.resolve(__dirname, 'static-assets.json'); const assets = {}; @@ -48,7 +50,7 @@ const cleanDir = (dir) => { } } } -} +}; // The is set to true after all files are processed for the first time. let ready = false; @@ -75,12 +77,13 @@ const processFile = async (file, _details) => { return; } - const minJS = result.code + ( - argv.enableSourcemaps && result.map - ? `//# sourceMappingURL=data:application/json;charset=utf-8;base64,${ - Buffer.from(result.map).toString('base64')}` - : '' - ); + const minJS = + result.code + + (argv.enableSourcemaps && result.map + ? `//# sourceMappingURL=data:application/json;charset=utf-8;base64,${Buffer.from( + result.map + ).toString('base64')}` + : ''); const contentHash = crypto.createHash('sha256'); contentHash.update(minJS); @@ -114,18 +117,19 @@ const processFile = async (file, _details) => { return; } - if (result.sourceMap) result.sourceMap.sources = [ baseName ]; + if (result.sourceMap) result.sourceMap.sources = [baseName]; // Pass the compiled css through the autoprefixer. // This is really only needed for the bootstrap.css files, but doesn't hurt for the rest. let prefixedResult = await postcss([autoprefixer, cssMinify]).process(result.css, { from: baseName }); - const minCSS = prefixedResult.css + ( - argv.enableSourcemaps && result.sourceMap - ? `/*# sourceMappingURL=data:application/json;charset=utf-8;base64,${ - Buffer.from(JSON.stringify(result.sourceMap)).toString('base64')}*/` - : '' - ); + const minCSS = + prefixedResult.css + + (argv.enableSourcemaps && result.sourceMap + ? `/*# sourceMappingURL=data:application/json;charset=utf-8;base64,${Buffer.from( + JSON.stringify(result.sourceMap) + ).toString('base64')}*/` + : ''); const contentHash = crypto.createHash('sha256'); contentHash.update(minCSS); @@ -149,18 +153,21 @@ const processFile = async (file, _details) => { // Pass the compiled css through rtlcss and autoprefixer to generate css for right-to-left languages. let rtlResult = await postcss([rtlcss, autoprefixer, cssMinify]).process(result.css, { from: baseName }); - const rtlCSS = rtlResult.css + ( - argv.enableSourcemaps && result.sourceMap - ? `/*# sourceMappingURL=data:application/json;charset=utf-8;base64,${ - Buffer.from(JSON.stringify(result.sourceMap)).toString('base64')}*/` - : '' - ); + const rtlCSS = + rtlResult.css + + (argv.enableSourcemaps && result.sourceMap + ? `/*# sourceMappingURL=data:application/json;charset=utf-8;base64,${Buffer.from( + JSON.stringify(result.sourceMap) + ).toString('base64')}*/` + : ''); const rtlContentHash = crypto.createHash('sha256'); rtlContentHash.update(rtlCSS); - const newRTLVersion = file.replace(/\.s?css$/, - `.rtl.${rtlContentHash.digest('hex').substring(0, 8)}.min.css`); + const newRTLVersion = file.replace( + /\.s?css$/, + `.rtl.${rtlContentHash.digest('hex').substring(0, 8)}.min.css` + ); fs.writeFileSync(path.resolve(__dirname, newRTLVersion), rtlCSS); const rtlAssetName = file.replace(/\.s?css$/, '.rtl.css'); @@ -180,8 +187,9 @@ const processFile = async (file, _details) => { } } else { if (argv.watchFiles) - console.log('\x1b[33mWatches established, and initial build complete.\n' - + 'Press Control-C to stop.\x1b[0m'); + console.log( + '\x1b[33mWatches established, and initial build complete.\n' + 'Press Control-C to stop.\x1b[0m' + ); ready = true; } @@ -202,20 +210,25 @@ for (const file of fs.readdirSync(themesDir, { withFileTypes: true })) { if (!file.isDirectory()) continue; if (!fs.existsSync(path.resolve(themesDir, file.name, 'math4-overrides.js'))) fs.closeSync(fs.openSync(path.resolve(themesDir, file.name, 'math4-overrides.js'), 'w')); - if (!fs.existsSync(path.resolve(themesDir, file.name, 'math4-overrides.css')) - && !fs.existsSync(path.resolve(themesDir, file.name, 'math4-overrides.scss'))) + if ( + !fs.existsSync(path.resolve(themesDir, file.name, 'math4-overrides.css')) && + !fs.existsSync(path.resolve(themesDir, file.name, 'math4-overrides.scss')) + ) fs.closeSync(fs.openSync(path.resolve(themesDir, file.name, 'math4-overrides.css'), 'w')); } // Set up the watcher. if (argv.watchFiles) console.log('\x1b[32mEstablishing watches and performing initial build.\x1b[0m'); -chokidar.watch(['js', 'themes'], { - ignored: /layouts|\.min\.(js|css)$/, - cwd: __dirname, // Make sure all paths are given relative to the htdocs directory. - awaitWriteFinish: { stabilityThreshold: 500 }, - persistent: argv.watchFiles ? true : false -}) - .on('add', processFile).on('change', processFile).on('ready', processFile) +chokidar + .watch(['js', 'themes'], { + ignored: /layouts|\.min\.(js|css)$/, + cwd: __dirname, // Make sure all paths are given relative to the htdocs directory. + awaitWriteFinish: { stabilityThreshold: 500 }, + persistent: argv.watchFiles ? true : false + }) + .on('add', processFile) + .on('change', processFile) + .on('ready', processFile) .on('unlink', (file) => { // If a file is deleted, then also delete the corresponding generated file. if (assets[file]) { diff --git a/htdocs/index.dist.html b/htdocs/index.dist.html index 532c6f4032..a82efd7355 100644 --- a/htdocs/index.dist.html +++ b/htdocs/index.dist.html @@ -1,4 +1,4 @@ - + WeBWorK Placeholder Page @@ -6,12 +6,10 @@

WeBWorK Placeholder Page

Exploring?

-

- This is the default page for the root url of this site. -

+

This is the default page for the root url of this site.

If you want to see something better here, then copy webwork2/htdocs/index.dist.html (this file) to - webwork/htdocs/index.html, and modify it to show what you want to show. Then that file will be displayed + webwork/htdocs/index.html, and modify it to show what you want to show. Then that file will be displayed instead.

diff --git a/htdocs/js/DatePicker/datepicker.js b/htdocs/js/DatePicker/datepicker.js index bdaef40623..3cbe63dfc6 100644 --- a/htdocs/js/DatePicker/datepicker.js +++ b/htdocs/js/DatePicker/datepicker.js @@ -50,11 +50,11 @@ // Compute the time difference between the current browser timezone and the course timezone. // flatpickr gives the time in the browser's timezone, and this is used to adjust to the course timezone. // Note that this is in seconds. - const timezoneAdjustment = ( - (new Date((new Date).toLocaleString('en-US'))).getTime() - - (new Date((new Date).toLocaleString('en-US', - { timeZone: rule.dataset.timezone ?? 'America/New_York' }))).getTime() - ); + const timezoneAdjustment = + new Date(new Date().toLocaleString('en-US')).getTime() - + new Date( + new Date().toLocaleString('en-US', { timeZone: rule.dataset.timezone ?? 'America/New_York' }) + ).getTime(); const fp = flatpickr(rule.parentNode, { allowInput: true, diff --git a/htdocs/js/GatewayQuiz/gateway.js b/htdocs/js/GatewayQuiz/gateway.js index 09f97d2c63..26ddd35fc1 100644 --- a/htdocs/js/GatewayQuiz/gateway.js +++ b/htdocs/js/GatewayQuiz/gateway.js @@ -12,9 +12,10 @@ const timerDiv = document.getElementById('gwTimer'); // The timer div element let actuallySubmit = false; // This needs to be set to true to allow an actual submission. // The 'Grade Test' submit button. - const submitAnswers = document.gwquiz.elements.submitAnswers instanceof NodeList - ? document.gwquiz.elements.submitAnswers[document.gwquiz.elements.submitAnswers.length - 1] - : document.gwquiz.elements.submitAnswers; + const submitAnswers = + document.gwquiz.elements.submitAnswers instanceof NodeList + ? document.gwquiz.elements.submitAnswers[document.gwquiz.elements.submitAnswers.length - 1] + : document.gwquiz.elements.submitAnswers; let timeDelta; // The difference between the browser time and the server time let serverDueTime; // The time the test is due let gracePeriod; // The grace period @@ -32,7 +33,14 @@ const alertToast = (message, delay = 5000) => { const toastContainer = document.createElement('div'); toastContainer.classList.add( - 'gwAlert', 'toast-container', 'position-fixed', 'top-0', 'start-50', 'translate-middle-x', 'p-3'); + 'gwAlert', + 'toast-container', + 'position-fixed', + 'top-0', + 'start-50', + 'translate-middle-x', + 'p-3' + ); toastContainer.innerHTML = '