diff --git a/scripts/ci/codegen/spreadGeneration.ts b/scripts/ci/codegen/spreadGeneration.ts index c60cca7b89..25711540fe 100644 --- a/scripts/ci/codegen/spreadGeneration.ts +++ b/scripts/ci/codegen/spreadGeneration.ts @@ -1,5 +1,8 @@ /* eslint-disable no-console */ +import { copy } from 'fs-extra'; + import { + emptyDirExceptForDotGit, gitBranchExists, gitCommit, LANGUAGES, @@ -71,7 +74,8 @@ async function spreadGeneration(): Promise { }); const clientPath = toAbsolutePath(getLanguageFolder(lang)); - await run(`cp -r ${clientPath}/ ${tempGitDir}`); + await emptyDirExceptForDotGit(tempGitDir); + await copy(clientPath, tempGitDir, { preserveTimestamps: true }); await configureGitHubAuthor(tempGitDir); await run(`git add .`, { cwd: tempGitDir }); diff --git a/scripts/common.ts b/scripts/common.ts index a01c6165a0..2284eace7c 100644 --- a/scripts/common.ts +++ b/scripts/common.ts @@ -3,6 +3,7 @@ import path from 'path'; import execa from 'execa'; // https://github.com/sindresorhus/execa/tree/v5.1.1 import { hashElement } from 'folder-hash'; +import { remove } from 'fs-extra'; import openapitools from '../openapitools.json'; @@ -280,3 +281,11 @@ export async function buildCustomGenerators(verbose: boolean): Promise { export async function gitBranchExists(branchName: string): Promise { return Boolean(await run(`git ls-remote --heads origin ${branchName}`)); } + +export async function emptyDirExceptForDotGit(dir: string): Promise { + for (const file of await fsp.readdir(dir)) { + if (file !== '.git') { + await remove(path.resolve(dir, file)); + } + } +} diff --git a/scripts/release/process-release.ts b/scripts/release/process-release.ts index 9c5c91ce29..927d1cd2f2 100755 --- a/scripts/release/process-release.ts +++ b/scripts/release/process-release.ts @@ -1,10 +1,9 @@ /* eslint-disable no-console */ import fsp from 'fs/promises'; -import path from 'path'; import dotenv from 'dotenv'; import execa from 'execa'; -import { copy, remove } from 'fs-extra'; +import { copy } from 'fs-extra'; import semver from 'semver'; import type { ReleaseType } from 'semver'; @@ -16,6 +15,7 @@ import { exists, getGitHubUrl, gitCommit, + emptyDirExceptForDotGit, } from '../common'; import { getLanguageFolder } from '../config'; @@ -127,14 +127,6 @@ async function updateOpenApiTools( ); } -async function emptyDirExceptForDotGit(dir: string): Promise { - for (const file of await fsp.readdir(dir)) { - if (file !== '.git') { - await remove(path.resolve(dir, file)); - } - } -} - async function updateChangelog({ lang, issueBody,