Skip to content

Commit

Permalink
Port the source code to TypeScript
Browse files Browse the repository at this point in the history
  • Loading branch information
cedx committed Jan 22, 2024
1 parent 7e92a18 commit 572500d
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 87 deletions.
50 changes: 23 additions & 27 deletions bin/mc2it_card.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@
"mc2it"
],
"scripts": {
"build": "tsc --project src/tsconfig.json",
"build": "tsc --project src/tsconfig.json && esbuild --allow-overwrite --bundle --format=esm --legal-comments=none --log-level=warning --minify --outfile=bin/mc2it_card.js --platform=node src/cli.ts",
"clean": "node tool/clean.js",
"dist": "npm run clean && npm run build",
"dist": "npm run clean && npm run build && node tool/dist.js && git update-index --chmod=+x bin/mc2it_card.js",
"doc": "typedoc --options etc/typedoc.json && node tool/doc.js",
"lint": "tsc --project tsconfig.json && eslint --config=etc/eslint.json src tool",
"postpublish": "node tool/publish.js",
"prepack": "npm run dist",
"start": "node bin/mc2it_card.js"
"start": "npm run build && node bin/mc2it_card.js"
}
}
26 changes: 26 additions & 0 deletions src/card.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import boxen from "boxen";
import chalk from "chalk";

/**
* Returns the card content.
* @param margin The margin size.
* @returns The card content.
*/
export function getCard(margin = 0): string {
const buffer = [
`${chalk.white.bold(" MC2IT")} ${chalk.white("- Distribution & Services")}`,
"",
`${chalk.white.bold(" GitHub:")} ${chalk.gray("https://github.com/")}${chalk.cyan("mc2it")}`,
"",
`${chalk.white.bold(" Card:")} ${chalk.yellow("npx")} ${chalk.white("@mc2it/card")}`,
`${chalk.white.bold(" Email:")} ${chalk.white("[email protected]")}`,
`${chalk.white.bold("Website:")} ${chalk.white("https://www.mc2it.com")}`
];

return boxen(buffer.join("\n"), {
borderColor: "green",
borderStyle: "round",
margin,
padding: 1
});
}
30 changes: 30 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import console from "node:console";
import {parseArgs} from "node:util";
import pkg from "../package.json" with {type: "json"};
import {getCard} from "./card.js";

// The usage information.
const usage = `
Print the business card of MC2IT, distribution and services.
Usage:
npx @mc2it/card
Options:
-h, --help Display this help.
-v, --version Output the version number.
`;

// Start the application.
try {
const {values} = parseArgs({options: {
help: {short: "h", type: "boolean"},
version: {short: "v", type: "boolean"}
}});

console.log(values.help ? usage.trim() : (values.version ? pkg.version : getCard(1)));
}
catch (error) {
console.error(error instanceof Error ? error.message : error);
process.exitCode = 1;
}
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./card.js";
56 changes: 0 additions & 56 deletions src/mc2it_card/Program.hx

This file was deleted.

2 changes: 1 addition & 1 deletion tool/dist.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ import {shebang} from "./tools.js";
/**
* Packages the project.
*/
shebang("bin/belin_card.js");
shebang("bin/mc2it_card.js");

0 comments on commit 572500d

Please sign in to comment.