Skip to content

Commit

Permalink
Merge pull request #579 from VitNode/deployment/remove_force_files
Browse files Browse the repository at this point in the history
perf: Remove forced files from frontend package
  • Loading branch information
aXenDeveloper authored Nov 22, 2024
2 parents e562e99 + e908a2d commit 9d474a9
Show file tree
Hide file tree
Showing 12 changed files with 16 additions and 179 deletions.
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ services:
DB_HOST: ${DB_HOST:-database}
env_file:
- .env
command: sh -c "cd apps/backend && pnpm config:init && node dist/main.js"
command: sh -c "cd apps/backend && npm run config:init && node dist/main.js"
ports:
- '8080:8080'
volumes:
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"license": "MIT",
"scripts": {
"config:init:skip-database": "cd apps/backend && pnpm config:init --skip-database && cd ../..",
"config:init": "turbo config:init",
"build:scripts": "turbo build:scripts && pnpm i",
"build": "turbo build:packages && turbo build",
"build:packages": "turbo build:packages",
Expand Down
6 changes: 3 additions & 3 deletions packages/create-vitnode-app/helpers/create-packages-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ export const createPackagesJSON = ({
version: '1.0.0',
private: true,
scripts: {
'config:init': 'vitnode-frontend init',
dev: 'vitnode-frontend dev && next dev --turbo',
postinstall: 'vitnode-frontend init',
dev: 'next dev --turbo',
build: 'next build',
start: 'next start',
'start:prod': 'node server.js',
Expand Down Expand Up @@ -133,7 +133,7 @@ export const createPackagesJSON = ({
scripts: {
'drizzle-kit': 'drizzle-kit',
'config:init': 'vitnode-backend init',
dev: 'pnpm config:init && cross-env NODE_ENV=development nest start -w',
dev: 'vitnode-backend init && cross-env NODE_ENV=development nest start -w',
build: 'nest build',
start: 'node dist/main',
lint: 'eslint .',
Expand Down
2 changes: 0 additions & 2 deletions packages/create-vitnode-app/templates/docker/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ fi
# ================================
# Install Nginx
sudo apt install nginx -y
# Allow Nginx through the firewall
sudo ufw allow 'Nginx HTTP'

# Delete the default Nginx configuration file if it exists
if [ -f /etc/nginx/sites-available/default ]; then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ services:
DB_HOST: ${DB_HOST:-database}
env_file:
- .env
command: sh -c "cd apps/backend && pnpm config:init && node dist/main.js"
command: sh -c "cd apps/backend && npm run config:init && node dist/main.js"
ports:
- '8080:8080'
volumes:
Expand Down
132 changes: 0 additions & 132 deletions packages/frontend/scripts/helpers/check-files-and-filter-if-exist.ts

This file was deleted.

34 changes: 0 additions & 34 deletions packages/frontend/scripts/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import * as fs from 'fs';
import { join } from 'path';

import { checkFilesAndFilterIfExist } from './helpers/check-files-and-filter-if-exist';

const init = ({ dev }: { dev: boolean }) => {
const initConsole = '\x1b[34m[VitNode]\x1b[0m \x1b[33m[Frontend]\x1b[0m';

Expand Down Expand Up @@ -34,10 +32,6 @@ const init = ({ dev }: { dev: boolean }) => {
file: string;
path: string;
}[] = [
{
path: join('src', 'app'),
file: 'not-found.tsx',
},
{
path: join('src', 'plugins', 'core', 'langs'),
file: 'en.json',
Expand All @@ -48,41 +42,13 @@ const init = ({ dev }: { dev: boolean }) => {
},
];

// Stage 2 - Force files
forcePathFiles.forEach(file => {
const packageFromCopyPath = join(packagePath, file.path, file.file);
const rootToCopyPath = join(process.cwd(), file.path, file.file);

fs.copyFileSync(packageFromCopyPath, rootToCopyPath);
});

// Stage 3 - Force copy folders
const forceCopyFolders = [
join('src', 'app', '[locale]', 'admin', '(vitnode)'),
join('src', 'app', '[locale]', 'admin', '(auth)', '(vitnode)'),
];

// Stage 4 - Force folders
forceCopyFolders.forEach(folder => {
const packageFromCopyPath = join(packagePath, folder);
const rootToCopyPath = join(process.cwd(), folder);

fs.cpSync(packageFromCopyPath, rootToCopyPath, { recursive: true });
});

// Stage 5 - Copy folders if not exist
const foldersOptional = checkFilesAndFilterIfExist(
packagePath,
process.cwd(),
);

foldersOptional.forEach(folder => {
const packageFromCopyPath = join(packagePath, folder);
const rootToCopyPath = join(process.cwd(), folder);

fs.cpSync(packageFromCopyPath, rootToCopyPath, { recursive: true });
});

console.log(`${initConsole} ✅ Frontend files copied successfully.`);
process.exit(0);
};
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/api/fetcher-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export async function fetcherClient<
res: Response;
}> {
const query = queryFromArgs ? buildFilteredQuery(queryFromArgs) : '';
const href = `${CONFIG.backend_url}${url}${query ? `?${query}` : ''}`;
const href = `${CONFIG.backend_client_url}${url}${query ? `?${query}` : ''}`;
const method = options?.method ?? 'GET';
const res = await fetch(href, {
...options,
Expand Down
3 changes: 2 additions & 1 deletion packages/frontend/src/helpers/config-with-env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ const urls = {

export const CONFIG = {
backend_url: urls.backend.origin,
backend_client_url: urls.backend_client.origin,
frontend_url: urls.frontend.origin,
backend_public_url: `${urls.backend_client.origin}/public`,
backend_public_url: `${urls.backend.origin}/public`,
local_storage: {
editor_skin_tone: 'emoji:skin-tone',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const SearchSidebarAdmin = ({
return (
<div className="px-3 py-2">
<button
className="bg-secondary/50 text-muted-foreground hover:bg-accent hover:text-accent-foreground flex w-full items-center gap-2 rounded-lg border p-1.5 text-sm transition-colors max-md:hidden"
className="bg-secondary/50 text-muted-foreground hover:bg-accent hover:text-accent-foreground flex w-full items-center gap-2 rounded-lg border p-1.5 text-sm transition-colors"
data-search-full=""
onClick={() => {
setOpen(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import { Drawer, DrawerContent, DrawerTrigger } from '@/components/ui/drawer';
import { AvatarUser } from '@/components/ui/user/avatar';
import { useMiddlewareData } from '@/hooks/use-middleware-data';
import { useSession } from '@/hooks/use-session';
import { usePathname, useRouter } from '@/navigation';
import { DialogDescription, DialogTitle } from '@radix-ui/react-dialog';
Expand All @@ -19,6 +20,7 @@ export const NavBarMobile = () => {
const { user } = useSession();
const pathname = usePathname();
const { back } = useRouter();
const { nav } = useMiddlewareData();

return (
<>
Expand All @@ -45,9 +47,7 @@ export const NavBarMobile = () => {
</VisuallyHidden>

<UserHeaderNavBarMobile />

<NavNavBarMobile />

{nav.length > 0 && <NavNavBarMobile />}
{user && <UserFooterNavBarMobile />}
</DrawerContent>
</Drawer>
Expand Down
3 changes: 3 additions & 0 deletions turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
"lint:fix": {
"dependsOn": ["^lint:fix"]
},
"config:init": {
"dependsOn": ["^config:init"]
},
"dev:packages": {
"cache": false,
"persistent": true
Expand Down

0 comments on commit 9d474a9

Please sign in to comment.