-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7d71f04
commit 0dd9b68
Showing
6 changed files
with
59 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#!/usr/bin/env node | ||
|
||
import { config } from 'dotenv'; | ||
import { readFileSync, writeFileSync } from 'node:fs'; | ||
import { dirname, join } from 'node:path'; | ||
import { ENV, findHtmlFiles } from './build.utils.mjs'; | ||
import { findFiles } from './utils.mjs'; | ||
|
||
config({ path: `.env.${ENV}` }); | ||
|
||
const PLACEHOLDER = '<!-- ROUTE_STYLE -->'; | ||
|
||
const src = join(process.cwd(), 'src', 'frontend', 'src', 'routes'); | ||
const build = join(process.cwd(), 'build'); | ||
|
||
const parseStyle = (srcFile) => { | ||
const parsedSrcFile = srcFile.replace(/\/\([^)]+\)\//, '/'); // Remove e.g. /(sign)/ from path | ||
const srcDir = dirname(parsedSrcFile); | ||
|
||
const destDir = srcDir.replace(src, build); | ||
const destFile = join(destDir, 'index.html'); | ||
|
||
const style = readFileSync(srcFile, 'utf8'); | ||
|
||
// Just in case there is an empty CSS source file. Placeholder is cleaned with another hook. | ||
if (style.trim().length === 0) { | ||
return; | ||
} | ||
|
||
const content = readFileSync(destFile, 'utf8'); | ||
const updatedContent = content.replace(PLACEHOLDER, `<style>\n${style}\n</style>`); | ||
|
||
writeFileSync(destFile, updatedContent); | ||
}; | ||
|
||
const cleanPlaceholder = (targetFile) => { | ||
const content = readFileSync(targetFile, 'utf8'); | ||
const updatedContent = content.replace(PLACEHOLDER, ''); | ||
|
||
writeFileSync(targetFile, updatedContent); | ||
}; | ||
|
||
const styleFiles = findFiles({ dir: src, extensions: ['.page.css'] }); | ||
styleFiles.forEach(parseStyle); | ||
|
||
const htmlFiles = findHtmlFiles(); | ||
htmlFiles.forEach(cleanPlaceholder); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,3 +22,7 @@ | |
</main> | ||
|
||
<Modals /> | ||
|
||
<style global lang="scss"> | ||
@import './+oisy.page.css'; | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
:root { | ||
background: #e8f1ff; | ||
} |