diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..5ac85e2 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,4 @@ +{ + "printWidth": 100, + "singleQuote": true +} diff --git a/README.md b/README.md index 25ce846..be7e9eb 100644 --- a/README.md +++ b/README.md @@ -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/) diff --git a/images/icon.png b/images/icon.png new file mode 100644 index 0000000..6200063 Binary files /dev/null and b/images/icon.png differ diff --git a/screenshot.gif b/images/screenshot.gif similarity index 100% rename from screenshot.gif rename to images/screenshot.gif diff --git a/images/screenshot01.gif b/images/screenshot01.gif new file mode 100644 index 0000000..61d0abe Binary files /dev/null and b/images/screenshot01.gif differ diff --git a/package-lock.json b/package-lock.json index 9e9f19c..2fd0a12 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,26 +1,32 @@ { "name": "vscode-readme-pattern", - "version": "1.2.0", + "version": "1.3.0", "lockfileVersion": 1, "requires": true, "dependencies": { "@babel/code-frame": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.0.0.tgz", - "integrity": "sha512-OfC2uemaknXr87bdLUkWog7nYuliM9Ij5HUcajsVcMCpQrcLmtxRbVFTIqmcSkSeYRBFBRxs2FiUqFJDLdiebA==", + "version": "7.10.4", + "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.10.4.tgz", + "integrity": "sha512-vG6SvB6oYEhvgisZNFRmRCUkLz11c7rp+tbNTynGqc6mS1d5ATd/sGyV6W0KZZnXRKMTzZDRgQT3Ou9jhpAfUg==", "dev": true, "requires": { - "@babel/highlight": "^7.0.0" + "@babel/highlight": "^7.10.4" } }, + "@babel/helper-validator-identifier": { + "version": "7.10.4", + "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.10.4.tgz", + "integrity": "sha512-3U9y+43hz7ZM+rzG24Qe2mufW5KhvFg/NhnNph+i9mgCtdTCtMJuI1TMkrIUiK7Ix4PYlRF9I5dhqaLYA/ADXw==", + "dev": true + }, "@babel/highlight": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.0.0.tgz", - "integrity": "sha512-UFMC4ZeFC48Tpvj7C8UgLvtkaUuovQX+5xNWrsIoMG8o2z+XFKjKaN9iVmS84dPwVN00W4wPmqvYoZF3EGAsfw==", + "version": "7.10.4", + "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.10.4.tgz", + "integrity": "sha512-i6rgnR/YgPEQzZZnbTHHuZdlE8qyoBNalD6F+q4vAFlcMEcqmkoG+mPqJYJCo63qPf74+Y1UZsl3l6f7/RIkmA==", "dev": true, "requires": { + "@babel/helper-validator-identifier": "^7.10.4", "chalk": "^2.0.0", - "esutils": "^2.0.2", "js-tokens": "^4.0.0" } }, @@ -118,9 +124,9 @@ "dev": true }, "commander": { - "version": "2.20.0", - "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.0.tgz", - "integrity": "sha512-7j2y+40w61zy6YC2iRNpUe/NwhNyoXrYpHMrSunaMG64nRnaf96zO/KMQR4OyN/UnE5KLyEBnKHd4aG3rskjpQ==", + "version": "2.20.3", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", + "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==", "dev": true }, "concat-map": { @@ -139,9 +145,9 @@ } }, "diff": { - "version": "3.5.0", - "resolved": "https://registry.npmjs.org/diff/-/diff-3.5.0.tgz", - "integrity": "sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA==", + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", + "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==", "dev": true }, "es6-promise": { @@ -171,12 +177,6 @@ "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==", "dev": true }, - "esutils": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.2.tgz", - "integrity": "sha1-Cr9PHKpbyx96nYrMbepPqqBLrJs=", - "dev": true - }, "fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", @@ -246,9 +246,9 @@ "dev": true }, "js-yaml": { - "version": "3.13.1", - "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.13.1.tgz", - "integrity": "sha512-YfbcO7jXDdyj0DGxYVSlSeQNHbD7XPWvrVWeVUujrQEoZzWJIRrCPoyk6kL6IAjAG2IolMK4T0hNUe0HOUs5Jw==", + "version": "3.14.0", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.14.0.tgz", + "integrity": "sha512-/4IbIeHcD9VMHFqDR/gQ7EdZdLimOvW2DdcxFjdyyZ9NsbS+ccrXqVWDtab/lRl5AlUqmpBx8EhPaWR+OtY17A==", "dev": true, "requires": { "argparse": "^1.0.7", @@ -307,9 +307,9 @@ "dev": true }, "resolve": { - "version": "1.11.1", - "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.11.1.tgz", - "integrity": "sha512-vIpgF6wfuJOZI7KKKSP+HmiKggadPQAdsp5HiC1mvqnfp0gF1vdwgBWZIdrVft9pgqoMFQN+R7BSWZiBxx+BBw==", + "version": "1.17.0", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.17.0.tgz", + "integrity": "sha512-ic+7JYiV8Vi2yzQGFWOkiZD5Z9z7O2Zhm9XMaTxdJExKasieFCr+yXZ/WmXsckHiKl12ar0y6XiXDx3m4RHn1w==", "dev": true, "requires": { "path-parse": "^1.0.6" @@ -325,9 +325,9 @@ } }, "semver": { - "version": "5.7.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.0.tgz", - "integrity": "sha512-Ya52jSX2u7QKghxeoFGpLwCtGlt7j0oY9DYb5apt9nPlJ42ID+ulTXESnt/qAQcoSERyZ5sl3LDIOw0nAn/5DA==", + "version": "5.7.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", + "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==", "dev": true }, "sprintf-js": { @@ -346,29 +346,29 @@ } }, "tslib": { - "version": "1.10.0", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.10.0.tgz", - "integrity": "sha512-qOebF53frne81cf0S9B41ByenJ3/IuH8yJKngAX35CmiZySA0khhkovshKK+jGCaMnVomla7gVlIcc3EvKPbTQ==", + "version": "1.13.0", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.13.0.tgz", + "integrity": "sha512-i/6DQjL8Xf3be4K/E6Wgpekn5Qasl1usyw++dAA35Ue5orEn65VIxOA+YvNNl9HV3qv70T7CNwjODHZrLwvd1Q==", "dev": true }, "tslint": { - "version": "5.18.0", - "resolved": "https://registry.npmjs.org/tslint/-/tslint-5.18.0.tgz", - "integrity": "sha512-Q3kXkuDEijQ37nXZZLKErssQVnwCV/+23gFEMROi8IlbaBG6tXqLPQJ5Wjcyt/yHPKBC+hD5SzuGaMora+ZS6w==", + "version": "6.1.3", + "resolved": "https://registry.npmjs.org/tslint/-/tslint-6.1.3.tgz", + "integrity": "sha512-IbR4nkT96EQOvKE2PW/djGz8iGNeJ4rF2mBfiYaR/nvUWYKJhLwimoJKgjIFEIDibBtOevj7BqCRL4oHeWWUCg==", "dev": true, "requires": { "@babel/code-frame": "^7.0.0", "builtin-modules": "^1.1.1", "chalk": "^2.3.0", "commander": "^2.12.1", - "diff": "^3.2.0", + "diff": "^4.0.1", "glob": "^7.1.1", "js-yaml": "^3.13.1", "minimatch": "^3.0.4", - "mkdirp": "^0.5.1", + "mkdirp": "^0.5.3", "resolve": "^1.3.2", "semver": "^5.3.0", - "tslib": "^1.8.0", + "tslib": "^1.13.0", "tsutils": "^2.29.0" } }, diff --git a/package.json b/package.json index 3e706e3..5587d10 100644 --- a/package.json +++ b/package.json @@ -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", @@ -25,7 +25,8 @@ }, "homepage": "https://github.com/thomascsd/vscode-readme-pattern", "activationEvents": [ - "onCommand:extension.readme" + "onCommand:extension.readme", + "onCommand:extension.readmeOnExplorer" ], "main": "./out/extension.js", "contributes": { @@ -33,9 +34,22 @@ { "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 ./", @@ -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" } diff --git a/src/extension.ts b/src/extension.ts index 3bc2d3e..6c96491 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -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 diff --git a/src/lib/ReadmeWriter.ts b/src/lib/ReadmeWriter.ts index 33e3489..d4b6488 100644 --- a/src/lib/ReadmeWriter.ts +++ b/src/lib/ReadmeWriter.ts @@ -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; + } }