refactor(core): Replace promisify-d node calls with native promises (no-changelog) (#8464)

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™
2024-01-30 09:49:23 +01:00
committed by GitHub
parent 238b54c77b
commit 5cb55270b7
8 changed files with 19 additions and 46 deletions

View File

@@ -4,17 +4,12 @@
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
import { Command } from '@oclif/core';
import * as changeCase from 'change-case';
import * as fs from 'fs';
import { access } from 'fs/promises';
import * as inquirer from 'inquirer';
import { join } from 'path';
import { createTemplate } from '../src';
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { promisify } = require('util');
const fsAccess = promisify(fs.access);
export class New extends Command {
static description = 'Create new credentials/node';
@@ -113,7 +108,7 @@ export class New extends Command {
// Check if node with the same name already exists in target folder
// to not overwrite it by accident
try {
await fsAccess(destinationFilePath);
await access(destinationFilePath);
// File does already exist. So ask if it should be overwritten.
const overwriteQuestion: inquirer.QuestionCollection = [

View File

@@ -1,13 +1,7 @@
import * as fs from 'fs';
import { copyFile } from 'fs/promises';
import type { ReplaceInFileConfig } from 'replace-in-file';
import { replaceInFile } from 'replace-in-file';
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-var-requires
const { promisify } = require('util');
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
const fsCopyFile = promisify(fs.copyFile);
/**
* Creates a new credentials or node
*
@@ -22,7 +16,7 @@ export async function createTemplate(
): Promise<void> {
// Copy the file to then replace the values in it
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
await fsCopyFile(sourceFilePath, destinationFilePath);
await copyFile(sourceFilePath, destinationFilePath);
// Replace the variables in the template file
const options: ReplaceInFileConfig = {