mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
change: Use @css: instead of $PACKAGE_ROOT/
This makes usage from the command line easier, since $ is typically used to mark variables.
This commit is contained in:
@@ -5,9 +5,11 @@ import type { IComponentsManagerBuilderOptions, LogLevel } from 'componentsjs';
|
||||
import { ComponentsManager } from 'componentsjs';
|
||||
import yargs from 'yargs';
|
||||
import { getLoggerFor } from '../logging/LogUtil';
|
||||
import { ensureTrailingSlash, resolveAssetPath } from '../util/PathUtil';
|
||||
import { ensureTrailingSlash, resolveAssetPath, modulePathPlaceholder } from '../util/PathUtil';
|
||||
import type { App } from './App';
|
||||
|
||||
const defaultConfig = `${modulePathPlaceholder}config/default.json`;
|
||||
|
||||
export interface CliParams {
|
||||
loggingLevel: string;
|
||||
port: number;
|
||||
@@ -72,7 +74,7 @@ export class AppRunner {
|
||||
})
|
||||
.options({
|
||||
baseUrl: { type: 'string', alias: 'b', requiresArg: true },
|
||||
config: { type: 'string', alias: 'c', requiresArg: true },
|
||||
config: { type: 'string', alias: 'c', default: defaultConfig, requiresArg: true },
|
||||
loggingLevel: { type: 'string', alias: 'l', default: 'info', requiresArg: true },
|
||||
mainModulePath: { type: 'string', alias: 'm', requiresArg: true },
|
||||
port: { type: 'number', alias: 'p', default: 3000, requiresArg: true },
|
||||
@@ -89,7 +91,7 @@ export class AppRunner {
|
||||
dumpErrorState: true,
|
||||
logLevel: params.loggingLevel as LogLevel,
|
||||
};
|
||||
const configFile = resolveAssetPath(params.config ?? '$PACKAGE_ROOT/config/default.json');
|
||||
const configFile = resolveAssetPath(params.config);
|
||||
|
||||
// Create and execute the app
|
||||
this.createApp(loaderProperties, configFile, params)
|
||||
|
||||
@@ -29,7 +29,7 @@ interface TemplateResourceLink extends ResourceLink {
|
||||
* A FileIdentifierMapper will be used to generate identifiers that correspond to the relative structure.
|
||||
*
|
||||
* A relative `templateFolder` is resolved relative to cwd,
|
||||
* unless it's preceded by $PACKAGE_ROOT/, e.g. $PACKAGE_ROOT/foo/bar.
|
||||
* unless it's preceded by `@css:`, e.g. `@css:foo/bar`.
|
||||
*/
|
||||
export class TemplatedResourcesGenerator implements ResourcesGenerator {
|
||||
private readonly templateFolder: string;
|
||||
|
||||
@@ -14,7 +14,7 @@ import type { HttpRequest } from '../HttpRequest';
|
||||
/**
|
||||
* Handler that serves static resources on specific paths.
|
||||
* Relative file paths are assumed to be relative to cwd.
|
||||
* Relative file paths can be preceded by $PACKAGE_ROOT/, e.g. $PACKAGE_ROOT/foo/bar,
|
||||
* Relative file paths can be preceded by `@css:`, e.g. `@css:foo/bar`,
|
||||
* in case they need to be relative to the module root.
|
||||
*/
|
||||
export class StaticAssetHandler extends HttpHandler {
|
||||
|
||||
@@ -5,6 +5,7 @@ import type { Representation } from '../../ldp/representation/Representation';
|
||||
import { INTERNAL_ERROR } from '../../util/ContentTypes';
|
||||
import { HttpError } from '../../util/errors/HttpError';
|
||||
import { InternalServerError } from '../../util/errors/InternalServerError';
|
||||
import { modulePathPlaceholder } from '../../util/PathUtil';
|
||||
import type { TemplateEngine } from '../../util/templates/TemplateEngine';
|
||||
import type { RepresentationConverterArgs } from './RepresentationConverter';
|
||||
import { TypedRepresentationConverter } from './TypedRepresentationConverter';
|
||||
@@ -18,8 +19,8 @@ export interface TemplateOptions {
|
||||
}
|
||||
|
||||
const DEFAULT_TEMPLATE_OPTIONS: TemplateOptions = {
|
||||
mainTemplatePath: '$PACKAGE_ROOT/templates/error/main.md.hbs',
|
||||
codeTemplatesPath: '$PACKAGE_ROOT/templates/error/descriptions/',
|
||||
mainTemplatePath: `${modulePathPlaceholder}templates/error/main.md.hbs`,
|
||||
codeTemplatesPath: `${modulePathPlaceholder}templates/error/descriptions/`,
|
||||
extension: '.md.hbs',
|
||||
contentType: 'text/markdown',
|
||||
};
|
||||
|
||||
@@ -173,16 +173,20 @@ export function getModuleRoot(): string {
|
||||
return joinFilePath(__dirname, '../../');
|
||||
}
|
||||
|
||||
const modulePath = '$PACKAGE_ROOT/';
|
||||
/**
|
||||
* A placeholder for the path to the `@solid/community-server` module root.
|
||||
* The resolveAssetPath function will replace this string with the actual path.
|
||||
*/
|
||||
export const modulePathPlaceholder = '@css:';
|
||||
|
||||
/**
|
||||
* Converts file path inputs into absolute paths.
|
||||
* Works similar to `absoluteFilePath` but paths that start with '$PACKAGE_ROOT/'
|
||||
* Works similar to `absoluteFilePath` but paths that start with the `modulePathPlaceholder`
|
||||
* will be relative to the module directory instead of the cwd.
|
||||
*/
|
||||
export function resolveAssetPath(path: string = modulePath): string {
|
||||
if (path.startsWith(modulePath)) {
|
||||
return joinFilePath(getModuleRoot(), path.slice(modulePath.length));
|
||||
export function resolveAssetPath(path: string = modulePathPlaceholder): string {
|
||||
if (path.startsWith(modulePathPlaceholder)) {
|
||||
return joinFilePath(getModuleRoot(), path.slice(modulePathPlaceholder.length));
|
||||
}
|
||||
return absoluteFilePath(path);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user