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
5 changes: 4 additions & 1 deletion cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@
}
},
"hooks": {
"init": "./dist/cli/src/hooks/init/add-description"
"init": [
"./dist/cli/src/hooks/init/add-description",
"./dist/cli/src/hooks/init/setup-channel"
]
}
},
"repository": "https://github.com/nonfx/starchitect-cloudguard/tree/main/cli",
Expand Down
21 changes: 21 additions & 0 deletions cli/src/hooks/init/setup-channel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { type Hook } from "@oclif/core";
import { mkdir, writeFile } from "fs/promises";
import { join } from "path";
import { homedir } from "os";

const hook: Hook<"init"> = async function () {
try {
const starkitDir = join(homedir(), ".local", "share", "starkit");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this work on windows?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

await mkdir(starkitDir, { recursive: true });

const channelFile = join(starkitDir, "channel");
await writeFile(channelFile, "stable", { flag: "wx" }); // wx flag means write only if file doesn't exist
} catch (error: unknown) {
// Ignore error if file already exists
if (error instanceof Error && "code" in error && error.code !== "EEXIST") {
console.error("Warning: Failed to setup starkit channel", error);
}
}
};

export default hook;