Skip to content

Commit

Permalink
feat(api): add addon version
Browse files Browse the repository at this point in the history
  • Loading branch information
aidenlx committed Aug 22, 2021
1 parent 57cea9f commit bcb32e5
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
11 changes: 9 additions & 2 deletions package.json
Expand Up @@ -49,8 +49,15 @@
},
"release-it": {
"hooks": {
"after:bump": "npm run build",
"after:git:release": "echo After git push, before github release",
"before:init": [
"npm run prettier",
"npm run eslint"
],
"after:bump": [
"sed -i '' -E -e 's/const version = \"[0-9.]+\"/const version = \"${version}\"/' src/modules/const.ts",
"git add .",
"npm run build"
],
"after:release": "echo Successfully released ${name} v${version} to ${repo.repository}."
},
"git": {
Expand Down
4 changes: 4 additions & 0 deletions src/modules/const.ts
@@ -0,0 +1,4 @@
import { MNMark } from "./return";
export const PREFIX: MNMark = "<!--MN-->\n";
const version = "2.0.0";
export const VERSION: string = "v" + version;
9 changes: 5 additions & 4 deletions src/modules/parser.ts
@@ -1,9 +1,9 @@
import { excerptPic_video, MbBook, MbBookNote } from "@alx-plugins/marginnote";

import { PREFIX, VERSION } from "./const";
import PopupRecorder from "./PopupRecorder";
import {
Data,
MNMark,
ReturnBody,
ReturnBody_Note,
ReturnBody_Sel,
Expand All @@ -23,7 +23,7 @@ const getBook = (docMd5: string | undefined): MbBook | null => {
};

const stringify = (obj: any): string => {
return MNMark + JSON.stringify(obj);
return PREFIX + JSON.stringify(obj);
};

const getLastAndSendTime = (
Expand All @@ -37,6 +37,7 @@ const getLastAndSendTime = (
export const handleSel = (sel: Selection): void => {
const { last, sendTime } = getLastAndSendTime(sel);
const returns: ReturnBody_Sel = {
version: VERSION,
type: "sel",
sendTime,
data: sel,
Expand Down Expand Up @@ -75,6 +76,7 @@ export const handleNote = (note: MbBookNote): void => {
: {};

const returns: ReturnBody_Note = {
version: VERSION,
type: "note",
sendTime,
bookMap,
Expand All @@ -93,6 +95,7 @@ export const handleToc = (note: MbBookNote): void => {
{ last, sendTime } = getLastAndSendTime(data),
bookMap = arrToObj(bookMd5s, (id) => getBook(id));
const returns: ReturnBody_Toc = {
version: VERSION,
type: "toc",
sendTime,
bookMap,
Expand All @@ -104,7 +107,5 @@ export const handleToc = (note: MbBookNote): void => {
} else showHUD(result);
};

const MNMark: MNMark = "<!--MN-->\n";

const isSel = (node: Data): node is Selection =>
typeof (node as Selection).sel === "string";
1 change: 1 addition & 0 deletions src/modules/return.d.ts
Expand Up @@ -14,6 +14,7 @@ export type DataType = "sel" | "note" | "toc";
export type MNMark = "<!--MN-->\n";

type ReturnBody_Basic = {
version: string;
type: DataType;
sendTime: ReturnType<typeof Date.now>;
data: Data;
Expand Down

0 comments on commit bcb32e5

Please sign in to comment.