Skip to content

Commit dd6eee3

Browse files
authored
feat(ui-devkit): Add "exclude" option to UI extensions (#2009)
1 parent dc3220d commit dd6eee3

File tree

3 files changed

+37
-10
lines changed

3 files changed

+37
-10
lines changed

packages/ui-devkit/src/compiler/scaffold.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* tslint:disable:no-console */
22
import { spawn } from 'child_process';
33
import * as fs from 'fs-extra';
4+
import glob from 'glob';
45
import * as path from 'path';
56

67
import {
@@ -103,7 +104,17 @@ async function copyExtensionModules(outputPath: string, extensions: Array<AdminU
103104

104105
for (const extension of extensions) {
105106
const dest = path.join(outputPath, MODULES_OUTPUT_DIR, extension.id);
106-
fs.copySync(extension.extensionPath, dest);
107+
if (!extension.exclude) {
108+
fs.copySync(extension.extensionPath, dest);
109+
continue;
110+
}
111+
112+
const exclude = extension.exclude
113+
.map(e => glob.sync(path.join(extension.extensionPath, e)))
114+
.flatMap(e => e);
115+
fs.copySync(extension.extensionPath, dest, {
116+
filter: name => name === extension.extensionPath || exclude.every(e => e !== name),
117+
});
107118
}
108119
}
109120

packages/ui-devkit/src/compiler/types.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,18 @@ export interface AdminUiExtension
206206
* ```
207207
*/
208208
pathAlias?: string;
209+
210+
/**
211+
* @description
212+
* Optional array specifying filenames or [glob](https://github.com/isaacs/node-glob) patterns that should
213+
* be skipped when copying the directory defined by `extensionPath`.
214+
*
215+
* @example
216+
* ```ts
217+
* exclude: ['**\/*.spec.ts']
218+
* ```
219+
*/
220+
exclude?: string[];
209221
}
210222

211223
/**

scripts/docs/typescript-docs-parser.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
*/
2121
export class TypescriptDocsParser {
2222
private readonly atTokenPlaceholder = '__EscapedAtToken__';
23+
private readonly commentBlockEndTokenPlaceholder = '__EscapedCommentBlockEndToken__'
2324

2425
/**
2526
* Parses the TypeScript files given by the filePaths array and returns the
@@ -29,7 +30,7 @@ export class TypescriptDocsParser {
2930
const sourceFiles = filePaths.map(filePath => {
3031
return ts.createSourceFile(
3132
filePath,
32-
this.replaceEscapedAtTokens(fs.readFileSync(filePath).toString()),
33+
this.replaceEscapedTokens(fs.readFileSync(filePath).toString()),
3334
ts.ScriptTarget.ES2015,
3435
true,
3536
);
@@ -288,7 +289,7 @@ export class TypescriptDocsParser {
288289
const memberInfo: MemberInfo = {
289290
fullText,
290291
name,
291-
description: this.restoreAtTokens(description),
292+
description: this.restoreTokens(description),
292293
type,
293294
modifiers,
294295
since,
@@ -383,7 +384,7 @@ export class TypescriptDocsParser {
383384
description: comment => (description += comment),
384385
example: comment => (description += this.formatExampleCode(comment)),
385386
});
386-
return this.restoreAtTokens(description);
387+
return this.restoreTokens(description);
387388
}
388389

389390
/**
@@ -446,20 +447,23 @@ export class TypescriptDocsParser {
446447

447448
/**
448449
* TypeScript from v3.5.1 interprets all '@' tokens in a tag comment as a new tag. This is a problem e.g.
449-
* when a plugin includes in it's description some text like "install the @vendure/some-plugin package". Here,
450+
* when a plugin includes in its description some text like "install the @vendure/some-plugin package". Here,
450451
* TypeScript will interpret "@vendure" as a JSDoc tag and remove it and all remaining text from the comment.
451452
*
452453
* The solution is to replace all escaped @ tokens ("\@") with a replacer string so that TypeScript treats them
453454
* as regular comment text, and then once it has parsed the statement, we replace them with the "@" character.
455+
*
456+
* Similarly, '/*' is interpreted as end of a comment block. However, it can be useful to specify a globstar
457+
* pattern in descriptions and therefore it is supported as long as the leading '/' is escaped ("\/").
454458
*/
455-
private replaceEscapedAtTokens(content: string): string {
456-
return content.replace(/\\@/g, this.atTokenPlaceholder);
459+
private replaceEscapedTokens(content: string): string {
460+
return content.replace(/\\@/g, this.atTokenPlaceholder).replace(/\\\/\*/g, this.commentBlockEndTokenPlaceholder);
457461
}
458462

459463
/**
460-
* Restores "@" tokens which were replaced by the replaceEscapedAtTokens() method.
464+
* Restores "@" and "/*" tokens which were replaced by the replaceEscapedTokens() method.
461465
*/
462-
private restoreAtTokens(content: string): string {
463-
return content.replace(new RegExp(this.atTokenPlaceholder, 'g'), '@');
466+
private restoreTokens(content: string): string {
467+
return content.replace(new RegExp(this.atTokenPlaceholder, 'g'), '@').replace(new RegExp(this.commentBlockEndTokenPlaceholder, 'g'), '/*');
464468
}
465469
}

0 commit comments

Comments
 (0)