Skip to content

Commit

Permalink
Use commander for CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
alexkiro committed Dec 8, 2024
1 parent 5cca47b commit 6aa3be8
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 49 deletions.
57 changes: 22 additions & 35 deletions build/cli.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,31 @@
import { parseArgs } from "node:util";
import * as console from "node:console";
import { buildFlipForge } from "./build";
import { Command } from "commander";
import { version } from "../package.json";
import { buildFlipForge, type BuildOptions } from "./build";

function main() {
const { values, positionals } = parseArgs({
strict: true,
allowPositionals: true,
options: {
baseUrl: {
type: "string",
default: "",
},
fullUrl: {
type: "string",
default: "http://localhost:8080",
},
title: {
type: "string",
default: "",
},
description: {
type: "string",
default: "",
},
writeEnv: {
type: "boolean",
default: true,
},
},
});
const program = new Command();
program
.name("build-flip-forge")
.description("Build flip forge site from cmd line")
.version(version)
.argument("<pdfPath>", "PDF File to build site from")
.option("--base-url <value>", "Base url of the site", "")
.option("--full-url <value>", "Full url of the site", "")
.option("--title <value>", "Meta title of the site", "")
.option("--description <value>", "Meta description for the site", "")
.option("--write-env", "", false)
.allowExcessArguments(false);
program.parse();

if (positionals.length !== 1) {
console.error("One file must be specified, got:", positionals);
process.exit(1);
}
const [pdfPath] = program.processedArgs;
const options = program.opts();

console.log(options);
buildFlipForge({
pdfPath: positionals[0],
...values,
});
pdfPath,
...options,
} as BuildOptions);
}

main();
27 changes: 14 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"dev": "vite",
"build": "run-p type-check \"build-only {@}\" --",
"build-action": "tsx ./build/action.ts",
"build-test": "tsx ./build/cli.ts --title='Lorem Ipsum' --description='Test description' --writeEnv test/lorem_ipsum.pdf",
"build-test": "tsx ./build/cli.ts --title='Lorem Ipsum' --description='Test description' --write-env test/lorem_ipsum.pdf",
"preview": "vite preview",
"test:unit": "vitest",
"test:e2e": "start-server-and-test preview http://localhost:4173 'cypress run --e2e'",
Expand Down Expand Up @@ -45,6 +45,7 @@
"@vue/eslint-config-prettier": "10.1.0",
"@vue/eslint-config-typescript": "14.1.3",
"@vue/test-utils": "2.4.6",
"commander": "12.1.0",
"cypress": "13.15.1",
"eslint": "9.14.0",
"eslint-plugin-cypress": "4.1.0",
Expand Down

0 comments on commit 6aa3be8

Please sign in to comment.