Commands
Commands
Build current Project Workspace
To build a tapestry project, within the projects working directory execute:
$ tapestry build
By default the build command will load the site configuration followed by its kernel and then begin building using the default environment local. The compiled project will then be output to a folder called build_local
within the current working directory.
To change the environment that Tapestry builds the project for use the --env=
option, for example:
$ tapestry build --env=development
Tapestry will then output to a folder called build_development
within the current working directory.
Changing Source and Destination Paths
By default the Tapestry Build command will use the current working directory for targeting both source and destination paths.
To tell Tapestry to look in a specific source path use the --site-dir
option, for example:
$ tapestry build --site-dir=C:\Tapestry\Project\Path
To tell Tapestry to output the compiled files to a specific destination path use the --dist-dir
option, for example:
$ tapestry build --dist-dir=C:\An\Output\Path
The build command also has several special flags that may be used:
--no-write
: When set, Tapestry will compile the project but not write the result to disk. This is useful when twinned with the --json
flag.
--clear
: When set, Tapestry will clear the destination path of all files and disable caching.
--json
: When set, Tapestry will output a .json file containing the current build state. This is useful for third party tools when paired with --no-write
.
--stopwatch
: When set, Tapestry will benchmark the build process, reporting on the total execution time and memory used. This was found to be useful during development and has since been left in.
Initiate New Project Workspace
To initiate a new project within an empty path execute:
$ tapestry init
The current working directory must be void of any folders or files otherwise Tapestry will exit with an error.
Alternatively to initiate a new project inside a new folder within the current working directory follow the init command with the name argument:
$ tapestry init ProjectName
Tapestry will create a new folder in the current working directory and initiate into it, if the folder exists it must be empty otherwise Tapestry will exit with an error.
Self Update
If you have installed Tapestry via the preferred route of using the phar archive you can check for and subsequently update Tapestry to the most recent build by executing the following:
$ tapestry init self-update
Tapestry will make a backup copy of your current version of Tapestry before downloading and installing in place the new version – see below for more details on reverting to your previous version.
The self update command also has several special flags that may be used:
--force
: When set, Tapestry will update regardless of whether it is the current version or not.
---rollback
: When set, Tapestry will rollback to the previous version of Tapestry you had installed. This only works if there is a backup copy available.
--clean-backups
: When set, Tapestry will delete any backups that were made; using this option will make reverting to a previously installed version impossible.
Adding your own Commands
Adding commands to Tapestry is done on a per project basis and loaded via the Project Kernel, within its register
method. For example:
<?php
namespace Site;
use Tapestry\Modules\Kernel\KernelInterface;
use Tapestry\Tapestry;
class kernel implements KernelInterface
{
/**
* @var Tapestry
*/
private $tapestry;
public function __construct()
{
$this->tapestry = Tapestry::getInstance();
}
public function register()
{
// Not the ideal way of adding the file.
include __DIR__.'/TestCommand.php';
/** @var \Tapestry\Console\Application $cliApplication */
$cliApplication = $this->tapestry->getContainer()->get(\Tapestry\Console\Application::class);
$cliApplication->add(new TestCommand());
}
public function boot()
{
// ...
}
}
Every Tapestry command must extend Tapestry\Console\Commands\Command
and implement two methods configure
and fire
.
While the configure
method is part of the Symfony Console base class, the fire
method is not; the fire method is called when your command is loaded and the execute
method is called. Tapestry operates in this way to add a stopwatch and make both the Input and Output interfaces available to a few helper methods.
Below is an example test command, loaded by the previous kernel example:
<?php
namespace Site;
use Tapestry\Console\Commands\Command;
class TestKernelCommand extends Command
{
/**
* @return void
*/
protected function configure()
{
$this->setName('hello')
->setDescription('Hello World From A Kernel Loaded Command');
}
/**
* @return int
*/
protected function fire()
{
$this->info('Hello world! This command was loaded via a site Kernel.');
return 0;
}
}
Command Helper Methods
The Tapestry Command class makes a few helper methods available to Tapestry commands:
$this->info($string)
: A shortcut for $outputInterface->writeln("<info>{$string}</info>")
$this->error($string)
: A shortcut for $outputInterface->writeln('<error>[!]</error> '.$string);
$this->panic($string, $code = 1)
: A shortcut for $this->error($string); exit($code);