Skip to content

Commit a2b51b0

Browse files
authored
Add CLI parameter to set prefix of package
1 parent c969d74 commit a2b51b0

7 files changed

Lines changed: 305 additions & 220 deletions

File tree

.DS_Store

6 KB
Binary file not shown.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ Usage:
100100
-c components Relative path to directory that will contain components files, defaults to 'components'
101101
-e jsonld Extension for components files (without .), defaults to 'jsonld'
102102
-i ignore-classes.json Relative path to an optional file with class names to ignore
103+
-r prefix Optional custom JSON-LD module prefix
103104
--help Show information about this command
104105

105106
Experimental options:

bin/componentsjs-generator.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Usage:
1616
-e jsonld Extension for components files (without .), defaults to 'jsonld'
1717
-i ignore-classes.json Relative path to an optional file with class names to ignore
1818
-l info The logger level
19+
-r prefix Optional custom JSON-LD module prefix
1920
--help Show information about this command
2021
2122
Experimental options:
@@ -39,6 +40,7 @@ if (args.help) {
3940
fileExtension: args.e || 'jsonld',
4041
typeScopedContexts: args.typeScopedContexts,
4142
logLevel: args.l || 'info',
43+
prefix: args.r,
4244
ignoreClasses: args.i ?
4345
// eslint-disable-next-line no-sync
4446
JSON.parse(fs.readFileSync(args.i, 'utf8')).reduce((acc: Record<string, boolean>, entry: string) => {

lib/generate/Generator.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export class Generator {
2525
private readonly ignoreClasses: Record<string, boolean>;
2626
private readonly typeScopedContexts: boolean;
2727
private readonly logLevel: LogLevel;
28+
private readonly prefix?: string;
2829

2930
public constructor(args: GeneratorArgs) {
3031
this.resolutionContext = args.resolutionContext;
@@ -33,13 +34,15 @@ export class Generator {
3334
this.ignoreClasses = args.ignoreClasses;
3435
this.typeScopedContexts = args.typeScopedContexts;
3536
this.logLevel = args.logLevel;
37+
this.prefix = args.prefix;
3638
}
3739

3840
public async generateComponents(): Promise<void> {
3941
const logger = ComponentsManagerBuilder.createLogger(this.logLevel);
4042

4143
// Load package metadata
42-
const packageMetadata = await new PackageMetadataLoader({ resolutionContext: this.resolutionContext })
44+
const packageMetadata = await new PackageMetadataLoader({ resolutionContext: this.resolutionContext,
45+
prefix: this.prefix })
4346
.load(this.pathDestination.packageRootDirectory);
4447

4548
const classLoader = new ClassLoader({ resolutionContext: this.resolutionContext, logger });
@@ -110,4 +113,5 @@ export interface GeneratorArgs {
110113
ignoreClasses: Record<string, boolean>;
111114
typeScopedContexts: boolean;
112115
logLevel: LogLevel;
116+
prefix?: string;
113117
}

lib/parse/PackageMetadataLoader.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ import type { ResolutionContext } from '../resolution/ResolutionContext';
77
*/
88
export class PackageMetadataLoader {
99
private readonly resolutionContext: ResolutionContext;
10+
private readonly prefix?: string;
1011

1112
public constructor(args: PackageMetadataLoaderArgs) {
1213
this.resolutionContext = args.resolutionContext;
14+
this.prefix = args.prefix;
1315
}
1416

1517
/**
@@ -78,12 +80,14 @@ export class PackageMetadataLoader {
7880
contexts,
7981
importPaths,
8082
typesPath,
83+
prefix: this.prefix,
8184
};
8285
}
8386
}
8487

8588
export interface PackageMetadataLoaderArgs {
8689
resolutionContext: ResolutionContext;
90+
prefix?: string;
8791
}
8892

8993
export interface PackageMetadata {
@@ -94,4 +98,5 @@ export interface PackageMetadata {
9498
contexts: Record<string, string>;
9599
importPaths: Record<string, string>;
96100
typesPath: string;
101+
prefix?: string;
97102
}

lib/serialize/ContextConstructor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export class ContextConstructor {
3434
*/
3535
public constructContext(components?: ComponentDefinitions): ContextRaw {
3636
// Determine a compact prefix to represent this package.
37-
const prefix = ContextConstructor.getPackageNamePrefix(this.packageMetadata.name);
37+
const prefix = this.packageMetadata.prefix ?? ContextConstructor.getPackageNamePrefix(this.packageMetadata.name);
3838

3939
// Determine component shortcuts if provided.
4040
const componentShortcuts = components ? this.constructComponentShortcuts(components) : {};

0 commit comments

Comments
 (0)