@zuplo/cli 1.79.0 → 1.80.0

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.
@@ -1,5 +1,5 @@
1
1
 
2
- !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="91beac2e-2f71-54d6-8ec4-22de6a806272")}catch(e){}}();
2
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="cf6db85e-4a14-503e-918f-daa35bc7f81c")}catch(e){}}();
3
3
  import fastifyStatic from "@fastify/static";
4
4
  import chokidar from "chokidar";
5
5
  import Fastify from "fastify";
@@ -11,15 +11,19 @@ import { logger } from "../../common/logger.js";
11
11
  import { corsPlugin } from "./cors-plugin.js";
12
12
  import { dirExists, fileExists } from "./xfs.js";
13
13
  const POLICIES_FILENAME = "policies.json";
14
+ const CONFIG_DIR = "config";
14
15
  export class ApiServer {
15
16
  fastify;
16
17
  listenerPort;
17
18
  listenerHost;
18
19
  workingDir;
20
+ watcher;
21
+ sseContext;
19
22
  constructor(workingDir) {
20
23
  this.workingDir = workingDir ?? ".";
21
24
  this.listenerPort = 5500;
22
25
  this.listenerHost = "localhost";
26
+ this.watcher = chokidar.watch(path.join(this.workingDir, CONFIG_DIR));
23
27
  this.fastify = Fastify({
24
28
  logger: logger,
25
29
  trustProxy: true,
@@ -54,7 +58,7 @@ export class ApiServer {
54
58
  const policiesPath = path.join(this.workingDir, "config", POLICIES_FILENAME);
55
59
  if (!(await fileExists(policiesPath))) {
56
60
  return reply.code(404).send({
57
- message: `Cannot find a '${POLICIES_FILENAME}' file in the 'config'`,
61
+ message: `Cannot find a '${POLICIES_FILENAME}' file in the '${CONFIG_DIR}'`,
58
62
  });
59
63
  }
60
64
  const openApiFileContent = await fs.readFile(openApiFilePath, "utf-8");
@@ -74,11 +78,11 @@ export class ApiServer {
74
78
  });
75
79
  instance.get("/open-api-files", {
76
80
  handler: async (request, reply) => {
77
- const projectConfigPath = path.join(this.workingDir, "config");
81
+ const projectConfigPath = path.join(this.workingDir, CONFIG_DIR);
78
82
  if (!(await dirExists(projectConfigPath))) {
79
- request.log.warn(`Cannot find the project 'config' folder. Make sure '${this.workingDir}' has a 'config' folder.`);
83
+ request.log.warn(`Cannot find the project '${CONFIG_DIR}' folder. Make sure '${this.workingDir}' has a '${CONFIG_DIR}' folder.`);
80
84
  return reply.code(404).send({
81
- message: `Cannot find the project 'config' folder. Make sure '${this.workingDir}' has a 'config' folder.`,
85
+ message: `Cannot find the project '${CONFIG_DIR}' folder. Make sure '${this.workingDir}' has a '${CONFIG_DIR}' folder.`,
82
86
  });
83
87
  }
84
88
  const files = await readdir(projectConfigPath);
@@ -105,19 +109,22 @@ export class ApiServer {
105
109
  });
106
110
  instance.get("/updates", {
107
111
  handler: async (request, reply) => {
108
- const projectConfigPath = path.join(this.workingDir, "config");
109
- const watcher = chokidar.watch(projectConfigPath);
110
- watcher.on("change", (filePath) => {
112
+ if (this.watcher && this.watcher.closed === true) {
113
+ this.watcher = chokidar.watch(path.join(this.workingDir, CONFIG_DIR));
114
+ }
115
+ this.watcher.on("change", (filePath) => {
111
116
  const eventData = JSON.stringify({ type: "update", filePath });
112
117
  reply.sse({ id: Date.now().toString(), data: eventData });
113
118
  });
114
- request.raw.on("close", () => {
115
- watcher.close();
119
+ request.raw.on("close", async () => {
120
+ await this.watcher.close();
116
121
  });
117
122
  reply.sse({
118
123
  id: Date.now().toString(),
119
124
  data: JSON.stringify({ filePath: POLICIES_FILENAME, type: "init" }),
125
+ retry: 10,
120
126
  });
127
+ this.sseContext = reply.sseContext;
121
128
  },
122
129
  });
123
130
  instance.get("/modules-data", {
@@ -152,6 +159,11 @@ export class ApiServer {
152
159
  reply.code(200).send(results);
153
160
  },
154
161
  });
162
+ instance.get("/ping", {
163
+ handler: async (_request, reply) => {
164
+ reply.code(200).send();
165
+ },
166
+ });
155
167
  done();
156
168
  });
157
169
  };
@@ -176,6 +188,12 @@ export class ApiServer {
176
188
  close = async () => {
177
189
  this.fastify.log.info("Closing api server");
178
190
  try {
191
+ if (this.sseContext) {
192
+ this.sseContext.source.end();
193
+ }
194
+ if (this.watcher) {
195
+ await this.watcher.close();
196
+ }
179
197
  await this.fastify.close();
180
198
  }
181
199
  catch (err) {
@@ -185,4 +203,4 @@ export class ApiServer {
185
203
  };
186
204
  }
187
205
  //# sourceMappingURL=server.js.map
188
- //# debugId=91beac2e-2f71-54d6-8ec4-22de6a806272
206
+ //# debugId=cf6db85e-4a14-503e-918f-daa35bc7f81c
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zuplo/cli",
3
- "version": "1.79.0",
3
+ "version": "1.80.0",
4
4
  "type": "module",
5
5
  "repository": "https://github.com/zuplo/cli",
6
6
  "description": "The command-line interface for Zuplo",