From 2337190a1b3112d97e916b586888cb1c49daa866 Mon Sep 17 00:00:00 2001 From: Caleb Webber Date: Fri, 15 Nov 2024 12:09:55 -0500 Subject: [PATCH] wip: until-destroyed-migrator --- until-destroyed-migrator/.gitignore | 175 ++++++++++++++++++++++++++++ until-destroyed-migrator/README.md | 15 +++ until-destroyed-migrator/bun.lockb | Bin 0 -> 10038 bytes until-destroyed-migrator/index.ts | 86 ++++++++++++++ 4 files changed, 276 insertions(+) create mode 100644 until-destroyed-migrator/.gitignore create mode 100644 until-destroyed-migrator/README.md create mode 100755 until-destroyed-migrator/bun.lockb create mode 100644 until-destroyed-migrator/index.ts diff --git a/until-destroyed-migrator/.gitignore b/until-destroyed-migrator/.gitignore new file mode 100644 index 0000000..468f82a --- /dev/null +++ b/until-destroyed-migrator/.gitignore @@ -0,0 +1,175 @@ +# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore + +# Logs + +logs +_.log +npm-debug.log_ +yarn-debug.log* +yarn-error.log* +lerna-debug.log* +.pnpm-debug.log* + +# Caches + +.cache + +# Diagnostic reports (https://nodejs.org/api/report.html) + +report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json + +# Runtime data + +pids +_.pid +_.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover + +lib-cov + +# Coverage directory used by tools like istanbul + +coverage +*.lcov + +# nyc test coverage + +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) + +.grunt + +# Bower dependency directory (https://bower.io/) + +bower_components + +# node-waf configuration + +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) + +build/Release + +# Dependency directories + +node_modules/ +jspm_packages/ + +# Snowpack dependency directory (https://snowpack.dev/) + +web_modules/ + +# TypeScript cache + +*.tsbuildinfo + +# Optional npm cache directory + +.npm + +# Optional eslint cache + +.eslintcache + +# Optional stylelint cache + +.stylelintcache + +# Microbundle cache + +.rpt2_cache/ +.rts2_cache_cjs/ +.rts2_cache_es/ +.rts2_cache_umd/ + +# Optional REPL history + +.node_repl_history + +# Output of 'npm pack' + +*.tgz + +# Yarn Integrity file + +.yarn-integrity + +# dotenv environment variable files + +.env +.env.development.local +.env.test.local +.env.production.local +.env.local + +# parcel-bundler cache (https://parceljs.org/) + +.parcel-cache + +# Next.js build output + +.next +out + +# Nuxt.js build / generate output + +.nuxt +dist + +# Gatsby files + +# Comment in the public line in if your project uses Gatsby and not Next.js + +# https://nextjs.org/blog/next-9-1#public-directory-support + +# public + +# vuepress build output + +.vuepress/dist + +# vuepress v2.x temp and cache directory + +.temp + +# Docusaurus cache and generated files + +.docusaurus + +# Serverless directories + +.serverless/ + +# FuseBox cache + +.fusebox/ + +# DynamoDB Local files + +.dynamodb/ + +# TernJS port file + +.tern-port + +# Stores VSCode versions used for testing VSCode extensions + +.vscode-test + +# yarn v2 + +.yarn/cache +.yarn/unplugged +.yarn/build-state.yml +.yarn/install-state.gz +.pnp.* + +# IntelliJ based IDEs +.idea + +# Finder (MacOS) folder config +.DS_Store diff --git a/until-destroyed-migrator/README.md b/until-destroyed-migrator/README.md new file mode 100644 index 0000000..9921179 --- /dev/null +++ b/until-destroyed-migrator/README.md @@ -0,0 +1,15 @@ +# until-destroyed-migrator + +To install dependencies: + +```bash +bun install +``` + +To run: + +```bash +bun run index.ts +``` + +This project was created using `bun init` in bun v1.0.23. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime. diff --git a/until-destroyed-migrator/bun.lockb b/until-destroyed-migrator/bun.lockb new file mode 100755 index 0000000000000000000000000000000000000000..3c2607129dadc0b43b765c374dfb97fdff43347b GIT binary patch literal 10038 zcmeHN2~<A_2_LR7Iyf>^AY{0q(c&n+l)J!2Q=Ouyb(u$svwj`7 zVR-Z4=c&m#++~GUMnZ3ctYI#Khbz7sbhITY0&WHRJ?gXDFiC_Rw6Acul%gnGomGu!VM-R1pNg4BZY{ypTl z9~I@GJKJu1>ZaBPy)8X6k28)g#XFgaS-<3G8ysmqr`GqTZ$a&=2fvmKE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@dzgxUhZf48LB z25};(K*$Y&^(u}|WJ0)6f-o^(8ZDM4#y~(=EQpc1vyavg)pif!2QfnHFh<0%Z4`NS zz~XSJG)6Mo+FHzn34kn-7R5wGNa$#B7!+Y_+M26);K~;?Ee%V8VlGQBiH;KoGu$YC zj8q^>N-htUwH;D+h3G_$&`t$hb^~||M~9+-@5sQIU|T^f zE&nfo+zn`a-B|#KRtRi~q^3O|A?ZR{#ij;M$)-Iou~Zv}5Oy zE1x$|u?xOVQw*GP3|GG7-(sr2x(mSDT?ZLpdqf6BGu92{6PlTwZ~ z%o}!*Fj6jGEaoSwI&{(=2Th(~xNvyAZMgECO1^W!q~T`vrptvh!Wc%(h208VNwFLh z-l(WjEY)Z+R}jL$P8lj-#L{SPC@!rSaWtT%0;a3=^JZfh%bSJZmT(@bHmELC1MV(r z<*U}|oqFkHn-2O;#VYOw^2vZ>1ZeOtQh3s{8vth5$}ZfZy^R7apHcZ`0SBZwq~axt z2NA5WF6fk60UM!W>j@e(e3!C_rn fe(K9l`Y!OS71%=>2s$#*xr6*Ll-~jV^S=KFaMc(T literal 0 HcmV?d00001 diff --git a/until-destroyed-migrator/index.ts b/until-destroyed-migrator/index.ts new file mode 100644 index 0000000..9fb4a9d --- /dev/null +++ b/until-destroyed-migrator/index.ts @@ -0,0 +1,86 @@ +import { Glob } from "bun"; +import babelParser from "@babel/parser"; + +let dir = "/Users/caleb.webber/git/snag/Web.MarketplaceAdmin/"; +let glob = new Glob("!{node_modules}/**/*.ts"); + +const files = [...glob.scanSync(dir)].filter((f) => !f.includes("e2e")); + +export function parse(text: string) { + return babelParser.parse(text, { + allowImportExportEverywhere: true, + plugins: ["decorators-legacy", "typescript"], + }); +} + +export async function fileContainsNgNeat(file: string) { + const text = await Bun.file(`${dir}${file}`).text(); + return text.includes("ngneat"); +} + +export function getImportFrom(tree: any, module: string) { + return tree.program.body.find( + (n: any) => n.type === "ImportDeclaration" && n.source.value === module, + ); +} + +export function ensureAngularCoreImports(tree: any) { + const t2 = structuredClone(tree); + + const angularCoreImport = getImportFrom(t2, "@angular/core") ?? { + type: "ImportDeclaration", + specifiers: [], + source: { type: "StringLiteral", value: "@angular/core" }, + }; + + angularCoreImport.specifiers.push({ + type: "ImportSpecifier", + imported: { type: "Identifier", name: "inject" }, + local: { type: "Identifier", name: "inject" }, + }); + + angularCoreImport.specifiers.push({ + type: "ImportSpecifier", + imported: { type: "Identifier", name: "takeUntilDestroyed" }, + local: { type: "Identifier", name: "takeUntilDestroyed" }, + }); + + return t2; +} + +export function removeNgNeatImports(tree: any) { + const t2 = structuredClone(tree); + + t2.program.body = t2.program.body.filter( + (n: any) => + n.type !== "ImportDeclaration" || !n.source.value.includes("ngneat"), + ); + + return t2; +} + +const filesToFix = ( + await Promise.all(files.map(async (f) => [await fileContainsNgNeat(f), f])) +) + .filter(([shouldFix]) => shouldFix) + .map(([, f]) => f); + +export const trees = await Promise.all( + filesToFix.map(async (f) => { + const text = await Bun.file(`${dir}${f}`).text(); + return parse(text); + }), +); + +for (const f of filesToFix) { + const text = await Bun.file(`${dir}${f}`).text(); + try { + const parsed = parse(text); + console.log(`could parse ${f} - ${parsed.type === "File"}`); + } catch (e) { + console.error(`could not parse ${f}`); + console.error(e); + } +} + +console.log(`Found ${filesToFix.length} files to fix`);