Browse Source

setup prettier (not applied until closer to merge)

Hakim El Hattab 6 months ago
parent
commit
294d7c2486
10 changed files with 732 additions and 523 deletions
  1. 3 0
      .prettierignore
  2. 8 0
      .prettierrc
  3. 4 4
      index.html
  4. 642 453
      js/config.ts
  5. 17 15
      js/index.ts
  6. 1 1
      js/reveal.js
  7. 0 3
      package.json
  8. 37 26
      test.js
  9. 9 7
      vite.config.styles.ts
  10. 11 14
      vite.config.ts

+ 3 - 0
.prettierignore

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

+ 8 - 0
.prettierrc

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

+ 4 - 4
index.html

@@ -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
+ 642 - 453
js/config.ts


+ 17 - 15
js/index.ts

@@ -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 ) );
+	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,14 +50,16 @@ 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 => {
-	Reveal[method] = ( ...args: any ) => {
-		enqueuedAPICalls.push( deck => deck[method].call( null, ...args ) );
+['configure', 'on', 'off', 'addEventListener', 'removeEventListener', 'registerPlugin'].forEach(
+	(method) => {
+		Reveal[method] = (...args: any) => {
+			enqueuedAPICalls.push((deck) => deck[method].call(null, ...args));
+		};
 	}
-} );
+);
 
 Reveal.isReady = () => false;
 
 Reveal.VERSION = VERSION;
 
-export default Reveal;
+export default Reveal;

+ 1 - 1
js/reveal.js

@@ -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 {

+ 0 - 3
package.json

@@ -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",

+ 37 - 26
test.js

@@ -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,34 +25,45 @@ const startServer = async () => {
 
 // Run tests
 const runTests = async (server) => {
-  await Promise.all(testFiles.map(async (file) => {
-    const qunitArgs = {
-      targetUrl: `http://localhost:8009/${file}`,
-      timeout: 30000,
-      redirectConsole: false,
-      puppeteerArgs: ['--allow-file-access-from-files']
-    };
+  await Promise.all(
+    testFiles.map(async (file) => {
+      const qunitArgs = {
+        targetUrl: `http://localhost:8009/${file}`,
+        timeout: 30000,
+        redirectConsole: false,
+        puppeteerArgs: ['--allow-file-access-from-files'],
+      };
 
-    try {
-      const result = await runQunitPuppeteer(qunitArgs);
-      combinedResults.passed += result.stats.passed;
-      combinedResults.failed += result.stats.failed;
-      combinedResults.total += result.stats.total;
-      combinedResults.runtime += result.stats.runtime;
+      try {
+        const result = await runQunitPuppeteer(qunitArgs);
+        combinedResults.passed += result.stats.passed;
+        combinedResults.failed += result.stats.failed;
+        combinedResults.total += result.stats.total;
+        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);
-        printFailedTests(result, console);
+        if (result.stats.failed > 0) {
+          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
+          );
+        }
+      } catch (error) {
+        console.error(`Error running tests for ${file}:`, error);
       }
-      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);

+ 9 - 7
vite.config.styles.ts

@@ -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: [],
-})
+});

+ 11 - 14
vite.config.ts

@@ -1,31 +1,30 @@
-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' ) {
+export const appendExtension = (format: ModuleFormat, name: String): string => {
+  if (format === 'es') {
     return `${name}.mjs`;
-  }
-  else {
+  } else {
     return `${name}.js`;
   }
-}
+};
 
 export default defineConfig({
   build: {
     emptyOutDir: true,
     lib: {
       formats: ['es', 'umd'],
-      entry:  resolve(__dirname, 'js/index.ts'),
+      entry: resolve(__dirname, 'js/index.ts'),
       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 })],
+});

Some files were not shown because too many files changed in this diff