Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.4.1

- Fix: Relative project paths are now handled correctly (e.g. `gm-cli ./some/project.yyp` works as intended)

# 1.4.0

- Fix: `gm-cli package` now works correctly on Linux.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"url": "https://github.com/YoYoGames/gm-cli"
},
"type": "module",
"version": "1.4.0",
"version": "1.4.1",
"files": [
"dist",
"NOTICE"
Expand Down
5 changes: 3 additions & 2 deletions src/commands/cache/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { findProjectFile, parseProjectPath } from "~/project";
export const FLAGS = {
project: {
kind: "parsed",
parse: parseProjectPath,
parse: String,
brief: "Path to the project .yyp file",
optional: true,
},
Expand Down Expand Up @@ -79,7 +79,8 @@ export async function setupCache(
if (flags.cacheDir) {
cacheType = { type: "absolute", path: flags.cacheDir };
} else if (flags.project) {
cacheType = { type: "infer", projectDir: ctx.path.dirname(flags.project) };
const projectPath = parseProjectPath(ctx, flags.project);
cacheType = { type: "infer", projectDir: ctx.path.dirname(projectPath) };
} else {
// Try inferring from cwd.
const projectPath = await findProjectFile(ctx, ctx.process.cwd());
Expand Down
3 changes: 1 addition & 2 deletions src/commands/compile/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import { buildCommand } from "@stricli/core";
import { TARGETS, TargetSchema } from "~/target";
import { parseProjectPath } from "~/project";
import { parseToolchainVersion } from "~/toolchain";

export const compileProjectCommand = buildCommand({
Expand All @@ -28,7 +27,7 @@ export const compileProjectCommand = buildCommand({
{
brief: "Path to the project .yyp file",
placeholder: "project",
parse: parseProjectPath,
parse: String,
optional: true,
},
],
Expand Down
11 changes: 8 additions & 3 deletions src/commands/compile/impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,18 @@
*/

import type { Context } from "~/context";
import type { ProjectPath } from "~/project";
import { parseProjectPath } from "~/project";
import { runBuildPipeline, type CommonCliBuildFlags } from "~/build-pipeline";

export default async function (
this: Context,
flags: CommonCliBuildFlags,
project?: ProjectPath,
project?: string,
): Promise<void> {
await runBuildPipeline(this, flags, project, { type: "compile" });
await runBuildPipeline(
this,
flags,
project ? parseProjectPath(this, project) : undefined,
{ type: "compile" },
);
}
3 changes: 1 addition & 2 deletions src/commands/gxgames/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@
*/

import { buildCommand, buildRouteMap } from "@stricli/core";
import { parseProjectPath } from "~/project";

const projectParam = {
brief: "Path to the project .yyp file (defaults to current directory)",
placeholder: "project",
parse: parseProjectPath,
parse: String,
optional: true as const,
};

Expand Down
7 changes: 4 additions & 3 deletions src/commands/gxgames/commands/link-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import * as p from "@clack/prompts";
import type { Context } from "~/context";
import { KnownError } from "~/error";
import type { ProjectPath } from "~/project";
import { parseProjectPath } from "~/project";

import { createAuthManager } from "../auth";
import { apiUserErrorMessage, getApiClient } from "../api";
Expand All @@ -26,11 +26,12 @@ import { LinkStorage } from "../api";
export default async function (
this: Context,
flags: { studioid?: string; gameid?: string },
project?: ProjectPath,
project?: string,
): Promise<void> {
let studioId = flags.studioid;
let gameId = flags.gameid;
const projectDir = project ? this.path.dirname(project) : undefined;
const projectPath = project ? parseProjectPath(this, project) : undefined;
const projectDir = projectPath ? this.path.dirname(projectPath) : undefined;

if (!studioId || !gameId) {
const api = getApiClient(this, createAuthManager(this, projectDir));
Expand Down
7 changes: 4 additions & 3 deletions src/commands/gxgames/commands/meta-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import type { Context } from "~/context";
import { KnownError } from "~/error";
import type { ProjectPath } from "~/project";
import { parseProjectPath } from "~/project";

import { apiUserErrorMessage, LinkStorage } from "../api";
import { createAuthManager } from "../auth";
Expand All @@ -39,9 +39,10 @@ interface MetaFlags {
export default async function (
this: Context,
flags: MetaFlags,
project?: ProjectPath,
project?: string,
): Promise<void> {
const projectDir = project ? this.path.dirname(project) : undefined;
const projectPath = project ? parseProjectPath(this, project) : undefined;
const projectDir = projectPath ? this.path.dirname(projectPath) : undefined;
const link = await new LinkStorage(this, projectDir).read();
const api = getApiClient(this, createAuthManager(this, projectDir));

Expand Down
7 changes: 4 additions & 3 deletions src/commands/gxgames/commands/publish-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import type { Context } from "~/context";
import chalk from "chalk";
import { KnownError } from "~/error";
import type { ProjectPath } from "~/project";
import { parseProjectPath } from "~/project";

import { apiUserErrorMessage, LinkStorage } from "../api";
import { createAuthManager } from "../auth";
Expand All @@ -26,9 +26,10 @@ import { getApiClient } from "../api";
export default async function (
this: Context,
_flags: Record<never, never>,
project?: ProjectPath,
project?: string,
): Promise<void> {
const projectDir = project ? this.path.dirname(project) : undefined;
const projectPath = project ? parseProjectPath(this, project) : undefined;
const projectDir = projectPath ? this.path.dirname(projectPath) : undefined;
const link = await new LinkStorage(this, projectDir).read();
const api = getApiClient(this, createAuthManager(this, projectDir));

Expand Down
7 changes: 4 additions & 3 deletions src/commands/gxgames/commands/upload-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import chalk from "chalk";
import { apiUserErrorMessage, getApiClient } from "../api";
import { createAuthManager } from "../auth";
import { KnownError } from "~/error";
import type { ProjectPath } from "~/project";
import { parseProjectPath } from "~/project";

import { LinkStorage } from "../api";

Expand All @@ -33,9 +33,10 @@ const validateVersion = (v: string | undefined): string | undefined =>
export default async function (
this: Context,
flags: { file: string; version?: string },
project?: ProjectPath,
project?: string,
): Promise<void> {
const projectDir = project ? this.path.dirname(project) : undefined;
const projectPath = project ? parseProjectPath(this, project) : undefined;
const projectDir = projectPath ? this.path.dirname(projectPath) : undefined;
const link = await new LinkStorage(this, projectDir).read();

const api = getApiClient(this, createAuthManager(this, projectDir));
Expand Down
3 changes: 1 addition & 2 deletions src/commands/package/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import { buildCommand } from "@stricli/core";
import { TARGETS, TargetSchema } from "~/target";
import { parseProjectPath } from "~/project";
import { parseToolchainVersion } from "~/toolchain";

export const packageCommand = buildCommand({
Expand All @@ -28,7 +27,7 @@ export const packageCommand = buildCommand({
{
brief: "Path to the project .yyp file",
placeholder: "project",
parse: parseProjectPath,
parse: String,
optional: true,
},
],
Expand Down
17 changes: 11 additions & 6 deletions src/commands/package/impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,21 @@
*/

import type { Context } from "~/context";
import type { ProjectPath } from "~/project";
import { parseProjectPath } from "~/project";
import { runBuildPipeline, type CommonCliBuildFlags } from "~/build-pipeline";

export default async function (
this: Context,
flags: CommonCliBuildFlags & { output?: string },
project?: ProjectPath,
project?: string,
): Promise<void> {
await runBuildPipeline(this, flags, project, {
type: "package",
outputPath: flags.output,
});
await runBuildPipeline(
this,
flags,
project ? parseProjectPath(this, project) : undefined,
{
type: "package",
outputPath: flags.output,
},
);
}
11 changes: 5 additions & 6 deletions src/commands/resourcetool/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/

import { buildCommand, buildRouteMap } from "@stricli/core";
import { parseProjectPath, type ProjectPath } from "~/project";
import type { Context } from "~/context";
import type { CommonFlags } from "./impl";

Expand All @@ -31,7 +30,7 @@ const commonFlags = {
const projectParam = {
brief: "Path to the project .yyp file",
placeholder: "project",
parse: parseProjectPath,
parse: String,
optional: true as const,
};

Expand All @@ -44,7 +43,7 @@ export const resourcetoolCommand = buildRouteMap({
default: async function (
this: Context,
flags: CommonFlags,
project?: ProjectPath,
project?: string,
) {
return run(this, flags, project, { mode: "mcp" });
},
Expand All @@ -64,7 +63,7 @@ export const resourcetoolCommand = buildRouteMap({
this: Context,
flags: CommonFlags,
command: string,
project?: ProjectPath,
project?: string,
) {
return run(this, flags, project, { mode: "command", command });
},
Expand Down Expand Up @@ -93,7 +92,7 @@ export const resourcetoolCommand = buildRouteMap({
default: async function (
this: Context,
flags: CommonFlags,
project?: ProjectPath,
project?: string,
) {
return run(this, flags, project, { mode: "cli" });
},
Expand All @@ -113,7 +112,7 @@ export const resourcetoolCommand = buildRouteMap({
this: Context,
flags: CommonFlags,
file: string,
project?: ProjectPath,
project?: string,
) {
return run(this, flags, project, {
mode: "script",
Expand Down
8 changes: 5 additions & 3 deletions src/commands/resourcetool/impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import { Cache } from "~/cache";
import { type Context } from "~/context";
import { findProjectFile, type ProjectPath } from "~/project";
import { findProjectFile, parseProjectPath } from "~/project";
import {
downloadGmpm,
downloadPackageTool,
Expand All @@ -34,11 +34,13 @@ export interface CommonFlags {
export async function run(
ctx: Context,
flags: CommonFlags,
project: ProjectPath | undefined,
project: string | undefined,
mode: ResourceToolMode,
): Promise<void> {
const cwd = ctx.process.cwd();
const projectPath = project ?? (await findProjectFile(ctx, cwd));
const projectPath = project
? parseProjectPath(ctx, project)
: await findProjectFile(ctx, cwd);

if (projectPath === undefined && mode.mode === "mcp") {
// Since we hide the "project load" tool in mcp mode
Expand Down
3 changes: 1 addition & 2 deletions src/commands/run/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import { buildCommand } from "@stricli/core";
import { TARGETS, TargetSchema } from "~/target";
import { parseProjectPath } from "~/project";
import { parseToolchainVersion } from "~/toolchain";

export const runCommand = buildCommand({
Expand All @@ -28,7 +27,7 @@ export const runCommand = buildCommand({
{
brief: "Path to the project .yyp file",
placeholder: "project",
parse: parseProjectPath,
parse: String,
optional: true,
},
],
Expand Down
11 changes: 8 additions & 3 deletions src/commands/run/impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,18 @@
*/

import type { Context } from "~/context";
import type { ProjectPath } from "~/project";
import { parseProjectPath } from "~/project";
import { runBuildPipeline, type CommonCliBuildFlags } from "~/build-pipeline";

export default async function (
this: Context,
flags: CommonCliBuildFlags,
project?: ProjectPath,
project?: string,
): Promise<void> {
await runBuildPipeline(this, flags, project, { type: "run" });
await runBuildPipeline(
this,
flags,
project ? parseProjectPath(this, project) : undefined,
{ type: "run" },
);
}
6 changes: 3 additions & 3 deletions src/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ import { KnownError } from "./error";

export type ProjectPath = string & { readonly __brand: unique symbol };

export function parseProjectPath(s: string): ProjectPath {
export function parseProjectPath(ctx: Context, s: string): ProjectPath {
if (!s.endsWith(".yyp")) {
throw new KnownError(`Expected a file with the .yyp extension.`);
}
return s as ProjectPath;
return ctx.path.resolve(s) as ProjectPath;
}

export async function findProjectFile(
Expand All @@ -35,7 +35,7 @@ export async function findProjectFile(
if (!yypFile) {
return undefined;
}
return ctx.path.join(dir, yypFile) as ProjectPath;
return ctx.path.resolve(ctx.path.join(dir, yypFile)) as ProjectPath;
}

export function getProjectName(ctx: Context, projectPath: ProjectPath) {
Expand Down
Loading