diff --git a/src/build.js b/src/build.js index 5268bb1..3c36eb7 100644 --- a/src/build.js +++ b/src/build.js @@ -1,5 +1,3 @@ -import { join } from 'node:path' - const INDEX_TEMPLATE_NAME = 'index.pug' const INDEX_OUTPUT_NAME = 'index.html' const ASSET_DIR_NAME = 'assets' @@ -44,31 +42,22 @@ export function renderIndex( ) { return withSrcDir((prefixWithSrcDir) => { return withBuildDir(async (prefixWithBuildDir) => { - const renderedTemplate = renderTemplate( - await readFile(prefixWithSrcDir(INDEX_TEMPLATE_NAME)), - data, - ) - return writeFile( prefixWithBuildDir(INDEX_OUTPUT_NAME), - renderedTemplate, + renderTemplate( + await readFile(prefixWithSrcDir(INDEX_TEMPLATE_NAME)), + data, + ), ) }) }) } -export function copyAssetDir( - withSrcDir, - withBuildDir, - copyDir, - ifPathExists, -) { +export function copyAssetDir(withSrcDir, withBuildDir, copyDir, ifPathExists) { return withSrcDir((prefixWithSrcDir) => { return withBuildDir((prefixWithBuildDir) => { - const assetDirPath = prefixWithSrcDir(ASSET_DIR_NAME) - return ifPathExists( - assetDirPath, + prefixWithSrcDir(ASSET_DIR_NAME), (path) => copyDir(path, prefixWithBuildDir(ASSET_DIR_NAME)), ) }) diff --git a/src/data.js b/src/data.js index dc3f0b2..39b8d49 100644 --- a/src/data.js +++ b/src/data.js @@ -9,12 +9,7 @@ function normalizeEnvVarName(str) { ) } -export function parseDataFromJsonFile( - withSrcDir, - ifPathExists, - readFile, - parseJson, -) { +export function parseDataFromJsonFile(withSrcDir, ifPathExists, readFile, parseJson) { return withSrcDir((prefixWithSrcDir) => { const jsonFilePath = prefixWithSrcDir(JSON_FILE_NAME) @@ -26,6 +21,10 @@ export function parseDataFromJsonFile( }) } +/** + * Extracts env vars whose name starts with `ENV_VAR_PREFIX`, converts this name + * to snake case, and returns a normalized dictionary of these extracted vars. + */ export function parseDataFromEnv(envObject) { return ( Object.fromEntries( diff --git a/src/i18n.js b/src/i18n.js index eb5eede..a042bf5 100644 --- a/src/i18n.js +++ b/src/i18n.js @@ -5,13 +5,7 @@ const LANG_PATTERN = /^[a-z]{2}$/ const TRANSLATION_DIR_PATH = 'i18n' const TRANSLATION_FILE_PREFIX = '.json' -export function parseTranslations( - withSrcDir, - ifPathExists, - readFile, - parseJson, - lang, -) { +export function parseTranslations(withSrcDir, ifPathExists, readFile, parseJson, lang) { assert.match(lang, LANG_PATTERN) return withSrcDir((prefixWithSrcDir) => { @@ -23,7 +17,7 @@ export function parseTranslations( return ifPathExists( translationFilePath, async () => parseJson(await readFile(translationFilePath)), - {} + {}, ) }) } diff --git a/src/index.js b/src/index.js index f13b979..d8f0322 100644 --- a/src/index.js +++ b/src/index.js @@ -13,15 +13,17 @@ import { parseTranslations } from '#src/i18n' import { parseJson } from '#src/utils/json' import renderTemplate from '#src/renderTemplate/pug' -export default async function buildProject(srcDirPath, buildDirPath, lang = null) { +export default async function buildProject( + srcDirPath, + buildDirPath, + lang = null, +) { await ifPathExists(buildDirPath, rmDir) - const [withSrcDir, withBuildDir] = await ( - Promise.all([ - withDir(srcDirPath), - withScratchDir(buildDirPath), - ]) - ) + const [withSrcDir, withBuildDir] = await Promise.all([ + withDir(srcDirPath), + withScratchDir(buildDirPath), + ]) const data = await parseData( withSrcDir, diff --git a/tests/data.test.js b/tests/data.test.js index a076e7c..2a656a9 100644 --- a/tests/data.test.js +++ b/tests/data.test.js @@ -1,8 +1,8 @@ import { describe, it } from 'node:test' import assert from 'node:assert' +import { withTempDir } from '#tests/helpers' import { mkdir, writeFile } from 'node:fs/promises' import { join } from 'node:path' -import { withTempDir } from '#tests/helpers' import { withDir, ifPathExists, readFile } from '#src/utils/fs' import { parseJson } from '#src/utils/json' import { parseDataFromJsonFile, parseDataFromEnv } from '#src/data' @@ -18,12 +18,7 @@ describe('#src/data', () => { await writeFile(jsonFilePath, '{"stuff": ["thing", "trinket", "gizmo"]}') assert.deepStrictEqual( - await parseDataFromJsonFile( - withDir(dirPath), - ifPathExists, - readFile, - parseJson, - ), + await parseDataFromJsonFile(withDir(dirPath), ifPathExists, readFile, parseJson), { stuff: [ 'thing', diff --git a/tests/i18n.test.js b/tests/i18n.test.js index fadec35..9b38523 100644 --- a/tests/i18n.test.js +++ b/tests/i18n.test.js @@ -1,9 +1,9 @@ import { describe, it } from 'node:test' import assert from 'node:assert' +import { withTempDir } from '#tests/helpers' import { join } from 'node:path' import { mkdir, writeFile } from 'node:fs/promises' import { tmpdir } from 'node:os' -import { withTempDir } from '#tests/helpers' import { withDir, ifPathExists, readFile } from '#src/utils/fs' import { parseJson } from '#src/utils/json' import { parseTranslations } from '#src/i18n'