Skip to content

Commit 1a049ed

Browse files
refactor(ngfs): allow multiple ignore patterns
- update - ignore dist and node_modules by default - upgrade-packages - set default framework & project type
1 parent 4ff9dff commit 1a049ed

File tree

4 files changed

+19
-19
lines changed

4 files changed

+19
-19
lines changed

packages/core/types/FileSystem.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ export interface IFileSystem {
88
* Returns a list of file paths under a directory based on a match pattern
99
* @param dirPath Root dir to search in
1010
* @param pattern Pattern to match
11+
* @param ignorePatterns Optional pattern to ignore for each subdirectory
1112
*/
12-
glob(dirPath: string, pattern: string, ignorePattern?: string): string[];
13+
glob(dirPath: string, pattern: string, ignorePatterns?: string[]): string[];
1314
}
1415

1516
export const FS_TOKEN: string = "fs";

packages/core/update/Update.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export async function updateWorkspace(rootPath: string): Promise<boolean> {
6161
const logicFiles = [];
6262
const styleFiles = [];
6363
const pkgJsonFiles = [];
64-
pkgJsonFiles.push(...fs.glob(rootPath, `package.json`, "node_modules"));
64+
pkgJsonFiles.push(...fs.glob(rootPath, `package.json`, ['node_modules', 'dist']));
6565

6666
let workspaceConfig = null;
6767
switch (framework.toLowerCase()) {

packages/ng-schematics/src/upgrade-packages/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ export default function(options: UpgradeOptions): Rule {
1818
});
1919
const templateManager = new SchematicsTemplateManager();
2020
const config = ProjectConfig.getConfig();
21-
const library = templateManager.getProjectLibrary(config.project.framework, config.project.projectType);
21+
const library = templateManager.getProjectLibrary('angular', config.project?.projectType || 'igx-ts');
2222
let project: ProjectTemplate;
23-
if (!config.project.projectTemplate || !library.hasProject(config.project.projectTemplate)) {
23+
if (!config.project?.projectTemplate || !library.hasProject(config.project?.projectTemplate)) {
2424
// in case project template is missing from the config we provide backward.
2525
project = library.getProject(library.projectIds[0]);
2626
} else {

packages/ng-schematics/src/utils/NgFileSystem.ts

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { DirEntry, FileEntry, Tree } from "@angular-devkit/schematics";
22
import { App, FS_TOKEN, FS_TYPE_TOKEN, FsTypes, IFileSystem } from "@igniteui/cli-core";
33
import { minimatch } from 'minimatch';
4+
import * as path from "path";
45

56
export class NgTreeFileSystem implements IFileSystem {
67
constructor(private tree: Tree) { }
@@ -25,9 +26,9 @@ export class NgTreeFileSystem implements IFileSystem {
2526
* Returns a list of file paths under a directory based on a match pattern
2627
* @param dirPath Root dir to search in
2728
* @param pattern Supports only recursive wildcard `\*\*\/\*`
28-
* @param ignorePattern Optional pattern to ignore for each subdirectory
29+
* @param ignorePatterns Optional patterns to ignore for each subdirectory
2930
*/
30-
public glob(dirPath: string, pattern: string, ignorePattern?: string): string[] {
31+
public glob(dirPath: string, pattern: string, ignorePatterns?: string[]): string[] {
3132
const dir = this.tree.getDir(dirPath);
3233
const entries: string[] = [];
3334

@@ -37,22 +38,20 @@ export class NgTreeFileSystem implements IFileSystem {
3738
}
3839
};
3940

40-
if (ignorePattern) {
41-
dir.subfiles.forEach(file => {
42-
if (minimatch(file, pattern) && !minimatch(file, ignorePattern)) {
43-
entries.push(file);
44-
}
45-
});
46-
41+
if (ignorePatterns?.length) {
4742
const recurse = (dir: DirEntry): void => {
4843
for (const subdirPath of dir.subdirs) {
49-
if (!minimatch(subdirPath, ignorePattern)) {
50-
const currDir = dir.dir(subdirPath);
51-
if (currDir.subdirs.length) {
52-
recurse(currDir);
53-
return;
44+
if (ignorePatterns.every(p => !minimatch(subdirPath, p))) {
45+
const subDir = dir.dir(subdirPath);
46+
if (subDir.subdirs.length) {
47+
recurse(subDir);
48+
continue;
49+
}
50+
for (const file of dir.subfiles) {
51+
if (minimatch(file, pattern) && ignorePatterns.every(p => !minimatch(file, p))) {
52+
entries.push(path.posix.normalize(`${dir.path}/${file}`));
53+
}
5454
}
55-
currDir.visit(visitor);
5655
}
5756
}
5857
};

0 commit comments

Comments
 (0)