Skip to content

Commit

Permalink
Implement autoloader & buildscript
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Thulin committed Aug 30, 2023
1 parent fed552b commit 228220f
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 109 deletions.
12 changes: 4 additions & 8 deletions algolia-index-js-searchpage.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,15 @@
define('ALGOLIAINDEXJSSEARCHPAGE_PATH', plugin_dir_path(__FILE__));
define('ALGOLIAINDEXJSSEARCHPAGE_URL', plugins_url('', __FILE__));
define('ALGOLIAINDEXJSSEARCHPAGE_TEMPLATE_PATH', ALGOLIAINDEXJSSEARCHPAGE_PATH . 'templates/');

define('ALGOLIAINDEXJSSEARCHPAGE_VIEW_PATH', ALGOLIAINDEXJSSEARCHPAGE_PATH . 'views/');

load_plugin_textdomain('algolia-index-js-searchpage', false, plugin_basename(dirname(__FILE__)) . '/languages');

require_once ALGOLIAINDEXJSSEARCHPAGE_PATH . 'source/php/Vendor/Psr4ClassLoader.php';
// Autoload from plugin
if (file_exists(ALGOLIAINDEXJSSEARCHPAGE_PATH . 'vendor/autoload.php')) {
require_once ALGOLIAINDEXJSSEARCHPAGE_PATH . 'vendor/autoload.php';
}
require_once ALGOLIAINDEXJSSEARCHPAGE_PATH . 'Public.php';

// Instantiate and register the autoloader
$loader = new AlgoliaIndexJsSearchpage\Vendor\Psr4ClassLoader();
$loader->addPrefix('AlgoliaIndexJsSearchpage', ALGOLIAINDEXJSSEARCHPAGE_PATH);
$loader->addPrefix('AlgoliaIndexJsSearchpage', ALGOLIAINDEXJSSEARCHPAGE_PATH . 'source/php/');
$loader->register();

// Start application
new AlgoliaIndexJsSearchpage\App();
40 changes: 28 additions & 12 deletions build.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,29 @@
}

// Any command needed to run and build plugin assets when newly cheched out of repo.
$buildCommands = [
'npm ci --no-progress --no-audit',
'npx --yes browserslist@latest --update-db',
'npm run build',
];
$buildCommands = [];

//Add composer build, if flag --no-composer is undefined.
if(is_array($argv) && !in_array('--no-composer', $argv)) {
$buildCommands[] = 'composer install --prefer-dist --no-progress --no-dev';
//Dump autloader.
//Only if composer.json exists.
if(file_exists('composer.json')) {
if(is_array($argv) && !in_array('--no-composer', $argv)) {
$buildCommands[] = 'composer install --prefer-dist --no-progress --no-dev';
}
$buildCommands[] = 'composer dump-autoload';
}

//Run npm if package.json is found
if(file_exists('package.json') && file_exists('package.lock')) {
$buildCommands[] = 'npm ci --no-progress --no-audit';
} elseif(file_exists('package.json') && !file_exists('package.lock')) {
$buildCommands[] = 'npm install --no-progress --no-audit';
}

//Run build if package.lock is found
if(file_exists('package.lock')) {
$buildCommands[] = 'npx --yes browserslist@latest --update-db';
$buildCommands[] = 'npm run build';
}

// Files and directories not suitable for prod to be removed.
Expand All @@ -23,13 +37,15 @@
'.gitignore',
'.github',
'build.php',
'.npmrc',
'composer.json',
'composer.lock',
'node_modules',
'package.json',
'env-example',
'webpack.config.js',
'package-lock.json',
'.vscode',
'webpack.config.js'
'package.json',
'phpunit.xml.dist',
'README.md'
];

$dirName = basename(dirname(__FILE__));
Expand Down Expand Up @@ -91,4 +107,4 @@ function executeCommand($command)

// Return exit status.
return intval($matches[0]);
}
}
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,10 @@
}
],
"require": {
},
"autoload": {
"psr-4": {
"AlgoliaIndexJsSearchpage\\": "source/php/"
}
}
}
89 changes: 0 additions & 89 deletions source/php/Vendor/Psr4ClassLoader.php

This file was deleted.

0 comments on commit 228220f

Please sign in to comment.