Skip to content

Commit 113bb76

Browse files
committed
feat: options, path resolves, nodejs version, annotations
1 parent 3986841 commit 113bb76

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

src/options.defaults.ts

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,29 @@
1-
import { basename, join } from 'node:path';
1+
import { basename, join, resolve } from 'node:path';
2+
import { pathToFileURL } from 'node:url';
23
import packageJson from '../package.json';
34

45
/**
5-
* Application defaults, not user-configurable
6+
* Application defaults, not all fields are user-configurable
67
*
78
* @interface DefaultOptions
89
*
910
* @template TLogOptions The logging options type, defaulting to LoggingOptions.
1011
* @property contextPath - Current working directory.
12+
* @property contextUrl - Current working directory URL.
1113
* @property docsHost - Flag indicating whether to use the docs-host.
1214
* @property docsPath - Path to the documentation directory.
1315
* @property isHttp - Flag indicating whether the server is running in HTTP mode.
1416
* @property {HttpOptions} http - HTTP server options.
1517
* @property llmsFilesPath - Path to the LLMs files directory.
1618
* @property {LoggingOptions} logging - Logging options.
1719
* @property name - Name of the package.
20+
* @property nodeVersion - Node.js major version.
1821
* @property repoName - Name of the repository.
1922
* @property pfExternal - PatternFly external docs URL.
2023
* @property pfExternalDesignComponents - PatternFly design guidelines' components' URL.
2124
* @property pfExternalExamplesComponents - PatternFly examples' core components' URL.
2225
* @property pfExternalExamplesLayouts - PatternFly examples' core layouts' URL.
23-
* @property pfExternalExamplesCharts - PatternFly examples' charts' components' URL.'
26+
* @property pfExternalExamplesCharts - PatternFly examples' charts' components' URL.
2427
* @property pfExternalExamplesTable - PatternFly examples' table components' URL.
2528
* @property pfExternalChartsDesign - PatternFly charts' design guidelines URL.
2629
* @property pfExternalDesignLayouts - PatternFly design guidelines' layouts' URL.
@@ -33,13 +36,15 @@ import packageJson from '../package.json';
3336
*/
3437
interface DefaultOptions<TLogOptions = LoggingOptions> {
3538
contextPath: string;
39+
contextUrl: string;
3640
docsHost: boolean;
3741
docsPath: string;
3842
http: HttpOptions;
3943
isHttp: boolean;
4044
llmsFilesPath: string;
4145
logging: TLogOptions;
4246
name: string;
47+
nodeVersion: number;
4348
pfExternal: string;
4449
pfExternalDesignComponents: string;
4550
pfExternalExamplesComponents: string;
@@ -253,20 +258,35 @@ const PF_EXTERNAL_ACCESSIBILITY = `${PF_EXTERNAL}/accessibility`;
253258
*/
254259
const PF_EXTERNAL_CHARTS_DESIGN = `${PF_EXTERNAL}/design-guidelines/charts`;
255260

261+
/**
262+
* Get the current Node.js major version.
263+
*/
264+
const getNodeMajorVersion = () => {
265+
const major = Number.parseInt(process.versions.node.split('.')[0] || '0', 10);
266+
267+
if (Number.isFinite(major)) {
268+
return major;
269+
}
270+
271+
return 0;
272+
};
273+
256274
/**
257275
* Global default options. Base defaults before CLI/programmatic overrides.
258276
*
259277
* @type {DefaultOptions} Default options object.
260278
*/
261279
const DEFAULT_OPTIONS: DefaultOptions = {
262280
docsHost: false,
263-
contextPath: (process.env.NODE_ENV === 'local' && '/') || process.cwd(),
264-
docsPath: (process.env.NODE_ENV === 'local' && '/documentation') || join(process.cwd(), 'documentation'),
281+
contextPath: (process.env.NODE_ENV === 'local' && '/') || resolve(process.cwd()),
282+
contextUrl: pathToFileURL((process.env.NODE_ENV === 'local' && '/') || resolve(process.cwd())).href,
283+
docsPath: (process.env.NODE_ENV === 'local' && '/documentation') || join(resolve(process.cwd()), 'documentation'),
265284
isHttp: false,
266285
http: HTTP_OPTIONS,
267-
llmsFilesPath: (process.env.NODE_ENV === 'local' && '/llms-files') || join(process.cwd(), 'llms-files'),
286+
llmsFilesPath: (process.env.NODE_ENV === 'local' && '/llms-files') || join(resolve(process.cwd()), 'llms-files'),
268287
logging: LOGGING_OPTIONS,
269288
name: packageJson.name,
289+
nodeVersion: (process.env.NODE_ENV === 'local' && 22) || getNodeMajorVersion(),
270290
pfExternal: PF_EXTERNAL,
271291
pfExternalDesignComponents: PF_EXTERNAL_DESIGN_COMPONENTS,
272292
pfExternalExamplesComponents: PF_EXTERNAL_EXAMPLES_REACT_CORE,
@@ -299,6 +319,7 @@ export {
299319
PF_EXTERNAL_ACCESSIBILITY,
300320
LOG_BASENAME,
301321
DEFAULT_OPTIONS,
322+
getNodeMajorVersion,
302323
type DefaultOptions,
303324
type DefaultOptionsOverrides,
304325
type HttpOptions,

0 commit comments

Comments
 (0)