@towles/tool 0.0.17 → 0.0.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.mjs +103 -8
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -40,10 +40,12 @@ const AppInfo = {
40
40
  const USER_SETTINGS_DIR = path.join(homedir(), ".config", AppInfo.toolName);
41
41
  const USER_SETTINGS_PATH = path.join(USER_SETTINGS_DIR, `${AppInfo.toolName}.settings.json`);
42
42
  const JournalSettingsSchema = z.object({
43
+ // Base folder where all journal files are stored
44
+ baseFolder: z.string().default(path.join(homedir())),
43
45
  // https://moment.github.io/luxon/#/formatting?id=table-of-tokens
44
- dailyPathTemplate: z.string().default(path.join(homedir(), "journal", "{monday:yyyy}/{monday:MM}/daily-notes/{monday:yyyy}-{monday:MM}-{monday:dd}-daily-notes.md")),
45
- meetingPathTemplate: z.string().default(path.join(homedir(), "journal", "{yyyy}/{MM}/meetings/{yyyy}-{MM}-{dd}-{title}.md")),
46
- notePathTemplate: z.string().default(path.join(homedir(), "journal", "{yyyy}/{MM}/notes/{yyyy}-{MM}-{dd}-{title}.md"))
46
+ dailyPathTemplate: z.string().default(path.join("journal/{monday:yyyy}/{monday:MM}/daily-notes/{monday:yyyy}-{monday:MM}-{monday:dd}-daily-notes.md")),
47
+ meetingPathTemplate: z.string().default(path.join("journal/{yyyy}/{MM}/meetings/{yyyy}-{MM}-{dd}-{title}.md")),
48
+ notePathTemplate: z.string().default(path.join("journal/{yyyy}/{MM}/notes/{yyyy}-{MM}-{dd}-{title}.md"))
47
49
  });
48
50
  const UserSettingsSchema = z.object({
49
51
  preferredEditor: z.string().default("code"),
@@ -121,7 +123,7 @@ async function loadSettings() {
121
123
  );
122
124
  }
123
125
 
124
- const version = "0.0.17";
126
+ const version = "0.0.20";
125
127
 
126
128
  const JOURNAL_TYPES = {
127
129
  DAILY_NOTES: "daily-notes",
@@ -208,6 +210,14 @@ async function parseArguments(argv) {
208
210
  parsedResult = { command: "config", args: {} };
209
211
  }
210
212
  );
213
+ parser.command(
214
+ ["weather", "w"],
215
+ "Show current weather for Cincinnati, OH",
216
+ {},
217
+ () => {
218
+ parsedResult = { command: "weather", args: {} };
219
+ }
220
+ );
211
221
  await parser.parse();
212
222
  if (!parsedResult) {
213
223
  throw new Error("No command was parsed");
@@ -403,9 +413,13 @@ function createNoteContent({ title, date }) {
403
413
  content.push(``);
404
414
  return content.join("\n");
405
415
  }
406
- async function openInEditor({ editor, filePath }) {
416
+ async function openInEditor({ editor, filePath, folderPath }) {
407
417
  try {
408
- await execAsync(`"${editor}" "${filePath}"`);
418
+ if (folderPath) {
419
+ await execAsync(`"${editor}" "${folderPath}" "${filePath}"`);
420
+ } else {
421
+ await execAsync(`"${editor}" "${filePath}"`);
422
+ }
409
423
  } catch (ex) {
410
424
  consola.warn(`Could not open in editor : '${editor}'. Modify your editor in the config: examples include 'code', 'code-insiders', etc...`, ex);
411
425
  }
@@ -462,9 +476,10 @@ function generateJournalFileInfoByType({ journalSettings, date = /* @__PURE__ */
462
476
  throw new Error(`Unknown JournalType: ${type}`);
463
477
  }
464
478
  const resolvedPath = resolvePathTemplate(templatePath, title, currentDate, mondayDate);
479
+ const fullPath = path__default.join(journalSettings.baseFolder, resolvedPath);
465
480
  return {
466
481
  currentDate,
467
- fullPath: resolvedPath,
482
+ fullPath,
468
483
  mondayDate
469
484
  };
470
485
  }
@@ -503,7 +518,11 @@ async function createJournalFile({ context, type, title }) {
503
518
  consola.info(`Creating new ${type} file: ${colors.cyan(fileInfo.fullPath)}`);
504
519
  writeFileSync(fileInfo.fullPath, content, "utf8");
505
520
  }
506
- await openInEditor({ editor: context.settingsFile.settings.preferredEditor, filePath: fileInfo.fullPath });
521
+ await openInEditor({
522
+ editor: context.settingsFile.settings.preferredEditor,
523
+ filePath: fileInfo.fullPath,
524
+ folderPath: context.settingsFile.settings.journalSettings.baseFolder
525
+ });
507
526
  } catch (error) {
508
527
  consola.warn(`Error creating ${type} file:`, error);
509
528
  process$1.exit(1);
@@ -668,6 +687,79 @@ async function githubBranchCommand(context, args) {
668
687
  }
669
688
  }
670
689
 
690
+ const CINCINNATI_LATITUDE = 39.1031;
691
+ const CINCINNATI_LONGITUDE = -84.512;
692
+ const WEATHER_DESCRIPTIONS = {
693
+ 0: { description: "Clear sky", emoji: "\u2600\uFE0F" },
694
+ 1: { description: "Mainly clear", emoji: "\u{1F324}\uFE0F" },
695
+ 2: { description: "Partly cloudy", emoji: "\u26C5" },
696
+ 3: { description: "Overcast", emoji: "\u2601\uFE0F" },
697
+ 45: { description: "Fog", emoji: "\u{1F32B}\uFE0F" },
698
+ 48: { description: "Depositing rime fog", emoji: "\u{1F32B}\uFE0F" },
699
+ 51: { description: "Light drizzle", emoji: "\u{1F326}\uFE0F" },
700
+ 53: { description: "Moderate drizzle", emoji: "\u{1F326}\uFE0F" },
701
+ 55: { description: "Dense drizzle", emoji: "\u{1F327}\uFE0F" },
702
+ 56: { description: "Light freezing drizzle", emoji: "\u{1F328}\uFE0F" },
703
+ 57: { description: "Dense freezing drizzle", emoji: "\u{1F328}\uFE0F" },
704
+ 61: { description: "Slight rain", emoji: "\u{1F327}\uFE0F" },
705
+ 63: { description: "Moderate rain", emoji: "\u{1F327}\uFE0F" },
706
+ 65: { description: "Heavy rain", emoji: "\u{1F327}\uFE0F" },
707
+ 66: { description: "Light freezing rain", emoji: "\u{1F328}\uFE0F" },
708
+ 67: { description: "Heavy freezing rain", emoji: "\u{1F328}\uFE0F" },
709
+ 71: { description: "Slight snow fall", emoji: "\u{1F328}\uFE0F" },
710
+ 73: { description: "Moderate snow fall", emoji: "\u2744\uFE0F" },
711
+ 75: { description: "Heavy snow fall", emoji: "\u2744\uFE0F" },
712
+ 77: { description: "Snow grains", emoji: "\u{1F328}\uFE0F" },
713
+ 80: { description: "Slight rain showers", emoji: "\u{1F326}\uFE0F" },
714
+ 81: { description: "Moderate rain showers", emoji: "\u{1F327}\uFE0F" },
715
+ 82: { description: "Violent rain showers", emoji: "\u26C8\uFE0F" },
716
+ 85: { description: "Slight snow showers", emoji: "\u{1F328}\uFE0F" },
717
+ 86: { description: "Heavy snow showers", emoji: "\u2744\uFE0F" },
718
+ 95: { description: "Thunderstorm", emoji: "\u26C8\uFE0F" },
719
+ 96: { description: "Thunderstorm with slight hail", emoji: "\u26C8\uFE0F" },
720
+ 99: { description: "Thunderstorm with heavy hail", emoji: "\u26C8\uFE0F" }
721
+ };
722
+ function getWindDirection(degrees) {
723
+ const directions = ["N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW"];
724
+ const index = Math.round(degrees / 22.5) % 16;
725
+ return directions[index];
726
+ }
727
+ function formatWeatherData(data) {
728
+ const { current_weather: weather, current_weather_units: units } = data;
729
+ const weatherInfo = WEATHER_DESCRIPTIONS[weather.weathercode] || {
730
+ description: "Unknown",
731
+ emoji: "\u2753"
732
+ };
733
+ const windDirection = getWindDirection(weather.winddirection);
734
+ const timeOfDay = weather.is_day ? "Day" : "Night";
735
+ consola.info("\u{1F30E} Current Weather in Cincinnati, OH");
736
+ consola.log("");
737
+ consola.log(`${weatherInfo.emoji} ${weatherInfo.description}`);
738
+ consola.log(`\u{1F321}\uFE0F Temperature: ${weather.temperature}${units.temperature}`);
739
+ consola.log(`\u{1F4A8} Wind: ${weather.windspeed} ${units.windspeed} ${windDirection}`);
740
+ consola.log(`\u{1F550} Time: ${new Date(weather.time).toLocaleTimeString()} (${timeOfDay})`);
741
+ }
742
+ async function weatherCommand(context) {
743
+ try {
744
+ consola.start("Fetching current weather for Cincinnati...");
745
+ const url = `https://api.open-meteo.com/v1/forecast?latitude=${CINCINNATI_LATITUDE}&longitude=${CINCINNATI_LONGITUDE}&current_weather=true&temperature_unit=fahrenheit&windspeed_unit=mph&timezone=America/New_York`;
746
+ const response = await fetch(url);
747
+ if (!response.ok) {
748
+ throw new Error(`Weather API request failed: ${response.status} ${response.statusText}`);
749
+ }
750
+ const data = await response.json();
751
+ if (!data.current_weather) {
752
+ throw new Error("No weather data received from API");
753
+ }
754
+ consola.success("Weather data retrieved successfully!");
755
+ consola.log("");
756
+ formatWeatherData(data);
757
+ } catch (error) {
758
+ consola.error("Failed to fetch weather data:", error instanceof Error ? error.message : String(error));
759
+ process.exit(1);
760
+ }
761
+ }
762
+
671
763
  async function executeCommand(parsedArgs, context) {
672
764
  switch (parsedArgs.command) {
673
765
  case "journal": {
@@ -683,6 +775,9 @@ async function executeCommand(parsedArgs, context) {
683
775
  case "config":
684
776
  await configCommand(context);
685
777
  break;
778
+ case "weather":
779
+ await weatherCommand();
780
+ break;
686
781
  default:
687
782
  throw new Error(`Unknown command: ${parsedArgs.command}`);
688
783
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@towles/tool",
3
3
  "type": "module",
4
- "version": "0.0.17",
4
+ "version": "0.0.20",
5
5
  "description": "One off quality of life scripts that I use on a daily basis.",
6
6
  "author": "Chris Towles <Chris.Towles.Dev@gmail.com>",
7
7
  "license": "MIT",