Skip to content

Commit

Permalink
new master branch: phar build (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
xy2z authored Feb 11, 2024
1 parent 32f4745 commit 00e9f5d
Show file tree
Hide file tree
Showing 30 changed files with 31 additions and 8,345 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Gitattributes for the Capro BUILD repo.

/capro-logo.png export-ignore
/README.md export-ignore
/.gitignore export-ignore
Expand Down
19 changes: 10 additions & 9 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# Gitignore for Capro Core (not for sites)
# Gitignore for the Capro BUILD repo.
/.vscode
/vendor/
/cache/
/config/
/content/
/views/
/static/
/public/
/vendor
/build
/public
/config
/static
/views
/.env
/tmp*
.capro-cache*
.php-cs-fixer.cache
desktop.ini
/.env
/demo*
/.box_dump/
81 changes: 0 additions & 81 deletions .php-cs-fixer.dist.php

This file was deleted.

14 changes: 13 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Contributing to Capro

Pull Requests are welcome!
Pull Requests are welcome! Remember development is done in the `dev` branch, and only phar releases is merged to `master`.

- If you want to work on a completely new feature please make an issue beforehand to discuss if it fits the projects scope.
- Use `php-cs-fixer` to follow the coding standard. This can be called automatically in modern editors on file save.
Expand All @@ -9,3 +9,15 @@ Pull Requests are welcome!
- When you test the code you should run "php capro <command>" to make sure you are running the correct script.

If you have any questions or notes about contributing, please ask in [Discussions](https://github.com/xy2z/capro/discussions)


## Build and Release
1. Check `box validate` command to validate the box.json.dist file. (should be part of "build.sh" script, fails if not valid)
1. Make sure the version is bumped in `src/capro_bootstrap.php`
1. Run `composer build` to build the phar file in the `build` dir.
1. Test the `build/capro.phar` file.
1. Run `composer validate` to check the `build/composer.json` file.
1. Overwrite the `build/capro.phar` file in the master branch, commit and push
1. Make a new release on GitHub (make sure the version matches the one in `src/capro_bootstrap.php`)

To get back the development composer packages (phpstan, etc.) run `composer install` again.
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ Capro is a static-site generator for PHP 8+

## ⚠ Notice

Capro is currently in [alpha](https://github.com/xy2z/capro/issues/5), and is not thoroughly tested for production.

Please report bugs via [GitHub Issues](https://github.com/xy2z/capro/issues)
Capro is currently in [alpha](https://github.com/xy2z/capro/issues/5), please report bugs via [GitHub Issues](https://github.com/xy2z/capro/issues)


## About
Expand Down Expand Up @@ -64,4 +62,4 @@ Learn more in the **[full documentation site](https://capro.xy2z.io).** (which w

## Contributing

Pull Requests are welcome! See more in the [Contributing Guide](CONTRIBUTING.md).
Pull Requests are welcome! Remember to send PR's to the `dev` branch - see more in the [Contributing Guide](CONTRIBUTING.md).
81 changes: 2 additions & 79 deletions capro
Original file line number Diff line number Diff line change
@@ -1,83 +1,6 @@
#!/usr/bin/env php
<?php

// Start Timer
use xy2z\Capro\Commands\CommandBuild;
use xy2z\Capro\Commands\CommandNewSite;
use xy2z\Capro\Commands\CommandConfig;
use xy2z\Capro\Commands\CommandServe;
use xy2z\Capro\Config;
Phar::loadPhar(__DIR__ . '/capro.phar', 'capro.phar');

// Call bootstrap to check if we should use capro shortcut for vendor/bin/capro.
require __DIR__ . '/src/capro_bootstrap.php';

// Prepare
// Check if we are in a project dir
if (file_exists(__DIR__ . '/vendor/autoload.php')) {
// Development (when developing/testing this project),
// using `php capro <cmd>`
require __DIR__ . '/vendor/autoload.php';
define('CAPRO_SITE_ROOT_DIR', __DIR__ . DIRECTORY_SEPARATOR);
}

if (file_exists(__DIR__ . '/../../autoload.php')) {
// For sites that is using this using vendor/bin
// Also for global installed..
require __DIR__ . '/../../autoload.php';
define('CAPRO_SITE_ROOT_DIR', __DIR__ . '/../../../'); // go back 3 dirs (/vendor/xy2z/capro/)
}

if (!defined('CAPRO_SITE_ROOT_DIR')) {
echo 'Error: Composer autoload.php was not found. (try "composer install")' . PHP_EOL;
exit(1);
}

// This is required to make the classes available in the Blade views.
class_alias('xy2z\Capro\Capro', 'Capro');

// Load env (before config)
if (file_exists(CAPRO_SITE_ROOT_DIR . '.env')) {
// Load .env file
$dotenv = Dotenv\Dotenv::createImmutable(CAPRO_SITE_ROOT_DIR);
try {
$dotenv->load();
} catch (Exception $e) {
// Do nothing
tell_error('Invalid .env file. Error message: ' . $e->getMessage());
}
}

// Load config
define('CAPRO_CONFIG_DIR', CAPRO_SITE_ROOT_DIR . 'config');
if (is_dir(CAPRO_CONFIG_DIR)) {
Config::load_capro_config();
// } else {
// tell('Notice: Config dir not found: ' . CAPRO_CONFIG_DIR); // verbose. (but never for global composer "capro" commands.)
}

// Set CONSTANTS from Config (or use defaults) -- after loading config.
// Cant use realpath() here because the directories might not exist yet.
define('CAPRO_PUBLIC_DIR', CAPRO_SITE_ROOT_DIR . Config::get('core.public_dir', 'public'));
define('CAPRO_VIEWS_DIR', CAPRO_SITE_ROOT_DIR . Config::get('core.views_dir', 'views'));
define('CAPRO_VIEWS_CACHE_DIR', CAPRO_SITE_ROOT_DIR . Config::get('core.views_cache_dir', 'views/cache'));
define('CAPRO_STATIC_DIR', CAPRO_SITE_ROOT_DIR . Config::get('core.static_dir', 'static'));

// Check if command argument is set.
$command = $argv[1] ?? null;
if (isset($command)) {
$command = strtolower($command);
} else {
tell('Need a command.');
exit;
}

// Run command.
match ($command) {
'build', 'b' => (new CommandBuild($argv))->run(),
'new' => (new CommandNewSite($argv))->run(),
'config' => (new CommandConfig($argv))->run(),
'serve' => (new CommandServe($argv))->run(),
'where' => tell(__DIR__),
'-v', 'v', '--version', 'version' => tell(CAPRO_VERSION),
default => tell('Unknown command.'),
};
require 'phar://capro.phar/capro';
Binary file added capro.phar
Binary file not shown.
26 changes: 2 additions & 24 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,11 @@
}
],
"require": {
"php": "8.0 - 8.2",
"jenssegers/blade": "1.4.*",
"xy2z/lite-config": "1.*",
"symfony/yaml": "5.*",
"spatie/yaml-front-matter": "2.*",
"league/commonmark": "2.*",
"statix/server": "^0.4.1",
"vlucas/phpdotenv": "5.*",
"symfony/var-dumper": "6.*"
},
"autoload": {
"psr-4": {
"xy2z\\Capro\\": "src/",
"xy2z\\Capro\\Commands\\": "src/Commands"
},
"files": [
"src/helpers.php"
]
"php": "8.*"
},
"bin": [
"capro"
"capro.phar"
],
"require-dev": {
"friendsofphp/php-cs-fixer": "3.15.*",
"phpstan/phpstan": "1.*",
"phpunit/phpunit": "9.*"
},
"funding": [
{
"type": "github",
Expand Down
Loading

0 comments on commit 00e9f5d

Please sign in to comment.