Skip to content

Commit 9ab0813

Browse files
authored
Lots of Bug Fixes (#55)
* Change internal git logic * Rename git to lib * Don't create dir if create fails * Improve error messages * Make linter require 'import type' * Add deno.json and .vtignore automatically by default * Remove useless error handling * Remove encodeURIComponents * Get rid of extra loadGigitnoreRules method * Remove useless checks * Repair git logic * Update push test * Improve test cases * Fix jsdoc message * Add rename test * Update empty dir tests * Fix push logic for files and dirs * Stronger dirty check for checkout * Add initial push * Fix push test * Tick version * Clean up dirty check * Improve type detection * Update watch debounce * Remove old install script * Fix push for api bug * Update deno lock * Modify pagination * Tests passing * Format code * Fix permissions
1 parent 90dbf20 commit 9ab0813

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1766
-1111
lines changed

deno.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@valtown/vt",
33
"description": "The Val Town CLI",
4-
"version": "0.0.5",
4+
"version": "0.0.6",
55
"exports": "./vt.ts",
66
"license": "MIT",
77
"tasks": {
@@ -23,7 +23,7 @@
2323
"@std/encoding": "jsr:@std/encoding@^1.0.7",
2424
"@std/fs": "jsr:@std/fs@^1.0.13",
2525
"@std/path": "jsr:@std/path@^1.0.8",
26-
"@valtown/sdk": "jsr:@valtown/sdk@^0.36.0",
26+
"@valtown/sdk": "jsr:@valtown/sdk@^0.37.0",
2727
"~/": "./src/",
2828
"emphasize": "npm:emphasize@^7.0.0",
2929
"highlight.js": "npm:highlight.js@^11.11.1",
@@ -33,6 +33,7 @@
3333
},
3434
"compilerOptions": {
3535
"noUnusedLocals": true,
36-
"noUnusedParameters": true
36+
"noUnusedParameters": true,
37+
"verbatimModuleSyntax": true
3738
}
3839
}

deno.lock

Lines changed: 5 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

install.ts

Lines changed: 0 additions & 56 deletions
This file was deleted.

src/cmd/git/clone.ts

Lines changed: 0 additions & 73 deletions
This file was deleted.
File renamed without changes.
File renamed without changes.

src/cmd/git/checkout.ts renamed to src/cmd/lib/checkout.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { Command } from "@cliffy/command";
22
import ValTown from "@valtown/sdk";
3-
import { CheckoutResult } from "~/vt/git/checkout.ts";
4-
import { dirtyErrorMsg } from "~/cmd/git/utils.ts";
3+
import type { CheckoutResult } from "~/vt/lib/checkout.ts";
4+
import { dirtyErrorMsg } from "~/cmd/lib/utils.ts";
55
import { doWithSpinner } from "~/cmd/utils.ts";
66
import VTClient from "~/vt/vt/VTClient.ts";
77
import { findVtRoot } from "~/vt/vt/utils.ts";
8+
import { branchIdToBranch } from "~/sdk.ts";
89

910
const toListBranches = "Use \`vt branch\` to list branches.";
1011

@@ -46,9 +47,20 @@ export const checkoutCmd = new Command()
4647
const config = await vt.getMeta().loadConfig();
4748

