From 9029588590bea8b10451575c5142dcde77ecd1b5 Mon Sep 17 00:00:00 2001 From: 简律纯 Date: Fri, 3 Nov 2023 21:25:40 +0800 Subject: chore: delete useless files --- packages/turbo-codemod/src/runner/FileTransform.ts | 94 ---------------------- 1 file changed, 94 deletions(-) delete mode 100644 packages/turbo-codemod/src/runner/FileTransform.ts (limited to 'packages/turbo-codemod/src/runner/FileTransform.ts') diff --git a/packages/turbo-codemod/src/runner/FileTransform.ts b/packages/turbo-codemod/src/runner/FileTransform.ts deleted file mode 100644 index 3b23f73..0000000 --- a/packages/turbo-codemod/src/runner/FileTransform.ts +++ /dev/null @@ -1,94 +0,0 @@ -import chalk from "chalk"; -import { diffLines, Change, diffJson } from "diff"; -import fs from "fs-extra"; -import os from "os"; -import path from "path"; - -import type { FileTransformArgs, LogFileArgs } from "./types"; - -export default class FileTransform { - filePath: string; - rootPath: string; - before: string | object; - after?: string | object; - error?: Error; - changes: Array = []; - - constructor(args: FileTransformArgs) { - this.filePath = args.filePath; - this.rootPath = args.rootPath; - this.after = args.after; - this.error = args.error; - - // load original file for comparison - if (args.before === undefined) { - try { - if (path.extname(args.filePath) === ".json") { - this.before = fs.readJsonSync(args.filePath); - } else { - this.before = fs.readFileSync(args.filePath); - } - } catch (err) { - this.before = ""; - } - } else if (args.before === null) { - this.before = ""; - } else { - this.before = args.before; - } - - // determine diff - if (args.after) { - if (typeof this.before === "object" || typeof args.after === "object") { - this.changes = diffJson(this.before, args.after); - } else { - this.changes = diffLines(this.before, args.after); - } - } else { - this.changes = []; - } - } - - fileName(): string { - return path.relative(this.rootPath, this.filePath); - } - - write(): void { - if (this.after) { - if (typeof this.after === "object") { - fs.writeJsonSync(this.filePath, this.after, { spaces: 2 }); - } else { - fs.writeFileSync(this.filePath, this.after); - } - } - } - - additions(): number { - return this.changes.filter((c) => c.added).length; - } - - deletions(): number { - return this.changes.filter((c) => c.removed).length; - } - - hasChanges(): boolean { - return this.additions() > 0 || this.deletions() > 0; - } - - log(args: LogFileArgs): void { - if (args.diff) { - this.changes.forEach((part) => { - if (part.added) { - process.stdout.write(chalk.green(part.value)); - } else if (part.removed) { - process.stdout.write(chalk.red(part.value)); - } else { - process.stdout.write(chalk.dim(part.value)); - } - }); - console.log(os.EOL); - } else { - console.log(this.after); - } - } -} -- cgit v1.2.3-70-g09d2