@jspsych/config 3.1.1 → 3.2.0
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/CHANGELOG.md +10 -0
- package/generateCitations.js +94 -0
- package/package.json +11 -2
- package/rollup.js +23 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @jspsych/config
|
|
2
2
|
|
|
3
|
+
## 3.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#3385](https://github.com/jspsych/jsPsych/pull/3385) [`3948fdc0ac176584fe4b8fe0b9cca5ed6e8b3afc`](https://github.com/jspsych/jsPsych/commit/3948fdc0ac176584fe4b8fe0b9cca5ed6e8b3afc) Thanks [@cherriechang](https://github.com/cherriechang)! - Added citations property to info field of all plugins/extensions in two citation formats (apa, bibtex); added getCitations() as function in jsPsych package allowing user to generate citations by passing an array of plugins/extensions by name as first input and citation format as string as second input; changed template of plugins/extensions to contain citations field by default; citations for each plugin/extension are automatically generated from .cff file (if any) at its folder's root during build process; getCitations() prints out citations in the form of a string separating each citation with newline character, and always prints the jsPsych library citation first.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- [#3482](https://github.com/jspsych/jsPsych/pull/3482) [`a733fc685c8d1a3f1a9dea25bd4c70940885c6e9`](https://github.com/jspsych/jsPsych/commit/a733fc685c8d1a3f1a9dea25bd4c70940885c6e9) Thanks [@jodeleeuw](https://github.com/jodeleeuw)! - Fixes gulp build process that was attempting to use glob v10 by adding glob v7 as explicit dependency. glob v9+ changed the API and would require some rewrites and testing before implementing
|
|
12
|
+
|
|
3
13
|
## 3.1.1
|
|
4
14
|
|
|
5
15
|
### Patch Changes
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import "@citation-js/plugin-bibtex";
|
|
2
|
+
import "@citation-js/plugin-software-formats";
|
|
3
|
+
import "@citation-js/plugin-csl";
|
|
4
|
+
|
|
5
|
+
import fs from "node:fs";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
|
|
8
|
+
import { Cite } from "@citation-js/core";
|
|
9
|
+
import appRootPath from "app-root-path";
|
|
10
|
+
import yaml from "yaml";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Generate citation data from CITATION.cff file
|
|
14
|
+
* Currently supported formats: APA, BibTeX
|
|
15
|
+
*
|
|
16
|
+
* @returns {Object} - Object containing APA and BibTeX formatted citation data
|
|
17
|
+
*/
|
|
18
|
+
export default function generateCitations() {
|
|
19
|
+
let preferredCitation = false;
|
|
20
|
+
|
|
21
|
+
// Try to find CITATION.cff file and look for preferred-citation
|
|
22
|
+
const citationCff = (() => {
|
|
23
|
+
let rawCff;
|
|
24
|
+
const getCff = (path) => {
|
|
25
|
+
rawCff = fs.readFileSync(path, "utf-8").toString();
|
|
26
|
+
const cffData = yaml.parse(rawCff);
|
|
27
|
+
if (cffData["preferred-citation"]) {
|
|
28
|
+
preferredCitation = true;
|
|
29
|
+
}
|
|
30
|
+
return yaml.stringify(rawCff);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
try {
|
|
34
|
+
// look for CITATION.cff in the current directory
|
|
35
|
+
return getCff("./CITATION.cff");
|
|
36
|
+
} catch (error) {
|
|
37
|
+
try {
|
|
38
|
+
// look for CITATION.cff in the root of the repository
|
|
39
|
+
return getCff(path.join(appRootPath.path, "CITATION.cff"));
|
|
40
|
+
} catch (error) {
|
|
41
|
+
console.warn(
|
|
42
|
+
`No CITATION.cff file found: ${error.message}. If you would like to include a citation, please create a CITATION.cff file in the root of your repository.`
|
|
43
|
+
);
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
})();
|
|
48
|
+
|
|
49
|
+
if (!citationCff) {
|
|
50
|
+
return { apa: "", bibtex: "" };
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Convert CITATION.cff to APA string
|
|
54
|
+
const citationApa = (() => {
|
|
55
|
+
try {
|
|
56
|
+
const apaCite = new Cite(citationCff);
|
|
57
|
+
apaCite["data"] = preferredCitation ? apaCite["data"].slice(1) : apaCite["data"];
|
|
58
|
+
const citationApa = apaCite.format("bibliography", {
|
|
59
|
+
format: "text",
|
|
60
|
+
template: "apa",
|
|
61
|
+
lang: "en-us",
|
|
62
|
+
});
|
|
63
|
+
return citationApa;
|
|
64
|
+
} catch (error) {
|
|
65
|
+
console.log(`Error converting CITATION.cff to APA string: ${error.message}`);
|
|
66
|
+
return "";
|
|
67
|
+
}
|
|
68
|
+
})();
|
|
69
|
+
|
|
70
|
+
// Convert CITATION.cff to BibTeX string
|
|
71
|
+
const citationBibtex = (() => {
|
|
72
|
+
try {
|
|
73
|
+
const bibtexCite = new Cite(citationCff);
|
|
74
|
+
bibtexCite["data"] = preferredCitation ? bibtexCite["data"].slice(1) : bibtexCite["data"];
|
|
75
|
+
const citationBibtex = bibtexCite.format("bibtex", {
|
|
76
|
+
format: "text",
|
|
77
|
+
template: "bibtex",
|
|
78
|
+
lang: "en-us",
|
|
79
|
+
});
|
|
80
|
+
return citationBibtex;
|
|
81
|
+
} catch (error) {
|
|
82
|
+
console.log(`Error converting CITATION.cff to BibTeX string: ${error.message}`);
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
})();
|
|
86
|
+
|
|
87
|
+
// Return formatted citation data
|
|
88
|
+
const citationData = {
|
|
89
|
+
apa: citationApa.replace(/\n/g, " "),
|
|
90
|
+
bibtex: citationBibtex.replace(/\n/g, " "),
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
return citationData;
|
|
94
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jspsych/config",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"description": "Shared (build) configuration for jsPsych packages",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -35,14 +35,21 @@
|
|
|
35
35
|
},
|
|
36
36
|
"homepage": "https://www.jspsych.org/latest/developers/configuration",
|
|
37
37
|
"dependencies": {
|
|
38
|
+
"@citation-js/core": "^0.7.14",
|
|
39
|
+
"@citation-js/plugin-bibtex": "^0.7.14",
|
|
40
|
+
"@citation-js/plugin-csl": "^0.7.14",
|
|
41
|
+
"@citation-js/plugin-software-formats": "^0.6.1",
|
|
38
42
|
"@rollup/plugin-commonjs": "26.0.1",
|
|
39
43
|
"@rollup/plugin-node-resolve": "15.2.3",
|
|
44
|
+
"@rollup/plugin-replace": "^6.0.1",
|
|
40
45
|
"@sucrase/jest-plugin": "3.0.0",
|
|
41
46
|
"@types/gulp": "4.0.17",
|
|
42
47
|
"@types/jest": "29.5.8",
|
|
43
48
|
"alias-hq": "6.2.4",
|
|
49
|
+
"app-root-path": "^3.1.0",
|
|
44
50
|
"canvas": "^2.11.2",
|
|
45
51
|
"esbuild": "0.23.1",
|
|
52
|
+
"glob": "7.2.3",
|
|
46
53
|
"gulp": "5.0.0",
|
|
47
54
|
"gulp-cli": "3.0.0",
|
|
48
55
|
"gulp-file": "0.4.0",
|
|
@@ -55,9 +62,11 @@
|
|
|
55
62
|
"rollup": "4.21.2",
|
|
56
63
|
"rollup-plugin-dts": "6.1.1",
|
|
57
64
|
"rollup-plugin-esbuild": "6.1.1",
|
|
65
|
+
"rollup-plugin-modify": "^3.0.0",
|
|
58
66
|
"rollup-plugin-node-externals": "7.1.3",
|
|
59
67
|
"sucrase": "3.34.0",
|
|
60
68
|
"tslib": "2.6.2",
|
|
61
|
-
"typescript": "^5.2.2"
|
|
69
|
+
"typescript": "^5.2.2",
|
|
70
|
+
"yaml": "^2.5.1"
|
|
62
71
|
}
|
|
63
72
|
}
|
package/rollup.js
CHANGED
|
@@ -6,9 +6,12 @@ import resolve from "@rollup/plugin-node-resolve";
|
|
|
6
6
|
import { defineConfig } from "rollup";
|
|
7
7
|
import dts from "rollup-plugin-dts";
|
|
8
8
|
import esbuild from "rollup-plugin-esbuild";
|
|
9
|
+
import modify from "rollup-plugin-modify";
|
|
9
10
|
import externals from "rollup-plugin-node-externals";
|
|
10
11
|
import ts from "typescript";
|
|
11
12
|
|
|
13
|
+
import generateCitations from "./generateCitations.js";
|
|
14
|
+
|
|
12
15
|
const getTsCompilerOptions = () => {
|
|
13
16
|
const cwd = process.cwd();
|
|
14
17
|
return ts.parseJsonConfigFileContent(
|
|
@@ -38,6 +41,8 @@ const makeConfig = ({
|
|
|
38
41
|
...outputOptions,
|
|
39
42
|
};
|
|
40
43
|
|
|
44
|
+
const citationData = generateCitations();
|
|
45
|
+
|
|
41
46
|
/** @type{import("rollup-plugin-esbuild").Options} */
|
|
42
47
|
const esBuildPluginOptions = {
|
|
43
48
|
loaders: { ".json": "json" },
|
|
@@ -71,6 +76,11 @@ const makeConfig = ({
|
|
|
71
76
|
input,
|
|
72
77
|
plugins: [
|
|
73
78
|
externals(),
|
|
79
|
+
modify({
|
|
80
|
+
// prettier-ignore
|
|
81
|
+
find: /'__CITATIONS__'/g,
|
|
82
|
+
replace: JSON.stringify(citationData, null, 2),
|
|
83
|
+
}),
|
|
74
84
|
esbuild({ ...esBuildPluginOptions, target: "node18" }),
|
|
75
85
|
commonjs(commonjsPluginOptions),
|
|
76
86
|
],
|
|
@@ -96,6 +106,11 @@ const makeConfig = ({
|
|
|
96
106
|
input,
|
|
97
107
|
plugins: [
|
|
98
108
|
externals({ deps: false }),
|
|
109
|
+
modify({
|
|
110
|
+
// prettier-ignore
|
|
111
|
+
find: /'__CITATIONS__'/g,
|
|
112
|
+
replace: JSON.stringify(citationData, null, 2),
|
|
113
|
+
}),
|
|
99
114
|
resolve({ preferBuiltins: false }),
|
|
100
115
|
esbuild({ ...esBuildPluginOptions, target: "esnext" }),
|
|
101
116
|
commonjs(commonjsPluginOptions),
|
|
@@ -115,6 +130,11 @@ const makeConfig = ({
|
|
|
115
130
|
input,
|
|
116
131
|
plugins: [
|
|
117
132
|
externals({ deps: false }),
|
|
133
|
+
modify({
|
|
134
|
+
// prettier-ignore
|
|
135
|
+
find: /'__CITATIONS__'/g,
|
|
136
|
+
replace: JSON.stringify(citationData, null, 2),
|
|
137
|
+
}),
|
|
118
138
|
resolve({ preferBuiltins: false }),
|
|
119
139
|
esbuild({ ...esBuildPluginOptions, target: "es2015", minify: true }),
|
|
120
140
|
commonjs(commonjsPluginOptions),
|
|
@@ -164,8 +184,9 @@ export const makeCoreRollupConfig = () =>
|
|
|
164
184
|
/**
|
|
165
185
|
* Returns the rollup configuration for Node.js-only packages
|
|
166
186
|
*/
|
|
167
|
-
export const makeNodeRollupConfig = () =>
|
|
168
|
-
makeConfig({
|
|
187
|
+
export const makeNodeRollupConfig = () => {
|
|
188
|
+
return makeConfig({
|
|
169
189
|
globalOptions: { external: ["jspsych"] },
|
|
170
190
|
isNodeOnlyBuild: true,
|
|
171
191
|
});
|
|
192
|
+
};
|