Skip to content

Commit

Permalink
Upgrade Dependencies (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
henriqueleite42 committed May 30, 2022
1 parent efa64ab commit 4cfa12d
Show file tree
Hide file tree
Showing 15 changed files with 1,199 additions and 1,820 deletions.
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Jest
/jest.config.cjs

# OS
.DS_Store

Expand Down
2 changes: 1 addition & 1 deletion .lintstagedrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"*{ts,js}": [
"*{ts,js,cjs}": [
"yarn format"
]
}
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Removed

### Dependencies

- [chalk] 5.0.0 -> 5.0.1
- [commander] 9.0.0 -> 9.3.0
2 changes: 1 addition & 1 deletion jest.config.js → jest.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = {
rootDir: "src",
testRegex: ".*\\.spec\\.ts$",
transform: {
"^.+\\.(t|j)s$": "ts-jest",
"^.+\\.(t|j|cj)s$": "ts-jest",
},
collectCoverageFrom: ["lib/**/*.ts"],
setupFiles: ["./tests/setup.ts"],
Expand Down
25 changes: 13 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"types": "index.d.ts",
"license": "Apache-2.0",
"author": "Techmmunity",
"type": "module",
"description": "CLI for @thothom/core",
"homepage": "https://thothom.com/",
"bin": {
Expand Down Expand Up @@ -34,23 +35,23 @@
},
"dependencies": {
"@techmmunity/utils": "^1.5.0",
"chalk": "^5.0.0",
"commander": "^9.0.0"
"chalk": "^5.0.1",
"commander": "^9.3.0"
},
"devDependencies": {
"@techmmunity/eslint-config": "^5.2.2",
"@techmmunity/eslint-config": "^5.2.3",
"@thothom/core": "^0.0.1",
"@types/jest": "^27.0.1",
"eslint": "^8.9.0",
"husky": "^7.0.4",
"jest": "^27.5.1",
"lint-staged": "^12.3.3",
"prettier": "^2.3.2",
"@types/jest": "^27.5.1",
"eslint": "^8.16.0",
"husky": "^8.0.1",
"jest": "^28.1.0",
"lint-staged": "^12.4.2",
"prettier": "^2.6.2",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"ts-jest": "^27.1.3",
"ts-node": "^10.5.0",
"typescript": "^4.5.5"
"ts-jest": "^28.0.3",
"ts-node": "^10.8.0",
"typescript": "^4.7.2"
},
"scripts": {
"prepare": "husky install",
Expand Down
17 changes: 5 additions & 12 deletions src/cli/bin/index.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,23 @@
#!/usr/bin/env node

/* eslint-disable @typescript-eslint/no-require-imports */
/* eslint-disable @typescript-eslint/no-var-requires */

import { getRootPath } from "@techmmunity/utils";
import { program } from "commander";

import { loadCommands } from "../commands";

import { getThothVersion } from "../utils/get-thoth-version";
import { localBinExists } from "../utils/local-bin-exists";
import { loadLocalBinCommandLoader } from "../utils/local-binaries";

const bootstrap = () => {
const packageJsonPath = getRootPath("node_modules/@thothom/cli/package.json");
const bootstrap = async () => {
const thothVersion = getThothVersion();

program
.version(
require(packageJsonPath).version,
"-v, --version",
"Output the current version.",
)
.version(thothVersion, "-v, --version", "Output the current version.")
.usage("<command> [options]")
.helpOption("-h, --help", "Output usage information.");

if (localBinExists()) {
loadLocalBinCommandLoader(program);
await loadLocalBinCommandLoader(program);
} else {
loadCommands(program);
}
Expand Down
6 changes: 3 additions & 3 deletions src/cli/commands/gen-migration/gen-migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import { getThothVersion } from "../../utils/get-thoth-version";
import type { Plugin } from "../types/plugin";

export const genMigrations = async () => {
const migrationsPath = getMigrationsPath();
const migrationsPath = await getMigrationsPath();

const { connectionConfig, plugin, entitiesDir } = getConfigFile();
const { connectionConfig, plugin, entitiesDir } = await getConfigFile();

const pluginPath = getRootPath(`node_modules/${plugin}`);

Expand All @@ -28,7 +28,7 @@ export const genMigrations = async () => {
process.exit(1);
}

const { Connection } = require(pluginPath) as Plugin;
const { Connection } = (await import(pluginPath)) as Plugin;

const entities = await loadEntities(entitiesDir);

Expand Down
4 changes: 2 additions & 2 deletions src/cli/commands/migration-create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ interface Args {
description: string;
}

export const createMigration = ({ description }: Args) => {
const migrationsDirPath = getMigrationsPath();
export const createMigration = async ({ description }: Args) => {
const migrationsDirPath = await getMigrationsPath();

const template = getTemplate("migration:create");
const code = Date.now().toString();
Expand Down
18 changes: 11 additions & 7 deletions src/cli/commands/run-migrations.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-await-in-loop */
/* eslint-disable @typescript-eslint/naming-convention */

import { isEmptyArray, isPackageInstalled } from "@techmmunity/utils";
Expand All @@ -21,17 +22,19 @@ interface MigrationFile {
}

export const runMigrations = async () => {
const migrationsPath = getMigrationsPath();
const migrationsPath = await getMigrationsPath();

const { connectionConfig, plugin, entitiesDir } = getConfigFile();
const { connectionConfig, plugin, entitiesDir } = await getConfigFile();

if (!isPackageInstalled(plugin)) {
Logger.cliError(`Plugin not found: ${plugin}`);

process.exit(1);
}

const { Connection, QueryRunner, SyncManager } = require(plugin) as Plugin;
const { Connection, QueryRunner, SyncManager } = (await import(
plugin
)) as Plugin;

const entities = await loadEntities(entitiesDir);

Expand Down Expand Up @@ -60,15 +63,16 @@ export const runMigrations = async () => {
const queryRunner = new QueryRunner(connection);

for (const migrationFileName of notExecutedMigrations) {
const { Migration } =
require(`${migrationsPath}/${migrationFileName}`) as MigrationFile;
const { Migration } = (await import(
`${migrationsPath}/${migrationFileName}`
)) as MigrationFile;

const migration = new Migration();

try {
migration.up(queryRunner);
await migration.up(queryRunner);
} catch (err: any) {
migration.down(queryRunner).catch();
await migration.down(queryRunner).catch();
}
}
};
4 changes: 2 additions & 2 deletions src/cli/utils/get-config-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { existsSync } from "fs";

import type { ConfigFile } from "../types/config";

export const getConfigFile = () => {
export const getConfigFile = async () => {
const path = getRootPath("thothom.config.js");

if (existsSync(path)) {
const config = require(path) as ConfigFile;
const config = (await import(path)) as ConfigFile;

if (getTypeof(config) === "object") {
if (!config.plugin) {
Expand Down
6 changes: 3 additions & 3 deletions src/cli/utils/get-migrations-path.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Logger } from "@thothom/core";
import { getRootPath } from "@techmmunity/utils";
import { Logger } from "@thothom/core";
import { existsSync } from "fs";

import { getConfigFile } from "./get-config-file";

export const getMigrationsPath = () => {
const { migrationsDir } = getConfigFile();
export const getMigrationsPath = async () => {
const { migrationsDir } = await getConfigFile();

if (!migrationsDir) {
Logger.cliError("Missing config: migrationsDir");
Expand Down
26 changes: 24 additions & 2 deletions src/cli/utils/get-thoth-version.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,31 @@
import { getRootPath } from "@techmmunity/utils";
import { ThothError } from "@thothom/core";
import { readFileSync, existsSync } from "fs";

export const getThothVersion = () => {
const { dependencies } = require(getRootPath("package.json"));
const packageJsonPath = getRootPath("package.json");

const version = dependencies["@thothom/core"].replace("^", "");
if (!existsSync(packageJsonPath)) {
throw new ThothError({
message: "package.json was not found",
code: "AUTOMATION_FAILED",
origin: "THOTHOM",
details: [`Path: ${packageJsonPath}`],
});
}

const { dependencies } = JSON.parse(readFileSync(packageJsonPath, "utf8"));

const version = dependencies?.["@thothom/core"]?.replace("^", "");

if (!version) {
throw new ThothError({
message: "@thothom/cli version was not found on the dependencies",
code: "AUTOMATION_FAILED",
origin: "THOTHOM",
details: [`Path: ${packageJsonPath}`],
});
}

return version;
};
11 changes: 4 additions & 7 deletions src/cli/utils/local-binaries.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable @typescript-eslint/no-require-imports */

import { getRootPath } from "@techmmunity/utils";
import type { Command } from "commander";

export const loadLocalBinCommandLoader = (program: Command) => {
const { loadCommands } = require(getRootPath(
"node_modules/@thothom/cli/cli/commands",
));
export const loadLocalBinCommandLoader = async (program: Command) => {
const { loadCommands } = await import(
getRootPath("node_modules/@thothom/cli/cli/commands")
);

return loadCommands(program);
};
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@
"skipLibCheck": true,
"types": ["node", "jest", "reflect-metadata"]
},
"include": ["src/**/*.ts", "jest.config.js"]
"include": ["src/**/*.ts"]
}
Loading

0 comments on commit 4cfa12d

Please sign in to comment.