feat: add repo.json to .gitignore #12

This commit is contained in:
bsourisse 2022-12-20 14:54:30 +01:00
parent 199fe64ae6
commit 332b484106
3 changed files with 13 additions and 5 deletions

4
.gitignore vendored
View file

@ -103,6 +103,8 @@ dist
# TernJS port file
.tern-port
# local env files
.env*.local
# config file for BorgWarehouse
config/repo.json

View file

@ -1 +0,0 @@
[]

View file

@ -1,4 +1,4 @@
import { promises as fs } from 'fs';
import fs from 'fs';
import path from 'path';
import { authOptions } from '../../../pages/api/auth/[...nextauth]';
import { unstable_getServerSession } from 'next-auth/next';
@ -17,8 +17,15 @@ export default async function handler(req, res) {
//console.log('API call (GET)');
//Find the absolute path of the json directory
const jsonDirectory = path.join(process.cwd(), '/config');
//Read the json data file data.json
let repoList = await fs.readFile(
//Check if the repo.json file exists and initialize it if not.
if (!fs.existsSync(jsonDirectory + '/repo.json')) {
fs.writeFileSync(
jsonDirectory + '/repo.json',
JSON.stringify([])
);
}
//Read the file repo.json
let repoList = await fs.promises.readFile(
jsonDirectory + '/repo.json',
'utf8'
);