As you’ve discovered, the GUI is not available at this point. I don’t know of a specific tutorial on build scripts yet, although there are some clues in the tutorial link above. If you have access to the components SVN, you can download the sample build script (under templates, I think) or the build script for any of the components (in that component’s build folder) to get an idea of how it’s done.
Here’s the one I did for EZfaq:
<?php
$mtime = microtime();
$mtime = explode(" ", $mtime);
$mtime = $mtime[1] + $mtime[0];
$tstart = $mtime;
$sources= array (
'root' => dirname(dirname(__FILE__)) . '/',
'assets' => dirname(dirname(__FILE__)) . '/assets/',
);
/* This example assumes that you are creating one element with one namespace, a lexicon, and one file resolver.
* You'll need to modify it if your situation is different. A snippet with no support files (no images, no css, no js includes, etc.) doesn't need a file
* resolver so you can comment out that part of the code. If you have no lexicon, you can comment out that part of the code. If you need to create multiple
* elements (e.g. a snippet, several chunks, and maybe a plugin) you can do it all in this file, but you'll have to duplicate the code below that creates
* and packages the element. You'll also have to reset the variables for each segment. If you put all your support files in or below in a single
* directory, you'll only need one file resolver.
*/
$element_namespace = 'ezfaq'; // lexicon namespace for your add-on
$element_name = 'EZfaq'; // name of your element as it will appear in the Manager
$element_object_type = 'modSnippet'; // What is it? modSnippet, modChunk, modPlugin, etc.
$element_type = 'snippet'; // What is it without the "mod"
$element_description = 'EZfaq 3.0.5-beta - Generates a FAQ page for your site.'; // description field in the element's editing page
$element_source_file = $sources['assets'] . 'ezfaq/snippet.ezfaq.php'; // Where's the file PB will use to create the element
$element_category = 0; // the category of the element
$package_name = $element_name; // The name of the package as it will appear in Workspaces will be this plus the next two variables
$package_version = '3.0.5';
$package_release = 'beta';
$lexicon_path = $sources['root'] . '_build/lexicon/'; // Where's the lexicon directory
$resolver_source = $sources['assets'] . 'ezfaq'; // Files in this directory will be packaged
$resolver_target = "return MODX_ASSETS_PATH . 'snippets/';"; // Those files will go here
/* Note that for file resolvers, the named directory itself is also packaged.
* So the two lines above will copy the ezfaq dir and its contents
* to the assets/snippets/ directory in the target install.
*/
// get rid of time limit
set_time_limit(0);
// override with your own defines here (see build.config.sample.php)
require_once dirname(__FILE__).'/build.config.php';
require_once (MODX_CORE_PATH . 'model/modx/modx.class.php');
$modx= new modX();
$modx->initialize('mgr');
//$modx->setDebug(true);
$modx->loadClass('transport.modPackageBuilder','',false, true);
$builder = new modPackageBuilder($modx);
$builder->create($package_name,$package_version,$package_release);
$builder->registerNamespace($element_namespace,false,true);
if (!file_exists($element_source_file)) {
echo "<b>Error</b> - Element source file not found: {$element_source_file}<br>";
exit();
}
print "Creating element from source file: {$element_source_file}<br>";
// get the source from the actual element in your database OR
// manually create the object, grabbing the source from a file
$c= $modx->newObject($element_object_type);
$c->set('name', $element_name);
$c->set('description', $element_description);
$c->set('category', $element_category);
$c->set($element_type, file_get_contents($element_source_file));
// create a transport vehicle for the data object
$attributes= array(
XPDO_TRANSPORT_UNIQUE_KEY => 'name',
XPDO_TRANSPORT_UPDATE_OBJECT => true,
);
$vehicle = $builder->createVehicle($c, $attributes);
echo "<br>Creating Resolver<br>";
if (!is_dir($resolver_source)) {
echo "<b>Error</b> - Resolver source directory not found: {$resolver_source}<br>";
exit();
}
echo " Source: {$resolver_source}<br>";
echo " Target: {$resolver_target}<br><br>";
$vehicle->resolve('file',array(
'source' => $resolver_source,
'target' => $resolver_target,
));
$builder->putVehicle($vehicle);
if (!is_dir($lexicon_path)) {
echo "<b>Error</b> - Lexicon path not found: {$lexicon_path}";
exit();
}
echo "Creating lexicon from: {$lexicon_path}<br><br>";
// load lexicon strings
$builder->buildLexicon($lexicon_path);
// zip up the package
$builder->pack();
$mtime= microtime();
$mtime= explode(" ", $mtime);
$mtime= $mtime[1] + $mtime[0];
$tend= $mtime;
$totalTime= ($tend - $tstart);
$totalTime= sprintf("%2.4f s", $totalTime);
echo "Package completed<br>Execution time: {$totalTime}<br>";
exit ();