Skip to content

Commit

Permalink
Merge pull request #29 from yakisova41/publicdir-cant-load
Browse files Browse the repository at this point in the history
Publicdir cant load
  • Loading branch information
yakisova41 authored Apr 2, 2024
2 parents e3ff5c8 + 83a98a3 commit 6c22891
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
7 changes: 4 additions & 3 deletions packages/crx-monkey/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,13 @@ async function search(dir: string): Promise<string | null> {
}

function isKeyof<T>(obj: object, key: T | string): key is T {
Object.entries(obj).forEach(([objkey]) => {
let result = false;
Object.keys(obj).forEach((objkey) => {
if (key === objkey) {
return true;
result = true;
}
});
return false;
return result;
}

function setDefaultConfig(config: Record<string, never>) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import express from 'express';
import { getConfig } from 'src/node/config';
import path from 'path';
import fse from 'fs-extra';

export class ScriptHostingServer {
private readonly app: express.Express;
Expand Down Expand Up @@ -30,17 +31,24 @@ export class ScriptHostingServer {
});

this.app.get('/userscript', (req, res) => {
if (config.userscriptOutput !== undefined) {
res.sendFile(config.userscriptOutput);
const filepath = path.join(path.dirname(config.manifestJsonPath), config.userscriptOutput);

if (fse.existsSync(filepath)) {
res.sendFile(filepath);
} else {
res.send(400);
}
});

this.app.get('/dev.user.js', (req, res) => {
if (config.userscriptOutput !== undefined) {
const userscriptDir = path.dirname(config.userscriptOutput);
res.sendFile(path.join(userscriptDir, 'crx-monkey-dev.user.js'));
const filepath = path.join(
path.dirname(config.manifestJsonPath),
path.dirname(config.userscriptOutput),
'crx-monkey-dev.user.js',
);

if (fse.existsSync(filepath)) {
res.sendFile(filepath);
} else {
res.send(400);
}
Expand Down
9 changes: 2 additions & 7 deletions packages/crx-monkey/src/node/handlers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,8 @@ export function getlocalesPath() {

export function copyPublic() {
const config = getConfig();
const publicDir = config.publicDir;

if (
publicDir !== undefined &&
fse.pathExistsSync(publicDir) &&
config.chromeOutputDir !== undefined
) {
const publicDir = path.join(process.cwd(), config.publicDir);
if (publicDir !== undefined && fse.pathExistsSync(publicDir)) {
fse.copy(publicDir, path.join(config.chromeOutputDir, path.basename(publicDir)));
}
}

0 comments on commit 6c22891

Please sign in to comment.