Skip to content
Closed
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
66 changes: 36 additions & 30 deletions src/lib/stores/marketplace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,40 @@ export const marketplace: MarketplaceTemplate[] = [
usecases: ['Starter'],
runtimes: [
{
name: 'node-18.0',
name: 'node',
commands: 'npm install',
entrypoint: 'src/main.js',
providerRootDirectory: 'node/starter'
},
{
name: 'php-8.0',
name: 'php',
commands: 'composer install',
entrypoint: 'src/index.php',
providerRootDirectory: 'php/starter'
},
{
name: 'ruby-3.0',
name: 'ruby',
commands: 'bundle install',
entrypoint: 'lib/main.rb',
providerRootDirectory: 'ruby/starter'
},
{
name: 'python-3.9',
name: 'python',
commands: 'pip install -r requirements.txt',
entrypoint: 'src/main.py',
providerRootDirectory: 'python/starter'
},
{
name: 'dart-2.17',
name: 'dart',
commands: 'dart pub get',
entrypoint: 'lib/main.dart',
providerRootDirectory: 'dart/starter'
},
{
name: 'bun',
commands: 'bun install',
entrypoint: 'src/main.ts',
providerRootDirectory: 'bun/starter'
}
],
instructions: `For documentation and instructions check out <a target="_blank" rel="noopener noreferrer" class="link" href="https://github.com/appwrite/templates/tree/main/node/starter">file</a>.`,
Expand Down Expand Up @@ -70,25 +76,25 @@ export const marketplace: MarketplaceTemplate[] = [
usecases: ['AI'],
runtimes: [
{
name: 'node-18.0',
name: 'node',
commands: 'npm install',
entrypoint: 'src/main.js',
providerRootDirectory: 'node/prompt-chatgpt'
},
{
name: 'python-3.9',
name: 'python',
commands: 'pip install -r requirements.txt',
entrypoint: 'src/main.py',
providerRootDirectory: 'python/prompt_chatgpt'
},
{
name: 'php-8.0',
name: 'php',
commands: 'composer install',
entrypoint: 'src/index.php',
providerRootDirectory: 'php/prompt-chatgpt'
},
{
name: 'dart-2.17',
name: 'dart',
commands: 'dart pub get',
entrypoint: 'lib/main.dart',
providerRootDirectory: 'dart/prompt_chatgpt'
Expand Down Expand Up @@ -130,13 +136,13 @@ export const marketplace: MarketplaceTemplate[] = [
usecases: ['Messaging'],
runtimes: [
{
name: 'node-18.0',
name: 'node',
commands: 'npm install && npm run setup',
entrypoint: 'src/main.js',
providerRootDirectory: 'node/discord-command-bot'
},
{
name: 'python-3.9',
name: 'python',
commands: 'pip install -r requirements.txt && python src/setup.py',
entrypoint: 'src/main.py',
providerRootDirectory: 'python/discord_command_bot'
Expand Down Expand Up @@ -186,7 +192,7 @@ export const marketplace: MarketplaceTemplate[] = [
usecases: ['AI'],
runtimes: [
{
name: 'node-18.0',
name: 'node',
commands: 'npm install',
entrypoint: 'src/main.js',
providerRootDirectory: 'node/analyze-with-perspectiveapi'
Expand Down Expand Up @@ -221,19 +227,19 @@ export const marketplace: MarketplaceTemplate[] = [
usecases: ['AI'],
runtimes: [
{
name: 'node-18.0',
name: 'node',
commands: 'npm install',
entrypoint: 'src/main.js',
providerRootDirectory: 'node/censor-with-redact'
},
{
name: 'python-3.9',
name: 'python',
commands: 'pip install -r requirements.txt',
entrypoint: 'src/main.py',
providerRootDirectory: 'python/censor_with_redact'
},
{
name: 'dart-2.17',
name: 'dart',
commands: 'dart pub get',
entrypoint: 'lib/main.dart',
providerRootDirectory: 'dart/censor_with_redact'
Expand Down Expand Up @@ -267,7 +273,7 @@ export const marketplace: MarketplaceTemplate[] = [
usecases: ['Utilities'],
runtimes: [
{
name: 'node-18.0',
name: 'node',
commands: 'npm install',
entrypoint: 'src/main.js',
providerRootDirectory: 'node/generate-pdf'
Expand All @@ -293,7 +299,7 @@ export const marketplace: MarketplaceTemplate[] = [
usecases: ['Dev Tools'],
runtimes: [
{
name: 'node-18.0',
name: 'node',
commands: 'npm install',
entrypoint: 'src/main.js',
providerRootDirectory: 'node/github-issue-bot'
Expand Down Expand Up @@ -335,7 +341,7 @@ export const marketplace: MarketplaceTemplate[] = [
usecases: ['Utilities'],
runtimes: [
{
name: 'node-18.0',
name: 'node',
commands: 'npm install',
entrypoint: 'src/main.js',
providerRootDirectory: 'node/url-shortener'
Expand Down Expand Up @@ -401,19 +407,19 @@ export const marketplace: MarketplaceTemplate[] = [
usecases: ['Databases'],
runtimes: [
{
name: 'node-18.0',
name: 'node',
commands: 'npm install',
entrypoint: 'src/main.js',
providerRootDirectory: 'node/sync-with-algolia'
},
{
name: 'python-3.9',
name: 'python',
commands: 'pip install -r requirements.txt',
entrypoint: 'src/main.py',
providerRootDirectory: 'python/sync_with_algolia'
},
{
name: 'php-8.0',
name: 'php',
commands: 'composer install',
entrypoint: 'src/index.php',
providerRootDirectory: 'php/sync-with-algolia'
Expand Down Expand Up @@ -490,7 +496,7 @@ export const marketplace: MarketplaceTemplate[] = [
usecases: ['Databases'],
runtimes: [
{
name: 'node-18.0',
name: 'node',
commands: 'npm install',
entrypoint: 'src/main.js',
providerRootDirectory: 'node/sync-with-meilisearch'
Expand Down Expand Up @@ -574,7 +580,7 @@ export const marketplace: MarketplaceTemplate[] = [
usecases: ['Messaging'],
runtimes: [
{
name: 'node-18.0',
name: 'node',
commands: 'npm install',
entrypoint: 'src/main.js',
providerRootDirectory: 'node/whatsapp-with-vonage'
Expand Down Expand Up @@ -629,7 +635,7 @@ export const marketplace: MarketplaceTemplate[] = [
usecases: ['Messaging'],
runtimes: [
{
name: 'node-18.0',
name: 'node',
commands: 'npm install',
entrypoint: 'src/main.js',
providerRootDirectory: 'node/push-notification-with-fcm'
Expand Down Expand Up @@ -684,19 +690,19 @@ export const marketplace: MarketplaceTemplate[] = [
usecases: ['Utilities'],
runtimes: [
{
name: 'node-18.0',
name: 'node',
commands: 'npm install',
entrypoint: 'src/main.js',
providerRootDirectory: 'node/email-contact-form'
},
{
name: 'python-3.9',
name: 'python',
commands: 'pip install -r requirements.txt',
entrypoint: 'src/main.py',
providerRootDirectory: 'python/email_contact_form'
},
{
name: 'php-8.0',
name: 'php',
commands: 'composer install',
entrypoint: 'src/index.php',
providerRootDirectory: 'php/email-contact-form'
Expand Down Expand Up @@ -766,7 +772,7 @@ export const marketplace: MarketplaceTemplate[] = [
usecases: ['Utilities'],
runtimes: [
{
name: 'node-18.0',
name: 'node',
commands: 'npm install',
entrypoint: 'src/main.js',
providerRootDirectory: 'node/subscriptions-with-stripe'
Expand Down Expand Up @@ -822,7 +828,7 @@ export const marketplace: MarketplaceTemplate[] = [
usecases: ['Utilities'],
runtimes: [
{
name: 'node-18.0',
name: 'node',
commands: 'npm install && npm run setup',
entrypoint: 'src/main.js',
providerRootDirectory: 'node/payments-with-stripe'
Expand Down Expand Up @@ -932,7 +938,7 @@ Template:
"timeout": 15,
"runtimes": [
{
"name": "node-18",
"name": "node",
"entrypoint": "src/main.js",
"commands": "npm install"
}
Expand Down
31 changes: 16 additions & 15 deletions src/lib/wizards/functions/cover.svelte
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
<script context="module" lang="ts">
import CreateTemplate from './createTemplate.svelte';
export function connectTemplate(template: MarketplaceTemplate, runtime: string | null = null) {
export function connectTemplate(
template: MarketplaceTemplate,
forceLanguage: string | null = null
) {
const variables: Record<string, string> = {};
template.variables.forEach((variable) => {
variables[variable.name] = variable.value ?? '';
});
if (!runtime) {
runtime = template.runtimes[0].name;
}
templateStore.set(template);
templateConfig.set({
$id: null,
runtime,
name: template.name,
language: forceLanguage,
runtime: null,
variables,
repositoryBehaviour: 'new',
repositoryName: template.id,
Expand Down Expand Up @@ -106,12 +106,15 @@
</li>
{/each}
{:then response}
{@const runtimes = new Map(response.runtimes.map((r) => [r.$id, r]))}
{@const templates = quickStart.runtimes.filter((_template) =>
runtimes.has(_template.name)
)}
{@const templates = quickStart.runtimes.filter((_template) => {
return response.runtimes.some((runtime) =>
runtime.$id.includes(_template.name)
);
})}
Comment on lines -109 to +113
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it reverted a previous change. We should make sure to use better data types when available to avoid doing n^2 operations (iterating over an array in an array).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But now the template name is only going to include the language used not the version so has will not work anymore 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then, maybe use the language as the map key. In general, we should try to avoid doing these nested iterations.

Also, we're back to discussing whether we should ignore the runtime version.

{#each templates.slice(0, 6) as template}
{@const runtimeDetail = runtimes.get(template.name)}
{@const runtimeDetail = response.runtimes?.find((runtime) =>
runtime?.$id?.includes(template.name)
)}
<li>
<button
on:click={() => {
Expand All @@ -128,13 +131,11 @@
<div class="avatar is-size-small">
<img
style:--p-text-size="1.25rem"
src={`${base}/icons/${$app.themeInUse}/color/${
template.name.split('-')[0]
}.svg`}
src={`${base}/icons/${$app.themeInUse}/color/${template.name}.svg`}
alt={template.name} />
</div>
<div class="body-text-2">
{runtimeDetail.name}
{runtimeDetail?.name ?? template.name}
</div>
</button>
</li>
Expand Down
4 changes: 2 additions & 2 deletions src/lib/wizards/functions/createTemplate.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

async function create() {
try {
const runtimeDetail = $template.runtimes.find(
(r) => r.name === $templateConfig.runtime
const runtimeDetail = $template.runtimes.find((r) =>
$templateConfig.runtime.includes(r.name)
);
if ($templateConfig.appwriteApiKey) {
$templateConfig.variables['APPWRITE_API_KEY'] = $templateConfig.appwriteApiKey;
Expand Down
19 changes: 12 additions & 7 deletions src/lib/wizards/functions/steps/templateConfiguration.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,22 @@
}

async function loadRuntimes() {
const options = (await $runtimesList).runtimes
const allowedRuntimes = (await $runtimesList).runtimes.filter((runtime) => {
if ($templateConfig.language) {
return runtime.$id.includes($templateConfig.language);
} else {
return $template.runtimes.some((templateRuntime) =>
runtime.$id.includes(templateRuntime.name)
);
}
});
const options = allowedRuntimes
.map((runtime) => ({
label: `${runtime.name} - ${runtime.version}`,
value: runtime.$id
}))
.filter((runtime) => {
const allowedRuntimes = $template.runtimes.map((r) => r.name);
return allowedRuntimes.includes(runtime.value);
});

.reverse();
$templateConfig.runtime = options[0]?.value;
return options;
}
</script>
Expand Down Expand Up @@ -54,7 +60,6 @@
<InputSelect
label="Runtime"
id="runtime"
placeholder="Select runtime"
required
disabled={options.length <= 1}
{options}
Expand Down
1 change: 1 addition & 0 deletions src/lib/wizards/functions/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const template = writable<MarketplaceTemplate>();
export const templateConfig = writable<{
$id: string;
name: string;
language: string;
runtime: string;
variables: { [key: string]: unknown };
repositoryBehaviour: 'new' | 'existing';
Expand Down
Loading