Code Monkey home page Code Monkey logo

vscode-auto-run-command's Introduction

VSCode Extension - auto-run-command

Run a command when VSCode starts, based on some conditions. Built to run Wallaby.js automatically on projects that have a config. I decided to make it a bit more generic to play around with the API (and because developing an extension there is super smooth! Awesome work VSCode guys!)

Usage

The way this extension works is by reading a list of rules from your settings. Each rule is evaluated and if the rule's condition is met, a command is ran.

A rule consists of a condition, a command and an optional message. The message will be shown if the condition is met.

You need to open your settings: File -> Preferences -> User Settings, and add a rule. Check below for examples.

ProTip™: Both command and condition accept arrays. If you pass in multiple conditions, all of them have to be met. If multiple commands are passed, all of the will run.

Note: commands run after a 5s delay to ensure the command was registered. If there's a better way to do that other than delaying, let me know!

Example Settings

  1. Simple -Running wallaby.js when vscode opens on a folder with a config file
"auto-run-command.rules": [
		{
			"condition": "hasFile: wallaby.js",
			"command": "wallaby.start",
			"message": "Running wallaby"
		}
	]
  1. Running some command (assuming an extension exposed it) when vscode opens on a specific project containing a specific file
"auto-run-command.rules": [
		{
			"condition": [
				"hasFile: special-file",
				"isRootFolder: my-coolz-prodgekt"
			]
			"command": "crazy-ext.do-magic",
			"message": "Super condition met. Running "
		}
	]

If you find a real usage for this other than wallaby.js I'll be glad to know! Leave a message in the issues part.

#Supported rules

Condition Description Arguments Example
always Is always true none always
hasFile Will only be true if a file exists in the current folder file name / glob (did not test glob) hasFile: wallaby.js
isLanguage Will run if the first file opened is using a specific language. Not sure how useful is it :) language id isLanguage: typescript
isRootFolder Will run if the name of the root folder in the current workspace matches the argument folder name isRootFolder: my-cool-project

Release Notes

1.0.0

Initial release of auto-run-command


Contributing

  • To run locally just open the project and debug using vscode.
  • To add more rules check out src/lib/condition-parser.ts and src/lib/condition-checker.ts. Make sure to add a test on the parser too

PR's are welcomed!

Enjoy!

vscode-auto-run-command's People

Contributors

gabigrin avatar oshalygin avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.