Docker build works

This commit is contained in:
Jordan Roher 2023-12-18 12:47:46 -08:00
parent 8b21ff6e68
commit 8ad6b201da
5 changed files with 41 additions and 10 deletions

3
.gitignore vendored
View File

@ -4,4 +4,5 @@ dist
src/*.js
src/**/*.js
public/index.html
public/main.*.css
public/main.css
public/css

View File

@ -1,7 +1,7 @@
server {
listen 4173;
root /app;
root /app/public;
location /app {
try_files $uri $uri/ =404;

View File

@ -41,4 +41,4 @@ EXPOSE 4173
RUN chmod +x /app/docker-entrypoint.sh
ENTRYPOINT ["/app/docker-entrypoint.sh"]
CMD ["npm", "run", "build"]
CMD ["sh", "-c", "npm run build && nginx -g 'daemon off;'"]

View File

@ -1,21 +1,24 @@
import CleanCSS from "clean-css";
import * as path from "path";
import { sbReadFile, sbRename, sbWriteFile } from "./shared/files";
import { sbMakeFolder, sbReadFile, sbRemoveAllCSS, sbWriteFile } from "./shared/files";
const mainCSSFilename = `main.${new Date().getTime()}.css`;
const cssFileInPath = path.join(__dirname, "../", "./public", "main.css");
const cssFileOutPath = path.join(__dirname, "../", "./public", mainCSSFilename);
const indexFileInOutPath = path.join(__dirname, "../", "./public", "index.html");
const cssFilePath = path.join(__dirname, "../public/css");
const cssFileInPath = path.join(__dirname, "../public", "main.css");
const cssFileOutPath = path.join(cssFilePath, mainCSSFilename);
const indexFileInOutPath = path.join(__dirname, "../public", "index.html");
async function start(): Promise<void> {
await sbRename(cssFileInPath, cssFileOutPath);
const css = await sbReadFile(cssFileOutPath);
await sbRemoveAllCSS(cssFilePath);
await sbMakeFolder(cssFilePath);
const css = await sbReadFile(cssFileInPath);
await sbWriteFile(cssFileOutPath, new CleanCSS().minify(css).styles);
const index = await sbReadFile(indexFileInOutPath);
const cssLink = `<link rel="stylesheet" href="./main.css" crossorigin="">`;
const cssLinkReplacement = `<link rel="stylesheet" href="./${mainCSSFilename}" crossorigin="" />`;
const cssLinkReplacement = `<link rel="stylesheet" href="./css/${mainCSSFilename}" crossorigin="" />`;
await sbWriteFile(indexFileInOutPath, index.replace(cssLink, cssLinkReplacement));
}

View File

@ -36,3 +36,30 @@ export async function sbRename(fileNameOld: string, fileNameNew: string): Promis
}
});
}
export async function sbMakeFolder(path: string): Promise<boolean> {
return new Promise(async (resolve, reject) => {
try {
await fs.mkdir(path, { recursive: true });
return resolve(true);
} catch (exception) {
console.error(`Could not make folder: ${path}`, exception);
reject(exception);
}
});
}
export async function sbRemoveAllCSS(path: string): Promise<boolean> {
return new Promise(async (resolve, reject) => {
try {
await fs.rm(path, {
recursive: true,
force: true,
});
return resolve(true);
} catch (exception) {
console.error(`Could not remove all CSS from path: ${path}`);
reject(exception);
}
});
}