Skip to content

Commit be759e9

Browse files
committed
Use prefetched document loader for offline context access, Closes #51
1 parent d6416ec commit be759e9

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

bin/componentsjs-generator.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Usage:
1414
-c components Relative path to directory that will contain components files, defaults to 'components'
1515
-e jsonld Extension for components files (without .), defaults to 'jsonld'
1616
-i ignore-classes.json Relative path to an optional file with class names to ignore
17+
-l info The logger level
1718
--help Show information about this command
1819
`);
1920
process.exit(1);
@@ -31,7 +32,7 @@ if (args.help) {
3132
replacementPath: args.c || 'components',
3233
},
3334
fileExtension: args.e || 'jsonld',
34-
level: args.l || 'info',
35+
logLevel: args.l || 'info',
3536
ignoreClasses: args.i ?
3637
// eslint-disable-next-line no-sync
3738
JSON.parse(fs.readFileSync(args.i, 'utf8')).reduce((acc: Record<string, boolean>, entry: string) => {

lib/generate/Generator.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import { ComponentsManagerBuilder } from 'componentsjs/lib/loading/ComponentsManagerBuilder';
2+
import { PrefetchedDocumentLoader } from 'componentsjs/lib/rdf/PrefetchedDocumentLoader';
3+
import type { LogLevel } from 'componentsjs/lib/util/LogLevel';
14
import { ContextParser } from 'jsonld-context-parser';
25
import { ClassFinder } from '../parse/ClassFinder';
36
import { ClassIndexer } from '../parse/ClassIndexer';
@@ -19,12 +22,14 @@ export class Generator {
1922
private readonly pathDestination: PathDestinationDefinition;
2023
private readonly fileExtension: string;
2124
private readonly ignoreClasses: Record<string, boolean>;
25+
private readonly logLevel: LogLevel;
2226

2327
public constructor(args: GeneratorArgs) {
2428
this.resolutionContext = args.resolutionContext;
2529
this.pathDestination = args.pathDestination;
2630
this.fileExtension = args.fileExtension;
2731
this.ignoreClasses = args.ignoreClasses;
32+
this.logLevel = args.logLevel;
2833
}
2934

3035
public async generateComponents(): Promise<void> {
@@ -53,7 +58,12 @@ export class Generator {
5358
pathDestination: this.pathDestination,
5459
classReferences: classIndex,
5560
classConstructors: constructors,
56-
contextParser: new ContextParser(),
61+
contextParser: new ContextParser({
62+
documentLoader: new PrefetchedDocumentLoader({
63+
contexts: {},
64+
logger: ComponentsManagerBuilder.createLogger(this.logLevel),
65+
}),
66+
}),
5767
});
5868
const components = await componentConstructor.constructComponents();
5969
const componentsIndex = await componentConstructor.constructComponentsIndex(components, this.fileExtension);
@@ -78,6 +88,6 @@ export interface GeneratorArgs {
7888
resolutionContext: ResolutionContext;
7989
pathDestination: PathDestinationDefinition;
8090
fileExtension: string;
81-
level: string;
8291
ignoreClasses: Record<string, boolean>;
92+
logLevel: LogLevel;
8393
}

0 commit comments

Comments
 (0)