Skip to content

Commit

Permalink
refactor: populate readme on start
Browse files Browse the repository at this point in the history
  • Loading branch information
cpvalente committed Oct 22, 2024
1 parent f2d7f4a commit 46e9fcb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
12 changes: 12 additions & 0 deletions apps/server/src/setup/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ export const srcDir = {
export const srcFiles = {
/** Path to bundled CSS */
cssOverride: join(srcDir.root, config.user, config.styles.directory, config.styles.filename),
/** Path to bundled external readme */
externalReadme: join(srcDir.root, config.external, 'README.md'),
/** Path to bundled user readme */
userReadme: join(srcDir.root, config.user, 'README.md'),
/** Path to bundled CSS readme */
cssReadme: join(srcDir.root, config.user, config.styles.directory, 'README.md'),
};

/**
Expand Down Expand Up @@ -135,4 +141,10 @@ export const publicFiles = {
restoreFile: join(publicDir.root, config.restoreFile),
/** path to CSS override file */
cssOverride: join(publicDir.stylesDir, config.styles.filename),
/** path to external readme file */
externalReadme: join(publicDir.externalDir, 'README.md'),
/** path to user readme file */
userReadme: join(publicDir.userDir, 'README.md'),
/** path to CSS readme file */
cssReadme: join(publicDir.stylesDir, 'README.md'),
} as const;
6 changes: 4 additions & 2 deletions apps/server/src/setup/loadDemo.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { copyFileSync } from 'fs';
import { copyDirectory, ensureDirectory } from '../utils/fileManagement.js';

import { publicDir, srcDir } from './index.js';
import { publicDir, publicFiles, srcDir, srcFiles } from './index.js';

/**
* @description ensures directories exist and populates demo folder
*/
export const populateDemo = () => {
ensureDirectory(publicDir.demoDir);

// even if demo exist we want to use startup demo
try {
copyFileSync(srcFiles.externalReadme, publicFiles.externalReadme);
// even if demo exist we want to use startup demo
copyDirectory(srcDir.demoDir, publicDir.demoDir);
} catch (_) {
/* we do not handle this */
Expand Down
12 changes: 7 additions & 5 deletions apps/server/src/setup/loadStyles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ import { publicDir, publicFiles, srcFiles } from './index.js';
export const populateStyles = () => {
ensureDirectory(publicDir.stylesDir);
// if styles doesn't exist we want to use startup stylesheet
if (!existsSync(publicFiles.cssOverride)) {
try {
// copy the startup stylesheet to the public directory
try {
copyFileSync(srcFiles.userReadme, publicFiles.userReadme);
copyFileSync(srcFiles.cssReadme, publicFiles.cssReadme);
if (!existsSync(publicFiles.cssOverride)) {
// copy the startup stylesheet only if user doesnt have one
copyFileSync(srcFiles.cssOverride, publicFiles.cssOverride);
} catch (_) {
/* we do not handle this */
}
} catch (_) {
/* we do not handle this */
}
};

0 comments on commit 46e9fcb

Please sign in to comment.