Skip to content

Commit

Permalink
use bob
Browse files Browse the repository at this point in the history
  • Loading branch information
joshstoik1 committed May 10, 2018
1 parent 54cc2bd commit ce15ee7
Show file tree
Hide file tree
Showing 9 changed files with 237 additions and 316 deletions.
1 change: 1 addition & 0 deletions build/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/composer.phar
/phpab.phar
/composer.lock
185 changes: 0 additions & 185 deletions build/build.php

This file was deleted.

26 changes: 14 additions & 12 deletions build/composer.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "musty",
"description": "Manage Must-Use Plugins via WP-CLI.",
"version": "0.3.0",
"name": "musty-build",
"description": "Build musty package.",
"version": "0.1",
"type": "library",
"homepage": "https:\/\/blobfolio.com",
"homepage": "https:\/\/blobfolio.com\/",
"license": "WTFPL",
"authors": [
{
Expand All @@ -14,20 +14,22 @@
],
"require": {
"php": ">= 7.0",
"blobfolio\/blob-common": "dev-7.0_Next",
"blobfolio\/blob-domain": "dev-7.0_Next",
"blobfolio\/blob-mimes": "dev-7.0_Next",
"blobfolio\/blob-phone": "dev-7.0_Next"
"bob": "dev-master"
},
"repositories": [
{
"type": "vcs",
"url": "ssh://[email protected]:3417/bob"
}
],
"config": {
"vendor-dir": "lib\/vendor",
"preferred-install": "dist"
},
"minimum-stability": "dev",
"autoload": {
"psr-4": {
"blobfolio\\wp\\cli\\":"lib\/blobfolio\/wp\/cli"
},
"files": [
]
"blobfolio\\dev\\":"lib\/dev"},
"files":[]
}
}
1 change: 1 addition & 0 deletions build/lib/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/vendor/
160 changes: 160 additions & 0 deletions build/lib/dev/plugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
<?php
/**
* Compile Plugin
*
* This will update dependencies, optimize the autoloader, and
* optionally generate a new release zip.
*
* @package musty
* @author Blobfolio, LLC <[email protected]>
*/

namespace blobfolio\dev;

use \blobfolio\bob\utility;
use \blobfolio\common\file as v_file;

class plugin extends \blobfolio\bob\base\build_wp {
const NAME = 'musty';

// Various file paths.
const SOURCE_DIR = MUSTY_SOURCE_DIR;
const COMPOSER_CONFIG = MUSTY_COMPOSER_CONFIG;
const GRUNT_TASK = 'build';
const PHPAB_AUTOLOADER = MUSTY_PHPAB_AUTOLOADER;

// Namespace patching.
const VENDOR_DIR = MUSTY_SOURCE_DIR . 'lib/vendor/';
const NAMESPACE_SWAP = 'blobfolio\\wp\\musty\\vendor\\';

// Release info.
const RELEASE_OUT = MUSTY_RELEASE_DIR . 'musty.zip';
const RELEASE_COMPRESS = array(
'%TMP%lib/vendor/blobfolio/',
);

// There are no file dependencies.
const SKIP_FILE_DEPENDENCIES = true;

protected static $_version;



/**
* Patch Extra
*
* @param string $content Content.
* @return int Replacements.
*/
protected static function patch_extra(string &$content) {
$manual = array(
"\\blobfolio\\common"=>"\\blobfolio\\wp\\musty\\vendor\\common",
"\\blobfolio\\domain"=>"\\blobfolio\\wp\\musty\\vendor\\domain",
"use \\blobfolio\\phone\\phone;"=>''
);
$tmp = $content;
$content = str_replace(
array_keys($manual),
array_values($manual),
$content
);
return ($tmp !== $content) ? 1 : 0;
}

/**
* Patch Version
*
* @param string $version Version.
* @return void Nothing.
*/
protected static function patch_version(string $version) {
// Patch the base hook cache-break version.
$tmp = file_get_contents(static::SOURCE_DIR . 'index.php');
$tmp = preg_replace("/define\('MUSTY_VERSION', '(\d+\.\d+\.\d+)'\);/", "define('MUSTY_VERSION', '$version');", $tmp);
file_put_contents(static::SOURCE_DIR . 'index.php', $tmp);

// Store this so we can find it more easily later.
static::$_version = $version;
}

/**
* Post-Package Tasks
*
* @return void Nothing.
*/
protected static function post_package() {
// We also want to build a Debian package.
utility::log('Copying debian release files…');

$working = utility::generate_tmp_dir();
v_file::copy(MUSTY_SKEL_DIR, $working);

// Remove composer file.
$composer = "{$working}composer.json";
if (is_file($composer)) {
unlink($composer);
}

// Copy our working directory over too.
$php = "{$working}opt/musty/";
v_file::copy(static::$working_dir, $php);

// If there is a control file, try to patch it.
$control = "{$working}DEBIAN/control";
if (is_file($control)) {
utility::log('Patching DEBIAN control…');
$tmp = file_get_contents($control);
$tmp = str_replace(
array(
'%VERSION%',
'%SIZE%',
),
array(
static::get_package_version(),
static::get_package_size(),
),
$tmp
);
file_put_contents($control, $tmp);
}

// Make the deb!
$deb = MUSTY_RELEASE_DIR . 'wp-cli-musty.deb';
utility::deb($working, $deb);
}

/**
* Get Version
*
* Projects will handle this differently depending on how and where
* sources come from.
*
* @return string Version.
*/
protected static function get_package_version() {
return static::$_version;
}

/**
* Get Size
*
* We can usually calculate this automatically.
*
* @return int Size.
*/
protected static function get_package_size() {
$size = 0;

// Size the whole working directory.
if (static::$working_dir && is_dir(static::$working_dir)) {
$size += v_file::dirsize(static::$working_dir);

// Subtract the DEBIAN folder.
if (is_dir(static::$working_dir . 'DEBIAN/')) {
$size -= v_file::dirsize(static::$working_dir . 'DEBIAN/');
}
}

return $size;
}
}
Loading

0 comments on commit ce15ee7

Please sign in to comment.