mirror of
https://github.com/jspsych/jsPsych.git
synced 2025-05-10 11:10:54 +00:00
move citation rollup plugin to config folder
This commit is contained in:
parent
1c5f826fbe
commit
bbd09e2ace
44
packages/config/rollup-plugin-build-citation.js
Normal file
44
packages/config/rollup-plugin-build-citation.js
Normal file
@ -0,0 +1,44 @@
|
||||
const fs = require("node:fs");
|
||||
const path = require("path");
|
||||
require("@citation-js/plugin-software-formats");
|
||||
const { Cite } = require("@citation-js/core");
|
||||
|
||||
function cffToJsonPlugin(options = {}) {
|
||||
return {
|
||||
name: "rollup-plugin-cff-to-json",
|
||||
version: "1.0.0",
|
||||
|
||||
generateBundle() {
|
||||
const srcDir = options.srcDir || __dirname;
|
||||
const indexFilePath = path.join(srcDir, "index.js"); // Assume index.js is in src
|
||||
|
||||
const updateCitations = (indexFilePath, citationJson) => {
|
||||
let fileContent = fs.readFileSync(indexFilePath, "utf-8");
|
||||
fileContent = fileContent.replace(/`{citationJson}`/g, citationJson);
|
||||
fs.writeFileSync(indexFilePath, fileContent, "utf-8");
|
||||
};
|
||||
|
||||
const templateDir = path.dirname(srcDir);
|
||||
const cffFilePath = path.join(templateDir, "CITATION.cff"); // Assume CITATION.cff is top level
|
||||
|
||||
try {
|
||||
let cffCitation = fs.readFileSync(cffFilePath, "utf-8").toString();
|
||||
Cite.async(cffCitation).then((data) => {
|
||||
const citationJson = JSON.stringify(
|
||||
data.format("data", {
|
||||
format: "object",
|
||||
lang: "en-US",
|
||||
}),
|
||||
null,
|
||||
2
|
||||
);
|
||||
updateCitations(indexFilePath, citationJson);
|
||||
});
|
||||
} catch (error) {
|
||||
this.error(`Error building citation from CITATION.cff: ${error.message}`);
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = cffToJsonPlugin;
|
@ -9,6 +9,8 @@ import esbuild from "rollup-plugin-esbuild";
|
||||
import externals from "rollup-plugin-node-externals";
|
||||
import ts from "typescript";
|
||||
|
||||
import cffToJsonPlugin from "./rollup-plugin-build-citation";
|
||||
|
||||
const getTsCompilerOptions = () => {
|
||||
const cwd = process.cwd();
|
||||
return ts.parseJsonConfigFileContent(
|
||||
|
Loading…
Reference in New Issue
Block a user