xycode是vscode的轻量级命令执行器.

Posted by ExiaHuang on December 19, 2019

xycode

xycode 是 vscode 的轻量级命令执行器.

如果您想构建一个 vscode 扩展程序,也许您可 ​​ 以先使用xycode

特征

  • 小于 100k.
  • 定义您的 vscode 扩展。
  • 只需要配置一次,是 Vscode 的 Task 扩展。
  • Integrated with system command and work with vscode.
  • 支持 c 语言编程.
  • 支持 vbs.
  • 支持 dotnet core.
  • 支持 go language.
  • 支持 python.
  • 支持 ruby.
  • 支持 gradle language.
  • 支持 npm/nodejs/express/vue.
  • 支持 prettier, format source automatically.
  • 支持 Heroku development.
  • 支持 git command.
  • 支持 sfdx, 用于 Salesforce SFDX 开发的快速开发工具。
  • 支持 Wenyan 文言文編程語言.
  • 支持写博客 hexo/mkdoc blog.
  • TODO : jekyll .
  • TODO : Docker development.
  • TODO : a calculator.

下载配置

在 vscode 中自动下载

执行 xycode: download config命令, 下载配置.

手动下载

从 github 中下载配置 xycode-config. 复制到 Home 目录( ~/.xycode or %USERPROFILE%/.xycode)

自定义配置

创建 json 文件

在下面目录下创建配置 Windows user: %USERPROFILE%/.xycode Linux/Mac user: ~/.xycode

json 数据结构

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
{
    "tasks": [
        {
            "label": "label name, required",
            "description": "description, not required",
            "command": "your command, required",
            // cwd is not required
            "cwd": "path of current working directory",
            // filetypes is not required
            // "filetypes": [".py"],
            // if you not need the command , please set it true
            // "inActive": false,
            // show the message in termial, default show in channel.
            // "termial": { name?: string, shellPath?: string, shellArgs?: string[] | string };
            // before run the command, you can set some check.
            "beforeTriggers": [
                {
                    "type": "buildin",
                    "fn": "CheckFileExist",
                    "params": ["${project_directory}/${project_name}"]
                }
            ],
            // after ran the command, you can do something.
            "afterTriggers": [
                {
                    "type": "buildin",
                    "fn": "SwitchFolder",
                    "params": ["${project_directory}/${project_name}"]
                }
            ]
        }
    ],
    "variables": {
        "apex_template": {
            "label": "sfdc apex template",
            "description": "",
            "value": [
                "DefaultApexClass",
                "ApexException",
                "ApexUnitTest",
                "InboundEmailService"
            ]
        },
        "base_metadata": {
            "label": "default sfdc metadata",
            "description": "",
            "value": "ApexClass, ApexPage, ApexComponent, ApexTrigger"
        }
    }
}

预定义变量

  • ${HOME} - Home directory
  • ${file} - the current opened file
  • ${fileBasename} - the current opened file’s basename
  • ${fileBasenameNoExtension} - the current opened file’s basename with no file extension
  • ${workspaceFolder} - the path of the folder opened
  • ${workspaceFolderBasename} - the name of the folder opened in Sublime without any slashes (/)
  • ${fileDirname} - the current opened file’s dirname
  • ${fileExtname} - the current opened file’s extension
  • ${YYYYMMDD} - current date
  • ${YYYYMMDD_HHmm} - current datetime

预定义触发器

  • Mkdirs - make directory
  • SwitchFolder - switch project folder
  • OpenFile - open file
  • CheckFileExist - check file exist
  • Diff - diff file

用户交互命令

  • input - Custom Input String
  • select - Select List
  • multiselect - Multiple Select List
  • openFolderDailog - Folder Path Selector
  • singleFileDailog - File Path Selector
  • multiFilesDailog - Mutliple File Paths Selector

配置例子

例子 1: input

echo user input

1
2
3
4
5
6
7
8
9
10
{
    "tasks": [
        {
            "label": "hello:echo:user-input",
            "description": "echo user input",
            "command": "echo ${input:project_directory}"
        }
    ],
    "variables": {}
}

