Skip to content

Commit

Permalink
Merge pull request #14 from yamajyn/feature/sort-command
Browse files Browse the repository at this point in the history
コマンドをアルファベット順に並べるようにした
  • Loading branch information
yamajyn authored Aug 2, 2019
2 parents af24432 + bbb1e84 commit b6924ad
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 38 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
29 changes: 28 additions & 1 deletion package-lock.json

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

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Save and display shell commands like File Explorer",
"publisher": "yamajyn",
"icon": "resources/[email protected]",
"version": "1.0.1",
"version": "1.0.2",
"license": "MIT",
"galleryBanner": {
"color": "#ffffff",
Expand Down Expand Up @@ -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",
Expand All @@ -238,6 +239,7 @@
"dependencies": {
"mkdirp": "^0.5.1",
"rimraf": "^2.6.3",
"sanitize-filename": "^1.6.2",
"uuid": "^3.3.2"
}
}
65 changes: 30 additions & 35 deletions src/commandExplorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -179,17 +180,15 @@ export class FileSystemProvider implements vscode.TreeDataProvider<Entry>, 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 });
}
}
});
Expand All @@ -212,14 +211,18 @@ export class FileSystemProvider implements vscode.TreeDataProvider<Entry>, 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){
Expand Down Expand Up @@ -339,31 +342,23 @@ export class FileSystemProvider implements vscode.TreeDataProvider<Entry>, vscod
// tree data provider

async getChildren(element?: Entry): Promise<Entry[]> {
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 {
Expand Down

0 comments on commit b6924ad

Please sign in to comment.