Skip to content

Commit

Permalink
Merge pull request #397 from vuelessjs/VL-34_Add-vueless-config-back-…
Browse files Browse the repository at this point in the history
…up-on-init_Dmytro-Holdobin

VL-34_Add-vueless-config-back-up-on-init_Dmytro-Holdobin
  • Loading branch information
Explicit12 authored Feb 19, 2025
2 parents a9c920d + d25123f commit f2b6b3b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
18 changes: 17 additions & 1 deletion src/bin/commands/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import { cwd } from "node:process";
import path from "node:path";
import { writeFile } from "node:fs/promises";
import { existsSync } from "node:fs";
import { writeFile, rename } from "node:fs/promises";
import { styleText } from "node:util";

import { DEFAULT_VUELESS_CONFIG_CONTNET } from "../constants.js";
Expand All @@ -24,6 +25,21 @@ export async function vuelessInit(options) {
ext: fileExt,
});

if (existsSync(formattedDestPath)) {
const timestamp = new Date().valueOf();
const renamedTarget = `${VUELESS_CONFIG_FILE_NAME}-backup-${timestamp}${fileExt}`;

await rename(formattedDestPath, renamedTarget);

const warnMessage = styleText(
"yellow",
// eslint-disable-next-line vue/max-len
`Current Vueless config backed into: '${path.basename(renamedTarget)}' folder. Don't forget to remove it before commit.`,
);

console.warn(warnMessage);
}

await writeFile(formattedDestPath, DEFAULT_VUELESS_CONFIG_CONTNET, "utf-8");

const successMessage = styleText(
Expand Down
6 changes: 4 additions & 2 deletions src/bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

/* eslint-disable no-console */

import { styleText } from "node:util";

import { commands } from "./commands/index.js";

import { DEFAULT_EXIT_CODE, FAILURE_CODE } from "../constants.js";
Expand All @@ -16,9 +18,9 @@ try {
if (command in commands) {
commands[command](options);
} else {
throw new Error(`There is no such command: ${command}`);
throw new Error(styleText("red", `There is no such command: ${command}`));
}
} catch (error) {
console.error(error.message);
console.error(styleText("red", error.message));
process.exit(error.code || FAILURE_CODE);
}

0 comments on commit f2b6b3b

Please sign in to comment.