File reorganisation

Signed-off-by: Avior <github@avior.me>
This commit is contained in:
Florian Bouillon 2021-06-22 16:51:27 +02:00
parent f28fa11710
commit 4789c15c7d
Signed by: Florian Bouillon
GPG Key ID: 50BD648F12C86AB6
14 changed files with 1715 additions and 61 deletions

8
.gitignore vendored
View File

@ -1,8 +1,6 @@
# Dev Files
node_modules
test.ts
# Dist files
*.js
*.d.ts
!interfaces.d.ts
!main.d.ts
test.ts
dist

View File

@ -1,8 +1,8 @@
src
.editorconfig
.gitignore
.npmignore
tsconfig.json
*.ts
webpack.config.js
tsconfig.*
yarn.lock
test.js
test.d.ts
CHANGELOG.md

View File

@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
## [2.2.0] - 2021-06-19
### Added
- Added new fields
## [2.1.1] - 2021-05-31
### Fixed

4
main.d.ts vendored
View File

@ -1,4 +0,0 @@
import TCGdex from './tcgdex'
export * from './interfaces'
export default TCGdex

View File

@ -1,26 +1,44 @@
{
"name": "@tcgdex/sdk",
"version": "2.2.0",
"main": "./tcgdex.js",
"types": "./main.d.ts",
"main": "./dist/cjs/tcgdex.js",
"module": "./dist/modules/tcgdex.js",
"types": "./dist/types/tcgdex.d.ts",
"repository": "https://github.com/tcgdex/javascript-sdk.git",
"license": "MIT",
"devDependencies": {
"@parcel/packager-ts": "2.0.0-beta.2",
"@types/node-fetch": "^2.5.10",
"awesome-typescript-loader": "^5.2.1",
"ts-node": "^10.0.0",
"typescript": "^4.1.3"
"typescript": "^4.1.3",
"webpack": "^5.40.0",
"webpack-nano": "^1.1.1"
},
"dependencies": {
"isomorphic-unfetch": "^3.1.0"
"node-fetch": "^2.6.1",
"unfetch": "^4.2.0"
},
"scripts": {
"build": "tsc --project tsconfig.json",
"build": "yarn build:cjs && yarn build:browser && yarn build:es2015",
"build:cjs": "tsc --project tsconfig.json",
"build:es2015": "tsc --project tsconfig.es2015.json",
"build:browser": "wp --config webpack.config.js",
"prepublishOnly": "yarn build"
},
"files": [
"*.js",
"*.d.ts",
"**/*.js",
"**/*.d.ts"
]
"dist"
],
"sideEffects": false,
"targets": {
"browser": {
"context": "browser",
"engines": {
"browsers": "since 2017-06"
},
"includeNodeModules": true,
"optimize": false,
"scopeHoist": false
}
}
}

View File

