Skip to content

Commit

Permalink
确认列表显示位置更新
Browse files Browse the repository at this point in the history
检查列表显示位置变为临时文件, 修复ignore包含模式BUG(!), 打包到单文件-准备Web端
  • Loading branch information
xiaohuohumax committed Mar 27, 2024
1 parent 3244a31 commit 5b2f5f6
Show file tree
Hide file tree
Showing 40 changed files with 999 additions and 544 deletions.
5 changes: 5 additions & 0 deletions .changeset/funny-hotels-develop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"format-files-by-ignores": minor
---

检查列表显示位置变为临时文件, 修复 ignore 包含模式 BUG(!), 打包到单文件-准备 Web 端
3 changes: 2 additions & 1 deletion .formatignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ images
.formatignore
LICENSE
*.png
*.md
*.md
*.txt
3 changes: 3 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ jobs:
- name: Create Release Pull Request
id: changesets
uses: changesets/action@v1
# todo 将 vsix 加入 release
with:
publish: npx changeset tag
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Expand Down
38 changes: 33 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

VSCode Extensions Select `Format Files By Ignores`

![ext.png](https://cdn.jsdelivr.net/gh/xiaohuohumax/format-files-by-ignores/images/ext.png)

## 📄 Usage

- **Format Workspace**
Expand All @@ -29,6 +27,26 @@ VSCode Extensions Select `Format Files By Ignores`
- **Custom Ignore File**
- Create a file called `.formatignore` under the folder, and then write the ignore rules (like `.gitignore`)

## Practical tips (ignore rule)

### Exclude model

**For example:** Exclude all **svg** files

```txt
*.svg
```

### Include model

**For example:** Only include **ts** files

```txt
*
!src/**/
!src/**/*.ts
```

## ⚙ Options

- `formatFilesByIgnores.useignoreExtension`: Is use ignore extension ?
Expand All @@ -40,12 +58,22 @@ VSCode Extensions Select `Format Files By Ignores`
- `formatFilesByIgnores.collapseExplorerFolders`: Whether to collapse the explorer folder after formatting?
- `default`: true

## Ignore priority

```txt
ignoreExtension < ignoreFileNames
ignoreFileNames[1] < ignoreFileNames[2]
```

## 📹 Demo

![folder.gif](https://cdn.jsdelivr.net/gh/xiaohuohumax/format-files-by-ignores/images/folder.gif)
![folder.gif](https://cdn.jsdelivr.net/gh/xiaohuohumax/format-files-by-ignores/images/folder_1_5_0.gif)

![workspace.gif](https://cdn.jsdelivr.net/gh/xiaohuohumax/format-files-by-ignores/images/workspace_1_5_0.gif)

![workspace.gif](https://cdn.jsdelivr.net/gh/xiaohuohumax/format-files-by-ignores/images/cancel_1_5_0.gif)

![workspace.gif](https://cdn.jsdelivr.net/gh/xiaohuohumax/format-files-by-ignores/images/workspace.gif)

## 🔗 Link

- [Homepage](https://github.com/xiaohuohumax/format-files-by-ignores#readme)
Expand Down
32 changes: 28 additions & 4 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ VSCode插件:依据 ignore 文件筛选文件,然后批量格式化文件(

VSCode 插件搜索 `Format Files By Ignores`

![ext.png](https://cdn.jsdelivr.net/gh/xiaohuohumax/format-files-by-ignores/images/ext.png)

## 使用

+ **格式文件夹(folder)**
Expand All @@ -32,6 +30,22 @@ VSCode 插件搜索 `Format Files By Ignores`
+ **自定义ignore文件**
+ 文件夹下创建名叫 `.formatignore` 的文件, 接着写入过滤规则(规则和 `.gitignore` 相同)

## ignore 实用技巧

### 排除模式 (例如: 排除全部 **svg** 文件)

```txt
*.svg
```

### 包含模式 (例如: 只包含 **ts** 文件)

```txt
*
!src/**/
!src/**/*.ts
```

## 配置

- `formatFilesByIgnores.useignoreExtension`: 是否使用过滤规则扩展?
Expand All @@ -43,11 +57,21 @@ VSCode 插件搜索 `Format Files By Ignores`
- `formatFilesByIgnores.collapseExplorerFolders`: 格式化完成后是否折叠资源管理器文件夹?
- `default`: true

## ignore 优先级

```txt
ignoreExtension < ignoreFileNames
ignoreFileNames[1] < ignoreFileNames[2]
```

## 演示

![folder.gif](https://cdn.jsdelivr.net/gh/xiaohuohumax/format-files-by-ignores/images/folder.gif)
![folder.gif](https://cdn.jsdelivr.net/gh/xiaohuohumax/format-files-by-ignores/images/folder_1_5_0.gif)

![workspace.gif](https://cdn.jsdelivr.net/gh/xiaohuohumax/format-files-by-ignores/images/workspace_1_5_0.gif)

![workspace.gif](https://cdn.jsdelivr.net/gh/xiaohuohumax/format-files-by-ignores/images/workspace.gif)
![workspace.gif](https://cdn.jsdelivr.net/gh/xiaohuohumax/format-files-by-ignores/images/cancel_1_5_0.gif)

## 链接

Expand Down
Binary file added images/cancel_1_5_0.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed images/ext.png
Binary file not shown.
Binary file removed images/folder.gif
Binary file not shown.
Binary file added images/folder_1_5_0.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed images/workspace.gif
Binary file not shown.
Binary file added images/workspace_1_5_0.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions package-lock.json

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

14 changes: 11 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@
".gitignore",
".formatignore"
]
},
"formatFilesByIgnores.organizeImports": {
"scope": "resource",
"type": "boolean",
"description": "Is organize imports?",
"default": false
}
}
}
Expand All @@ -77,17 +83,18 @@
{
"command": "formatFilesByIgnores.start.formatFolder",
"title": "Start Format Folder By Ignores 📂",
"enablement": "explorerViewletVisible && filesExplorerFocus && explorerResourceIsFolder"
"enablement": "explorerViewletVisible && filesExplorerFocus && explorerResourceIsFolder && !formatFilesByIgnores.formating"
},
{
"command": "formatFilesByIgnores.start.formatWorkspace",
"title": "Start Format Workspace By Ignores 📂"
"title": "Start Format Workspace By Ignores 📂",
"enablement": "!formatFilesByIgnores.formating"
}
],
"menus": {
"explorer/context": [
{
"when": "explorerResourceIsFolder",
"when": "explorerResourceIsFolder && !formatFilesByIgnores.formating",
"command": "formatFilesByIgnores.start.formatFolder",
"group": "navigation@-1"
}
Expand All @@ -97,6 +104,7 @@
"scripts": {
"vscode:prepublish": "npm run compile",
"compile": "vite build",
"build": "vite build",
"watch": "vite build --watch --mode development --emptyOutDir",
"pretest": "npm run compile && npm run lint:fix",
"lint:fix": "eslint --ext .ts,.mts,.d.ts --fix .",
Expand Down
78 changes: 78 additions & 0 deletions src/cmd/iCmd.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { Config } from '@/config';
import { EAborted } from '@/error';
import log from '@/log';
import msg from '@components/msg';
import { ExtensionContext, commands, window } from 'vscode';

/**
* 配置
*/
export interface CmdOptions {
/**
* 注册 key
*/
key: string
}

/**
* 通用命令
*/
export default abstract class ICmd {

constructor(protected options: CmdOptions) { }

/**
* 命令回调
* @param args 任意回调参数
*/
abstract run(...args: unknown[]): Promise<void>;

/**
* 回调抛出异常时执行
* @param error 异常
*/
async catch(error: Error) {
if (error instanceof EAborted) {
msg.showWarningMessage(error.message);
return;
}
window.showErrorMessage(error.message);
log.error(error.stack ?? error.message);
}

/**
* 回调执行完后执行
*/
async finally() { }

/**
* 注册指令
* @param context 上下文
*/
async activate(context: ExtensionContext) {
log.debug('Register command:', this.options.key);

const callback = async (...args: unknown[]) => {
log.debug('Format config:', JSON.stringify(Config.get));
log.debug('Command:', this.options.key, 'callback args:', args);
try {
return await this.run(...args);
} catch (error) {
await this.catch(error as Error);
} finally {
await this.finally();
}
};

const disposable = commands.registerCommand(this.options.key, callback);

context.subscriptions.push(disposable);
}

/**
* 注销指令
*/
async deactivate() {
log.debug('Deactivate command:', this.options.key);
}
}
Loading

0 comments on commit 5b2f5f6

Please sign in to comment.