draply-dev 1.0.3 → 1.0.5

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.
Files changed (2) hide show
  1. package/bin/cli.js +17 -11
  2. package/package.json +1 -1
package/bin/cli.js CHANGED
@@ -18,8 +18,8 @@ const INJECT_TAG = `\n<link rel="stylesheet" href="/draply.css">\n<script ${MARK
18
18
 
19
19
  function injectOverlay(html) {
20
20
  if (html.includes(MARKER)) return html;
21
- if (html.includes('</body>')) return html.replace(/<\/body>/i, INJECT_TAG + '\n</body>');
22
- if (html.includes('</html>')) return html.replace(/<\/html>/i, INJECT_TAG + '\n</html>');
21
+ if (html.includes('</body>')) return html.replace(/<\/body>/i, () => INJECT_TAG + '\n</body>');
22
+ if (html.includes('</html>')) return html.replace(/<\/html>/i, () => INJECT_TAG + '\n</html>');
23
23
  return html + INJECT_TAG;
24
24
  }
25
25
 
@@ -107,16 +107,22 @@ const server = http.createServer((req, res) => {
107
107
  const results = [];
108
108
  const fileMap = new Map();
109
109
 
110
- // 1. Group by exact file (thanks to React Fiber)
110
+ // 1. Group by exact file (thanks to React Fiber, fallback to index.html)
111
111
  for (const ch of (changes || [])) {
112
- if (!ch.exactFile || !fs.existsSync(ch.exactFile)) {
113
- results.push({ selector: ch.selector, ok: false, reason: 'Source file not linked' });
114
- continue;
112
+ let targetFile = ch.exactFile;
113
+ if (!targetFile || !fs.existsSync(targetFile)) {
114
+ const fallbackHTML = path.join(process.cwd(), 'index.html');
115
+ if (fs.existsSync(fallbackHTML)) {
116
+ targetFile = fallbackHTML;
117
+ } else {
118
+ results.push({ selector: ch.selector, ok: false, reason: 'Source file not linked' });
119
+ continue;
120
+ }
115
121
  }
116
- if (!fileMap.has(ch.exactFile)) {
117
- fileMap.set(ch.exactFile, { content: fs.readFileSync(ch.exactFile, 'utf8'), items: [] });
122
+ if (!fileMap.has(targetFile)) {
123
+ fileMap.set(targetFile, { content: fs.readFileSync(targetFile, 'utf8'), items: [] });
118
124
  }
119
- fileMap.get(ch.exactFile).items.push(ch);
125
+ fileMap.get(targetFile).items.push(ch);
120
126
  }
121
127
 
122
128
  // 2. Call AI per file using XML Patches
@@ -150,14 +156,14 @@ FILE: ${path.basename(filePath)} (lines ${ctxStart + 1}-${ctxEnd + 1})
150
156
  ${snippet}
151
157
  \`\`\`
152
158
 
153
- CHANGES (Apply to React elements matching selectors):
159
+ CHANGES (Apply to HTML/React elements matching selectors):
154
160
  ${changesBlock}
155
161
 
156
162
  IMPORTANT: Return your changes wrapped in <patch> tags containing <search> and <replace> blocks. DO NOT use JSON.
157
163
 
158
164
  Rules:
159
165
  - The content inside <search> must be an EXACT substring from the file snippet above.
160
- - Update JSX inline styles or Tailwind classes appropriately.
166
+ - Update HTML/JSX inline styles or Tailwind classes appropriately.
161
167
  - REPLACE old style values if they exist, DO NOT duplicate keys!
162
168
 
163
169
  Example response:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "draply-dev",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "Visual overlay for any frontend project — move, resize, restyle live in the browser, save to CSS",
5
5
  "author": "Arman",
6
6
  "type": "commonjs",