-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: Node initial * feat: Node initial * feat: Node initial
- Loading branch information
Showing
4 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
)); | ||
} | ||
} |