Skip to content

Commit

Permalink
#29 node_modulesや.gitignoreを見ないようにした、次はワークスペースからhitignoreのパスを取得して中身を取…
Browse files Browse the repository at this point in the history
…得するだけ
  • Loading branch information
illionillion committed Apr 25, 2023
1 parent 8b32b42 commit bd62dc2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
7 changes: 7 additions & 0 deletions src/commands/create-readme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,13 @@ export const create_readme = async (openai: OpenAIApi | undefined) => {

// ファイルの親フォルダ取得
const folderPath = targetfilePath.replace(/\/[^\/]*$/, "");
const workspaceFolders = vscode.workspace.workspaceFolders
if (!workspaceFolders || workspaceFolders.length === 0) {
vscode.window.showErrorMessage("No workspace folder found.");
return
}
// ワークスペースのフォルダ取得
const workspaceFolderPath = workspaceFolders[0].uri.fsPath;
// ツリーのルートを作成する
const root = readDirRecursive(folderPath);
// アスキーアート出力
Expand Down
15 changes: 10 additions & 5 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as vscode from "vscode";
import { AxiosError } from "axios";
import { ChatCompletionRequestMessageRoleEnum, OpenAIApi } from "openai";
import { readdirSync, statSync } from "fs";

import { join } from "path";
/**
* 共通のモジュール
*/
Expand Down Expand Up @@ -79,18 +79,23 @@ export const generateReadme = async (
/**
* フォルダの配下のtreeを取得
* @param path パス
* @param ignores ignoreで除外されているもの
* @returns
*/
export const readDirRecursive = (
path: string
path: string,
ignores: string[] = []
): { label: string; nodes?: any[] } => {
const stats = statSync(path);

if (stats.isDirectory()) {
const folderName = path.split("/").pop() as string;
const children = readdirSync(path).map((child) =>
readDirRecursive(`${path}/${child}`)
);
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に記載されたファイルを除外する
.map(child => readDirRecursive(join(path, child), ignores));

return { label: folderName, nodes: children };
} else {
Expand Down

0 comments on commit bd62dc2

Please sign in to comment.