Skip to content

Commit

Permalink
Merge pull request #1380 from polywrap/pileks/patch-0.9.3/add-migrati…
Browse files Browse the repository at this point in the history
…on-warnings

[Patch 0.9.3] - Add logging to migration actions
  • Loading branch information
dOrgJelli authored Nov 2, 2022
2 parents 03906ef + 8d11e45 commit 06e1eab
Show file tree
Hide file tree
Showing 52 changed files with 264 additions and 75 deletions.
1 change: 1 addition & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"@polywrap/test-env-js": "0.9.3",
"@polywrap/wasm-js": "0.9.3",
"@polywrap/wrap-manifest-types-js": "0.9.3",
"@polywrap/logging-js": "0.9.3",
"axios": "0.21.2",
"chalk": "4.1.0",
"chokidar": "3.5.1",
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/commands/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ const runMigrateCommand = async (

function migrateManifestFile(
manifestFile: string,
migrationFn: (input: string, to: string) => string,
migrationFn: (input: string, to: string, logger?: Logger) => string,
to: string,
logger: Logger
): void {
Expand All @@ -528,7 +528,7 @@ function migrateManifestFile(
encoding: "utf-8",
});

const outputManifestString = migrationFn(manifestString, to);
const outputManifestString = migrationFn(manifestString, to, logger);

// Cache the old manifest file
const cache = new CacheDirectory({
Expand Down
4 changes: 3 additions & 1 deletion packages/cli/src/commands/utils/createLogger.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { Logger, LogLevel, ConsoleLog } from "../../lib";
import { Logger, ConsoleLog } from "../../lib";

import { LogLevel } from "@polywrap/logging-js";

export function createLogger(flags: {
verbose?: boolean;
Expand Down
7 changes: 1 addition & 6 deletions packages/cli/src/lib/logging/Log.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
export enum LogLevel {
DEBUG,
INFO,
WARN,
ERROR,
}
import { LogLevel } from "@polywrap/logging-js";

export abstract class Log {
public readonly level: LogLevel;
Expand Down
6 changes: 4 additions & 2 deletions packages/cli/src/lib/logging/Logger.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { Log, LogLevel } from "./Log";
import { Log } from "./Log";

import { ILogger, LogLevel } from "@polywrap/logging-js";

interface Logs {
[name: string]: Log;
}

export class Logger {
export class Logger implements ILogger {
private _logs: Logs;

constructor(logs: Logs) {
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/lib/logging/logs/ConsoleLog.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Log, LogLevel } from "../Log";
import { Log } from "../Log";

import chalk from "chalk";
import { LogLevel } from "@polywrap/logging-js";

export class ConsoleLog extends Log {
constructor(level: LogLevel) {
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/lib/logging/logs/FileLog.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Log, LogLevel } from "../Log";
import { Log } from "../Log";

import fs, { WriteStream } from "fs";
import { LogLevel } from "@polywrap/logging-js";

export class FileLog extends Log {
private _logFileStream: WriteStream;
Expand Down
8 changes: 5 additions & 3 deletions packages/cli/src/lib/manifest/migrate/migrateAnyManifest.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
/* eslint-disable no-empty */

import { ILogger } from "@polywrap/logging-js";
import YAML from "yaml";

export function migrateAnyManifest(
manifestString: string,
manifestTypeName: string,
migrateFn: (manifest: unknown, to: string) => unknown,
to: string
migrateFn: (manifest: unknown, to: string, logger?: ILogger) => unknown,
to: string,
logger?: ILogger
): string {
let manifest: unknown | undefined;
try {
Expand All @@ -21,7 +23,7 @@ export function migrateAnyManifest(
throw Error(`Unable to parse ${manifestTypeName}: ${manifestString}`);
}

const newManifest = migrateFn(manifest, to);
const newManifest = migrateFn(manifest, to, logger);

const cleanedManifest = JSON.parse(JSON.stringify(newManifest));
delete cleanedManifest.__type;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import { migrateAnyManifest } from "./migrateAnyManifest";

import { migrateAppManifest } from "@polywrap/polywrap-manifest-types-js";
import { ILogger } from "@polywrap/logging-js";

export function migrateAppProjectManifest(
manifestString: string,
to: string
to: string,
logger?: ILogger
): string {
return migrateAnyManifest(
manifestString,
"AppManifest",
migrateAppManifest,
to
to,
logger
);
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import { migrateAnyManifest } from "./migrateAnyManifest";

import { migrateBuildManifest } from "@polywrap/polywrap-manifest-types-js";
import { ILogger } from "@polywrap/logging-js";

export function migrateBuildExtensionManifest(
manifestString: string,
to: string
to: string,
logger?: ILogger
): string {
return migrateAnyManifest(
manifestString,
"BuildManifest",
migrateBuildManifest,
to
to,
logger
);
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import { migrateAnyManifest } from "./migrateAnyManifest";

import { migrateDeployManifest } from "@polywrap/polywrap-manifest-types-js";
import { ILogger } from "@polywrap/logging-js";

export function migrateDeployExtensionManifest(
manifestString: string,
to: string
to: string,
logger?: ILogger
): string {
return migrateAnyManifest(
manifestString,
"DeployManifest",
migrateDeployManifest,
to
to,
logger
);
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import { migrateAnyManifest } from "./migrateAnyManifest";

import { migrateInfraManifest } from "@polywrap/polywrap-manifest-types-js";
import { ILogger } from "@polywrap/logging-js";

export function migrateInfraExtensionManifest(
manifestString: string,
to: string
to: string,
logger?: ILogger
): string {
return migrateAnyManifest(
manifestString,
"InfraManifest",
migrateInfraManifest,
to
to,
logger
);
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import { migrateAnyManifest } from "./migrateAnyManifest";

import { migrateMetaManifest } from "@polywrap/polywrap-manifest-types-js";
import { ILogger } from "@polywrap/logging-js";

export function migrateMetaExtensionManifest(
manifestString: string,
to: string
to: string,
logger?: ILogger
): string {
return migrateAnyManifest(
manifestString,
"MetaManifest",
migrateMetaManifest,
to
to,
logger
);
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import { migrateAnyManifest } from "./migrateAnyManifest";

import { migratePluginManifest } from "@polywrap/polywrap-manifest-types-js";
import { ILogger } from "@polywrap/logging-js";

export function migratePluginProjectManifest(
manifestString: string,
to: string
to: string,
logger?: ILogger
): string {
return migrateAnyManifest(
manifestString,
"PluginManifest",
migratePluginManifest,
to
to,
logger
);
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import { migrateAnyManifest } from "./migrateAnyManifest";

import { migratePolywrapManifest } from "@polywrap/polywrap-manifest-types-js";
import { ILogger } from "@polywrap/logging-js";

export function migratePolywrapProjectManifest(
manifestString: string,
to: string
to: string,
logger?: ILogger
): string {
return migrateAnyManifest(
manifestString,
"PolywrapManifest",
migratePolywrapManifest,
to
to,
logger
);
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import { migrateAnyManifest } from "./migrateAnyManifest";

import { migratePolywrapWorkflow } from "@polywrap/polywrap-manifest-types-js";
import { ILogger } from "@polywrap/logging-js";

export function migrateWorkflow(manifestString: string, to: string): string {
export function migrateWorkflow(
manifestString: string,
to: string,
logger?: ILogger
): string {
return migrateAnyManifest(
manifestString,
"PolywrapWorkflow",
migratePolywrapWorkflow,
to
to,
logger
);
}
2 changes: 1 addition & 1 deletion packages/cli/src/lib/project/manifests/app/load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export async function loadAppManifest(
}

try {
const result = deserializeAppManifest(manifest);
const result = deserializeAppManifest(manifest, { logger: logger });
return Promise.resolve(result);
} catch (e) {
return Promise.reject(e);
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/lib/project/manifests/plugin/load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export async function loadPluginManifest(
}

try {
const result = deserializePluginManifest(manifest);
const result = deserializePluginManifest(manifest, { logger: logger });
return Promise.resolve(result);
} catch (e) {
return Promise.reject(e);
Expand Down
11 changes: 6 additions & 5 deletions packages/cli/src/lib/project/manifests/polywrap/load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export async function loadPolywrapManifest(
}

try {
const result = deserializePolywrapManifest(manifest);
const result = deserializePolywrapManifest(manifest, { logger: logger });
return Promise.resolve(result);
} catch (e) {
return Promise.reject(e);
Expand Down Expand Up @@ -102,6 +102,7 @@ export async function loadBuildManifest(

return deserializeBuildManifest(manifest, {
extSchema: extSchema,
logger: logger,
});
};

Expand Down Expand Up @@ -137,7 +138,7 @@ export async function loadDeployManifest(
}

try {
let result = deserializeDeployManifest(manifest);
let result = deserializeDeployManifest(manifest, { logger: logger });
result = (loadEnvironmentVariables(
(result as unknown) as Record<string, unknown>
) as unknown) as DeployManifest;
Expand Down Expand Up @@ -213,7 +214,7 @@ export async function loadMetaManifest(
}

try {
const result = deserializeMetaManifest(manifest);
const result = deserializeMetaManifest(manifest, { logger: logger });
return Promise.resolve(result);
} catch (e) {
return Promise.reject(e);
Expand Down Expand Up @@ -252,7 +253,7 @@ export async function loadInfraManifest(
}

try {
let result = deserializeInfraManifest(manifest);
let result = deserializeInfraManifest(manifest, { logger: logger });
result = (loadEnvironmentVariables(
(result as unknown) as Record<string, unknown>
) as unknown) as InfraManifest;
Expand Down Expand Up @@ -294,7 +295,7 @@ export async function loadWorkflowManifest(
}

try {
const result = deserializePolywrapWorkflow(manifest);
const result = deserializePolywrapWorkflow(manifest, { logger: logger });
return Promise.resolve(result);
} catch (e) {
return Promise.reject(e);
Expand Down
8 changes: 8 additions & 0 deletions packages/js/logging/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# @polywrap/logging-js

An interface to which Loggers within the Polywrap Toolchain must conform.

Contains:

- `ILogger.ts` - the logger interface
- `LogLevel.ts` - the log levels supported by the logger
28 changes: 28 additions & 0 deletions packages/js/logging/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "@polywrap/logging-js",
"description": "Polywrap Core Logging Interface",
"version": "0.9.3",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/polywrap/monorepo.git"
},
"main": "build/index.js",
"files": [
"build"
],
"scripts": {
"build": "rimraf ./build && tsc --project tsconfig.build.json",
"lint": "eslint --color -c ../../../.eslintrc.js src/"
},
"dependencies": {
},
"devDependencies": {
"rimraf": "3.0.2",
"typescript": "4.1.6"
},
"gitHead": "7346adaf5adb7e6bbb70d9247583e995650d390a",
"publishConfig": {
"access": "public"
}
}
9 changes: 9 additions & 0 deletions packages/js/logging/src/ILogger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { LogLevel } from "./LogLevel";

export interface ILogger {
log(message: string, level: LogLevel): void;
debug(message: string): void;
info(message: string): void;
warn(message: string): void;
error(message: string): void;
}
6 changes: 6 additions & 0 deletions packages/js/logging/src/LogLevel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export enum LogLevel {
DEBUG,
INFO,
WARN,
ERROR,
}
Loading

0 comments on commit 06e1eab

Please sign in to comment.