Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pulling joel/feat/migrate-tool into main #31

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 31 additions & 31 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,44 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

Please do not update the unreleased notes.

## [1.1.1](https://github.com/locomotive-charcoal/Charcoal/compare/v1.1.0...v1.1.1) (2022-06-01)
## [v2.0.0](https://github.com/locomotive-charcoal/Charcoal/compare/v1.3.4...v2.0.0) - 2022-06-08

### Changes :

#### ⚠ BREAKING CHANGES

- The location of the packages must be changed everywhere they are called.

#### Code Refactoring

- remove the "charcoal-" prefix from the package names ([3302354](https://github.com/locomotive-charcoal/Charcoal/commit/3302354378025fe038f5b8091d8b54dfb50ba54a))

## [v1.3.4](https://github.com/locomotive-charcoal/Charcoal/compare/v1.3.3...v1.3.4) - 2022-06-08

### Changes :

#### Bug Fixes

- **action:** add token to checkout in update-changelog.yaml ([20a51aa](https://github.com/locomotive-charcoal/Charcoal/commit/20a51aa09fbd8eff49100d68654a3fddf84f5bc0))
- Regenerate composer.lock from PHP 7.4 ([4d1eddd](https://github.com/locomotive-charcoal/Charcoal/commit/4d1edddccf66630b5582ef7e7897df4e8f9acc4a))

## [v1.3.3](https://github.com/locomotive-charcoal/Charcoal/compare/v1.1.1...v1.3.3) - 2022-06-08

### Changes :

#### Bug Fixes

- **action:** add token to checkout in update-changelog.yaml ([f491bbd](https://github.com/locomotive-charcoal/Charcoal/commit/f491bbd8456f19882b3ee1bd6358b8681b62e8d8))

## [v1.1.1](https://github.com/locomotive-charcoal/Charcoal/compare/v1.1.0...v1.1.1) - 2022-06-01

### Bug Fixes

- **gitignore:** remove CHANGELOG from gitignore ([d695b92](https://github.com/locomotive-charcoal/Charcoal/commit/d695b927cba3ae2fd7033c58db36b4b0956cb3bc))
- **release:** remove pull_request event from release action ([1b64881](https://github.com/locomotive-charcoal/Charcoal/commit/1b648818bd7f828cd03b0747e9318ee386b54982))
- **release:** remove pull_request generation from semantic release workflow ([3027fcb](https://github.com/locomotive-charcoal/Charcoal/commit/3027fcbfbf34dc813c73b1d6ba54591e9d6817ee))

## [1.1.0](https://github.com/locomotive-charcoal/Charcoal/compare/v1.0.0...v1.1.0) (2022-05-31)
## [v1.1.0](https://github.com/locomotive-charcoal/Charcoal/compare/v1.0.0...v1.1.0) - 2022-05-31

### Bug Fixes

Expand All @@ -41,32 +70,3 @@ Please do not update the unreleased notes.
- **changelog:** add title and description to changelog generation ([93b8f2a](https://github.com/locomotive-charcoal/Charcoal/commit/93b8f2ae9b01c82a714c87b8b9257daa42e60288))
- **release:** add github pull-request ([79e6915](https://github.com/locomotive-charcoal/Charcoal/commit/79e69154876231c292e0c1c30c37a4a3dc15197d))
- **release:** add github pull-request to .releaserc ([8a5f33e](https://github.com/locomotive-charcoal/Charcoal/commit/8a5f33eafe6f9f7e252c4ee75b9b7d24c21f00e6))

## [v2.0.0](https://github.com/locomotive-charcoal/Charcoal/compare/v1.3.4...v2.0.0) - 2022-06-08

### [2.0.0](https://github.com/locomotive-charcoal/Charcoal/compare/v1.3.4...v2.0.0) (2022-06-08)

#### ⚠ BREAKING CHANGES

- The location of the packages must be changed everywhere they are called.

#### Code Refactoring

- remove the "charcoal-" prefix from the package names ([3302354](https://github.com/locomotive-charcoal/Charcoal/commit/3302354378025fe038f5b8091d8b54dfb50ba54a))

## [v1.3.4](https://github.com/locomotive-charcoal/Charcoal/compare/v1.3.3...v1.3.4) - 2022-06-08

### [1.3.4](https://github.com/locomotive-charcoal/Charcoal/compare/v1.3.3...v1.3.4) (2022-06-08)

#### Bug Fixes

- **action:** add token to checkout in update-changelog.yaml ([20a51aa](https://github.com/locomotive-charcoal/Charcoal/commit/20a51aa09fbd8eff49100d68654a3fddf84f5bc0))
- Regenerate composer.lock from PHP 7.4 ([4d1eddd](https://github.com/locomotive-charcoal/Charcoal/commit/4d1edddccf66630b5582ef7e7897df4e8f9acc4a))

## [v1.3.3](https://github.com/locomotive-charcoal/Charcoal/compare/v1.1.1...v1.3.3) - 2022-06-08

### [1.3.3](https://github.com/locomotive-charcoal/Charcoal/compare/v1.3.2...v1.3.3) (2022-06-08)

#### Bug Fixes

- **action:** add token to checkout in update-changelog.yaml ([f491bbd](https://github.com/locomotive-charcoal/Charcoal/commit/f491bbd8456f19882b3ee1bd6358b8681b62e8d8))
71 changes: 36 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div align="center">
<br/>
<img width="300" alt="charcoal" src="assets/docs/images/charcoal-logo-full.svg"/>
<h2>by Locomotive 🚂</h2>
<h1 alt="charcoal" title="charcoal" aria-title="charcoal"><img width="300" alt="charcoal" src="assets/docs/images/charcoal-logo-full.svg"/></h1>
<h2>by <a href="https://locomotive.ca">Locomotive</a> 🚂</h2>
</div>

[![License][badge-license]][charcoal]
Expand All @@ -12,43 +12,44 @@

## A Monorepo for the Charcoal Application suite 🔥

This monorepo contains the integrality of the Charcoal Framework that can be used directly within a website project.
You'll find all the different packages in [`/packages`](./packages/) directory. These packages all also individually hosted in `READONLY` format under the [charcoal][charcoal-git].
This monorepo contains the integrality of the Charcoal Framework usable directly within a website project.
You'll find all the different packages in [`/packages`](./packages/) directory. These packages all also individually
hosted in `READONLY` format under the [charcoal][charcoal-git].

## Charcoal packages

| Package | Description |
|-------------------------------------------------------------------------------------|-------------|
| [`admin`](https://github.com/locomotive-charcoal/charcoal-admin) | |
| [`app`](https://github.com/locomotive-charcoal/charcoal-app) | |
| [`attachment`](https://github.com/locomotive-charcoal/charcoal-attachment) | |
| [`cache`](https://github.com/locomotive-charcoal/charcoal-cache) | |
| [`cms`](https://github.com/locomotive-charcoal/charcoal-cms) | |
| [`config`](https://github.com/locomotive-charcoal/charcoal-config) | |
| [`core`](https://github.com/locomotive-charcoal/charcoal-core) | |
| [`email`](https://github.com/locomotive-charcoal/charcoal-email) | |
| [`factory`](https://github.com/locomotive-charcoal/charcoal-factory) | |
| [`image`](https://github.com/locomotive-charcoal/charcoal-image) | |
| [`object`](https://github.com/locomotive-charcoal/charcoal-object) | |
| [`property`](https://github.com/locomotive-charcoal/charcoal-property) | |
| [`queue`](https://github.com/locomotive-charcoal/charcoal-queue) | |
| [`translator`](https://github.com/locomotive-charcoal/charcoal-translator) | |
| [`ui`](https://github.com/locomotive-charcoal/charcoal-ui) | |
| [`user`](https://github.com/locomotive-charcoal/charcoal-user) | |
| [`view`](https://github.com/locomotive-charcoal/charcoal-view) | |
| Package | Description |
|-----------------------------------------------------------|-------------|
| [`admin`](https://github.com/charcoalphp/admin) | |
| [`app`](https://github.com/charcoalphp/app) | |
| [`attachment`](https://github.com/charcoalphp/attachment) | |
| [`cache`](https://github.com/charcoalphp/cache) | |
| [`cms`](https://github.com/charcoalphp/cms) | |
| [`config`](https://github.com/charcoalphp/config) | |
| [`core`](https://github.com/charcoalphp/core) | |
| [`email`](https://github.com/charcoalphp/email) | |
| [`factory`](https://github.com/charcoalphp/factory) | |
| [`image`](https://github.com/charcoalphp/image) | |
| [`object`](https://github.com/charcoalphp/object) | |
| [`property`](https://github.com/charcoalphp/property) | |
| [`queue`](https://github.com/charcoalphp/queue) | |
| [`translator`](https://github.com/charcoalphp/translator) | |
| [`ui`](https://github.com/charcoalphp/ui) | |
| [`user`](https://github.com/charcoalphp/user) | |
| [`view`](https://github.com/charcoalphp/view) | |


## Installation

The preferred (and only supported) method is with Composer:

```shell
$ composer require locomotive-charcoal/charcoal
$ composer require charcoal/charcoal
```
> Note that `charcoal` is intended to be run along a `charcoal-app` based project. To start from a boilerplate:
>
> ```shell
> $ composer create-project locomotive-charcoal/boilerplate
> $ composer create-project charcoal/boilerplate

### À la carte methode

Expand Down Expand Up @@ -154,13 +155,13 @@ Output:
>
>### Features
>
>* **create-pr:** add a script to trigger a pull request on the remote ([3016115](https://github.com/locomotive-charcoal/charcoal/commit/3016115d4f7c919261c54e3a17ae6c36552e532a))
>* **create-pr:** add a script to trigger a pull request on the remote ([3016115](https://github.com/charcoalphp/charcoal/commit/3016115d4f7c919261c54e3a17ae6c36552e532a))
>
>
>### Bug Fixes
>
>* **create-pr:** remove Personal access token from script and replace with $GITHUB_TOKEN instead ([f2aaac6](https://github.com/locomotive-charcoal/charcoal/commit/f2aaac6dbd630f0f8fa759e49f9f41c957e3868a))
>* **package:** add missing semantic-release plugin ([59bd1b1](https://github.com/locomotive-charcoal/charcoal/commit/59bd1b1798e4e7b6bf874c7ba8ecbae19d76342b))
>* **create-pr:** remove Personal access token from script and replace with $GITHUB_TOKEN instead ([f2aaac6](https://github.com/charcoalphp/charcoal/commit/f2aaac6dbd630f0f8fa759e49f9f41c957e3868a))
>* **package:** add missing semantic-release plugin ([59bd1b1](https://github.com/charcoalphp/charcoal/commit/59bd1b1798e4e7b6bf874c7ba8ecbae19d76342b))

## Contributing

Expand All @@ -174,7 +175,7 @@ Please see [CONTRIBUTION.md](./CONTRIBUTION.md) for guidelines on how to contrib

## 🎉 Contributors

[![contributors](https://contrib.rocks/image?repo=Locomotive-Charcoal/charcoal)](https://github.com/Locomotive-Charcoal/charcoal/graphs/contributors)
[![contributors](https://contrib.rocks/image?repo=charcoalphp/charcoal)](https://github.com/charcoalphp/charcoal/graphs/contributors)

Made with [contrib.rocks](https://contrib.rocks).

Expand All @@ -188,15 +189,15 @@ The changelog is compliant with [*keepachangelog*](https://keepachangelog.com/en

Charcoal is licensed under the MIT license. See [LICENSE](LICENSE) for details.

[charcoal]: https://packagist.org/packages/locomotive-charcoal/charcoal
[charcoal-git]: https://github.com/locomotive-charcoal
[charcoal]: https://packagist.org/packages/charcoal/charcoal
[charcoal-git]: https://github.com/charcoalphp
[semantic-release]: https://github.com/semantic-release/semantic-release
[commitizen]: http://commitizen.github.io/cz-cli/
[reviewers]: https://github.com/orgs/locomotive-charcoal/teams/reviewers
[reviewers]: https://github.com/orgs/charcoalphp/teams/reviewers

[badge-license]: https://img.shields.io/packagist/l/locomotive-charcoal/charcoal.svg?style=flat-square
[badge-version]: https://img.shields.io/packagist/v/locomotive-charcoal/charcoal.svg?style=flat-square&logo=packagist
[badge-php]: https://img.shields.io/packagist/php-v/locomotive-charcoal/charcoal?style=flat-square&logo=php
[badge-license]: https://img.shields.io/packagist/l/charcoal/charcoal.svg?style=flat-square
[badge-version]: https://img.shields.io/packagist/v/charcoal/charcoal.svg?style=flat-square&logo=packagist
[badge-php]: https://img.shields.io/packagist/php-v/charcoal/charcoal?style=flat-square&logo=php
[badge-semantic-release]: https://img.shields.io/badge/semantic--release-conventionalcommits-e10079?logo=semantic-release&style=flat-square
[badge-commitizen]: https://img.shields.io/badge/commitizen-friendly-brightgreen.svg?style=flat-square

Expand Down
File renamed without changes
2 changes: 2 additions & 0 deletions build/script/create-release-notes
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ const cli = meow(`
type: 'boolean'
},
from: {
alias: 'f',
type: 'string'
},
to: {
alias: 't',
type: 'string'
},
}
Expand Down
25 changes: 25 additions & 0 deletions build/script/migrate-project
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/sh

# Migrate a charcoal project to the monorepo version
cd $(dirname $0)

CHARCOAL_BASE=../../
PROJECT_BASE=../../../
FILE=config/config.json

echo navigating to charcoal directory

cd $CHARCOAL_BASE

echo Fetching and parsing charcoal packages

PACKAGES="$(vendor/bin/monorepo-builder packages-json)"

PACKAGES=$(sed -Ee 's/(\[|\]|")//g' <<< $PACKAGES)
PACKAGES=$(sed -Ee 's/,/|/g' <<< $PACKAGES)

echo Replacing metadata paths in ${PROJECT_BASE}${FILE}

NEW_CONTENT=$(sed -Ee "s#vendor/locomotivemtl/charcoal-($PACKAGES)#%package.\1.path%#g" ${PROJECT_BASE}${FILE})

echo "$NEW_CONTENT" > ${PROJECT_BASE}${FILE}
4 changes: 2 additions & 2 deletions create-pr
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#!/bin/sh

OWNER=locomotive-charcoal
OWNER=charcoalphp
REPO=charcoal
REF=$(git branch --show-current)
BASE=${1:-main}
USER=$(git config user.email)

echo "Preparing pull request form $REF to $BASE..."

HTTP_CODE=$(curl --write-out "%{http_code}\n" --output output.txt --silent \
HTTP_CODE=$(curl --write-out "%{http_code}\n" --silent \
-X POST \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/$OWNER/$REPO/actions/workflows/create-pull-request.yaml/dispatches \
Expand Down
2 changes: 1 addition & 1 deletion packages/admin/composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"type": "library",
"name": "locomotivemtl/charcoal-admin",
"name": "charcoal/admin",
"description": "The Charcoal Administration Dashboard",
"keywords": ["charcoal", "admin", "cms"],
"homepage": "https://charcoal.locomotive.ca",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ protected function registerAdminServices(Container $container)
// The `admin.json` file is not part of regular config
if (!empty($appConfig['admin_config'])) {
$appAdminConfigs = (array)$appConfig['admin_config'];
$container['package/map']->map($appAdminConfigs);
array_push($extraConfigs, ...$appAdminConfigs);
}

Expand Down Expand Up @@ -195,7 +196,7 @@ protected function registerMetadataExtensions(Container $container)
/**
* @return MetadataConfig
*/
$container['metadata/config'] = function () {
$container['metadata/config'] = function (Container $container) {
$settings = $container['admin/config']['metadata'];
$metaConfig = new MetadataConfig($settings);

Expand Down
100 changes: 100 additions & 0 deletions packages/app/src/Charcoal/App/Service/PackageMapService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?php

namespace Charcoal\App\Service;

use UnexpectedValueException;

/**
* Class PackageMapService
*/
class PackageMapService
{
const PACKAGES_DIRECTORY = '/vendor/charcoal/charcoal/packages/';
const CHARCOAL_PACKAGE = 'charcoal/charcoal';

private bool $isMonoRepo;
private string $basePath;

/**
* @param array $data The init data.
*/
public function __construct(array $data)
{
$this->isMonoRepo = \Composer\InstalledVersions::isInstalled(self::CHARCOAL_PACKAGE);
$this->basePath = $data['basePath'];
}

/**
* @param string|string[] $value The value(s) to map to package.
* @return mixed
*/
public function map(&$value)
{
if (is_array($value)) {
array_walk($value, [$this, 'mapOne']);
return $value;
}

return $this->mapOne($value);
}

/**
* Replaces placeholders (%package.key.path%) by their values in the config.
*
* @param string $value A value to resolve.
* @throws UnexpectedValueException If the resolved value is not a string or number.
* @return mixed
*/
public function mapOne(string &$value): string
{
$value = preg_replace_callback('/%%|%package\.([^\.%\s]+)\.path%/', function ($match) use ($value) {
// skip escaped %%
if (!isset($match[1])) {
return '%%';
}

$package = $match[1];

$resolved = ($this->resolvePackagePath($package) ?? null);

if (!is_string($resolved) && !is_numeric($resolved)) {
$resolvedType = (is_object($resolved) ? get_class($resolved) : gettype($resolved));

throw new UnexpectedValueException(sprintf(
'Invalid config parameter "%s" inside string value "%s"; '.
'must be a string or number, received %s',
$package,
$value,
$resolvedType
));
}

return $resolved;
}, $value);

return $value;
}

/**
* @param string $package The package string identifier.
* @return string|null
*/
private function resolvePackagePath(string $package): ?string
{
if ($this->isMonoRepo) {
$directory = self::PACKAGES_DIRECTORY.$package;

if (file_exists($this->basePath.$directory)) {
return $directory;
}
} else {
$packageName = 'charcoal/'.$package;

if (\Composer\InstalledVersions::isInstalled($packageName)) {
return \Composer\InstalledVersions::getInstallPath($packageName);
};
}

return null;
}
}
Loading