Skip to content

Commit

Permalink
[fix] 린트 수정 및 프리티어 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
lybell-art committed Aug 23, 2024
1 parent 3026717 commit ac5cb1a
Show file tree
Hide file tree
Showing 13 changed files with 169 additions and 164 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"version": "1.0.0",
"type": "module",
"scripts": {
"format": "prettier --write 'src/**/*.{js,jsx,ts,tsx,json,css}'",
"format": "prettier --write 'packages/**/*.{js,jsx,ts,tsx,json,css}'",
"lint": "eslint . --ext js,jsx --max-warnings 0",
"lint-fix": "eslint . --ext js,jsx --fix",
"build": "npm --prefix ./packages/mainPage run build",
Expand Down
110 changes: 53 additions & 57 deletions packages/adminPage/build.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
import { build } from "vite";
import { resolve, dirname } from "node:path";
import { fileURLToPath } from "node:url";
import process from "node:process";
import { readFile, writeFile, rm, mkdir, readdir, copyFile } from "node:fs/promises";
import { readFile, writeFile, mkdir, readdir, copyFile } from "node:fs/promises";
import config from "./vite.config.js";

const __dirname = fileURLToPath(new URL('.', import.meta.url));
const __dirname = fileURLToPath(new URL(".", import.meta.url));
const toAbsolute = (p) => resolve(__dirname, p);

console.log("yeahhhhh!!!!");

const buildUrl = [
"index",
"events",
"events/create",
"login",
"events/[id]",
"comments",
"comments/[id]"
]
"index",
"events",
"events/create",
"login",
"events/[id]",
"comments",
"comments/[id]",
];

async function copyFolder(src, dest) {
// 대상 폴더가 존재하지 않으면 생성
Expand All @@ -43,63 +42,60 @@ async function copyFolder(src, dest) {
}

async function processBuild() {
await Promise.all([
buildClient(),
buildSSG()
]);
await Promise.all([
copyFolder("../../public/font", `./dist/font`),
copyFolder("../../public/icons", `./dist/shared/icons`)
]);
await injectSSGToHtml();
await Promise.all([buildClient(), buildSSG()]);
await Promise.all([
copyFolder("../../public/font", `./dist/font`),
copyFolder("../../public/icons", `./dist/shared/icons`),
]);
await injectSSGToHtml();
}

async function buildClient() {
await build({
...config
});
await build({
...config,
});
}

function buildSSG() {
return build({
...config,
build: {
ssr: true,
rollupOptions: {
input: {
entry: `./src/main-server.jsx`
},
output: {
dir: `./dist-ssg`
}
}
}
});
return build({
...config,
build: {
ssr: true,
rollupOptions: {
input: {
entry: `./src/main-server.jsx`,
},
output: {
dir: `./dist-ssg`,
},
},
},
});
}

async function injectSSGToHtml() {
console.log("--ssg result--");
const {default: render} = await import(`./dist-ssg/entry.js`);
const template = await readFile(`./dist/index.html`, "utf-8");
console.log("--ssg result--");
const { default: render } = await import(`./dist-ssg/entry.js`);
const template = await readFile(`./dist/index.html`, "utf-8");

const urlEntryPoint = buildUrl ?? ["index"];
const urlEntryPoint = buildUrl ?? ["index"];

const promises = urlEntryPoint.map( async (path)=>{
const absolutePath = toAbsolute(`./dist/${path}.html`);
try {
const html = template.replace("<!--hydrate_root-->", render(path));
const promises = urlEntryPoint.map(async (path) => {
const absolutePath = toAbsolute(`./dist/${path}.html`);
try {
const html = template.replace("<!--hydrate_root-->", render(path));

const dir = dirname(absolutePath);
await mkdir(dir, { recursive: true });
await writeFile(absolutePath, html);
console.log(`pre-rendered : ${path}`);
} catch(e) {
console.log(`pre-rendered failed : ${path}`);
console.error(e);
}
} );
await Promise.allSettled(promises);
console.log("--successfully build completed!--");
const dir = dirname(absolutePath);
await mkdir(dir, { recursive: true });
await writeFile(absolutePath, html);
console.log(`pre-rendered : ${path}`);
} catch (e) {
console.log(`pre-rendered failed : ${path}`);
console.error(e);
}
});
await Promise.allSettled(promises);
console.log("--successfully build completed!--");
}

processBuild();
processBuild();
2 changes: 1 addition & 1 deletion packages/adminPage/src/features/users/Users.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default function Comments({ searchString, category }) {
return res;
})
.catch((e) => {
alert("통신 오류로 유저 목록 로드 실패.")
alert("통신 오류로 유저 목록 로드 실패.");
console.log(e);
return { users: [] };
}),
Expand Down
8 changes: 7 additions & 1 deletion packages/adminPage/src/shared/modals/AlertModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ function AlertModal({ title, description }) {
<div className="border-b border-neutral-200 flex justify-between">
<p className="text-body-l text-black font-bold ">{title}</p>
<button onClick={close} aria-label="닫기">
<img src="/shared/icons/close.svg" alt="닫기" width="24" height="24" draggable="false" />
<img
src="/shared/icons/close.svg"
alt="닫기"
width="24"
height="24"
draggable="false"
/>
</button>
</div>
<div className="text-body-s font-medium">{description}</div>
Expand Down
8 changes: 7 additions & 1 deletion packages/adminPage/src/shared/modals/ConfirmModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ function ConfirmModal({ title, description, onConfirm }) {
<div className="border-b border-neutral-200 flex justify-between">
<p className="text-body-l text-black font-bold ">{title}</p>
<button onClick={close} aria-label="닫기">
<img src="/shared/icons/close.svg" alt="닫기" width="24" height="24" draggable="false" />
<img
src="/shared/icons/close.svg"
alt="닫기"
width="24"
height="24"
draggable="false"
/>
</button>
</div>
<div className="text-body-s font-medium">{description}</div>
Expand Down
32 changes: 16 additions & 16 deletions packages/adminPage/vercel.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"rewrites": [
{
"source": "/api/:path*",
"destination": "http://softeerorange.store/api/:path*"
},
{
"source": "/events/:path*",
"destination": "/events/[id].html"
},
{
"source": "/comments/:path*",
"destination": "/comments/[id].html"
}
],
"cleanUrls": true
}
"rewrites": [
{
"source": "/api/:path*",
"destination": "http://softeerorange.store/api/:path*"
},
{
"source": "/events/:path*",
"destination": "/events/[id].html"
},
{
"source": "/comments/:path*",
"destination": "/comments/[id].html"
}
],
"cleanUrls": true
}
2 changes: 1 addition & 1 deletion packages/adminPage/vite-devRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ export default function devRouter(rawRouteList) {
});
},
};
}
}
18 changes: 9 additions & 9 deletions packages/adminPage/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { fileURLToPath } from "node:url";
import svgr from "vite-plugin-svgr";
import sharedAssetRouter from "@awesome-orange/common/sharedAssetRouter.js";

