VS-Shell-Format 项目使用教程
1. 项目的目录结构及介绍
VS-Shell-Format 是一个用于 Visual Studio Code 的插件,主要用于格式化 Shell 脚本、Dockerfile、gitignore 等文件。项目的目录结构如下:
vs-shell-format/
├── .github/
│ └── workflows/
├── client/
│ ├── src/
│ │ ├── commands/
│ │ ├── extension.ts
│ │ └── test/
│ ├── package.json
│ └── tsconfig.json
├── server/
│ ├── src/
│ │ ├── main.ts
│ │ └── test/
│ ├── package.json
│ └── tsconfig.json
├── .gitignore
├── LICENSE
├── package.json
├── README.md
└── tsconfig.json
目录结构介绍
- .github/workflows: 包含 GitHub Actions 的工作流配置文件。
- client: 包含插件客户端的源代码和配置文件。
- src: 客户端的源代码目录。
- commands: 包含插件的命令实现。
- extension.ts: 插件的主入口文件。
- test: 客户端的测试代码。
- package.json: 客户端的 npm 配置文件。
- tsconfig.json: 客户端的 TypeScript 配置文件。
- src: 客户端的源代码目录。
- server: 包含插件服务端的源代码和配置文件。
- src: 服务端的源代码目录。
- main.ts: 服务端的主入口文件。
- test: 服务端的测试代码。
- package.json: 服务端的 npm 配置文件。
- tsconfig.json: 服务端的 TypeScript 配置文件。
- src: 服务端的源代码目录。
- .gitignore: Git 忽略文件配置。
- LICENSE: 项目的开源许可证。
- package.json: 项目的 npm 配置文件。
- README.md: 项目的说明文档。
- tsconfig.json: 项目的 TypeScript 配置文件。
2. 项目的启动文件介绍
VS-Shell-Format 插件的启动文件主要位于 client/src/extension.ts
。这个文件是插件的入口点,负责初始化插件并注册命令。
import * as vscode from 'vscode';
import { format } from './commands/format';
export function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(
vscode.commands.registerCommand('shell-format.format', format)
);
}
export function deactivate() {}
启动文件介绍
- activate: 插件激活时调用的函数,注册了
shell-format.format
命令。 - deactivate: 插件停用时调用的函数,目前为空。
3. 项目的配置文件介绍
VS-Shell-Format 插件的配置文件主要位于 client/package.json
和 server/package.json
。这些文件包含了插件的依赖、命令、配置等信息。
client/package.json
{
"name": "shell-format",
"displayName": "shell-format",
"description": "A formatter for shell scripts, Dockerfile, gitignore, properties, etc.",
"version": "7.0.0",
"publisher": "foxundermoon",
"engines": {
"vscode": "^1.50.0"
},
"categories": [
"Formatters"
],
"activationEvents": [
"onCommand:shell-format.format"
],
"main": "./out/extension.js",
"contributes": {
"commands": [
{
"command": "shell-format.format",
"title": "Format Shell Script"
}
]
},
"scripts": {
"vscode:prepublish": "npm run compile",
"compile": "tsc -p ./",
"watch": "tsc -watch -p ./",
"pretest": "npm run compile && npm run lint",
"lint": "eslint src --ext ts",
"test": "node ./out/test/runTest.js"