Add runtimes to templates

This commit is contained in:
Matej Bačo
2024-10-27 16:15:49 +01:00
parent 9c566ec17c
commit 7a0e7bfb95
4 changed files with 37 additions and 20 deletions
+14 -13
View File
@@ -2,22 +2,19 @@
const TEMPLATE_FRAMEWORKS = [
'SVELTEKIT' => [
'name' => 'Svelte Kit'
],
'NEXTJS' => [
'name' => 'Next.js'
'name' => 'Svelte Kit',
'installCommand' => 'npm install',
'buildCommand' => 'npm run build',
'outputDirectory' => './build',
'serveRuntime' => 'node-22',
'buildRuntime' => 'node-22',
],
];
function getFramework($framework, $installCommand, $buildCommand, $outputDirectory, $providerRootDirectory)
function getFramework(string $frameworkEnum, array $overrides)
{
return [
'name' => $framework['name'],
'installCommand' => $installCommand,
'buildCommand' => $buildCommand,
'outputDirectory' => $outputDirectory,
'providerRootDirectory' => $providerRootDirectory
];
$settings = \array_merge(TEMPLATE_FRAMEWORKS[$frameworkEnum], $overrides);
return $settings;
}
return [
@@ -26,7 +23,11 @@ return [
'name' => 'Personal portfolio',
'useCases' => ['starter'],
'frameworks' => [
...getFramework(TEMPLATE_FRAMEWORKS['SVELTEKIT'], 'npm install --force', 'npm run build', './build', './')
...getFramework(TEMPLATE_FRAMEWORKS['SVELTEKIT'], [
'serveRuntime' => 'static-1',
'installCommand' => 'npm install --force',
'providerRootDirectory' => './'
])
],
'vcsProvider' => 'github',
'providerRepositoryId' => 'portfolio-walter-o-brien',
@@ -64,6 +64,8 @@ class CreateSite extends Base
->param('buildCommand', '', new Text(8192, 0), 'Build Command.', true)
->param('outputDirectory', '', new Text(8192, 0), 'Output Directory for site.', true)
->param('subdomain', '', new CustomId(), 'Unique custom sub-domain. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.', true)
->param('buildRuntime', '', new WhiteList(array_keys(Config::getParam('runtimes')), true), 'Runtime to use during build step.', true)
->param('serveRuntime', '', new WhiteList(array_keys(Config::getParam('runtimes')), true), 'Runtime to use when serving site.', true)
->param('installationId', '', new Text(128, 0), 'Appwrite Installation ID for VCS (Version Control System) deployment.', true)
->param('providerRepositoryId', '', new Text(128, 0), 'Repository ID of the repo linked to the site.', true)
->param('providerBranch', '', new Text(128, 0), 'Production branch for the repo linked to the site.', true)
@@ -91,7 +93,7 @@ class CreateSite extends Base
->callback([$this, 'action']);
}
public function action(string $siteId, string $name, string $framework, bool $enabled, string $installCommand, string $buildCommand, string $outputDirectory, string $subdomain, string $installationId, string $providerRepositoryId, string $providerBranch, bool $providerSilentMode, string $providerRootDirectory, string $templateRepository, string $templateOwner, string $templateRootDirectory, string $templateVersion, string $specification, Request $request, Response $response, Database $dbForProject, Document $project, Document $user, Event $queueForEvents, Build $queueForBuilds, Database $dbForConsole, GitHub $github)
public function action(string $siteId, string $name, string $framework, bool $enabled, string $installCommand, string $buildCommand, string $outputDirectory, string $subdomain, string $buildRuntime, string $serveRuntime, string $installationId, string $providerRepositoryId, string $providerBranch, bool $providerSilentMode, string $providerRootDirectory, string $templateRepository, string $templateOwner, string $templateRootDirectory, string $templateVersion, string $specification, Request $request, Response $response, Database $dbForProject, Document $project, Document $user, Event $queueForEvents, Build $queueForBuilds, Database $dbForConsole, GitHub $github)
{
$sitesDomain = System::getEnv('_APP_DOMAIN_SITES', '');
$ruleId = '';
@@ -165,8 +167,8 @@ class CreateSite extends Base
'providerRootDirectory' => $providerRootDirectory,
'providerSilentMode' => $providerSilentMode,
'specification' => $specification,
'buildRuntime' => Config::getParam('frameworks', [])[$framework]['defaultBuildRuntime'],
'serveRuntime' => Config::getParam('frameworks', [])[$framework]['defaultServeRuntime'],
'buildRuntime' => $buildRuntime,
'serveRuntime' => $serveRuntime,
]));
// Git connect logic
@@ -32,14 +32,27 @@ class TemplateFramework extends Model
'type' => self::TYPE_STRING,
'description' => 'The output directory to store the build output.',
'default' => '',
'example' => 'build',
'example' => './build',
])
->addRule('providerRootDirectory', [
'type' => self::TYPE_STRING,
'description' => 'Path to site in VCS (Version Control System) repository',
'default' => '',
'example' => 'node/starter',
]);
'example' => './svelte-kit/starter',
])
->addRule('serveRuntime', [
'type' => self::TYPE_STRING,
'description' => 'Runtime used during serve of template deployment.',
'default' => '',
'example' => 'static-1',
])
->addRule('buildRuntime', [
'type' => self::TYPE_STRING,
'description' => 'Runtime used during build step of template.',
'default' => '',
'example' => 'node-22',
])
;
}
/**
@@ -66,7 +66,8 @@ class TemplateSite extends Model
'default' => [],
'example' => [],
'array' => true
]);
])
;
}
/**