Skip to content

Commit 810d6c6

Browse files
Merge pull request #13 from snelusha/feat/migrate-ts
feat: migrate to TypeScript
2 parents 7eaa346 + f56192d commit 810d6c6

File tree

13 files changed

+134
-39
lines changed

13 files changed

+134
-39
lines changed

bin/thyra.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

bun.lock

Lines changed: 45 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,17 @@
44
"description": "Simple project folder opener CLI",
55
"type": "module",
66
"bin": {
7-
"thyra": "./bin/thyra.js"
7+
"thyra": "dist/cli.js"
88
},
99
"scripts": {
10-
"start": "node ./bin/thyra.js",
10+
"build": "bun build ./src/cli.ts --outdir ./dist --target node --banner '#!/usr/bin/env node' --minify",
11+
"start": "node ./dist/cli.js",
1112
"lint": "eslint ."
1213
},
14+
"files": [
15+
"dist",
16+
"README.md"
17+
],
1318
"engines": {
1419
"node": ">=18.0.0"
1520
},
@@ -29,5 +34,10 @@
2934
"bugs": {
3035
"url": "https://github.com/udithavithanage/thyra/issues"
3136
},
32-
"homepage": "https://github.com/udithavithanage/thyra#readme"
37+
"homepage": "https://github.com/udithavithanage/thyra#readme",
38+
"devDependencies": {
39+
"@types/node": "^24.10.1",
40+
"bun": "^1.3.3",
41+
"typescript": "^5.9.3"
42+
}
3343
}

src/cli.js renamed to src/cli.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { ConfigStore } from "./configStore.js";
2-
import { runConfig } from "./commands/config.js";
3-
import { runVersion } from "./commands/version.js";
4-
import { runOpen } from "./commands/open.js";
5-
import { runList } from "./commands/list.js";
6-
import { runHelp } from "./commands/help.js";
7-
import { getConfigFilePath } from "./configStore.js";
1+
import { runConfig } from "~/commands/config";
2+
import { runVersion } from "~/commands/version";
3+
import { runOpen } from "~/commands/open";
4+
import { runList } from "~/commands/list";
5+
import { runHelp } from "~/commands/help";
6+
7+
import { getConfigFilePath, ConfigStore } from "~/configStore";
88

99
(function run() {
1010
const [, , command, ...rest] = process.argv;
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ import fs from "node:fs";
22
import os from "node:os";
33
import path from "node:path";
44

5-
function resolveFolderPath(inputPath) {
5+
import type { ConfigStore } from "~/configStore";
6+
7+
function resolveFolderPath(inputPath: string): string {
68
let folderPath = inputPath.replace(/^~(?=$|[\\/])/, os.homedir());
79
folderPath = path.resolve(folderPath);
810
return folderPath;
911
}
1012

11-
function ensureDirectoryExists(folderPath) {
13+
function ensureDirectoryExists(folderPath: string): void {
1214
if (!fs.existsSync(folderPath)) {
1315
console.error(`Folder does not exist: ${folderPath}`);
1416
process.exit(1);
@@ -21,7 +23,7 @@ function ensureDirectoryExists(folderPath) {
2123
}
2224
}
2325

24-
export function runConfig(store, args) {
26+
export function runConfig(store: ConfigStore, args: string[]): void {
2527
const name = args[0];
2628
const folderArg = args[1];
2729

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export function runHelp(exitCode) {
1+
export function runHelp(exitCode?: number): void {
22
console.log(`
33
thyra - Quick shortcut manager for project folders
44
`);
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
export function runList(store) {
1+
import type { ConfigStore } from "~/configStore";
2+
3+
export function runList(store: ConfigStore): void {
24
const all = store.all();
35
const keys = Object.keys(all);
46

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import fs from "node:fs";
2-
import { openInEditor } from "../editor.js";
2+
import { openInEditor } from "~/editor.js";
33

4-
function ensureDirectoryExists(folderPath) {
4+
import type { ConfigStore } from "~/configStore";
5+
6+
function ensureDirectoryExists(folderPath: string): void {
57
if (!fs.existsSync(folderPath)) {
68
console.error(`Folder does not exist: ${folderPath}`);
79
process.exit(1);
@@ -14,7 +16,7 @@ function ensureDirectoryExists(folderPath) {
1416
}
1517
}
1618

17-
export function runOpen(store, args) {
19+
export function runOpen(store: ConfigStore, args: string[]): void {
1820
const name = args[0];
1921
if (!name) {
2022
console.error("Missing <name> argument for 'open' command.");
@@ -24,12 +26,17 @@ export function runOpen(store, args) {
2426

2527
if (!store.has(name)) {
2628
console.error(
27-
`No folder found for name "${name}". Use 'thyra list' to see saved entries.`
29+
`No folder found for name "${name}". Use 'thyra list' to see saved entries.`,
2830
);
2931
process.exit(1);
3032
}
3133

3234
const folderPath = store.get(name);
35+
if (!folderPath) {
36+
console.error(`Invalid folder path for name "${name}".`);
37+
process.exit(1);
38+
}
39+
3340
ensureDirectoryExists(folderPath);
3441
openInEditor(folderPath);
3542
}

src/commands/version.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/commands/version.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { version } from "package" assert { type: "json" };
2+
3+
export function runVersion(): void {
4+
console.log(`v${version}`);
5+
}

0 commit comments

Comments
 (0)