Skip to content

Scripting

Daniel Hazelbaker edited this page Aug 4, 2018 · 7 revisions

Scripting

You can now design scripts, in JavaScript, that let you automate tasks in RockDevBooster.

I still need to write up real documentation on the features available, but here is a quick list:

Global Variables

  • Template - Template Class reference.
  • Instance - Instance Class reference.
  • Log(message) - Logs a line of text to the RockDevBooster window.
  • LogProgress(message) - Logs a line of text without adding a new line (think "1%...", then replaced with "2%...", and so on).
  • Abort(message) - Aborts the script and displays the given message.

Template

Class Methods

  • All() - Get the names of all installed templates.
  • Exists(name) - Check if the named template exists.
  • Prompt(title) - Prompt the user to select a template (returns a Template instance).

Instance Methods

  • Deploy(instanceName, progressCallback) - Deploys a template as a new instance.

Instance

Class Methods

  • All() - Get the names of all installed instances.
  • Exists(name) - Check if the named instance exists.
  • Prompt(title) - Prompt the user to select a instance (returns an Instance instance).
  • Delete(name) - Delete the named instance.

Instance Methods

  • Start() - Starts the IIS Express process for the instance.
  • Stop() - Stops the IIS Express process.
  • InstallPlugin(pluginSpecFile, [verbose]) - Builds a rockplugin.json based plugin and installs it into the instance.
  • Warmup() - Requests the / page of the site to make sure Rock is warmed up.
  • ExecuteSqlStatement(sql) - Executes a non-select statement (such as DELETE).
  • ExecuteSqlScalar(sql) - Executes a select statement that returns a single row single value.
  • ExecuteSql(sql) - Executes a select statement that returns multiple rows and/or columns.

Example

A quick example is below. This script does the following:

  1. Ask the user what Template to use for the process (for example, a beta version of Rock).
  2. Deploys the template as the ScriptTest instance.
  3. Builds and installs 2 plugins
  4. Starts the instance
  5. Warms it up (i.e. loads a page in the background to get the RockWeb built and initialized.
  6. Runs a SQL query against the database to display the names of every person in the database.
  7. Tell the user they can now go to the instance and perform testing.
var verbose = false;

function GetInstance()
{
  // ITEM 1
  var template = Template.Prompt('Select a Template to build from');
  if (template == null) {
    Abort('Cancelled by user');
  }

  if (Instance.Exists('ScriptTest')) {
    Instance.Delete('ScriptTest');
  }

  // ITEM 2
  Log('Deploying ' + template.Name + ' as ScriptTest');
  var instance = template.Deploy('ScriptTest', function (message) {
    LogProgress(message);
  });
  Log(' Done');

  return instance;
}

function InstallPlugin(instance, plugin)
{
  var pluginBase = 'C:\\Users\\Daniel Hazelbaker\\Desktop\\Rockit\\';
  var pluginPath = pluginBase + plugin + '\\rockplugin.json';

  Log('Installing plugin ' + plugin);
  instance.InstallPlugin(pluginPath, verbose);
}

// ITEM 1 AND 2
var instance = GetInstance();

// ITEM 3
InstallPlugin(instance, 'com.blueboxmoon.WatchdogMonitor');
InstallPlugin(instance, 'com.blueboxmoon.ProjectManagement');

// ITEM 4
Log('Starting IIS');
instance.Start();

// ITEM 4
Log('Warming up IIS');
instance.Warmup();

// ITEM 6
var data = instance.ExecuteSql('SELECT * FROM [Person]');
Log('Got ' + data.length + ' people');
for (var i = 0; i < data.length; i++) {
  Log('Name: ' + data[i].FirstName + ' ' + data[i].LastName);
}

// ITEM 7
Log('------------');
Log('Instance ready. You are now free to test.');
Clone this wiki locally