Skip to content

Commit

Permalink
getting rid of 'graceful-fs' and everything is working here
Browse files Browse the repository at this point in the history
  • Loading branch information
danielc-n committed Oct 1, 2024
1 parent 02b264a commit f62e774
Show file tree
Hide file tree
Showing 70 changed files with 135 additions and 137 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,6 @@ jobs:
- name: install dependencies
run: yarn install

- name: increase max file opened
run: ulimit -n 1048576

- name: install wine
run: |
sudo dpkg --add-architecture i386
Expand Down
2 changes: 1 addition & 1 deletion e2e-tests/base.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
createUser, projectPageExpect
} from './common';

const fs = require('graceful-fs');
const fs = require('fs');
const path = require('path');
const { _electron: electron } = require('@playwright/test');

Expand Down
46 changes: 35 additions & 11 deletions main/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Native
require('@electron/remote/main').initialize();
const path = require('path');
const fs = require('graceful-fs').promises;
const fs = require('fs');
const { format } = require('url');
const { install } = require('@puppeteer/browsers');
const config = require("dotenv");
Expand All @@ -21,14 +21,14 @@ function isDev() {

async function setPermissions(chromePath) {
try {
await fs.chmod(chromePath, '755'); // Set the permissions to be executable
fs.chmodSync(chromePath, '755'); // Set the permissions to be executable
console.log(`Permissions set for: ${chromePath}`);
} catch (err) {
console.error(`Failed to set permissions for ${chromePath}: `, err);
}
}

async function getChromeCacheDir() {
function getChromeCacheDir() {
// Use Electron's app.getPath to get the userData directory (persistent)
const dataDir = app.getPath('appData');

Expand All @@ -37,28 +37,45 @@ async function getChromeCacheDir() {

// Create the folder if it doesn't exist
try {
await fs.access(chromeDataDir);
fs.accessSync(chromeDataDir);
} catch (err) {
// If the directory doesn't exist, create it
await fs.mkdir(chromeDataDir, { recursive: true });
fs.mkdirSync(chromeDataDir, { recursive: true });
console.log(`Created persistent Chrome data directory at: ${chromeDataDir}`);
}

return chromeDataDir;
}

function getChromeExecutablePath(platform, chromeDir, platformDir) {
let executableName = '';
if (platform === 'linux') {
executableName = 'chrome-linux64/chrome';
} else if (platform === 'darwin') {
executableName = 'chrome-mac/Chromium.app/Contents/MacOS/Chromium';
} else if (platform === 'win64') {
executableName = 'chrome-win64/chrome.exe';
}

return path.join(chromeDir, platformDir, executableName);
}

async function verifyAndInstallChrome(version) {
const platform = process.platform === 'win32' ? 'win64' : process.platform;

// Get the persistent directory
const cacheDir = await getChromeCacheDir();
const bPath = path.join(cacheDir, `chrome/${platform}-${version}`);
const cacheDir = getChromeCacheDir();
const chromeDir = path.join(cacheDir, 'chrome');
const platformDir = `${platform}-${version}`;

const chromeExecutablePath = getChromeExecutablePath(platform, chromeDir, platformDir);


// Check if the browser is already installed
try {
await fs.access(bPath);
fs.accessSync(chromeExecutablePath);
console.log(`Chrome version ${version} is already installed.`);
browserPath = bPath;
browserPath = chromeExecutablePath;
} catch (err) {
console.log(`Chrome version ${version} is not installed. Installing now...`);
await install({
Expand All @@ -67,10 +84,17 @@ async function verifyAndInstallChrome(version) {
buildId: version,
platform,
}).then((res) => {
browserPath = res.path;
const installedChromePath = getChromeExecutablePath(platform, chromeDir, platformDir);
if (fs.existsSync(installedChromePath)) {
browserPath = installedChromePath;
console.log(`Chrome version ${version} has been installed to ${browserPath}.`);
}
let bet = res.path;
console.log("## browserPath ==",bet);
setPermissions(browserPath);
}).catch((err) => {
throw new Error(`Failed to install Chrome version ${version}`);
});
console.log(`Chrome version ${version} has been installed.`);
}
}

Expand Down
10 changes: 0 additions & 10 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,6 @@ const nextConfig = {
config.resolve.alias.canvas = false;
}

config.optimization = {
...config.optimization,
minimize: true,
minimizer: [
new TerserPlugin({
parallel: 1,
}),
],
};

config.module.rules.push({
test: /\.md$/,
use: 'raw-loader',
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@
"fs-extra": "^10.1.0",
"get-system-fonts": "^2.0.2",
"gitea-react-toolkit": "2.1.2",
"graceful-fs": "^4.2.11",
"history": "^5.3.0",
"i18next": "^21.8.9",
"ionicons": "^7.1.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const AudioEditor = ({ editor }) => {
// Checking whether the selected book and chapter is in the scope or not
if (key === bookId.toUpperCase() && _data.type.flavorType.currentScope[key].includes(chapter)) {
_books.push(bookId.toUpperCase());
const fs = window.require('graceful-fs');
const fs = window.require('fs');
const path = require('path');
let bookContent = [];
const exists = fs.existsSync(path.join(projectsDir, 'text-1', 'ingredients', `${bookId.toUpperCase()}.usfm`));
Expand Down
8 changes: 4 additions & 4 deletions renderer/src/components/EditorPage/AudioEditor/MainPlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const MainPlayer = () => {

const loadChapter = async () => {
if (audioCurrentChapter) {
const fs = window.require('graceful-fs');
const fs = window.require('fs');
const path = require('path');
// Fetching the Audios
const chapters = await fs.readdirSync(path.join(audioCurrentChapter.filePath, audioCurrentChapter.chapterNum));
Expand Down Expand Up @@ -101,7 +101,7 @@ const MainPlayer = () => {

// Setting up the default audio from the takes
const changeDefault = (value) => {
const fs = window.require('graceful-fs');
const fs = window.require('fs');
const path = require('path');
let i = 1;
// Checking whether the take has any audio
Expand All @@ -126,7 +126,7 @@ const MainPlayer = () => {
.then(({
projectsDir, path,
}) => {
const fs = window.require('graceful-fs');
const fs = window.require('fs');
const result = take.replace(/take/g, '');
// Fetching the mp3 files
const folderName = fs.readdirSync(path.join(projectsDir, 'audio', 'ingredients', bookId.toUpperCase(), chapter));
Expand Down Expand Up @@ -178,7 +178,7 @@ const MainPlayer = () => {
const handleFunction = () => {
// We have used trigger to identify whether the call is from DeleteAudio or Re-record
if (trigger === 'delete') {
const fs = window.require('graceful-fs');
const fs = window.require('fs');
const path = require('path');
const result = take.replace(/take/g, '');
let versePosition;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const ReferenceAudio = ({
setIsLoading(true);
setDisplayScreen(false);
setBookData();
const fs = window.require('graceful-fs');
const fs = window.require('fs');
const path = require('path');
const newpath = localStorage.getItem('userPath');
// Fetching the reference list
Expand Down
2 changes: 1 addition & 1 deletion renderer/src/components/EditorPage/Reference/OBS/ObsTn.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function ObsTnCard({
try {
localForage.getItem('userProfile').then(async (user) => {
logger.debug('OfflineResourceFetch.js', 'reading offline obs-tn ', offlineResource.data?.projectDir);
const fs = window.require('graceful-fs');
const fs = window.require('fs');
const path = require('path');
const newpath = localStorage.getItem('userPath');
const currentUser = user?.username;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export default function TaNavigation({ languageId, referenceResources }) {
// console.log('offline data : ', { taList, offlineResource });
localForage.getItem('userProfile').then(async (user) => {
logger.debug('TaNavigation.js', 'reading offline helps ', offlineResource.data?.projectDir);
const fs = window.require('graceful-fs');
const fs = window.require('fs');
const path = require('path');
const newpath = localStorage.getItem('userPath');
const currentUser = user?.username;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default function TwNavigation({ languageId, referenceResources, setRefere
if (referenceResources && referenceResources?.offlineResource?.offline) {
const { offlineResource } = referenceResources;
localForage.getItem('userProfile').then(async (user) => {
const fs = window.require('graceful-fs');
const fs = window.require('fs');
const path = require('path');
const newpath = localStorage.getItem('userPath');
const currentUser = user?.username;
Expand Down Expand Up @@ -97,7 +97,7 @@ export default function TwNavigation({ languageId, referenceResources, setRefere
const taArrayOffline = [];
const { offlineResource } = referenceResources;
localForage.getItem('userProfile').then(async (user) => {
const fs = window.require('graceful-fs');
const fs = window.require('fs');
const path = require('path');
const newpath = localStorage.getItem('userPath');
const currentUser = user?.username;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export default function TranslationHelpsCard({
setOfflineItems('');
localForage.getItem('userProfile').then(async (user) => {
logger.debug('TranslationHelpsCard.js', `reading offline helps ${offlineResource.data?.projectDir}`);
const fs = window.require('graceful-fs');
const fs = window.require('fs');
const path = require('path');
const newpath = localStorage.getItem('userPath');
const currentUser = user?.username;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ const UsfmEditor = () => {
const username = value?.username;
localforage.getItem('currentProject').then((projectName) => {
const path = require('path');
const fs = window.require('graceful-fs');
const fs = window.require('fs');
const newpath = localStorage.getItem('userPath');
const projectsDir = path.join(newpath, packageInfo.name, 'users', username, 'projects', projectName);
const metaPath = path.join(newpath, packageInfo.name, 'users', username, 'projects', projectName, 'metadata.json');
Expand Down
2 changes: 1 addition & 1 deletion renderer/src/components/Login/LeftLogin.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ const LeftLogin = () => {
// router.push('/main');
// The below code is commented for UI dev purpose.
if (handleValidation(values)) {
const fs = window.require('graceful-fs');
const fs = window.require('fs');
logger.debug(
'LeftLogin.js',
'Triggers handleLogin to check whether the user is existing or not',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ const getDirectories = (readdirSync, source) => readdirSync(source, { withFileTy
export const getScope = async (project) => {
const path = require('path');
const scope = {};
const { readdirSync } = window.require('graceful-fs');
const fs = window.require('graceful-fs');
const { readdirSync } = window.require('fs');
const fs = window.require('fs');
const list = getDirectories(readdirSync, project);

list.forEach(async (book) => {
Expand Down Expand Up @@ -43,7 +43,7 @@ export const readProjectScope = async (projectName) => {
logger.debug('readProjectScope.js', `In read metadata - ${projectName}`);
const currentUser = await localForage.getItem('userProfile');
const newpath = localStorage.getItem('userPath');
const fs = window.require('graceful-fs');
const fs = window.require('fs');
const path = require('path');
const file = path.join(newpath, packageInfo.name, 'users', currentUser.username, 'projects');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const updateBurritoScope = async (projectName, metadata) => {
logger.debug('updateBurritoScope.js', `In update metadata - ${projectName}`);
const currentUser = await localForage.getItem('userProfile');
const newpath = localStorage.getItem('userPath');
const fs = window.require('graceful-fs');
const fs = window.require('fs');
const path = require('path');
const file = path.join(newpath, packageInfo.name, 'users', currentUser.username, 'projects');
// Finally updating the scope in the metadata
Expand Down
2 changes: 1 addition & 1 deletion renderer/src/components/Projects/ImportPopUp.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export default function ImportPopUp(props) {

const importFiles = (folderPath) => {
logger.debug('ImportPopUp.js', 'Inside importFiles');
const fs = window.require('graceful-fs');
const fs = window.require('fs');
const files = [];
const bookCodeList = [];
folderPath.forEach((filePath) => {
Expand Down
2 changes: 1 addition & 1 deletion renderer/src/components/Projects/hooks/useEditProject.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const useEditProject = () => {
const userProfile = await localforage.getItem('userProfile');

if (isElectron()) {
const fs = window.require('graceful-fs');
const fs = window.require('fs');
const newpath = localStorage.getItem('userPath');
folder = path.join(newpath, packageInfo.name, 'users', userProfile.username, 'projects', `${project.name}_${project.id[0]}`);
data = fs.readFileSync(path.join(folder, 'metadata.json'), 'utf-8');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export default function AdvancedSettingsDropdown({ call, project, projectType })
if (isElectron()) {
let title = licenceTitle;
let myLicence = {};
const fs = window.require('graceful-fs');
const fs = window.require('fs');
if ((title === 'Custom' || !title) && !selectNew) {
myLicence.title = 'Custom';
myLicence.locked = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const checkandDownloadObsImages = async () => {
// check for the folder and images
// const imageCdnBaseUrl = 'https://cdn.door43.org/obs/jpg/360px/';
if (isElectron()) {
const fs = window.require('graceful-fs');
const fs = window.require('fs');
const path = require('path');
const newpath = localStorage.getItem('userPath');
const obsImagePath = path.join(newpath, packageInfo.name, 'common', environment.OBS_IMAGE_DIR);
Expand Down
4 changes: 2 additions & 2 deletions renderer/src/components/Resources/ImportResource.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default function ImportResource({
};

const importReference = async (projectsDir, name, burritoType) => {
const fs = window.require('graceful-fs');
const fs = window.require('fs');
const fse = window.require('fs-extra');
const path = require('path');
let dirPath;
Expand Down Expand Up @@ -84,7 +84,7 @@ export default function ImportResource({
setFolderPath('');
};
const uploadRefBible = async () => {
const fs = window.require('graceful-fs');
const fs = window.require('fs');
const path = require('path');
try {
const user = await localforage.getItem('userProfile');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const DownloadCreateSBforHelps = async (projectResource, setLoading, update = fa
setLoading(true);
await localForage.getItem('userProfile').then(async (user) => {
logger.debug('DownloadCreateSBforHelps.js', 'In helps-resource download user fetch - ', user?.username);
const fs = window.require('graceful-fs');
const fs = window.require('fs');
const path = require('path');
const newpath = localStorage.getItem('userPath');
const folder = path.join(newpath, packageInfo.name, 'users', `${user?.username}`, 'resources');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ function RemoveResource({
logger.warn('removeResource.js', 'inside removing resource call');
localForage.getItem('userProfile').then(async (user) => {
logger.debug('DownloadResourcePopUp.js', 'In resource download user fetch - ', user?.username);
const fs = window.require('graceful-fs');
const fs = window.require('fs');
const newpath = localStorage.getItem('userPath');
const folder = path.join(newpath, packageInfo.name, 'users', `${user?.username}`, 'resources');
let resourceName = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export const generateResourceIngredientsTextTransaltion = async (currentResource
// generating ingredients content in metadata
currentResourceMeta?.projects.forEach(async (project) => {
logger.debug('createDownloadedResourceSB.js', 'In adding ingredients to burrito for TextTransaltion');
const fs = window.require('graceful-fs');
const fs = window.require('fs');
if (fs.existsSync(path.join(folder, currentResourceProject.name, project.path))) {
const filecontent = await fs.readFileSync(path.join(folder, currentResourceProject.name, project.path), 'utf8');
// find checksum & size by reading the file
Expand All @@ -184,7 +184,7 @@ export const generateResourceIngredientsTextTransaltion = async (currentResource
export const generateResourceIngredientsOBS = async (currentResourceMeta, path, folder, currentResourceProject, resourceBurritoFile, files) => {
logger.debug('createDownloadedResourceSB.js', 'In adding ingredients to burrito of OBS');
files.forEach(async (file) => { // en_obs/content/01.md, en_obs/content/front/title.md
const fs = window.require('graceful-fs');
const fs = window.require('fs');
const endPart = file.split('/').pop();
const regX = /^\d{2}.md$/;
if (regX.test(endPart) || ['intro.md', 'title.md'].indexOf(endPart) > -1) {
Expand Down Expand Up @@ -272,7 +272,7 @@ export const handleDownloadResources = async (resourceData, selectResource, acti
localForage.getItem('userProfile').then(async (user) => {
logger.debug('createDownloadedResourceSB.js', 'In create downloaded resource SB user fetch - ', user?.username);
const folder = path.join(newpath, packageInfo.name, 'users', `${user?.username}`, 'resources');
const fs = window.require('graceful-fs');
const fs = window.require('fs');
let resourceBurritoFile = {};
let currentResourceMeta = '';
let currentResourceProject = '';
Expand Down
2 changes: 1 addition & 1 deletion renderer/src/components/Resources/useReadLocalResources.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { createDirectory, newPath } from '../../../../supabase';
export default async function readLocalResources(username, setSubMenuItems) {
if (isElectron()) {
const parseData = [];
const fs = window.require('graceful-fs');
const fs = window.require('fs');
const path = require('path');
const newpath = localStorage.getItem('userPath');
const projectsDir = path.join(newpath, packageInfo.name, 'users', username, 'resources');// Read user resources
Expand Down
Loading

0 comments on commit f62e774

Please sign in to comment.