draftify-cli 1.0.12 → 1.0.15

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.
package/dist/index.js CHANGED
@@ -44,8 +44,25 @@ async function checkVersion() {
44
44
  try {
45
45
  const latestVersion = JSON.parse(data).version;
46
46
  const currentVersion = require("../package.json").version;
47
- // Semver comparison: strict inequality since we just want to block older versions
47
+ // Semver comparison: we only want to block older versions
48
+ let isOlder = false;
48
49
  if (latestVersion && currentVersion && latestVersion !== currentVersion) {
50
+ // Simple numeric split comparison for semver
51
+ const latestParts = latestVersion.split('.').map(Number);
52
+ const currentParts = currentVersion.split('.').map(Number);
53
+ for (let i = 0; i < Math.max(latestParts.length, currentParts.length); i++) {
54
+ const l = latestParts[i] || 0;
55
+ const c = currentParts[i] || 0;
56
+ if (l > c) {
57
+ isOlder = true;
58
+ break;
59
+ }
60
+ if (l < c) {
61
+ break;
62
+ }
63
+ }
64
+ }
65
+ if (isOlder) {
49
66
  console.error(`\n\x1b[31m[!] Elavult verziót használsz: ${currentVersion}\x1b[0m`);
50
67
  console.error(`\x1b[33mKérlek frissítsd a legújabbra (${latestVersion}) a folytatáshoz:\x1b[0m`);
51
68
  console.error(`\n \x1b[36mnpm install -g draftify-cli@latest\x1b[0m\n`);
package/dist/repl.js CHANGED
@@ -662,22 +662,22 @@ async function startRepl(initialUsername) {
662
662
  search = search.replace(/\r\n/g, '\n');
663
663
  replace = replace.replace(/\r\n/g, '\n');
664
664
  if (normalizedFile.includes(search)) {
665
- fileContent = normalizedFile.replace(search, replace);
665
+ fileContent = normalizedFile.replace(search, () => replace);
666
666
  diffApplied = true;
667
667
  }
668
668
  else {
669
669
  // Fallback 1: try stripping leading/trailing empty lines/whitespace from the search block
670
670
  const trimmedSearch = search.trim();
671
671
  if (trimmedSearch && normalizedFile.includes(trimmedSearch)) {
672
- fileContent = normalizedFile.replace(trimmedSearch, replace.trim());
672
+ fileContent = normalizedFile.replace(trimmedSearch, () => replace.trim());
673
673
  diffApplied = true;
674
674
  }
675
675
  else {
676
676
  // Fallback 2: Regex fuzzy matching that ignores exact whitespace differences (e.g. indentation or newlines)
677
- const escapedSearch = trimmedSearch.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&').replace(/\\s+/g, '\\s+');
677
+ const escapedSearch = trimmedSearch.replace(/[.*+?^${}()|[\]\\]/g, '\\$&').replace(/\s+/g, '\\s+');
678
678
  const regex = new RegExp(escapedSearch);
679
679
  if (regex.test(normalizedFile)) {
680
- fileContent = normalizedFile.replace(regex, replace.trim());
680
+ fileContent = normalizedFile.replace(regex, () => replace.trim());
681
681
  diffApplied = true;
682
682
  }
683
683
  else {
@@ -1079,6 +1079,9 @@ async function startRepl(initialUsername) {
1079
1079
  catch (err) {
1080
1080
  ui_1.ui.error(`Command failed:\n${err}`);
1081
1081
  commandOutputs.push(`Command: ${cmdToRun}\nFailed with error:\n${err}`);
1082
+ if (err === "Command aborted by user." || err?.name === "AbortError" || err?.message === "Command aborted by user.") {
1083
+ throw new Error("Aborted");
1084
+ }
1082
1085
  }
1083
1086
  }
1084
1087
  }
package/dist/utils/api.js CHANGED
@@ -85,23 +85,44 @@ Always use these tags when you write code or ask questions so the CLI can apply
85
85
  CRITICAL RULE: If the user's request is too broad, underspecified, or ambiguous (e.g., "Create a beautiful landing page", "Make a website" without further details), YOU MUST NOT generate any code. Instead, you MUST use the <ASK_QUESTIONS> tag to ask 2-3 clarifying questions (about design, framework, functionality, target audience, etc.). Wait for the user's answers before making file modifications.
86
86
 
87
87
  IMPORTANT: Do NOT include your own properties, name ('Draftify'), or AI identity in the code you generate (e.g., when creating a discord bot, landing page, or admin panel). Do not use 'Draftify' as a brand name or prefix in generated projects. If a fictional brand or name is needed, invent a new, unique one instead.`;
88
- const responseStream = await ai.models.generateContentStream({
89
- model: geminiModel,
90
- contents: contents,
91
- config: {
92
- systemInstruction: systemInstruction
88
+ if (abortSignal?.aborted)
89
+ throw new Error("Aborted");
90
+ const fullResult = await new Promise(async (resolve, reject) => {
91
+ const onAbort = () => reject(new Error("Aborted"));
92
+ if (abortSignal) {
93
+ abortSignal.addEventListener("abort", onAbort);
93
94
  }
94
- });
95
- let fullResult = "";
96
- for await (const chunk of responseStream) {
97
- if (abortSignal?.aborted)
98
- throw new Error("Aborted");
99
- if (chunk.text) {
100
- fullResult += chunk.text;
101
- if (onChunk)
102
- onChunk(chunk.text);
95
+ try {
96
+ const responseStream = await ai.models.generateContentStream({
97
+ model: geminiModel,
98
+ contents: contents,
99
+ config: {
100
+ systemInstruction: systemInstruction
101
+ }
102
+ });
103
+ let tempResult = "";
104
+ for await (const chunk of responseStream) {
105
+ if (abortSignal?.aborted) {
106
+ reject(new Error("Aborted"));
107
+ return;
108
+ }
109
+ if (chunk.text) {
110
+ tempResult += chunk.text;
111
+ if (onChunk)
112
+ onChunk(chunk.text);
113
+ }
114
+ }
115
+ resolve(tempResult);
103
116
  }
104
- }
117
+ catch (err) {
118
+ reject(err);
119
+ }
120
+ finally {
121
+ if (abortSignal) {
122
+ abortSignal.removeEventListener("abort", onAbort);
123
+ }
124
+ }
125
+ });
105
126
  // Rough estimation of tokens
106
127
  const estimatedTokens = Math.ceil((JSON.stringify(contents).length + fullResult.length) / 4);
107
128
  (0, config_1.addTokensUsed)(estimatedTokens);
@@ -132,6 +153,10 @@ IMPORTANT: Do NOT include your own properties, name ('Draftify'), or AI identity
132
153
  let buffer = "";
133
154
  let fullResult = "";
134
155
  while (true) {
156
+ if (abortSignal?.aborted) {
157
+ reader.cancel().catch(() => { });
158
+ throw new Error("Aborted");
159
+ }
135
160
  const { done, value } = await reader.read();
136
161
  if (done)
137
162
  break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "draftify-cli",
3
- "version": "1.0.12",
3
+ "version": "1.0.15",
4
4
  "description": "Draftify AI CLI tool",
5
5
  "main": "dist/index.js",
6
6
  "bin": {