mirror of
https://github.com/logto-io/logto.git
synced 2024-12-30 20:33:54 -05:00
refactor: remove fs-extra (#2695)
This commit is contained in:
parent
cb159ac8bb
commit
cc18103419
7 changed files with 23 additions and 27 deletions
|
@ -50,7 +50,6 @@
|
||||||
"chalk": "^5.0.0",
|
"chalk": "^5.0.0",
|
||||||
"decamelize": "^6.0.0",
|
"decamelize": "^6.0.0",
|
||||||
"dotenv": "^16.0.0",
|
"dotenv": "^16.0.0",
|
||||||
"fs-extra": "^10.1.0",
|
|
||||||
"got": "^12.5.3",
|
"got": "^12.5.3",
|
||||||
"hpagent": "^1.2.0",
|
"hpagent": "^1.2.0",
|
||||||
"inquirer": "^8.2.2",
|
"inquirer": "^8.2.2",
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
|
import fs from 'fs/promises';
|
||||||
|
|
||||||
import chalk from 'chalk';
|
import chalk from 'chalk';
|
||||||
import fsExtra from 'fs-extra';
|
|
||||||
import type { CommandModule } from 'yargs';
|
import type { CommandModule } from 'yargs';
|
||||||
|
|
||||||
import { log } from '../../utilities.js';
|
import { log } from '../../utilities.js';
|
||||||
|
@ -39,7 +40,7 @@ const remove: CommandModule<{ path?: string }, { path?: string; packages?: strin
|
||||||
const packageInfo = existingPackages.find(({ name }) => name === current);
|
const packageInfo = existingPackages.find(({ name }) => name === current);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await fsExtra.remove(packageInfo?.path ?? '');
|
await fs.rm(packageInfo?.path ?? '', { force: true, recursive: true });
|
||||||
|
|
||||||
return okSymbol;
|
return okSymbol;
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
import { exec } from 'child_process';
|
import { exec } from 'child_process';
|
||||||
import { existsSync } from 'fs';
|
import { existsSync } from 'fs';
|
||||||
import { readFile, mkdir, unlink } from 'fs/promises';
|
import fs from 'fs/promises';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import { promisify } from 'util';
|
import { promisify } from 'util';
|
||||||
|
|
||||||
import { assert, conditionalString } from '@silverhand/essentials';
|
import { assert, conditionalString } from '@silverhand/essentials';
|
||||||
import chalk from 'chalk';
|
import chalk from 'chalk';
|
||||||
import fsExtra from 'fs-extra';
|
|
||||||
import inquirer from 'inquirer';
|
import inquirer from 'inquirer';
|
||||||
import pRetry from 'p-retry';
|
import pRetry from 'p-retry';
|
||||||
import tar from 'tar';
|
import tar from 'tar';
|
||||||
|
@ -36,7 +35,7 @@ const validatePath = async (value: string) => {
|
||||||
return buildPathErrorMessage(value);
|
return buildPathErrorMessage(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
const packageJson = await readFile(corePackageJsonPath, { encoding: 'utf8' });
|
const packageJson = await fs.readFile(corePackageJsonPath, { encoding: 'utf8' });
|
||||||
const packageName = await z
|
const packageName = await z
|
||||||
.object({ name: z.string() })
|
.object({ name: z.string() })
|
||||||
.parseAsync(JSON.parse(packageJson))
|
.parseAsync(JSON.parse(packageJson))
|
||||||
|
@ -112,7 +111,7 @@ export const addConnectors = async (instancePath: string, packageNames: string[]
|
||||||
const cwd = getConnectorDirectory(instancePath);
|
const cwd = getConnectorDirectory(instancePath);
|
||||||
|
|
||||||
if (!existsSync(cwd)) {
|
if (!existsSync(cwd)) {
|
||||||
await mkdir(cwd);
|
await fs.mkdir(cwd, { recursive: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
log.info('Fetch connector metadata');
|
log.info('Fetch connector metadata');
|
||||||
|
@ -136,10 +135,10 @@ export const addConnectors = async (instancePath: string, packageNames: string[]
|
||||||
const tarPath = path.join(cwd, escapedFilename);
|
const tarPath = path.join(cwd, escapedFilename);
|
||||||
const packageDirectory = path.join(cwd, name.replace(/\//g, '-'));
|
const packageDirectory = path.join(cwd, name.replace(/\//g, '-'));
|
||||||
|
|
||||||
await fsExtra.remove(packageDirectory);
|
await fs.rm(packageDirectory, { force: true, recursive: true });
|
||||||
await fsExtra.ensureDir(packageDirectory);
|
await fs.mkdir(packageDirectory, { recursive: true });
|
||||||
await tar.extract({ cwd: packageDirectory, file: tarPath, strip: 1 });
|
await tar.extract({ cwd: packageDirectory, file: tarPath, strip: 1 });
|
||||||
await unlink(tarPath);
|
await fs.unlink(tarPath);
|
||||||
|
|
||||||
log.succeed(`Added ${chalk.green(name)}`);
|
log.succeed(`Added ${chalk.green(name)}`);
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
|
import { existsSync } from 'fs';
|
||||||
|
import fs from 'fs/promises';
|
||||||
import { fileURLToPath } from 'node:url';
|
import { fileURLToPath } from 'node:url';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
|
||||||
import { findPackage } from '@logto/shared';
|
import { findPackage } from '@logto/shared';
|
||||||
import fsExtra from 'fs-extra';
|
|
||||||
|
|
||||||
import { getPathInModule } from '../../../utilities.js';
|
import { getPathInModule } from '../../../utilities.js';
|
||||||
import { metaUrl } from './meta-url.js';
|
import { metaUrl } from './meta-url.js';
|
||||||
import type { AlterationFile } from './type.js';
|
import type { AlterationFile } from './type.js';
|
||||||
|
|
||||||
const currentDirname = path.dirname(fileURLToPath(metaUrl));
|
const currentDirname = path.dirname(fileURLToPath(metaUrl));
|
||||||
const { copy, existsSync, remove, readdir } = fsExtra;
|
|
||||||
const alterationFilenameRegex = /-(\d+)-?.*\.js$/;
|
const alterationFilenameRegex = /-(\d+)-?.*\.js$/;
|
||||||
|
|
||||||
export const getTimestampFromFilename = (filename: string) => {
|
export const getTimestampFromFilename = (filename: string) => {
|
||||||
|
@ -42,10 +42,10 @@ export const getAlterationFiles = async (): Promise<AlterationFile[]> => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// We need to copy alteration files to execute in the CLI context to make `slonik` available
|
// We need to copy alteration files to execute in the CLI context to make `slonik` available
|
||||||
await remove(localAlterationDirectory);
|
await fs.rm(localAlterationDirectory, { force: true, recursive: true });
|
||||||
await copy(alterationDirectory, localAlterationDirectory);
|
await fs.cp(alterationDirectory, localAlterationDirectory, { recursive: true });
|
||||||
|
|
||||||
const directory = await readdir(localAlterationDirectory);
|
const directory = await fs.readdir(localAlterationDirectory);
|
||||||
const files = directory.filter((file) => alterationFilenameRegex.test(file));
|
const files = directory.filter((file) => alterationFilenameRegex.test(file));
|
||||||
|
|
||||||
return files
|
return files
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
import { execSync } from 'child_process';
|
import { execSync } from 'child_process';
|
||||||
import { existsSync } from 'fs';
|
import { existsSync } from 'fs';
|
||||||
import { mkdir } from 'fs/promises';
|
import fs from 'fs/promises';
|
||||||
import os from 'os';
|
import os from 'os';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
|
||||||
import { assert } from '@silverhand/essentials';
|
import { assert } from '@silverhand/essentials';
|
||||||
import chalk from 'chalk';
|
import chalk from 'chalk';
|
||||||
import fsExtra from 'fs-extra';
|
|
||||||
import inquirer from 'inquirer';
|
import inquirer from 'inquirer';
|
||||||
import * as semver from 'semver';
|
import * as semver from 'semver';
|
||||||
import tar from 'tar';
|
import tar from 'tar';
|
||||||
|
@ -115,7 +114,7 @@ export const downloadRelease = async (url?: string) => {
|
||||||
export const decompress = async (toPath: string, tarPath: string) => {
|
export const decompress = async (toPath: string, tarPath: string) => {
|
||||||
const run = async () => {
|
const run = async () => {
|
||||||
try {
|
try {
|
||||||
await mkdir(toPath);
|
await fs.mkdir(toPath);
|
||||||
await tar.extract({ file: tarPath, cwd: toPath, strip: 1 });
|
await tar.extract({ file: tarPath, cwd: toPath, strip: 1 });
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
log.error(error);
|
log.error(error);
|
||||||
|
@ -140,7 +139,7 @@ export const seedDatabase = async (instancePath: string) => {
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
|
||||||
await oraPromise(fsExtra.remove(instancePath), {
|
await oraPromise(fs.rm(instancePath, { force: true, recursive: true }), {
|
||||||
text: 'Clean up',
|
text: 'Clean up',
|
||||||
prefixText: chalk.blue('[info]'),
|
prefixText: chalk.blue('[info]'),
|
||||||
});
|
});
|
||||||
|
@ -156,9 +155,7 @@ export const seedDatabase = async (instancePath: string) => {
|
||||||
|
|
||||||
export const createEnv = async (instancePath: string, databaseUrl: string) => {
|
export const createEnv = async (instancePath: string, databaseUrl: string) => {
|
||||||
const dotEnvPath = path.resolve(instancePath, '.env');
|
const dotEnvPath = path.resolve(instancePath, '.env');
|
||||||
await fsExtra.writeFile(dotEnvPath, `DB_URL=${databaseUrl}`, {
|
await fs.writeFile(dotEnvPath, `DB_URL=${databaseUrl}`, 'utf8');
|
||||||
encoding: 'utf8',
|
|
||||||
});
|
|
||||||
log.info(`Saved database URL to ${chalk.blue(dotEnvPath)}`);
|
log.info(`Saved database URL to ${chalk.blue(dotEnvPath)}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,6 @@
|
||||||
"dotenv": "^16.0.0",
|
"dotenv": "^16.0.0",
|
||||||
"etag": "^1.8.1",
|
"etag": "^1.8.1",
|
||||||
"find-up": "^6.3.0",
|
"find-up": "^6.3.0",
|
||||||
"fs-extra": "^10.1.0",
|
|
||||||
"hash-wasm": "^4.9.0",
|
"hash-wasm": "^4.9.0",
|
||||||
"i18next": "^21.8.16",
|
"i18next": "^21.8.16",
|
||||||
"iconv-lite": "0.6.3",
|
"iconv-lite": "0.6.3",
|
||||||
|
|
|
@ -41,7 +41,6 @@ importers:
|
||||||
decamelize: ^6.0.0
|
decamelize: ^6.0.0
|
||||||
dotenv: ^16.0.0
|
dotenv: ^16.0.0
|
||||||
eslint: ^8.21.0
|
eslint: ^8.21.0
|
||||||
fs-extra: ^10.1.0
|
|
||||||
got: ^12.5.3
|
got: ^12.5.3
|
||||||
hpagent: ^1.2.0
|
hpagent: ^1.2.0
|
||||||
inquirer: ^8.2.2
|
inquirer: ^8.2.2
|
||||||
|
@ -70,7 +69,6 @@ importers:
|
||||||
chalk: 5.1.2
|
chalk: 5.1.2
|
||||||
decamelize: 6.0.0
|
decamelize: 6.0.0
|
||||||
dotenv: 16.0.0
|
dotenv: 16.0.0
|
||||||
fs-extra: 10.1.0
|
|
||||||
got: 12.5.3
|
got: 12.5.3
|
||||||
hpagent: 1.2.0
|
hpagent: 1.2.0
|
||||||
inquirer: 8.2.2
|
inquirer: 8.2.2
|
||||||
|
@ -289,7 +287,6 @@ importers:
|
||||||
eslint: ^8.21.0
|
eslint: ^8.21.0
|
||||||
etag: ^1.8.1
|
etag: ^1.8.1
|
||||||
find-up: ^6.3.0
|
find-up: ^6.3.0
|
||||||
fs-extra: ^10.1.0
|
|
||||||
hash-wasm: ^4.9.0
|
hash-wasm: ^4.9.0
|
||||||
http-errors: ^1.6.3
|
http-errors: ^1.6.3
|
||||||
i18next: ^21.8.16
|
i18next: ^21.8.16
|
||||||
|
@ -343,7 +340,6 @@ importers:
|
||||||
dotenv: 16.0.0
|
dotenv: 16.0.0
|
||||||
etag: 1.8.1
|
etag: 1.8.1
|
||||||
find-up: 6.3.0
|
find-up: 6.3.0
|
||||||
fs-extra: 10.1.0
|
|
||||||
hash-wasm: 4.9.0
|
hash-wasm: 4.9.0
|
||||||
i18next: 21.8.16
|
i18next: 21.8.16
|
||||||
iconv-lite: 0.6.3
|
iconv-lite: 0.6.3
|
||||||
|
@ -7408,6 +7404,7 @@ packages:
|
||||||
graceful-fs: 4.2.9
|
graceful-fs: 4.2.9
|
||||||
jsonfile: 6.1.0
|
jsonfile: 6.1.0
|
||||||
universalify: 2.0.0
|
universalify: 2.0.0
|
||||||
|
dev: true
|
||||||
|
|
||||||
/fs-extra/7.0.1:
|
/fs-extra/7.0.1:
|
||||||
resolution: {integrity: sha512-YJDaCJZEnBmcbw13fvdAM9AwNOJwOzrE4pqMqBq5nFiEqXUqHwlK4B+3pUw6JNvfSPtX05xFHtYy/1ni01eGCw==}
|
resolution: {integrity: sha512-YJDaCJZEnBmcbw13fvdAM9AwNOJwOzrE4pqMqBq5nFiEqXUqHwlK4B+3pUw6JNvfSPtX05xFHtYy/1ni01eGCw==}
|
||||||
|
@ -7730,9 +7727,11 @@ packages:
|
||||||
|
|
||||||
/graceful-fs/4.2.10:
|
/graceful-fs/4.2.10:
|
||||||
resolution: {integrity: sha512-9ByhssR2fPVsNZj478qUUbKfmL0+t5BDVyjShtyZZLiK7ZDAArFFfopyOTj0M05wE2tJPisA4iTnnXl2YoPvOA==}
|
resolution: {integrity: sha512-9ByhssR2fPVsNZj478qUUbKfmL0+t5BDVyjShtyZZLiK7ZDAArFFfopyOTj0M05wE2tJPisA4iTnnXl2YoPvOA==}
|
||||||
|
dev: true
|
||||||
|
|
||||||
/graceful-fs/4.2.9:
|
/graceful-fs/4.2.9:
|
||||||
resolution: {integrity: sha512-NtNxqUcXgpW2iMrfqSfR73Glt39K+BLwWsPs94yR63v45T0Wbej7eRmL5cWfwEgqXnmjQp3zaJTshdRW/qC2ZQ==}
|
resolution: {integrity: sha512-NtNxqUcXgpW2iMrfqSfR73Glt39K+BLwWsPs94yR63v45T0Wbej7eRmL5cWfwEgqXnmjQp3zaJTshdRW/qC2ZQ==}
|
||||||
|
dev: true
|
||||||
|
|
||||||
/grapheme-splitter/1.0.4:
|
/grapheme-splitter/1.0.4:
|
||||||
resolution: {integrity: sha512-bzh50DW9kTPM00T8y4o8vQg89Di9oLJVLW/KaOGIXJWP/iqCN6WKYkbNOF04vFLJhwcpYUh9ydh/+5vpOqV4YQ==}
|
resolution: {integrity: sha512-bzh50DW9kTPM00T8y4o8vQg89Di9oLJVLW/KaOGIXJWP/iqCN6WKYkbNOF04vFLJhwcpYUh9ydh/+5vpOqV4YQ==}
|
||||||
|
@ -9973,6 +9972,7 @@ packages:
|
||||||
universalify: 2.0.0
|
universalify: 2.0.0
|
||||||
optionalDependencies:
|
optionalDependencies:
|
||||||
graceful-fs: 4.2.10
|
graceful-fs: 4.2.10
|
||||||
|
dev: true
|
||||||
|
|
||||||
/jsonparse/1.3.1:
|
/jsonparse/1.3.1:
|
||||||
resolution: {integrity: sha512-POQXvpdL69+CluYsillJ7SUhKvytYjW9vG/GKpnf+xP8UWgYEM/RaMzHHofbALDiKbbP1W8UEYmgGl39WkPZsg==}
|
resolution: {integrity: sha512-POQXvpdL69+CluYsillJ7SUhKvytYjW9vG/GKpnf+xP8UWgYEM/RaMzHHofbALDiKbbP1W8UEYmgGl39WkPZsg==}
|
||||||
|
@ -14765,6 +14765,7 @@ packages:
|
||||||
/universalify/2.0.0:
|
/universalify/2.0.0:
|
||||||
resolution: {integrity: sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==}
|
resolution: {integrity: sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==}
|
||||||
engines: {node: '>= 10.0.0'}
|
engines: {node: '>= 10.0.0'}
|
||||||
|
dev: true
|
||||||
|
|
||||||
/unpipe/1.0.0:
|
/unpipe/1.0.0:
|
||||||
resolution: {integrity: sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==}
|
resolution: {integrity: sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==}
|
||||||
|
|
Loading…
Reference in a new issue