Skip to content

Commit

Permalink
Build compiled by Ruby script
Browse files Browse the repository at this point in the history
  • Loading branch information
wbharding committed Dec 30, 2023
1 parent d51ad20 commit 70aa066
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
36 changes: 28 additions & 8 deletions build/compiled.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,6 @@
if (endIndex !== -1 && startIndex !== -1) {
const constantValue = constantAdjacentText.substring(startIndex, endIndex + 1);
const constantName = constantDeclarationMatch.groups?.constantName;
console.log("Got constant value length", constantValue?.length, "for", constantName);
constantTranslations.push({ constantName, constantValue });
}
}
Expand Down Expand Up @@ -331,14 +330,20 @@
// Javascript updated ${(/* @__PURE__ */ new Date()).toLocaleString()} by Amplenote Plugin Builder from source code within "${repoUrl}"
${newPluginBlock}
\`\`\``;
const replaceTarget = this._sectionFromHeadingText(this._constants.codeHeading);
await note.replaceContent(newPluginBlock, replaceTarget);
if (this.processingError) {
await app.alert(`\u26A0\uFE0F Plugin refresh from "${repoUrl}" completed, but errors were encountered:
const replaceTarget = this._sectionFromHeadingText(this._constants.codeHeading, noteContent);
if (replaceTarget) {
await note.replaceContent(newPluginBlock, replaceTarget);
}
if (!replaceTarget || this.processingError) {
if (replaceTarget) {
await app.alert(`\u26A0\uFE0F Plugin refresh from "${repoUrl}" completed, but errors were encountered:
` + this.processingError + `
Please check your console for more details.`);
} else {
await app.alert(`\u26A0\uFE0F Plugin refresh from "${repoUrl}" failed. Could not find "${this._constants.codeHeading}" within note content.`);
}
} else {
await app.alert(`\u{1F389} Plugin refresh from "${repoUrl}" succeeded at ${(/* @__PURE__ */ new Date()).toLocaleString()}`);
}
Expand All @@ -350,12 +355,27 @@ Please check your console for more details.`);
}
},
//----------------------------------------------------------------------
_sectionFromHeadingText(headingText, { level = 1 } = {}) {
return { section: { heading: { text: headingText, level } } };
_sectionFromHeadingText(headingText, noteContent, { level = 1 } = {}) {
let headingTextInNote;
if (noteContent.includes(headingText)) {
headingTextInNote = headingText;
} else {
const headingIndex = noteContent.toLowerCase().indexOf(headingText.toLowerCase());
if (headingIndex > 0) {
headingTextInNote = noteContent.substring(headingIndex, headingIndex + headingText.length);
} else {
return null;
}
}
if (headingTextInNote) {
return { section: { heading: { text: headingTextInNote, level } } };
} else {
return null;
}
},
//----------------------------------------------------------------------
async _isAbleToSync(app, noteContent) {
if (noteContent.includes(this._constants.codeHeading)) {
if (noteContent.toLowerCase().includes(this._constants.codeHeading.toLowerCase())) {
return true;
} else {
if (/^```/m.test(noteContent)) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"main": "lib/index.js",
"name": "plugin-builder",
"scripts": {
"run": "node esbuild.js",
"build": "node esbuild.js",
"test": "jest"
},
"testEnvironment": "jsdom",
Expand Down

0 comments on commit 70aa066

Please sign in to comment.