Skip to content

Commit

Permalink
Autoload & Build
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Thulin committed Aug 31, 2023
1 parent 4da761e commit 16f7ad7
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 109 deletions.
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]);
}
}
7 changes: 6 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,10 @@
"type": "vcs",
"url": "https://github.com/helsingborg-stad/modularity-products.git"
}
]
],
"autoload": {
"psr-4": {
"ModularityProducts\\": "source/php/"
}
}
}
11 changes: 4 additions & 7 deletions modularity-products.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,12 @@

load_plugin_textdomain('modularity-products', false, plugin_basename(dirname(__FILE__)) . '/languages');

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

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

// Acf auto import and export
$acfExportManager = new \AcfExportManager\AcfExportManager();
$acfExportManager->setTextdomain('modularity-products');
Expand Down
89 changes: 0 additions & 89 deletions source/php/Vendor/Psr4ClassLoader.php

This file was deleted.

0 comments on commit 16f7ad7

Please sign in to comment.