Skip to content

Commit

Permalink
chore: ts setup, fix ts-sdk issues (#1395)
Browse files Browse the repository at this point in the history
  • Loading branch information
emmenko authored Sep 9, 2019
1 parent ba49914 commit 4dfe320
Show file tree
Hide file tree
Showing 167 changed files with 13,802 additions and 15,514 deletions.
4 changes: 3 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
package-lock.json
credentials.js
package.json
**/dist/
**/lib/
7 changes: 6 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{
"eslint.validate": [
"javascript",
"typescript"
],
"flow.useNPMPackagedFlow": true,
"javascript.validate.enable": false
"javascript.validate.enable": false,
"typescript.tsdk": "node_modules/typescript/lib"
}
9 changes: 9 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,13 @@ module.exports = {
['@babel/plugin-proposal-pipeline-operator', { proposal: 'minimal' }],
'@babel/plugin-proposal-nullish-coalescing-operator',
],
overrides: [
{
test: ['./src/**/*.ts'],
presets: [
'@babel/preset-typescript',
['@babel/preset-env', getPresets()],
],
},
],
}
2 changes: 1 addition & 1 deletion husky.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
hooks: {
'commit-msg': 'commitlint -e $HUSKY_GIT_PARAMS',
'pre-commit': 'lint-staged',
'pre-commit': 'yarn typecheck:ts && lint-staged',
},
}
2 changes: 1 addition & 1 deletion jest.eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
runner: 'jest-runner-eslint',
displayName: 'eslint',
testMatch: ['<rootDir>/packages/**/*.js'],
testMatch: ['<rootDir>/packages/**/*.js', '<rootDir>/packages/**/*.ts'],
}
3 changes: 3 additions & 0 deletions jest.test.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ module.exports = {
},
transform: {
'^.+\\.js$': '<rootDir>/jest.transform.js',
'^.+\\.ts?$': '<rootDir>/node_modules/babel-jest',
},
testRegex: '\\.spec\\.(js|ts)$',
moduleFileExtensions: ['ts', 'js'],
testPathIgnorePatterns: [
'/node_modules/',
'/integration-tests/',
Expand Down
14 changes: 11 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
"test:package": "cross-env NODE_ENV=development ./scripts/test-package",
"pretest:integration": "./scripts/install-npm-packages-for-integration-tests",
"test:integration": "cross-env NODE_ENV=development jest --config integration-tests/jest.test.config.js",
"format": "npm run format:js & npm run format:md",
"format:js": "prettier --write '{packages,integration-tests,types}/**/*.js'",
"format": "npm run format:js && npm run format:md",
"format:js": "prettier --write '{packages,integration-tests,types}/**/*.{js,ts}'",
"format:md": "prettier --parser markdown --write '**/*.md'",
"test:coverage": "npm run build && npm test -- --no-watchman --coverage",
"test:ci": "npm run test -- --ci --no-watchman --maxWorkers=10",
Expand All @@ -33,7 +33,9 @@
"docs:build": "npm run docs:prepare && gitbook build && cp logo/apple-touch-icon.png _book/gitbook/images/apple-touch-icon-precomposed-152.png && cp logo/favicon.ico _book/gitbook/images",
"docs:watch": "npm run docs:prepare && gitbook serve",
"docs:publish": "npm run docs:clean && npm run docs:build && ./scripts/publish-docs",
"typecheck": "yarn typecheck:flow && yarn typecheck:ts",
"typecheck:flow": "flow check --include-warnings",
"typecheck:ts": "tsc --noEmit",
"generate:todos": "leasot -x 'packages/*/(src|test)/**/**.js'",
"build:todos": "leasot -x --reporter markdown 'packages/*/(src|test)/**/**.js' > TODOS.md",
"package-readme-entry": "./scripts/package-readme-entry.sh"
Expand All @@ -54,7 +56,11 @@
"@babel/preset-typescript": "7.3.3",
"@commitlint/cli": "8.0.0",
"@commitlint/config-conventional": "8.0.0",
"@types/node": "12.6.1",
"@types/jest": "24.0.18",
"@types/node": "10.14.17",
"@types/node-fetch": "2.5.0",
"@typescript-eslint/eslint-plugin": "2.1.0",
"@typescript-eslint/parser": "2.1.0",
"babel-core": "7.0.0-bridge.0",
"babel-eslint": "10.0.2",
"babel-jest": "23.6.0",
Expand All @@ -70,6 +76,8 @@
"eslint-config-airbnb-base": "13.2.0",
"eslint-config-prettier": "6.0.0",
"eslint-formatter-pretty": "2.1.1",
"eslint-import-resolver-typescript": "1.1.1",
"eslint-plugin-babel": "5.3.0",
"eslint-plugin-flowtype": "3.11.1",
"eslint-plugin-import": "2.18.0",
"eslint-plugin-jest": "22.7.2",
Expand Down
3 changes: 0 additions & 3 deletions packages/api-request-builder/src/create-request-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ export default function createRequestBuilder(
const allServices = { ...services, ...options.customServices }

return Object.keys(allServices).reduce(
// a return type object is not allowed in flow due to a bug (https://github.com/facebook/flow/issues/5182)
/* eslint-disable-next-line */
// $FlowFixMe
(acc: {}, key: string) => ({
...acc,
[key]: createService(allServices[key], options.projectKey),
Expand Down
46 changes: 46 additions & 0 deletions packages/typescript-sdk/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
module.exports = {
parser: '@typescript-eslint/parser',
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:import/typescript',
'plugin:jest/recommended',
'prettier',
'prettier/@typescript-eslint',
],
plugins: ['import', 'jest', 'prettier', '@typescript-eslint/eslint-plugin'],
env: {
es6: true,
browser: true,
jest: true,
node: true,
},
rules: {
'@typescript-eslint/camelcase': 0,
'@typescript-eslint/consistent-type-definitions': 0,
'@typescript-eslint/explicit-function-return-type': 0,
'@typescript-eslint/no-explicit-any': 2,
'@typescript-eslint/no-use-before-define': ['error', { functions: false }],
'@typescript-eslint/no-var-requires': 0,
'@typescript-eslint/unbound-method': 0,
'import/no-extraneous-dependencies': 0,
'import/no-named-as-default': 0,
'import/no-unresolved': 2,

// Specific for the generated SDK
'import/no-duplicates': 0,
'import/no-cycle': 0,
'spaced-comment': 0
},
settings: {
'import/parsers': {
'@typescript-eslint/parser': ['.ts'],
},
'import/resolver': {
'eslint-import-resolver-typescript': true,
typescript: {},
node: {
extensions: ['.js', '.ts'],
},
},
},
}
41 changes: 0 additions & 41 deletions packages/typescript-sdk/babel.config.js

This file was deleted.

28 changes: 14 additions & 14 deletions packages/typescript-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,28 @@
"bugs": "https://github.com/commercetools/nodejs/issues",
"license": "MIT",
"author": "Beniasaad Achraf <[email protected]> (https://github.com/acbeni)",
"main": "lib/typescript-sdk.cjs.js",
"module": "lib/typescript-sdk.es.js",
"browser": "lib/typescript-sdk.umd.js",
"types": "lib/types/index.d.ts",
"main": "dist/typescript-sdk.cjs.js",
"module": "dist/typescript-sdk.es.js",
"browser": "dist/typescript-sdk.umd.js",
"typings": "./dist/typings/index.d.ts",
"types": "./dist/typings/index.d.ts",
"repository": {
"type": "git",
"url": "https://github.com/commercetools/nodejs.git"
},
"files": [
"lib"
"dist"
],
"scripts": {
"type-check": "tsc --noEmit",
"build:types": "tsc --emitDeclarationOnly",
"prebuild": "rimraf -rf lib && npm run build:types",
"build": "cross-env npm run build:umd && npm run build:umd:min && npm run build:es && npm run build:cjs",
"build:umd": "cross-env NODE_ENV=rollup rollup -c ../../rollup.config.js -f umd -n TypescriptSdk -i ./src/index.ts -o lib/typescript-sdk.umd.js",
"build:umd:min": "cross-env NODE_ENV=production rollup -c ../../rollup.config.js -f umd -n TypescriptSdk -i ./src/index.ts -o lib/typescript-sdk.umd.min.js",
"build:es": "cross-env NODE_ENV=rollup rollup -c ../../rollup.config.js -f es -n TypescriptSdk -i ./src/index.ts -o lib/typescript-sdk.es.js",
"build:cjs": "cross-env NODE_ENV=rollup rollup -c ../../rollup.config.js -f cjs -n TypescriptSdk -i ./src/index.ts -o lib/typescript-sdk.cjs.js"
"prebuild": "rimraf dist/**",
"build": "cross-env yarn build:umd && yarn build:umd:min && yarn build:es && yarn build:cjs",
"build:umd": "cross-env NODE_ENV=rollup rollup -c ../../rollup.config.js -f umd -n TypescriptSdk -i ./src/index.ts -o dist/typescript-sdk.umd.js",
"build:umd:min": "cross-env NODE_ENV=production rollup -c ../../rollup.config.js -f umd -n TypescriptSdk -i ./src/index.ts -o dist/typescript-sdk.umd.min.js",
"build:es": "cross-env NODE_ENV=rollup rollup -c ../../rollup.config.js -f es -n TypescriptSdk -i ./src/index.ts -o dist/typescript-sdk.es.js",
"build:cjs": "cross-env NODE_ENV=rollup rollup -c ../../rollup.config.js -f cjs -n TypescriptSdk -i ./src/index.ts -o dist/typescript-sdk.cjs.js",
"build:typings": "tsc -p tsconfig.declarations.json --emitDeclarationOnly --declarationDir dist/typings"
},
"dependencies": {
"regenerator-runtime": "^0.13.2"
}
}
}
44 changes: 23 additions & 21 deletions packages/typescript-sdk/src/gen/base/common-types.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
export type MethodType =
| "GET"
| "HEAD"
| "POST"
| "PUT"
| "DELETE"
| "CONNECT"
| "OPTIONS"
| "TRACE";
| 'GET'
| 'HEAD'
| 'POST'
| 'PUT'
| 'DELETE'
| 'CONNECT'
| 'OPTIONS'
| 'TRACE'

export type VariableMap = { [key: string]: string | number | boolean | undefined }
export type VariableMap = {
[key: string]: string | number | boolean | undefined
}

export type MiddlewareArg = {
request: ClientRequest;
response?: ClientResponse<any>;
error?: Error;
next: Middleware;
};
request: ClientRequest
response?: ClientResponse<any>
error?: Error
next: Middleware
}

export type ClientRequest = {
uri: string,
method: MethodType,
body?: any,
headers?: VariableMap,
uri: string
method: MethodType
body?: any
headers?: VariableMap
}

export type ClientResponse<T> = {
body: T,
statusCode?: number,
body: T
statusCode?: number
headers?: Object
}

export type Middleware = (arg: MiddlewareArg) => Promise<MiddlewareArg>;
export type Middleware = (arg: MiddlewareArg) => Promise<MiddlewareArg>
18 changes: 9 additions & 9 deletions packages/typescript-sdk/src/gen/base/local-common-types.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { MethodType, VariableMap } from "./common-types";
import { MethodType, VariableMap } from './common-types'

export interface CommonRequest<T> {
baseURL: string;
url?: string,
headers?: VariableMap;
method: MethodType;
uriTemplate: string;
pathVariables?: VariableMap;
queryParams?: VariableMap;
baseURL: string
url?: string
headers?: VariableMap
method: MethodType
uriTemplate: string
pathVariables?: VariableMap
queryParams?: VariableMap
body?: T
}
}
Loading

0 comments on commit 4dfe320

Please sign in to comment.