1
0
mirror of https://github.com/tcgdex/cards-database.git synced 2025-06-13 16:19:18 +00:00

Maintenance work

Signed-off-by: Avior <github@avior.me>
This commit is contained in:
2021-10-11 15:18:10 +02:00
parent 146aad93fa
commit 83705dd880
5 changed files with 11 additions and 13 deletions

102
meta/codeshift.ts Normal file
View File

@ -0,0 +1,102 @@
import { ArrayExpression, Identifier, JSCodeshift, Literal, ObjectExpression, Property, Transform } from "jscodeshift";
interface ObjectField {
type: 'Object'
items: Record<string, Field>
item: ObjectExpression
}
interface EndField {
type: 'Literal'
item: Literal
}
interface ArrayField {
type: 'Array'
items: Array<Field>
item: ArrayExpression
}
type Field = ObjectField | EndField | ArrayField
type Possible = ObjectExpression | ArrayExpression | Literal
function processItem(value: Possible): Field {
if (value.type === 'ObjectExpression') {
return simplify(value)
} else if (value.type === 'ArrayExpression') {
const field: Field = {
type: 'Array',
items: [],
item: value
}
value.elements.forEach((it) => {
field.items.push(processItem(it as Possible))
})
return field
} else {
return {
type: 'Literal',
item: value
}
}
}
function simplify(base: ObjectExpression): ObjectField {
const list: ObjectField['items'] = {}
base.properties.forEach((it) => {
const item = it as Property
const key = (item.key as Identifier).name
list[key] = processItem(item.value as Possible)
})
return {
type: 'Object',
items: list,
item: base
}
}
function set(j: JSCodeshift, path: ObjectExpression | ArrayExpression, value: Possible, key: string | number, options?: {override?: boolean}) {
let exists = false
if (path.type === 'ObjectExpression') {
path.properties.forEach((p) => {
const prop = p as Property
if ((prop.key as Identifier).name === (key + '')) {
exists = true
if (!options?.override) {
console.warn('Property already exist, add the option override to change it')
return
}
prop.value = value
}
})
if (exists) {return}
path.properties.push(j.property('init', j.identifier(key + ''), value))
} else {
}
}
/**
* Start editing here !
*/
const transformer: Transform = (file, api) => {
const j = api.jscodeshift
const root = j(file.source)
return root
.find(j.ObjectExpression)
.forEach((path, index) => {
if (index !== 0) return
let simplified = simplify(path.node)
// Example Set/Add regulationMArk to cards
set(j, simplified.item, j.literal('D'), 'regulationMark')
})
.toSource({useTabs: true, lineTerminator: '\n'}).replace(/ /g, ' ')
}
module.exports = transformer
module.exports.parser = 'ts'

106
meta/legals.ts Normal file
View File

@ -0,0 +1,106 @@
import { Filter } from '../interfaces'
/**
* File Explanation
*
* The main goal of this file is to update quickly the current list of authorized/banned cards in the standard and expanded formats
*
* For included cards/set/etc we are currently using the April post of each years (note: posts seems to be coming each April)
* - 2022: https://www.pokemon.com/us/pokemon-news/2022-pokemon-tcg-championship-series-season-format-rotation/
* - 2021: https://www.pokemon.com/us/pokemon-news/2021-season-pokemon-tcg-format-rotation/
* - 2020: https://www.pokemon.com/us/pokemon-news/2020-season-pokemon-tcg-format-rotation/
*
* For banned cards we are also following this webpage
* - https://www.pokemon.com/us/pokemon-tcg-banned-card-list/
*/
/**
* for each cards the compiler will check
* - if the card is in the `series` list
* - if the card is in the `sets` list
* - if the card is in the `regulationMark` list
*
* then it will check if the card is currently excluded
* - if the card is in the `sets` list
* - if the card is in the `cards` list
*/
export const standard: Filter = {
includes: {
series: [],
sets: [],
regulationMark: ['D', 'E']
},
excludes: {
sets: [],
cards: []
}
}
export const expanded: Filter = {
includes: {
series: ['bw', 'xy', 'sm', 'swsh'],
sets: [],
regulationMark: []
},
excludes: {
sets: [],
cards: [
// BW
'bw3-67',
'bw5-110',
'bw9-101',
'bw9-115',
// XY
'xy1-124',
'xy2-23',
'xy4-99',
'xy4-118',
'xy5-133',
'xy5-158',
'xy6-77',
'xy6-106',
'xy7-74',
'xy7-75',
'xy9-98',
'xy9-109',
'g1-71',
// SM
'smp-SM85',
'sm35-45',
'sm5-114',
'sm6-83',
'sm8-90',
'sm8-91',
'sm10-78',
'sm10-165',
'sm10-178',
'sm11-206',
'sm11-253',
'sm115-58',
'sm115-68',
'sm12-186',
'sm12-194',
'sm12-265',
]
}
}