1
0
mirror of https://github.com/hakimel/reveal.js.git synced 2025-08-09 16:17:28 +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>
<link rel="stylesheet" href="css/reset.css">
<link rel="stylesheet" href="css/reveal.scss">
<link rel="stylesheet" href="css/theme/black.scss">
<link rel="stylesheet" href="css/reset.css" />
<link rel="stylesheet" href="css/reveal.scss" />
<link rel="stylesheet" href="css/theme/black.scss" />
<!-- Theme used for syntax highlighted code -->
<link rel="stylesheet" href="plugin/highlight/monokai.css">
<link rel="stylesheet" href="plugin/highlight/monokai.css" />
</head>
<body>
<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
import Deck, { VERSION } from './reveal.js'
import Deck, { VERSION } from './reveal.js';
/**
* Expose the Reveal class to the window. To create a
@@ -13,8 +13,10 @@ import Deck, { VERSION } from './reveal.js'
* // 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
@@ -32,17 +34,15 @@ type RevealApiFunction = (...args: any[]) => any;
let enqueuedAPICalls: RevealApiFunction[] = [];
Reveal.initialize = ( options: PartialRevealConfig ) => {
Reveal.initialize = (options?: Config) => {
// Create our singleton reveal.js instance
Object.assign(Reveal, new Deck(document.querySelector('.reveal'), options));
// Invoke any enqueued API calls
enqueuedAPICalls.map( method => method( Reveal ) );
enqueuedAPICalls.map((method) => method(Reveal));
return Reveal.initialize();
}
};
/**
* 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
* 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) => {
enqueuedAPICalls.push( deck => deck[method].call( null, ...args ) );
enqueuedAPICalls.push((deck) => deck[method].call(null, ...args));
};
}
} );
);
Reveal.isReady = () => false;

View File

@@ -18,7 +18,7 @@ import Touch from './controllers/touch.js'
import Focus from './controllers/focus.js'
import Notes from './controllers/notes.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 Device from './utils/device.js'
import {

View File

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

31
test.js
View File

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

View File

@@ -1,9 +1,11 @@
import { resolve } from 'path'
import { defineConfig } from 'vite'
import { resolve } from 'path';
import { defineConfig } from 'vite';
import fs from 'fs';
// 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) => {
acc[`theme/${file.replace('.scss', '')}`] = resolve(__dirname, `css/theme/${file}`);
return acc;
@@ -17,12 +19,12 @@ export default defineConfig({
lib: {
formats: ['es'],
entry: {
'reveal': resolve(__dirname, 'css/reveal.scss'),
'reset': resolve(__dirname, 'css/reset.css'),
reveal: resolve(__dirname, 'css/reveal.scss'),
reset: resolve(__dirname, 'css/reset.css'),
...themeEntries,
},
}
},
},
plugins: [],
})
});

View File

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