diff --git a/package-lock.json b/package-lock.json index c244540..e6462f1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,7 +12,8 @@ "@googleapis/calendar": "^11.0.1", "@hackmd/api": "^2.5.0", "@octokit/rest": "^22.0.0", - "dedent": "^1.6.0" + "dedent": "^1.6.0", + "dotenv": "^17.2.2" }, "bin": { "create-meeting": "create-node-meeting-artifacts.mjs" @@ -1207,6 +1208,18 @@ "node": ">=0.4.0" } }, + "node_modules/dotenv": { + "version": "17.2.2", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-17.2.2.tgz", + "integrity": "sha512-Sf2LSQP+bOlhKWWyhFsn0UsfdK/kCWRv1iuA2gXAwt3dyNabr6QSj00I2V10pidqz69soatm9ZwZvpQMTIOd5Q==", + "license": "BSD-2-Clause", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://dotenvx.com" + } + }, "node_modules/dunder-proto": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", diff --git a/package.json b/package.json index 76d53dc..e5dc8fd 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,8 @@ "@googleapis/calendar": "^11.0.1", "@hackmd/api": "^2.5.0", "@octokit/rest": "^22.0.0", - "dedent": "^1.6.0" + "dedent": "^1.6.0", + "dotenv": "^17.2.2" }, "devDependencies": { "@eslint/js": "^9.33.0", diff --git a/src/meeting.mjs b/src/meeting.mjs index c56f042..09bd62c 100644 --- a/src/meeting.mjs +++ b/src/meeting.mjs @@ -1,6 +1,8 @@ import { readFile } from 'node:fs/promises'; import { join } from 'node:path'; +import { parse } from 'dotenv'; + import { DEFAULT_CONFIG } from './constants.mjs'; import * as dates from './utils/dates.mjs'; import * as templates from './utils/templates.mjs'; @@ -32,7 +34,7 @@ export const readMeetingConfig = async config => { invited, observers, baseMeetingInfo, - properties: templates.parseMeetingProperties(baseMeetingInfo), + properties: parse(baseMeetingInfo), }; }; diff --git a/src/utils/templates.mjs b/src/utils/templates.mjs index 6ca65d1..78a997e 100644 --- a/src/utils/templates.mjs +++ b/src/utils/templates.mjs @@ -21,26 +21,3 @@ export const parseVariables = (template, variables) => { return processed; }; - -/** - * Simple parser for template properties (KEY="value" format) - * @param {string} content - Template content - * @returns {Record} Parsed properties - */ -export const parseMeetingProperties = content => { - const properties = {}; - - // Handle multiline properties first with a generic regex - // Matches: KEY="multiline content" where content can span multiple lines - const multilineMatches = content.matchAll( - /^([A-Z_][A-Z0-9_]*)="([\s\S]*?)"$/gm - ); - - for (const match of multilineMatches) { - const [, key, value] = match; - - properties[key] = value; - } - - return properties; -}; diff --git a/test/utils/templates.test.mjs b/test/utils/templates.test.mjs index 6346576..7e05127 100644 --- a/test/utils/templates.test.mjs +++ b/test/utils/templates.test.mjs @@ -1,10 +1,7 @@ import assert from 'node:assert'; import { describe, it } from 'node:test'; -import { - parseVariables, - parseMeetingProperties, -} from '../../src/utils/templates.mjs'; +import { parseVariables } from '../../src/utils/templates.mjs'; describe('Utils - Templates', () => { describe('parseVariables', () => { @@ -118,149 +115,4 @@ Line 3: Hello again` ); }); }); - - describe('parseMeetingProperties', () => { - it('should parse simple property', () => { - const content = 'NAME="John Doe"'; - - const result = parseMeetingProperties(content); - - assert.deepStrictEqual(result, { NAME: 'John Doe' }); - }); - - it('should parse multiple properties', () => { - const content = `NAME="John Doe" -EMAIL="john@example.com" -ROLE="Developer"`; - - const result = parseMeetingProperties(content); - - assert.deepStrictEqual(result, { - NAME: 'John Doe', - EMAIL: 'john@example.com', - ROLE: 'Developer', - }); - }); - - it('should parse multiline property values', () => { - const content = `DESCRIPTION="This is a -multiline description -with several lines"`; - - const result = parseMeetingProperties(content); - - assert.deepStrictEqual(result, { - DESCRIPTION: 'This is a\nmultiline description\nwith several lines', - }); - }); - - it('should parse properties with underscores and numbers', () => { - const content = `VAR_1="value1" -VAR_2_TEST="value2" -VAR3="value3"`; - - const result = parseMeetingProperties(content); - - assert.deepStrictEqual(result, { - VAR_1: 'value1', - VAR_2_TEST: 'value2', - VAR3: 'value3', - }); - }); - - it('should handle empty property values', () => { - const content = 'EMPTY=""'; - - const result = parseMeetingProperties(content); - - assert.deepStrictEqual(result, { EMPTY: '' }); - }); - - it('should handle properties with special characters in values', () => { - const content = 'SPECIAL="Value with $pecial ch@rs & symbols!"'; - - const result = parseMeetingProperties(content); - - assert.deepStrictEqual(result, { - SPECIAL: 'Value with $pecial ch@rs & symbols!', - }); - }); - - it('should handle properties with quotes in values', () => { - const content = `QUOTED="He said \\"Hello\\" to me"`; - - const result = parseMeetingProperties(content); - - assert.deepStrictEqual(result, { - QUOTED: 'He said \\"Hello\\" to me', - }); - }); - - it('should handle content with no properties', () => { - const content = 'Just some text without properties'; - - const result = parseMeetingProperties(content); - - assert.deepStrictEqual(result, {}); - }); - - it('should handle empty content', () => { - const content = ''; - - const result = parseMeetingProperties(content); - - assert.deepStrictEqual(result, {}); - }); - - it('should handle mixed content with properties and other text', () => { - const content = `Some random text -NAME="John Doe" -More text here -EMAIL="john@example.com" -Final text`; - - const result = parseMeetingProperties(content); - - assert.deepStrictEqual(result, { - NAME: 'John Doe', - EMAIL: 'john@example.com', - }); - }); - - it('should handle properties with markdown-like content', () => { - const content = `DESCRIPTION="# Meeting Notes - -## Agenda -- Item 1 -- Item 2 - -**Important**: Don't forget!"`; - - const result = parseMeetingProperties(content); - - assert.deepStrictEqual(result, { - DESCRIPTION: `# Meeting Notes - -## Agenda -- Item 1 -- Item 2 - -**Important**: Don't forget!`, - }); - }); - - it('should handle properties with URLs and special formatting', () => { - const content = `LINK="https://example.com/path?param=value&other=123" -INSTRUCTIONS="Join at: https://zoom.us/j/123456789 -Passcode: 123456"`; - - const result = parseMeetingProperties(content); - - assert.deepStrictEqual(result, { - LINK: 'https://example.com/path?param=value&other=123', - INSTRUCTIONS: `Join at: https://zoom.us/j/123456789 -Passcode: 123456`, - }); - }); - }); });