From 053b775e49bd0ce90295c768732b146dd36190b1 Mon Sep 17 00:00:00 2001 From: Gao Sun Date: Mon, 28 Jun 2021 01:16:28 +0800 Subject: [PATCH] Use essentials --- packages/schemas/.prettierrc | 5 ----- packages/schemas/.xo-config.json | 7 ------- packages/schemas/package.json | 11 +++++++---- packages/schemas/src/gen/index.ts | 15 +++++---------- packages/schemas/src/gen/utils.ts | 6 +----- packages/schemas/src/global.ts | 1 - packages/schemas/tsconfig.json | 17 ++++------------- packages/schemas/xo.config.js | 1 + packages/schemas/yarn.lock | 18 ++++++++++++++++++ 9 files changed, 36 insertions(+), 45 deletions(-) delete mode 100644 packages/schemas/.prettierrc delete mode 100644 packages/schemas/.xo-config.json delete mode 100644 packages/schemas/src/global.ts create mode 100644 packages/schemas/xo.config.js diff --git a/packages/schemas/.prettierrc b/packages/schemas/.prettierrc deleted file mode 100644 index fed742a7a..000000000 --- a/packages/schemas/.prettierrc +++ /dev/null @@ -1,5 +0,0 @@ -{ - "printWidth": 100, - "trailingComma": "es5", - "bracketSpacing": true -} diff --git a/packages/schemas/.xo-config.json b/packages/schemas/.xo-config.json deleted file mode 100644 index 7116a679b..000000000 --- a/packages/schemas/.xo-config.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "space": true, - "prettier": true, - "rules": { - "unicorn/no-array-reduce": "off" - } -} diff --git a/packages/schemas/package.json b/packages/schemas/package.json index 804652301..1d1da077e 100644 --- a/packages/schemas/package.json +++ b/packages/schemas/package.json @@ -5,18 +5,20 @@ "repository": "https://github.com/logto-io/schemas", "author": "Logto", "license": "UNLICENSED", - "files": ["lib"], + "files": [ + "lib" + ], "scripts": { "generate": "ts-node src/gen/index.ts", "build": "yarn generate && rm -rf lib/ && tsc --p tsconfig.build.json", - "lint": "xo src/", - "prepare": "yarn build" + "lint": "xo src/" }, "engines": { "node": "14", "yarn": "1" }, "devDependencies": { + "@logto/essentials": "^1.0.2", "@types/node": "14", "@types/pluralize": "^0.0.29", "camelcase": "^6.2.0", @@ -24,5 +26,6 @@ "ts-node": "^10.0.0", "typescript": "^4.3.4", "xo": "0.39.1" - } + }, + "prettier": "@logto/essentials/.prettierrc.json" } diff --git a/packages/schemas/src/gen/index.ts b/packages/schemas/src/gen/index.ts index 869c34ab8..52948bec6 100644 --- a/packages/schemas/src/gen/index.ts +++ b/packages/schemas/src/gen/index.ts @@ -3,14 +3,9 @@ import camelcase from 'camelcase'; import fs from 'fs/promises'; import path from 'path'; import pluralize from 'pluralize'; +import { conditionalString } from '@logto/essentials'; -import { - conditionalString, - findFirstParentheses, - getType, - normalizeWhitespaces, - removeParentheses, -} from './utils'; +import { findFirstParentheses, getType, normalizeWhitespaces, removeParentheses } from './utils'; type Field = { name: string; @@ -98,10 +93,10 @@ const generate = async () => { '', `export const ${camelcase(name, { pascalCase: true })} = Object.freeze({`, ` table: '${name}',`, - ` fields: {`, + ' fields: {', ...fields.map(({ name }) => ` ${camelcase(name)}: '${name}',`), - ` },`, - `} as const);`, + ' },', + '} as const);', ].join('\n') ) .join('\n') + diff --git a/packages/schemas/src/gen/utils.ts b/packages/schemas/src/gen/utils.ts index ac3d41e13..223f2a2bb 100644 --- a/packages/schemas/src/gen/utils.ts +++ b/packages/schemas/src/gen/utils.ts @@ -1,8 +1,4 @@ -import { Optional } from '../global'; - -export type Falsy = 0 | undefined | null | false | ''; - -export const conditionalString = (value: string | Falsy): string => (value ? value : ''); +import { Optional } from '@logto/essentials'; export const normalizeWhitespaces = (string: string): string => string.replace(/\s+/g, ' ').trim(); diff --git a/packages/schemas/src/global.ts b/packages/schemas/src/global.ts deleted file mode 100644 index 964b0f2e2..000000000 --- a/packages/schemas/src/global.ts +++ /dev/null @@ -1 +0,0 @@ -export type Optional = T | undefined; diff --git a/packages/schemas/tsconfig.json b/packages/schemas/tsconfig.json index 37e3426e9..138534822 100644 --- a/packages/schemas/tsconfig.json +++ b/packages/schemas/tsconfig.json @@ -1,17 +1,8 @@ { + "extends": "@logto/essentials/tsconfig.base", "compilerOptions": { - "target": "es2021", - "esModuleInterop": true, - "allowSyntheticDefaultImports": true, - "strict": true, - "forceConsistentCasingInFileNames": true, - "noFallthroughCasesInSwitch": true, - "module": "commonjs", - "moduleResolution": "node", - "declaration": true, - "outDir": "lib" + "outDir": "lib", + "declaration": true }, - "include": [ - "src" - ] + "include": ["src"] } diff --git a/packages/schemas/xo.config.js b/packages/schemas/xo.config.js new file mode 100644 index 000000000..9a8c91c1c --- /dev/null +++ b/packages/schemas/xo.config.js @@ -0,0 +1 @@ +module.exports = require("@logto/essentials/.xo-config.json"); diff --git a/packages/schemas/yarn.lock b/packages/schemas/yarn.lock index 1ae3a3aac..03a528321 100644 --- a/packages/schemas/yarn.lock +++ b/packages/schemas/yarn.lock @@ -232,6 +232,14 @@ minimatch "^3.0.4" strip-json-comments "^3.1.1" +"@logto/essentials@^1.0.2": + version "1.0.2" + resolved "https://registry.yarnpkg.com/@logto/essentials/-/essentials-1.0.2.tgz#02a8c878b4079a63709c35ce8c143370f259bb13" + integrity sha512-GN6m1c5ll7EhOgJbmFwRESkeWGjdoihst8O1aVIxvEOXhLe/79bph4hejsdm59piX3jgKWakEHimpqcBT1kO+Q== + dependencies: + lodash.orderby "^4.6.0" + lodash.pick "^4.4.0" + "@mrmlnc/readdir-enhanced@^2.2.1": version "2.2.1" resolved "https://registry.yarnpkg.com/@mrmlnc/readdir-enhanced/-/readdir-enhanced-2.2.1.tgz#524af240d1a360527b730475ecfa1344aa540dde" @@ -2534,6 +2542,16 @@ lodash.merge@^4.6.2: resolved "https://registry.yarnpkg.com/lodash.merge/-/lodash.merge-4.6.2.tgz#558aa53b43b661e1925a0afdfa36a9a1085fe57a" integrity sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ== +lodash.orderby@^4.6.0: + version "4.6.0" + resolved "https://registry.yarnpkg.com/lodash.orderby/-/lodash.orderby-4.6.0.tgz#e697f04ce5d78522f54d9338b32b81a3393e4eb3" + integrity sha1-5pfwTOXXhSL1TZM4syuBozk+TrM= + +lodash.pick@^4.4.0: + version "4.4.0" + resolved "https://registry.yarnpkg.com/lodash.pick/-/lodash.pick-4.4.0.tgz#52f05610fff9ded422611441ed1fc123a03001b3" + integrity sha1-UvBWEP/53tQiYRRB7R/BI6AwAbM= + lodash.truncate@^4.4.2: version "4.4.2" resolved "https://registry.yarnpkg.com/lodash.truncate/-/lodash.truncate-4.4.2.tgz#5a350da0b1113b837ecfffd5812cbe58d6eae193"