Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const createStartSliceMachineProcess = (
export type StartSliceMachineProcessConstructorArgs = {
open: boolean;
port?: number;
cwd?: string;
};

/**
Expand Down Expand Up @@ -60,7 +61,9 @@ export class StartSliceMachineProcess {
private _sliceMachineManager: SliceMachineManager;

constructor(args: StartSliceMachineProcessConstructorArgs) {
this._sliceMachineManager = createSliceMachineManager();
this._sliceMachineManager = createSliceMachineManager({
cwd: args.cwd,
});

this.open = args.open ?? false;
this.port = args.port ?? DEFAULT_SERVER_PORT;
Expand Down
20 changes: 19 additions & 1 deletion packages/start-slicemachine/src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
import * as path from "node:path";
import * as fs from "node:fs";

import mri from "mri";

import * as pkg from "../package.json";

type Args = {
open: boolean;
port: string;
config: string;
help: boolean;
version: boolean;
};

const args = mri<Args>(process.argv.slice(2), {
boolean: ["open", "help", "version"],
string: ["port"],
string: ["port", "config"],
alias: {
port: "p",
config: "c",
help: "h",
version: "v",
},
Expand All @@ -33,6 +38,7 @@ Usage:
Options:
--open Open Slice Machine automatically
--port, -p Specify the port on which to run Slice Machine
--config, -c Path to your slicemachine.config.json (directory or config file)
--help, -h Show help text
--version, -v Show version
`.trim(),
Expand All @@ -58,11 +64,23 @@ if (args.port) {
}
}

let cwd: string | undefined;
if (args.config) {
const configPath = path.resolve(process.cwd(), args.config);
// Handle both cases where the config is a directory or a file path
if (fs.existsSync(configPath) && fs.statSync(configPath).isDirectory()) {
cwd = configPath;
} else {
cwd = path.dirname(configPath);
}
}

import("./StartSliceMachineProcess").then(
({ createStartSliceMachineProcess }) => {
const startSliceMachineProcess = createStartSliceMachineProcess({
open: args.open,
port,
cwd,
});

startSliceMachineProcess.run();
Expand Down