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

feat: Node, initial #163

Merged
merged 3 commits into from
Jun 3, 2024
Merged
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
23 changes: 23 additions & 0 deletions resources/Node/common.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
ifndef SIGWIN_INFRA_ROOT
$(error SIGWIN_INFRA_ROOT must be defined before loading PHP/common.mk)
endif
ifndef OS_FAMILY
include ${SIGWIN_INFRA_ROOT:%/=%}/Common/default.mk
endif

ifndef NODE_VERSION
NODE_VERSION=21.7
endif

ifndef NODE_DOCKER_IMAGE
NODE_DOCKER_IMAGE=node:${NODE_VERSION}-alpine
endif

ifndef NODE_DOCKER_COMMAND
NODE_DOCKER_COMMAND=docker run --init --interactive ${DOCKER_TTY} --rm ${DOCKER_ENV} ${DOCKER_USER} --volume "$(DOCKER_CWD):/project" --volume "${HOME}/.npm:/home/node/.npm" --workdir /project ${NODE_DOCKER_IMAGE}
endif

sh/node: | ${HOME}/.npm ## Run Node shell
${NODE_DOCKER_COMMAND} sh
${HOME}/.npm:
mkdir -p ${HOME}/.npm
2 changes: 2 additions & 0 deletions resources/PHP/common.mk
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
ifndef SIGWIN_INFRA_ROOT
$(error SIGWIN_INFRA_ROOT must be defined before loading PHP/common.mk)
endif
ifndef OS_FAMILY
include ${SIGWIN_INFRA_ROOT:%/=%}/Common/default.mk
endif

ifndef PHP_VERSION
PHP_VERSION=8.3
Expand Down
1 change: 1 addition & 0 deletions tests/functional/MakefileTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ abstract class MakefileTestCase extends TestCase
'setup/filesystem' => 'Setup: filesystem (var, public/var folders)',
'setup/test' => 'Setup: create a functional test runtime',
'sh/app' => 'Run application shell',
'sh/node' => 'Run Node shell',
'sh/php' => 'Run PHP shell',
'start' => 'Start app in APP_ENV mode (defined in .env)',
'start/dev' => 'Start app in "dev" mode',
Expand Down
61 changes: 61 additions & 0 deletions tests/functional/Node/CommonTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Sigwin Infra project.
*
* (c) sigwin.hr
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Sigwin\Infra\Test\Functional\Node;

use Sigwin\Infra\Test\Functional\MakefileTestCase;

/**
* @internal
*/
#[\PHPUnit\Framework\Attributes\CoversNothing]
#[\PHPUnit\Framework\Attributes\Medium]
final class CommonTest extends MakefileTestCase
{
protected static function getExpectedHelpCommandsExecutionPath(?array $env = null): array
{
$nodeVersion = $env['NODE_VERSION'] ?? '21.7';
$nodeDockerImage = $env['NODE_DOCKER_IMAGE'] ?? 'node:%1$s-alpine';
$dockerEnv = $env['DOCKER_ENV'] ?? ' ';

return [
'help' => [self::generateHelpExecutionPath([
__DIR__.'/../../../resources/Node/common.mk',
])],
'sh/node' => [
'mkdir -p $HOME/.npm',
self::generateNodeExecutionPath('sh', nodeVersion: $nodeVersion, dockerImage: $nodeDockerImage, env: $dockerEnv),
],
];
}

protected function getExpectedInitPaths(): array
{
return [
'Common/Platform/$PLATFORM/default',
'Common/default',
'Node/common',
];
}

private static function generateNodeExecutionPath(string $command, string $nodeVersion, string $dockerImage, string $env): string
{
return self::normalize(sprintf(
'docker run --init --interactive --rm %4$s%2$s --volume "$ROOT:/project" --volume "$HOME/.npm:/home/node/.npm" --workdir /project %3$s %1$s',
sprintf($command, $nodeVersion),
self::generateDockerComposeExecutionUser(),
sprintf($dockerImage, $nodeVersion),
$env
));
}
}
Loading