Skip to content

Commit

Permalink
Merge branch 'main' of github.com:mstarongithub/mk-plugin-repo
Browse files Browse the repository at this point in the history
  • Loading branch information
mStar aka a person committed Apr 26, 2024
2 parents 268ea21 + d2e82e8 commit e074841
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 36 deletions.
35 changes: 35 additions & 0 deletions frontend/src/lib/aiScriptCodeParsers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
export function getAIscriptVersion(str: string): string | null {
const regex = /^\/\/\/ @ (.*)/m;
const match = str.match(regex);
if (match && match.length > 1) {
return match[1].trim();
}
return null;
}

export function getPluginVersion(str: string): string | null {
const regex = /###\s*{\s*.*version:\s*"([^"]*)".*\s*}/s;
const match = str.match(regex);
if (match && match.length > 1) {
return match[1].trim();
}
return null;
}

export function getPluginName(str: string): string | null {
const regex = /###\s*{\s*.*name:\s*"([^"]*)".*\s*}/s;
const match = str.match(regex);
if (match && match.length > 1) {
return match[1].trim();
}
return null;
}

export function getPluginDesc(str: string): string | null {
const regex = /###\s*{\s*.*description:\s*"([^"]*)".*\s*}/s;
const match = str.match(regex);
if (match && match.length > 1) {
return match[1].trim();
}
return null;
}
15 changes: 13 additions & 2 deletions frontend/src/routes/plugin/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
import Navbar from '$lib/Navbar.svelte';
import PluginCode from '$lib/PluginCode.svelte';
import PluginListing from '$lib/PluginListing.svelte';
import { getAIscriptVersion } from '$lib/aiScriptCodeParsers';
import { BASE_DIR } from '$lib/baseDir';
import { onMount } from 'svelte';
import toast from 'svelte-french-toast';
let selectedPluginData: Plugin | undefined = undefined;
let code: string;
let aiscriptVersion: string = "...";
let selectedVersion: string;
let pluginId: string = '';
Expand Down Expand Up @@ -50,7 +52,12 @@
if (response.ok) {
let data = await response.json();
code = data.code;
console.log(code);
aiscriptVersion = data.aiscript_version;
if (aiscriptVersion === "") {
aiscriptVersion = getAIscriptVersion(code) ?? "";
}
console.log(data);
//data.aiscript_version
} else {
let err = await response;
Expand Down Expand Up @@ -78,7 +85,7 @@
></PluginListing>
{/if}

<div class="card !w-10/12 !h-3/4 bg-base-100 shadow-xl overflow-clip p-4">
<div class="card flex flex-row items-center justify-between !w-10/12 !h-3/4 bg-base-100 shadow-xl overflow-clip p-4">
<select
class="select select-bordered w-full max-w-40"
on:change={showCode}
Expand All @@ -91,6 +98,10 @@
{/each}
{/if}
</select>

<!-- <div class = "align-middle h-full"> -->
<p class="text-center ">For AIscript @{aiscriptVersion}</p>
<!-- </div> -->
</div>

<div class="card !w-10/12 !h-3/4 bg-base-100 shadow-xl overflow-clip">
Expand Down
35 changes: 1 addition & 34 deletions frontend/src/routes/submit/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script lang="ts">
import { goto } from '$app/navigation';
import Navbar from '$lib/Navbar.svelte';
import { getAIscriptVersion, getPluginDesc, getPluginName, getPluginVersion } from '$lib/aiScriptCodeParsers';
import { BASE_DIR } from '$lib/baseDir';
import TagField from '$lib/components/TagField.svelte';
import toast from 'svelte-french-toast';
Expand Down Expand Up @@ -40,23 +41,6 @@
}
};
function getPluginName(str: string): string | null {
const regex = /###\s*{\s*.*name:\s*"([^"]*)".*\s*}/s;
const match = str.match(regex);
if (match && match.length > 1) {
return match[1].trim();
}
return null;
}
function getPluginDesc(str: string): string | null {
const regex = /###\s*{\s*.*description:\s*"([^"]*)".*\s*}/s;
const match = str.match(regex);
if (match && match.length > 1) {
return match[1].trim();
}
return null;
}
let codeEdited = () => {
const { code, name, summary_short, summary_long } = newPluginData;
Expand All @@ -73,23 +57,6 @@
}
};
function getAIscriptVersion(str: string): string | null {
const regex = /^\/\/\/ @ (.*)/m;
const match = str.match(regex);
if (match && match.length > 1) {
return match[1].trim();
}
return null;
}
function getPluginVersion(str: string): string | null {
const regex = /###\s*{\s*.*version:\s*"([^"]*)".*\s*}/s;
const match = str.match(regex);
if (match && match.length > 1) {
return match[1].trim();
}
return null;
}
function parseVersionFromCode(code: string) {
const aiscriptVersion = getAIscriptVersion(code);
Expand Down

0 comments on commit e074841

Please sign in to comment.