1
0
mirror of https://github.com/hakimel/reveal.js.git synced 2025-08-09 08:06:48 +02:00

setup prettier (not applied until closer to merge)

This commit is contained in:
Hakim El Hattab
2024-11-01 12:21:56 +01:00
parent 900bdd4686
commit 294d7c2486
10 changed files with 744 additions and 630 deletions

3
.prettierignore Normal file
View File

@@ -0,0 +1,3 @@
**/*
js/**/*.js
plugin/**/*.js

8
.prettierrc Normal file
View File

@@ -0,0 +1,8 @@
{
"useTabs": false,
"tabWidth": 2,
"trailingComma": "es5",
"printWidth": 100,
"singleQuote": true,
"bracketSameLine": false
}

View File

@@ -6,12 +6,12 @@
<title>reveal.js</title> <title>reveal.js</title>
<link rel="stylesheet" href="css/reset.css"> <link rel="stylesheet" href="css/reset.css" />
<link rel="stylesheet" href="css/reveal.scss"> <link rel="stylesheet" href="css/reveal.scss" />
<link rel="stylesheet" href="css/theme/black.scss"> <link rel="stylesheet" href="css/theme/black.scss" />
<!-- Theme used for syntax highlighted code --> <!-- Theme used for syntax highlighted code -->
<link rel="stylesheet" href="plugin/highlight/monokai.css"> <link rel="stylesheet" href="plugin/highlight/monokai.css" />
</head> </head>
<body> <body>
<div class="reveal"> <div class="reveal">

File diff suppressed because it is too large Load Diff

View File

@@ -1,7 +1,7 @@
import { PartialRevealConfig } from './config.js'; import { Config } from './config.ts';
//@ts-ignore //@ts-ignore
import Deck, { VERSION } from './reveal.js' import Deck, { VERSION } from './reveal.js';
/** /**
* Expose the Reveal class to the window. To create a * Expose the Reveal class to the window. To create a
@@ -13,8 +13,10 @@ import Deck, { VERSION } from './reveal.js'
* // reveal.js is ready * // reveal.js is ready
* }); * });
*/ */
let Reveal = Deck; let Reveal: {
initialize: (options?: Config) => Promise<void>;
[key: string]: any;
} = Deck;
/** /**
* The below is a thin shell that mimics the pre 4.0 * The below is a thin shell that mimics the pre 4.0
@@ -32,17 +34,15 @@ type RevealApiFunction = (...args: any[]) => any;
let enqueuedAPICalls: RevealApiFunction[] = []; let enqueuedAPICalls: RevealApiFunction[] = [];
Reveal.initialize = ( options: PartialRevealConfig ) => { Reveal.initialize = (options?: Config) => {
// Create our singleton reveal.js instance // Create our singleton reveal.js instance
Object.assign(Reveal, new Deck(document.querySelector('.reveal'), options)); Object.assign(Reveal, new Deck(document.querySelector('.reveal'), options));
// Invoke any enqueued API calls // Invoke any enqueued API calls
enqueuedAPICalls.map( method => method( Reveal ) ); enqueuedAPICalls.map((method) => method(Reveal));
return Reveal.initialize(); return Reveal.initialize();
};
}
/** /**
* The pre 4.0 API let you add event listener before * The pre 4.0 API let you add event listener before
@@ -50,11 +50,13 @@ Reveal.initialize = ( options: PartialRevealConfig ) => {
* queuing up premature API calls and invoking all * queuing up premature API calls and invoking all
* of them when Reveal.initialize is called. * of them when Reveal.initialize is called.
*/ */
[ 'configure', 'on', 'off', 'addEventListener', 'removeEventListener', 'registerPlugin' ].forEach( method => { ['configure', 'on', 'off', 'addEventListener', 'removeEventListener', 'registerPlugin'].forEach(
(method) => {
Reveal[method] = (...args: any) => { Reveal[method] = (...args: any) => {
enqueuedAPICalls.push( deck => deck[method].call( null, ...args ) ); enqueuedAPICalls.push((deck) => deck[method].call(null, ...args));
};
} }
} ); );
Reveal.isReady = () => false; Reveal.isReady = () => false;

View File

