mirror of
https://github.com/logto-io/logto.git
synced 2025-02-17 22:04:19 -05:00
refactor(cli): use cli project root as alteration scripts directory (#2075)
This commit is contained in:
parent
b6b9d7ce80
commit
e385b60418
3 changed files with 31 additions and 10 deletions
|
@ -40,6 +40,7 @@
|
|||
"chalk": "^4.1.2",
|
||||
"decamelize": "^5.0.0",
|
||||
"dotenv": "^16.0.0",
|
||||
"find-up": "^5.0.0",
|
||||
"fs-extra": "^10.1.0",
|
||||
"got": "^11.8.2",
|
||||
"hpagent": "^1.0.0",
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
import path from 'path';
|
||||
|
||||
import { AlterationScript } from '@logto/schemas/lib/types/alteration';
|
||||
import { conditionalString } from '@silverhand/essentials';
|
||||
import { conditional, conditionalString } from '@silverhand/essentials';
|
||||
import chalk from 'chalk';
|
||||
import findUp, { exists } from 'find-up';
|
||||
import { copy, existsSync, remove, readdir } from 'fs-extra';
|
||||
import { DatabasePool } from 'slonik';
|
||||
import { CommandModule } from 'yargs';
|
||||
|
@ -38,9 +39,32 @@ type AlterationFile = { path: string; filename: string };
|
|||
|
||||
export const getAlterationFiles = async (): Promise<AlterationFile[]> => {
|
||||
const alterationDirectory = getPathInModule('@logto/schemas', 'alterations');
|
||||
// Until we migrate to ESM
|
||||
// eslint-disable-next-line unicorn/prefer-module
|
||||
const localAlterationDirectory = path.resolve(__dirname, './alteration-scripts');
|
||||
|
||||
/**
|
||||
* We copy all alteration scripts to the CLI package root directory,
|
||||
* since they need a proper context that includes required dependencies (such as slonik) in `node_modules/`.
|
||||
* While the original `@logto/schemas` may remove them in production.
|
||||
*/
|
||||
const packageDirectory = await findUp(
|
||||
async (directory) => {
|
||||
const hasPackageJson = await exists(path.join(directory, 'package.json'));
|
||||
|
||||
return conditional(hasPackageJson && directory);
|
||||
},
|
||||
{
|
||||
// Until we migrate to ESM
|
||||
// eslint-disable-next-line unicorn/prefer-module
|
||||
cwd: __dirname,
|
||||
type: 'directory',
|
||||
}
|
||||
);
|
||||
|
||||
const localAlterationDirectory = path.resolve(
|
||||
// Until we migrate to ESM
|
||||
// eslint-disable-next-line unicorn/prefer-module
|
||||
packageDirectory ?? __dirname,
|
||||
'alteration-scripts'
|
||||
);
|
||||
|
||||
if (!existsSync(alterationDirectory)) {
|
||||
return [];
|
||||
|
|
8
pnpm-lock.yaml
generated
8
pnpm-lock.yaml
generated
|
@ -37,6 +37,7 @@ importers:
|
|||
decamelize: ^5.0.0
|
||||
dotenv: ^16.0.0
|
||||
eslint: ^8.21.0
|
||||
find-up: ^5.0.0
|
||||
fs-extra: ^10.1.0
|
||||
got: ^11.8.2
|
||||
hpagent: ^1.0.0
|
||||
|
@ -63,6 +64,7 @@ importers:
|
|||
chalk: 4.1.2
|
||||
decamelize: 5.0.1
|
||||
dotenv: 16.0.0
|
||||
find-up: 5.0.0
|
||||
fs-extra: 10.1.0
|
||||
got: 11.8.3
|
||||
hpagent: 1.0.0
|
||||
|
@ -7666,7 +7668,6 @@ packages:
|
|||
dependencies:
|
||||
locate-path: 6.0.0
|
||||
path-exists: 4.0.0
|
||||
dev: true
|
||||
|
||||
/flat-cache/3.0.4:
|
||||
resolution: {integrity: sha512-dm9s5Pw7Jc0GvMYbshN6zchCA9RgQlzzEZX3vylR9IqFfS8XciblUXOKfW6SiuJ0e13eDYZoZV5wdrev7P3Nwg==}
|
||||
|
@ -10526,7 +10527,6 @@ packages:
|
|||
engines: {node: '>=10'}
|
||||
dependencies:
|
||||
p-locate: 5.0.0
|
||||
dev: true
|
||||
|
||||
/lodash._reinterpolate/3.0.0:
|
||||
resolution: {integrity: sha1-DM8tiRZq8Ds2Y8eWU4t1rG4RTZ0=}
|
||||
|
@ -12173,7 +12173,6 @@ packages:
|
|||
engines: {node: '>=10'}
|
||||
dependencies:
|
||||
yocto-queue: 0.1.0
|
||||
dev: true
|
||||
|
||||
/p-locate/2.0.0:
|
||||
resolution: {integrity: sha512-nQja7m7gSKuewoVRen45CtVfODR3crN3goVQ0DDZ9N3yHxgpkuBhZqsaiotSQRrADUrne346peY7kT3TSACykg==}
|
||||
|
@ -12194,7 +12193,6 @@ packages:
|
|||
engines: {node: '>=10'}
|
||||
dependencies:
|
||||
p-limit: 3.1.0
|
||||
dev: true
|
||||
|
||||
/p-map-series/2.1.0:
|
||||
resolution: {integrity: sha512-RpYIIK1zXSNEOdwxcfe7FdvGcs7+y5n8rifMhMNWvaxRNMPINJHF5GDeuVxWqnfrcHPSCnp7Oo5yNXHId9Av2Q==}
|
||||
|
@ -12459,7 +12457,6 @@ packages:
|
|||
/path-exists/4.0.0:
|
||||
resolution: {integrity: sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==}
|
||||
engines: {node: '>=8'}
|
||||
dev: true
|
||||
|
||||
/path-is-absolute/1.0.1:
|
||||
resolution: {integrity: sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg==}
|
||||
|
@ -16065,7 +16062,6 @@ packages:
|
|||
/yocto-queue/0.1.0:
|
||||
resolution: {integrity: sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==}
|
||||
engines: {node: '>=10'}
|
||||
dev: true
|
||||
|
||||
/zod/3.18.0:
|
||||
resolution: {integrity: sha512-gwTm8RfUCe8l9rDwN5r2A17DkAa8Ez4Yl4yXqc5VqeGaXaJahzYYXbTwvhroZi0SNBqTwh/bKm2N0mpCzuw4bA==}
|
||||
|
|
Loading…
Add table
Reference in a new issue