aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.env.defaults2
-rw-r--r--README.md21
-rw-r--r--app/builder/build.ts16
3 files changed, 22 insertions, 17 deletions
diff --git a/.env.defaults b/.env.defaults
index a97130b..02be0c1 100644
--- a/.env.defaults
+++ b/.env.defaults
@@ -3,6 +3,8 @@ VIEWS_DIR=views
STATIC_DIR=static
OUTPUT_DIR=build
+SKIP_OUTPUT_DIR_CREATION=false
+
WEBSERVER_ENABLED=false
WEBSERVER_AUTOREBUILD=true
WEBSERVER_PORT=3000
diff --git a/README.md b/README.md
index 16ffaf6..1518503 100644
--- a/README.md
+++ b/README.md
@@ -13,13 +13,14 @@ $ docker build -t panulat .
The program uses the following environment variables:
-| Name | Value | Default |
-|-------------------------|-------------------------------------------------------------|----------|
-| `PAGES_DIR` | The directory containing Markdown and HTML formatted pages. | `pages` |
-| `VIEWS_DIR` | The directory containing templates. | `views` |
-| `STATIC_DIR` | The directory containing static files to be copied. | `static` |
-| `OUTPUT_DIR` | The output directory for rendered pages. | `build` |
-| `WEBSERVER_ENABLED` | If the webserver should start. Used for testing. | `false` |
-| `WEBSERVER_AUTOREBUILD` | If pages should be automatically rebuilt when changing. | `true` |
-| `WEBSERVER_PORT` | The port the webserver should listen on. | `3000` |
-| `LOGGING_LEVEL` | How verbose logs should be. | `info` |
+| Name | Value | Default |
+|----------------------------|-------------------------------------------------------------|----------|
+| `PAGES_DIR` | The directory containing Markdown and HTML formatted pages. | `pages` |
+| `VIEWS_DIR` | The directory containing templates. | `views` |
+| `STATIC_DIR` | The directory containing static files to be copied. | `static` |
+| `OUTPUT_DIR` | The output directory for rendered pages. | `build` |
+| `SKIP_OUTPUT_DIR_CREATION` | If the output dir should not be deleted and re-created. | `false` |
+| `WEBSERVER_ENABLED` | If the webserver should start. Used for testing. | `false` |
+| `WEBSERVER_AUTOREBUILD` | If pages should be automatically rebuilt when changing. | `true` |
+| `WEBSERVER_PORT` | The port the webserver should listen on. | `3000` |
+| `LOGGING_LEVEL` | How verbose logs should be. | `info` |
diff --git a/app/builder/build.ts b/app/builder/build.ts
index d0ed5a9..2e11d0f 100644
--- a/app/builder/build.ts
+++ b/app/builder/build.ts
@@ -6,14 +6,16 @@ import { logger } from '../logger.js';
export async function buildPages(): Promise<{ success: boolean, errors: number, pageDirectory: PageDirectory}> {
// Recreate output directory
- try {
- if (fs.existsSync(process.env.OUTPUT_DIR)) {
- fs.rmSync(process.env.OUTPUT_DIR, { recursive: true });
+ if (process.env.SKIP_OUTPUT_DIR_CREATION !== 'true') {
+ try {
+ if (fs.existsSync(process.env.OUTPUT_DIR)) {
+ fs.rmSync(process.env.OUTPUT_DIR, { recursive: true });
+ }
+ fs.mkdirSync(process.env.OUTPUT_DIR);
+ } catch (e) {
+ logger.error(`Failed to create output directory: ${e.message}`);
+ return { success: false, errors: 0, pageDirectory: null };
}
- fs.mkdirSync(process.env.OUTPUT_DIR);
- } catch (e) {
- logger.error(`Failed to create output directory: ${e.message}`);
- return { success: false, errors: 0, pageDirectory: null };
}