@savvy-web/silk-effects 0.2.1 → 0.2.2
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/index.js +8 -5
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -202,7 +202,7 @@ class SectionBlock extends Schema.TaggedClass()("SectionBlock", {
|
|
|
202
202
|
get rendered() {
|
|
203
203
|
const begin = `${this.commentStyle} --- BEGIN ${this.toolName.toUpperCase()} MANAGED SECTION ---`;
|
|
204
204
|
const end = `${this.commentStyle} --- END ${this.toolName.toUpperCase()} MANAGED SECTION ---`;
|
|
205
|
-
return `${begin}${this.content}${end}`;
|
|
205
|
+
return `${begin}\n${this.content}\n${end}`;
|
|
206
206
|
}
|
|
207
207
|
prepend(lines) {
|
|
208
208
|
return SectionBlock.make({
|
|
@@ -560,16 +560,19 @@ function parseContent(content, toolName, commentStyle) {
|
|
|
560
560
|
const beginIndex = content.indexOf(begin);
|
|
561
561
|
const endIndex = content.indexOf(end);
|
|
562
562
|
if (-1 === beginIndex || -1 === endIndex || endIndex <= beginIndex) return null;
|
|
563
|
+
let managed = content.slice(beginIndex + begin.length, endIndex);
|
|
564
|
+
if (managed.startsWith("\n")) managed = managed.slice(1);
|
|
565
|
+
if (managed.endsWith("\n")) managed = managed.slice(0, -1);
|
|
563
566
|
return {
|
|
564
567
|
before: content.slice(0, beginIndex),
|
|
565
|
-
managed
|
|
568
|
+
managed,
|
|
566
569
|
after: content.slice(endIndex + end.length)
|
|
567
570
|
};
|
|
568
571
|
}
|
|
569
572
|
function assembleContent(before, managed, after, toolName, commentStyle) {
|
|
570
573
|
const begin = beginMarker(toolName, commentStyle);
|
|
571
574
|
const end = endMarker(toolName, commentStyle);
|
|
572
|
-
return `${before}${begin}${managed}${end}${after}`;
|
|
575
|
+
return `${before}${begin}\n${managed}\n${end}${after}`;
|
|
573
576
|
}
|
|
574
577
|
class ManagedSection extends Context.Tag("@savvy-web/silk-effects/ManagedSection")() {
|
|
575
578
|
}
|
|
@@ -614,12 +617,12 @@ const ManagedSectionLive = Layer.effect(ManagedSection, Effect.gen(function*() {
|
|
|
614
617
|
const trimmed = raw.trimEnd();
|
|
615
618
|
const begin = beginMarker(block.toolName, block.commentStyle);
|
|
616
619
|
const end = endMarker(block.toolName, block.commentStyle);
|
|
617
|
-
fileContent = `${trimmed}\n\n${begin}${block.content}${end}\n`;
|
|
620
|
+
fileContent = `${trimmed}\n\n${begin}\n${block.content}\n${end}\n`;
|
|
618
621
|
}
|
|
619
622
|
} else {
|
|
620
623
|
const begin = beginMarker(block.toolName, block.commentStyle);
|
|
621
624
|
const end = endMarker(block.toolName, block.commentStyle);
|
|
622
|
-
fileContent = `${begin}${block.content}${end}\n`;
|
|
625
|
+
fileContent = `${begin}\n${block.content}\n${end}\n`;
|
|
623
626
|
}
|
|
624
627
|
yield* fs.writeFileString(path, fileContent).pipe(Effect.mapError((cause)=>new SectionWriteError({
|
|
625
628
|
path,
|
package/package.json
CHANGED