mirror of
https://github.com/jspsych/jsPsych.git
synced 2025-05-10 11:10:54 +00:00
fix browser tool for citations
This commit is contained in:
parent
bceacab4ca
commit
a2e7918773
58
package-lock.json
generated
58
package-lock.json
generated
@ -9,6 +9,8 @@
|
|||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@citation-js/core": "^0.7.14",
|
"@citation-js/core": "^0.7.14",
|
||||||
|
"@citation-js/plugin-bibtex": "^0.7.14",
|
||||||
|
"@citation-js/plugin-csl": "^0.7.14",
|
||||||
"@citation-js/plugin-software-formats": "^0.6.1",
|
"@citation-js/plugin-software-formats": "^0.6.1",
|
||||||
"symlink": "^2.1.0"
|
"symlink": "^2.1.0"
|
||||||
},
|
},
|
||||||
@ -1201,6 +1203,22 @@
|
|||||||
"node": ">=6"
|
"node": ">=6"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@citation-js/plugin-bibtex": {
|
||||||
|
"version": "0.7.14",
|
||||||
|
"resolved": "https://registry.npmjs.org/@citation-js/plugin-bibtex/-/plugin-bibtex-0.7.14.tgz",
|
||||||
|
"integrity": "sha512-xHOHqhF6dthLRv46N9U+mQgYLiiWQHLvQWK9+mcBKz+/3NWge62Xb1oBouNWwLEPd5FV/8gp9fp7SOp93T0dUg==",
|
||||||
|
"dependencies": {
|
||||||
|
"@citation-js/date": "^0.5.0",
|
||||||
|
"@citation-js/name": "^0.4.2",
|
||||||
|
"moo": "^0.5.1"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=16.0.0"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"@citation-js/core": "^0.7.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@citation-js/plugin-cff": {
|
"node_modules/@citation-js/plugin-cff": {
|
||||||
"version": "0.6.1",
|
"version": "0.6.1",
|
||||||
"resolved": "https://registry.npmjs.org/@citation-js/plugin-cff/-/plugin-cff-0.6.1.tgz",
|
"resolved": "https://registry.npmjs.org/@citation-js/plugin-cff/-/plugin-cff-0.6.1.tgz",
|
||||||
@ -1213,6 +1231,21 @@
|
|||||||
"node": ">=14.0.0"
|
"node": ">=14.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@citation-js/plugin-csl": {
|
||||||
|
"version": "0.7.14",
|
||||||
|
"resolved": "https://registry.npmjs.org/@citation-js/plugin-csl/-/plugin-csl-0.7.14.tgz",
|
||||||
|
"integrity": "sha512-7AKB8lMz1IqdtoE33NnWIpteLYMuSl3xqT+Cax7sQKwAIJEoq2HBmb43Ja8xQQ36nREAupQJv1V6XksIAmYnCg==",
|
||||||
|
"dependencies": {
|
||||||
|
"@citation-js/date": "^0.5.0",
|
||||||
|
"citeproc": "^2.4.6"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=16.0.0"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"@citation-js/core": "^0.7.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@citation-js/plugin-github": {
|
"node_modules/@citation-js/plugin-github": {
|
||||||
"version": "0.6.1",
|
"version": "0.6.1",
|
||||||
"resolved": "https://registry.npmjs.org/@citation-js/plugin-github/-/plugin-github-0.6.1.tgz",
|
"resolved": "https://registry.npmjs.org/@citation-js/plugin-github/-/plugin-github-0.6.1.tgz",
|
||||||
@ -4820,6 +4853,11 @@
|
|||||||
"node": ">=8"
|
"node": ">=8"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/citeproc": {
|
||||||
|
"version": "2.4.63",
|
||||||
|
"resolved": "https://registry.npmjs.org/citeproc/-/citeproc-2.4.63.tgz",
|
||||||
|
"integrity": "sha512-68F95Bp4UbgZU/DBUGQn0qV3HDZLCdI9+Bb2ByrTaNJDL5VEm9LqaiNaxljsvoaExSLEXe1/r6n2Z06SCzW3/Q=="
|
||||||
|
},
|
||||||
"node_modules/cjs-module-lexer": {
|
"node_modules/cjs-module-lexer": {
|
||||||
"version": "1.4.1",
|
"version": "1.4.1",
|
||||||
"resolved": "https://registry.npmjs.org/cjs-module-lexer/-/cjs-module-lexer-1.4.1.tgz",
|
"resolved": "https://registry.npmjs.org/cjs-module-lexer/-/cjs-module-lexer-1.4.1.tgz",
|
||||||
@ -10380,6 +10418,11 @@
|
|||||||
"resolved": "https://registry.npmjs.org/module-alias/-/module-alias-2.2.3.tgz",
|
"resolved": "https://registry.npmjs.org/module-alias/-/module-alias-2.2.3.tgz",
|
||||||
"integrity": "sha512-23g5BFj4zdQL/b6tor7Ji+QY4pEfNH784BMslY9Qb0UnJWRAt+lQGLYmRaM0KDBwIG23ffEBELhZDP2rhi9f/Q=="
|
"integrity": "sha512-23g5BFj4zdQL/b6tor7Ji+QY4pEfNH784BMslY9Qb0UnJWRAt+lQGLYmRaM0KDBwIG23ffEBELhZDP2rhi9f/Q=="
|
||||||
},
|
},
|
||||||
|
"node_modules/moo": {
|
||||||
|
"version": "0.5.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/moo/-/moo-0.5.2.tgz",
|
||||||
|
"integrity": "sha512-iSAJLHYKnX41mKcJKjqvnAN9sf0LMDTXDEvFv+ffuRR9a1MIuXLjMNL6EsnDHSkKLTWNqQQ5uo61P4EbU4NU+Q=="
|
||||||
|
},
|
||||||
"node_modules/mri": {
|
"node_modules/mri": {
|
||||||
"version": "1.2.0",
|
"version": "1.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/mri/-/mri-1.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/mri/-/mri-1.2.0.tgz",
|
||||||
@ -14594,6 +14637,9 @@
|
|||||||
"tslib": "2.6.2",
|
"tslib": "2.6.2",
|
||||||
"typescript": "^5.2.2"
|
"typescript": "^5.2.2"
|
||||||
},
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"yaml": "^2.5.1"
|
||||||
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=18.0.0"
|
"node": ">=18.0.0"
|
||||||
}
|
}
|
||||||
@ -14631,6 +14677,18 @@
|
|||||||
"node": ">=14.17"
|
"node": ">=14.17"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"packages/config/node_modules/yaml": {
|
||||||
|
"version": "2.5.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/yaml/-/yaml-2.5.1.tgz",
|
||||||
|
"integrity": "sha512-bLQOjaX/ADgQ20isPJRvF0iRUHIxVhYvr53Of7wGcWlO2jvtUlH5m87DsmulFVxRpNLOnI4tB6p/oh8D7kpn9Q==",
|
||||||
|
"dev": true,
|
||||||
|
"bin": {
|
||||||
|
"yaml": "bin.mjs"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 14"
|
||||||
|
}
|
||||||
|
},
|
||||||
"packages/extension-mouse-tracking": {
|
"packages/extension-mouse-tracking": {
|
||||||
"name": "@jspsych/extension-mouse-tracking",
|
"name": "@jspsych/extension-mouse-tracking",
|
||||||
"version": "1.1.0",
|
"version": "1.1.0",
|
||||||
|
@ -55,6 +55,8 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@citation-js/core": "^0.7.14",
|
"@citation-js/core": "^0.7.14",
|
||||||
"@citation-js/plugin-software-formats": "^0.6.1",
|
"@citation-js/plugin-software-formats": "^0.6.1",
|
||||||
|
"@citation-js/plugin-bibtex": "^0.7.14",
|
||||||
|
"@citation-js/plugin-csl": "^0.7.14",
|
||||||
"symlink": "^2.1.0"
|
"symlink": "^2.1.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -66,5 +66,8 @@
|
|||||||
"jscodeshift": "0.16.1",
|
"jscodeshift": "0.16.1",
|
||||||
"inquirer": "10.1.6"
|
"inquirer": "10.1.6"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"yaml": "^2.5.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
|
import "@citation-js/plugin-bibtex";
|
||||||
import "@citation-js/plugin-software-formats";
|
import "@citation-js/plugin-software-formats";
|
||||||
|
import "@citation-js/plugin-csl";
|
||||||
|
|
||||||
import fs from "node:fs";
|
import fs from "node:fs";
|
||||||
import { extname } from "path";
|
import { extname } from "path";
|
||||||
@ -6,6 +8,7 @@ import { extname } from "path";
|
|||||||
import { Cite } from "@citation-js/core";
|
import { Cite } from "@citation-js/core";
|
||||||
import { createFilter } from "@rollup/pluginutils";
|
import { createFilter } from "@rollup/pluginutils";
|
||||||
import MagicString from "magic-string";
|
import MagicString from "magic-string";
|
||||||
|
import yaml from "yaml";
|
||||||
|
|
||||||
export default function cffToJsonPlugin() {
|
export default function cffToJsonPlugin() {
|
||||||
const options = { include: ["**/index*"], exclude: [], sourcemap: false };
|
const options = { include: ["**/index*"], exclude: [], sourcemap: false };
|
||||||
@ -17,39 +20,37 @@ export default function cffToJsonPlugin() {
|
|||||||
transform: function (code, id) {
|
transform: function (code, id) {
|
||||||
if (!filter(id) || (extname(id) !== ".js" && extname(id) !== ".ts")) return;
|
if (!filter(id) || (extname(id) !== ".js" && extname(id) !== ".ts")) return;
|
||||||
const magicString = new MagicString(code);
|
const magicString = new MagicString(code);
|
||||||
|
let preferredCitation = false;
|
||||||
|
|
||||||
// Try to find CITATION.cff file
|
// Try to find CITATION.cff file and look for preferred-citation
|
||||||
const citationCff = (() => {
|
const citationCff = (() => {
|
||||||
try {
|
try {
|
||||||
return fs.readFileSync("./CITATION.cff", "utf-8").toString();
|
const rawCff = fs.readFileSync("./CITATION.cff", "utf-8").toString();
|
||||||
|
const cffData = yaml.parse(rawCff);
|
||||||
|
if (cffData["preferred-citation"]) {
|
||||||
|
console.log("Found 'preferred-citation' in CITATION.cff");
|
||||||
|
preferredCitation = true;
|
||||||
|
} else {
|
||||||
|
console.log("No 'preferred-citation' found in CITATION.cff");
|
||||||
|
}
|
||||||
|
return yaml.stringify(rawCff);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(`Error finding CITATION.cff: ${error.message}`);
|
console.log(`Error finding CITATION.cff: ${error.message}`);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
||||||
// Try to convert CITATION.cff to JSON
|
|
||||||
const citationJson = (() => {
|
|
||||||
if (!citationCff) return null;
|
|
||||||
try {
|
|
||||||
return Cite(citationCff).format("data", {
|
|
||||||
format: "object",
|
|
||||||
lang: "en-us",
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
console.log(`Error converting CITATION.cff to JSON: ${error.message}`);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
})();
|
|
||||||
|
|
||||||
// Try to convert CITATION.cff to APA string
|
// Try to convert CITATION.cff to APA string
|
||||||
const citationApa = (() => {
|
const citationApa = (() => {
|
||||||
try {
|
try {
|
||||||
return Cite(citationJson).format("data", {
|
const apaCite = new Cite(citationCff);
|
||||||
format: "html",
|
apaCite["data"] = preferredCitation ? apaCite["data"].slice(1) : apaCite["data"];
|
||||||
template: "citation-apa",
|
const citationApa = apaCite.format("bibliography", {
|
||||||
|
format: "text",
|
||||||
|
template: "apa",
|
||||||
lang: "en-us",
|
lang: "en-us",
|
||||||
});
|
});
|
||||||
|
return citationApa;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(`Error converting CITATION.cff to APA string: ${error.message}`);
|
console.log(`Error converting CITATION.cff to APA string: ${error.message}`);
|
||||||
return null;
|
return null;
|
||||||
@ -58,14 +59,15 @@ export default function cffToJsonPlugin() {
|
|||||||
|
|
||||||
// Try to convert CITATION.cff to bibtex string
|
// Try to convert CITATION.cff to bibtex string
|
||||||
const citationBibtex = (() => {
|
const citationBibtex = (() => {
|
||||||
if (!citationJson) return null;
|
|
||||||
try {
|
try {
|
||||||
let bibtexCitation = Cite(citationJson).format("data", {
|
const bibtexCite = new Cite(citationCff);
|
||||||
format: "html",
|
bibtexCite["data"] = preferredCitation ? bibtexCite["data"].slice(1) : bibtexCite["data"];
|
||||||
template: "citation-bibtex",
|
const citationBibtex = bibtexCite.format("bibtex", {
|
||||||
|
format: "text",
|
||||||
|
template: "bibtex",
|
||||||
lang: "en-us",
|
lang: "en-us",
|
||||||
});
|
});
|
||||||
return bibtexCitation;
|
return citationBibtex;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(`Error converting CITATION.cff to bibtex string: ${error.message}`);
|
console.log(`Error converting CITATION.cff to bibtex string: ${error.message}`);
|
||||||
return null;
|
return null;
|
||||||
@ -76,11 +78,15 @@ export default function cffToJsonPlugin() {
|
|||||||
if (!citationApa && !citationBibtex) {
|
if (!citationApa && !citationBibtex) {
|
||||||
return { code: code };
|
return { code: code };
|
||||||
}
|
}
|
||||||
const citationString = `citation: { "apa": "${citationApa}", "bibtex": "${citationBibtex}" }`;
|
//console.log(`citation: {\napa: "${citationApa.replace(/\n/g, ' ')}", \nbibtex: "${citationBibtex.replace(/\n/g, ' ')}"\n}`);
|
||||||
|
const citationString = `citation:\n { apa: "${citationApa.replace(
|
||||||
|
/\n/g,
|
||||||
|
" "
|
||||||
|
)}",\n bibtex: "${citationBibtex.replace(/\n/g, " ")}"\n }`;
|
||||||
|
console.log(citationString);
|
||||||
const targetString = "citation: []";
|
const targetString = "citation: []";
|
||||||
const startIndex = code.indexOf(targetString);
|
const startIndex = code.indexOf(targetString);
|
||||||
if (startIndex !== -1) {
|
if (startIndex !== -1) {
|
||||||
console.log(citationApa);
|
|
||||||
magicString.overwrite(startIndex, startIndex + targetString.length, citationString);
|
magicString.overwrite(startIndex, startIndex + targetString.length, citationString);
|
||||||
return { code: magicString.toString() };
|
return { code: magicString.toString() };
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user