diff --git a/resources/Node/common.mk b/resources/Node/common.mk new file mode 100644 index 0000000..e6d4999 --- /dev/null +++ b/resources/Node/common.mk @@ -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 diff --git a/resources/PHP/common.mk b/resources/PHP/common.mk index 75c579f..67dda91 100644 --- a/resources/PHP/common.mk +++ b/resources/PHP/common.mk @@ -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 diff --git a/tests/functional/MakefileTestCase.php b/tests/functional/MakefileTestCase.php index 44b0ad6..2f754a9 100644 --- a/tests/functional/MakefileTestCase.php +++ b/tests/functional/MakefileTestCase.php @@ -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', diff --git a/tests/functional/Node/CommonTest.php b/tests/functional/Node/CommonTest.php new file mode 100644 index 0000000..7c95946 --- /dev/null +++ b/tests/functional/Node/CommonTest.php @@ -0,0 +1,61 @@ + [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 + )); + } +}