Grunt plugin to check remote file existence
Check if file exists on remote server
This plugin requires Grunt ~0.4.5
If you haven’t used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you’re familiar with that process, you may install this plugin with this command:
npm install grunt-remote-exists --save-dev
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
grunt.loadNpmTasks('grunt-remote-exists');
In your project’s Gruntfile, add a section named remote_exists
to the data object passed into grunt.initConfig()
.
grunt.initConfig({
remote_exists: {
options: {
operation: null,
connectOpts: {
host: 'hostname',
port: 22,
username: 'username',
passphrase: 'passphrase',
privateKey: 'privateKey'
}
},
your_target: {
src: ['/remote/path/to/file']
},
},
});
Type: String
Default value: none
A path to file on a remote server to check if it exists.
Type: String
of null
Default value: null
String which tells plugin whether it should create, remove or just check file.
Type: Object
of null
Default value: null
An object with ssh connection params.
In this example, the default options for file creation are used. So the file specified in filePath
will be checked on the remote host
, and result of this checking will be outputted to the console.
grunt.initConfig({
remote_exists: {
options: {
filePath: '/remote/path/to/file',
connectOpts: {
host: 'hostname',
port: 22,
username: 'username',
passphrase: 'passphrase',
privateKey: 'privateKey'
}
}
}
});
If filePath
does not exist, it will be created since touch
option is enabled. Checking results will be outputted as well.
grunt.initConfig({
remote_exists: {
options: {
operation: 'touch',
connectOpts: {
host: 'hostname',
port: 22,
username: 'username',
passphrase: 'passphrase',
privateKey: 'privateKey'
}
},
default_config: {
src: ['/remote/path/to/file']
}
}
});
If filePath
exists, it will be removed, nothing will be done otherwise. Checking results will be outputted as well.
grunt.initConfig({
remote_exists: {
options: {
operation: 'rm',
connectOpts: {
host: 'hostname',
port: 22,
username: 'username',
passphrase: 'passphrase',
privateKey: 'privateKey'
}
},
default_config: {
src: ['/remote/path/to/file']
}
}
});