@@ -18,7 +18,7 @@ import Touch from './controllers/touch.js'
import Focus from './controllers/focus.js' import Focus from './controllers/focus.js'
import Notes from './controllers/notes.js' import Notes from './controllers/notes.js'
import Playback from './components/playback.js' import Playback from './components/playback.js'
import defaultConfig from './config.ts' import { defaultConfig } from './config.ts'
import * as Util from './utils/util.js' import * as Util from './utils/util.js'
import * as Device from './utils/device.js' import * as Device from './utils/device.js'
import { import {

View File

@@ -15,12 +15,9 @@
"require": "./dist/reveal.js", "require": "./dist/reveal.js",
"default": "./dist/reveal.js" "default": "./dist/reveal.js"
}, },
"./reveal.css": "./dist/reveal.css", "./reveal.css": "./dist/reveal.css",
"./reset.css": "./dist/reset.css", "./reset.css": "./dist/reset.css",
"./theme/*": "./dist/theme/*", "./theme/*": "./dist/theme/*",
"./plugin/highlight": { "./plugin/highlight": {
"import": "./dist/plugin/highlight.mjs", "import": "./dist/plugin/highlight.mjs",
"require": "./dist/plugin/highlight.js", "require": "./dist/plugin/highlight.js",

31
test.js
View File

@@ -1,7 +1,7 @@
import { fileURLToPath } from 'url'; import { fileURLToPath } from 'url';
import { dirname } from 'path'; import { dirname } from 'path';
import { glob } from "glob"; import { glob } from 'glob';
import { runQunitPuppeteer, printFailedTests } from "node-qunit-puppeteer"; import { runQunitPuppeteer, printFailedTests } from 'node-qunit-puppeteer';
import { createServer } from 'vite'; import { createServer } from 'vite';
const __filename = fileURLToPath(import.meta.url); const __filename = fileURLToPath(import.meta.url);
@@ -25,12 +25,13 @@ const startServer = async () => {
// Run tests // Run tests
const runTests = async (server) => { const runTests = async (server) => {
await Promise.all(testFiles.map(async (file) => { await Promise.all(
testFiles.map(async (file) => {
const qunitArgs = { const qunitArgs = {
targetUrl: `http://localhost:8009/${file}`, targetUrl: `http://localhost:8009/${file}`,
timeout: 30000, timeout: 30000,
redirectConsole: false, redirectConsole: false,
puppeteerArgs: ['--allow-file-access-from-files'] puppeteerArgs: ['--allow-file-access-from-files'],
}; };
try { try {
@@ -41,18 +42,28 @@ const runTests = async (server) => {
combinedResults.runtime += result.stats.runtime; combinedResults.runtime += result.stats.runtime;
if (result.stats.failed > 0) { if (result.stats.failed > 0) {
console.log(`${'!'} ${file} [${result.stats.passed}/${result.stats.total}] in ${result.stats.runtime}ms`.red); console.log(
`${'!'} ${file} [${result.stats.passed}/${result.stats.total}] in ${
result.stats.runtime
}ms`.red
);
printFailedTests(result, console); printFailedTests(result, console);
} } else {
else { console.log(
console.log(`${'✔'} ${file} [${result.stats.passed}/${result.stats.total}] in ${result.stats.runtime}ms`.green); `${'✔'} ${file} [${result.stats.passed}/${result.stats.total}] in ${
result.stats.runtime
}ms`.green
);
} }
} catch (error) { } catch (error) {
console.error(`Error running tests for ${file}:`, error); console.error(`Error running tests for ${file}:`, error);
} }
})); })
);
console.log(`\n${combinedResults.passed}/${combinedResults.total} tests passed, ${combinedResults.failed} failed, ${combinedResults.runtime}ms runtime`); console.log(
`\n${combinedResults.passed}/${combinedResults.total} tests passed, ${combinedResults.failed} failed, ${combinedResults.runtime}ms runtime`
);
// Exit with status code 1 if any tests failed, otherwise exit with 0 // Exit with status code 1 if any tests failed, otherwise exit with 0
process.exit(combinedResults.failed > 0 ? 1 : 0); process.exit(combinedResults.failed > 0 ? 1 : 0);

View File

@@ -1,9 +1,11 @@
import { resolve } from 'path' import { resolve } from 'path';
import { defineConfig } from 'vite' import { defineConfig } from 'vite';
import fs from 'fs'; import fs from 'fs';
// List all theme files in the css/theme directory // List all theme files in the css/theme directory
const themeFiles = fs.readdirSync(resolve(__dirname, 'css/theme')).filter(file => file.endsWith('.scss')); const themeFiles = fs
.readdirSync(resolve(__dirname, 'css/theme'))
.filter((file) => file.endsWith('.scss'));
const themeEntries = themeFiles.reduce((acc, file) => { const themeEntries = themeFiles.reduce((acc, file) => {
acc[`theme/${file.replace('.scss', '')}`] = resolve(__dirname, `css/theme/${file}`); acc[`theme/${file.replace('.scss', '')}`] = resolve(__dirname, `css/theme/${file}`);
return acc; return acc;
@@ -17,12 +19,12 @@ export default defineConfig({
lib: { lib: {
formats: ['es'], formats: ['es'],
entry: { entry: {
'reveal': resolve(__dirname, 'css/reveal.scss'), reveal: resolve(__dirname, 'css/reveal.scss'),
'reset': resolve(__dirname, 'css/reset.css'), reset: resolve(__dirname, 'css/reset.css'),
...themeEntries, ...themeEntries,
}, },
} },
}, },
plugins: [], plugins: [],
}) });

View File

@@ -1,16 +1,15 @@
import { resolve } from 'path' import { resolve } from 'path';
import { ModuleFormat } from 'rollup'; import { ModuleFormat } from 'rollup';
import { defineConfig } from 'vite' import { defineConfig } from 'vite';
import dts from 'vite-plugin-dts'; import dts from 'vite-plugin-dts';
export const appendExtension = (format: ModuleFormat, name: String): string => { export const appendExtension = (format: ModuleFormat, name: String): string => {
if (format === 'es') { if (format === 'es') {
return `${name}.mjs`; return `${name}.mjs`;
} } else {
else {
return `${name}.js`; return `${name}.js`;
} }
} };
export default defineConfig({ export default defineConfig({
build: { build: {
@@ -21,11 +20,11 @@ export default defineConfig({
name: 'Reveal', name: 'Reveal',
fileName: (format, entryName) => { fileName: (format, entryName) => {
return appendExtension(format, 'reveal'); return appendExtension(format, 'reveal');
} },
}, },
rollupOptions: { rollupOptions: {
output: { output: {
assetFileNames: "reveal.[ext]", assetFileNames: 'reveal.[ext]',
}, },
}, },
}, },
@@ -36,7 +35,5 @@ export default defineConfig({
'reveal.js': '/js', 'reveal.js': '/js',
}, },
}, },
plugins: [ plugins: [dts({ insertTypesEntry: true, rollupTypes: true })],
dts({ insertTypesEntry: true }), });
],
})