Skip to content

Commit 1021e5c

Browse files
authored
Merge pull request #4 from thomascsd/1.3
2 parents 2b8dd44 + f1ed828 commit 1021e5c

File tree

9 files changed

+126
-67
lines changed

9 files changed

+126
-67
lines changed

.prettierrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"printWidth": 100,
3+
"singleQuote": true
4+
}

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,17 @@
66
![Visual Studio Marketplace Downloads](https://img.shields.io/visual-studio-marketplace/d/thomascsd.vscode-readme-pattern)
77
![Visual Studio Marketplace Installs](https://img.shields.io/visual-studio-marketplace/i/thomascsd.vscode-readme-pattern)
88

9-
![Screenshot](https://raw.githubusercontent.com/thomascsd/vscode-readme-pattern/master/screenshot.gif)
9+
![Screenshot](https://raw.githubusercontent.com/thomascsd/vscode-readme-pattern/master/images/screenshot.gif)
10+
11+
![Screenshot](https://raw.githubusercontent.com/thomascsd/vscode-readme-pattern/master/images/screenshot01.gif)
1012

1113
## Features
1214

1315
- Includes 4 readme templates: Bot, Hackathon, Minimal, Standard, based on [The-Documentation-Compendium](https://github.com/kylelobo/The-Documentation-Compendium)
14-
- Creates project name by reading package.json
16+
- Creates README.md with context menu
17+
- Supports package.json and composer.json
18+
- Creates project name by reading config
19+
20+
## Logo
21+
22+
Created my free logo at [LogoMakr.com](https://logomakr.com/)

images/icon.png

18.7 KB
Loading
File renamed without changes.

images/screenshot01.gif

432 KB
Loading

package-lock.json

Lines changed: 39 additions & 39 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "vscode-readme-pattern",
33
"displayName": "Readme Pattern",
44
"description": "A VSCode extension that generates README.md files",
5-
"version": "1.2.0",
5+
"version": "1.3.0",
66
"publisher": "thomascsd",
77
"author": "Thomas Chang",
88
"license": "MIT",
@@ -25,17 +25,31 @@
2525
},
2626
"homepage": "https://github.com/thomascsd/vscode-readme-pattern",
2727
"activationEvents": [
28-
"onCommand:extension.readme"
28+
"onCommand:extension.readme",
29+
"onCommand:extension.readmeOnExplorer"
2930
],
3031
"main": "./out/extension.js",
3132
"contributes": {
3233
"commands": [
3334
{
3435
"command": "extension.readme",
3536
"title": "readme: Generates README.md"
37+
},
38+
{
39+
"command": "extension.readmeOnExplorer",
40+
"title": "Generates README.md on here"
3641
}
37-
]
42+
],
43+
"menus": {
44+
"explorer/context": [
45+
{
46+
"command": "extension.readmeOnExplorer",
47+
"when": "explorerResourceIsFolder"
48+
}
49+
]
50+
}
3851
},
52+
"icon": "images/icon.png",
3953
"scripts": {
4054
"vscode:prepublish": "npm run compile",
4155
"compile": "tsc -p ./",
@@ -48,7 +62,7 @@
4862
"@types/mocha": "^2.2.42",
4963
"@types/node": "^10.12.21",
5064
"@types/vscode": "^1.37.0",
51-
"tslint": "^5.18.0",
65+
"tslint": "^6.1.3",
5266
"typescript": "^3.5.3",
5367
"vscode-test": "^1.2.0"
5468
}

src/extension.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,25 @@ export function activate(context: vscode.ExtensionContext) {
1010
// This line of code will only be executed once when your extension is activated
1111
console.log('Congratulations, your extension "readme-pattern" is now active!');
1212

13-
// The command has been defined in the package.json file
14-
// Now provide the implementation of the command with registerCommand
15-
// The commandId parameter must match the command field in package.json
16-
let disposable = vscode.commands.registerCommand('extension.readme', () => {
13+
context.subscriptions.push(
14+
vscode.commands.registerCommand('extension.readme', () => insertReadMe(context))
15+
);
16+
17+
context.subscriptions.push(
18+
vscode.commands.registerCommand('extension.readmeOnExplorer', (e) =>
19+
insertReadmeOnExplorer(context, e.path)
20+
)
21+
);
22+
23+
function insertReadMe(context: vscode.ExtensionContext) {
1724
const writer = new ReadmeWriter(context);
1825
writer.insertReadme();
19-
});
26+
}
2027

21-
context.subscriptions.push(disposable);
28+
function insertReadmeOnExplorer(context: vscode.ExtensionContext, url: string) {
29+
const writer = new ReadmeWriter(context);
30+
writer.insertReadmeOnExplorer(url);
31+
}
2232
}
2333

2434
// this method is called when your extension is deactivated

src/lib/ReadmeWriter.ts

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,59 @@ export class ReadmeWriter {
77
constructor(private context: vscode.ExtensionContext) {}
88

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

1512
if (selectedItem) {
1613
await this.createFile(selectedItem);
1714
}
1815
}
1916

20-
private async createFile(selectedItem: string) {
21-
const tempPath = this.context.asAbsolutePath(
22-
path.join('templates', `${selectedItem}.md`)
23-
);
17+
async insertReadmeOnExplorer(url: string) {
18+
const selectedItem = await this.getQuickPickItem();
19+
20+
if (selectedItem) {
21+
await this.createFile(selectedItem, url);
22+
}
23+
}
24+
25+
private async createFile(selectedItem: string, url?: string) {
26+
const tempPath = this.context.asAbsolutePath(path.join('templates', `${selectedItem}.md`));
2427
const buffer = await this.fs.readFile(vscode.Uri.file(tempPath));
25-
const folders = vscode.workspace.workspaceFolders;
2628
const reader = new JsonContentReader();
2729
let content = '';
30+
const filePath = this.getFilePath(url);
2831

29-
console.log(`folders:${JSON.stringify(folders)}`);
3032
console.log(`selectedItem:${selectedItem}`);
33+
console.log(`url:${filePath}`);
3134

32-
if (folders) {
33-
const url = folders[0].uri;
34-
const filePath = path.join(url.fsPath, 'README.md');
35-
36-
console.log(`url:${filePath}`);
37-
35+
if (filePath) {
3836
content = await reader.replaceContent(buffer.toString());
3937
await this.fs.writeFile(vscode.Uri.file(filePath), Buffer.from(content));
4038
}
4139
}
40+
41+
private async getQuickPickItem() {
42+
const items: string[] = ['Bot', 'Hackathon', 'Minimal', 'Standard'];
43+
const selectedItem = await vscode.window.showQuickPick(items, {
44+
placeHolder: 'Select readme pattern that you want',
45+
});
46+
return selectedItem;
47+
}
48+
49+
private getFilePath(url?: string) {
50+
const folders = vscode.workspace.workspaceFolders;
51+
const fileName = 'README.md';
52+
let filePath = '';
53+
54+
if (url) {
55+
filePath = path.join(url, fileName);
56+
} else if (folders) {
57+
console.log(`folders:${JSON.stringify(folders)}`);
58+
59+
const folderUrl = folders[0].uri;
60+
filePath = path.join(folderUrl.fsPath, fileName);
61+
}
62+
63+
return filePath;
64+
}
4265
}

0 commit comments

Comments
 (0)