mfer 3.1.0 → 3.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,41 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { Command } from "commander";
11
+ import chalk from "chalk";
12
+ import { spawnSync } from "child_process";
13
+ import { getInstalledVersion, getLatestVersion, } from "../utils/version-utils.js";
14
+ const updateCommand = new Command("update")
15
+ .description("update mfer to the latest version")
16
+ .action(() => __awaiter(void 0, void 0, void 0, function* () {
17
+ const installedVersion = getInstalledVersion();
18
+ console.log(chalk.blue(`Current version: ${installedVersion}`));
19
+ console.log(chalk.blue("Checking for updates..."));
20
+ const latestVersion = yield getLatestVersion();
21
+ if (!latestVersion) {
22
+ console.log(chalk.red("Error: Could not fetch the latest version from npm."));
23
+ return;
24
+ }
25
+ if (latestVersion === installedVersion) {
26
+ console.log(chalk.green("You are already on the latest version."));
27
+ return;
28
+ }
29
+ console.log(chalk.yellow(`New version available: ${latestVersion}`));
30
+ console.log(chalk.blue("Updating mfer..."));
31
+ const result = spawnSync("npm", ["install", "-g", "mfer@latest"], {
32
+ stdio: "inherit",
33
+ shell: true,
34
+ });
35
+ if (result.status !== 0) {
36
+ console.log(chalk.red(`Error: Update failed with exit code ${result.status}. Try running: npm install -g mfer@latest`));
37
+ return;
38
+ }
39
+ console.log(chalk.green(`Successfully updated mfer to ${latestVersion}.`));
40
+ }));
41
+ export default updateCommand;
package/dist/index.js CHANGED
@@ -7,11 +7,13 @@ import installCommand from "./commands/install.js";
7
7
  import cloneCommand from "./commands/clone.js";
8
8
  import pullCommand from "./commands/pull.js";
9
9
  import libCommand from "./commands/lib/index.js";
10
+ import updateCommand from "./commands/update.js";
10
11
  import { loadConfig } from "./utils/config-utils.js";
12
+ import { checkForUpdateNotification } from "./utils/version-utils.js";
11
13
  program
12
14
  .name("mfer")
13
15
  .description("Micro Frontend Runner (mfer) - A CLI for running your project's micro frontends.")
14
- .version("3.1.0", "-v, --version", "mfer CLI version")
16
+ .version("3.2.4", "-v, --version", "mfer CLI version")
15
17
  .hook("preAction", () => {
16
18
  console.log();
17
19
  })
@@ -25,5 +27,7 @@ program.addCommand(installCommand);
25
27
  program.addCommand(cloneCommand);
26
28
  program.addCommand(pullCommand);
27
29
  program.addCommand(libCommand);
30
+ program.addCommand(updateCommand);
28
31
  loadConfig();
29
32
  program.parse();
33
+ checkForUpdateNotification().catch(() => { });
@@ -0,0 +1,84 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import * as fs from "fs";
11
+ import * as path from "path";
12
+ import * as os from "os";
13
+ import chalk from "chalk";
14
+ import { spawnSync } from "child_process";
15
+ const NOTIFIED_VERSION_FILE = path.join(os.homedir(), ".mfer", ".last-notified-version");
16
+ export function getInstalledVersion() {
17
+ const packageJsonPath = path.join(path.dirname(new URL(import.meta.url).pathname), "../../package.json");
18
+ try {
19
+ const raw = fs.readFileSync(packageJsonPath, "utf8");
20
+ return JSON.parse(raw).version;
21
+ }
22
+ catch (_a) {
23
+ return "unknown";
24
+ }
25
+ }
26
+ export function getLatestVersion() {
27
+ return __awaiter(this, void 0, void 0, function* () {
28
+ try {
29
+ const result = spawnSync("npm", ["view", "mfer", "version"], {
30
+ stdio: "pipe",
31
+ shell: true,
32
+ timeout: 10000,
33
+ });
34
+ if (result.status !== 0 || !result.stdout) {
35
+ return null;
36
+ }
37
+ return result.stdout.toString().trim();
38
+ }
39
+ catch (_a) {
40
+ return null;
41
+ }
42
+ });
43
+ }
44
+ function getLastNotifiedVersion() {
45
+ try {
46
+ return fs.readFileSync(NOTIFIED_VERSION_FILE, "utf8").trim();
47
+ }
48
+ catch (_a) {
49
+ return null;
50
+ }
51
+ }
52
+ function setLastNotifiedVersion(version) {
53
+ try {
54
+ const dir = path.dirname(NOTIFIED_VERSION_FILE);
55
+ if (!fs.existsSync(dir)) {
56
+ fs.mkdirSync(dir, { recursive: true });
57
+ }
58
+ fs.writeFileSync(NOTIFIED_VERSION_FILE, version);
59
+ }
60
+ catch (_a) {
61
+ }
62
+ }
63
+ export function checkForUpdateNotification() {
64
+ return __awaiter(this, void 0, void 0, function* () {
65
+ try {
66
+ const installedVersion = getInstalledVersion();
67
+ if (installedVersion === "unknown")
68
+ return;
69
+ const latestVersion = yield getLatestVersion();
70
+ if (!latestVersion)
71
+ return;
72
+ if (latestVersion === installedVersion)
73
+ return;
74
+ const lastNotified = getLastNotifiedVersion();
75
+ if (lastNotified === latestVersion)
76
+ return;
77
+ console.log(chalk.yellow(`\n Update available: ${installedVersion} → ${latestVersion}`));
78
+ console.log(chalk.yellow(` Run ${chalk.bold("mfer update")} to update.\n`));
79
+ setLastNotifiedVersion(latestVersion);
80
+ }
81
+ catch (_a) {
82
+ }
83
+ });
84
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mfer",
3
- "version": "3.1.0",
3
+ "version": "3.2.4",
4
4
  "description": "CLI tool designed to sensibly run micro-frontends from the terminal.",
5
5
  "bin": {
6
6
  "mfer": "dist/index.js"