Skip to content

Commit

Permalink
fix: fixing CLI paths issues
Browse files Browse the repository at this point in the history
  • Loading branch information
TayzenDev committed Nov 19, 2024
1 parent f919690 commit bb9cdea
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ export function createCli(postsFolder: string): CLI {
.action((fileId, options) => {
console.log("Creating post...");
try {
const underscoreToAdd = options.published ? false : !fileId.startsWith("_");
const filename = path.join(postsFolder, (underscoreToAdd ? "_" : "") + fileId + ".md");
const underscoreToAdd = options.published
? false
: !fileId.startsWith("_");
const filename = (underscoreToAdd ? "_" : "") + fileId + ".md";
const folder = postsFolder;
const params = {
title: options.title as string,
Expand Down Expand Up @@ -64,8 +66,14 @@ export function createCli(postsFolder: string): CLI {
console.log("Publishing post...");
try {
fs.moveSync(
path.join(fileId + ".md"),
path.join((!fileId.startsWith("_") ? fileId : fileId.substring(1)) + ".md"),
path.join(
postsFolder,
(!fileId.startsWith("_") ? "_" + fileId : fileId) + ".md",
),
path.join(
postsFolder,
(!fileId.startsWith("_") ? fileId : fileId.substring(1)) + ".md",
),
);
console.log("Post published.");
} catch (e) {
Expand All @@ -86,7 +94,9 @@ export function createCli(postsFolder: string): CLI {
if (options.all || options.published || !options.drafts) {
console.log("");
console.log("Published:");
for (const file of fs.expandGlobSync(path.join(postsFolder, "[!_]*.md"))) {
for (
const file of fs.expandGlobSync(path.join(postsFolder, "[!_]*.md"))
) {
console.log(" - ", file.name.replace(".md", ""));
}
}
Expand All @@ -110,7 +120,10 @@ export function createCli(postsFolder: string): CLI {
try {
fs.moveSync(
path.join(postsFolder, fileId + ".md"),
path.join((fileId.startsWith("_") ? fileId : "_" + fileId) + ".md"),
path.join(
postsFolder,
(fileId.startsWith("_") ? fileId : "_" + fileId) + ".md",
),
);
console.log("Post archived.");
} catch (e) {
Expand All @@ -129,7 +142,12 @@ export function createCli(postsFolder: string): CLI {
.action((fileId) => {
console.log("Removing post...");
try {
Deno.removeSync(path.join(postsFolder, "_" + fileId + ".md"));
Deno.removeSync(
path.join(
postsFolder,
(!fileId.startsWith("_") ? "_" + fileId : fileId) + ".md",
),
);
console.log("Post removed.");
} catch {
console.log("Post not found.");
Expand Down

0 comments on commit bb9cdea

Please sign in to comment.