-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor - move commands to a separate directory
- Loading branch information
1 parent
5c36eee
commit 815e2fb
Showing
4 changed files
with
69 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import * as vscode from "vscode"; | ||
import { parseTextToClass } from "../util/dart_class_parser"; | ||
import { writeWidgetbookEntry } from "../util/file_util"; | ||
import path = require("path"); | ||
|
||
async function generateWidgetbookEntriesForDirectory( | ||
uri: vscode.Uri | ||
): Promise<void> { | ||
const directoryPath = uri.fsPath; | ||
|
||
await generateWidgetbookEntriesForDirectoryImpl(directoryPath); | ||
} | ||
|
||
// FIXME Refactor the naming | ||
async function generateWidgetbookEntriesForDirectoryImpl( | ||
directoryPath: string | ||
): Promise<void> { | ||
const files = await vscode.workspace.fs.readDirectory( | ||
vscode.Uri.file(directoryPath) | ||
); | ||
|
||
for (const [fileName, fileType] of files) { | ||
if (fileType === vscode.FileType.File) { | ||
const filePath = path.join(directoryPath, fileName); | ||
|
||
const fileContent = await vscode.workspace.fs.readFile( | ||
vscode.Uri.file(filePath) | ||
); | ||
const fileContentString = new TextDecoder().decode(fileContent); | ||
|
||
const clazz = parseTextToClass(fileContentString); | ||
|
||
await writeWidgetbookEntry(clazz); | ||
} else if (fileType === vscode.FileType.Directory) { | ||
const subdirectoryPath = path.join(directoryPath, fileName); | ||
|
||
await generateWidgetbookEntriesForDirectoryImpl(subdirectoryPath); | ||
} | ||
} | ||
} | ||
|
||
export { generateWidgetbookEntriesForDirectory }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import * as vscode from "vscode"; | ||
import { parseTextToClass } from "../util/dart_class_parser"; | ||
import { writeWidgetbookEntry } from "../util/file_util"; | ||
|
||
async function generateWidgetbookEntryForWidgetInScope(): Promise<void> { | ||
const activeEditor = vscode.window.activeTextEditor; | ||
if (!activeEditor) return; | ||
|
||
const text = activeEditor.document.getText(); | ||
const currentLineIndex = activeEditor.selection.active.line; | ||
const fileContentFromCurrentLine = text | ||
.split("\n") | ||
.slice(currentLineIndex) | ||
.join("\n"); | ||
|
||
const clazz = parseTextToClass(fileContentFromCurrentLine); | ||
|
||
await writeWidgetbookEntry(clazz); | ||
} | ||
|
||
export { generateWidgetbookEntryForWidgetInScope }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from "./generate_entries_for_directory"; | ||
export * from "./generate_entry_for_widget"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters