diff --git a/CHANGELOG.md b/CHANGELOG.md index e533a0d..30a9dee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [1.0.2] - 2019-08-02 +### Fix +- put commands in alphabetical order + ## [1.0.1] - 2019-07-29 ### Added - explain images @@ -30,7 +34,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - README - icon -[Unreleased]: https://github.com/yamajyn/commandlist/compare/v1.0.1...HEAD +[Unreleased]: https://github.com/yamajyn/commandlist/compare/v1.0.2...HEAD +[1.0.2]: https://github.com/yamajyn/commandlist/releases/tag/v1.0.2 [1.0.1]: https://github.com/yamajyn/commandlist/releases/tag/v1.0.1 [1.0.0]: https://github.com/yamajyn/commandlist/releases/tag/v1.0.0 [0.2.0]: https://github.com/yamajyn/commandlist/releases/tag/v0.2.0 diff --git a/README.md b/README.md index f7c82e6..779c0dd 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,10 @@ right-click on command ## Release Notes +### 1.0.2 + +Put commands in alphabetical order + ### 1.0.1 Fix light theme icon. diff --git a/package-lock.json b/package-lock.json index e9974a3..0c1a645 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "commandlist", - "version": "0.0.2", + "version": "1.0.2", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -78,6 +78,12 @@ "@types/node": "*" } }, + "@types/sanitize-filename": { + "version": "1.1.28", + "resolved": "https://registry.npmjs.org/@types/sanitize-filename/-/sanitize-filename-1.1.28.tgz", + "integrity": "sha1-uqGPXOQzD8uz6nti9lVQlj2aqgc=", + "dev": true + }, "@types/uuid": { "version": "3.4.5", "resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-3.4.5.tgz", @@ -1011,6 +1017,14 @@ "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", "dev": true }, + "sanitize-filename": { + "version": "1.6.2", + "resolved": "https://registry.npmjs.org/sanitize-filename/-/sanitize-filename-1.6.2.tgz", + "integrity": "sha512-cmTzND7RMxUB+f7gI+4+KAVHWEg0lfXvQJdko+FXDP5bNbGIdx4KMP5pX6lv5jfT9jSf6OBbjyxjFtZQwYA/ig==", + "requires": { + "truncate-utf8-bytes": "^1.0.0" + } + }, "semver": { "version": "5.7.0", "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.0.tgz", @@ -1101,6 +1115,14 @@ } } }, + "truncate-utf8-bytes": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/truncate-utf8-bytes/-/truncate-utf8-bytes-1.0.2.tgz", + "integrity": "sha1-QFkjkJWS1W94pYGENLC3hInKXys=", + "requires": { + "utf8-byte-length": "^1.0.1" + } + }, "tslib": { "version": "1.10.0", "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.10.0.tgz", @@ -1211,6 +1233,11 @@ "requires-port": "^1.0.0" } }, + "utf8-byte-length": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/utf8-byte-length/-/utf8-byte-length-1.0.4.tgz", + "integrity": "sha1-9F8VDExm7uloGGUFq5P8u4rWv2E=" + }, "util-deprecate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", diff --git a/package.json b/package.json index 8d1342b..bda7291 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "Save and display shell commands like File Explorer", "publisher": "yamajyn", "icon": "resources/icon@128.png", - "version": "1.0.1", + "version": "1.0.2", "license": "MIT", "galleryBanner": { "color": "#ffffff", @@ -229,6 +229,7 @@ "@types/mocha": "^2.2.42", "@types/node": "^10.12.21", "@types/rimraf": "^2.0.2", + "@types/sanitize-filename": "^1.1.28", "@types/uuid": "^3.4.5", "tslint": "^5.12.1", "typescript": "^3.3.1", @@ -238,6 +239,7 @@ "dependencies": { "mkdirp": "^0.5.1", "rimraf": "^2.6.3", + "sanitize-filename": "^1.6.2", "uuid": "^3.3.2" } } diff --git a/src/commandExplorer.ts b/src/commandExplorer.ts index c05bde6..3965f8e 100644 --- a/src/commandExplorer.ts +++ b/src/commandExplorer.ts @@ -4,6 +4,7 @@ import * as fs from 'fs'; import * as mkdirp from 'mkdirp'; import * as rimraf from 'rimraf'; import * as uuid from 'uuid/v4'; +import * as sanitizeFilename from 'sanitize-filename'; import { Entry } from './type/Entry'; import { Command } from './type/Command'; @@ -179,17 +180,15 @@ export class FileSystemProvider implements vscode.TreeDataProvider, vscod vscode.window.showInputBox({ placeHolder: 'Enter a new command script' }) .then(value => { if (value !== null && value !== undefined) { + const fileName = sanitizeFilename(value).slice(0, 250); + const command: Command = { + script: value + }; if(selected){ - const command: Command = { - script: value - }; - const filePath = selected.type === vscode.FileType.Directory ? `${selected.uri.fsPath}/${uuid()}.json` : `${this.getDirectoryPath(selected.uri.fsPath)}/${uuid()}.json`; + const filePath = selected.type === vscode.FileType.Directory ? `${selected.uri.fsPath}/${fileName}.json` : `${this.getDirectoryPath(selected.uri.fsPath)}/${fileName}.json`; this._writeFile(filePath, this.stringToUnit8Array(JSON.stringify(command)),{ create: true, overwrite: true }); }else{ - const command: Command = { - script: value - }; - this._writeFile(`${this.rootUri.fsPath}/${uuid()}.json`, this.stringToUnit8Array(JSON.stringify(command)),{ create: true, overwrite: true }); + this._writeFile(`${this.rootUri.fsPath}/${fileName}.json`, this.stringToUnit8Array(JSON.stringify(command)),{ create: true, overwrite: true }); } } }); @@ -212,14 +211,18 @@ export class FileSystemProvider implements vscode.TreeDataProvider, vscod edit(element?: Entry){ if(element && element.type === vscode.FileType.File){ const file: Command = JSON.parse(fs.readFileSync(element.uri.fsPath, 'utf8')); - vscode.window.showInputBox({ placeHolder: 'Edit command and Save', value:file.script ? file.script : '' }) - .then(value => { + vscode.window.showInputBox({ + placeHolder: 'Edit command and Save', + value:file.script ? file.script : '' + }).then(async value => { if (value !== null && value !== undefined) { const data: Command = { script: value }; - const filePath = element.uri.fsPath; - this._writeFile(filePath, this.stringToUnit8Array(JSON.stringify(data)),{ create: false, overwrite: true }); + const fileName = sanitizeFilename(value).slice(0, 250); + const newUri = vscode.Uri.file(`${this.getDirectoryPath(element.uri.fsPath)}/${fileName}.json`); + await this.delete(element.uri, { recursive: false }); + await this._writeFile(newUri.fsPath, this.stringToUnit8Array(JSON.stringify(data)),{ create: true, overwrite: true }); } }); }else if(element && element.type === vscode.FileType.Directory){ @@ -339,31 +342,23 @@ export class FileSystemProvider implements vscode.TreeDataProvider, vscod // tree data provider async getChildren(element?: Entry): Promise { - if (element) { - const children = await this.readDirectory(element.uri); - return children - .filter(([name, type]) => this.isJson(name) || type === vscode.FileType.Directory) - .map(([name, type]) => ({ uri: vscode.Uri.file(path.join(element.uri.fsPath, name)), type })); + + let uri: vscode.Uri = element ? element.uri : this.rootUri; + + if (!element && !await _.exists(uri.fsPath)){ + this.createDirectory(this.rootUri); + return []; } - - const rootPath = this.rootUri.fsPath; - if (rootPath) { - if (!await _.exists(rootPath)){ - this.createDirectory(this.rootUri); + const children = await this.readDirectory(uri); + children.sort((a, b) => { + if (a[1] === b[1]) { + return a[0].localeCompare(b[0]); } - const children = await this.readDirectory(vscode.Uri.file(rootPath)); - children.sort((a, b) => { - if (a[1] === b[1]) { - return a[0].localeCompare(b[0]); - } - return a[1] === vscode.FileType.Directory ? -1 : 1; - }); - return children - .filter(([name, type]) => this.isJson(name) || type === vscode.FileType.Directory) - .map(([name, type]) => ({ uri: vscode.Uri.file(path.join(rootPath, name)), type })); - } - - return []; + return a[1] === vscode.FileType.Directory ? -1 : 1; + }); + return children + .filter(([name, type]) => this.isJson(name) || type === vscode.FileType.Directory) + .map(([name, type]) => ({ uri: vscode.Uri.file(path.join(uri.fsPath, name)), type })); } getTreeItem(element: Entry): vscode.TreeItem {