Skip to content

Commit

Permalink
build: update config and build flow
Browse files Browse the repository at this point in the history
  • Loading branch information
EdieLemoine committed Oct 19, 2023
1 parent 3e3713a commit 5061c18
Show file tree
Hide file tree
Showing 5 changed files with 208 additions and 36 deletions.
43 changes: 42 additions & 1 deletion .github/actions/build/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,48 @@ description: ''
runs:
using: composite
steps:
- name: 'Build JavaScript bundles'
- name: 'Cache php-scoper'
uses: actions/cache@v3
id: php-scoper-cache
with:
path: .cache/php-scoper
key: php-scoper-${{ inputs.php-scoper-version }}

- name: 'Install php-scoper'
if: steps.php-scoper-cache.outputs.cache-hit != 'true'
shell: bash
# language=sh
run: |
mkdir -p .cache/php-scoper
docker run \
--volume $PWD/.cache/php-scoper:/app \
${{ steps.setup.outputs.image }} \
composer require \
--no-interaction \
--no-plugins \
--no-progress \
--no-scripts \
"humbug/php-scoper:${{ inputs.php-scoper-version }}"
# The actual compilation is done in pdk.config.js
- name: 'Cache compiled php'
uses: actions/cache@v3
id: compiled-php-cache
with:
path: .cache/build
key: compiled-php-${{ hashFiles('**/composer.json', '**/composer.lock', 'src/**/*', 'config/**/*', '*.php') }}

- name: 'Build frontend'
shell: bash
#language=sh
run: |
yarn nx run-many \
--output-style=static \
--runner=cloud \
--target=build
- name: 'Build frontend'
shell: bash
#language=sh
run: |
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"array.prototype.flatmap": "^1.3.1",
"eslint": "^8.44.0",
"eslint-plugin-sort-exports": "^0.8.0",
"fast-glob": "^3.3.1",
"husky": "^8.0.3",
"is-ci": "^3.0.1",
"lint-staged": "^13.1.2",
Expand Down
122 changes: 122 additions & 0 deletions pdk.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import {
PdkPlatformName,
defineConfig,
executeCommand,
executePromises,
getPlatformDistPath,
} from '@myparcel-pdk/app-builder';
import {downloadCarrierLogos} from './private/downloadCarrierLogos.mjs';
import fs from 'fs';
import path from 'path';
import glob from 'fast-glob';

export default defineConfig({
name: 'prestashop',
platformFolderName: '{{platform}}',
platforms: [PdkPlatformName.MyParcelNl, PdkPlatformName.MyParcelBe],
source: [
'!**/node_modules/**',
'.cache/build/composer.json',
'.cache/build/config/**/*',
'.cache/build/controllers/**/*',
'.cache/build/myparcelnl.php',
'.cache/build/src/**/*',
'.cache/build/upgrade/**/*',
'.cache/build/vendor/**/*',
'mails/**/*',
'private/carrier-logos/**/*',
'views/js/**/dist/**/*',
'CONTRIBUTING.md',
'LICENSE.txt',
'README.md',
'logo.png',
],
versionSource: [{path: 'package.json'}, {path: 'composer.json'}],
translations: {
// eslint-disable-next-line no-magic-numbers
additionalSheet: 279275153,
},

rootCommand: 'docker compose run --rm -T php',

additionalCommands: [
{
name: 'download-carrier-logos',
description: 'Download carrier logos',
action: downloadCarrierLogos,
},
],

hooks: {
/**
* Prefix the vendor and source php files.
*/
async beforeCopy(args) {
const {debug} = args.context;

debug('Prefixing build files...');

if (fs.existsSync('.cache/build/composer.json')) {
debug('Build files already exist, skipping prefixing.');
return;
}

if (!args.dryRun) {
await executeCommand(
args.context,
'php',
[
'-d memory_limit=-1',
'.cache/php-scoper/vendor/bin/php-scoper',
'add-prefix',
'--output-dir=.cache/build',
'--force',
'--no-ansi',
'--no-interaction',
],
{stdio: 'inherit'},
);

await executeCommand(
args.context,
'composer',
['dump-autoload', '--working-dir=.cache/build', '--classmap-authoritative'],
{stdio: 'inherit'},
);
}

debug('Finished prefixing build files.');
},

async afterCopy(args) {
const {config, env, debug} = args.context;

debug('Copying scoped build files to root');

await executePromises(
args,
config.platforms.map(async (platform) => {
const platformDistPath = getPlatformDistPath({config, env, platform});

const files = glob.sync('.cache/build/**/*', {cwd: platformDistPath});

await Promise.all(
files.map(async (file) => {
const oldPath = `${platformDistPath}/${file}`;
const newPath = oldPath.replace('.cache/build/', '');

if (!args.dryRun) {
await fs.promises.mkdir(path.dirname(newPath), {recursive: true});
await fs.promises.rename(oldPath, newPath);
}
}),
);

await fs.promises.rm(`${platformDistPath}/.cache`, {recursive: true});
}),
);

debug('Copied scoped build files to root.');
},
},
});
35 changes: 0 additions & 35 deletions pdk.config.mjs

This file was deleted.

43 changes: 43 additions & 0 deletions scoper.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

declare(strict_types=1);

use Isolated\Symfony\Component\Finder\Finder;

// For more see: https://github.com/humbug/php-scoper/blob/master/docs/configuration.md
return [
'prefix' => 'MyParcelNL',
'finders' => [
Finder::create()
->append([
'myparcelnl.php',
'composer.json',
]),
Finder::create()
->files()
->in(['src', 'config', 'controllers', 'upgrade']),
Finder::create()
->files()
->ignoreVCS(true)
->notName('/LICENSE|.*\\.md|.*\\.dist|Makefile|composer\\.lock/')
->exclude([
'test',
'tests',
'Tests',
'vendor-bin',
])
->in('vendor'),
],

'exclude-files' => [
'vendor/php-di/php-di/src/Compiler/Template.php',
],

'exclude-namespaces' => [
// Exclude global namespace
'/^$/',
'MyParcelNL',
'PrestaShop',
'PrestaShopBundle',
],
];

0 comments on commit 5061c18

Please sign in to comment.