4849
const statusResult = await vt.status();
49-
// !branch && await vt.isDirty(cwd) means that we only do the isDirty
50-
// check if the branch is not new
51-
if (!force && (!branch && await vt.isDirty({ statusResult }))) {
50+
51+
if (
52+
!force &&
53+
(!branch && existingBranchName &&
54+
(await vt.isDirty({ statusResult }) ||
55+
await vt.isDirty({
56+
statusResult: await vt.status({
57+
branchId: (await branchIdToBranch(
58+
config.projectId,
59+
existingBranchName,
60+
)).id,
61+
}),
62+
})))
63+
) {
5264
throw new Error(dirtyErrorMsg("checkout"));
5365
}
5466

src/cmd/lib/clone.ts

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import { Command } from "@cliffy/command";
2+
import { user } from "~/sdk.ts";
3+
import { ALWAYS_IGNORE_PATTERNS, DEFAULT_BRANCH_NAME } from "~/consts.ts";
4+
import { parseProjectUri } from "~/cmd/parsing.ts";
5+
import VTClient from "~/vt/vt/VTClient.ts";
6+
import { checkDirectory } from "~/utils.ts";
7+
import { relative } from "@std/path";
8+
import * as join from "@std/path/join";
9+
import { doWithSpinner } from "~/cmd/utils.ts";
10+
11+
export const cloneCmd = new Command()
12+
.name("clone")
13+
.description("Clone a val town project")
14+
.arguments("<projectUri:string> [cloneDir:string] [branchName:string]")
15+
.example(
16+
"Clone with username/projectName",
17+
`vt clone username/projectName`,
18+
)
19+
.example(
20+
"Clone into the current directory",
21+
`vt clone username/projectName .`,
22+
)
23+
.example(
24+
"Clone with link",
25+
`vt clone https://www.val.town/x/username/projectName`,
26+
)
27+
.example(
28+
"Clone into a new directory",
29+
`vt clone username/projectName new-directory`,
30+
)
31+
.action((_, projectUri: string, rootPath?: string, branchName?: string) => {
32+
doWithSpinner("Cloning project...", async (spinner) => {
33+
let targetDir = rootPath || Deno.cwd();
34+
35+
const { ownerName, projectName } = parseProjectUri(
36+
projectUri,
37+
user.username!,
38+
);
39+
40+
branchName = branchName || DEFAULT_BRANCH_NAME;
41+
42+
// By default, if the target directory is the current working directory,
43+
// then use the project name as the target directory
44+
if (rootPath === undefined) {
45+
targetDir = join.join(targetDir, projectName);
46+
}
47+
48+
const vt = await VTClient.init({
49+
rootPath: targetDir,
50+
username: ownerName,
51+
projectName,
52+
branchName,
53+
});
54+
55+
// Make sure that the directory is safe to clone into (exists, or gets
56+
// created and then exists, and wasn't nonempty) deno-fmt-ignore
57+
await checkDirectory(targetDir, { gitignoreRules: ALWAYS_IGNORE_PATTERNS, });
58+
59+
await vt.clone(targetDir);
60+
await vt.addEditorFiles();
61+
62+
spinner.succeed(
63+
`Project ${ownerName}/${projectName} cloned to "./${
64+
relative(Deno.cwd(), targetDir)
65+
}"`,
66+
);
67+
});
68+
});

src/cmd/root/create.ts renamed to src/cmd/lib/create.ts

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { Command } from "@cliffy/command";
22
import { basename, join } from "@std/path";
3-
import { checkDirectory } from "~/utils.ts";
4-
import { DEFAULT_IGNORE_PATTERNS } from "~/consts.ts";
53
import VTClient from "~/vt/vt/VTClient.ts";
64
import { user } from "~/sdk.ts";
75
import { APIError } from "@valtown/sdk";
@@ -14,6 +12,7 @@ export const createCmd = new Command()
1412
.option("--public", "Create as public project (default)")
1513
.option("--private", "Create as private project")
1614
.option("--unlisted", "Create as unlisted project")
15+
.option("--no-editor-files", "Skip creating editor configuration files")
1716
.option("-d, --description <desc:string>", "Project description")
1817
.example(
1918
"Start fresh",
@@ -41,7 +40,12 @@ vt push
4140
vt checkout main`,
4241
)
4342
.action((
44-
{ public: isPublic, private: isPrivate, unlisted, description }: {
43+
{
44+
public: isPublic,
45+
private: isPrivate,
46+
unlisted,
47+
description,
48+
}: {
4549
public?: boolean;
4650
private?: boolean;
4751
unlisted?: boolean;
@@ -51,7 +55,10 @@ vt checkout main`,
5155
targetDir?: string,
5256
) => {
5357
doWithSpinner("Creating project...", async (spinner) => {
54-
let rootPath = targetDir || Deno.cwd();
58+
let rootPath: string;
59+
if (!targetDir) {
60+
rootPath = join(Deno.cwd(), projectName);
61+
} else rootPath = targetDir;
5562

5663
// Check for mutually exclusive privacy flags
5764
const privacyFlags =
@@ -65,14 +72,6 @@ vt checkout main`,
6572
// Determine privacy setting (defaults to public)
6673
const privacy = isPrivate ? "private" : unlisted ? "unlisted" : "public";
6774

68-
// If no target directory specified, use project name
69-
if (targetDir === undefined) rootPath = join(rootPath, projectName);
70-
71-
// Make sure directory is safe to create project in
72-
await checkDirectory(rootPath, {
73-
gitignoreRules: DEFAULT_IGNORE_PATTERNS,
74-
});
75-
7675
try {
7776
const vt = await VTClient.create(
7877
rootPath,
@@ -81,9 +80,7 @@ vt checkout main`,
8180
privacy,
8281
description,
8382
);
84-
85-
// Clone the initial project structure
86-
await vt.clone(rootPath);
83+
await vt.addEditorFiles();
8784

8885
spinner.succeed(
8986
`Created ${privacy} project ${projectName} in ./${
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
export { cloneCmd } from "./clone.ts";
2-
export { pullCmd } from "./pull.ts";
3-
export { statusCmd } from "./status.ts";
41
export { branchCmd } from "./branch.ts";
2+
export { browseCmd } from "./browse.ts";
53
export { checkoutCmd } from "./checkout.ts";
4+
export { cloneCmd } from "./clone.ts";
5+
export { createCmd } from "./create.ts";
6+
export { pullCmd } from "./pull.ts";
67
export { pushCmd } from "./push.ts";
8+
export { statusCmd } from "./status.ts";
9+
export { watchCmd } from "./watch.ts";

0 commit comments

Comments
 (0)