@ -1,5 +1,4 @@
import fetch from 'isomorphic-unfetch'
import { version, name } from './package.json'
import TCGdex from './tcgdex'
export default class RequestWrapper {
private static cache: Array<Request<any>> = []
@ -36,9 +35,10 @@ export class Request<T = any> {
}
// Fetch Response
const resp = await fetch(this.url, {
const unfetch = TCGdex.fetch
const resp = await unfetch(this.url, {
headers: {
'user-agent': `${name}/${version}`
'user-agent': `@tcgdex/javascript-sdk/${TCGdex.VERSION}`
}
})
if (resp.status !== 200) {

View File

@ -2,7 +2,7 @@ export type SupportedLanguages = 'en' | 'fr'
export type Languages<T = string> = Partial<Record<SupportedLanguages, T>>
interface SerieResume {
export interface SerieResume {
id: string
name: string
}
@ -22,7 +22,7 @@ export type SetList = Array<SetResume>
export type SerieList = Array<SerieResume>
export type CardList = Array<CardResume>
interface SetResume {
export interface SetResume {
id: string
name: string
logo?: string
@ -94,7 +94,7 @@ export interface Set extends SetResume {
cards: CardList
}
interface CardResume {
export interface CardResume {
id: string
localId: string

7
src/tcgdex.browser.ts Normal file
View File

@ -0,0 +1,7 @@
import TCGdex from './tcgdex'
import unfetch from 'unfetch'
TCGdex.fetch = unfetch as any
export default TCGdex
export * from './tcgdex'

7
src/tcgdex.node.ts Normal file
View File

@ -0,0 +1,7 @@
import TCGdex from './tcgdex'
import fetch from 'node-fetch'
TCGdex.fetch = fetch as any
export default TCGdex
export * from './tcgdex'

View File

@ -1,12 +1,16 @@
import RequestWrapper from './Request'
import { Serie, Set, Card, CardResume, SerieList, SetList, SupportedLanguages, StringEndpoint } from './interfaces'
type Endpoint = 'cards' | 'categories' | 'hp' | 'illustrators' | 'rarities' | 'retreats' | 'series' | 'sets' | 'types'
const ENDPOINTS: Array<Endpoint> = ['cards', 'categories', 'hp', 'illustrators', 'rarities', 'retreats', 'series', 'sets', 'types']
const BASE_URL = 'https://api.tcgdex.net/v2'
export default class TCGdex {
public static fetch: typeof fetch
public static readonly VERSION = "2.2.0"
/**
* @deprecated to change the lang use `this.lang`
*/
@ -169,3 +173,5 @@ export default class TCGdex {
return RequestWrapper.getRequest<T>(`${BASE_URL}/${this.getLang()}/${path}`).get()
}
}
export * from './interfaces'

11
tsconfig.es2015.json Normal file
View File

@ -0,0 +1,11 @@
{
"extends": "./tsconfig.json",
"include": ["./src/tcgdex.node.ts"],
"compilerOptions": {
"target": "ES2020", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
"module": "ES2015", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
"declaration": false, /* Generates corresponding '.d.ts' file. */
"declarationDir": null,
"outDir": "./dist/modules", /* Redirect output structure to the directory. */
}
}

View File

@ -1,22 +1,21 @@
{
"include": ["**/*.ts"],
"exclude": ["translations"],
"include": ["./src/tcgdex.node.ts"],
"compilerOptions": {
/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"target": "ES5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
"target": "ES2020", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
// "lib": [], /* Specify library files to be included in the compilation. */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
"declaration": true, /* Generates corresponding '.d.ts' file. */
// "declarationDir": "types", /* Folder where the declarations are*/
"declarationDir": "./dist/types", /* Folder where the declarations are*/
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
// "sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
// "outDir": "./", /* Redirect output structure to the directory. */
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
"outDir": "./dist/cjs", /* Redirect output structure to the directory. */
"rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "composite": true, /* Enable project compilation */
// "tsBuildInfoFile": "", /* Specify file to store incremental compilation information */
// "removeComments": true, /* Do not emit comments to output. */
@ -26,24 +25,24 @@
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
/* Strict Type-Checking Options */
"strict": true, /* Enable all strict type-checking options. */
"noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
"strictNullChecks": true, /* Enable strict null checks. */
"strictFunctionTypes": true, /* Enable strict checking of function types. */
"strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
"strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
"noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
"alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
"noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
"strictNullChecks": true, /* Enable strict null checks. */
"strictFunctionTypes": true, /* Enable strict checking of function types. */
"strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
"strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
"noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
"alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
/* Additional Checks */
"noUnusedLocals": true, /* Report errors on unused locals. */
"noUnusedParameters": true, /* Report errors on unused parameters. */
"noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
"noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
"noUnusedLocals": true, /* Report errors on unused locals. */
"noUnusedParameters": true, /* Report errors on unused parameters. */
"noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
"noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
/* Module Resolution Options */
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
@ -61,7 +60,7 @@
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
/* Experimental Options */
"experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
"emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
"experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
"emitDecoratorMetadata": true /* Enables experimental support for emitting type metadata for decorators. */
}
}
}

31
webpack.config.js Normal file
View File

@ -0,0 +1,31 @@
const path = require('path')
module.exports = {
mode: 'production',
entry: './src/tcgdex.browser.ts',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'tcgdex.browser.js',
libraryTarget: 'umd',
library: 'TCGdex',
umdNamedDefine: true
},
resolve: {
extensions: ['.ts']
},
optimization: {
minimize: true
},
module: {
rules: [{
test: /\.ts$/,
loader: 'awesome-typescript-loader',
exclude: /node_modules/,
options: {
sourceMap: false,
declarationDir: false,
target: 'ES2016'
}
}]
}
}

1591
yarn.lock

File diff suppressed because it is too large Load Diff