0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-16 20:26:19 -05:00

chore: use shared config

This commit is contained in:
Gao Sun 2021-07-11 18:06:03 +08:00
parent 5eab0a878a
commit b432b10df0
No known key found for this signature in database
GPG key ID: 0F0EFA2E36639F31
5 changed files with 167 additions and 1876 deletions

View file

@ -9,9 +9,9 @@
"lib"
],
"scripts": {
"generate": "ts-node src/gen/index.ts && xo src/db-entries --fix",
"generate": "ts-node src/gen/index.ts && eslint --format pretty \"src/db-entries/**\" --fix",
"build": "yarn generate && rm -rf lib/ && tsc --p tsconfig.build.json",
"lint": "xo src/",
"lint": "eslint --format pretty \"src/**\"",
"prepare": "yarn build"
},
"engines": {
@ -19,16 +19,21 @@
"yarn": "^1.22.10"
},
"devDependencies": {
"@logto/essentials": "^1.1.0-rc.0",
"@logto/eslint-config": "^0.1.0-rc.6",
"@logto/essentials": "^1.1.0-rc.1",
"@logto/ts-config": "^0.1.0-rc.6",
"@types/lodash.uniq": "^4.5.6",
"@types/node": "14",
"@types/pluralize": "^0.0.29",
"camelcase": "^6.2.0",
"eslint": "^7.30.0",
"eslint-formatter-pretty": "^4.1.0",
"lodash.uniq": "^4.5.0",
"pluralize": "^8.0.0",
"prettier": "^2.3.2",
"ts-node": "^10.0.0",
"typescript": "^4.3.4",
"xo": "0.39.1"
"typescript": "^4.3.5"
},
"prettier": "@logto/essentials/.prettierrc.json"
"eslintConfig": { "extends": "@logto" },
"prettier": "@logto/eslint-config/.prettierrc"
}

View file

@ -1,7 +1,7 @@
import assert from 'assert';
import camelcase from 'camelcase';
import fs from 'fs/promises';
import path from 'path';
import camelcase from 'camelcase';
import pluralize from 'pluralize';
import uniq from 'lodash.uniq';
import { conditional, conditionalString } from '@logto/essentials';
@ -45,15 +45,17 @@ type FileData = {
tables: Table[];
};
const dir = 'tables';
const directory = 'tables';
const getOutputFileName = (file: string) => pluralize(file.slice(0, -4).replace(/_/g, '-'), 1);
const generate = async () => {
const files = await fs.readdir(dir);
const files = await fs.readdir(directory);
const generated = await Promise.all(
files
.filter((file) => file.endsWith('.sql'))
.map<Promise<[string, FileData]>>(async (file) => {
const statements = (await fs.readFile(path.join(dir, file), { encoding: 'utf-8' }))
const statements = (await fs.readFile(path.join(directory, file), { encoding: 'utf-8' }))
.split(';')
.map((value) => normalizeWhitespaces(value));
const tables = statements
@ -126,14 +128,13 @@ const generate = async () => {
})
);
const generatedDir = 'src/db-entries';
const generatedDirectory = 'src/db-entries';
const generatedTypesFilename = 'custom-types';
const tsTypesFilename = '../foundations';
const header = '// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.\n\n';
const getOutputFileName = (file: string) => pluralize(file.slice(0, -4).replace(/_/g, '-'), 1);
await fs.rmdir(generatedDir, { recursive: true });
await fs.mkdir(generatedDir, { recursive: true });
await fs.rmdir(generatedDirectory, { recursive: true });
await fs.mkdir(generatedDirectory, { recursive: true });
// Postgres custom types
const allTypes = generated
@ -146,7 +147,7 @@ const generate = async () => {
if (allTypes.length > 0) {
// Generate custom types
await fs.writeFile(
path.join(generatedDir, `${generatedTypesFilename}.ts`),
path.join(generatedDirectory, `${generatedTypesFilename}.ts`),
header +
allTypes
.map(({ tsName, values }) =>
@ -234,11 +235,11 @@ const generate = async () => {
)
.join('\n') +
'\n';
await fs.writeFile(path.join(generatedDir, getOutputFileName(file) + '.ts'), content);
await fs.writeFile(path.join(generatedDirectory, getOutputFileName(file) + '.ts'), content);
})
);
await fs.writeFile(
path.join(generatedDir, 'index.ts'),
path.join(generatedDirectory, 'index.ts'),
header +
conditionalString(allTypes.length > 0 && `export * from './${generatedTypesFilename}';\n`) +
generated.map(([file]) => `export * from './${getOutputFileName(file)}';`).join('\n') +

View file

@ -1,5 +1,5 @@
{
"extends": "@logto/essentials/tsconfig.base",
"extends": "@logto/ts-config/tsconfig.base",
"compilerOptions": {
"outDir": "lib",
"declaration": true

View file

@ -1 +0,0 @@
module.exports = require('@logto/essentials/.xo-config.json');

File diff suppressed because it is too large Load diff