@uxf/scripts 11.58.0 → 11.61.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.
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env node
2
+ require("../src/uxf-claude-sync/cli")()
3
+ .then(exitCode => {
4
+ process.exitCode = exitCode;
5
+ })
6
+ .catch(() => {
7
+ process.exitCode = 1;
8
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uxf/scripts",
3
- "version": "11.58.0",
3
+ "version": "11.61.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
package/src/GoogleChat.js CHANGED
@@ -5,12 +5,18 @@ const axios = create({});
5
5
 
6
6
  /**
7
7
  * @see https://developers.google.com/chat/api/reference/rest/v1/cards-v1
8
+ *
9
+ * @param data
10
+ * @param {{dryRun?: boolean|undefined, webhookUrl?: string|undefined}} config
11
+ *
8
12
  * @returns {Promise<void>}
9
13
  */
10
- async function chatPostMessage(data, dryRun) {
11
- if (env.GOOGLE_WEBHOOK_URL && !dryRun) {
14
+ async function chatPostMessage(data, config = {}) {
15
+ const webhookUrl = config.webhookUrl ?? env.GOOGLE_WEBHOOK_URL;
16
+
17
+ if (webhookUrl && !config.dryRun) {
12
18
  try {
13
- await axios.post(env.GOOGLE_WEBHOOK_URL, { ...data });
19
+ await axios.post(webhookUrl, { ...data });
14
20
  } catch (error) {
15
21
  process.stderr.write("GOOGLE CHAT: chat.postMessage - error");
16
22
  console.error(error);
@@ -20,9 +26,19 @@ async function chatPostMessage(data, dryRun) {
20
26
  }
21
27
  }
22
28
 
23
- async function messageCardsV2(cardsV2) {
29
+ /**
30
+ *
31
+ * @param cardsV2
32
+ * @param {{webhookUrl?: string}} config
33
+ * @returns {Promise<axios.AxiosResponse<any>>}
34
+ */
35
+ async function messageCardsV2(cardsV2, config = {}) {
24
36
  return axios
25
- .post(env.GOOGLE_WEBHOOK_URL, { cardsV2 }, { headers: { "Content-Type": "application/json; charset=UTF-8" } })
37
+ .post(
38
+ config.webhookUrl ?? env.GOOGLE_WEBHOOK_URL,
39
+ { cardsV2 },
40
+ { headers: { "Content-Type": "application/json; charset=UTF-8" } },
41
+ )
26
42
  .then((r) => r.data);
27
43
  }
28
44
 
@@ -0,0 +1,35 @@
1
+ const { argv } = require("process");
2
+
3
+ module.exports = async () => {
4
+ const cli = require("yargs")
5
+ .command("$0", "UXF Claude code sync", (yargs) => {
6
+ yargs.demandCommand(0, 0).usage(`UXF Claude code sync
7
+ Usage:
8
+ uxf-claude-sync [options]
9
+
10
+ `);
11
+ })
12
+ .option("url", {
13
+ describe: "Global guidelines URL",
14
+ type: "string",
15
+ group: "Options",
16
+ })
17
+ .option("h", { alias: "help", group: "Options" })
18
+ .strict(false)
19
+ .exitProcess(false);
20
+
21
+ try {
22
+ const { help, url, ...options } = cli.parse(argv.slice(2));
23
+
24
+ if (Boolean(help)) {
25
+ return 0;
26
+ }
27
+
28
+ await require("./index")(
29
+ url,
30
+ );
31
+ } catch (e) {
32
+ console.error(e);
33
+ return 1;
34
+ }
35
+ };
@@ -0,0 +1,78 @@
1
+ const fs = require('fs');
2
+ const https = require('https');
3
+ const http = require('http');
4
+
5
+ const fileName = 'CLAUDE.md';
6
+ const header = '# Global guidelines';
7
+
8
+ // Funkce pro stažení obsahu z URL
9
+ function downloadContent(url) {
10
+ return new Promise((resolve, reject) => {
11
+ const protocol = url.startsWith('https') ? https : http;
12
+
13
+ protocol.get(url, (response) => {
14
+ if (response.statusCode !== 200) {
15
+ reject(new Error(`Chyba při stahování: HTTP status ${response.statusCode}`));
16
+ return;
17
+ }
18
+
19
+ let data = '';
20
+ response.on('data', (chunk) => {
21
+ data += chunk;
22
+ });
23
+
24
+ response.on('end', () => {
25
+ resolve(data);
26
+ });
27
+ }).on('error', (error) => {
28
+ reject(error);
29
+ });
30
+ });
31
+ }
32
+
33
+ // Funkce pro úpravu souboru
34
+ function processFile(content) {
35
+ try {
36
+ // Kontrola, zda soubor existuje
37
+ let fileContent = '';
38
+ try {
39
+ fileContent = fs.readFileSync(fileName, 'utf8');
40
+ } catch (error) {
41
+ // Soubor neexistuje, vytvoříme nový
42
+ console.log(`Soubor ${fileName} neexistuje, vytvářím nový...`);
43
+ fs.writeFileSync(fileName, `${header}\n\n${content}\n`);
44
+ console.log(`Hotovo! Obsah byl uložen do nově vytvořeného souboru ${fileName}.`);
45
+ return;
46
+ }
47
+
48
+ // Kontrola, zda soubor obsahuje nadpis
49
+ if (fileContent.includes(header)) {
50
+ console.log(`Nadpis '${header}' nalezen v souboru, nahrazuji obsah pod ním...`);
51
+
52
+ const parts = fileContent.split(header);
53
+ let newContent = parts[0] + header + '\n\n' + content;
54
+
55
+ fs.writeFileSync(fileName, newContent);
56
+ console.log(`Hotovo! Obsah pod nadpisem '${header}' byl nahrazen.`);
57
+ } else {
58
+ console.log(`Nadpis '${header}' nenalezen v souboru, přidávám na konec...`);
59
+ fs.writeFileSync(fileName, `${fileContent.trim()}\n\n${header}\n\n${content}\n`);
60
+ console.log(`Hotovo! Nadpis '${header}' a obsah byly přidány na konec souboru ${fileName}.`);
61
+ }
62
+ } catch (error) {
63
+ console.error(`Chyba při zpracování souboru: ${error.message}`);
64
+ process.exit(1);
65
+ }
66
+ }
67
+
68
+ module.exports = async function(url) {
69
+ console.log(`Stahuji obsah z ${url}...`);
70
+
71
+ try {
72
+ const content = await downloadContent(url);
73
+ processFile(content);
74
+ } catch (error) {
75
+ console.error(`Chyba: ${error.message}`);
76
+ process.exit(1);
77
+ }
78
+ }
@@ -88,7 +88,7 @@ module.exports = async (dryRun, channel, messageTitle) => {
88
88
 
89
89
  await Slack.chatPostMessage(channel, { text: generateSlackMessage(commits, messageTitle) }, dryRun);
90
90
 
91
- await GoogleChat.chatPostMessage(generateGoogleMessage(commits, messageTitle), dryRun);
91
+ await GoogleChat.chatPostMessage(generateGoogleMessage(commits, messageTitle), { dryRun });
92
92
 
93
93
  await GitLab.createRelease(commits.map(generateReleaseCommitMessage).join("\n"), dryRun);
94
94
  };
@@ -43,6 +43,11 @@ Environment variables:
43
43
  type: "boolean",
44
44
  group: "Options",
45
45
  })
46
+ .option("google-chat-webhook-url", {
47
+ describe: "Webhook URL of Google Chat where to send the results.",
48
+ type: "string",
49
+ group: "Options",
50
+ })
46
51
  .option("h", { alias: "help", group: "Options" })
47
52
  .strict(false)
48
53
  .exitProcess(false);
@@ -60,7 +65,13 @@ Environment variables:
60
65
  env.HTTP_PASSWORD = options["http-password"];
61
66
  }
62
67
 
63
- await require("./index")(url, skip, options["with-nested"], options["with-images"]);
68
+ await require("./index")(
69
+ url,
70
+ skip,
71
+ options["with-nested"],
72
+ options["with-images"],
73
+ options["google-chat-webhook-url"],
74
+ );
64
75
  } catch (e) {
65
76
  console.error(e);
66
77
  return 1;
@@ -406,12 +406,16 @@ function logStatistics(okResults, time) {
406
406
 
407
407
  /**
408
408
  * @param resultErrors {string}
409
+ * @param webhookUrl {string|undefined}
409
410
  * @return {Promise<void>}
410
411
  */
411
- async function sendGoogleChatMessage(resultErrors) {
412
- await GoogleChat.chatPostMessage({
413
- text: resultErrors,
414
- });
412
+ async function sendGoogleChatMessage(resultErrors, webhookUrl) {
413
+ await GoogleChat.chatPostMessage(
414
+ {
415
+ text: resultErrors,
416
+ },
417
+ { webhookUrl },
418
+ );
415
419
  }
416
420
 
417
421
  /**
@@ -419,9 +423,10 @@ async function sendGoogleChatMessage(resultErrors) {
419
423
  * @param skip {number}
420
424
  * @param withNested {boolean}
421
425
  * @param withImages {boolean}
426
+ * @param googleWebhookUrl {string|undefined}
422
427
  * @return {Promise<*>}
423
428
  */
424
- module.exports = async function run(sitemapUrl, skip, withNested, withImages) {
429
+ module.exports = async function run(sitemapUrl, skip, withNested, withImages, googleWebhookUrl) {
425
430
  if (!sitemapUrl) {
426
431
  stdout.write("⛔ Required parameter --url is empty.\n");
427
432
  return process.exit(1);
@@ -450,7 +455,7 @@ module.exports = async function run(sitemapUrl, skip, withNested, withImages) {
450
455
  if (errors.length > 0) {
451
456
  const errorText = createErrorResult(errors);
452
457
  logErrors(errorText, "\n\n\nErrors:\n");
453
- await sendGoogleChatMessage(errorText);
458
+ await sendGoogleChatMessage(errorText, googleWebhookUrl);
454
459
  }
455
460
 
456
461
  if (skippedUrls.length > 0) {