Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/cli/src/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
DeployJob,
DeployStep,
parseLogFileOption,
PolywrapDeploy,
Deployer,
defaultDeployManifest,
} from "../lib";

Expand Down Expand Up @@ -70,7 +70,7 @@ async function run(options: Required<DeployCommandOptions>): Promise<void> {
const { manifestFile, outputFile, verbose, quiet, logFile } = options;
const logger = createLogger({ verbose, quiet, logFile });

const deployer = await PolywrapDeploy.create(manifestFile, logger);
const deployer = await Deployer.create(manifestFile, logger);

const allStepsFromAllJobs = Object.entries(deployer.manifest.jobs).flatMap(
([jobName, job]) => {
Expand Down Expand Up @@ -117,7 +117,7 @@ async function run(options: Required<DeployCommandOptions>): Promise<void> {
return new DeployStep({
name: step.name,
uriOrStepResult: step.uri,
deployer: stepToPackageMap[step.name].deployer,
deployModule: stepToPackageMap[step.name].deployModule,
config: step.config ?? {},
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-require-imports */
/* eslint-disable @typescript-eslint/no-var-requires */
import { Deployer } from "../../../deploy";
import { DeployModule } from "../../../deploy";

import { Wallet } from "@ethersproject/wallet";
import { JsonRpcProvider } from "@ethersproject/providers";
Expand All @@ -13,7 +13,7 @@ import {
import { embeddedWrappers } from "@polywrap/test-env-js";
import { PolywrapClient } from "@polywrap/client-js";

class ENSRecursiveNameRegisterPublisher implements Deployer {
class ENSRecursiveNameRegisterPublisher implements DeployModule {
async execute(
uri: Uri,
config: {
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/lib/defaults/deploy-modules/ens/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-require-imports */
/* eslint-disable @typescript-eslint/no-var-requires */
import { Deployer } from "../../../deploy";
import { DeployModule } from "../../../deploy";

import { Wallet } from "@ethersproject/wallet";
import { JsonRpcProvider } from "@ethersproject/providers";
Expand All @@ -15,7 +15,7 @@ import { PolywrapClient } from "@polywrap/client-js";

const contentHash = require("content-hash");

class ENSPublisher implements Deployer {
class ENSPublisher implements DeployModule {
async execute(
uri: Uri,
config: {
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/lib/defaults/deploy-modules/http/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Deployer } from "../../../deploy/deployer";
import { DeployModule } from "../../../deploy";

import { Uri } from "@polywrap/core-js";
import FormData from "form-data";
Expand Down Expand Up @@ -33,7 +33,7 @@ const dirToFormData = (baseDirPath: string) => {
return formData;
};

class HTTPDeployer implements Deployer {
class HTTPDeployer implements DeployModule {
async execute(uri: Uri, config?: { postUrl: string }): Promise<Uri> {
if (!isValidUri(uri)) {
throw new Error(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Deployer } from "../../../deploy/deployer";
import { DeployModule } from "../../../deploy";

import { Uri } from "@polywrap/core-js";

class IPFSDeployer implements Deployer {
class IPFSDeployer implements DeployModule {
// eslint-disable-next-line @typescript-eslint/naming-convention
async execute(_: Uri, __: unknown): Promise<Uri> {
return new Uri(`ipfs/Qm`);
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/lib/defaults/deploy-modules/ipfs/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Deployer } from "../../../deploy/deployer";
import { DeployModule } from "../../../deploy";

import { Uri } from "@polywrap/core-js";

Expand All @@ -8,7 +8,7 @@ const { globSource } = IPFSClient;

const isValidUri = (uri: Uri) => uri.authority === "fs";

class IPFSDeployer implements Deployer {
class IPFSDeployer implements DeployModule {
async execute(uri: Uri, config?: { gatewayUri: string }): Promise<Uri> {
if (!isValidUri(uri)) {
throw new Error(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DeployStep, StepName, StepResult, UriOrPrevStepResult } from "./step";
import { DeployStep, StepName, StepResult, UriOrPrevStepResult } from "./DeployStep";
import { Logger } from "../logging";

import { Uri } from "@polywrap/core-js";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Uri } from "@polywrap/core-js";

export interface Deployer {
export interface DeployModule {
execute(uri: Uri, config?: unknown): Promise<Uri>;
}
8 changes: 8 additions & 0 deletions packages/cli/src/lib/deploy/DeployPackage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { DeployModule } from "./DeployModule";

import { Schema as JsonSchema } from "jsonschema";

export interface DeployPackage {
deployModule: DeployModule;
manifestExt: JsonSchema | undefined;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Deployer } from "./deployer";
import { DeployModule } from "./DeployModule";

import { Uri } from "@polywrap/core-js";

Expand All @@ -14,24 +14,24 @@ export interface StepResult {
interface StepArgs {
name: string;
uriOrStepResult: UriOrPrevStepResult;
deployer: Deployer;
deployModule: DeployModule;
config: Record<string, unknown>;
}

export class DeployStep {
public name: string;
public deployer: Deployer;
public deployModule: DeployModule;
public uriOrStepResult: string;
public config: Record<string, unknown>;

constructor(args: StepArgs) {
this.name = args.name;
this.deployer = args.deployer;
this.deployModule = args.deployModule;
this.uriOrStepResult = args.uriOrStepResult;
this.config = args.config;
}

public async run(uri: Uri, config: Record<string, unknown>): Promise<Uri> {
return await this.deployer.execute(uri, config);
return await this.deployModule.execute(uri, config);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-var-requires */

import { Deployer } from "./deployer";
import { DeployModule } from "./DeployModule";
import { loadDeployManifest, loadDeployManifestExt } from "../project";
import { CacheDirectory } from "../CacheDirectory";
import { Logger } from "../logging";
Expand All @@ -10,19 +10,19 @@ import { Schema as JsonSchema } from "jsonschema";
import path from "path";
import nodePath from "path";

interface PolywrapDeployConfig {
interface DeployerConfig {
cache: CacheDirectory;
logger: Logger;
defaultModulesCached: boolean;
}

export class PolywrapDeploy {
export class Deployer {
public static cacheLayout = {
root: "deploy/",
deployModulesDir: "modules/",
};
public manifest: DeployManifest;
private _config: PolywrapDeployConfig;
private _config: DeployerConfig;

private constructor(
manifest: DeployManifest,
Expand All @@ -40,24 +40,27 @@ export class PolywrapDeploy {
public static async create(
manifest: string,
logger: Logger
): Promise<PolywrapDeploy> {
): Promise<Deployer> {
const deployManifest = await loadDeployManifest(manifest, logger);
const cache = new CacheDirectory({
rootDir: nodePath.dirname(manifest),
subDir: PolywrapDeploy.cacheLayout.root,
subDir: Deployer.cacheLayout.root,
});
return new PolywrapDeploy(deployManifest, cache, logger);
return new Deployer(deployManifest, cache, logger);
}

public async getDeployModule(
moduleName: string
): Promise<{ deployer: Deployer; manifestExt: JsonSchema | undefined }> {
): Promise<{
deployModule: DeployModule;
manifestExt: JsonSchema | undefined;
}> {
if (!this._config.defaultModulesCached) {
throw new Error("Deploy modules have not been cached");
}

const cachePath = this._config.cache.getCachePath(
`${PolywrapDeploy.cacheLayout.deployModulesDir}/${moduleName}`
`${Deployer.cacheLayout.deployModulesDir}/${moduleName}`
);

const manifestExtPath = path.join(cachePath, "polywrap.deploy.ext.json");
Expand All @@ -69,7 +72,7 @@ export class PolywrapDeploy {

return {
// eslint-disable-next-line @typescript-eslint/no-require-imports
deployer: require(cachePath).default as Deployer,
deployModule: require(cachePath).default as DeployModule,
manifestExt,
};
}
Expand All @@ -79,13 +82,11 @@ export class PolywrapDeploy {
return;
}

this._config.cache.removeCacheDir(
PolywrapDeploy.cacheLayout.deployModulesDir
);
this._config.cache.removeCacheDir(Deployer.cacheLayout.deployModulesDir);

for await (const deployModule of modules) {
await this._config.cache.copyIntoCache(
`${PolywrapDeploy.cacheLayout.deployModulesDir}/${deployModule}`,
`${Deployer.cacheLayout.deployModulesDir}/${deployModule}`,
`${__dirname}/../defaults/deploy-modules/${deployModule}/*`,
{ up: true }
);
Expand Down
18 changes: 5 additions & 13 deletions packages/cli/src/lib/deploy/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
import { Deployer } from "./deployer";

import { Schema as JsonSchema } from "jsonschema";

export * from "./deployer";
export * from "./step";
export * from "./job";
export * from "./PolywrapDeploy";

export interface DeployPackage {
deployer: Deployer;
manifestExt: JsonSchema | undefined;
}
export * from "./Deployer";
export * from "./DeployModule";
export * from "./DeployPackage";
export * from "./DeployStep";
export * from "./DeployJob";
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12339,9 +12339,9 @@ minimalistic-crypto-utils@^1.0.1:
integrity sha512-JIYlbt6g8i5jKfJ3xz7rF0LXmv2TkDxBLUkiBeZ7bAx4GnnNMr8xFpGnOxn6GhTEHx3SjRrZEoU+j04prX1ktg==

minimatch@*:
version "6.0.4"
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-6.0.4.tgz#cbada37326e86dc19434874a04e29df0ba64cb17"
integrity sha512-9SQupyyavjdAc1VFjJS/5kdtFtlLAhKSWt7HocG0h/npy626jYrGegSslcM7Xxet5z0U9GOx9YbcpyIjBzn7tA==
version "6.1.0"
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-6.1.0.tgz#e0eafd0a19977f5accebd4b3909a34f6611d4288"
integrity sha512-eqe4xaKs1/JmNylXNFY2f41n3jNZAZTZlmOitWd71YazZlvvXMtzL+gK67jRKhrTQmHfrCbErYWV8z9Nz4aNuQ==
dependencies:
brace-expansion "^2.0.1"

Expand Down