if you want to set the default value, please define the variable:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
{
    "tasks": [
        {
            "label": "hello:echo:user-input",
            "description": "echo user input",
            "command": "echo ${input:project_directory}"
        }
    ],
    "variables": {
        "project_directory": {
            "label": "project directory",
            "value": "${HOME}/test-project"
        }
    }
}

例子 2: select

echo user select

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
{
    "tasks": [
        {
            "label": "hello:echo:user-select",
            "description": "echo user select",
            "command": "echo ${select:dotnet_template}"
        }
    ],
    "variables": {
        "dotnet_template": {
            "label": "dotnet core template",
            "value": [
                "console",
                "classlib",
                "wpf",
                "wpflib",
                "wpfcustomcontrollib",
                "wpfusercontrollib",
                "winforms"
            ]
        }
    }
}

例子 3: multiselect

echo files path, you can use separator to control the result string.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
{
    "tasks": [
        {
            "label": "hello:echo:multiselect",
            "description": "echo user multiselect",
            "command": "echo ${multiselect:METADATA}"
        }
    ],
    "variables": {
        "METADATA": {
            "label": "sfdc metadata",
            "separator": ",",
            "value": [
                "ApexClass",
                "ApexComponent",
                "ApexPage",
                "ApexTestSuite",
                "ApexTrigger"
            ]
        }
    }
}

例子 4: openFolderDailog

echo directory path

1
2
3
4
5
6
7
8
9
10
{
    "tasks": [
        {
            "label": "hello:echo:folder-path",
            "description": "echo directory",
            "command": "echo ${openFolderDailog:project_directory}"
        }
    ],
    "variables": {}
}

例子 5: singleFileDailog

single file dailog, you can use filters to control the file type.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
{
    "tasks": [
        {
            "label": "hello:echo:file-path",
            "description": "echo single file path",
            "command": "echo ${singleFileDailog:package_xml}"
        }
    ],
    "variables": {
        "package_xml": {
            "label": "sfdc package.xml path",
            "filters": { "package.xml": ["xml"] },
            "value": "./manifest/package.xml"
        }
    }
}

例子 6: multiFilesDailog

Mutliple File Paths Selector

  • use filters to control the file type.
  • use separator to control the result string.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
{
    "tasks": [
        {
            "label": "hello:echo:files-paths",
            "description": "echo files paths",
            "command": "echo ${multiFilesDailog:sfdcsourcesfiles}"
        }
    ],
    "variables": {
        "sfdcsourcesfiles": {
            "label": "sfdc sources files",
            "separator": ",",
            "value": ""
        }
    }
}

例子 7: run command in wsl

change the shellPath, you can run command in wsl/bash/powershell … or other termial

1
2
3
4
5
6
7
8
{
    "label": "run command in wsl",
    "termial": {
        "name": "xycode",
        "shellPath": "wsl.exe"
    },
    "command": "pwd"
}

例子 8: auto formatter and auto runner

After you save file in vscode, It will use yapf to format code and run python code automatically.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
{
    "tasks": [],
    "variables": {},
    "onSaveEvents": [
        {
            "label": "format python code",
            "description": "format python code",
            "filetypes": [".py"],
            "inActive": false,
            "command": "yapf \"${file}\" --style \"google\" -i"
        },
        {
            "label": "run python file",
            "description": "run python file",
            "filetypes": [".py"],
            "inActive": false,
            "cwd": "${fileDirname}",
            "command": "python \"${file}\""
        }
    ]
}

例子 10: user prettier to format source code.

use Prettier to pretty code .

1
2
3
4
5
6
7
8
9
10
11
12
13
14
{
    "tasks": [],
    "variables": {},
    "onSaveEvents": [
        {
            "label": "pretty code.",
            "description": "Prettier is an opinionated code formatter.",
            "filetypes": [".json", ".javascript", ".js", ".md", ".css", ".vue"],
            "inActive": false,
            "cwd": "${fileDirname}",
            "command": "prettier --write \"${file}\" --single-quote=true --end-of-line=lf --arrow-parens=always --tab-width=4"
        }
    ]
}

快捷键

快捷键: ctrl+shift+i

扩展程序设置

  • xycode.maxBuffer: The maxBuffer option specifies the largest number of bytes allowed on stdout or stderr.