Skip to content
This repository was archived by the owner on Feb 17, 2021. It is now read-only.

Commit d1b1e60

Browse files
committed
Initial commit
0 parents  commit d1b1e60

File tree

13 files changed

+855
-0
lines changed

13 files changed

+855
-0
lines changed

.circleci/config.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
version: 2.1
2+
3+
orbs:
4+
default:
5+
executors:
6+
php-73:
7+
docker:
8+
- image: 'circleci/php:7.3-stretch'
9+
jobs:
10+
build-php:
11+
executor: php-73
12+
steps:
13+
- run: php -v
14+
- checkout
15+
- restore_cache:
16+
keys:
17+
- composer-v1-{{ checksum "composer.lock" }}
18+
- composer-v1-
19+
- run: composer install -n --prefer-dist --no-scripts --no-suggest
20+
- run: composer lint
21+
- save_cache:
22+
key: composer-v1-{{ checksum "composer.lock" }}
23+
paths:
24+
- vendor
25+
26+
workflows:
27+
build:
28+
jobs:
29+
- default/build-php

.editorconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
insert_final_newline = true
7+
indent_style = space
8+
indent_size = 2
9+
trim_trailing_whitespace = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false
13+
14+
[*.php]
15+
indent_size = 4

.gitattributes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/.gitattributes export-ignore
2+
/.github export-ignore
3+
/.circleci export-ignore

.github/FUNDING.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
custom: https://www.paypal.me/log1x

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
vendor

LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 Brandon Nifong
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# Sage Eject Blocks
2+
3+
![Latest Stable Version](https://img.shields.io/packagist/v/log1x/sage-eject-blocks?style=flat-square)
4+
![Build Status](https://img.shields.io/circleci/build/github/Log1x/sage-eject-blocks?style=flat-square)
5+
![Total Downloads](https://img.shields.io/packagist/dt/log1x/sage-eject-blocks?style=flat-square)
6+
7+
## So what do we have here?
8+
9+
This package is a 4-5 hour, half-assed attempt/proof of concept to devise a strategy to solve the seperation of concerns that Gutenberg has created in the theme development workflow.
10+
11+
![Preview](https://i.imgur.com/LvZJ76W.gif)
12+
13+
### Current Problem
14+
15+
Gutenberg is amazing, but has destroyed the theme workflow with having to separate concerns between theme + Gutenberg package/plugin.
16+
17+
If you code your blocks into your theme and the theme changes, your blocks disappear and you risk losing content. Yikes.
18+
19+
### Proposed Solution
20+
21+
This attempts to address that concern by allowing you to eject the block scripts from your theme into a plugin auto-magically on-the-go while still prioritizing loading them from your theme if they exist. Styles still come from your theme and are not included during ejection. Theme goes away? Plugin takes over.
22+
23+
The theme stay themein', the generated plugin functions...if it _has_ too. There are currently no dependencies on Sage 10 or Acorn in the generated plugin, but obviously they are required if you want to use this.
24+
25+
### Avoiding conflicts
26+
27+
Conflict avoidence is currently done using [`wp_script_is()`](https://developer.wordpress.org/reference/functions/wp_script_is/) – but I am more than open to other solutions/ideas.
28+
29+
This allows us to maintain our workflow 100% inside of our theme, and as a freelance developer, agency, etc. – take it upon ourselves to do the right thing, and eject our scripts into a plugin whether it be manually, through continuous integration, etc. so down the road, if the site is to change - they aren't screwed, and you don't have to change how you've been doing things for the past XY years.
30+
31+
### Uhhh...okay?
32+
33+
The concept and CLI flow may be rough around the edges, but I assure you I can make it prettier and feel nicer if this is an idea that would prove to be fruitful and people actually want it.
34+
35+
Maybe this isn't the right way to look at this? Maybe this is useless? I don't know. That's why I'm putting it out there. You tell me.
36+
37+
No, really. Please stop my suffering immediately if this is useless.
38+
39+
### TODO (Maybe?)
40+
41+
- Make CLI prettier.
42+
- Allow more verbose output.
43+
- Allow things to be more programatical (no input required).
44+
- Allow things to be pre-configured (config/whatever.php).
45+
- Assure CI flow is adequate (see 3/4).
46+
- Debate `wp_script_is()` and alternatives.
47+
- Debate what should and should not be configurable for compatibility purposes.
48+
- Assure the plugin loader is written in the best way humanly possible (and works as intended).
49+
- Code check me, please.
50+
51+
## Requirements
52+
53+
- [Sage](https://github.com/roots/sage) >= 10.0
54+
- [PHP](https://secure.php.net/manual/en/install.php) >= 7.2
55+
- [Composer](https://getcomposer.org/download/)
56+
57+
## Installation
58+
59+
Install via Composer:
60+
61+
```bash
62+
$ composer require log1x/sage-eject-blocks
63+
```
64+
65+
## Usage
66+
67+
```bash
68+
$ wp acorn eject:blocks
69+
```
70+
71+
## Bug Reports
72+
73+
Yes.
74+
75+
## Contributing
76+
77+
Yes.
78+
79+
## License
80+
81+
Sage Eject Blocks is provided under the [MIT License](https://github.com/log1x/sage-eject-blocks/blob/master/LICENSE.md).

composer.json

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"name": "log1x/sage-eject-blocks",
3+
"type": "package",
4+
"license": "MIT",
5+
"description": "Eject Sage 10 editor scripts to a optional lazy-loaded plugin.",
6+
"authors": [
7+
{
8+
"name": "Brandon Nifong",
9+
"email": "brandon@tendency.me"
10+
}
11+
],
12+
"keywords": [
13+
"wordpress",
14+
"gutenberg"
15+
],
16+
"support": {
17+
"issues": "https://github.com/log1x/sage-eject-blocks/issues"
18+
},
19+
"autoload": {
20+
"psr-4": {
21+
"Log1x\\EjectBlocks\\": "src/"
22+
}
23+
},
24+
"require": {
25+
"php": ">=7.2"
26+
},
27+
"require-dev": {
28+
"squizlabs/php_codesniffer": "^3.5"
29+
},
30+
"extra": {
31+
"acorn": {
32+
"providers": [
33+
"Log1x\\EjectBlocks\\EjectBlocksServiceProvider"
34+
]
35+
}
36+
},
37+
"scripts": {
38+
"lint": [
39+
"phpcs --ignore=vendor --extensions=php --standard=PSR12 ."
40+
]
41+
}
42+
}

composer.lock

Lines changed: 71 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Console/Commands/Command.php

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
3+
namespace Log1x\EjectBlocks\Console\Commands;
4+
5+
use Symfony\Component\Process\Process;
6+
use Roots\Acorn\Console\Commands\Command as CommandBase;
7+
8+
class Command extends CommandBase
9+
{
10+
/**
11+
* Write a string as error output.
12+
*
13+
* @param string $string
14+
* @param int|string|null $verbosity
15+
* @return false
16+
*/
17+
public function error($string, $verbosity = null)
18+
{
19+
$this->line('');
20+
$this->line($string, 'error', $verbosity);
21+
$this->line('');
22+
return false;
23+
}
24+
25+
/**
26+
* Execute a process and return the status to console.
27+
*
28+
* @param string|array $commands
29+
* @param boolean $output
30+
* @return mixed
31+
*/
32+
protected function exec($commands, $output = false)
33+
{
34+
if (! is_array($commands)) {
35+
$commands = explode(' ', $commands);
36+
}
37+
38+
$process = new Process($commands);
39+
$process->run();
40+
41+
if ($output) {
42+
return $process->getOutput();
43+
}
44+
45+
return true;
46+
}
47+
48+
/**
49+
* Run a task in the console.
50+
*
51+
* @param string $title
52+
* @param callable|null $task
53+
* @param string $status
54+
* @return mixed
55+
*/
56+
protected function task($title, $task = null, $status = '...')
57+
{
58+
if (! $task) {
59+
return $this->output->write("$title: '<info>✔</info>'");
60+
}
61+
62+
$this->output->write("$title: <comment>{$status}</comment>");
63+
64+
try {
65+
$status = $task() === false ? false : true;
66+
} catch (\Exception $e) {
67+
$status = false;
68+
}
69+
70+
if ($this->output->isDecorated()) {
71+
$this->output->write("\x0D");
72+
$this->output->write("\x1B[2K");
73+
} else {
74+
$this->output->writeln('');
75+
}
76+
77+
$this->output->writeln(
78+
$title . ': ' . ($status ? '<info>✔</info>' : '<red>x</red>')
79+
);
80+
81+
if (! $status) {
82+
exit;
83+
}
84+
85+
return $status;
86+
}
87+
}

0 commit comments

Comments
 (0)