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

refactor: fix dev script

This commit is contained in:
Gao Sun 2022-10-13 14:39:09 +08:00
parent b0020efedc
commit 0843e8fdfc
No known key found for this signature in database
GPG key ID: 13EBE123E4773688
11 changed files with 31 additions and 24 deletions

1
packages/cli/.npmrc Normal file
View file

@ -0,0 +1 @@
enable-pre-post-scripts=true

View file

@ -19,7 +19,9 @@
},
"scripts": {
"precommit": "lint-staged",
"//": "Manually ln since `preserveSymlinks` in TSC doesn't work as expected",
"build": "rimraf lib && tsc -p tsconfig.build.json",
"postbuild": "unlink ./lib/package.json && ln -s ../package.json ./lib/package.json",
"start": "node .",
"start:dev": "ts-node --files src/index.ts",
"lint": "eslint --ext .ts src",

View file

@ -5,7 +5,6 @@ import { findPackage } from '@logto/shared';
import { conditionalString } from '@silverhand/essentials';
import chalk from 'chalk';
import { copy, existsSync, remove, readdir } from 'fs-extra';
import { SemVer } from 'semver';
import { DatabasePool } from 'slonik';
import { CommandModule } from 'yargs';
@ -30,12 +29,6 @@ const getTimestampFromFilename = (filename: string) => {
return Number(match[1]);
};
const getVersionFromFilename = (filename: string) => {
try {
return new SemVer(filename.split('-')[0]?.replaceAll('_', '-') ?? 'unknown');
} catch {}
};
const importAlterationScript = async (filePath: string): Promise<AlterationScript> => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const module = await import(filePath);

View file

@ -42,6 +42,11 @@ export const chooseAlterationsByVersion = async (
.filter((version, index, self) => index === self.findIndex((another) => eq(version, another)))
.slice()
.sort((i, j) => compare(j, i));
const initialSemVersion = conditional(initialVersion && new SemVer(initialVersion));
if (!versions[0]) {
return [];
}
const { version: targetVersion } =
initialVersion === latestTag
@ -57,14 +62,10 @@ export const chooseAlterationsByVersion = async (
})),
},
{
version: conditional(initialVersion && new SemVer(initialVersion)),
version: initialSemVersion,
}
);
if (!targetVersion) {
return [];
}
log.info(`Deploy target ${chalk.green(targetVersion.version)}`);
return alterations.filter(({ filename }) => {

View file

@ -4,7 +4,8 @@
"outDir": "lib",
"declaration": true,
"module": "node16",
"target": "es2022"
"target": "es2022",
"types": ["node", "jest"]
},
"include": [
"src",

View file

@ -87,7 +87,7 @@
"@types/koa-mount": "^4.0.0",
"@types/koa-send": "^4.1.3",
"@types/lodash.pick": "^4.4.6",
"@types/node": "^16.3.1",
"@types/node": "^16.0.0",
"@types/oidc-provider": "^7.11.1",
"@types/supertest": "^2.0.11",
"copyfiles": "^2.4.1",

View file

@ -32,7 +32,7 @@
"@silverhand/ts-config": "1.0.0",
"@types/jest": "^28.0.0",
"@types/lodash.uniq": "^4.5.6",
"@types/node": "16",
"@types/node": "^16.0.0",
"@types/pluralize": "^0.0.29",
"camelcase": "^6.2.0",
"eslint": "^8.21.0",

View file

@ -23,6 +23,7 @@
"@silverhand/jest-config": "1.0.0",
"@silverhand/ts-config": "1.0.0",
"@types/jest": "^28.1.6",
"@types/node": "^16.0.0",
"eslint": "^8.21.0",
"jest": "^28.1.3",
"lint-staged": "^13.0.0",

View file

@ -1,14 +1,19 @@
import { lstat } from 'fs/promises';
import path from 'path';
import { conditional } from '@silverhand/essentials';
import findUp, { exists } from 'find-up';
const findPackage = async (cwd: string) =>
const findPackage = async (cwd: string, allowSymlink = false) =>
findUp(
// Will update to 7 soon
// eslint-disable-next-line complexity
async (directory) => {
const hasPackageJson = await exists(path.join(directory, 'package.json'));
const testPath = path.join(directory, 'package.json');
const hasPackageJson = await exists(testPath);
const stat = conditional(hasPackageJson && !allowSymlink && (await lstat(testPath)));
return conditional(hasPackageJson && directory);
return conditional(hasPackageJson && (allowSymlink || !stat?.isSymbolicLink()) && directory);
},
{
cwd,

View file

@ -2,7 +2,8 @@
"extends": "@silverhand/ts-config/tsconfig.base",
"compilerOptions": {
"outDir": "lib",
"declaration": true
"declaration": true,
"types": ["node", "jest"]
},
"include": [
"src",

View file

@ -262,7 +262,7 @@ importers:
'@types/koa-mount': ^4.0.0
'@types/koa-send': ^4.1.3
'@types/lodash.pick': ^4.4.6
'@types/node': ^16.3.1
'@types/node': ^16.0.0
'@types/oidc-provider': ^7.11.1
'@types/supertest': ^2.0.11
chalk: ^4
@ -571,7 +571,7 @@ importers:
'@silverhand/ts-config': 1.0.0
'@types/jest': ^28.0.0
'@types/lodash.uniq': ^4.5.6
'@types/node': '16'
'@types/node': ^16.0.0
'@types/pluralize': ^0.0.29
camelcase: ^6.2.0
eslint: ^8.21.0
@ -619,6 +619,7 @@ importers:
'@silverhand/jest-config': 1.0.0
'@silverhand/ts-config': 1.0.0
'@types/jest': ^28.1.6
'@types/node': ^16.0.0
dayjs: ^1.10.5
eslint: ^8.21.0
find-up: ^5.0.0
@ -640,8 +641,9 @@ importers:
'@silverhand/jest-config': 1.0.0_bi2kohzqnxavgozw3csgny5hju
'@silverhand/ts-config': 1.0.0_typescript@4.7.4
'@types/jest': 28.1.6
'@types/node': 16.11.12
eslint: 8.21.0
jest: 28.1.3
jest: 28.1.3_@types+node@16.11.12
lint-staged: 13.0.0
prettier: 2.7.1
typescript: 4.7.4
@ -4618,7 +4620,7 @@ packages:
'@types/http-errors': 1.8.2
'@types/keygrip': 1.0.2
'@types/koa-compose': 3.2.5
'@types/node': 16.11.12
'@types/node': 17.0.23
dev: true
/@types/lodash.kebabcase/4.1.6:
@ -4806,7 +4808,7 @@ packages:
resolution: {integrity: sha512-mu/N4uvfDN2zVQQ5AYJI/g4qxn2bHB6521t1UuH09ShNWjebTqN0ZFuYK9uYjcgmI0dTQEs+Owi1EO6U0OkOZQ==}
dependencies:
'@types/cookiejar': 2.1.2
'@types/node': 16.11.12
'@types/node': 17.0.23
dev: true
/@types/supertest/2.0.11: