Skip to content

Commit

Permalink
Merge branch 'zotero:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
l0o0 authored Nov 6, 2023
2 parents 77114a7 + f4741ec commit 1e8fb4e
Show file tree
Hide file tree
Showing 98 changed files with 18,473 additions and 4,611 deletions.
6 changes: 3 additions & 3 deletions .ci/eslint-plugin-zotero-translator/bin/teslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

const fs = require('fs');
const path = require('path');
const find = require('recursive-readdir-synchronous');
const find = require('recursive-readdir');
const { ESLint } = require("eslint");
const argv = require('commander');

Expand Down Expand Up @@ -35,15 +35,15 @@ async function main() {
let allResults = [];

function findIgnore(file, stats) {
if (stats.isDirectory()) return (path.basename(file) == "node_modules");
if (stats.isDirectory()) return (path.basename(file) == "node_modules" || path.basename(file) == ".ci");
return !file.endsWith('.js');
}
for (const target of argv.args) {
if (!fs.existsSync(target)) {
console.error(`Target file '${target}' does not exist; skipping`); // eslint-disable-line no-console
continue;
}
const files = fs.lstatSync(target).isDirectory() ? find(target, [findIgnore]) : [target];
const files = fs.lstatSync(target).isDirectory() ? await find(target, [findIgnore]) : [target];
for (const file of files) {
if (path.dirname(path.resolve(file)) === translators.cache.repo) {
const translator = translators.cache.get(file);
Expand Down
13 changes: 10 additions & 3 deletions .ci/eslint-plugin-zotero-translator/lib/rules/test-cases.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,16 @@ module.exports = {
}
else if (testCase.type === 'search') {
// console.log(JSON.stringify(testCase.input))
const expected = ['DOI', 'ISBN', 'PMID', 'identifiers', 'contextObject', 'adsBibcode'];
if (!Object.keys(testCase.input).every(key => expected.includes(key))) {
let invalidKey = Object.keys(testCase.input).find(key => !expected.includes(key));
const expected = ['DOI', 'ISBN', 'PMID', 'identifiers', 'contextObject', 'adsBibcode', 'ericNumber'];
let keys;
if (Array.isArray(testCase.input)) {
keys = testCase.input.flatMap(Object.keys);
}
else {
keys = Object.keys(testCase.input);
}
if (!keys.every(key => expected.includes(key))) {
let invalidKey = keys.find(key => !expected.includes(key));
context.report({
message: `${prefix} of type "${testCase.type}" has invalid search term '${invalidKey}' - expected one of ${expected.join(', ')}`,
loc,
Expand Down
10 changes: 9 additions & 1 deletion .ci/eslint-plugin-zotero-translator/lib/translators.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@ const path = require('path');
const findRoot = require('find-root');
const childProcess = require('child_process');

const repo = path.resolve(findRoot(__dirname, dir => fs.existsSync(path.resolve(dir, '.git'))));
let repo;
try {
repo = path.resolve(findRoot(__dirname, dir => fs.existsSync(path.resolve(dir, '.git'))));
}
catch (e) {
console.error('ERROR: Translators can only be linted inside a clone of the zotero/translators repo (not a ZIP downloaded from GitHub)');
console.error(' git clone https://github.com/zotero/translators.git');
process.exit(1);
}

const metaDataRules = [
'zotero-translator/header-valid-json',
Expand Down
151 changes: 151 additions & 0 deletions .ci/eslint-plugin-zotero-translator/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .ci/eslint-plugin-zotero-translator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"dependencies": {
"commander": "^2.19.0",
"find-root": "^1.1.0",
"recursive-readdir-synchronous": "0.0.4",
"recursive-readdir": "^2.2.3",
"require-dir": "^1.2.0",
"uuid": "^3.3.2"
}
Expand Down
4 changes: 2 additions & 2 deletions .ci/pull-request-check/selenium-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ var allPassed = false;

// No API to retrieve extension ID. Hacks, sigh.
await driver.get("chrome://system/");
await driver.wait(until.elementLocated({id: 'extensions-value-btn'}), 60*1000);
await driver.wait(until.elementLocated({id: 'btn-extensions-value'}), 60*1000);
// Chrome 89+ has the extension list expanded by default
try {
let extBtn = await driver.findElement({css: '#extensions-value-btn'});
let extBtn = await driver.findElement({css: '#btn-extensions-value'});
await extBtn.click();
} catch (e) {}
let contentElem = await driver.findElement({css: '#content'});
Expand Down
75 changes: 75 additions & 0 deletions .ci/updateTypes.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/usr/bin/env node

import { readFile, writeFile } from 'fs/promises';

const INDEX_D_TS_URL = new URL('../index.d.ts', import.meta.url);
const SCHEMA_JSON_URL = new URL('../../zotero-client/resource/schema/global/schema.json', import.meta.url);

const BEGIN_MARKER = '\t/* *** BEGIN GENERATED TYPES *** */';
const END_MARKER = '\t/* *** END GENERATED TYPES *** */';

async function updateIndexDTS() {
let indexDTS = await readFile(INDEX_D_TS_URL, { encoding: 'utf8' });
let schema = JSON.parse(await readFile(SCHEMA_JSON_URL));

let typeItemTypes = '\ttype ItemTypes = {';
let itemTypeTypes = '';
let creatorTypes = new Set();

for (let typeSchema of schema.itemTypes) {
let itemType = typeSchema.itemType;
if (['annotation', 'attachment', 'note'].includes(itemType)) {
continue;
}

let itemTypeUppercase = itemType[0].toUpperCase() + itemType.substring(1) + 'Item';
if (itemTypeUppercase == 'TvBroadcastItem') {
itemTypeUppercase = 'TVBroadcastItem';
}

typeItemTypes += `\n\t\t"${itemType}": ${itemTypeUppercase},`;
itemTypeTypes += `\n\n\ttype ${itemTypeUppercase} = {`;
itemTypeTypes += `\n\t\titemType: "${itemType}";`;
for (let { field } of typeSchema.fields) {
itemTypeTypes += `\n\t\t${field}?: string;`
}

let creatorTypesJoined = typeSchema.creatorTypes.map(typeSchema => '"' + typeSchema.creatorType + '"').join(' | ');
itemTypeTypes += `\n\n\t\tcreators: Creator<${creatorTypesJoined}>[];`;
itemTypeTypes += '\n\t\tattachments: Attachment[];';
itemTypeTypes += '\n\t\ttags: Tag[];';
itemTypeTypes += '\n\t\tnotes: Note[];';
itemTypeTypes += '\n\t\tseeAlso: string[];';
itemTypeTypes += '\n\t\tcomplete(): void;';
itemTypeTypes += '\n\n\t\t[key: string]: string;';
itemTypeTypes += '\n\t};';

for (let { creatorType } of typeSchema.creatorTypes) {
creatorTypes.add(creatorType);
}
}
typeItemTypes += '\n\t};'

let typeCreatorType = '\n\ttype CreatorType =';
for (let creatorType of Array.from(creatorTypes).sort()) {
typeCreatorType += `\n\t\t| "${creatorType}"`;
}
typeCreatorType += ';';

let beginIdx = indexDTS.indexOf(BEGIN_MARKER);
let endIdx = indexDTS.indexOf(END_MARKER);
if (beginIdx == -1 || endIdx == -1) {
throw new Error('Could not find generated types section in index.d.ts');
}

indexDTS = indexDTS.substring(0, beginIdx) + BEGIN_MARKER + '\n'
+ typeItemTypes
+ itemTypeTypes
+ '\n' + typeCreatorType
+ '\n'
+ indexDTS.substring(endIdx);

await writeFile(INDEX_D_TS_URL, indexDTS);
}

updateIndexDTS();
5 changes: 1 addition & 4 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
{
"env": {
"browser": true,
"es2017": true
"es2018": true
},
"extends": [
"@zotero"
],
"parserOptions": {
"ecmaVersion": 2017
},
"globals": {
"Zotero": "readonly",
"Z": "readonly",
Expand Down
Loading

0 comments on commit 1e8fb4e

Please sign in to comment.