@towles/tool 0.0.14 → 0.0.16

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 +26 -5
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -38,7 +38,7 @@ const USER_SETTINGS_DIR = path.join(homedir(), ".config", AppInfo.toolName);
38
38
  const USER_SETTINGS_PATH = path.join(USER_SETTINGS_DIR, `${AppInfo.toolName}.settings.json`);
39
39
  const JournalSettingsSchema = z.object({
40
40
  // https://moment.github.io/luxon/#/formatting?id=table-of-tokens
41
- dailyPathTemplate: z.string().default(path.join(homedir(), "journal", "{yyyy}/{MM}/daily-notes/{yyyy}-{MM}-{dd}-daily-notes.md")),
41
+ dailyPathTemplate: z.string().default(path.join(homedir(), "journal", "{monday:yyyy}/{monday:MM}/daily-notes/{monday:yyyy}-{monday:MM}-{monday:dd}-daily-notes.md")),
42
42
  meetingPathTemplate: z.string().default(path.join(homedir(), "journal", "{yyyy}/{MM}/meetings/{yyyy}-{MM}-{dd}-{title}.md")),
43
43
  notePathTemplate: z.string().default(path.join(homedir(), "journal", "{yyyy}/{MM}/notes/{yyyy}-{MM}-{dd}-{title}.md"))
44
44
  });
@@ -52,12 +52,23 @@ class LoadedSettings {
52
52
  }
53
53
  settingsFile;
54
54
  }
55
+ function createDefaultSettings() {
56
+ return UserSettingsSchema.parse({
57
+ // NOTE: yes its odd zod can't use defaults from objects nested but it appears to be the case.
58
+ journalSettings: JournalSettingsSchema.parse({})
59
+ });
60
+ }
55
61
  function createSettingsFile() {
56
- let userSettings = UserSettingsSchema.parse({});
62
+ let userSettings = createDefaultSettings();
57
63
  if (fs.existsSync(USER_SETTINGS_PATH)) {
58
64
  const userContent = fs.readFileSync(USER_SETTINGS_PATH, "utf-8");
59
65
  const parsedUserSettings = commentJson.parse(userContent);
60
66
  userSettings = UserSettingsSchema.parse(parsedUserSettings);
67
+ } else {
68
+ saveSettings({
69
+ path: USER_SETTINGS_PATH,
70
+ settings: userSettings
71
+ });
61
72
  }
62
73
  return userSettings;
63
74
  }
@@ -107,7 +118,7 @@ async function loadSettings() {
107
118
  );
108
119
  }
109
120
 
110
- const version = "0.0.14";
121
+ const version = "0.0.16";
111
122
 
112
123
  async function parseArguments(argv) {
113
124
  let parsedResult = null;
@@ -382,13 +393,18 @@ async function openInEditor({ editor, filePath }) {
382
393
  consola.warn(`Could not open in editor : '${editor}'. Modify your editor in the config: examples include 'code', 'code-insiders', etc...`, ex);
383
394
  }
384
395
  }
385
- function resolvePathTemplate(template, title, date) {
396
+ function resolvePathTemplate(template, title, date, mondayDate) {
386
397
  const dateTime = DateTime.fromJSDate(date, { zone: "utc" });
387
398
  return template.replace(/\{([^}]+)\}/g, (match, token) => {
388
399
  try {
389
400
  if (token === "title") {
390
401
  return title.toLowerCase().replace(/\s+/g, "-");
391
402
  }
403
+ if (token.startsWith("monday:")) {
404
+ const mondayToken = token.substring(7);
405
+ const mondayDateTime = DateTime.fromJSDate(mondayDate, { zone: "utc" });
406
+ return mondayDateTime.toFormat(mondayToken);
407
+ }
392
408
  const result = dateTime.toFormat(token);
393
409
  const isLikelyInvalid = token.includes("invalid") || result.length > 20 || // Very long results are likely garbage
394
410
  result.length > token.length * 2 && /\d{10,}/.test(result) || // Contains very long numbers
@@ -428,7 +444,7 @@ function generateJournalFileInfoByType({ journalSettings, date = /* @__PURE__ */
428
444
  default:
429
445
  throw new Error(`Unknown journal type: ${type}`);
430
446
  }
431
- const resolvedPath = resolvePathTemplate(templatePath, title, currentDate);
447
+ const resolvedPath = resolvePathTemplate(templatePath, title, currentDate, mondayDate);
432
448
  return {
433
449
  currentDate,
434
450
  fullPath: resolvedPath,
@@ -437,6 +453,11 @@ function generateJournalFileInfoByType({ journalSettings, date = /* @__PURE__ */
437
453
  }
438
454
  async function createJournalFile({ context, type, title }) {
439
455
  try {
456
+ if (title.trim().length === 0 && (type === JOURNAL_TYPES.MEETING || type === JOURNAL_TYPES.NOTE)) {
457
+ title = await consola.prompt(`Enter ${type} title:`, {
458
+ type: "text"
459
+ });
460
+ }
440
461
  const currentDate = /* @__PURE__ */ new Date();
441
462
  const fileInfo = generateJournalFileInfoByType({
442
463
  journalSettings: context.settingsFile.settings.journalSettings,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@towles/tool",
3
3
  "type": "module",
4
- "version": "0.0.14",
4
+ "version": "0.0.16",
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",