mirror of
https://github.com/pesde-pkg/pesde.git
synced 2024-12-12 02:50:37 +00:00
docs: document scripts packages
This commit is contained in:
parent
16ab05ec72
commit
4a3619c26e
5 changed files with 95 additions and 11 deletions
53
docs/src/content/docs/guides/scripts-packages.mdx
Normal file
53
docs/src/content/docs/guides/scripts-packages.mdx
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
---
|
||||||
|
title: Using Scripts Packages
|
||||||
|
description: Learn how to use scripts packages.
|
||||||
|
---
|
||||||
|
|
||||||
|
A **scripts package** is a package that contains scripts. The scripts provided
|
||||||
|
by the package are linked in `.pesde/{alias}/{script_name}.luau` of the project
|
||||||
|
that uses the package.
|
||||||
|
|
||||||
|
## Using a scripts package
|
||||||
|
|
||||||
|
Scripts packages can be installed using the `pesde add` and `pesde install`
|
||||||
|
commands.
|
||||||
|
|
||||||
|
This requires a `pesde.toml` file to be present in the current directory, and
|
||||||
|
will add the scripts package to the `dependencies` section of the file.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
pesde add pesde/scripts_rojo
|
||||||
|
pesde install
|
||||||
|
```
|
||||||
|
|
||||||
|
This will add the scripts package to your project, and installing will put the
|
||||||
|
scripts at `.pesde/scripts_rojo/{script_name}.luau`. You can then add the scripts
|
||||||
|
to your manifest, for example:
|
||||||
|
|
||||||
|
```toml title="pesde.toml"
|
||||||
|
[scripts]
|
||||||
|
roblox_sync_config_generator = ".pesde/scripts_rojo/roblox_sync_config_generator.luau"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Making a scripts package
|
||||||
|
|
||||||
|
To make a scripts package you must use a target compatible with scripts exports.
|
||||||
|
These currently are `lune` and `luau`.
|
||||||
|
|
||||||
|
Here is an example of a scripts package:
|
||||||
|
|
||||||
|
```toml title="pesde.toml"
|
||||||
|
name = "pesde/scripts_rojo"
|
||||||
|
version = "1.0.0"
|
||||||
|
license = "MIT"
|
||||||
|
|
||||||
|
[target]
|
||||||
|
environment = "lune"
|
||||||
|
|
||||||
|
[target.scripts]
|
||||||
|
roblox_sync_config_generator = "roblox_sync_config_generator.luau"
|
||||||
|
```
|
||||||
|
|
||||||
|
The `scripts` table in the target is a map of script names to the path of the
|
||||||
|
script in the package. The scripts will be linked in the project that uses the
|
||||||
|
package at `.pesde/{alias}/{script_name}.luau`.
|
|
@ -155,6 +155,18 @@ build_files = [
|
||||||
These files are passed to [`roblox_sync_config_generator`](#roblox_sync_config_generator)
|
These files are passed to [`roblox_sync_config_generator`](#roblox_sync_config_generator)
|
||||||
when the package is installed in order to generate the necessary configuration.
|
when the package is installed in order to generate the necessary configuration.
|
||||||
|
|
||||||
|
### `scripts`
|
||||||
|
|
||||||
|
**Allowed in:** `luau`, `lune`
|
||||||
|
|
||||||
|
A list of scripts that will be linked to the project's `.pesde` directory, and
|
||||||
|
copied over to the [scripts](#scripts-1) section when initialising a project with
|
||||||
|
this package.
|
||||||
|
|
||||||
|
```toml
|
||||||
|
scripts = { roblox_sync_config_generator = "scripts/roblox_sync_config_generator.luau" }
|
||||||
|
```
|
||||||
|
|
||||||
## `[scripts]`
|
## `[scripts]`
|
||||||
|
|
||||||
The `[scripts]` section contains scripts that can be run using the `pesde run`
|
The `[scripts]` section contains scripts that can be run using the `pesde run`
|
||||||
|
|
|
@ -8,6 +8,8 @@ pub struct TargetInfo {
|
||||||
kind: TargetKind,
|
kind: TargetKind,
|
||||||
lib: bool,
|
lib: bool,
|
||||||
bin: bool,
|
bin: bool,
|
||||||
|
#[serde(skip_serializing_if = "BTreeSet::is_empty")]
|
||||||
|
scripts: BTreeSet<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Target> for TargetInfo {
|
impl From<Target> for TargetInfo {
|
||||||
|
@ -22,6 +24,10 @@ impl From<&Target> for TargetInfo {
|
||||||
kind: target.kind(),
|
kind: target.kind(),
|
||||||
lib: target.lib_path().is_some(),
|
lib: target.lib_path().is_some(),
|
||||||
bin: target.bin_path().is_some(),
|
bin: target.bin_path().is_some(),
|
||||||
|
scripts: target
|
||||||
|
.scripts()
|
||||||
|
.map(|scripts| scripts.keys().cloned().collect())
|
||||||
|
.unwrap_or_default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ export type TargetInfo = {
|
||||||
kind: TargetKind
|
kind: TargetKind
|
||||||
lib: boolean
|
lib: boolean
|
||||||
bin: boolean
|
bin: boolean
|
||||||
|
scripts?: string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export type TargetKind = "roblox" | "roblox_server" | "lune" | "luau"
|
export type TargetKind = "roblox" | "roblox_server" | "lune" | "luau"
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
import { page } from "$app/stores"
|
import { page } from "$app/stores"
|
||||||
import GitHub from "$lib/components/GitHub.svelte"
|
import GitHub from "$lib/components/GitHub.svelte"
|
||||||
import type { TargetInfo } from "$lib/registry-api"
|
import type { TargetInfo } from "$lib/registry-api"
|
||||||
import { BinaryIcon, Globe, Icon, LibraryIcon, Mail } from "lucide-svelte"
|
import { BinaryIcon, Globe, Icon, LibraryIcon, Mail, ScrollIcon } from "lucide-svelte"
|
||||||
import type { ComponentType } from "svelte"
|
import type { ComponentType } from "svelte"
|
||||||
import TargetSelector from "../../TargetSelector.svelte"
|
import TargetSelector from "../../TargetSelector.svelte"
|
||||||
import Command from "./Command.svelte"
|
import Command from "./Command.svelte"
|
||||||
|
@ -36,11 +36,13 @@
|
||||||
const exportNames: Partial<Record<keyof TargetInfo, string>> = {
|
const exportNames: Partial<Record<keyof TargetInfo, string>> = {
|
||||||
lib: "Library",
|
lib: "Library",
|
||||||
bin: "Binary",
|
bin: "Binary",
|
||||||
|
scripts: "Scripts",
|
||||||
}
|
}
|
||||||
|
|
||||||
const exportIcons: Partial<Record<keyof TargetInfo, ComponentType<Icon>>> = {
|
const exportIcons: Partial<Record<keyof TargetInfo, ComponentType<Icon>>> = {
|
||||||
lib: LibraryIcon,
|
lib: LibraryIcon,
|
||||||
bin: BinaryIcon,
|
bin: BinaryIcon,
|
||||||
|
scripts: ScrollIcon,
|
||||||
}
|
}
|
||||||
|
|
||||||
const exportEntries = $derived(
|
const exportEntries = $derived(
|
||||||
|
@ -92,20 +94,30 @@
|
||||||
<ul class="mb-6 space-y-0.5">
|
<ul class="mb-6 space-y-0.5">
|
||||||
{#each exportEntries as [exportKey, exportName]}
|
{#each exportEntries as [exportKey, exportName]}
|
||||||
{@const Icon = exportIcons[exportKey as keyof TargetInfo]}
|
{@const Icon = exportIcons[exportKey as keyof TargetInfo]}
|
||||||
<li class="flex items-center">
|
<li>
|
||||||
<Icon aria-hidden="true" class="text-primary mr-2 size-5" />
|
<div class="flex items-center">
|
||||||
{exportName}
|
<Icon aria-hidden="true" class="text-primary mr-2 size-5" />
|
||||||
|
{exportName}
|
||||||
|
</div>
|
||||||
|
{#if exportKey === "bin"}
|
||||||
|
<p class="text-body/80 mb-4 mt-3 text-sm">
|
||||||
|
This package provides a binary that can be executed after installation, or globally
|
||||||
|
via:
|
||||||
|
</p>
|
||||||
|
<Command command={xCommand} class="mb-6" />
|
||||||
|
{:else if exportKey === "scripts"}
|
||||||
|
<div class="text-body/80 mt-3 flex flex-wrap gap-2 text-sm">
|
||||||
|
{#each currentTarget?.scripts ?? [] as script}
|
||||||
|
<div class="bg-card text-heading w-max truncate rounded px-3 py-2" title={script}>
|
||||||
|
{script}
|
||||||
|
</div>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
</li>
|
</li>
|
||||||
{/each}
|
{/each}
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
{#if currentTarget?.bin}
|
|
||||||
<p class="text-body/80 -mt-3 mb-4 text-sm">
|
|
||||||
This package provides a binary that can be executed after installation, or globally via:
|
|
||||||
</p>
|
|
||||||
<Command command={xCommand} class="mb-6" />
|
|
||||||
{/if}
|
|
||||||
|
|
||||||
{#if data.pkg.authors && data.pkg.authors.length > 0}
|
{#if data.pkg.authors && data.pkg.authors.length > 0}
|
||||||
<h2 class="text-heading mb-2 text-lg font-semibold">Authors</h2>
|
<h2 class="text-heading mb-2 text-lg font-semibold">Authors</h2>
|
||||||
<ul>
|
<ul>
|
||||||
|
|
Loading…
Reference in a new issue