Skip to content

Commit

Permalink
#29 .gitignoreを元にnode_moduleなどの大規模フォルダを無視することに成功
Browse files Browse the repository at this point in the history
  • Loading branch information
illionillion committed Apr 26, 2023
1 parent 9d43b18 commit 9af7d71
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { existsSync, readFileSync, readdirSync, statSync } from "fs";
import { join } from "path";
import * as micromatch from "micromatch";


/**
* 共通のモジュール
*/
Expand Down Expand Up @@ -98,11 +97,11 @@ export const readDirRecursive = (
const folderName = path.split("/").pop() as string;
const children = readdirSync(path)
.filter((child) => !/(^|\/)\.[^\/\.]/g.test(child)) // ドットで始まるフォルダを除外する
.filter((child) => !/(^|\/)node_modules($|\/)/g.test(child)) // node_modulesフォルダを除外する
.filter((child) => !/(^|\/)mysql($|\/)/g.test(child)) // mysqlフォルダを除外する
.filter((child) => ignores.indexOf(child) === -1) // ignoresに記載されたファイルを除外する
// .filter((child) => !/(^|\/)node_modules($|\/)/g.test(child)) // node_modulesフォルダを除外する
// .filter((child) => !/(^|\/)mysql($|\/)/g.test(child)) // mysqlフォルダを除外する
.filter((child) => ignores.indexOf(join("/", child)) === -1) // ignoresに記載されたフォルダを除外する
.map((child) => readDirRecursive(join(path, child), ignores));

return { label: folderName, nodes: children };
} else {
return { label: path.split("/").pop() as string };
Expand All @@ -111,17 +110,17 @@ export const readDirRecursive = (

/**
* gitignoreの内容取得
* @param workspacePath
* @returns
* @param workspacePath
* @returns
*/
export const getGitignorePatterns = (workspacePath: string): string[] => {
const gitignorePath = join(workspacePath, '.gitignore');
const gitignorePath = join(workspacePath, ".gitignore");

if (existsSync(gitignorePath)) {
const gitignoreContent = readFileSync(gitignorePath, 'utf8');
const gitignoreContent = readFileSync(gitignorePath, "utf8");
return gitignoreContent
.split('\n')
.filter((line) => !line.startsWith('#') && line.trim() !== '');
.split("\n")
.filter((line) => !line.startsWith("#") && line.trim() !== "");
} else {
return [];
}
Expand Down Expand Up @@ -196,7 +195,6 @@ export const selectFile = async (): Promise<string | undefined> => {
};

/**
*
* Windows用の正規表現パターン
*/
const winPattern =
Expand Down

0 comments on commit 9af7d71

Please sign in to comment.