mkloubert / vs-deploy

Visual Studio Code extension that provides commands to deploy files of a workspace to a destination.
https://marketplace.visualstudio.com/items?itemName=mkloubert.vs-deploy
MIT License
131 stars 24 forks source link

Play sound after deployment? #144

Closed bavarianbytes closed 6 years ago

bavarianbytes commented 6 years ago

Hi, is there an option to run a command on the client after a deployment? I want to play a sound via afplay /System/Library/Sounds/Glass.aiff. Thx

mkloubert commented 6 years ago

@bavarianbytes

Yes, use can run a command via a target operation:

{
    "deploy": {
        "targets": [
            {
                "type": "test",
                "name": "This is a test",

                "deployed": [
                    {
                        "type": "open",
                        "target": "afplay",
                        "arguments": [ "/System/Library/Sounds/Glass.aiff" ],
                        "wait": false
                    }
                ]
            }
        ]
    }
}

Another way to do this is, is to run a script:

{
    "deploy": {
        "targets": [
            {
                // ...

                "deployed": [
                    {
                        "type": "script",
                        "script": "./play-sound.js",
                        "options": "/System/Library/Sounds/Glass.aiff"
                    }
                ]
            }
        ]
    }
}

The script (./play-sound.js) can look like that:

exports.execute = function(args) {
    // s. https://nodejs.org/api/child_process.html#child_process_child_process_execfilesync_file_args_options
    require('child_process').execFileSync(
        "afplay",
        [ args.options ]  // "/System/Library/Sounds/Glass.aiff"
    );
}

If you use relative paths, those paths are mapped to your workspace.

bavarianbytes commented 6 years ago

Thx for the extensive answer!