-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into mikro-orm-scripts
- Loading branch information
Showing
7 changed files
with
180 additions
and
32 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { existsSync, readFileSync, writeFileSync } from "fs"; | ||
|
||
type Json = { | ||
dependencies?: Record<string, string>; | ||
devDependencies?: Record<string, string>; | ||
}; | ||
|
||
export class PackageJson { | ||
private path: string; | ||
private json: Json; | ||
|
||
constructor(path: string) { | ||
if (!existsSync(path)) { | ||
throw new Error("File does not exist"); | ||
} | ||
|
||
this.path = path; | ||
this.json = JSON.parse(readFileSync(path, "utf-8")); | ||
} | ||
|
||
addDependency(name: string, version: string, dev = false) { | ||
if (dev) { | ||
this.json.devDependencies ??= {}; | ||
this.json.devDependencies[name] = version; | ||
} else { | ||
this.json.dependencies ??= {}; | ||
this.json.dependencies[name] = version; | ||
} | ||
} | ||
|
||
updateDependency(name: string, version: string) { | ||
if (this.json.dependencies?.[name]) { | ||
this.json.dependencies[name] = version; | ||
} | ||
|
||
if (this.json.devDependencies?.[name]) { | ||
this.json.devDependencies[name] = version; | ||
} | ||
} | ||
|
||
removeDependency(name: string) { | ||
delete this.json.dependencies?.[name]; | ||
delete this.json.devDependencies?.[name]; | ||
} | ||
|
||
save() { | ||
writeFileSync(this.path, JSON.stringify(this.json, null, 4)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { Project, SyntaxKind } from "ts-morph"; | ||
|
||
/** | ||
* From | ||
* | ||
* if (error instanceof ValidationError) { | ||
* return new ValidationError("Invalid request."); | ||
* } | ||
* | ||
* to | ||
* | ||
* if (error.extensions?.code === "GRAPHQL_VALIDATION_FAILED") { | ||
* return new ValidationError("Invalid request."); | ||
* } | ||
*/ | ||
export default async function updateGraphQLFormatError() { | ||
const project = new Project({ tsConfigFilePath: "./api/tsconfig.json" }); | ||
|
||
const sourceFile = project.getSourceFile("api/src/app.module.ts"); | ||
|
||
if (!sourceFile) { | ||
throw new Error("app.module.ts not found"); | ||
} | ||
|
||
// Change the import | ||
sourceFile.getImportDeclaration((importDeclaration) => importDeclaration.getModuleSpecifierValue() === "apollo-server-express")?.remove(); | ||
sourceFile.addImportDeclaration({ namedImports: ["ValidationError"], moduleSpecifier: "@nestjs/apollo" }); | ||
|
||
// Update the if statement | ||
sourceFile.getDescendantsOfKind(SyntaxKind.BinaryExpression).forEach((node) => { | ||
if (node.getText() === "error instanceof ValidationError") { | ||
node.replaceWithText(`error.extensions?.code === "GRAPHQL_VALIDATION_FAILED"`); | ||
} | ||
}); | ||
|
||
await sourceFile.save(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { glob } from "glob"; | ||
import { Project } from "ts-morph"; | ||
|
||
export default async function updateImportOfTooltip() { | ||
const project = new Project({ tsConfigFilePath: "./admin/tsconfig.json" }); | ||
const files: string[] = glob.sync(["admin/src/**/*.tsx"]); | ||
|
||
for (const filePath of files) { | ||
const sourceFile = project.getSourceFile(filePath); | ||
|
||
if (!sourceFile) { | ||
throw new Error(`Can't get source file for ${filePath}`); | ||
} | ||
|
||
const adminImport = sourceFile.getImportDeclaration((declaration) => declaration.getModuleSpecifierValue().includes("@comet/admin")); | ||
const adminImports = adminImport?.getNamedImports().map((namedImport) => namedImport.getText()); | ||
|
||
if (adminImports) { | ||
if (adminImports.includes("Tooltip")) { | ||
continue; | ||
} | ||
} | ||
|
||
const muiImport = sourceFile.getImportDeclaration((declaration) => declaration.getModuleSpecifierValue() === "@mui/material"); | ||
|
||
if (!muiImport) continue; | ||
|
||
const namedImports = muiImport.getNamedImports(); | ||
const tooltipImport = namedImports.find((namedImport) => namedImport.getText() === "Tooltip"); | ||
|
||
if (tooltipImport) { | ||
tooltipImport.remove(); | ||
} | ||
|
||
if (muiImport.getNamedImports().length === 0) { | ||
muiImport.remove(); | ||
} | ||
|
||
if (adminImport) { | ||
adminImport.addNamedImports(["Tooltip"]); | ||
} else { | ||
sourceFile.addImportDeclaration({ | ||
namedImports: ["Tooltip"], | ||
moduleSpecifier: "@comet/admin", | ||
}); | ||
} | ||
|
||
await sourceFile.save(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { existsSync } from "fs"; | ||
|
||
import { PackageJson } from "../util/package-json.util"; | ||
|
||
export const stage = "before-install"; | ||
|
||
export default async function updateNestDependencies() { | ||
if (!existsSync("api/package.json")) { | ||
return; | ||
} | ||
|
||
const packageJson = new PackageJson("api/package.json"); | ||
|
||
packageJson.updateDependency("@mikro-orm/cli", "^6.0.0"); | ||
packageJson.updateDependency("@mikro-orm/core", "^6.0.0"); | ||
packageJson.updateDependency("@mikro-orm/migrations", "^6.0.0"); | ||
packageJson.updateDependency("@mikro-orm/nestjs", "^6.0.2"); | ||
packageJson.updateDependency("@mikro-orm/postgresql", "^6.0.0"); | ||
|
||
packageJson.save(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,36 @@ | ||
import { existsSync } from "fs"; | ||
import { readFile, writeFile } from "fs/promises"; | ||
|
||
export const stage = "before-install"; | ||
import { PackageJson } from "../util/package-json.util"; | ||
|
||
function updateDependencyIfExists(dependencies: Record<string, string>, name: string, version: string) { | ||
if (dependencies[name]) { | ||
dependencies[name] = version; | ||
} | ||
} | ||
export const stage = "before-install"; | ||
|
||
export default async function updateNestDependencies() { | ||
if (!existsSync("api/package.json")) { | ||
return; | ||
} | ||
|
||
const packageJson = JSON.parse(await readFile("api/package.json", "utf-8")); | ||
const packageJson = new PackageJson("api/package.json"); | ||
|
||
if (packageJson.dependencies) { | ||
packageJson.dependencies["@apollo/server"] = "^4.0.0"; | ||
delete packageJson.dependencies["apollo-server-core"]; | ||
delete packageJson.dependencies["apollo-server-express"]; | ||
packageJson.addDependency("@apollo/server", "^4.0.0"); | ||
packageJson.removeDependency("apollo-server-core"); | ||
packageJson.removeDependency("apollo-server-express"); | ||
|
||
updateDependencyIfExists(packageJson.dependencies, "@nestjs/apollo", "^12.0.0"); | ||
updateDependencyIfExists(packageJson.dependencies, "@nestjs/common", "^10.0.0"); | ||
updateDependencyIfExists(packageJson.dependencies, "@nestjs/core", "^10.0.0"); | ||
updateDependencyIfExists(packageJson.dependencies, "@nestjs/graphql", "^12.0.0"); | ||
// TODO remove when https://github.com/vivid-planet/comet/pull/2809 has been merged | ||
updateDependencyIfExists(packageJson.dependencies, "@nestjs/passport", "^10.0.0"); | ||
updateDependencyIfExists(packageJson.dependencies, "@nestjs/platform-express", "^10.0.0"); | ||
packageJson.updateDependency("@nestjs/apollo", "^12.0.0"); | ||
packageJson.updateDependency("@nestjs/common", "^10.0.0"); | ||
packageJson.updateDependency("@nestjs/core", "^10.0.0"); | ||
packageJson.updateDependency("@nestjs/graphql", "^12.0.0"); | ||
// TODO remove when https://github.com/vivid-planet/comet/pull/2809 has been merged | ||
packageJson.updateDependency("@nestjs/passport", "^10.0.0"); | ||
packageJson.updateDependency("@nestjs/platform-express", "^10.0.0"); | ||
|
||
updateDependencyIfExists(packageJson.dependencies, "graphql", "^16.6.0"); | ||
packageJson.updateDependency("graphql", "^16.6.0"); | ||
|
||
updateDependencyIfExists(packageJson.dependencies, "nestjs-console", "^9.0.0"); | ||
updateDependencyIfExists(packageJson.dependencies, "@golevelup/nestjs-discovery", "^4.0.0"); | ||
} | ||
packageJson.updateDependency("nestjs-console", "^9.0.0"); | ||
packageJson.updateDependency("@golevelup/nestjs-discovery", "^4.0.0"); | ||
|
||
if (packageJson.devDependencies) { | ||
updateDependencyIfExists(packageJson.devDependencies, "@nestjs/cli", "^10.0.0"); | ||
updateDependencyIfExists(packageJson.devDependencies, "@nestjs/schematics", "^10.0.0"); | ||
updateDependencyIfExists(packageJson.devDependencies, "@nestjs/testing", "^10.0.0"); | ||
} | ||
packageJson.updateDependency("@nestjs/cli", "^10.0.0"); | ||
packageJson.updateDependency("@nestjs/schematics", "^10.0.0"); | ||
packageJson.updateDependency("@nestjs/testing", "^10.0.0"); | ||
|
||
await writeFile("api/package.json", JSON.stringify(packageJson, null, 4)); | ||
packageJson.save(); | ||
} |