From 5e2cec5b5dc3b6522aa4568d9257c2397fa06cdf Mon Sep 17 00:00:00 2001 From: Untone Date: Thu, 8 Feb 2024 02:23:18 +0300 Subject: [PATCH] ci-fix-3 --- .gitea/workflows/main.yml | 2 +- package.json | 1 + templates/compile.cjs | 40 ++++++++++++++++++++++++++------------- 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/.gitea/workflows/main.yml b/.gitea/workflows/main.yml index 05a49189..cf6d574a 100644 --- a/.gitea/workflows/main.yml +++ b/.gitea/workflows/main.yml @@ -41,7 +41,7 @@ jobs: with: node-version: '18' - - name: Test production build + - name: Run templates build run: npm run templates - name: "authorizer_email_confirmation template" diff --git a/package.json b/package.json index 1e9f7cdf..a1d46279 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "hygen": "HYGEN_TMPLS=gen hygen", "postinstall": "npm run codegen", "check:code": "npx @biomejs/biome check src --log-kind=compact --verbose", + "check:types": "tsc --noEmit", "check:code:fix": "npx @biomejs/biome check src --log-kind=compact --verbose --apply-unsafe", "lint": "npm run lint:code && stylelint **/*.{scss,css}", "lint:code": "npx @biomejs/biome lint src --log-kind=compact --verbose", diff --git a/templates/compile.cjs b/templates/compile.cjs index 3db01c32..b13b9380 100644 --- a/templates/compile.cjs +++ b/templates/compile.cjs @@ -1,22 +1,36 @@ const fs = require('fs'); const path = require('path'); +const currentDir = process.cwd(); +const templatePath = path.join(currentDir, 'templates', 'main.html'); +const outputDir = path.join(currentDir, 'templates', 'dist'); +const componentsDir = path.join(currentDir, 'templates', 'entries'); + const components = ['email_confirmation', 'first_publication', 'new_comment', 'password_reset']; -const template = fs.readFileSync("templates/main.html", "utf-8"); -const outputDir = 'templates/dist'; -// Generate HTML files for each template -components.forEach(component => { - const filePath = path.join(outputDir, `authorizer_${component}.html`); +try { + // Read the template file + const template = fs.readFileSync(templatePath, 'utf-8'); - // Read the component file - const componentContent = fs.readFileSync(`templates/entries/${component}.html`, 'utf-8'); + // Generate HTML files for each template + components.forEach(component => { + const filePath = path.join(outputDir, `authorizer_${component}.html`); + const componentFilePath = path.join(componentsDir, `${component}.html`); - // Replace placeholder with compiled component code - const htmlContent = template.replace('', componentContent); + try { + // Read the component file + const componentContent = fs.readFileSync(componentFilePath, 'utf-8'); + // Replace placeholder with compiled component code + const htmlContent = template.replace('', componentContent); - // Write formatted HTML file to disk - fs.writeFileSync(filePath, htmlContent); - console.log(`${filePath} was generated successfully`); -}); + // Write formatted HTML file to disk + fs.writeFileSync(filePath, htmlContent); + console.log(`${filePath} was generated successfully`); + } catch (error) { + console.error(`Error reading component file ${componentFilePath}:`, error); + } + }); +} catch (error) { + console.error(`Error reading template file ${templatePath}:`, error); +}