From 1d51a6c3eb6aa52a9731b7ee80c40e330e4d2035 Mon Sep 17 00:00:00 2001 From: Wolf Mermelstein Date: Fri, 2 May 2025 18:05:29 -0400 Subject: [PATCH 1/5] Export logic to 'vtlib' library, generate docs --- .github/workflows/docs.yaml | 28 +++++++++++ deno.json | 8 ++-- mod.ts | 80 +++++++++++++++++++++++++++++++ src/cmd/lib/utils/parsing.ts | 0 src/vt/lib/mod.ts | 11 +++++ src/vt/lib/tests/checkout_test.ts | 2 +- src/vt/lib/tests/clone_test.ts | 2 +- src/vt/lib/tests/pull_test.ts | 2 +- src/vt/lib/tests/push_test.ts | 2 +- src/vt/lib/tests/remix_test.ts | 2 +- src/vt/lib/tests/status_test.ts | 2 +- src/vt/lib/{ => utils}/paths.ts | 0 src/vt/lib/{ => vals}/checkout.ts | 47 ++++++++++-------- src/vt/lib/{ => vals}/clone.ts | 18 ++++--- src/vt/lib/{ => vals}/create.ts | 9 ++-- src/vt/lib/vals/mod.ts | 7 +++ src/vt/lib/{ => vals}/pull.ts | 43 ++++++++--------- src/vt/lib/{ => vals}/push.ts | 17 ++++--- src/vt/lib/{ => vals}/remix.ts | 13 +++-- src/vt/lib/{ => vals}/status.ts | 9 ++-- src/vt/vt/VTClient.ts | 14 +++--- vt.ts | 3 +- 22 files changed, 234 insertions(+), 85 deletions(-) create mode 100644 .github/workflows/docs.yaml create mode 100755 mod.ts create mode 100644 src/cmd/lib/utils/parsing.ts create mode 100644 src/vt/lib/mod.ts rename src/vt/lib/{ => utils}/paths.ts (100%) rename src/vt/lib/{ => vals}/checkout.ts (88%) rename src/vt/lib/{ => vals}/clone.ts (93%) rename src/vt/lib/{ => vals}/create.ts (93%) create mode 100644 src/vt/lib/vals/mod.ts rename src/vt/lib/{ => vals}/pull.ts (79%) rename src/vt/lib/{ => vals}/push.ts (95%) rename src/vt/lib/{ => vals}/remix.ts (94%) rename src/vt/lib/{ => vals}/status.ts (96%) mode change 100755 => 100644 vt.ts diff --git a/.github/workflows/docs.yaml b/.github/workflows/docs.yaml new file mode 100644 index 00000000..8949c8c8 --- /dev/null +++ b/.github/workflows/docs.yaml @@ -0,0 +1,28 @@ +Docs + +on: + push: + branches: + - '*' + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Check out the code + uses: actions/checkout@v2 + + - name: Set up Deno + uses: denoland/setup-deno@v1 + with: + deno-version: '2.x' + + - name: Generate documentation + run: deno task doc + + - name: Deploy to GitHub Pages + uses: peaceiris/actions-gh-pages@vr + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: ./docs \ No newline at end of file diff --git a/deno.json b/deno.json index 4d3e0249..ae699e0d 100644 --- a/deno.json +++ b/deno.json @@ -3,15 +3,17 @@ "name": "@valtown/vt", "description": "The Val Town CLI", "version": "0.1.24", - "exports": "./vt.ts", + "exports": "./mod.ts", "license": "MIT", "tasks": { - "run": "./vt.ts", + "run": "./mod.ts", "test": "deno task test:lib --parallel && deno task test:cmd", "test:cmd": "env DENO_NO_PROMPT=1 deno test -A ./src/cmd", "test:lib": "env DENO_NO_PROMPT=1 deno test -A ./src/vt/lib", "check": "env DENO_NO_PROMPT=1 deno check .", - "fmt:check": "env DENO_NO_PROMPT=1 deno fmt --check" + "fmt": "env DENO_NO_PROMPT=1 deno fmt --ignore=docs", + "fmt:check": "env DENO_NO_PROMPT=1 deno fmt --check", + "doc": "deno doc --html --name='vtlib' --output=docs mod.ts" }, "imports": { "@std/random": "jsr:@std/random@^0.1.0", diff --git a/mod.ts b/mod.ts new file mode 100755 index 00000000..d0754ba7 --- /dev/null +++ b/mod.ts @@ -0,0 +1,80 @@ +#!/usr/bin/env -S deno run --allow-read --allow-write --allow-env --allow-net --allow-sys --allow-run +import { launch } from "./vt.ts"; + +/** + * # vtlib + * + * ### What is `vtlib`? + * `vtlib` is the internal library used by `vt`, the Val Town CLI. `vtlib` lets + * you do `push`ing, `pull`ing, `clone`ing, and more, from a Deno context, so + * that you can reuse much of the internal syncing functionality of `vt`. + * + * Primary library functions include + * - {@link checkout} Check out a branch from a Val Town project + * - {@link clone} Clone a Val Town project to a local directory + * - {@link create} Create a new Val Town project from local files + * - {@link pull} Pull changes from a Val Town project to a local directory + * - {@link push} Push local changes to a Val Town project + * - {@link remix} Create a new project based on an existing project + * - {@link status} Check the status of local files compared to a Val Town project + * + * @example Clone a project to a directory + * ```typescript + * import { clone } from "@valtown/vt"; + * + * const result = await clone({ + * projectId: "d23e2d8d-9cc8-40e3-bbf4-107c42efe6c1", + * branchId: "0e73994d-f9bd-4e59-a255-7f4593127623", + * targetDir: "./my-project" + * }); + * ``` + * + * @example Push changes to a project + * ```typescript + * import { push } from "@valtown/vt"; + * + * const result = await push({ + * projectId: "c085baed-ec07-4a2e-811a-216f567b5ef1", + * targetDir: "." + * }); + * ``` + * + * @example Create a new project from local files + * ```typescript + * import { create } from "@valtown/vt"; + * + * const result = await create({ + * projectId: "01b34cb3-f581-47c9-8024-ae126c0f0b1e", + * sourceDir: "./my-code" + * }); + * ``` + * + * @example Check status of local files compared to remote + * ```typescript + * import { status } from "@valtown/vt"; + * + * const result = await status({ + * projectId: "79af7bd7-3e5b-4492-8b14-dac502cdbce6", + * targetDir: "." + * }); + * ``` + * + * @example Remix an existing project + * ```typescript + * import { remix } from "@valtown/vt"; + * + * const result = await remix({ + * srcProjectId: "a35e5f60-5a47-4201-9d82-b6a60bd57d4d", + * projectName: "My Remix", + * targetDir: "./remixed-project" + * }); + * ``` + * + * @module + */ + +if (import.meta.main) { + await launch(); +} + +export * from "~/vt/lib/mod.ts"; diff --git a/src/cmd/lib/utils/parsing.ts b/src/cmd/lib/utils/parsing.ts new file mode 100644 index 00000000..e69de29b diff --git a/src/vt/lib/mod.ts b/src/vt/lib/mod.ts new file mode 100644 index 00000000..3c8eaa18 --- /dev/null +++ b/src/vt/lib/mod.ts @@ -0,0 +1,11 @@ +/** + * Core functionalities of the Val Town CLI. It includes modules for checking + * out, cloning, creating, pulling, pushing, remixing, and checking the status + * of Val Town projects. + */ + +export * from "./vals/mod.ts"; + +export type { ItemStatusManager } from "./utils/ItemStatusManager.ts"; +export { getProjectItemType } from "./utils/paths.ts"; +export type * from "~/types.ts"; diff --git a/src/vt/lib/tests/checkout_test.ts b/src/vt/lib/tests/checkout_test.ts index a30eb473..9c582854 100644 --- a/src/vt/lib/tests/checkout_test.ts +++ b/src/vt/lib/tests/checkout_test.ts @@ -1,6 +1,6 @@ import { doWithNewProject } from "~/vt/lib/tests/utils.ts"; import sdk, { branchExists, getLatestVersion } from "~/sdk.ts"; -import { checkout } from "~/vt/lib/checkout.ts"; +import { checkout } from "~/vt/lib/vals/checkout.ts"; import { assert, assertEquals } from "@std/assert"; import { join } from "@std/path"; import { exists } from "@std/fs"; diff --git a/src/vt/lib/tests/clone_test.ts b/src/vt/lib/tests/clone_test.ts index 22142950..52c0b472 100644 --- a/src/vt/lib/tests/clone_test.ts +++ b/src/vt/lib/tests/clone_test.ts @@ -1,7 +1,7 @@ import { doWithTempDir } from "~/vt/lib/utils/misc.ts"; import { doWithNewProject } from "~/vt/lib/tests/utils.ts"; import sdk from "~/sdk.ts"; -import { clone } from "~/vt/lib/clone.ts"; +import { clone } from "~/vt/lib/vals/clone.ts"; import { assertEquals } from "@std/assert"; import { join } from "@std/path"; import { exists } from "@std/fs"; diff --git a/src/vt/lib/tests/pull_test.ts b/src/vt/lib/tests/pull_test.ts index 806add8a..31a49963 100644 --- a/src/vt/lib/tests/pull_test.ts +++ b/src/vt/lib/tests/pull_test.ts @@ -1,7 +1,7 @@ import { doWithTempDir } from "~/vt/lib/utils/misc.ts"; import { doWithNewProject } from "~/vt/lib/tests/utils.ts"; import sdk, { getLatestVersion } from "~/sdk.ts"; -import { pull } from "~/vt/lib/pull.ts"; +import { pull } from "~/vt/lib/vals/pull.ts"; import { assert, assertEquals } from "@std/assert"; import { join } from "@std/path"; import { exists } from "@std/fs"; diff --git a/src/vt/lib/tests/push_test.ts b/src/vt/lib/tests/push_test.ts index cea6dad6..6e158140 100644 --- a/src/vt/lib/tests/push_test.ts +++ b/src/vt/lib/tests/push_test.ts @@ -4,7 +4,7 @@ import sdk, { listProjectItems, projectItemExists, } from "~/sdk.ts"; -import { push } from "~/vt/lib/push.ts"; +import { push } from "~/vt/lib/vals/push.ts"; import { assert, assertEquals } from "@std/assert"; import { join } from "@std/path"; import { doWithTempDir } from "~/vt/lib/utils/misc.ts"; diff --git a/src/vt/lib/tests/remix_test.ts b/src/vt/lib/tests/remix_test.ts index 30dbaca9..29d5a6a5 100644 --- a/src/vt/lib/tests/remix_test.ts +++ b/src/vt/lib/tests/remix_test.ts @@ -4,7 +4,7 @@ import sdk, { getCurrentUser } from "~/sdk.ts"; import { assert, assertEquals } from "@std/assert"; import { join } from "@std/path"; import { exists } from "@std/fs"; -import { remix } from "~/vt/lib/remix.ts"; +import { remix } from "~/vt/lib/vals/remix.ts"; Deno.test({ name: "remix preserves HTTP val type", diff --git a/src/vt/lib/tests/status_test.ts b/src/vt/lib/tests/status_test.ts index 8154b257..de794730 100644 --- a/src/vt/lib/tests/status_test.ts +++ b/src/vt/lib/tests/status_test.ts @@ -3,7 +3,7 @@ import { doWithNewProject } from "~/vt/lib/tests/utils.ts"; import sdk, { getLatestVersion } from "~/sdk.ts"; import { assertEquals } from "@std/assert"; import { join } from "@std/path"; -import { status } from "~/vt/lib/status.ts"; +import { status } from "~/vt/lib/vals/status.ts"; import type { ItemStatusManager } from "../utils/ItemStatusManager.ts"; Deno.test({ diff --git a/src/vt/lib/paths.ts b/src/vt/lib/utils/paths.ts similarity index 100% rename from src/vt/lib/paths.ts rename to src/vt/lib/utils/paths.ts diff --git a/src/vt/lib/checkout.ts b/src/vt/lib/vals/checkout.ts similarity index 88% rename from src/vt/lib/checkout.ts rename to src/vt/lib/vals/checkout.ts index 08a3ab66..71b9c8f7 100644 --- a/src/vt/lib/checkout.ts +++ b/src/vt/lib/vals/checkout.ts @@ -1,9 +1,9 @@ import sdk from "~/sdk.ts"; import type ValTown from "@valtown/sdk"; -import { pull } from "~/vt/lib/pull.ts"; +import { pull } from "~/vt/lib/vals/pull.ts"; import { join, relative } from "@std/path"; import { walk } from "@std/fs"; -import { getProjectItemType, shouldIgnore } from "~/vt/lib/paths.ts"; +import { getProjectItemType, shouldIgnore } from "~/vt/lib/utils/paths.ts"; import { listProjectItems } from "~/sdk.ts"; import { ItemStatusManager } from "~/vt/lib/utils/ItemStatusManager.ts"; import { doAtomically, gracefulRecursiveCopy } from "~/vt/lib/utils/misc.ts"; @@ -12,7 +12,7 @@ import { doAtomically, gracefulRecursiveCopy } from "~/vt/lib/utils/misc.ts"; * Result of a checkout operation containing branch information and file * changes. */ -export interface CheckoutResult { +interface CheckoutResult { /** The source branch */ fromBranch: ValTown.Projects.BranchCreateResponse; /** @@ -29,7 +29,7 @@ export interface CheckoutResult { /** * Base parameters for all checkout operations. */ -export type BaseCheckoutParams = { +type BaseCheckoutParams = { /** The directory where the branch will be checked out */ targetDir: string; /** The ID of the project */ @@ -45,7 +45,7 @@ export type BaseCheckoutParams = { /** * Parameters for checking out an existing branch. */ -export type BranchCheckoutParams = BaseCheckoutParams & { +type BranchCheckoutParams = BaseCheckoutParams & { /** The ID of the branch to checkout */ toBranchId: string; /** The ID of the branch we're switching from */ @@ -55,7 +55,7 @@ export type BranchCheckoutParams = BaseCheckoutParams & { /** * Parameters for creating and checking out a new branch (fork). */ -export type ForkCheckoutParams = BaseCheckoutParams & { +type ForkCheckoutParams = BaseCheckoutParams & { /** The branch ID from which to create the fork */ forkedFromId: string; /** The name for the new forked branch */ @@ -64,19 +64,20 @@ export type ForkCheckoutParams = BaseCheckoutParams & { /** * Checks out a specific existing branch of a project. + * * @param params Options for the checkout operation. - * @returns {Promise} A promise that resolves with checkout information. + * @returns A promise that resolves with checkout information. */ -export function checkout(params: BranchCheckoutParams): Promise; +function checkout(params: BranchCheckoutParams): Promise; /** - * Creates a new branch from a project's branch and checks it out. - * @param params Options for the checkout operation. - * @returns {Promise} A promise that resolves with checkout information (including the new branch - details). - */ -export function checkout(params: ForkCheckoutParams): Promise; -export function checkout( + * Creates a new branch from a project's branch and checks it out. + * + * @param params Options for the checkout operation. + * @returns A promise that resolves with checkout information (including the new branch details). + */ +function checkout(params: ForkCheckoutParams): Promise; +function checkout( params: BranchCheckoutParams | ForkCheckoutParams, ): Promise { // Determine if we're creating a new branch or checking out an existing one @@ -91,9 +92,7 @@ export function checkout( } } -/** - * Handles creating a new branch (fork) and marking all files as not_modified - */ +// Handles creating a new branch (fork) and marking all files as not_modified async function handleForkCheckout( params: ForkCheckoutParams, ): Promise { @@ -147,9 +146,7 @@ async function handleForkCheckout( }; } -/** - * Handles checking out an existing branch - */ +// Handles checking out an existing branch async function handleBranchCheckout( params: BranchCheckoutParams, ): Promise { @@ -263,3 +260,11 @@ async function handleBranchCheckout( { targetDir: params.targetDir }, ); } + +export { checkout }; +export type { + BaseCheckoutParams, + BranchCheckoutParams, + CheckoutResult, + ForkCheckoutParams, +}; diff --git a/src/vt/lib/clone.ts b/src/vt/lib/vals/clone.ts similarity index 93% rename from src/vt/lib/clone.ts rename to src/vt/lib/vals/clone.ts index 12e5e7d3..e0722247 100644 --- a/src/vt/lib/clone.ts +++ b/src/vt/lib/vals/clone.ts @@ -1,5 +1,5 @@ -import sdk, { listProjectItems } from "~/sdk.ts"; -import { shouldIgnore } from "~/vt/lib/paths.ts"; +import sdk, { getLatestVersion, listProjectItems } from "~/sdk.ts"; +import { shouldIgnore } from "~/vt/lib/utils/paths.ts"; import { ensureDir, exists } from "@std/fs"; import { dirname } from "@std/path/dirname"; import { join } from "@std/path"; @@ -13,7 +13,7 @@ import { /** * Result of a clone operation. */ -export interface CloneResult { +interface CloneResult { /** Changes made to items during the cloning process */ itemStateChanges: ItemStatusManager; } @@ -22,7 +22,7 @@ export interface CloneResult { * Parameters for cloning a project by downloading its files and directories to the specified * target directory. */ -export interface CloneParams { +interface CloneParams { /** The directory where the project will be cloned */ targetDir: string; /** The id of the project to be cloned */ @@ -30,7 +30,7 @@ export interface CloneParams { /** The branch ID of the project to clone */ branchId: string; /** The version to clone. Defaults to latest */ - version: number; + version?: number; /** A list of gitignore rules. */ gitignoreRules?: string[]; /** If true, don't actually write files, just report what would change */ @@ -46,8 +46,8 @@ export interface CloneParams { * @param params Options for the clone operation * @returns Promise that resolves with changes that were applied or would be applied (if dryRun=true) */ -export function clone(params: CloneParams): Promise { - const { +function clone(params: CloneParams): Promise { + let { targetDir, projectId, branchId, @@ -58,6 +58,7 @@ export function clone(params: CloneParams): Promise { } = params; return doAtomically( async (tmpDir) => { + version = version ?? (await getLatestVersion(projectId, branchId)); const itemStateChanges = new ItemStatusManager(); const projectItems = await listProjectItems( projectId, @@ -216,3 +217,6 @@ async function createFile( // Set the file's mtime to match the source await Deno.utime(join(targetRoot, path), updatedAt, updatedAt); } + +export { clone }; +export type { CloneParams, CloneResult }; diff --git a/src/vt/lib/create.ts b/src/vt/lib/vals/create.ts similarity index 93% rename from src/vt/lib/create.ts rename to src/vt/lib/vals/create.ts index 501fbf94..d68e8d3f 100644 --- a/src/vt/lib/create.ts +++ b/src/vt/lib/vals/create.ts @@ -1,4 +1,4 @@ -import { push } from "~/vt/lib/push.ts"; +import { push } from "~/vt/lib/vals/push.ts"; import sdk, { branchNameToBranch } from "~/sdk.ts"; import type { ProjectPrivacy } from "~/types.ts"; import { DEFAULT_BRANCH_NAME } from "~/consts.ts"; @@ -21,7 +21,7 @@ interface CreateResponse { /** * Parameters for creating a new Val Town project from a local directory. */ -export interface CreateParams { +interface CreateParams { /** The root directory containing the files to upload to the new project. */ sourceDir: string; /** The name for the new project. */ @@ -41,7 +41,7 @@ export interface CreateParams { * * @returns Promise that resolves with changes that were applied during the push operation and the new project ID. */ -export async function create( +async function create( params: CreateParams, ): Promise { const { @@ -79,3 +79,6 @@ export async function create( newBranchId: newBranch.id, }; } + +export { create }; +export type { CreateParams, CreateResponse }; diff --git a/src/vt/lib/vals/mod.ts b/src/vt/lib/vals/mod.ts new file mode 100644 index 00000000..8941ef47 --- /dev/null +++ b/src/vt/lib/vals/mod.ts @@ -0,0 +1,7 @@ +export * as checkout from "./checkout.ts"; +export * as clone from "./clone.ts"; +export * as create from "./create.ts"; +export * as pull from "./pull.ts"; +export * as push from "./push.ts"; +export * as remix from "./remix.ts"; +export * as status from "./status.ts"; diff --git a/src/vt/lib/pull.ts b/src/vt/lib/vals/pull.ts similarity index 79% rename from src/vt/lib/pull.ts rename to src/vt/lib/vals/pull.ts index c114082c..3f901649 100644 --- a/src/vt/lib/pull.ts +++ b/src/vt/lib/vals/pull.ts @@ -1,26 +1,31 @@ import { join, relative } from "@std/path"; import { walk } from "@std/fs"; -import { getProjectItemType, shouldIgnore } from "~/vt/lib/paths.ts"; -import { listProjectItems } from "~/sdk.ts"; -import { clone } from "~/vt/lib/clone.ts"; +import { getProjectItemType, shouldIgnore } from "~/vt/lib/utils/paths.ts"; +import { + branchNameToBranch, + getLatestVersion, + listProjectItems, +} from "~/sdk.ts"; +import { clone } from "~/vt/lib/vals/clone.ts"; import { doAtomically, gracefulRecursiveCopy } from "~/vt/lib/utils/misc.ts"; import { type ItemStatus, ItemStatusManager, } from "~/vt/lib/utils/ItemStatusManager.ts"; +import { DEFAULT_BRANCH_NAME } from "~/consts.ts"; /** * Parameters for pulling latest changes from a Val Town project into a vt folder. */ -export interface PullParams { +interface PullParams { /** The vt project root directory. */ targetDir: string; /** The id of the project to download from. */ projectId: string; - /** The branch ID to download file content from. */ - branchId: string; + /** The branch ID to download file content from. Defaults to main. */ + branchId?: string; /** The version to pull. Defaults to latest version. */ - version: number; + version?: number; /** A list of gitignore rules. */ gitignoreRules?: string[]; /** If true, don't actually modify files, just report what would change. */ @@ -28,30 +33,21 @@ export interface PullParams { } /** - * Pulls latest changes from a Val Town project into a vt folder. + * Pulls the latest changes from a Val Town project into a local directory. * * @param {PullParams} params Options for pull operation. - * - * @description - * After a pull: - * - All files from the remote project exist at the remote's version's location locally - * - Local files that match gitignore rules are preserved at their current path - * - Untracked local files that were never pushed are preserved - * - * Files that are removed: - * - Files that previously existed in the remote project but were deleted - * - * @returns Promise that resolves with changes that were applied or would be applied (if dryRun=true) + * @returns Promise that resolves with an ItemStatusManager containing information about changes. */ -export function pull(params: PullParams): Promise { +async function pull(params: PullParams): Promise { const { targetDir, projectId, - branchId, - version, + branchId = (await branchNameToBranch(projectId, DEFAULT_BRANCH_NAME)).id, + version = await getLatestVersion(projectId, branchId), gitignoreRules = [], dryRun = false, } = params; + return doAtomically( async (tmpDir) => { const changes = new ItemStatusManager(); @@ -133,3 +129,6 @@ export function pull(params: PullParams): Promise { { targetDir, prefix: "vt_pull_" }, ); } + +export { pull }; +export type { PullParams }; diff --git a/src/vt/lib/push.ts b/src/vt/lib/vals/push.ts similarity index 95% rename from src/vt/lib/push.ts rename to src/vt/lib/vals/push.ts index b8daa550..dbdcff42 100644 --- a/src/vt/lib/push.ts +++ b/src/vt/lib/vals/push.ts @@ -1,10 +1,11 @@ import type { ProjectFileType, ProjectItemType } from "~/types.ts"; import sdk, { + branchNameToBranch, getLatestVersion, getProjectItem, listProjectItems, } from "~/sdk.ts"; -import { status } from "~/vt/lib/status.ts"; +import { status } from "~/vt/lib/vals/status.ts"; import { basename, dirname, join } from "@std/path"; import { assert } from "@std/assert"; import { exists } from "@std/fs/exists"; @@ -14,8 +15,9 @@ import { ItemStatusManager, } from "~/vt/lib/utils/ItemStatusManager.ts"; import { pooledMap } from "@std/async"; +import { DEFAULT_BRANCH_NAME } from "~/consts.ts"; -export interface PushResult { +interface PushResult { /** Changes made to project items during the push process */ itemStateChanges: ItemStatusManager; } @@ -23,13 +25,13 @@ export interface PushResult { /** * Parameters for pushing latest changes from a vt folder into a Val Town project. */ -export interface PushParams { +interface PushParams { /** The vt project root directory. */ targetDir: string; /** The id of the project to upload to. */ projectId: string; /** The branch ID to upload to. */ - branchId: string; + branchId?: string; /** A list of gitignore rules. */ gitignoreRules?: string[]; /** If true, don't actually modify files on server, just report what would change. */ @@ -45,11 +47,11 @@ export interface PushParams { * @param {PushParams} params Options for push operation. * @returns Promise that resolves with changes that were applied or would be applied (if dryRun=true) */ -export async function push(params: PushParams): Promise { +async function push(params: PushParams): Promise { const { targetDir, projectId, - branchId, + branchId = (await branchNameToBranch(projectId, DEFAULT_BRANCH_NAME)).id, gitignoreRules, dryRun = false, concurrencyPoolSize = 10, @@ -309,3 +311,6 @@ async function doReqMaybeApplyWarning( return undefined; } } + +export { push }; +export type { PushParams, PushResult }; diff --git a/src/vt/lib/remix.ts b/src/vt/lib/vals/remix.ts similarity index 94% rename from src/vt/lib/remix.ts rename to src/vt/lib/vals/remix.ts index a5b9ed65..c048661b 100644 --- a/src/vt/lib/remix.ts +++ b/src/vt/lib/vals/remix.ts @@ -1,5 +1,5 @@ -import { clone } from "~/vt/lib/clone.ts"; -import { create } from "~/vt/lib/create.ts"; +import { clone } from "~/vt/lib/vals/clone.ts"; +import { create } from "~/vt/lib/vals/create.ts"; import sdk, { branchNameToBranch, getLatestVersion, @@ -17,7 +17,7 @@ import { doAtomically } from "~/vt/lib/utils/misc.ts"; * This object contains information about the newly created project and the changes * that were made to the local file state during the remix operation. */ -export interface RemixResult { +interface RemixResult { /** The ID of the newly created project */ toProjectId: string; /** The version number of the newly created project */ @@ -32,7 +32,7 @@ export interface RemixResult { /** * Parameters for remixing some Val Town project to a new Val Town project. */ -export interface RemixParams { +interface RemixParams { /** The root directory to contain the newly remixed project. */ targetDir: string; /** The id of the project to remix from. */ @@ -57,7 +57,7 @@ export interface RemixParams { * @returns Promise that resolves with a CheckoutResult containing information about the * newly created project and the changes made during the remix operation. */ -export async function remix( +async function remix( params: RemixParams, ): Promise { const itemStateChanges = new ItemStatusManager(); @@ -128,3 +128,6 @@ export async function remix( }, true]; }, { targetDir }); } + +export { remix }; +export type { RemixParams, RemixResult }; diff --git a/src/vt/lib/status.ts b/src/vt/lib/vals/status.ts similarity index 96% rename from src/vt/lib/status.ts rename to src/vt/lib/vals/status.ts index d46bd5f5..80cbedff 100644 --- a/src/vt/lib/status.ts +++ b/src/vt/lib/vals/status.ts @@ -1,5 +1,5 @@ import sdk, { listProjectItems } from "~/sdk.ts"; -import { getProjectItemType, shouldIgnore } from "~/vt/lib/paths.ts"; +import { getProjectItemType, shouldIgnore } from "~/vt/lib/utils/paths.ts"; import * as fs from "@std/fs"; import * as path from "@std/path"; import { @@ -17,7 +17,7 @@ import { isFileModified } from "~/vt/lib/utils/misc.ts"; /** * Parameters for scanning a directory and determining the status of files compared to the Val Town project. */ -export interface StatusParams { +interface StatusParams { /** The directory to scan for changes. */ targetDir: string; /** The Val Town project ID. */ @@ -38,7 +38,7 @@ export interface StatusParams { * @param params Options for status operation. * @returns Promise that resolves to a FileState object containing categorized files. */ -export async function status(params: StatusParams): Promise { +async function status(params: StatusParams): Promise { const { targetDir, projectId, @@ -222,3 +222,6 @@ async function getLocalFiles({ const results = await Promise.all(filePromises); return results.filter((item): item is ItemInfo => item !== null); } + +export { status }; +export type { StatusParams }; diff --git a/src/vt/vt/VTClient.ts b/src/vt/vt/VTClient.ts index 09c592a8..8e6d8645 100644 --- a/src/vt/vt/VTClient.ts +++ b/src/vt/vt/VTClient.ts @@ -1,8 +1,8 @@ -import { clone } from "~/vt/lib/clone.ts"; +import { clone } from "~/vt/lib/vals/clone.ts"; import { debounce, delay } from "@std/async"; import VTMeta from "~/vt/vt/VTMeta.ts"; -import { pull } from "~/vt/lib/pull.ts"; -import { push } from "~/vt/lib/push.ts"; +import { pull } from "~/vt/lib/vals/pull.ts"; +import { push } from "~/vt/lib/vals/push.ts"; import { join, relative } from "@std/path"; import { type BaseCheckoutParams, @@ -10,7 +10,7 @@ import { checkout, type CheckoutResult, type ForkCheckoutParams, -} from "~/vt/lib/checkout.ts"; +} from "~/vt/lib/vals/checkout.ts"; import sdk, { branchNameToBranch, getCurrentUser, @@ -22,14 +22,14 @@ import { FIRST_VERSION_NUMBER, META_FOLDER_NAME, } from "~/consts.ts"; -import { status } from "~/vt/lib/status.ts"; +import { status } from "~/vt/lib/vals/status.ts"; import { exists } from "@std/fs"; import ValTown from "@valtown/sdk"; import { dirIsEmpty } from "~/utils.ts"; import VTConfig from "~/vt/VTConfig.ts"; -import { remix } from "~/vt/lib/remix.ts"; +import { remix } from "~/vt/lib/vals/remix.ts"; import type { ProjectPrivacy } from "~/types.ts"; -import { create } from "~/vt/lib/create.ts"; +import { create } from "~/vt/lib/vals/create.ts"; import type { ItemStatusManager } from "~/vt/lib/utils/ItemStatusManager.ts"; import { parseProjectUri } from "~/cmd/parsing.ts"; diff --git a/vt.ts b/vt.ts old mode 100755 new mode 100644 index b3a38704..7e102749 --- a/vt.ts +++ b/vt.ts @@ -1,4 +1,3 @@ -#!/usr/bin/env -S deno run --allow-read --allow-write --allow-env --allow-net --allow-sys --allow-run import { ensureGlobalVtConfig, globalConfig } from "~/vt/VTConfig.ts"; import { onboardFlow } from "~/cmd/flows/onboard.ts"; import { API_KEY_KEY } from "~/consts.ts"; @@ -55,7 +54,7 @@ async function startVt() { await vt.parse(Deno.args); } -if (import.meta.main) { +export async function launch() { await ensureValidApiKey(); await startVt(); } From 6ddee17b19bcc2162cd37ac3a1a3d189e2ffe4b2 Mon Sep 17 00:00:00 2001 From: Wolf Mermelstein Date: Fri, 2 May 2025 19:40:58 -0400 Subject: [PATCH 2/5] Reorganize files --- .github/workflows/docs.yaml | 37 ++-- deno.lock | 248 +++++++++++++++++++++++++- mod.ts | 1 + src/cmd/lib/branch.ts | 2 +- src/cmd/lib/browse.ts | 2 +- src/cmd/lib/checkout.ts | 2 +- src/cmd/lib/clone.ts | 2 +- src/cmd/lib/config.ts | 2 +- src/cmd/lib/create.ts | 2 +- src/cmd/lib/delete.ts | 2 +- src/cmd/lib/list.ts | 2 +- src/cmd/lib/push.ts | 2 +- src/cmd/lib/remix.ts | 2 +- src/cmd/lib/status.ts | 2 +- src/cmd/lib/watch.ts | 2 +- src/cmd/tests/branch_test.ts | 2 +- src/cmd/tests/checkout_test.ts | 2 +- src/cmd/tests/clone_test.ts | 2 +- src/cmd/tests/create_test.ts | 4 +- src/cmd/tests/delete_test.ts | 2 +- src/cmd/tests/pull_test.ts | 2 +- src/cmd/tests/push_test.ts | 2 +- src/cmd/tests/remix_test.ts | 2 +- src/cmd/tests/status_test.ts | 2 +- src/cmd/tests/utils.ts | 2 +- src/cmd/tests/watch_test.ts | 2 +- src/vt/lib/mod.ts | 5 +- src/vt/lib/tests/checkout_test.ts | 2 +- src/vt/lib/tests/clone_test.ts | 2 +- src/vt/lib/tests/pull_test.ts | 2 +- src/vt/lib/tests/push_test.ts | 2 +- src/vt/lib/tests/remix_test.ts | 2 +- src/vt/lib/tests/status_test.ts | 2 +- src/vt/lib/tests/utils.ts | 5 +- src/vt/lib/utils/ItemStatusManager.ts | 2 +- src/vt/lib/utils/paths.ts | 2 +- src/vt/lib/vals/checkout.ts | 4 +- src/vt/lib/vals/clone.ts | 5 +- src/vt/lib/vals/create.ts | 2 +- src/vt/lib/vals/pull.ts | 2 +- src/vt/lib/vals/push.ts | 2 +- src/vt/lib/vals/remix.ts | 2 +- src/vt/lib/vals/status.ts | 2 +- src/vt/vt/VTClient.ts | 4 +- src/vt/vt/utils.ts | 2 +- src/utils.ts => utils/misc.ts | 0 utils/mod.ts | 2 + {src => utils}/sdk.ts | 0 48 files changed, 330 insertions(+), 57 deletions(-) rename src/utils.ts => utils/misc.ts (100%) create mode 100644 utils/mod.ts rename {src => utils}/sdk.ts (100%) diff --git a/.github/workflows/docs.yaml b/.github/workflows/docs.yaml index 8949c8c8..98e38474 100644 --- a/.github/workflows/docs.yaml +++ b/.github/workflows/docs.yaml @@ -1,28 +1,45 @@ -Docs +name: Docs on: push: branches: - - '*' + - "*" jobs: build: runs-on: ubuntu-latest steps: - - name: Check out the code - uses: actions/checkout@v2 - - name: Set up Deno uses: denoland/setup-deno@v1 with: - deno-version: '2.x' + deno-version: "2.x" + + - name: Check out the code + uses: actions/checkout@v2 - name: Generate documentation run: deno task doc - - name: Deploy to GitHub Pages - uses: peaceiris/actions-gh-pages@vr + - name: Upload static files as artifact + id: deployment + uses: actions/upload-pages-artifact@v3 with: - github_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: ./docs \ No newline at end of file + path: docs/ + + deploy: + needs: build + + permissions: + pages: write + id-token: write + + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + + runs-on: ubuntu-latest + steps: + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v4 diff --git a/deno.lock b/deno.lock index 9548a672..0e72c0ad 100644 --- a/deno.lock +++ b/deno.lock @@ -11,35 +11,54 @@ "jsr:@cliffy/keycode@1.0.0-rc.7": "1.0.0-rc.7", "jsr:@cliffy/prompt@^1.0.0-rc.7": "1.0.0-rc.7", "jsr:@cliffy/table@1.0.0-rc.7": "1.0.0-rc.7", + "jsr:@david/code-block-writer@^13.0.2": "13.0.3", "jsr:@deno-library/logger@^1.1.9": "1.1.9", + "jsr:@deno/cache-dir@~0.10.3": "0.10.3", + "jsr:@deno/dnt@*": "0.41.3", "jsr:@jonasschiano/kia@0.0.120": "0.0.120", + "jsr:@std/assert@0.223": "0.223.0", + "jsr:@std/assert@0.226": "0.226.0", "jsr:@std/assert@1": "1.0.12", "jsr:@std/assert@~1.0.6": "1.0.12", "jsr:@std/async@^1.0.11": "1.0.12", + "jsr:@std/bytes@0.223": "0.223.0", "jsr:@std/bytes@^1.0.5": "1.0.5", "jsr:@std/cache@0.2": "0.2.0", "jsr:@std/collections@^1.0.10": "1.0.10", "jsr:@std/dotenv@~0.225.3": "0.225.3", "jsr:@std/encoding@^1.0.7": "1.0.9", "jsr:@std/encoding@~1.0.5": "1.0.9", + "jsr:@std/fmt@0.223": "0.223.0", + "jsr:@std/fmt@1": "1.0.6", "jsr:@std/fmt@1.0.3": "1.0.3", "jsr:@std/fmt@1.0.5": "1.0.5", "jsr:@std/fmt@~1.0.2": "1.0.6", + "jsr:@std/fs@0.223": "0.223.0", + "jsr:@std/fs@1": "1.0.16", "jsr:@std/fs@^1.0.13": "1.0.16", "jsr:@std/fs@^1.0.6": "1.0.16", + "jsr:@std/fs@~0.229.3": "0.229.3", "jsr:@std/internal@^1.0.6": "1.0.6", + "jsr:@std/io@0.223": "0.223.0", "jsr:@std/io@~0.224.9": "0.224.9", "jsr:@std/io@~0.225.2": "0.225.2", + "jsr:@std/path@0.223": "0.223.0", + "jsr:@std/path@1": "1.0.8", + "jsr:@std/path@1.0.0-rc.1": "1.0.0-rc.1", "jsr:@std/path@^1.0.8": "1.0.8", + "jsr:@std/path@~0.225.2": "0.225.2", "jsr:@std/path@~1.0.6": "1.0.8", "jsr:@std/random@0.1": "0.1.0", "jsr:@std/text@^1.0.12": "1.0.12", "jsr:@std/text@~1.0.7": "1.0.12", "jsr:@std/yaml@^1.0.5": "1.0.5", + "jsr:@ts-morph/bootstrap@0.24": "0.24.0", + "jsr:@ts-morph/common@0.24": "0.24.0", "jsr:@valtown/sdk@0.38": "0.38.2", "npm:@types/node@*": "22.12.0", "npm:emphasize@7": "7.0.0", "npm:highlight.js@^11.11.1": "11.11.1", + "npm:jsdoc@*": "4.0.4_@types+markdown-it@14.1.2_markdown-it@14.1.0", "npm:open@^10.1.0": "10.1.0", "npm:strip-ansi@^7.1.0": "7.1.0", "npm:word-wrap@^1.2.5": "1.2.5", @@ -107,6 +126,9 @@ "jsr:@std/fmt@~1.0.2" ] }, + "@david/code-block-writer@13.0.3": { + "integrity": "f98c77d320f5957899a61bfb7a9bead7c6d83ad1515daee92dbacc861e13bb7f" + }, "@deno-library/logger@1.1.9": { "integrity": "f7d7347b3bdf85dd3692b501bb27b11d685c53efd90a07bc6a4d6edd01f8511b", "dependencies": [ @@ -114,6 +136,26 @@ "jsr:@std/fs@^1.0.6" ] }, + "@deno/cache-dir@0.10.3": { + "integrity": "eb022f84ecc49c91d9d98131c6e6b118ff63a29e343624d058646b9d50404776", + "dependencies": [ + "jsr:@std/fmt@0.223", + "jsr:@std/fs@0.223", + "jsr:@std/io@0.223", + "jsr:@std/path@0.223" + ] + }, + "@deno/dnt@0.41.3": { + "integrity": "b2ef2c8a5111eef86cb5bfcae103d6a2938e8e649e2461634a7befb7fc59d6d2", + "dependencies": [ + "jsr:@david/code-block-writer", + "jsr:@deno/cache-dir", + "jsr:@std/fmt@1", + "jsr:@std/fs@1", + "jsr:@std/path@1", + "jsr:@ts-morph/bootstrap" + ] + }, "@jonasschiano/kia@0.0.120": { "integrity": "6b88a98a10788ada17bde6accae2d807cabc4a610eff86446f7c7c05c8429309", "dependencies": [ @@ -121,6 +163,12 @@ "jsr:@std/io@~0.225.2" ] }, + "@std/assert@0.223.0": { + "integrity": "eb8d6d879d76e1cc431205bd346ed4d88dc051c6366365b1af47034b0670be24" + }, + "@std/assert@0.226.0": { + "integrity": "0dfb5f7c7723c18cec118e080fec76ce15b4c31154b15ad2bd74822603ef75b3" + }, "@std/assert@1.0.12": { "integrity": "08009f0926dda9cbd8bef3a35d3b6a4b964b0ab5c3e140a4e0351fbf34af5b9a", "dependencies": [ @@ -130,6 +178,9 @@ "@std/async@1.0.12": { "integrity": "d1bfcec459e8012846fe4e38dfc4241ab23240ecda3d8d6dfcf6d81a632e803d" }, + "@std/bytes@0.223.0": { + "integrity": "84b75052cd8680942c397c2631318772b295019098f40aac5c36cead4cba51a8" + }, "@std/bytes@1.0.5": { "integrity": "4465dd739d7963d964c809202ebea6d5c6b8e3829ef25c6a224290fbb8a1021e" }, @@ -145,6 +196,9 @@ "@std/encoding@1.0.9": { "integrity": "025b8f18eb1749bc30d1353bf48b77d1eb5e35610220fa226f5a046b9240c5d7" }, + "@std/fmt@0.223.0": { + "integrity": "6deb37794127dfc7d7bded2586b9fc6f5d50e62a8134846608baf71ffc1a5208" + }, "@std/fmt@1.0.3": { "integrity": "97765c16aa32245ff4e2204ecf7d8562496a3cb8592340a80e7e554e0bb9149f" }, @@ -154,6 +208,15 @@ "@std/fmt@1.0.6": { "integrity": "a2c56a69a2369876ddb3ad6a500bb6501b5bad47bb3ea16bfb0c18974d2661fc" }, + "@std/fs@0.223.0": { + "integrity": "3b4b0550b2c524cbaaa5a9170c90e96cbb7354e837ad1bdaf15fc9df1ae9c31c" + }, + "@std/fs@0.229.3": { + "integrity": "783bca21f24da92e04c3893c9e79653227ab016c48e96b3078377ebd5222e6eb", + "dependencies": [ + "jsr:@std/path@1.0.0-rc.1" + ] + }, "@std/fs@1.0.16": { "integrity": "81878f62b6eeda0bf546197fc3daa5327c132fee1273f6113f940784a468b036", "dependencies": [ @@ -163,15 +226,37 @@ "@std/internal@1.0.6": { "integrity": "9533b128f230f73bd209408bb07a4b12f8d4255ab2a4d22a1fd6d87304aca9a4" }, + "@std/io@0.223.0": { + "integrity": "2d8c3c2ab3a515619b90da2c6ff5ea7b75a94383259ef4d02116b228393f84f1", + "dependencies": [ + "jsr:@std/assert@0.223", + "jsr:@std/bytes@0.223" + ] + }, "@std/io@0.224.9": { "integrity": "4414664b6926f665102e73c969cfda06d2c4c59bd5d0c603fd4f1b1c840d6ee3" }, "@std/io@0.225.2": { "integrity": "3c740cd4ee4c082e6cfc86458f47e2ab7cb353dc6234d5e9b1f91a2de5f4d6c7", "dependencies": [ - "jsr:@std/bytes" + "jsr:@std/bytes@^1.0.5" ] }, + "@std/path@0.223.0": { + "integrity": "593963402d7e6597f5a6e620931661053572c982fc014000459edc1f93cc3989", + "dependencies": [ + "jsr:@std/assert@0.223" + ] + }, + "@std/path@0.225.2": { + "integrity": "0f2db41d36b50ef048dcb0399aac720a5348638dd3cb5bf80685bf2a745aa506", + "dependencies": [ + "jsr:@std/assert@0.226" + ] + }, + "@std/path@1.0.0-rc.1": { + "integrity": "b8c00ae2f19106a6bb7cbf1ab9be52aa70de1605daeb2dbdc4f87a7cbaf10ff6" + }, "@std/path@1.0.8": { "integrity": "548fa456bb6a04d3c1a1e7477986b6cffbce95102d0bb447c67c4ee70e0364be" }, @@ -184,6 +269,19 @@ "@std/yaml@1.0.5": { "integrity": "71ba3d334305ee2149391931508b2c293a8490f94a337eef3a09cade1a2a2742" }, + "@ts-morph/bootstrap@0.24.0": { + "integrity": "a826a2ef7fa8a7c3f1042df2c034d20744d94da2ee32bf29275bcd4dffd3c060", + "dependencies": [ + "jsr:@ts-morph/common" + ] + }, + "@ts-morph/common@0.24.0": { + "integrity": "12b625b8e562446ba658cdbe9ad77774b4bd96b992ae8bd34c60dbf24d06c1f3", + "dependencies": [ + "jsr:@std/fs@~0.229.3", + "jsr:@std/path@~0.225.2" + ] + }, "@valtown/sdk@0.38.2": { "integrity": "39c5c04408a86a611a0bc6699388f9b60534dbc44b21b79aae599b2817677021" }, @@ -192,12 +290,50 @@ } }, "npm": { + "@babel/helper-string-parser@7.25.9": { + "integrity": "sha512-4A/SCr/2KLd5jrtOMFzaKjVtAei3+2r/NChoBNoZ3EyP/+GlhoaEGoWOZUmFmoITP7zOJyHIMm+DYRd8o3PvHA==" + }, + "@babel/helper-validator-identifier@7.25.9": { + "integrity": "sha512-Ed61U6XJc3CVRfkERJWDz4dJwKe7iLmmJsbOGu9wSloNSFttHV0I8g6UAgb7qnK5ly5bGLPd4oXZlxCdANBOWQ==" + }, + "@babel/parser@7.27.0": { + "integrity": "sha512-iaepho73/2Pz7w2eMS0Q5f83+0RKI7i4xmiYeBmDzfRVbQtTOG7Ts0S4HzJVsTMGI9keU8rNfuZr8DKfSt7Yyg==", + "dependencies": [ + "@babel/types" + ] + }, + "@babel/types@7.27.0": { + "integrity": "sha512-H45s8fVLYjbhFH62dIJ3WtmJ6RSPt/3DRO0ZcT2SUiYiQyz3BLVb9ADEnLl91m74aQPS3AzzeajZHYOalWe3bg==", + "dependencies": [ + "@babel/helper-string-parser", + "@babel/helper-validator-identifier" + ] + }, + "@jsdoc/salty@0.2.9": { + "integrity": "sha512-yYxMVH7Dqw6nO0d5NIV8OQWnitU8k6vXH8NtgqAfIa/IUqRMxRv/NUJJ08VEKbAakwxlgBl5PJdrU0dMPStsnw==", + "dependencies": [ + "lodash" + ] + }, "@types/hast@3.0.4": { "integrity": "sha512-WPs+bbQw5aCj+x6laNGWLH3wviHtoCv/P3+otBhbOhJgG8qtpdAMlTCxLtsTWA7LH1Oh/bFCHsBn0TPS5m30EQ==", "dependencies": [ "@types/unist" ] }, + "@types/linkify-it@5.0.0": { + "integrity": "sha512-sVDA58zAw4eWAffKOaQH5/5j3XeayukzDk+ewSsnv3p4yJEZHCCzMDiZM8e0OUrRvmpGZ85jf4yDHkHsgBNr9Q==" + }, + "@types/markdown-it@14.1.2": { + "integrity": "sha512-promo4eFwuiW+TfGxhi+0x3czqTYJkG8qB17ZUJiVF10Xm7NLVRSLUsfRTU/6h1e24VvRnXCx+hG7li58lkzog==", + "dependencies": [ + "@types/linkify-it", + "@types/mdurl" + ] + }, + "@types/mdurl@2.0.0": { + "integrity": "sha512-RGdgjQUZba5p6QEFAVx2OGb8rQDL/cPRG7GiedRzMcJ1tYnUANBncjbSB1NRGwbvjcPeikRABz2nshyPk1bhWg==" + }, "@types/node@22.12.0": { "integrity": "sha512-Fll2FZ1riMjNmlmJOdAyY5pUbkftXslB5DgEzlIuNaiWhXd00FhWxVC/r4yV/4wBb9JfImTu+jiSvXTkJ7F/gA==", "dependencies": [ @@ -210,12 +346,24 @@ "ansi-regex@6.1.0": { "integrity": "sha512-7HSX4QQb4CspciLpVFwyRe79O3xsIZDDLER21kERQ71oaPodF8jL725AgJMFAYbooIqolJoRLuM81SpeUkpkvA==" }, + "argparse@2.0.1": { + "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==" + }, + "bluebird@3.7.2": { + "integrity": "sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg==" + }, "bundle-name@4.1.0": { "integrity": "sha512-tjwM5exMg6BGRI+kNmTntNsvdZS1X8BFYS6tnJ2hdH0kVxM6/eVZ2xy+FqStSWvYmtfFMDLIxurorHwDKfDz5Q==", "dependencies": [ "run-applescript" ] }, + "catharsis@0.9.0": { + "integrity": "sha512-prMTQVpcns/tzFgFVkVp6ak6RykZyWb3gu8ckUpd6YkTlacOd3DXGJjIpD4Q6zJirizvaiAjSSHlOsA+6sNh2A==", + "dependencies": [ + "lodash" + ] + }, "chalk@5.4.1": { "integrity": "sha512-zgVZuo2WcZgfUEmsn6eO3kINexW8RAE4maiQ8QNs8CtpPCSyMiYsULR3HQYkm3w8FIA3SberyMJMSldGsW+U3w==" }, @@ -250,6 +398,15 @@ "lowlight" ] }, + "entities@4.5.0": { + "integrity": "sha512-V0hjH4dGPh9Ao5p0MoRY6BVqtwCjhz6vI5LT8AJ55H+4g9/4vbHx1I54fS0XuclLhDHArPQCiMjDxjaL8fPxhw==" + }, + "escape-string-regexp@2.0.0": { + "integrity": "sha512-UpzcLCXolUWcNu5HtVMHYdXJjArjsF9C0aNnquZYY4uW/Vu0miy5YoWvbV345HauVvcAUnpRuhMMcqTcGOY2+w==" + }, + "graceful-fs@4.2.11": { + "integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==" + }, "highlight.js@11.11.1": { "integrity": "sha512-Xwwo44whKBVCYoliBQwaPvtd/2tYFkRQtXDWj1nackaV2JPXx3L0+Jvd8/qCJ2p+ML0/XVkJ2q+Mr+UVdpJK5w==" }, @@ -271,6 +428,47 @@ "is-inside-container" ] }, + "js2xmlparser@4.0.2": { + "integrity": "sha512-6n4D8gLlLf1n5mNLQPRfViYzu9RATblzPEtm1SthMX1Pjao0r9YI9nw7ZIfRxQMERS87mcswrg+r/OYrPRX6jA==", + "dependencies": [ + "xmlcreate" + ] + }, + "jsdoc@4.0.4_@types+markdown-it@14.1.2_markdown-it@14.1.0": { + "integrity": "sha512-zeFezwyXeG4syyYHbvh1A967IAqq/67yXtXvuL5wnqCkFZe8I0vKfm+EO+YEvLguo6w9CDUbrAXVtJSHh2E8rw==", + "dependencies": [ + "@babel/parser", + "@jsdoc/salty", + "@types/markdown-it", + "bluebird", + "catharsis", + "escape-string-regexp", + "js2xmlparser", + "klaw", + "markdown-it", + "markdown-it-anchor", + "marked", + "mkdirp", + "requizzle", + "strip-json-comments", + "underscore" + ] + }, + "klaw@3.0.0": { + "integrity": "sha512-0Fo5oir+O9jnXu5EefYbVK+mHMBeEVEy2cmctR1O1NECcCkPRreJKrS6Qt/j3KC2C148Dfo9i3pCmCMsdqGr0g==", + "dependencies": [ + "graceful-fs" + ] + }, + "linkify-it@5.0.0": { + "integrity": "sha512-5aHCbzQRADcdP+ATqnDuhhJ/MRIqDkZX5pyjFHRRysS8vZ5AbqGEoFIb6pYHPZ+L/OC2Lc+xT8uHVVR5CAK/wQ==", + "dependencies": [ + "uc.micro" + ] + }, + "lodash@4.17.21": { + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" + }, "lowlight@3.1.0": { "integrity": "sha512-CEbNVoSikAxwDMDPjXlqlFYiZLkDJHwyGu/MfOsJnF3d7f3tds5J3z8s/l9TMXhzfsJCCJEAsD78842mwmg0PQ==", "dependencies": [ @@ -279,6 +477,33 @@ "highlight.js@11.9.0" ] }, + "markdown-it-anchor@8.6.7_@types+markdown-it@14.1.2_markdown-it@14.1.0": { + "integrity": "sha512-FlCHFwNnutLgVTflOYHPW2pPcl2AACqVzExlkGQNsi4CJgqOHN7YTgDd4LuhgN1BFO3TS0vLAruV1Td6dwWPJA==", + "dependencies": [ + "@types/markdown-it", + "markdown-it" + ] + }, + "markdown-it@14.1.0": { + "integrity": "sha512-a54IwgWPaeBCAAsv13YgmALOF1elABB08FxO9i+r4VFk5Vl4pKokRPeX8u5TCgSsPi6ec1otfLjdOpVcgbpshg==", + "dependencies": [ + "argparse", + "entities", + "linkify-it", + "mdurl", + "punycode.js", + "uc.micro" + ] + }, + "marked@4.3.0": { + "integrity": "sha512-PRsaiG84bK+AMvxziE/lCFss8juXjNaWzVbN5tXAm4XjeaS9NAHhop+PjQxz2A9h8Q4M/xGmzP8vqNwy6JeK0A==" + }, + "mdurl@2.0.0": { + "integrity": "sha512-Lf+9+2r+Tdp5wXDXC4PcIBjTDtq4UKjCPMQhKIuzpJNW0b96kVqSwW0bT7FhRSfmAiFYgP+SCRvdrDozfh0U5w==" + }, + "mkdirp@1.0.4": { + "integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==" + }, "open@10.1.0": { "integrity": "sha512-mnkeQ1qP5Ue2wd+aivTD3NHd/lZ96Lu0jgf0pwktLPtx6cTZiH7tyeGRRHs0zX0rbrahXPnXlUnbeXyaBBuIaw==", "dependencies": [ @@ -288,6 +513,15 @@ "is-wsl" ] }, + "punycode.js@2.3.1": { + "integrity": "sha512-uxFIHU0YlHYhDQtV4R9J6a52SLx28BCjT+4ieh7IGbgwVJWO+km431c4yRlREUAsAmt/uMjQUyQHNEPf0M39CA==" + }, + "requizzle@0.2.4": { + "integrity": "sha512-JRrFk1D4OQ4SqovXOgdav+K8EAhSB/LJZqCz8tbX0KObcdeM15Ss59ozWMBWmmINMagCwmqn4ZNryUGpBsl6Jw==", + "dependencies": [ + "lodash" + ] + }, "run-applescript@7.0.0": { "integrity": "sha512-9by4Ij99JUr/MCFBUkDKLWK3G9HVXmabKz9U5MlIAIuvuzkiOicRYs8XJLxX+xahD+mLiiCYDqF9dKAgtzKP1A==" }, @@ -297,12 +531,24 @@ "ansi-regex" ] }, + "strip-json-comments@3.1.1": { + "integrity": "sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==" + }, + "uc.micro@2.1.0": { + "integrity": "sha512-ARDJmphmdvUk6Glw7y9DQ2bFkKBHwQHLi2lsaH6PPmz/Ka9sFOBsBluozhDltWmnv9u/cF6Rt87znRTPV+yp/A==" + }, + "underscore@1.13.7": { + "integrity": "sha512-GMXzWtsc57XAtguZgaQViUOzs0KTkk8ojr3/xAxXLITqf/3EMwxC0inyETfDFjH/Krbhuep0HNbbjI9i/q3F3g==" + }, "undici-types@6.20.0": { "integrity": "sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg==" }, "word-wrap@1.2.5": { "integrity": "sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA==" }, + "xmlcreate@2.0.4": { + "integrity": "sha512-nquOebG4sngPmGPICTS5EnxqhKbCmz5Ox5hsszI2T6U5qdrJizBc+0ilYSEjTSzU0yZcmvppztXe/5Al5fUwdg==" + }, "zod-to-json-schema@3.24.5_zod@3.24.2": { "integrity": "sha512-/AuWwMP+YqiPbsJx5D6TfgRTc4kTLjsh5SOcd4bLsfUg2RcEXrFMJl1DGgdHy2aCfsIA/cr/1JM0xcB2GZji8g==", "dependencies": [ diff --git a/mod.ts b/mod.ts index d0754ba7..2767f53d 100755 --- a/mod.ts +++ b/mod.ts @@ -10,6 +10,7 @@ import { launch } from "./vt.ts"; * that you can reuse much of the internal syncing functionality of `vt`. * * Primary library functions include + * * - {@link checkout} Check out a branch from a Val Town project * - {@link clone} Clone a Val Town project to a local directory * - {@link create} Create a new Val Town project from local files diff --git a/src/cmd/lib/branch.ts b/src/cmd/lib/branch.ts index 24b00384..1fae2410 100644 --- a/src/cmd/lib/branch.ts +++ b/src/cmd/lib/branch.ts @@ -1,5 +1,5 @@ import { Command } from "@cliffy/command"; -import sdk, { branchNameToBranch } from "~/sdk.ts"; +import sdk, { branchNameToBranch } from "../../../utils/sdk.ts"; import { colors } from "@cliffy/ansi/colors"; import { Table } from "@cliffy/table"; import type ValTown from "@valtown/sdk"; diff --git a/src/cmd/lib/browse.ts b/src/cmd/lib/browse.ts index 5f11ce5b..1e13c4ec 100644 --- a/src/cmd/lib/browse.ts +++ b/src/cmd/lib/browse.ts @@ -1,6 +1,6 @@ import { Command } from "@cliffy/command"; import open from "open"; -import sdk from "~/sdk.ts"; +import sdk from "../../../utils/sdk.ts"; import { doWithSpinner } from "~/cmd/utils.ts"; import VTClient from "~/vt/vt/VTClient.ts"; import { findVtRoot } from "~/vt/vt/utils.ts"; diff --git a/src/cmd/lib/checkout.ts b/src/cmd/lib/checkout.ts index 43a8b87a..cf07f5a9 100644 --- a/src/cmd/lib/checkout.ts +++ b/src/cmd/lib/checkout.ts @@ -6,7 +6,7 @@ import { findVtRoot } from "~/vt/vt/utils.ts"; import { colors } from "@cliffy/ansi/colors"; import { Confirm } from "@cliffy/prompt"; import { tty } from "@cliffy/ansi/tty"; -import sdk, { getCurrentUser } from "~/sdk.ts"; +import sdk, { getCurrentUser } from "../../../utils/sdk.ts"; import { displayFileStateChanges } from "~/cmd/lib/utils/displayFileStatus.ts"; import { noChangesDryRunMsg } from "~/cmd/lib/utils/messages.ts"; diff --git a/src/cmd/lib/clone.ts b/src/cmd/lib/clone.ts index 635e7078..873a62a9 100644 --- a/src/cmd/lib/clone.ts +++ b/src/cmd/lib/clone.ts @@ -1,7 +1,7 @@ import { Command } from "@cliffy/command"; import { Input } from "@cliffy/prompt/input"; import { colors } from "@cliffy/ansi/colors"; -import sdk, { getCurrentUser } from "~/sdk.ts"; +import sdk, { getCurrentUser } from "../../../utils/sdk.ts"; import VTClient from "~/vt/vt/VTClient.ts"; import { relative } from "@std/path"; import { doWithSpinner, getClonePath } from "~/cmd/utils.ts"; diff --git a/src/cmd/lib/config.ts b/src/cmd/lib/config.ts index 8f0a354f..e80187a3 100644 --- a/src/cmd/lib/config.ts +++ b/src/cmd/lib/config.ts @@ -2,7 +2,7 @@ import { Command } from "@cliffy/command"; import VTConfig from "~/vt/VTConfig.ts"; import { findVtRoot } from "~/vt/vt/utils.ts"; import { doWithSpinner } from "~/cmd/utils.ts"; -import { getNestedProperty, setNestedProperty } from "~/utils.ts"; +import { getNestedProperty, setNestedProperty } from "../../../utils/misc.ts"; import { stringify as stringifyYaml } from "@std/yaml"; import { VTConfigSchema } from "~/vt/vt/schemas.ts"; import { zodToJsonSchema } from "zod-to-json-schema"; diff --git a/src/cmd/lib/create.ts b/src/cmd/lib/create.ts index a34b1bb1..3a055cb5 100644 --- a/src/cmd/lib/create.ts +++ b/src/cmd/lib/create.ts @@ -1,7 +1,7 @@ import { Command } from "@cliffy/command"; import { basename } from "@std/path"; import VTClient from "~/vt/vt/VTClient.ts"; -import { getCurrentUser } from "~/sdk.ts"; +import { getCurrentUser } from "../../../utils/sdk.ts"; import { APIError } from "@valtown/sdk"; import { doWithSpinner, getClonePath } from "~/cmd/utils.ts"; import { ensureAddEditorFiles } from "~/cmd/lib/utils/messages.ts"; diff --git a/src/cmd/lib/delete.ts b/src/cmd/lib/delete.ts index d5ab316f..78c8f7c4 100644 --- a/src/cmd/lib/delete.ts +++ b/src/cmd/lib/delete.ts @@ -2,7 +2,7 @@ import { Command } from "@cliffy/command"; import VTClient from "~/vt/vt/VTClient.ts"; import { doWithSpinner } from "~/cmd/utils.ts"; import { Confirm } from "@cliffy/prompt"; -import sdk from "~/sdk.ts"; +import sdk from "../../../utils/sdk.ts"; import { findVtRoot } from "~/vt/vt/utils.ts"; import { colors } from "@cliffy/ansi/colors"; diff --git a/src/cmd/lib/list.ts b/src/cmd/lib/list.ts index 8a9cb5a2..3cdaca78 100644 --- a/src/cmd/lib/list.ts +++ b/src/cmd/lib/list.ts @@ -1,7 +1,7 @@ import { Command } from "@cliffy/command"; import { colors } from "@cliffy/ansi/colors"; import { Table } from "@cliffy/table"; -import sdk from "~/sdk.ts"; +import sdk from "../../../utils/sdk.ts"; import { doWithSpinner } from "~/cmd/utils.ts"; export const listCmd = new Command() diff --git a/src/cmd/lib/push.ts b/src/cmd/lib/push.ts index 6ac33c3a..53c25b23 100644 --- a/src/cmd/lib/push.ts +++ b/src/cmd/lib/push.ts @@ -2,7 +2,7 @@ import { Command } from "@cliffy/command"; import { doWithSpinner } from "~/cmd/utils.ts"; import VTClient from "~/vt/vt/VTClient.ts"; import { findVtRoot } from "~/vt/vt/utils.ts"; -import sdk, { getCurrentUser } from "~/sdk.ts"; +import sdk, { getCurrentUser } from "../../../utils/sdk.ts"; import { displayFileStateChanges } from "~/cmd/lib/utils/displayFileStatus.ts"; import { noChangesDryRunMsg } from "~/cmd/lib/utils/messages.ts"; diff --git a/src/cmd/lib/remix.ts b/src/cmd/lib/remix.ts index e49f906c..1a4fec69 100644 --- a/src/cmd/lib/remix.ts +++ b/src/cmd/lib/remix.ts @@ -1,7 +1,7 @@ import { Command } from "@cliffy/command"; import { join } from "@std/path"; import VTClient from "~/vt/vt/VTClient.ts"; -import { getCurrentUser, projectExists } from "~/sdk.ts"; +import { getCurrentUser, projectExists } from "../../../utils/sdk.ts"; import { APIError } from "@valtown/sdk"; import { doWithSpinner } from "~/cmd/utils.ts"; import { parseProjectUri } from "~/cmd/parsing.ts"; diff --git a/src/cmd/lib/status.ts b/src/cmd/lib/status.ts index 025655aa..bb0a0099 100644 --- a/src/cmd/lib/status.ts +++ b/src/cmd/lib/status.ts @@ -1,6 +1,6 @@ import { Command } from "@cliffy/command"; import { colors } from "@cliffy/ansi/colors"; -import sdk from "~/sdk.ts"; +import sdk from "../../../utils/sdk.ts"; import { FIRST_VERSION_NUMBER } from "~/consts.ts"; import { doWithSpinner } from "~/cmd/utils.ts"; import VTClient from "~/vt/vt/VTClient.ts"; diff --git a/src/cmd/lib/watch.ts b/src/cmd/lib/watch.ts index fb75d6a5..a82a836a 100644 --- a/src/cmd/lib/watch.ts +++ b/src/cmd/lib/watch.ts @@ -1,7 +1,7 @@ import { Command } from "@cliffy/command"; import VTClient from "~/vt/vt/VTClient.ts"; import { colors } from "@cliffy/ansi/colors"; -import sdk from "~/sdk.ts"; +import sdk from "../../../utils/sdk.ts"; import { FIRST_VERSION_NUMBER } from "~/consts.ts"; import { doWithSpinner } from "~/cmd/utils.ts"; import { findVtRoot } from "~/vt/vt/utils.ts"; diff --git a/src/cmd/tests/branch_test.ts b/src/cmd/tests/branch_test.ts index 15c9c619..7358b737 100644 --- a/src/cmd/tests/branch_test.ts +++ b/src/cmd/tests/branch_test.ts @@ -1,7 +1,7 @@ import { doWithNewProject } from "~/vt/lib/tests/utils.ts"; import { doWithTempDir } from "~/vt/lib/utils/misc.ts"; import { join } from "@std/path"; -import sdk from "~/sdk.ts"; +import sdk from "../../../utils/sdk.ts"; import { runVtCommand } from "~/cmd/tests/utils.ts"; import { assert, assertEquals, assertStringIncludes } from "@std/assert"; import type ValTown from "@valtown/sdk"; diff --git a/src/cmd/tests/checkout_test.ts b/src/cmd/tests/checkout_test.ts index 467a9f22..4ee3ba88 100644 --- a/src/cmd/tests/checkout_test.ts +++ b/src/cmd/tests/checkout_test.ts @@ -1,7 +1,7 @@ import { doWithNewProject } from "~/vt/lib/tests/utils.ts"; import { doWithTempDir } from "~/vt/lib/utils/misc.ts"; import { join } from "@std/path"; -import sdk from "~/sdk.ts"; +import sdk from "../../../utils/sdk.ts"; import { runVtCommand } from "~/cmd/tests/utils.ts"; import { assert, assertStringIncludes } from "@std/assert"; import { exists } from "@std/fs"; diff --git a/src/cmd/tests/clone_test.ts b/src/cmd/tests/clone_test.ts index ec11d1cf..521a3a1b 100644 --- a/src/cmd/tests/clone_test.ts +++ b/src/cmd/tests/clone_test.ts @@ -5,7 +5,7 @@ import { join } from "@std/path"; import { deadline, delay } from "@std/async"; import { runVtCommand, streamVtCommand } from "~/cmd/tests/utils.ts"; import { doWithTempDir } from "~/vt/lib/utils/misc.ts"; -import sdk, { getCurrentUser, randomProjectName } from "~/sdk.ts"; +import sdk, { getCurrentUser, randomProjectName } from "../../../utils/sdk.ts"; import type { ProjectFileType } from "~/types.ts"; Deno.test({ diff --git a/src/cmd/tests/create_test.ts b/src/cmd/tests/create_test.ts index b8dec029..33c75d4d 100644 --- a/src/cmd/tests/create_test.ts +++ b/src/cmd/tests/create_test.ts @@ -2,9 +2,9 @@ import { assert, assertEquals } from "@std/assert"; import { exists } from "@std/fs"; import { join } from "@std/path"; import type ValTown from "@valtown/sdk"; -import { dirIsEmpty } from "~/utils.ts"; +import { dirIsEmpty } from "../../../utils/misc.ts"; import { doWithTempDir } from "~/vt/lib/utils/misc.ts"; -import sdk, { getCurrentUser, randomProjectName } from "~/sdk.ts"; +import sdk, { getCurrentUser, randomProjectName } from "../../../utils/sdk.ts"; import { runVtCommand } from "~/cmd/tests/utils.ts"; Deno.test({ diff --git a/src/cmd/tests/delete_test.ts b/src/cmd/tests/delete_test.ts index 2e64d8b3..af546205 100644 --- a/src/cmd/tests/delete_test.ts +++ b/src/cmd/tests/delete_test.ts @@ -3,7 +3,7 @@ import { doWithTempDir } from "~/vt/lib/utils/misc.ts"; import { join } from "@std/path"; import { runVtCommand, runVtProc } from "~/cmd/tests/utils.ts"; import { assert, assertStringIncludes } from "@std/assert"; -import { projectExists } from "~/sdk.ts"; +import { projectExists } from "../../../utils/sdk.ts"; import stripAnsi from "strip-ansi"; import { exists } from "@std/fs"; import { META_FOLDER_NAME } from "~/consts.ts"; diff --git a/src/cmd/tests/pull_test.ts b/src/cmd/tests/pull_test.ts index 014e2132..3a86c126 100644 --- a/src/cmd/tests/pull_test.ts +++ b/src/cmd/tests/pull_test.ts @@ -1,7 +1,7 @@ import { doWithNewProject } from "~/vt/lib/tests/utils.ts"; import { doWithTempDir } from "~/vt/lib/utils/misc.ts"; import { join } from "@std/path"; -import sdk from "~/sdk.ts"; +import sdk from "../../../utils/sdk.ts"; import { removeAllEditorFiles, runVtCommand } from "~/cmd/tests/utils.ts"; import { assertStringIncludes } from "@std/assert"; diff --git a/src/cmd/tests/push_test.ts b/src/cmd/tests/push_test.ts index 62670c5f..e128d960 100644 --- a/src/cmd/tests/push_test.ts +++ b/src/cmd/tests/push_test.ts @@ -1,7 +1,7 @@ import { doWithNewProject } from "~/vt/lib/tests/utils.ts"; import { doWithTempDir } from "~/vt/lib/utils/misc.ts"; import { join } from "@std/path"; -import sdk from "~/sdk.ts"; +import sdk from "../../../utils/sdk.ts"; import { runVtCommand } from "~/cmd/tests/utils.ts"; import { assertStringIncludes } from "@std/assert"; diff --git a/src/cmd/tests/remix_test.ts b/src/cmd/tests/remix_test.ts index 04317f9d..5fab0314 100644 --- a/src/cmd/tests/remix_test.ts +++ b/src/cmd/tests/remix_test.ts @@ -1,7 +1,7 @@ import { doWithNewProject } from "~/vt/lib/tests/utils.ts"; import { doWithTempDir } from "~/vt/lib/utils/misc.ts"; import { join } from "@std/path"; -import sdk, { getCurrentUser } from "~/sdk.ts"; +import sdk, { getCurrentUser } from "../../../utils/sdk.ts"; import { runVtCommand } from "~/cmd/tests/utils.ts"; import { assert, assertStringIncludes } from "@std/assert"; import { exists } from "@std/fs"; diff --git a/src/cmd/tests/status_test.ts b/src/cmd/tests/status_test.ts index 0e53bda9..b6e79f90 100644 --- a/src/cmd/tests/status_test.ts +++ b/src/cmd/tests/status_test.ts @@ -1,7 +1,7 @@ import { doWithNewProject } from "~/vt/lib/tests/utils.ts"; import { doWithTempDir } from "~/vt/lib/utils/misc.ts"; import { join } from "@std/path"; -import sdk from "~/sdk.ts"; +import sdk from "../../../utils/sdk.ts"; import { runVtCommand } from "~/cmd/tests/utils.ts"; import { assertStringIncludes } from "@std/assert"; diff --git a/src/cmd/tests/utils.ts b/src/cmd/tests/utils.ts index 353a3be8..9512a79f 100644 --- a/src/cmd/tests/utils.ts +++ b/src/cmd/tests/utils.ts @@ -8,7 +8,7 @@ import sdk, { getCurrentUser, getLatestVersion, listProjectItems, -} from "~/sdk.ts"; +} from "../../../utils/sdk.ts"; import { ENTRYPOINT_NAME } from "~/consts.ts"; import { doWithTempDir } from "~/vt/lib/utils/misc.ts"; diff --git a/src/cmd/tests/watch_test.ts b/src/cmd/tests/watch_test.ts index 034a077d..87c8e536 100644 --- a/src/cmd/tests/watch_test.ts +++ b/src/cmd/tests/watch_test.ts @@ -5,7 +5,7 @@ import { assert } from "@std/assert"; import { exists } from "@std/fs"; import { delay, retry } from "@std/async"; import VTClient from "~/vt/vt/VTClient.ts"; -import { getLatestVersion, listProjectItems } from "~/sdk.ts"; +import { getLatestVersion, listProjectItems } from "../../../utils/sdk.ts"; import { runVtCommand, streamVtCommand } from "~/cmd/tests/utils.ts"; Deno.test({ diff --git a/src/vt/lib/mod.ts b/src/vt/lib/mod.ts index 3c8eaa18..843b03cb 100644 --- a/src/vt/lib/mod.ts +++ b/src/vt/lib/mod.ts @@ -4,8 +4,9 @@ * of Val Town projects. */ -export * from "./vals/mod.ts"; - export type { ItemStatusManager } from "./utils/ItemStatusManager.ts"; export { getProjectItemType } from "./utils/paths.ts"; export type * from "~/types.ts"; + +export * from "./vals/mod.ts"; +export * as utils from "../../../utils/mod.ts"; diff --git a/src/vt/lib/tests/checkout_test.ts b/src/vt/lib/tests/checkout_test.ts index 9c582854..f9be96ca 100644 --- a/src/vt/lib/tests/checkout_test.ts +++ b/src/vt/lib/tests/checkout_test.ts @@ -1,5 +1,5 @@ import { doWithNewProject } from "~/vt/lib/tests/utils.ts"; -import sdk, { branchExists, getLatestVersion } from "~/sdk.ts"; +import sdk, { branchExists, getLatestVersion } from "../../../../utils/sdk.ts"; import { checkout } from "~/vt/lib/vals/checkout.ts"; import { assert, assertEquals } from "@std/assert"; import { join } from "@std/path"; diff --git a/src/vt/lib/tests/clone_test.ts b/src/vt/lib/tests/clone_test.ts index 52c0b472..21d3e8b7 100644 --- a/src/vt/lib/tests/clone_test.ts +++ b/src/vt/lib/tests/clone_test.ts @@ -1,6 +1,6 @@ import { doWithTempDir } from "~/vt/lib/utils/misc.ts"; import { doWithNewProject } from "~/vt/lib/tests/utils.ts"; -import sdk from "~/sdk.ts"; +import sdk from "../../../../utils/sdk.ts"; import { clone } from "~/vt/lib/vals/clone.ts"; import { assertEquals } from "@std/assert"; import { join } from "@std/path"; diff --git a/src/vt/lib/tests/pull_test.ts b/src/vt/lib/tests/pull_test.ts index 31a49963..8e400d25 100644 --- a/src/vt/lib/tests/pull_test.ts +++ b/src/vt/lib/tests/pull_test.ts @@ -1,6 +1,6 @@ import { doWithTempDir } from "~/vt/lib/utils/misc.ts"; import { doWithNewProject } from "~/vt/lib/tests/utils.ts"; -import sdk, { getLatestVersion } from "~/sdk.ts"; +import sdk, { getLatestVersion } from "../../../../utils/sdk.ts"; import { pull } from "~/vt/lib/vals/pull.ts"; import { assert, assertEquals } from "@std/assert"; import { join } from "@std/path"; diff --git a/src/vt/lib/tests/push_test.ts b/src/vt/lib/tests/push_test.ts index 6e158140..559e3ea3 100644 --- a/src/vt/lib/tests/push_test.ts +++ b/src/vt/lib/tests/push_test.ts @@ -3,7 +3,7 @@ import sdk, { getLatestVersion, listProjectItems, projectItemExists, -} from "~/sdk.ts"; +} from "../../../../utils/sdk.ts"; import { push } from "~/vt/lib/vals/push.ts"; import { assert, assertEquals } from "@std/assert"; import { join } from "@std/path"; diff --git a/src/vt/lib/tests/remix_test.ts b/src/vt/lib/tests/remix_test.ts index 29d5a6a5..fb1d0f55 100644 --- a/src/vt/lib/tests/remix_test.ts +++ b/src/vt/lib/tests/remix_test.ts @@ -1,6 +1,6 @@ import { doWithTempDir } from "~/vt/lib/utils/misc.ts"; import { doWithNewProject } from "~/vt/lib/tests/utils.ts"; -import sdk, { getCurrentUser } from "~/sdk.ts"; +import sdk, { getCurrentUser } from "../../../../utils/sdk.ts"; import { assert, assertEquals } from "@std/assert"; import { join } from "@std/path"; import { exists } from "@std/fs"; diff --git a/src/vt/lib/tests/status_test.ts b/src/vt/lib/tests/status_test.ts index de794730..6f7ddfff 100644 --- a/src/vt/lib/tests/status_test.ts +++ b/src/vt/lib/tests/status_test.ts @@ -1,6 +1,6 @@ import { doWithTempDir } from "~/vt/lib/utils/misc.ts"; import { doWithNewProject } from "~/vt/lib/tests/utils.ts"; -import sdk, { getLatestVersion } from "~/sdk.ts"; +import sdk, { getLatestVersion } from "../../../../utils/sdk.ts"; import { assertEquals } from "@std/assert"; import { join } from "@std/path"; import { status } from "~/vt/lib/vals/status.ts"; diff --git a/src/vt/lib/tests/utils.ts b/src/vt/lib/tests/utils.ts index 149bf17c..622f9af4 100644 --- a/src/vt/lib/tests/utils.ts +++ b/src/vt/lib/tests/utils.ts @@ -1,4 +1,7 @@ -import sdk, { branchNameToBranch, randomProjectName } from "~/sdk.ts"; +import sdk, { + branchNameToBranch, + randomProjectName, +} from "../../../../utils/sdk.ts"; export interface ExpectedProjectInode { path: string; diff --git a/src/vt/lib/utils/ItemStatusManager.ts b/src/vt/lib/utils/ItemStatusManager.ts index dcdcf333..7e04430c 100644 --- a/src/vt/lib/utils/ItemStatusManager.ts +++ b/src/vt/lib/utils/ItemStatusManager.ts @@ -8,7 +8,7 @@ import { TYPE_PRIORITY, } from "~/consts.ts"; import { basename } from "@std/path"; -import { hasNullBytes } from "~/utils.ts"; +import { hasNullBytes } from "../../../../utils/misc.ts"; /** * Possible warning states for a project item. diff --git a/src/vt/lib/utils/paths.ts b/src/vt/lib/utils/paths.ts index fb7aa2fb..cca64781 100644 --- a/src/vt/lib/utils/paths.ts +++ b/src/vt/lib/utils/paths.ts @@ -3,7 +3,7 @@ import { FIRST_VERSION_NUMBER, RECENT_VERSION_COUNT, } from "~/consts.ts"; -import { getProjectItem } from "~/sdk.ts"; +import { getProjectItem } from "../../../../utils/sdk.ts"; import { compile as compileGitignore } from "gitignore-parser"; import type { ProjectItemType } from "~/types.ts"; diff --git a/src/vt/lib/vals/checkout.ts b/src/vt/lib/vals/checkout.ts index 71b9c8f7..74694128 100644 --- a/src/vt/lib/vals/checkout.ts +++ b/src/vt/lib/vals/checkout.ts @@ -1,10 +1,10 @@ -import sdk from "~/sdk.ts"; +import sdk from "../../../../utils/sdk.ts"; import type ValTown from "@valtown/sdk"; import { pull } from "~/vt/lib/vals/pull.ts"; import { join, relative } from "@std/path"; import { walk } from "@std/fs"; import { getProjectItemType, shouldIgnore } from "~/vt/lib/utils/paths.ts"; -import { listProjectItems } from "~/sdk.ts"; +import { listProjectItems } from "../../../../utils/sdk.ts"; import { ItemStatusManager } from "~/vt/lib/utils/ItemStatusManager.ts"; import { doAtomically, gracefulRecursiveCopy } from "~/vt/lib/utils/misc.ts"; diff --git a/src/vt/lib/vals/clone.ts b/src/vt/lib/vals/clone.ts index e0722247..91ccbedd 100644 --- a/src/vt/lib/vals/clone.ts +++ b/src/vt/lib/vals/clone.ts @@ -1,4 +1,7 @@ -import sdk, { getLatestVersion, listProjectItems } from "~/sdk.ts"; +import sdk, { + getLatestVersion, + listProjectItems, +} from "../../../../utils/sdk.ts"; import { shouldIgnore } from "~/vt/lib/utils/paths.ts"; import { ensureDir, exists } from "@std/fs"; import { dirname } from "@std/path/dirname"; diff --git a/src/vt/lib/vals/create.ts b/src/vt/lib/vals/create.ts index d68e8d3f..27a23cde 100644 --- a/src/vt/lib/vals/create.ts +++ b/src/vt/lib/vals/create.ts @@ -1,5 +1,5 @@ import { push } from "~/vt/lib/vals/push.ts"; -import sdk, { branchNameToBranch } from "~/sdk.ts"; +import sdk, { branchNameToBranch } from "../../../../utils/sdk.ts"; import type { ProjectPrivacy } from "~/types.ts"; import { DEFAULT_BRANCH_NAME } from "~/consts.ts"; import { ensureDir } from "@std/fs"; diff --git a/src/vt/lib/vals/pull.ts b/src/vt/lib/vals/pull.ts index 3f901649..c390b380 100644 --- a/src/vt/lib/vals/pull.ts +++ b/src/vt/lib/vals/pull.ts @@ -5,7 +5,7 @@ import { branchNameToBranch, getLatestVersion, listProjectItems, -} from "~/sdk.ts"; +} from "../../../../utils/sdk.ts"; import { clone } from "~/vt/lib/vals/clone.ts"; import { doAtomically, gracefulRecursiveCopy } from "~/vt/lib/utils/misc.ts"; import { diff --git a/src/vt/lib/vals/push.ts b/src/vt/lib/vals/push.ts index dbdcff42..0725fd24 100644 --- a/src/vt/lib/vals/push.ts +++ b/src/vt/lib/vals/push.ts @@ -4,7 +4,7 @@ import sdk, { getLatestVersion, getProjectItem, listProjectItems, -} from "~/sdk.ts"; +} from "../../../../utils/sdk.ts"; import { status } from "~/vt/lib/vals/status.ts"; import { basename, dirname, join } from "@std/path"; import { assert } from "@std/assert"; diff --git a/src/vt/lib/vals/remix.ts b/src/vt/lib/vals/remix.ts index c048661b..f3f7f419 100644 --- a/src/vt/lib/vals/remix.ts +++ b/src/vt/lib/vals/remix.ts @@ -4,7 +4,7 @@ import sdk, { branchNameToBranch, getLatestVersion, listProjectItems, -} from "~/sdk.ts"; +} from "../../../../utils/sdk.ts"; import { DEFAULT_BRANCH_NAME, DEFAULT_PROJECT_PRIVACY } from "~/consts.ts"; import type { ProjectPrivacy } from "~/types.ts"; import { ItemStatusManager } from "~/vt/lib/utils/ItemStatusManager.ts"; diff --git a/src/vt/lib/vals/status.ts b/src/vt/lib/vals/status.ts index 80cbedff..4446a6be 100644 --- a/src/vt/lib/vals/status.ts +++ b/src/vt/lib/vals/status.ts @@ -1,4 +1,4 @@ -import sdk, { listProjectItems } from "~/sdk.ts"; +import sdk, { listProjectItems } from "../../../../utils/sdk.ts"; import { getProjectItemType, shouldIgnore } from "~/vt/lib/utils/paths.ts"; import * as fs from "@std/fs"; import * as path from "@std/path"; diff --git a/src/vt/vt/VTClient.ts b/src/vt/vt/VTClient.ts index 8e6d8645..3f7cc802 100644 --- a/src/vt/vt/VTClient.ts +++ b/src/vt/vt/VTClient.ts @@ -15,7 +15,7 @@ import sdk, { branchNameToBranch, getCurrentUser, getLatestVersion, -} from "~/sdk.ts"; +} from "../../../utils/sdk.ts"; import { DEFAULT_BRANCH_NAME, DEFAULT_EDITOR_TEMPLATE, @@ -25,7 +25,7 @@ import { import { status } from "~/vt/lib/vals/status.ts"; import { exists } from "@std/fs"; import ValTown from "@valtown/sdk"; -import { dirIsEmpty } from "~/utils.ts"; +import { dirIsEmpty } from "../../../utils/misc.ts"; import VTConfig from "~/vt/VTConfig.ts"; import { remix } from "~/vt/lib/vals/remix.ts"; import type { ProjectPrivacy } from "~/types.ts"; diff --git a/src/vt/vt/utils.ts b/src/vt/vt/utils.ts index b60b9803..fcb3d12c 100644 --- a/src/vt/vt/utils.ts +++ b/src/vt/vt/utils.ts @@ -1,6 +1,6 @@ import { join } from "@std/path"; import { MAX_WALK_UP_LEVELS } from "~/consts.ts"; -import { findRoot } from "~/utils.ts"; +import { findRoot } from "../../../utils/misc.ts"; /** * Finds the nearest directory containing a .vt folder by climbing up the directory tree diff --git a/src/utils.ts b/utils/misc.ts similarity index 100% rename from src/utils.ts rename to utils/misc.ts diff --git a/utils/mod.ts b/utils/mod.ts new file mode 100644 index 00000000..ec1585dc --- /dev/null +++ b/utils/mod.ts @@ -0,0 +1,2 @@ +export * from "./sdk.ts"; +export * from "./misc.ts"; diff --git a/src/sdk.ts b/utils/sdk.ts similarity index 100% rename from src/sdk.ts rename to utils/sdk.ts From 7853418f951de468382e9071d3e6220b6b1d1d6b Mon Sep 17 00:00:00 2001 From: Wolf Mermelstein Date: Sat, 3 May 2025 00:07:41 -0400 Subject: [PATCH 3/5] Add vt electric to workflow --- .github/workflows/docs.yaml | 29 ++++++----------------------- .gitignore | 3 ++- 2 files changed, 8 insertions(+), 24 deletions(-) diff --git a/.github/workflows/docs.yaml b/.github/workflows/docs.yaml index 98e38474..7289095a 100644 --- a/.github/workflows/docs.yaml +++ b/.github/workflows/docs.yaml @@ -6,7 +6,7 @@ on: - "*" jobs: - build: + publish-docs: runs-on: ubuntu-latest steps: @@ -21,25 +21,8 @@ jobs: - name: Generate documentation run: deno task doc - - name: Upload static files as artifact - id: deployment - uses: actions/upload-pages-artifact@v3 - with: - path: docs/ - - deploy: - needs: build - - permissions: - pages: write - id-token: write - - environment: - name: github-pages - url: ${{ steps.deployment.outputs.page_url }} - - runs-on: ubuntu-latest - steps: - - name: Deploy to GitHub Pages - id: deployment - uses: actions/deploy-pages@v4 + - name: Upload the docs to Val Town Electric + run: cd docs && deno run -A https://esm.town/v/wolf/VTDocs/cli/mod.ts upload + env: + ELECTRIC_ROOT_URL: https://vt-docs.val.run + ELECTRIC_MASTER_BEARER: ${{ secrets.ELECTRIC_MASTER_BEARER }} diff --git a/.gitignore b/.gitignore index c03e4ca0..8459a2d9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ tinker +docs # Created by https://www.toptal.com/developers/gitignore/api/deno # Edit at https://www.toptal.com/developers/gitignore?templates=deno @@ -16,4 +17,4 @@ tinker # End of https://www.toptal.com/developers/gitignore/api/deno -.DS_Store \ No newline at end of file +.DS_Store From e5fcad366c662b29ea2c5f1fc2fda9875dec463f Mon Sep 17 00:00:00 2001 From: Wolf Mermelstein Date: Sat, 3 May 2025 00:30:48 -0400 Subject: [PATCH 4/5] Only run on push to main --- .github/workflows/docs.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docs.yaml b/.github/workflows/docs.yaml index 7289095a..8edc8592 100644 --- a/.github/workflows/docs.yaml +++ b/.github/workflows/docs.yaml @@ -3,7 +3,7 @@ name: Docs on: push: branches: - - "*" + - main jobs: publish-docs: From b07054a981c03cdd3917d0d974d9e9525fb141f8 Mon Sep 17 00:00:00 2001 From: Wolf Mermelstein Date: Mon, 12 May 2025 13:17:43 -0400 Subject: [PATCH 5/5] Add explicit typing --- src/utils/sdk.ts | 62 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 42 insertions(+), 20 deletions(-) diff --git a/src/utils/sdk.ts b/src/utils/sdk.ts index 1f119826..664a0c94 100644 --- a/src/utils/sdk.ts +++ b/src/utils/sdk.ts @@ -120,20 +120,27 @@ export async function valItemExists( * @param options.filePath - The file path to locate * @returns Promise resolving to the file data or undefined if not found */ -export const getValItem = memoize(async ( +export const getValItem: ( valId: string, branchId: string, version: number, filePath: string, -): Promise => { - const valItems = await listValItems(valId, branchId, version); - - for (const filepath of valItems) { - if (filepath.path === filePath) return filepath; - } +) => Promise = memoize( + async ( + valId: string, + branchId: string, + version: number, + filePath: string, + ) => { + const valItems = await listValItems(valId, branchId, version); + + for (const filepath of valItems) { + if (filepath.path === filePath) return filepath; + } - return undefined; -}); + return undefined; + }, +); /** * Lists all file paths in a Val with pagination support. @@ -146,16 +153,22 @@ export const getValItem = memoize(async ( * @param [params.options.recursive] Whether to recursively list files in subdirectories * @returns Promise resolving to a Set of file paths */ -export const listValItems = memoize(async ( +export const listValItems: ( + valId: string, + branchId: string, + version: number, +) => Promise = memoize(async ( valId: string, branchId: string, version: number, -): Promise => { - const files: ValTown.Vals.FileRetrieveResponse[] = []; +) => { + const files: ValTown.Vals.Files.FileRetrieveResponse[] = []; - branchId = branchId || - (await branchNameToBranch(valId, DEFAULT_BRANCH_NAME) + // If branchId is not provided, get the default branch id + if (!branchId) { + branchId = (await branchNameToBranch(valId, DEFAULT_BRANCH_NAME) .then((resp) => resp.id))!; + } for await ( const file of sdk.vals.files.retrieve(valId, { @@ -164,7 +177,9 @@ export const listValItems = memoize(async ( version, recursive: true, }) - ) files.push(file); + ) { + files.push(file); + } return files; }); @@ -172,22 +187,29 @@ export const listValItems = memoize(async ( /** * Get the latest version of a branch. */ -export async function getLatestVersion(valId: string, branchId: string) { +export async function getLatestVersion( + valId: string, + branchId: string, +): Promise { return (await sdk.vals.branches.retrieve(valId, branchId)).version; } /** * Generate a random (valid) Val name. Useful for tests. */ -export function randomValName(label = "") { +export function randomValName(label = ""): string { return `a${crypto.randomUUID().replaceAll("-", "").slice(0, 10)}_${label}`; } /** * Get the owner of the API key used to auth the current ValTown instance. */ -export const getCurrentUser = memoize(async () => { - return await sdk.me.profile.retrieve(); -}); +export const getCurrentUser: () => Promise< + ValTown.Me.Profile.ProfileRetrieveResponse +> = memoize( + async () => { + return await sdk.me.profile.retrieve(); + }, +); export default sdk;