Skip to content

Commit

Permalink
Cleanup for local paths (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
soulgalore authored May 24, 2024
1 parent 3e3f289 commit 8fa7c87
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import nconf from 'nconf';
import yaml from 'js-yaml';

import { SitespeedioServer } from './src/server.js';
import { getLocalFilePath } from './src/util/fileutil.js';
import { getBaseFilePath } from './src/util/fileutil.js';

const require = createRequire(import.meta.url);
const version = require('./package.json').version;
const defaultConfig = getLocalFilePath('../../config/default.yaml');
const defaultConfig = getBaseFilePath('./config/default.yaml');

nconf.argv();

Expand Down
4 changes: 2 additions & 2 deletions server/src/util/add-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
getDeviceQueue
} from '../queuehandler.js';
import { setConfigById } from '../configs.js';
import { getLocalFilePath } from './fileutil.js';
import { getBaseFilePath } from './fileutil.js';

const logger = log.getLogger('sitespeedio.server');

Expand All @@ -31,7 +31,7 @@ async function getDefaultSitespeedConfiguration() {
return JSON.parse(result.toString());
}
const result = await readFile(
path.resolve(getLocalFilePath('../../config/sitespeed.json'))
path.resolve(getBaseFilePath('./config/sitespeed.json'))
);
return JSON.parse(result.toString());
}
Expand Down
4 changes: 2 additions & 2 deletions server/src/util/fileutil.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
import path from 'node:path';

export function getLocalFilePath(thePath) {
export function getBaseFilePath(theFile) {
const currentFileUrl = import.meta.url;
const currentFilePath = fileURLToPath(currentFileUrl);
const currentDirectory = dirname(currentFilePath);
return path.resolve(currentDirectory, thePath);
return path.resolve(currentDirectory, '../../', theFile);
}
4 changes: 2 additions & 2 deletions server/src/util/text.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import nconf from 'nconf';
import y18n from 'y18n';
import { getLocalFilePath } from './fileutil.js';
import { getBaseFilePath } from './fileutil.js';
const locale = nconf.get('localization:defaultLocale');
const directory =
nconf.get('localization:directory') || getLocalFilePath('../../locales');
nconf.get('localization:directory') || getBaseFilePath('./locales');

const myy18n = y18n({ updateFiles: false, locale, directory });

Expand Down
4 changes: 2 additions & 2 deletions server/src/webserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { api } from './routes/api/api.js';
import { BasicAuth } from './middleware/basicauth.js';
import { error404, error500 } from './middleware/errorhandler.js';
import { setupStatic } from './static/index.js';
import { getLocalFilePath } from './util/fileutil.js';
import { getBaseFilePath } from './util/fileutil.js';

const logger = log.getLogger('sitespeedio.server');

Expand All @@ -46,7 +46,7 @@ function setupExpressServer() {
app.use(express.json());

app.set('view engine', 'pug');
app.set('views', path.resolve(getLocalFilePath('../../views')));
app.set('views', path.resolve(getBaseFilePath('./views')));

app.enable('view cache');

Expand Down
4 changes: 2 additions & 2 deletions testrunner/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ const version = require('./package.json').version;

import { SitespeedioTestRunner } from './src/sitespeedio-testrunner.js';
import { validate } from './src/validateconfig.js';
import { getLocalFilePath } from './src/util.js';
import { getBaseFilePath } from './src/util.js';

const defaultConfig = getLocalFilePath('../config/default.yaml');
const defaultConfig = getBaseFilePath('./config/default.yaml');

function getFilteredConfig() {
const config = nconf.get();
Expand Down
4 changes: 2 additions & 2 deletions testrunner/src/testrunners/testrunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import log from 'intel';
import nconf from 'nconf';

import { queueHandler } from '../queue/queuehandler.js';
import { getLocalFilePath } from '../util.js';
import { getBaseFilePath } from '../util.js';
const { join } = path;

/**
Expand Down Expand Up @@ -103,7 +103,7 @@ function prepareSitespeedConfig(job) {

jobConfig.extends =
nconf.get('sitespeedioConfigFile') === undefined
? getLocalFilePath('../config/sitespeedDefault.json')
? getBaseFilePath('./config/sitespeedDefault.json')
: path.resolve(nconf.get('sitespeedioConfigFile'));

return jobConfig;
Expand Down
4 changes: 2 additions & 2 deletions testrunner/src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
import path from 'node:path';

export function getLocalFilePath(thePath) {
export function getBaseFilePath(theFile) {
const currentFileUrl = import.meta.url;
const currentFilePath = fileURLToPath(currentFileUrl);
const currentDirectory = dirname(currentFilePath);
return path.resolve(currentDirectory, thePath);
return path.resolve(currentDirectory, '../', theFile);
}

0 comments on commit 8fa7c87

Please sign in to comment.