From aa5e2edbc53f70dc27019134ef3b8e026fef6424 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Sun, 20 Feb 2022 14:40:15 +0100 Subject: [PATCH] feat: Scan for lock files and set right commands --- src/lib/components/templates.ts | 177 ++++++++++++++---- .../[id]/configuration/_BuildPack.svelte | 6 +- .../[id]/configuration/buildpack.svelte | 62 ++++-- .../[id]/configuration/source.svelte | 2 +- 4 files changed, 189 insertions(+), 58 deletions(-) diff --git a/src/lib/components/templates.ts b/src/lib/components/templates.ts index d6029e4d2..bea552812 100644 --- a/src/lib/components/templates.ts +++ b/src/lib/components/templates.ts @@ -1,16 +1,146 @@ -const defaultBuildAndDeploy = { - installCommand: 'yarn install', - buildCommand: 'yarn build', - startCommand: 'yarn start' -}; -export const buildPacks = [ - { +function defaultBuildAndDeploy(packageManager) { + return { + installCommand: + packageManager === 'npm' ? `${packageManager} run install` : `${packageManager} install`, + buildCommand: + packageManager === 'npm' ? `${packageManager} run build` : `${packageManager} build`, + startCommand: + packageManager === 'npm' ? `${packageManager} run start` : `${packageManager} start` + }; +} +export function findBuildPack(pack, packageManager = 'npm') { + const metaData = buildPacks.find((b) => b.name === pack); + if (pack === 'node') { + return { + ...metaData, + installCommand: null, + buildCommand: null, + startCommand: null, + publishDirectory: null, + port: null + }; + } + if (pack === 'static') { + return { + ...metaData, + installCommand: null, + buildCommand: null, + startCommand: null, + publishDirectory: null, + port: 80 + }; + } + if (pack === 'docker') { + return { + ...metaData, + installCommand: null, + buildCommand: null, + startCommand: null, + publishDirectory: null, + port: null + }; + } + if (pack === 'svelte') { + return { + ...metaData, + ...defaultBuildAndDeploy(packageManager), + publishDirectory: 'public', + port: 80 + }; + } + if (pack === 'nestjs') { + return { + ...metaData, + ...defaultBuildAndDeploy(packageManager), + startCommand: + packageManager === 'npm' ? 'npm run start:prod' : `${packageManager} run start:prod`, + publishDirectory: null, + port: 3000 + }; + } + if (pack === 'react') { + return { + ...metaData, + ...defaultBuildAndDeploy(packageManager), + publishDirectory: 'build', + port: 80 + }; + } + if (pack === 'nextjs') { + return { + ...metaData, + ...defaultBuildAndDeploy(packageManager), + publishDirectory: null, + port: 3000 + }; + } + if (pack === 'gatsby') { + return { + ...metaData, + ...defaultBuildAndDeploy(packageManager), + publishDirectory: 'public', + port: 80 + }; + } + if (pack === 'vuejs') { + return { + ...metaData, + ...defaultBuildAndDeploy(packageManager), + publishDirectory: 'dist', + port: 80 + }; + } + if (pack === 'nuxtjs') { + return { + ...metaData, + ...defaultBuildAndDeploy(packageManager), + publishDirectory: null, + port: 3000 + }; + } + if (pack === 'preact') { + return { + ...metaData, + ...defaultBuildAndDeploy(packageManager), + publishDirectory: 'build', + port: 80 + }; + } + if (pack === 'php') { + return { + ...metaData, + installCommand: null, + buildCommand: null, + startCommand: null, + publishDirectory: null, + port: 80 + }; + } + if (pack === 'rust') { + return { + ...metaData, + installCommand: null, + buildCommand: null, + startCommand: null, + publishDirectory: null, + port: 3000 + }; + } + return { name: 'node', + fancyName: 'Node.js', + hoverColor: 'hover:bg-green-700', + color: 'bg-green-700', installCommand: null, buildCommand: null, startCommand: null, publishDirectory: null, - port: null, + port: null + }; +} +export const buildPacks = [ + { + name: 'node', fancyName: 'Node.js', hoverColor: 'hover:bg-green-700', color: 'bg-green-700' @@ -18,103 +148,72 @@ export const buildPacks = [ { name: 'static', - publishDirectory: 'dist', - port: 80, fancyName: 'Static', hoverColor: 'hover:bg-orange-700', color: 'bg-orange-700' }, { name: 'docker', - installCommand: null, - buildCommand: null, - startCommand: null, - publishDirectory: null, - port: null, fancyName: 'Docker', hoverColor: 'hover:bg-sky-700', color: 'bg-sky-700' }, { name: 'svelte', - ...defaultBuildAndDeploy, - publishDirectory: 'public', - port: 80, fancyName: 'Svelte', hoverColor: 'hover:bg-orange-700', color: 'bg-orange-700' }, { name: 'nestjs', - ...defaultBuildAndDeploy, - startCommand: 'yarn start:prod', - port: 3000, fancyName: 'NestJS', hoverColor: 'hover:bg-red-700', color: 'bg-red-700' }, { name: 'react', - ...defaultBuildAndDeploy, - publishDirectory: 'build', - port: 80, fancyName: 'React', hoverColor: 'hover:bg-blue-700', color: 'bg-blue-700' }, { name: 'nextjs', - ...defaultBuildAndDeploy, - port: 3000, fancyName: 'NextJS', hoverColor: 'hover:bg-blue-700', color: 'bg-blue-700' }, { name: 'gatsby', - ...defaultBuildAndDeploy, - publishDirectory: 'public', - port: 80, fancyName: 'Gatsby', hoverColor: 'hover:bg-blue-700', color: 'bg-blue-700' }, { name: 'vuejs', - ...defaultBuildAndDeploy, - publishDirectory: 'dist', - port: 80, fancyName: 'VueJS', hoverColor: 'hover:bg-green-700', color: 'bg-green-700' }, { name: 'nuxtjs', - ...defaultBuildAndDeploy, - port: 3000, fancyName: 'NuxtJS', hoverColor: 'hover:bg-green-700', color: 'bg-green-700' }, { name: 'preact', - ...defaultBuildAndDeploy, - publishDirectory: 'build', - port: 80, fancyName: 'Preact', hoverColor: 'hover:bg-blue-700', color: 'bg-blue-700' }, { name: 'php', - port: 80, fancyName: 'PHP', hoverColor: 'hover:bg-indigo-700', color: 'bg-indigo-700' }, { name: 'rust', - port: 3000, fancyName: 'Rust', hoverColor: 'hover:bg-pink-700', color: 'bg-pink-700' diff --git a/src/routes/applications/[id]/configuration/_BuildPack.svelte b/src/routes/applications/[id]/configuration/_BuildPack.svelte index df04789c1..dadbc9dde 100644 --- a/src/routes/applications/[id]/configuration/_BuildPack.svelte +++ b/src/routes/applications/[id]/configuration/_BuildPack.svelte @@ -3,6 +3,7 @@ import { page } from '$app/stores'; import { post } from '$lib/api'; + import { findBuildPack } from '$lib/components/templates'; import { errorNotification } from '$lib/form'; const { id } = $page.params; @@ -11,10 +12,13 @@ export let buildPack; export let foundConfig; export let scanning; + export let packageManager; async function handleSubmit(name) { try { - const tempBuildPack = JSON.parse(JSON.stringify(buildPack)); + const tempBuildPack = JSON.parse( + JSON.stringify(findBuildPack(buildPack.name, packageManager)) + ); delete tempBuildPack.name; delete tempBuildPack.fancyName; delete tempBuildPack.color; diff --git a/src/routes/applications/[id]/configuration/buildpack.svelte b/src/routes/applications/[id]/configuration/buildpack.svelte index 79f424753..434986fcb 100644 --- a/src/routes/applications/[id]/configuration/buildpack.svelte +++ b/src/routes/applications/[id]/configuration/buildpack.svelte @@ -29,14 +29,16 @@