Skip to content

Commit

Permalink
Final changes for initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
dentolos19 committed Mar 4, 2024
1 parent 5088c60 commit 5be3a2c
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 20 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

An easy way to quickly edit wikis locally inside your editor!

**What is my rationale of making this extension?** I want to edit my projects' wiki quickly and easily right inside my editor just by running commands instead of typing commands manually inside the terminal. There wasn't any specialized extensions for editing GitHub wikis and extensions like [Remote Repositories](https://marketplace.visualstudio.com/items?itemName=ms-vscode.remote-repositories) doesn't allow you to remotely access them as well.

## Features

- [x] Supports GitHub
Expand Down
12 changes: 9 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,19 @@
"configuration": {
"title": "Git Wiki Editor",
"properties": {
"git-wiki-editor.isWikiWorkspace": {
"git-wiki-editor.github.username": {
"type": "string",
"default": "",
"description": "The default GitHub username to use when searching for wikis."
},
"git-wiki-editor.workspace.isWikiWorkspace": {
"type": "boolean",
"default": false,
"description": "Whether the current workspace is a wiki workspace. Do not set manually!"
},
"git-wiki-editor.repoFullName": {
"git-wiki-editor.workspace.repoFullName": {
"type": "string",
"default": "",
"description": "The GitHub repository that the wiki belongs to. Do not set manually!"
}
}
Expand All @@ -57,7 +63,7 @@
"test": "vscode-test",
"pretest": "pnpm run compile && pnpm run lint",
"pack": "pnpm vsce pack --no-dependencies --out extension.vsix",
"publish": "pnpm vsce publish --no-dependencies --out extension.vsix"
"publish": "pnpm vsce publish --no-dependencies"
},
"devDependencies": {
"@types/mocha": "^10.0.6",
Expand Down
4 changes: 2 additions & 2 deletions src/commands/initialize-wiki.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import * as utils from "../utils";

export default async function initializeWiki() {
// checks whether the current workspace is a valid wiki workspace
const isWikiWorkspace = environment.config.get<boolean>("isWikiWorkspace", false);
const repoFullName = environment.config.get<string>("repoFullName");
const isWikiWorkspace = environment.config.get<boolean>("workspace.isWikiWorkspace", false);
const repoFullName = environment.config.get<string>("workspace.repoFullName");
if (!isWikiWorkspace) {
return;
}
Expand Down
48 changes: 36 additions & 12 deletions src/commands/open-wiki.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ import * as path from "path";
import * as vscode from "vscode";
import environment from "../environment";
import * as github from "../github";
import * as utils from "../utils";

export default async function openWiki() {
// ask for user's GitHub username
const username = await vscode.window.showInputBox({
placeHolder: "Enter a GitHub username...",
});

let username = environment.config.get<string>("github.username");
if (!username) {
username = await vscode.window.showInputBox({
placeHolder: "Enter a GitHub username...",
});
}
if (!username) {
return;
}
Expand Down Expand Up @@ -41,14 +42,37 @@ export default async function openWiki() {
return;
}

const wikiBasePath = path.join(
environment.tempDir,
repo.name,
utils.generateRandomString(8)
);
const wikiBasePath = path.join(environment.tempDir, repo.full_name);
const wikiSourcePath = path.join(wikiBasePath, "wiki");
const wikiWorkspacePath = path.join(wikiBasePath, "wiki.code-workspace");

// checks if wiki already exists
if (fs.existsSync(wikiWorkspacePath)) {
const newWorkspace = await vscode.window
.showInformationMessage(
"A wiki workspace already exists. Do you want to open it or create a new one?",
"Open",
"New"
)
.then(async (value) => {
if (value === "New") {
return true;
}
return false;
});
if (newWorkspace) {
// delete existing wiki workspace
fs.rmdirSync(wikiBasePath, { recursive: true });
} else {
// open existing wiki workspace
await vscode.commands.executeCommand(
"vscode.openFolder",
vscode.Uri.file(wikiWorkspacePath)
);
return;
}
}

// create wiki workspace
fs.mkdirSync(wikiSourcePath, { recursive: true });
fs.writeFileSync(
Expand All @@ -61,8 +85,8 @@ export default async function openWiki() {
},
],
settings: {
"git-wiki-editor.isWikiWorkspace": true,
"git-wiki-editor.repoFullName": `${repo.full_name}.wiki`,
"git-wiki-editor.workspace.isWikiWorkspace": true,
"git-wiki-editor.workspace.repoFullName": `${repo.full_name}.wiki`,
},
extensions: {
recommendations: [
Expand Down
4 changes: 2 additions & 2 deletions src/commands/publish-wiki.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import environment from "../environment";
import * as utils from "../utils";

export default async function publishWiki() {
const isWikiWorkspace = environment.config.get<boolean>("isWikiWorkspace", false);
const repoFullName = environment.config.get<string>("repoFullName");
const isWikiWorkspace = environment.config.get<boolean>("workspace.isWikiWorkspace", false);
const repoFullName = environment.config.get<string>("workspace.repoFullName");

if (!isWikiWorkspace) {
vscode.window.showErrorMessage("Please open a wiki first!");
Expand Down
2 changes: 1 addition & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function activate(context: vscode.ExtensionContext) {
].forEach((command) => context.subscriptions.push(command));

// initialize wiki if the workspace is a wiki
const isWikiWorkspace = environment.config.get<boolean>("isWikiWorkspace", false);
const isWikiWorkspace = environment.config.get<boolean>("workspace.isWikiWorkspace", false);
if (isWikiWorkspace) {
initializeWiki();
}
Expand Down

0 comments on commit 5be3a2c

Please sign in to comment.