const __dirname = fileURLToPath(new URL('.', import.meta.url));
const __dirname = fileURLToPath(new URL(".", import.meta.url));

// https://vitejs.dev/config/
export default defineConfig({
Expand All @@ -15,13 +15,13 @@ export default defineConfig({
["/admin", "/admin.html"],
["/admin/*", "/admin.html"],
]),
react(),
react(),
svgr(),
sharedAssetRouter([
["/font", "/public/font"],
["/shared", "/public"],
["/mockServiceWorker.js", "/public/mockServiceWorker.js"]
])
["/mockServiceWorker.js", "/public/mockServiceWorker.js"],
]),
],
resolve: {
alias: [
Expand All @@ -33,9 +33,9 @@ export default defineConfig({
preview: {
proxy: {
"/api": {
target: 'http://softeerorange.store',
target: "http://softeerorange.store",
changeOrigin: true,
}
}
}
});
},
},
},
});
18 changes: 9 additions & 9 deletions packages/common/sharedAssetRouter.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { fileURLToPath } from "node:url";
import { join, extname } from "node:path";
import { join } from "node:path";
import { createReadStream } from "node:fs";
import { lookup } from "mime-types";

const __dirname = fileURLToPath(new URL('../../', import.meta.url));
const __dirname = fileURLToPath(new URL("../../", import.meta.url));

export default function sharedAssetRouter(paths) {
function foundRoute(path) {
Expand All @@ -25,20 +25,20 @@ export default function sharedAssetRouter(paths) {
const filePath = join(__dirname, originPath);

const stream = createReadStream(filePath);
stream.on("error", (err)=>{
if (err.code === 'ENOENT') {
stream.on("error", (err) => {
if (err.code === "ENOENT") {
res.statusCode = 404;
res.end('File not found');
res.end("File not found");
} else {
res.statusCode = 500;
res.end('Server error');
res.end("Server error");
}
})
});

const contentType = lookup(filePath);
res.setHeader('Content-Type', contentType);
res.setHeader("Content-Type", contentType);
stream.pipe(res);
});
},
};
}
}
12 changes: 6 additions & 6 deletions packages/common/tailwind.redefine.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ export default {
black: "#0D0D0D",
},
spacing: {
"11.5": "2.875rem", //46px
"15": "3.75rem", //60px
"17.5": "4.375rem", //70px
11.5: "2.875rem", //46px
15: "3.75rem", //60px
17.5: "4.375rem", //70px
},
fontSize: {
"detail-s": ["10px", "13px"],
Expand All @@ -77,9 +77,9 @@ export default {
"head-l": ["57px", "80px"],
},
transitionTimingFunction: {
'in-out-cubic': 'cubic-bezier(0.645, 0.045, 0.355, 1.000)'
"in-out-cubic": "cubic-bezier(0.645, 0.045, 0.355, 1.000)",
},
backgroundImage: {
"checked": "url('/shared/icons/checked.svg')"
}
checked: "url('/shared/icons/checked.svg')",
},
};
Loading

0 comments on commit ac5cb1a

Please sign in to comment.