fix(repository): make sure organization folder exists before creating folder into it or create it recusively
+ 20
- 6
@@ -1,5 +1,5 @@
 {
-  "_generatedAtUnix": 1663843732633,
+  "_generatedAtUnix": 1663845732496,
   "_hashAlgorithm": "sha1",
   "_version": 2,
   "islands": {

...
@@ -22,7 +22,7 @@
       "pathSourceMap": "./public/.islands/RepositoryCreateForm.bundle.js.map"
     },
     "RepositoryFilesDiffsList": {
-      "hash": "aa3f65c492e626fc1ea7d552bc6813bf6667914d",
+      "hash": "ab1579b7b0bfbe3f8af63352960a7b4c0e987971",
       "pathSource": "./app/islands/RepositoryFilesDiffsList.tsx",
       "pathBundle": "./public/.islands/RepositoryFilesDiffsList.bundle.js",
       "pathSourceMap": "./public/.islands/RepositoryFilesDiffsList.bundle.js.map"

app/islands/RepositoryFilesDiffsList.tsx
@@ -60,6 +60,12 @@ const RepositoryFilesDiffsList: ReactIsland<
                 >
                   View file (current ref)
                 </a>
+                <a
+                  href={`/${orgSlug}/${repoSlug}/main/tree/${diff.to}`}
+                  style={{ marginLeft: 16 }}
+                >
+                  View file (main)
+                </a>
               </div>
             </Grid.Row>
           </Grid.Col>

app/services/repository/createRepository.ts
@@ -1,4 +1,5 @@
 // std
+import { existsSync } from "node:fs";
 import { spawn } from "node:child_process";
 // 1st-party
 import type { ServiceMethodFactory } from "@ethicdevs/react-monolith";

...
@@ -6,6 +7,7 @@ import type { ServiceMethodFactory } from "@ethicdevs/react-monolith";
 import type { Repository } from "@prisma/client";
 // service
 import type { CreateRepositoryDTO, RepositoryServiceDeps } from "./types";
+import { mkdir } from "node:fs/promises";
 
 const makeCreateRepository: ServiceMethodFactory<
   RepositoryServiceDeps,

...
@@ -48,6 +50,15 @@ const makeCreateRepository: ServiceMethodFactory<
       `[ok] created repository in database with id "${newRepo.id}" and slug "${parentOrg.slug}/${newRepo.slug}"!`
     );
 
+    if (existsSync(orgRepositoriesDir.toString()) === false) {
+      console.log(`[..] creating organization directory...`);
+      await mkdir(orgRepositoriesDir.toString(), { recursive: true });
+      console.log(
+        `[ok] created organization directory in:`,
+        orgRepositoriesDir
+      );
+    }
+
     console.log(
       `[..] creating repository folder with "git init --bare --shared=group" in org directory:`,
       orgRepositoriesDir

@@ -8,10 +8,7 @@ export const ROOT_FOLDER = resolve(join(__dirname));
 // Where to get public content to serve static (fastify-static)
 // in prod it would be better to let that to nginx/whatever else
 export const PUBLIC_FOLDER_NAME = "public";
-export const PUBLIC_FOLDER =
-  process.env.NODE_ENV === "production"
-    ? resolve(join(ROOT_FOLDER, "..", PUBLIC_FOLDER_NAME))
-    : resolve(join(ROOT_FOLDER, PUBLIC_FOLDER_NAME));
+export const PUBLIC_FOLDER = resolve(join(ROOT_FOLDER, PUBLIC_FOLDER_NAME));
 // Where are external dependencies stored in public folder?
 // i.e; ${PUBLIC_FOLDER}/<ASSET_DEPS_FOLDER_NAME>/dep.env.js
 export const ASSET_DEPS_FOLDER_NAME = ".deps";