https://github.com/oneofone/vscode-save-runner
Save Runner for Visual Studio Code
https://github.com/oneofone/vscode-save-runner
typescript vscode vscode-extension
Last synced: about 2 months ago
JSON representation
Save Runner for Visual Studio Code
- Host: GitHub
- URL: https://github.com/oneofone/vscode-save-runner
- Owner: OneOfOne
- Created: 2018-04-30T04:55:49.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2019-05-08T18:55:32.000Z (about 7 years ago)
- Last Synced: 2026-01-01T05:47:22.894Z (6 months ago)
- Topics: typescript, vscode, vscode-extension
- Language: TypeScript
- Homepage: https://marketplace.visualstudio.com/items?itemName=oneofone.save-runner
- Size: 105 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# Save Runner for Visual Studio Code
This extension allows configuring commands that get run whenever a file is about to be saved or after it gets saved to disk.
This extension is heavily inspired by [emeraldwalk.runonsave](https://marketplace.visualstudio.com/items?itemName=emeraldwalk.RunOnSave) and
eslint extension's lack of proper fixing on save.
## Features
* Preprocess the document and save the processed results.
* Pipe the document to multiple preprocessors.
* Use a temp file for before-save commands that doesn't support pipes.
* Regex pattern matching for files that trigger commands running.
* Sync and async support for after save commands.
## Configuration
```ts
interface Config extends vscode.WorkspaceConfiguration {
enabled: boolean; // default false
// show the output panel on updates
showOutput: boolean; // default false
// execute pre/post commands under the specified shell.
shell: string; // default ''
// auto clear the output channel before running commands.
autoClearOutput: boolean;
// commands to run
commands: Command[];
}
interface Command {
enabled?: boolean; // default false
include?: string; // regexp to match the file names
exclude?: string; // regexp to exclude file names
// use a tempfile on pre-save, pass ${tmpFile} to the commands.
useTempFile?: boolean; // default true
// run post-save commands async.
isAsync?: boolean; // default false
// commands to run before the document is saved, the documen will be replaced with the stdout of the command chain.
// if useTempFile is false, the document will be piped to the commands.
pre: string | string[];
// commands to run after the file is successfully saved to disk.
post: string | string[];
}
```
* **TODO:** make this section human readable. *
## Example
Run `eslint_d --fix` and update the document before saving.
```json
"save-runner.enabled": true,
"save-runner.commands": [
// write the current document to a tmp file, run eslint_d --fix on it,
// and run diff on the modified tmp file and apply it to the document.
{
"enabled": false,
"include": "\\.[tj]sx?$",
"exclude": "/node_modules/",
"pre": "eslint_d --fix ${tmpFile}",
"post": "echo saved ${relname}"
},
// pipe the current document to goimports,
// then runs a diff on the output of goimports and applies it to the document.
{
"enabled": true,
"include": "\\.go$",
"useTempFile": false,
"pre": "goimports",
"post": "echo saved ${relname}"
}
]
```
## Placeholders in commands
* `${tmpFile}`: temp file path when `useTempFile` is set
* `${workspaceRoot}`: workspace root folder
* `${file}`: full path to the file
* `${relname}`: path to the file without the workspace path.
* `${ext}`: file extension
* `${dirname}`: directory name of saved file
* `${basename}`: saved file's basename
* `${basenameNoExt}`: saved file's basename without extension
* `${cwd}`: current working directory
* `${env.**name**}` match environment variable by name
## TODO
* Detect commands that can return a diff (`goimports` for example`) and use that rather than using internal diff.
## Links
* [Marketplace](https://marketplace.visualstudio.com/items?itemName=oneofone.save-runner)
* [Source Code](https://github.com/OneOfOne/vscode-save-runner)
## License
[MIT](https://opensource.org/licenses/MIT)