From 65a70d64855f3d6217cada2b618ac806d9fdfa2a Mon Sep 17 00:00:00 2001 From: Florian Pichler Date: Fri, 9 Aug 2024 15:13:03 +0200 Subject: [PATCH 1/2] Replace custom args parsing with commander --- bin/auto-reveal.js | 26 ++++++++++++++++++++------ package.json | 7 ++++--- pnpm-lock.yaml | 9 +++++++++ 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/bin/auto-reveal.js b/bin/auto-reveal.js index ebb7f30..01bff4b 100755 --- a/bin/auto-reveal.js +++ b/bin/auto-reveal.js @@ -2,12 +2,12 @@ import path from 'node:path'; import { fileURLToPath } from 'node:url'; +import { Command } from 'commander'; import { build, createServer } from 'vite'; import { ViteEjsPlugin as viteEjsPlugin } from 'vite-plugin-ejs'; import { getTheme, getTitle } from '../lib/utils.js'; const __dirname = fileURLToPath(new URL('.', import.meta.url)); -const argv = process.argv.slice(2); const cwd = process.cwd(); const themeFolder = path.dirname(getTheme()); @@ -47,8 +47,22 @@ async function start() { server.bindCLIShortcuts({ print: true }); } -if (!argv[0] || argv[0] === 'start') { - start(); -} else if (argv[0] === 'build') { - build(config); -} +const program = new Command(); + +program.name(process.env.npm_package_name); +program.description(process.env.npm_package_description); +program.version(process.env.npm_package_version); + +program + .command('start', { + isDefault: true, + }) + .description('Live-reloading server for your slides.') + .action(start); + +program + .command('build') + .description('Build a static copy of your presentation.') + .action(() => build(config)); + +program.parse(); diff --git a/package.json b/package.json index 6816ec0..975629b 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { "name": "auto-reveal", "version": "0.2.1", - "description": "", - "keywords": [], + "description": "The command-line interface for reveal.js presentations.", + "keywords": ["reveal.js", "cli", "markdown"], "repository": { "type": "git", "url": "git@github.com:mainmatter/auto-reveal.git" @@ -15,11 +15,12 @@ "auto-reveal": "./bin/auto-reveal.js" }, "scripts": { - "format": "biome check --apply .", + "format": "biome check --write .", "lint": "biome check .", "test": "echo \"Error: no test specified\" && exit 1" }, "dependencies": { + "commander": "^12.1.0", "reveal.js": "5.1.0", "vite": "5.4.0", "vite-plugin-ejs": "1.7.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d8fa114..9599abd 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8,6 +8,9 @@ importers: .: dependencies: + commander: + specifier: ^12.1.0 + version: 12.1.0 reveal.js: specifier: 5.1.0 version: 5.1.0 @@ -545,6 +548,10 @@ packages: color-name@1.1.4: resolution: {integrity: sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==} + commander@12.1.0: + resolution: {integrity: sha512-Vw8qHK3bZM9y/P10u3Vib8o/DdkvA2OtPtZvD871QKjy74Wj1WSKFILMPRPSdUSx5RFK1arlJzEtA4PkFgnbuA==} + engines: {node: '>=18'} + concat-map@0.0.1: resolution: {integrity: sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==} @@ -1872,6 +1879,8 @@ snapshots: color-name@1.1.4: {} + commander@12.1.0: {} + concat-map@0.0.1: {} config-chain@1.1.13: From 0c465cb5d85ea3685e8226c2639ec6d99aeb0ce3 Mon Sep 17 00:00:00 2001 From: Florian Pichler Date: Fri, 9 Aug 2024 15:13:34 +0200 Subject: [PATCH 2/2] Add -o / --outDir option for output folder --- bin/auto-reveal.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/bin/auto-reveal.js b/bin/auto-reveal.js index 01bff4b..5748f29 100755 --- a/bin/auto-reveal.js +++ b/bin/auto-reveal.js @@ -63,6 +63,17 @@ program program .command('build') .description('Build a static copy of your presentation.') - .action(() => build(config)); + .option('-o, --outDir ', 'Output directory', config.build.outDir) + .action((options) => + build({ + ...config, + build: { + ...config.build, + outDir: options.outDir + ? path.resolve(cwd, options.outDir) + : config.build.outDir, + }, + }), + ); program.parse();