-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
373 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/bin/sh | ||
# | ||
# Wrapper for our install command; at least this way it's somewhat discoverable. | ||
# Previously: | ||
# vendor/bin/phing -f vendor/palantirnet/the-build/tasks/install.xml | ||
|
||
# Relative path to this script. | ||
SCRIPT=$(readlink "$0") | ||
|
||
# Absolute path to this script's parent directory. | ||
SCRIPTPATH=$(cd `dirname $0` && cd `dirname $SCRIPT` && pwd) | ||
|
||
REPOPATH=$(cd `dirname $SCRIPTPATH` && cd ../../../ && pwd) | ||
|
||
if [ "$REPOPATH" = `pwd` ]; then | ||
# Run our install task. | ||
$SCRIPTPATH/../../../bin/phing -f $SCRIPTPATH/../tasks/install.xml | ||
else | ||
echo "Please run this command from your project root." | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,28 @@ | ||
{ | ||
"name": "palantirnet/the-build", | ||
"description": "Drupal build tasks for our projects.", | ||
"license": "proprietary", | ||
"description": "Phing build tasks for Drupal projects.", | ||
"license": "GPL-2.0+", | ||
"copyright": "Copyright 2016 Palantir.net, Inc.", | ||
"authors": [ | ||
{ | ||
"name": "Palantir.net", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"bin": [ | ||
"bin/the-build-installer" | ||
], | ||
"require": { | ||
"phing/phing": "^2.14", | ||
"continuousphp/phing-drush-task": "dev-master", | ||
"drupal/coder": "^8.2", | ||
"phpmd/phpmd" : "^2.4", | ||
"nilportugues/php_todo": "^1.0", | ||
"pear/versioncontrol_git": "@dev" | ||
}, | ||
"autoload": { | ||
"psr-0": { | ||
"TheBuild\\": "src/" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Custom Tasks | ||
|
||
## IncludeResourceTask [🔗](../src/TheBuild/IncludeResourceTask.php) | ||
|
||
Copies or symlinks a file or directory within your project. | ||
|
||
### Attributes | ||
|
||
| Name | Type | Description | Default | Required | | ||
|---|---|---|---|---| | ||
| mode | string | Either `copy` or `symlink`. Inherited from `build.artifact_mode` if available. | `symlink` | No | | ||
| source | string | Path to the resource. | n/a | Yes | | ||
| dest | string | Path where the resource should be included in your build. | n/a | Yes | | ||
|
||
### Examples | ||
|
||
```xml | ||
<!-- Copy generated CSS into your theme. --> | ||
<includeresource mode="copy" source="styleguide/src/content/assets/css" dest="web/themes/custom/my_theme/css" /> | ||
|
||
<!-- Use build properties to include a JS library in your Drupal libraries directory --> | ||
<includeresource mode="${build.artifact_mode}" source="vendor/foo/somelibrary" dest="${drupal.root}/libraries/somelibrary" /> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
<?php | ||
/** | ||
* @file IncludeResourceTask.php | ||
* | ||
* @copyright 2016 Palantir.net, Inc. | ||
*/ | ||
|
||
namespace TheBuild; | ||
|
||
use PhingFile; | ||
use BuildException; | ||
use FileSystem; | ||
|
||
|
||
class IncludeResourceTask extends \Task { | ||
|
||
/** | ||
* @var string | ||
* Either 'symlink' or 'copy'. | ||
*/ | ||
protected $mode = 'symlink'; | ||
|
||
/** | ||
* @var PhingFile | ||
* The source file or directory to include. | ||
*/ | ||
protected $source; | ||
|
||
/** | ||
* @var PhingFile | ||
* The location to link the file to. | ||
*/ | ||
protected $dest = NULL; | ||
|
||
|
||
/** | ||
* Init tasks. | ||
* | ||
* Inherits the mode from the project's build.artifact_mode property. This | ||
* can be overridden by setting the "mode" attribute. | ||
*/ | ||
public function init() { | ||
$this->setMode($this->getProject()->getProperty('build.artifact_mode')); | ||
} | ||
|
||
|
||
/** | ||
* Copy or link the resource. | ||
*/ | ||
public function main() { | ||
$this->validate(); | ||
|
||
// Remove existing destination first. | ||
if ($this->dest->exists()) { | ||
$this->log("Replacing existing resource '" . $this->dest->getPath() . "'"); | ||
|
||
if ($this->dest->delete(TRUE) === FALSE) { | ||
throw new BuildException("Failed to delete existing destination '$this->dest'"); | ||
} | ||
} | ||
|
||
// Link or copy the source artifact. | ||
if ($this->mode == 'copy') { | ||
$this->log(sprintf("Copying '%s' to '%s'", $this->source->getPath(), $this->dest->getPath())); | ||
$this->source->copyTo($this->dest); | ||
} | ||
else { | ||
$this->log(sprintf("Linking '%s' to '%s'", $this->source->getPath(), $this->dest->getPath())); | ||
FileSystem::getFileSystem()->symlink($this->source->getPath(), $this->dest->getPath()); | ||
} | ||
} | ||
|
||
|
||
/** | ||
* Verify that the required attributes are set. | ||
*/ | ||
public function validate() { | ||
if (empty($this->source) || empty($this->dest)) { | ||
throw new BuildException("Both the 'source' and 'dest' attributes are required."); | ||
} | ||
} | ||
|
||
|
||
/** | ||
* Set the artifact mode. | ||
* | ||
* @param $mode | ||
* Use 'symlink' to link resources, and 'copy' to copy them. | ||
*/ | ||
public function setMode($mode) { | ||
if (!in_array($mode, ['symlink', 'copy'])) { | ||
throw new BuildException("mode attribute must be either 'symlink' or 'copy'", $this->location); | ||
} | ||
|
||
$this->mode = $mode; | ||
} | ||
|
||
|
||
/** | ||
* Set the source of the resource to include. | ||
* | ||
* @param \PhingFile $source | ||
*/ | ||
public function setSource(PhingFile $source) { | ||
if (!$source->exists()) { | ||
throw new BuildException("resource '$source' is not available'"); | ||
} | ||
|
||
$this->source = $source; | ||
} | ||
|
||
|
||
/** | ||
* Set the destination for the resource. | ||
* @param PhingFile $dest | ||
*/ | ||
public function setDest(PhingFile $dest) { | ||
$this->dest = $dest; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.