Skip to content

Commit

Permalink
Merge pull request #4 from thomascsd/1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
thomascsd authored Aug 30, 2020
2 parents 2b8dd44 + f1ed828 commit 1021e5c
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 67 deletions.
4 changes: 4 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"printWidth": 100,
"singleQuote": true
}
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,17 @@
![Visual Studio Marketplace Downloads](https://img.shields.io/visual-studio-marketplace/d/thomascsd.vscode-readme-pattern)
![Visual Studio Marketplace Installs](https://img.shields.io/visual-studio-marketplace/i/thomascsd.vscode-readme-pattern)

![Screenshot](https://raw.githubusercontent.com/thomascsd/vscode-readme-pattern/master/screenshot.gif)
![Screenshot](https://raw.githubusercontent.com/thomascsd/vscode-readme-pattern/master/images/screenshot.gif)

![Screenshot](https://raw.githubusercontent.com/thomascsd/vscode-readme-pattern/master/images/screenshot01.gif)

## Features

- Includes 4 readme templates: Bot, Hackathon, Minimal, Standard, based on [The-Documentation-Compendium](https://github.com/kylelobo/The-Documentation-Compendium)
- Creates project name by reading package.json
- Creates README.md with context menu
- Supports package.json and composer.json
- Creates project name by reading config

## Logo

Created my free logo at [LogoMakr.com](https://logomakr.com/)
Binary file added images/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Binary file added images/screenshot01.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
78 changes: 39 additions & 39 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 18 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vscode-readme-pattern",
"displayName": "Readme Pattern",
"description": "A VSCode extension that generates README.md files",
"version": "1.2.0",
"version": "1.3.0",
"publisher": "thomascsd",
"author": "Thomas Chang",
"license": "MIT",
Expand All @@ -25,17 +25,31 @@
},
"homepage": "https://github.com/thomascsd/vscode-readme-pattern",
"activationEvents": [
"onCommand:extension.readme"
"onCommand:extension.readme",
"onCommand:extension.readmeOnExplorer"
],
"main": "./out/extension.js",
"contributes": {
"commands": [
{
"command": "extension.readme",
"title": "readme: Generates README.md"
},
{
"command": "extension.readmeOnExplorer",
"title": "Generates README.md on here"
}
]
],
"menus": {
"explorer/context": [
{
"command": "extension.readmeOnExplorer",
"when": "explorerResourceIsFolder"
}
]
}
},
"icon": "images/icon.png",
"scripts": {
"vscode:prepublish": "npm run compile",
"compile": "tsc -p ./",
Expand All @@ -48,7 +62,7 @@
"@types/mocha": "^2.2.42",
"@types/node": "^10.12.21",
"@types/vscode": "^1.37.0",
"tslint": "^5.18.0",
"tslint": "^6.1.3",
"typescript": "^3.5.3",
"vscode-test": "^1.2.0"
}
Expand Down
22 changes: 16 additions & 6 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,25 @@ export function activate(context: vscode.ExtensionContext) {
// This line of code will only be executed once when your extension is activated
console.log('Congratulations, your extension "readme-pattern" is now active!');

// The command has been defined in the package.json file
// Now provide the implementation of the command with registerCommand
// The commandId parameter must match the command field in package.json
let disposable = vscode.commands.registerCommand('extension.readme', () => {
context.subscriptions.push(
vscode.commands.registerCommand('extension.readme', () => insertReadMe(context))
);

context.subscriptions.push(
vscode.commands.registerCommand('extension.readmeOnExplorer', (e) =>
insertReadmeOnExplorer(context, e.path)
)
);

function insertReadMe(context: vscode.ExtensionContext) {
const writer = new ReadmeWriter(context);
writer.insertReadme();
});
}

context.subscriptions.push(disposable);
function insertReadmeOnExplorer(context: vscode.ExtensionContext, url: string) {
const writer = new ReadmeWriter(context);
writer.insertReadmeOnExplorer(url);
}
}

// this method is called when your extension is deactivated
Expand Down
55 changes: 39 additions & 16 deletions src/lib/ReadmeWriter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,59 @@ export class ReadmeWriter {
constructor(private context: vscode.ExtensionContext) {}

async insertReadme() {
const items: string[] = ['Bot', 'Hackathon', 'Minimal', 'Standard'];
const selectedItem = await vscode.window.showQuickPick(items, {
placeHolder: 'Select readme pattern that you want'
});
const selectedItem = await this.getQuickPickItem();

if (selectedItem) {
await this.createFile(selectedItem);
}
}

private async createFile(selectedItem: string) {
const tempPath = this.context.asAbsolutePath(
path.join('templates', `${selectedItem}.md`)
);
async insertReadmeOnExplorer(url: string) {
const selectedItem = await this.getQuickPickItem();

if (selectedItem) {
await this.createFile(selectedItem, url);
}
}

private async createFile(selectedItem: string, url?: string) {
const tempPath = this.context.asAbsolutePath(path.join('templates', `${selectedItem}.md`));
const buffer = await this.fs.readFile(vscode.Uri.file(tempPath));
const folders = vscode.workspace.workspaceFolders;
const reader = new JsonContentReader();
let content = '';
const filePath = this.getFilePath(url);

console.log(`folders:${JSON.stringify(folders)}`);
console.log(`selectedItem:${selectedItem}`);
console.log(`url:${filePath}`);

if (folders) {
const url = folders[0].uri;
const filePath = path.join(url.fsPath, 'README.md');

console.log(`url:${filePath}`);

if (filePath) {
content = await reader.replaceContent(buffer.toString());
await this.fs.writeFile(vscode.Uri.file(filePath), Buffer.from(content));
}
}

private async getQuickPickItem() {
const items: string[] = ['Bot', 'Hackathon', 'Minimal', 'Standard'];
const selectedItem = await vscode.window.showQuickPick(items, {
placeHolder: 'Select readme pattern that you want',
});
return selectedItem;
}

private getFilePath(url?: string) {
const folders = vscode.workspace.workspaceFolders;
const fileName = 'README.md';
let filePath = '';

if (url) {
filePath = path.join(url, fileName);
} else if (folders) {
console.log(`folders:${JSON.stringify(folders)}`);

const folderUrl = folders[0].uri;
filePath = path.join(folderUrl.fsPath, fileName);
}

return filePath;
}
}

0 comments on commit 1021e5c

Please sign in to comment.