From f9812c62ef2d6bfe7265ae328a378dd13282f809 Mon Sep 17 00:00:00 2001 From: krisbitney Date: Thu, 20 Oct 2022 11:09:14 +0500 Subject: [PATCH 01/38] added first draft of cli-api --- package.json | 2 +- packages/cli/package.json | 2 + packages/cli/src/__tests__/e2e/build.spec.ts | 2 +- packages/cli/src/commands/build.ts | 14 +-- packages/cli/src/commands/codegen.ts | 2 +- packages/cli/src/commands/create.ts | 11 +- packages/cli/src/commands/deploy.ts | 2 +- packages/cli/src/commands/docgen.ts | 7 +- packages/cli/src/commands/infra.ts | 31 +++-- packages/cli/src/commands/manifest.ts | 6 +- packages/cli/src/commands/run.ts | 19 ++- packages/cli/src/index.ts | 19 +++ packages/js/cli-api/README.md | 35 ++++++ packages/js/cli-api/package.json | 29 +++++ packages/js/cli-api/src/commands.ts | 103 +++++++++++++++++ packages/js/cli-api/src/index.ts | 3 + packages/js/cli-api/src/run-cli.ts | 64 +++++++++++ packages/js/cli-api/src/types.ts | 108 ++++++++++++++++++ packages/js/cli-api/src/utils/ICommands.ts | 61 ++++++++++ .../js/cli-api/src/utils/declarations.d.ts | 7 ++ packages/js/cli-api/src/utils/index.ts | 1 + packages/js/cli-api/tsconfig.build.json | 9 ++ packages/js/cli-api/tsconfig.json | 10 ++ .../assemblyscript/012-no-codegen/cmd.json | 2 +- 24 files changed, 504 insertions(+), 45 deletions(-) create mode 100644 packages/cli/src/index.ts create mode 100644 packages/js/cli-api/README.md create mode 100644 packages/js/cli-api/package.json create mode 100644 packages/js/cli-api/src/commands.ts create mode 100644 packages/js/cli-api/src/index.ts create mode 100644 packages/js/cli-api/src/run-cli.ts create mode 100644 packages/js/cli-api/src/types.ts create mode 100644 packages/js/cli-api/src/utils/ICommands.ts create mode 100644 packages/js/cli-api/src/utils/declarations.d.ts create mode 100644 packages/js/cli-api/src/utils/index.ts create mode 100644 packages/js/cli-api/tsconfig.build.json create mode 100644 packages/js/cli-api/tsconfig.json diff --git a/package.json b/package.json index 2befafc862..9b1625fd50 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "dependencies:install": "cd dependencies && yarn", "preinstall": "yarn dependencies:install", "build": "yarn build:core && yarn build:interfaces && yarn build:plugins && yarn build:resolver:plugins && yarn build:config && yarn build:client && yarn build:test-env && yarn build:cli", - "build:core": "lerna run build --no-private --ignore @polywrap/*-plugin-js --ignore @polywrap/client-config-builder-js --ignore polywrap --ignore @polywrap/client-js --ignore @polywrap/react --ignore @polywrap/test-env-js --ignore @polywrap/*-interface", + "build:core": "lerna run build --no-private --ignore @polywrap/*-plugin-js --ignore @polywrap/client-config-builder-js --ignore polywrap --ignore @polywrap/client-js --ignore @polywrap/react --ignore @polywrap/test-env-js --ignore @polywrap/*-interface --ignore @polywrap/cli-js", "build:interfaces": "lerna run build --scope @polywrap/*-interface", "build:plugins": "lerna run build --scope @polywrap/*-plugin-js --ignore @polywrap/*-resolver-plugin-js", "build:resolver:plugins": "lerna run build --scope @polywrap/*-resolver-plugin-js", diff --git a/packages/cli/package.json b/packages/cli/package.json index cd533f4995..c9b02c089d 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -15,6 +15,8 @@ "bin": { "polywrap": "bin/polywrap" }, + "main": "build/index.js", + "types": "build/types/index.d.ts", "scripts": { "build": "yarn build:intl && yarn build:fast", "build:fast": "rimraf ./build && tsc --project tsconfig.build.json && yarn build:build-strategies && yarn build:deploy-modules && yarn build:infra-modules && yarn build:docgen-templates", diff --git a/packages/cli/src/__tests__/e2e/build.spec.ts b/packages/cli/src/__tests__/e2e/build.spec.ts index 5765dfc696..b0303f4e01 100644 --- a/packages/cli/src/__tests__/e2e/build.spec.ts +++ b/packages/cli/src/__tests__/e2e/build.spec.ts @@ -17,7 +17,7 @@ Options: (default: ./build) -c, --client-config Add custom configuration to the PolywrapClient - -n, --no-codegen Skip code generation + -n, --skip-codegen Skip code generation -s, --strategy Strategy to use for building the wrapper (default: "vm") -w, --watch Automatically rebuild when changes are diff --git a/packages/cli/src/commands/build.ts b/packages/cli/src/commands/build.ts index 5b9a1478ee..a9aa8994f4 100644 --- a/packages/cli/src/commands/build.ts +++ b/packages/cli/src/commands/build.ts @@ -33,11 +33,11 @@ const strategyStr = intlMsg.commands_build_options_s_strategy(); const defaultManifestStr = defaultPolywrapManifest.join(" | "); const pathStr = intlMsg.commands_build_options_o_path(); -type BuildCommandOptions = { +export type BuildCommandOptions = { manifestFile: string; outputDir: string; clientConfig: Partial; - codegen: boolean; // defaults to true + skipCodegen?: boolean; watch?: boolean; strategy: SupportedStrategies; verbose?: boolean; @@ -66,7 +66,7 @@ export const build: Command = { `-c, --client-config <${intlMsg.commands_common_options_configPath()}>`, `${intlMsg.commands_common_options_config()}` ) - .option(`-n, --no-codegen`, `${intlMsg.commands_build_options_n()}`) + .option(`-n, --skip-codegen`, `${intlMsg.commands_build_options_n()}`) .option( `-s, --strategy <${strategyStr}>`, `${intlMsg.commands_build_options_s()}`, @@ -132,7 +132,7 @@ async function run(options: BuildCommandOptions) { outputDir, clientConfig, strategy, - codegen, + skipCodegen, verbose, quiet, } = options; @@ -159,9 +159,9 @@ async function run(options: BuildCommandOptions) { }); const execute = async (): Promise => { - const codeGenerator = codegen - ? new CodeGenerator({ project, schemaComposer }) - : undefined; + const codeGenerator = skipCodegen + ? undefined + : new CodeGenerator({ project, schemaComposer }); const compiler = new Compiler({ project, diff --git a/packages/cli/src/commands/codegen.ts b/packages/cli/src/commands/codegen.ts index 3ff81f8a1c..e5840bc753 100644 --- a/packages/cli/src/commands/codegen.ts +++ b/packages/cli/src/commands/codegen.ts @@ -27,7 +27,7 @@ const defaultPublishDir = "./build"; const pathStr = intlMsg.commands_codegen_options_o_path(); const defaultManifestStr = defaultPolywrapManifest.join(" | "); -type CodegenCommandOptions = { +export type CodegenCommandOptions = { manifestFile: string; codegenDir: string; publishDir: string; diff --git a/packages/cli/src/commands/create.ts b/packages/cli/src/commands/create.ts index e071e6f4f8..b80d8adeeb 100644 --- a/packages/cli/src/commands/create.ts +++ b/packages/cli/src/commands/create.ts @@ -23,8 +23,15 @@ export const supportedLangs = { }; export type ProjectType = keyof typeof supportedLangs; -export type SupportedLangs = typeof supportedLangs[ProjectType][number]; -type CreateCommandOptions = { +export type SupportedWasmLangs = typeof supportedLangs.wasm[number]; +export type SupportedAppLangs = typeof supportedLangs.app[number]; +export type SupportedPluginLangs = typeof supportedLangs.plugin[number]; +type SupportedLangs = + | SupportedWasmLangs + | SupportedAppLangs + | SupportedPluginLangs; + +export type CreateCommandOptions = { outputDir?: string; verbose?: boolean; quiet?: boolean; diff --git a/packages/cli/src/commands/deploy.ts b/packages/cli/src/commands/deploy.ts index c35f6ef210..853f733b85 100644 --- a/packages/cli/src/commands/deploy.ts +++ b/packages/cli/src/commands/deploy.ts @@ -20,7 +20,7 @@ import { validate } from "jsonschema"; const defaultManifestStr = defaultPolywrapManifest.join(" | "); const pathStr = intlMsg.commands_deploy_options_o_path(); -type DeployCommandOptions = { +export type DeployCommandOptions = { manifestFile: string; outputFile?: string; verbose?: boolean; diff --git a/packages/cli/src/commands/docgen.ts b/packages/cli/src/commands/docgen.ts index b207ee0da2..933c0c5124 100644 --- a/packages/cli/src/commands/docgen.ts +++ b/packages/cli/src/commands/docgen.ts @@ -26,12 +26,10 @@ const commandToPathMap: Record = { jsdoc: jsdocScriptPath, }; -export type DocType = keyof typeof commandToPathMap; - const defaultDocgenDir = "./docs"; const pathStr = intlMsg.commands_codegen_options_o_path(); -type DocgenCommandOptions = { +export type DocgenCommandOptions = { manifestFile: string; docgenDir: string; clientConfig: Partial; @@ -45,6 +43,7 @@ enum Actions { DOCUSAURUS = "docusaurus", JSDOC = "jsdoc", } +export type DocgenAction = keyof Record; const argumentsDescription = ` ${chalk.bold(Actions.SCHEMA)} ${intlMsg.commands_docgen_options_schema()} @@ -107,7 +106,7 @@ export const docgen: Command = { }, }; -async function run(command: DocType, options: DocgenCommandOptions) { +async function run(command: DocgenAction, options: DocgenCommandOptions) { const { manifestFile, docgenDir, diff --git a/packages/cli/src/commands/infra.ts b/packages/cli/src/commands/infra.ts index 3cac5c8039..3ff37f4bde 100644 --- a/packages/cli/src/commands/infra.ts +++ b/packages/cli/src/commands/infra.ts @@ -15,11 +15,11 @@ import chalk from "chalk"; import yaml from "yaml"; import { readdirSync } from "fs"; -type InfraCommandOptions = { - modules?: string; +export type InfraCommandOptions = { + manifestFile: string; + modules?: string[]; verbose?: boolean; quiet?: boolean; - manifest: string; }; enum InfraActions { @@ -28,6 +28,7 @@ enum InfraActions { VARS = "vars", CONFIG = "config", } +export type InfraAction = keyof Record; const DEFAULT_MODULES_PATH = path.join( __dirname, @@ -74,18 +75,13 @@ export const infra: Command = { }) ) .option( - `-o, --modules <${moduleNameStr},${moduleNameStr}>`, + `-o, --modules <${moduleNameStr}...>`, intlMsg.commands_infra_options_o() ) .option("-v, --verbose", intlMsg.commands_common_options_verbose()) .option("-q, --quiet", intlMsg.commands_common_options_quiet()) .action(async (action, options) => { - await run(action, { - ...options, - manifest: options.manifestFile - ? [options.manifestFile] - : defaultInfraManifest, - }); + await run(action, options); }); }, }; @@ -100,18 +96,17 @@ Example: 'polywrap infra up --modules=eth-ens-ipfs'.`; async function run( action: InfraActions, - options: InfraCommandOptions & { manifest: string[] } + options: InfraCommandOptions ): Promise { - const { modules, verbose, quiet, manifest } = options; + const { modules, verbose, quiet, manifestFile } = options; const logger = createLogger({ verbose, quiet }); - // eslint-disable-next-line prefer-const - let modulesArray: string[] = []; - if (modules) { - modulesArray = modules.split(",").map((m: string) => m.trim()); - } + const modulesArray: string[] = modules ?? []; + const manifest: string[] = manifestFile + ? [manifestFile] + : defaultInfraManifest; const manifestPath = resolvePathIfExists(manifest); let infraManifest: InfraManifest | undefined; @@ -143,7 +138,7 @@ async function run( if (!filteredModules.length) { if (modules) { const errorMsg = intlMsg.commands_infra_error_noModulesMatch({ - modules, + modules: modules.join(", "), }); logger.error(errorMsg); return; diff --git a/packages/cli/src/commands/manifest.ts b/packages/cli/src/commands/manifest.ts index 65696fac62..825ac83e7a 100644 --- a/packages/cli/src/commands/manifest.ts +++ b/packages/cli/src/commands/manifest.ts @@ -74,16 +74,16 @@ const manifestTypes = [ "meta", "workflow", ] as const; -type ManifestType = typeof manifestTypes[number]; +export type ManifestType = typeof manifestTypes[number]; -type ManifestSchemaCommandOptions = { +export type ManifestSchemaCommandOptions = { raw: boolean; manifestFile: ManifestType; verbose?: boolean; quiet?: boolean; }; -type ManifestMigrateCommandOptions = { +export type ManifestMigrateCommandOptions = { manifestFile: string; format: string; verbose?: boolean; diff --git a/packages/cli/src/commands/run.ts b/packages/cli/src/commands/run.ts index 0d74fd17b7..908d51ddab 100644 --- a/packages/cli/src/commands/run.ts +++ b/packages/cli/src/commands/run.ts @@ -23,9 +23,9 @@ import path from "path"; import yaml from "yaml"; import fs from "fs"; -type WorkflowCommandOptions = { +export type RunCommandOptions = { clientConfig: Partial; - manifest: string; + manifestFile: string; jobs?: string[]; validationScript?: string; outputFile?: string; @@ -65,7 +65,7 @@ export const run: Command = { .action(async (options) => { await _run({ ...options, - manifest: parseManifestFileOption( + manifestFile: parseManifestFileOption( options.manifestFile, defaultWorkflowManifest ), @@ -78,12 +78,19 @@ export const run: Command = { }, }; -const _run = async (options: WorkflowCommandOptions) => { - const { manifest, clientConfig, outputFile, verbose, quiet, jobs } = options; +const _run = async (options: RunCommandOptions) => { + const { + manifestFile, + clientConfig, + outputFile, + verbose, + quiet, + jobs, + } = options; const logger = createLogger({ verbose, quiet }); const client = new PolywrapClient(clientConfig); - const manifestPath = path.resolve(manifest); + const manifestPath = path.resolve(manifestFile); const workflow = await loadWorkflowManifest(manifestPath, logger); validateJobNames(workflow.jobs); const validationScript = workflow.validation diff --git a/packages/cli/src/index.ts b/packages/cli/src/index.ts new file mode 100644 index 0000000000..53112786e2 --- /dev/null +++ b/packages/cli/src/index.ts @@ -0,0 +1,19 @@ +export { + BuildCommandOptions, + CodegenCommandOptions, + CreateCommandOptions, + DeployCommandOptions, + DocgenCommandOptions, + InfraCommandOptions, + ManifestMigrateCommandOptions, + ManifestSchemaCommandOptions, + RunCommandOptions, + ManifestType, + ProjectType, + SupportedWasmLangs, + SupportedPluginLangs, + SupportedAppLangs, + DocgenAction, + InfraAction, +} from "./commands"; +export { SupportedStrategies } from "./lib/build-strategies"; diff --git a/packages/js/cli-api/README.md b/packages/js/cli-api/README.md new file mode 100644 index 0000000000..a0f39cf556 --- /dev/null +++ b/packages/js/cli-api/README.md @@ -0,0 +1,35 @@ +# @polywrap/cli-js + +Programmatically execute the Polywrap CLI + +# Description + +It allows user execute Polywrap CLI commands programmatically, with simple and type-safe methods. + +# Usage + +Start infra and build a wrapper + +``` typescript +import { Commands } from "@polywrap/cli-js; +import path from "path"; + +// test wrapper in a test environment +export async function foo({ + // spin up infra modules defined in a polywrap.infra.yaml manifest + await Commands.infra({ verbose: true }); + + // get path to the wrapper + const wrapperPath: string = path.join(path.resolve(__dirname), ".."); + + // build current wrapper with CLI + await Commands.build(undefined, wrapperPath); + + // get URI to the local wrapper build + const wrapperUri = `fs/${wrapperPath}/build`; +}); +``` + +# Reference + +TODO diff --git a/packages/js/cli-api/package.json b/packages/js/cli-api/package.json new file mode 100644 index 0000000000..0cafba1071 --- /dev/null +++ b/packages/js/cli-api/package.json @@ -0,0 +1,29 @@ +{ + "name": "@polywrap/cli-js", + "description": "Programmatically execute the Polywrap CLI", + "version": "0.9.2", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/polywrap/toolchain.git" + }, + "main": "build/index.js", + "files": [ + "build" + ], + "scripts": { + "build": "rimraf ./build && tsc --project tsconfig.build.json", + "lint": "eslint --color -c ../../../.eslintrc.js src/" + }, + "dependencies": { + "polywrap": "0.9.2", + "spawn-command": "0.0.2-1" + }, + "devDependencies": { + "rimraf": "3.0.2", + "typescript": "4.1.6" + }, + "publishConfig": { + "access": "public" + } +} diff --git a/packages/js/cli-api/src/commands.ts b/packages/js/cli-api/src/commands.ts new file mode 100644 index 0000000000..99d7561da6 --- /dev/null +++ b/packages/js/cli-api/src/commands.ts @@ -0,0 +1,103 @@ +import { runCLI } from "./run-cli"; +import { ICommands } from "./utils"; +import { + BuildCommandOptions, + CodegenCommandOptions, + CreateCommandOptions, + DeployCommandOptions, + DocgenCommandOptions, + InfraCommandOptions, + ManifestCommandOptions, + RunCommandOptions, +} from "./types"; + +export const commands: ICommands = { + build: simpleCommandExecutorFactory("build"), + codegen: simpleCommandExecutorFactory("codegen"), + create: createCommandExecutor, + deploy: simpleCommandExecutorFactory("deploy"), + docgen: actionCommandExecutorFactory("docgen"), + infra: actionCommandExecutorFactory("infra"), + manifest: manifestCommandExecutor, + run: simpleCommandExecutorFactory("run"), +}; + +type CommandOptions = + | BuildCommandOptions + | CodegenCommandOptions + | CreateCommandOptions + | DeployCommandOptions + | DocgenCommandOptions + | InfraCommandOptions + | ManifestCommandOptions + | RunCommandOptions; + +function toKebabCase(camelCase: string): string { + return camelCase.replace(/([a-z])([A-Z])/g, "$1-$2"); +} + +function parseValue(value: string | string[] | boolean): string { + if (Array.isArray(value)) { + return value.join(" "); + } + return value.toString(); +} + +function parseOptions(options?: CommandOptions): string[] { + const parsed: string[] = []; + if (options) { + for (const [key, value] of Object.entries(options)) { + if (value === undefined) continue; + parsed.push(toKebabCase(key)); + parsed.push(parseValue(value)); + } + } + return parsed; +} + +function simpleCommandExecutorFactory(command: string) { + return async (options?: CommandOptions, cwd?: string, cli?: string) => { + const args = [command, ...parseOptions(options)]; + return await runCLI({ args, cwd, cli }); + }; +} + +function actionCommandExecutorFactory(command: string) { + return async ( + options: InfraCommandOptions | DocgenCommandOptions, + cwd?: string, + cli?: string + ) => { + const { action, ...cmdOptions } = options; + const args = [command, action, ...parseOptions(cmdOptions)]; + return await runCLI({ args, cwd, cli }); + }; +} + +async function createCommandExecutor( + options: CreateCommandOptions, + cwd?: string, + cli?: string +): Promise<{ + exitCode: number; + stdout: string; + stderr: string; +}> { + const { command, language, name, ...createOpts } = options; + const args = ["create", command, language, name, ...parseOptions(createOpts)]; + return await runCLI({ args, cwd, cli }); +} + +async function manifestCommandExecutor( + options: ManifestCommandOptions, + cwd?: string, + cli?: string +): Promise<{ + exitCode: number; + stdout: string; + stderr: string; +}> { + const { command, type, ...manifestOptions } = options; + const args = ["manifest", command, type, ...parseOptions(manifestOptions)]; + return await runCLI({ args, cwd, cli }); +} diff --git a/packages/js/cli-api/src/index.ts b/packages/js/cli-api/src/index.ts new file mode 100644 index 0000000000..6c7da4d89a --- /dev/null +++ b/packages/js/cli-api/src/index.ts @@ -0,0 +1,3 @@ +export * from "./types"; +export { runCLI } from "./run-cli"; +export { commands as Commands } from "./commands"; diff --git a/packages/js/cli-api/src/run-cli.ts b/packages/js/cli-api/src/run-cli.ts new file mode 100644 index 0000000000..457a94304f --- /dev/null +++ b/packages/js/cli-api/src/run-cli.ts @@ -0,0 +1,64 @@ +import path from "path"; +import fs from "fs"; +import spawn from "spawn-command"; + +const monorepoCli = `${__dirname}/../../../cli/bin/polywrap`; +const npmCli = `${__dirname}/../../../polywrap/bin/polywrap`; + +export const runCLI = async (options: { + args: string[]; + cwd?: string; + cli?: string; + env?: Record; +}): Promise<{ + exitCode: number; + stdout: string; + stderr: string; +}> => { + const [exitCode, stdout, stderr] = await new Promise((resolve, reject) => { + if (!options.cwd) { + // Make sure to set an absolute working directory + const cwd = process.cwd(); + options.cwd = cwd[0] !== "/" ? path.resolve(__dirname, cwd) : cwd; + } + + // Resolve the CLI + if (!options.cli) { + if (fs.existsSync(monorepoCli)) { + options.cli = monorepoCli; + } else if (fs.existsSync(npmCli)) { + options.cli = npmCli; + } else { + throw Error(`runCli is missing a valid CLI path, please provide one`); + } + } + + const command = `node ${options.cli} ${options.args.join(" ")}`; + const child = spawn(command, { cwd: options.cwd, env: options.env }); + + let stdout = ""; + let stderr = ""; + + child.on("error", (error: Error) => { + reject(error); + }); + + child.stdout?.on("data", (data: string) => { + stdout += data.toString(); + }); + + child.stderr?.on("data", (data: string) => { + stderr += data.toString(); + }); + + child.on("exit", (exitCode: number) => { + resolve([exitCode, stdout, stderr]); + }); + }); + + return { + exitCode, + stdout, + stderr, + }; +}; diff --git a/packages/js/cli-api/src/types.ts b/packages/js/cli-api/src/types.ts new file mode 100644 index 0000000000..63d2ca393c --- /dev/null +++ b/packages/js/cli-api/src/types.ts @@ -0,0 +1,108 @@ +import { + BuildCommandOptions as ParsedBuildCommandOptions, + CodegenCommandOptions as ParsedCodegenCommandOptions, + CreateCommandOptions as ParsedCreateCommandOptions, + DeployCommandOptions as ParsedDeployCommandOptions, + DocgenCommandOptions as ParsedDocgenCommandOptions, + InfraCommandOptions as ParsedInfraCommandOptions, + ManifestMigrateCommandOptions as ParsedManifestMigrateCommandOptions, + ManifestSchemaCommandOptions as ParsedManifestSchemaCommandOptions, + RunCommandOptions as ParsedRunCommandOptions, + SupportedWasmLangs, + SupportedPluginLangs, + SupportedAppLangs, + DocgenAction, + InfraAction, + ManifestType, +} from "polywrap"; + +export type DeployCommandOptions = Partial; + +export type BuildCommandOptions = Omit< + Partial, + "watch" | "clientConfig" +> & { + clientConfig?: string; +}; + +export type CodegenCommandOptions = Omit< + Partial, + "clientConfig" +> & { + clientConfig?: string; +}; + +export type RunCommandOptions = Omit< + Partial, + "clientConfig" +> & { + clientConfig?: string; +}; + +// create + +export type CreateWasmCommandArgs = { + command: "wasm"; + language: SupportedWasmLangs; + name: string; +}; + +export type CreatePluginCommandArgs = { + command: "plugin"; + language: SupportedPluginLangs; + name: string; +}; + +export type CreateAppCommandArgs = { + command: "app"; + language: SupportedAppLangs; + name: string; +}; + +export type CreateCommandArgs = + | CreateWasmCommandArgs + | CreatePluginCommandArgs + | CreateAppCommandArgs; + +export type CreateCommandOptions = CreateCommandArgs & + Partial; + +// docgen + +export type DocgenCommandArgs = { + action: DocgenAction; +}; + +export type DocgenCommandOptions = DocgenCommandArgs & + Omit, "clientConfig"> & { + clientConfig?: string; + }; + +// infra + +export type InfraCommandArgs = { + action: InfraAction; +}; + +export type InfraCommandOptions = InfraCommandArgs & + Partial; + +// manifest + +export type ManifestSchemaCommandArgs = { + command: "schema"; + type: ManifestType; +}; + +export type ManifestMigrateCommandArgs = { + command: "migrate"; + type: ManifestType; +}; + +export type ManifestSchemaCommandOptions = Partial; + +export type ManifestMigrateCommandOptions = Partial; + +export type ManifestCommandOptions = + | (ManifestSchemaCommandArgs & ManifestSchemaCommandOptions) + | (ManifestMigrateCommandArgs & ManifestMigrateCommandOptions); diff --git a/packages/js/cli-api/src/utils/ICommands.ts b/packages/js/cli-api/src/utils/ICommands.ts new file mode 100644 index 0000000000..8f79fc5350 --- /dev/null +++ b/packages/js/cli-api/src/utils/ICommands.ts @@ -0,0 +1,61 @@ +import { runCLI } from "./run-cli"; +import { + BuildCommandOptions, + CodegenCommandOptions, + CreateCommandOptions, + DeployCommandOptions, + DocgenCommandOptions, + InfraCommandOptions, + ManifestCommandOptions, + RunCommandOptions, +} from "./types"; + +export interface ICommands { + readonly build: ( + options?: BuildCommandOptions, + cwd?: string, + cli?: string + ) => ReturnType; + + readonly codegen: ( + options?: CodegenCommandOptions, + cwd?: string, + cli?: string + ) => ReturnType; + + readonly create: ( + options: CreateCommandOptions, + cwd?: string, + cli?: string + ) => ReturnType; + + readonly deploy: ( + options?: DeployCommandOptions, + cwd?: string, + cli?: string + ) => ReturnType; + + readonly docgen: ( + options: DocgenCommandOptions, + cwd?: string, + cli?: string + ) => ReturnType; + + readonly infra: ( + options: InfraCommandOptions, + cwd?: string, + cli?: string + ) => ReturnType; + + readonly manifest: ( + options: ManifestCommandOptions, + cwd?: string, + cli?: string + ) => ReturnType; + + readonly run: ( + options?: RunCommandOptions, + cwd?: string, + cli?: string + ) => ReturnType; +} diff --git a/packages/js/cli-api/src/utils/declarations.d.ts b/packages/js/cli-api/src/utils/declarations.d.ts new file mode 100644 index 0000000000..37d190a635 --- /dev/null +++ b/packages/js/cli-api/src/utils/declarations.d.ts @@ -0,0 +1,7 @@ +declare module "spawn-command" { + import { ChildProcess } from "child_process"; + export default function spawn( + command: string, + options?: Record + ): ChildProcess; +} diff --git a/packages/js/cli-api/src/utils/index.ts b/packages/js/cli-api/src/utils/index.ts new file mode 100644 index 0000000000..64e271203c --- /dev/null +++ b/packages/js/cli-api/src/utils/index.ts @@ -0,0 +1 @@ +export * from "./ICommands"; diff --git a/packages/js/cli-api/tsconfig.build.json b/packages/js/cli-api/tsconfig.build.json new file mode 100644 index 0000000000..77aadfdd2f --- /dev/null +++ b/packages/js/cli-api/tsconfig.build.json @@ -0,0 +1,9 @@ +{ + "extends": "./tsconfig.json", + "include": [ + "./src/**/*.ts" + ], + "exclude": [ + "./src/**/__tests__" + ] +} diff --git a/packages/js/cli-api/tsconfig.json b/packages/js/cli-api/tsconfig.json new file mode 100644 index 0000000000..5d37204c00 --- /dev/null +++ b/packages/js/cli-api/tsconfig.json @@ -0,0 +1,10 @@ +{ + "extends": "../../../tsconfig", + "compilerOptions": { + "outDir": "build" + }, + "include": [ + "./src/**/*.ts" + ], + "exclude": [] +} diff --git a/packages/test-cases/cases/cli/wasm/build-cmd/assemblyscript/012-no-codegen/cmd.json b/packages/test-cases/cases/cli/wasm/build-cmd/assemblyscript/012-no-codegen/cmd.json index 0fa14b3655..eca753fdab 100644 --- a/packages/test-cases/cases/cli/wasm/build-cmd/assemblyscript/012-no-codegen/cmd.json +++ b/packages/test-cases/cases/cli/wasm/build-cmd/assemblyscript/012-no-codegen/cmd.json @@ -1,3 +1,3 @@ { - "args": ["--no-codegen"] + "args": ["--skip-codegen"] } \ No newline at end of file From 9e09bee5db3c5f20a732aa7a3da56ab57671ad72 Mon Sep 17 00:00:00 2001 From: krisbitney Date: Thu, 20 Oct 2022 13:14:45 +0500 Subject: [PATCH 02/38] added awaitResponse to cli-js --- packages/js/cli-api/README.md | 5 +++- packages/js/cli-api/src/awaitResponse.ts | 28 ++++++++++++++++++++++ packages/js/cli-api/src/index.ts | 1 + packages/js/cli-api/src/utils/ICommands.ts | 4 ++-- 4 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 packages/js/cli-api/src/awaitResponse.ts diff --git a/packages/js/cli-api/README.md b/packages/js/cli-api/README.md index a0f39cf556..a5db385a07 100644 --- a/packages/js/cli-api/README.md +++ b/packages/js/cli-api/README.md @@ -18,6 +18,9 @@ import path from "path"; export async function foo({ // spin up infra modules defined in a polywrap.infra.yaml manifest await Commands.infra({ verbose: true }); + + // wait for infra to be ready to go + await awaitResponse("http://localhost:5001"); // get path to the wrapper const wrapperPath: string = path.join(path.resolve(__dirname), ".."); @@ -25,7 +28,7 @@ export async function foo({ // build current wrapper with CLI await Commands.build(undefined, wrapperPath); - // get URI to the local wrapper build + // get invokable URI to the local wrapper build const wrapperUri = `fs/${wrapperPath}/build`; }); ``` diff --git a/packages/js/cli-api/src/awaitResponse.ts b/packages/js/cli-api/src/awaitResponse.ts new file mode 100644 index 0000000000..9cc989f33e --- /dev/null +++ b/packages/js/cli-api/src/awaitResponse.ts @@ -0,0 +1,28 @@ +import axios from "axios"; + +export async function awaitResponse( + url: string, + timeout = 2000, + maxTimeout = 20000 +): Promise { + let time = 0; + + while (time < maxTimeout) { + const request = axios.get(url, { timeout }); + const success = await request + .then(() => true) + .catch((e) => e.code !== "ECONNRESET"); + + if (success) { + return true; + } + + await new Promise(function (resolve) { + setTimeout(() => resolve(), timeout); + }); + + time += timeout; + } + + return false; +} diff --git a/packages/js/cli-api/src/index.ts b/packages/js/cli-api/src/index.ts index 6c7da4d89a..73f992f8d8 100644 --- a/packages/js/cli-api/src/index.ts +++ b/packages/js/cli-api/src/index.ts @@ -1,3 +1,4 @@ export * from "./types"; export { runCLI } from "./run-cli"; export { commands as Commands } from "./commands"; +export * from "./awaitResponse"; diff --git a/packages/js/cli-api/src/utils/ICommands.ts b/packages/js/cli-api/src/utils/ICommands.ts index 8f79fc5350..a1c4f47025 100644 --- a/packages/js/cli-api/src/utils/ICommands.ts +++ b/packages/js/cli-api/src/utils/ICommands.ts @@ -1,4 +1,4 @@ -import { runCLI } from "./run-cli"; +import { runCLI } from "../run-cli"; import { BuildCommandOptions, CodegenCommandOptions, @@ -8,7 +8,7 @@ import { InfraCommandOptions, ManifestCommandOptions, RunCommandOptions, -} from "./types"; +} from "../types"; export interface ICommands { readonly build: ( From 82795714ff0be71575aa5c140e9b51f65690c125 Mon Sep 17 00:00:00 2001 From: krisbitney Date: Thu, 20 Oct 2022 13:17:25 +0500 Subject: [PATCH 03/38] added test configuration to cli-js --- packages/js/cli-api/jest.config.js | 11 +++++++++++ packages/js/cli-api/package.json | 4 ++++ packages/js/cli-api/src/__tests__/cli-js.test.ts | 15 +++++++++++++++ packages/js/cli-api/tsconfig.json | 1 - 4 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 packages/js/cli-api/jest.config.js create mode 100644 packages/js/cli-api/src/__tests__/cli-js.test.ts diff --git a/packages/js/cli-api/jest.config.js b/packages/js/cli-api/jest.config.js new file mode 100644 index 0000000000..a5ca876a5a --- /dev/null +++ b/packages/js/cli-api/jest.config.js @@ -0,0 +1,11 @@ +module.exports = { + collectCoverage: true, + preset: 'ts-jest', + testEnvironment: 'node', + testMatch: ["**/?(*.)+(spec|test).[jt]s?(x)"], + globals: { + 'ts-jest': { + diagnostics: false + } + } +}; diff --git a/packages/js/cli-api/package.json b/packages/js/cli-api/package.json index 0cafba1071..e1c1fe96a8 100644 --- a/packages/js/cli-api/package.json +++ b/packages/js/cli-api/package.json @@ -16,11 +16,15 @@ "lint": "eslint --color -c ../../../.eslintrc.js src/" }, "dependencies": { + "axios": "0.21.2", "polywrap": "0.9.2", "spawn-command": "0.0.2-1" }, "devDependencies": { + "@types/jest": "26.0.8", + "jest": "26.6.3", "rimraf": "3.0.2", + "ts-jest": "26.5.4", "typescript": "4.1.6" }, "publishConfig": { diff --git a/packages/js/cli-api/src/__tests__/cli-js.test.ts b/packages/js/cli-api/src/__tests__/cli-js.test.ts new file mode 100644 index 0000000000..e845bcb61d --- /dev/null +++ b/packages/js/cli-api/src/__tests__/cli-js.test.ts @@ -0,0 +1,15 @@ +jest.setTimeout(300000); + +describe("cli-js tests", () => { + beforeAll(async () => { + + }); + + afterAll(async () => { + + }); + + it("infra", async () => { + + }); +}); \ No newline at end of file diff --git a/packages/js/cli-api/tsconfig.json b/packages/js/cli-api/tsconfig.json index 5d37204c00..d34dfd8f5a 100644 --- a/packages/js/cli-api/tsconfig.json +++ b/packages/js/cli-api/tsconfig.json @@ -6,5 +6,4 @@ "include": [ "./src/**/*.ts" ], - "exclude": [] } From 688ebf0f08f1a7b87f8c30fdebc874404295b2ad Mon Sep 17 00:00:00 2001 From: krisbitney Date: Thu, 20 Oct 2022 13:22:58 +0500 Subject: [PATCH 04/38] renamed Actions enum to DocgenActions in docgen and removed extra space in codegen-dir option description --- packages/cli/src/__tests__/e2e/codegen.spec.ts | 2 +- packages/cli/src/commands/codegen.ts | 2 +- packages/cli/src/commands/docgen.ts | 18 ++++++++++-------- .../js/cli-api/src/__tests__/cli-js.test.ts | 1 + 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/packages/cli/src/__tests__/e2e/codegen.spec.ts b/packages/cli/src/__tests__/e2e/codegen.spec.ts index cef88b42c9..156c37c27f 100644 --- a/packages/cli/src/__tests__/e2e/codegen.spec.ts +++ b/packages/cli/src/__tests__/e2e/codegen.spec.ts @@ -14,7 +14,7 @@ Generate Code For Polywrap Projects Options: -m, --manifest-file Path to the Polywrap manifest file (default: polywrap.yaml | polywrap.yml) - -g, --codegen-dir Output directory for the generated code + -g, --codegen-dir Output directory for the generated code (default: ./src/wrap) -p, --publish-dir Output path for the built schema and manifest (default: ./build) diff --git a/packages/cli/src/commands/codegen.ts b/packages/cli/src/commands/codegen.ts index e5840bc753..ba9d2e6215 100644 --- a/packages/cli/src/commands/codegen.ts +++ b/packages/cli/src/commands/codegen.ts @@ -51,7 +51,7 @@ export const codegen: Command = { ) .option( `-g, --codegen-dir <${pathStr}>`, - ` ${intlMsg.commands_codegen_options_codegen({ + `${intlMsg.commands_codegen_options_codegen({ default: defaultCodegenDir, })}` ) diff --git a/packages/cli/src/commands/docgen.ts b/packages/cli/src/commands/docgen.ts index 933c0c5124..c1ce081300 100644 --- a/packages/cli/src/commands/docgen.ts +++ b/packages/cli/src/commands/docgen.ts @@ -38,22 +38,24 @@ export type DocgenCommandOptions = { quiet?: boolean; }; -enum Actions { +enum DocgenActions { SCHEMA = "schema", DOCUSAURUS = "docusaurus", JSDOC = "jsdoc", } -export type DocgenAction = keyof Record; +export type DocgenAction = keyof Record; const argumentsDescription = ` - ${chalk.bold(Actions.SCHEMA)} ${intlMsg.commands_docgen_options_schema()} ${chalk.bold( - Actions.DOCUSAURUS + DocgenActions.SCHEMA + )} ${intlMsg.commands_docgen_options_schema()} + ${chalk.bold( + DocgenActions.DOCUSAURUS )} ${intlMsg.commands_docgen_options_markdown({ framework: "Docusaurus", })} ${chalk.bold( - Actions.JSDOC + DocgenActions.JSDOC )} ${intlMsg.commands_docgen_options_markdown({ framework: "JSDoc", })} @@ -68,9 +70,9 @@ export const docgen: Command = { .usage(" [options]") .addArgument( new Argument("", argumentsDescription).choices([ - Actions.SCHEMA, - Actions.DOCUSAURUS, - Actions.JSDOC, + DocgenActions.SCHEMA, + DocgenActions.DOCUSAURUS, + DocgenActions.JSDOC, ]) ) .option( diff --git a/packages/js/cli-api/src/__tests__/cli-js.test.ts b/packages/js/cli-api/src/__tests__/cli-js.test.ts index e845bcb61d..210ee61b85 100644 --- a/packages/js/cli-api/src/__tests__/cli-js.test.ts +++ b/packages/js/cli-api/src/__tests__/cli-js.test.ts @@ -1,6 +1,7 @@ jest.setTimeout(300000); describe("cli-js tests", () => { + beforeAll(async () => { }); From 440a3cc01b6f49f9eecda40d9bf3d4415ebfb9d2 Mon Sep 17 00:00:00 2001 From: krisbitney Date: Thu, 20 Oct 2022 17:10:01 +0500 Subject: [PATCH 05/38] added cli-js tests for build, codegen, infra, deploy, and awaitResponse (tests for infra, deploy, and awaitResponse failing) --- packages/cli/src/commands/docgen.ts | 5 +- packages/cli/src/commands/infra.ts | 3 +- packages/cli/src/index.ts | 4 +- packages/js/cli-api/package.json | 4 +- .../src/__tests__/awaitResponse.test.ts | 31 ++++++++ .../js/cli-api/src/__tests__/cli-js.test.ts | 73 ++++++++++++++++++- .../local-ipfs-node/docker-compose.yaml | 8 ++ .../wrapper/local-ipfs-node/ipfs/Dockerfile | 4 + .../wrapper/local-ipfs-node/ipfs/config_ipfs | 4 + .../wrapper/local-ipfs-node/ipfs/start_ipfs | 58 +++++++++++++++ .../src/__tests__/wrapper/package.json | 8 ++ .../src/__tests__/wrapper/polywrap.build.yaml | 6 ++ .../__tests__/wrapper/polywrap.deploy.yaml | 7 ++ .../src/__tests__/wrapper/polywrap.infra.yaml | 4 + .../src/__tests__/wrapper/polywrap.yaml | 10 +++ .../src/__tests__/wrapper/src/index.ts | 5 ++ .../src/__tests__/wrapper/src/schema.graphql | 3 + packages/js/cli-api/src/awaitResponse.ts | 11 ++- packages/js/cli-api/src/types.ts | 18 ++++- 19 files changed, 249 insertions(+), 17 deletions(-) create mode 100644 packages/js/cli-api/src/__tests__/awaitResponse.test.ts create mode 100644 packages/js/cli-api/src/__tests__/wrapper/local-ipfs-node/docker-compose.yaml create mode 100644 packages/js/cli-api/src/__tests__/wrapper/local-ipfs-node/ipfs/Dockerfile create mode 100755 packages/js/cli-api/src/__tests__/wrapper/local-ipfs-node/ipfs/config_ipfs create mode 100755 packages/js/cli-api/src/__tests__/wrapper/local-ipfs-node/ipfs/start_ipfs create mode 100644 packages/js/cli-api/src/__tests__/wrapper/package.json create mode 100644 packages/js/cli-api/src/__tests__/wrapper/polywrap.build.yaml create mode 100644 packages/js/cli-api/src/__tests__/wrapper/polywrap.deploy.yaml create mode 100644 packages/js/cli-api/src/__tests__/wrapper/polywrap.infra.yaml create mode 100644 packages/js/cli-api/src/__tests__/wrapper/polywrap.yaml create mode 100644 packages/js/cli-api/src/__tests__/wrapper/src/index.ts create mode 100644 packages/js/cli-api/src/__tests__/wrapper/src/schema.graphql diff --git a/packages/cli/src/commands/docgen.ts b/packages/cli/src/commands/docgen.ts index c1ce081300..06e517f14d 100644 --- a/packages/cli/src/commands/docgen.ts +++ b/packages/cli/src/commands/docgen.ts @@ -38,12 +38,11 @@ export type DocgenCommandOptions = { quiet?: boolean; }; -enum DocgenActions { +export enum DocgenActions { SCHEMA = "schema", DOCUSAURUS = "docusaurus", JSDOC = "jsdoc", } -export type DocgenAction = keyof Record; const argumentsDescription = ` ${chalk.bold( @@ -108,7 +107,7 @@ export const docgen: Command = { }, }; -async function run(command: DocgenAction, options: DocgenCommandOptions) { +async function run(command: DocgenActions, options: DocgenCommandOptions) { const { manifestFile, docgenDir, diff --git a/packages/cli/src/commands/infra.ts b/packages/cli/src/commands/infra.ts index 3ff37f4bde..313347e63a 100644 --- a/packages/cli/src/commands/infra.ts +++ b/packages/cli/src/commands/infra.ts @@ -22,13 +22,12 @@ export type InfraCommandOptions = { quiet?: boolean; }; -enum InfraActions { +export enum InfraActions { UP = "up", DOWN = "down", VARS = "vars", CONFIG = "config", } -export type InfraAction = keyof Record; const DEFAULT_MODULES_PATH = path.join( __dirname, diff --git a/packages/cli/src/index.ts b/packages/cli/src/index.ts index 53112786e2..4d960cea5f 100644 --- a/packages/cli/src/index.ts +++ b/packages/cli/src/index.ts @@ -13,7 +13,7 @@ export { SupportedWasmLangs, SupportedPluginLangs, SupportedAppLangs, - DocgenAction, - InfraAction, + DocgenActions, + InfraActions, } from "./commands"; export { SupportedStrategies } from "./lib/build-strategies"; diff --git a/packages/js/cli-api/package.json b/packages/js/cli-api/package.json index e1c1fe96a8..a32678c63b 100644 --- a/packages/js/cli-api/package.json +++ b/packages/js/cli-api/package.json @@ -13,7 +13,9 @@ ], "scripts": { "build": "rimraf ./build && tsc --project tsconfig.build.json", - "lint": "eslint --color -c ../../../.eslintrc.js src/" + "lint": "eslint --color -c ../../../.eslintrc.js src/", + "test": "jest --passWithNoTests --runInBand --verbose", + "test:ci": "jest --passWithNoTests --runInBand --detectOpenHandles --verbose" }, "dependencies": { "axios": "0.21.2", diff --git a/packages/js/cli-api/src/__tests__/awaitResponse.test.ts b/packages/js/cli-api/src/__tests__/awaitResponse.test.ts new file mode 100644 index 0000000000..073047b0c7 --- /dev/null +++ b/packages/js/cli-api/src/__tests__/awaitResponse.test.ts @@ -0,0 +1,31 @@ +import { awaitResponse, runCLI } from "../../"; + +import path from "path"; + +jest.setTimeout(60_000); + +describe("awaitResponse", () => { + + const localIpfsNode = "http://localhost:5001"; + const wrapperPath = path.resolve(path.join(__dirname, "wrapper")); + + it.only("returns false when infra is unavailable", async () => { + const isInfraUp = await awaitResponse(localIpfsNode); + expect(isInfraUp).toBeFalsy(); + }); + + it("returns true when infra is available", async () => { + await runCLI({ + args: ["infra", "up", "--verbose"], + cwd: wrapperPath, + }); + + const isInfraUp = await awaitResponse(localIpfsNode); + expect(isInfraUp).toBeTruthy(); + + await runCLI({ + args: ["infra", "down", "--verbose"], + cwd: wrapperPath, + }); + }); +}); \ No newline at end of file diff --git a/packages/js/cli-api/src/__tests__/cli-js.test.ts b/packages/js/cli-api/src/__tests__/cli-js.test.ts index 210ee61b85..31ed319e6b 100644 --- a/packages/js/cli-api/src/__tests__/cli-js.test.ts +++ b/packages/js/cli-api/src/__tests__/cli-js.test.ts @@ -1,16 +1,81 @@ -jest.setTimeout(300000); +import { awaitResponse, Commands, InfraActions } from "../../"; + +import path from "path"; +import fs from "fs"; + +jest.setTimeout(300_000); describe("cli-js tests", () => { - beforeAll(async () => { + const localIpfsNode = "http://localhost:5001"; + const wrapperPath = path.resolve(path.join(__dirname, "wrapper")); + + it("build", async () => { + // clear build dir + const buildDir = path.join(wrapperPath, "build"); + if (fs.existsSync(buildDir)) { + fs.rmSync(buildDir, { recursive: true }); + } + expect(fs.existsSync(buildDir)).toBeFalsy(); + + // build + await Commands.build({ strategy: "image" }, wrapperPath); + + // check for build dir and artifacts + const wasmPath = path.join(buildDir, "wrap.wasm"); + const manifestPath = path.join(buildDir, "wrap.info"); + expect(fs.existsSync(buildDir)).toBeTruthy(); + expect(fs.existsSync(wasmPath)).toBeTruthy(); + expect(fs.existsSync(manifestPath)).toBeTruthy(); + }); + + it("codegen", async () => { + // clear wrap dir + const wrapDir = path.join(wrapperPath, "src", "wrap"); + if (fs.existsSync(wrapDir)) { + fs.rmSync(wrapDir, { recursive: true }); + } + expect(fs.existsSync(wrapDir)).toBeFalsy(); + + // codegen + await Commands.codegen(undefined, wrapperPath); + // check output + expect(fs.existsSync(wrapDir)).toBeTruthy(); }); - afterAll(async () => { + it.only("infra", async () => { + // start infra + await Commands.infra({ action: InfraActions.UP, verbose: true }, wrapperPath); + const isInfraUp = await awaitResponse(localIpfsNode); + expect(isInfraUp).toBeTruthy(); + // stop infra + await Commands.infra({ action: InfraActions.DOWN, verbose: true }, wrapperPath); + await new Promise((r) => setTimeout(r, 20000)); + const isInfraStillUp = await awaitResponse(localIpfsNode); + expect(isInfraStillUp).toBeFalsy(); }); - it("infra", async () => { + it("deploy", async () => { + // start infra + await Commands.infra({ action: InfraActions.UP }, wrapperPath); + const isInfraUp = await awaitResponse(localIpfsNode); + expect(isInfraUp).toBeTruthy(); + // clear output + const outputFile = path.join(wrapperPath, "ipfs.json"); + if (fs.existsSync(outputFile)) { + fs.rmSync(outputFile); + } + expect(fs.existsSync(outputFile)).toBeFalsy(); + + // deploy wrapper + await Commands.deploy({ outputFile }, wrapperPath); + + // check output + expect(fs.existsSync(outputFile)).toBeTruthy(); }); + + }); \ No newline at end of file diff --git a/packages/js/cli-api/src/__tests__/wrapper/local-ipfs-node/docker-compose.yaml b/packages/js/cli-api/src/__tests__/wrapper/local-ipfs-node/docker-compose.yaml new file mode 100644 index 0000000000..fb5d495a6a --- /dev/null +++ b/packages/js/cli-api/src/__tests__/wrapper/local-ipfs-node/docker-compose.yaml @@ -0,0 +1,8 @@ +version: '3' +services: + ipfs: + build: ./ipfs + ports: + - '${IPFS_PORT:-5001}:5001' + - '8080:8080' + - '4001:4001' diff --git a/packages/js/cli-api/src/__tests__/wrapper/local-ipfs-node/ipfs/Dockerfile b/packages/js/cli-api/src/__tests__/wrapper/local-ipfs-node/ipfs/Dockerfile new file mode 100644 index 0000000000..7a277d85f8 --- /dev/null +++ b/packages/js/cli-api/src/__tests__/wrapper/local-ipfs-node/ipfs/Dockerfile @@ -0,0 +1,4 @@ +FROM ipfs/go-ipfs:v0.4.23 + +COPY ./start_ipfs /usr/local/bin +COPY ./config_ipfs /usr/local/bin diff --git a/packages/js/cli-api/src/__tests__/wrapper/local-ipfs-node/ipfs/config_ipfs b/packages/js/cli-api/src/__tests__/wrapper/local-ipfs-node/ipfs/config_ipfs new file mode 100755 index 0000000000..0935f84c2d --- /dev/null +++ b/packages/js/cli-api/src/__tests__/wrapper/local-ipfs-node/ipfs/config_ipfs @@ -0,0 +1,4 @@ +#!/bin/sh + +ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin '["*"]' +ipfs config --json API.HTTPHeaders.Access-Control-Allow-Methods '["GET", "POST", "PUT", "DELETE"]' diff --git a/packages/js/cli-api/src/__tests__/wrapper/local-ipfs-node/ipfs/start_ipfs b/packages/js/cli-api/src/__tests__/wrapper/local-ipfs-node/ipfs/start_ipfs new file mode 100755 index 0000000000..f2ca2a2c07 --- /dev/null +++ b/packages/js/cli-api/src/__tests__/wrapper/local-ipfs-node/ipfs/start_ipfs @@ -0,0 +1,58 @@ +#!/bin/sh +set -e +user=ipfs +repo="$IPFS_PATH" + +if [ `id -u` -eq 0 ]; then + echo "Changing user to $user" + # ensure folder is writable + su-exec "$user" test -w "$repo" || chown -R -- "$user" "$repo" + # restart script with new privileges + exec su-exec "$user" "$0" "$@" +fi + +# 2nd invocation with regular user +ipfs version + +if [ -e "$repo/config" ]; then + echo "Found IPFS fs-repo at $repo" +else + case "$IPFS_PROFILE" in + "") INIT_ARGS="" ;; + *) INIT_ARGS="--profile=$IPFS_PROFILE" ;; + esac + ipfs init $INIT_ARGS + ipfs config Addresses.API /ip4/0.0.0.0/tcp/5001 + ipfs config Addresses.Gateway /ip4/0.0.0.0/tcp/8080 + + # Set up the swarm key, if provided + + SWARM_KEY_FILE="$repo/swarm.key" + SWARM_KEY_PERM=0400 + + # Create a swarm key from a given environment variable + if [ ! -z "$IPFS_SWARM_KEY" ] ; then + echo "Copying swarm key from variable..." + echo -e "$IPFS_SWARM_KEY" >"$SWARM_KEY_FILE" || exit 1 + chmod $SWARM_KEY_PERM "$SWARM_KEY_FILE" + fi + + # Unset the swarm key variable + unset IPFS_SWARM_KEY + + # Check during initialization if a swarm key was provided and + # copy it to the ipfs directory with the right permissions + # WARNING: This will replace the swarm key if it exists + if [ ! -z "$IPFS_SWARM_KEY_FILE" ] ; then + echo "Copying swarm key from file..." + install -m $SWARM_KEY_PERM "$IPFS_SWARM_KEY_FILE" "$SWARM_KEY_FILE" || exit 1 + fi + + # Unset the swarm key file variable + unset IPFS_SWARM_KEY_FILE + +fi + +$(dirname $0)/config_ipfs + +exec ipfs "$@" diff --git a/packages/js/cli-api/src/__tests__/wrapper/package.json b/packages/js/cli-api/src/__tests__/wrapper/package.json new file mode 100644 index 0000000000..2e565b4de7 --- /dev/null +++ b/packages/js/cli-api/src/__tests__/wrapper/package.json @@ -0,0 +1,8 @@ +{ + "name": "test-case-simple", + "private": true, + "dependencies": { + "@polywrap/wasm-as": "0.9.2", + "assemblyscript": "0.19.23" + } +} diff --git a/packages/js/cli-api/src/__tests__/wrapper/polywrap.build.yaml b/packages/js/cli-api/src/__tests__/wrapper/polywrap.build.yaml new file mode 100644 index 0000000000..6418278821 --- /dev/null +++ b/packages/js/cli-api/src/__tests__/wrapper/polywrap.build.yaml @@ -0,0 +1,6 @@ +format: 0.2.0 +config: + node_version: "16.13.0" + include: + - ./src + - ./package.json diff --git a/packages/js/cli-api/src/__tests__/wrapper/polywrap.deploy.yaml b/packages/js/cli-api/src/__tests__/wrapper/polywrap.deploy.yaml new file mode 100644 index 0000000000..fe51063194 --- /dev/null +++ b/packages/js/cli-api/src/__tests__/wrapper/polywrap.deploy.yaml @@ -0,0 +1,7 @@ +format: 0.1.0 +stages: + local_ipfs_deploy: + package: ipfs + uri: fs/./build + config: + gatewayUri: "http://localhost:5001" \ No newline at end of file diff --git a/packages/js/cli-api/src/__tests__/wrapper/polywrap.infra.yaml b/packages/js/cli-api/src/__tests__/wrapper/polywrap.infra.yaml new file mode 100644 index 0000000000..0589334529 --- /dev/null +++ b/packages/js/cli-api/src/__tests__/wrapper/polywrap.infra.yaml @@ -0,0 +1,4 @@ +format: 0.1.0 +modules: + local-ipfs-node: + path: ./local-ipfs-node \ No newline at end of file diff --git a/packages/js/cli-api/src/__tests__/wrapper/polywrap.yaml b/packages/js/cli-api/src/__tests__/wrapper/polywrap.yaml new file mode 100644 index 0000000000..76f8327359 --- /dev/null +++ b/packages/js/cli-api/src/__tests__/wrapper/polywrap.yaml @@ -0,0 +1,10 @@ +format: 0.2.0 +project: + name: Simple + type: wasm/assemblyscript +source: + schema: ./src/schema.graphql + module: ./src/index.ts +extensions: + build: ./polywrap.build.yaml + deploy: ./polywrap.deploy.yaml diff --git a/packages/js/cli-api/src/__tests__/wrapper/src/index.ts b/packages/js/cli-api/src/__tests__/wrapper/src/index.ts new file mode 100644 index 0000000000..65c1f47ee4 --- /dev/null +++ b/packages/js/cli-api/src/__tests__/wrapper/src/index.ts @@ -0,0 +1,5 @@ +import { Args_simpleMethod } from "./wrap"; + +export function simpleMethod(args: Args_simpleMethod): string { + return args.arg; +} diff --git a/packages/js/cli-api/src/__tests__/wrapper/src/schema.graphql b/packages/js/cli-api/src/__tests__/wrapper/src/schema.graphql new file mode 100644 index 0000000000..1fa8e36696 --- /dev/null +++ b/packages/js/cli-api/src/__tests__/wrapper/src/schema.graphql @@ -0,0 +1,3 @@ +type Module { + simpleMethod(arg: String!): String! +} diff --git a/packages/js/cli-api/src/awaitResponse.ts b/packages/js/cli-api/src/awaitResponse.ts index 9cc989f33e..ffbdc3639f 100644 --- a/packages/js/cli-api/src/awaitResponse.ts +++ b/packages/js/cli-api/src/awaitResponse.ts @@ -9,9 +9,16 @@ export async function awaitResponse( while (time < maxTimeout) { const request = axios.get(url, { timeout }); + console.log("requesting: " + url); const success = await request - .then(() => true) - .catch((e) => e.code !== "ECONNRESET"); + .then(() => { + console.log("no error thrown"); + return true; + }) + .catch((e) => { + console.log(e.code); + return e.code !== "ECONNRESET"; + }); if (success) { return true; diff --git a/packages/js/cli-api/src/types.ts b/packages/js/cli-api/src/types.ts index 63d2ca393c..e44c9ec952 100644 --- a/packages/js/cli-api/src/types.ts +++ b/packages/js/cli-api/src/types.ts @@ -11,18 +11,30 @@ import { SupportedWasmLangs, SupportedPluginLangs, SupportedAppLangs, - DocgenAction, - InfraAction, + DocgenActions, + InfraActions, + SupportedStrategies, ManifestType, } from "polywrap"; +export { + DocgenActions, + InfraActions, + SupportedStrategies as BuildStrategies, +} from "polywrap"; + +export type DocgenAction = `${DocgenActions}`; +export type InfraAction = `${InfraActions}`; +export type BuildStrategy = `${SupportedStrategies}`; + export type DeployCommandOptions = Partial; export type BuildCommandOptions = Omit< Partial, - "watch" | "clientConfig" + "watch" | "clientConfig" | "strategy" > & { clientConfig?: string; + strategy?: BuildStrategy; }; export type CodegenCommandOptions = Omit< From 5ff3db65073f396b2ceb15755144daa26d64de7d Mon Sep 17 00:00:00 2001 From: krisbitney Date: Thu, 20 Oct 2022 20:10:55 +0500 Subject: [PATCH 06/38] reworked Commands types in cli-js --- packages/js/cli-api/src/commands.ts | 48 +++++++-------- packages/js/cli-api/src/utils/ICommands.ts | 61 ------------------- packages/js/cli-api/src/utils/index.ts | 2 +- .../js/cli-api/src/utils/internal-types.ts | 34 +++++++++++ 4 files changed, 57 insertions(+), 88 deletions(-) delete mode 100644 packages/js/cli-api/src/utils/ICommands.ts create mode 100644 packages/js/cli-api/src/utils/internal-types.ts diff --git a/packages/js/cli-api/src/commands.ts b/packages/js/cli-api/src/commands.ts index 99d7561da6..e8c51e9247 100644 --- a/packages/js/cli-api/src/commands.ts +++ b/packages/js/cli-api/src/commands.ts @@ -1,17 +1,13 @@ import { runCLI } from "./run-cli"; -import { ICommands } from "./utils"; import { - BuildCommandOptions, - CodegenCommandOptions, - CreateCommandOptions, - DeployCommandOptions, - DocgenCommandOptions, - InfraCommandOptions, - ManifestCommandOptions, - RunCommandOptions, -} from "./types"; + Commands, + CommandNames, + CommandOptions, + ActionCommandNames, +} from "./utils"; +import { CreateCommandOptions, ManifestCommandOptions } from "./types"; -export const commands: ICommands = { +export const commands: Commands = { build: simpleCommandExecutorFactory("build"), codegen: simpleCommandExecutorFactory("codegen"), create: createCommandExecutor, @@ -22,16 +18,6 @@ export const commands: ICommands = { run: simpleCommandExecutorFactory("run"), }; -type CommandOptions = - | BuildCommandOptions - | CodegenCommandOptions - | CreateCommandOptions - | DeployCommandOptions - | DocgenCommandOptions - | InfraCommandOptions - | ManifestCommandOptions - | RunCommandOptions; - function toKebabCase(camelCase: string): string { return camelCase.replace(/([a-z])([A-Z])/g, "$1-$2"); } @@ -43,7 +29,9 @@ function parseValue(value: string | string[] | boolean): string { return value.toString(); } -function parseOptions(options?: CommandOptions): string[] { +function parseOptions( + options?: CommandOptions[Command] +): string[] { const parsed: string[] = []; if (options) { for (const [key, value] of Object.entries(options)) { @@ -55,16 +43,24 @@ function parseOptions(options?: CommandOptions): string[] { return parsed; } -function simpleCommandExecutorFactory(command: string) { - return async (options?: CommandOptions, cwd?: string, cli?: string) => { +function simpleCommandExecutorFactory( + command: Command +) { + return async ( + options?: CommandOptions[Command], + cwd?: string, + cli?: string + ) => { const args = [command, ...parseOptions(options)]; return await runCLI({ args, cwd, cli }); }; } -function actionCommandExecutorFactory(command: string) { +function actionCommandExecutorFactory( + command: Command +) { return async ( - options: InfraCommandOptions | DocgenCommandOptions, + options: CommandOptions[Command], cwd?: string, cli?: string ) => { diff --git a/packages/js/cli-api/src/utils/ICommands.ts b/packages/js/cli-api/src/utils/ICommands.ts deleted file mode 100644 index a1c4f47025..0000000000 --- a/packages/js/cli-api/src/utils/ICommands.ts +++ /dev/null @@ -1,61 +0,0 @@ -import { runCLI } from "../run-cli"; -import { - BuildCommandOptions, - CodegenCommandOptions, - CreateCommandOptions, - DeployCommandOptions, - DocgenCommandOptions, - InfraCommandOptions, - ManifestCommandOptions, - RunCommandOptions, -} from "../types"; - -export interface ICommands { - readonly build: ( - options?: BuildCommandOptions, - cwd?: string, - cli?: string - ) => ReturnType; - - readonly codegen: ( - options?: CodegenCommandOptions, - cwd?: string, - cli?: string - ) => ReturnType; - - readonly create: ( - options: CreateCommandOptions, - cwd?: string, - cli?: string - ) => ReturnType; - - readonly deploy: ( - options?: DeployCommandOptions, - cwd?: string, - cli?: string - ) => ReturnType; - - readonly docgen: ( - options: DocgenCommandOptions, - cwd?: string, - cli?: string - ) => ReturnType; - - readonly infra: ( - options: InfraCommandOptions, - cwd?: string, - cli?: string - ) => ReturnType; - - readonly manifest: ( - options: ManifestCommandOptions, - cwd?: string, - cli?: string - ) => ReturnType; - - readonly run: ( - options?: RunCommandOptions, - cwd?: string, - cli?: string - ) => ReturnType; -} diff --git a/packages/js/cli-api/src/utils/index.ts b/packages/js/cli-api/src/utils/index.ts index 64e271203c..316a1aa00e 100644 --- a/packages/js/cli-api/src/utils/index.ts +++ b/packages/js/cli-api/src/utils/index.ts @@ -1 +1 @@ -export * from "./ICommands"; +export * from "./internal-types"; diff --git a/packages/js/cli-api/src/utils/internal-types.ts b/packages/js/cli-api/src/utils/internal-types.ts new file mode 100644 index 0000000000..ef6ed2479f --- /dev/null +++ b/packages/js/cli-api/src/utils/internal-types.ts @@ -0,0 +1,34 @@ +import { runCLI } from "../run-cli"; +import { + BuildCommandOptions, + CodegenCommandOptions, + CreateCommandOptions, + DeployCommandOptions, + DocgenCommandOptions, + InfraCommandOptions, + ManifestCommandOptions, + RunCommandOptions, +} from "../types"; + +export type CommandNames = keyof CommandOptions; + +export type ActionCommandNames = "docgen" | "infra"; + +export type CommandOptions = { + build: BuildCommandOptions; + codegen: CodegenCommandOptions; + create: CreateCommandOptions; + deploy: DeployCommandOptions; + docgen: DocgenCommandOptions; + infra: InfraCommandOptions; + manifest: ManifestCommandOptions; + run: RunCommandOptions; +}; + +export type Commands = { + [Command in CommandNames]: ( + options?: CommandOptions[Command], + cwd?: string, + cli?: string + ) => ReturnType; +}; From 7031a4adc52a588bf7337a7b2b39401f28e6695b Mon Sep 17 00:00:00 2001 From: krisbitney Date: Thu, 20 Oct 2022 20:27:27 +0500 Subject: [PATCH 07/38] correctly prefixing options with '--' and making them lowercase; tests passing for infra, codegen, build, deploy, and awaitResponse --- .../src/__tests__/awaitResponse.test.ts | 9 ++++++++- .../js/cli-api/src/__tests__/cli-js.test.ts | 18 +++++++++++++----- packages/js/cli-api/src/awaitResponse.ts | 11 ++--------- packages/js/cli-api/src/commands.ts | 4 ++-- 4 files changed, 25 insertions(+), 17 deletions(-) diff --git a/packages/js/cli-api/src/__tests__/awaitResponse.test.ts b/packages/js/cli-api/src/__tests__/awaitResponse.test.ts index 073047b0c7..952b09529e 100644 --- a/packages/js/cli-api/src/__tests__/awaitResponse.test.ts +++ b/packages/js/cli-api/src/__tests__/awaitResponse.test.ts @@ -9,7 +9,14 @@ describe("awaitResponse", () => { const localIpfsNode = "http://localhost:5001"; const wrapperPath = path.resolve(path.join(__dirname, "wrapper")); - it.only("returns false when infra is unavailable", async () => { + afterAll(async () => { + await runCLI({ + args: ["infra", "down"], + cwd: wrapperPath, + }); + }); + + it("returns false when infra is unavailable", async () => { const isInfraUp = await awaitResponse(localIpfsNode); expect(isInfraUp).toBeFalsy(); }); diff --git a/packages/js/cli-api/src/__tests__/cli-js.test.ts b/packages/js/cli-api/src/__tests__/cli-js.test.ts index 31ed319e6b..89fd92bcc6 100644 --- a/packages/js/cli-api/src/__tests__/cli-js.test.ts +++ b/packages/js/cli-api/src/__tests__/cli-js.test.ts @@ -1,4 +1,4 @@ -import { awaitResponse, Commands, InfraActions } from "../../"; +import { awaitResponse, Commands, InfraActions, runCLI } from "../../"; import path from "path"; import fs from "fs"; @@ -10,6 +10,13 @@ describe("cli-js tests", () => { const localIpfsNode = "http://localhost:5001"; const wrapperPath = path.resolve(path.join(__dirname, "wrapper")); + afterAll(async () => { + await runCLI({ + args: ["infra", "down"], + cwd: wrapperPath, + }); + }); + it("build", async () => { // clear build dir const buildDir = path.join(wrapperPath, "build"); @@ -44,7 +51,7 @@ describe("cli-js tests", () => { expect(fs.existsSync(wrapDir)).toBeTruthy(); }); - it.only("infra", async () => { + it("infra", async () => { // start infra await Commands.infra({ action: InfraActions.UP, verbose: true }, wrapperPath); const isInfraUp = await awaitResponse(localIpfsNode); @@ -52,7 +59,7 @@ describe("cli-js tests", () => { // stop infra await Commands.infra({ action: InfraActions.DOWN, verbose: true }, wrapperPath); - await new Promise((r) => setTimeout(r, 20000)); + await new Promise((r) => setTimeout(r, 5000)); const isInfraStillUp = await awaitResponse(localIpfsNode); expect(isInfraStillUp).toBeFalsy(); }); @@ -75,7 +82,8 @@ describe("cli-js tests", () => { // check output expect(fs.existsSync(outputFile)).toBeTruthy(); - }); - + // stop infra + await Commands.infra({ action: InfraActions.DOWN }, wrapperPath); + }); }); \ No newline at end of file diff --git a/packages/js/cli-api/src/awaitResponse.ts b/packages/js/cli-api/src/awaitResponse.ts index ffbdc3639f..c5893338fe 100644 --- a/packages/js/cli-api/src/awaitResponse.ts +++ b/packages/js/cli-api/src/awaitResponse.ts @@ -9,16 +9,9 @@ export async function awaitResponse( while (time < maxTimeout) { const request = axios.get(url, { timeout }); - console.log("requesting: " + url); const success = await request - .then(() => { - console.log("no error thrown"); - return true; - }) - .catch((e) => { - console.log(e.code); - return e.code !== "ECONNRESET"; - }); + .then(() => true) + .catch((e) => e.code !== "ECONNRESET" && e.code !== "ECONNREFUSED"); if (success) { return true; diff --git a/packages/js/cli-api/src/commands.ts b/packages/js/cli-api/src/commands.ts index e8c51e9247..6aade89844 100644 --- a/packages/js/cli-api/src/commands.ts +++ b/packages/js/cli-api/src/commands.ts @@ -19,7 +19,7 @@ export const commands: Commands = { }; function toKebabCase(camelCase: string): string { - return camelCase.replace(/([a-z])([A-Z])/g, "$1-$2"); + return camelCase.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(); } function parseValue(value: string | string[] | boolean): string { @@ -36,7 +36,7 @@ function parseOptions( if (options) { for (const [key, value] of Object.entries(options)) { if (value === undefined) continue; - parsed.push(toKebabCase(key)); + parsed.push(`--${toKebabCase(key)}`); parsed.push(parseValue(value)); } } From fcd6a8bdff4fc0174594d3c3574329b63aa0d985 Mon Sep 17 00:00:00 2001 From: dOrgJelli Date: Thu, 20 Oct 2022 19:00:51 +0200 Subject: [PATCH 08/38] init refactor CLI package --- packages/cli/src/commands/build.ts | 14 ++--- packages/cli/src/commands/codegen.ts | 14 ++--- packages/cli/src/commands/create.ts | 49 ++++++++++----- packages/cli/src/commands/deploy.ts | 6 +- packages/cli/src/commands/docgen.ts | 33 +++++----- packages/cli/src/commands/index.ts | 40 ++++++++++++- packages/cli/src/commands/infra.ts | 23 +++---- packages/cli/src/commands/manifest.ts | 28 +++++---- packages/cli/src/commands/run.ts | 14 ++--- packages/cli/src/commands/types.ts | 15 +++++ packages/cli/src/index.ts | 21 +------ packages/js/cli-api/src/commands.ts | 60 ++++++++++++++----- .../cli-api/src/{utils => }/declarations.d.ts | 0 packages/js/cli-api/src/utils/index.ts | 1 - .../js/cli-api/src/utils/internal-types.ts | 34 ----------- todo | 14 +++++ 16 files changed, 212 insertions(+), 154 deletions(-) rename packages/js/cli-api/src/{utils => }/declarations.d.ts (100%) delete mode 100644 packages/js/cli-api/src/utils/index.ts delete mode 100644 packages/js/cli-api/src/utils/internal-types.ts create mode 100644 todo diff --git a/packages/cli/src/commands/build.ts b/packages/cli/src/commands/build.ts index a9aa8994f4..6fa177217a 100644 --- a/packages/cli/src/commands/build.ts +++ b/packages/cli/src/commands/build.ts @@ -1,4 +1,4 @@ -import { Command, Program } from "./types"; +import { Command, Program, BaseCommandOptions } from "./types"; import { createLogger } from "./utils/createLogger"; import { Compiler, @@ -24,7 +24,7 @@ import { import path from "path"; import readline from "readline"; -import { PolywrapClient, PolywrapClientConfig } from "@polywrap/client-js"; +import { PolywrapClient } from "@polywrap/client-js"; import { PolywrapManifest } from "@polywrap/polywrap-manifest-types-js"; const defaultOutputDir = "./build"; @@ -33,15 +33,13 @@ const strategyStr = intlMsg.commands_build_options_s_strategy(); const defaultManifestStr = defaultPolywrapManifest.join(" | "); const pathStr = intlMsg.commands_build_options_o_path(); -export type BuildCommandOptions = { +export interface BuildCommandOptions extends BaseCommandOptions { manifestFile: string; outputDir: string; - clientConfig: Partial; + clientConfig: string; skipCodegen?: boolean; watch?: boolean; strategy: SupportedStrategies; - verbose?: boolean; - quiet?: boolean; }; export const build: Command = { @@ -82,7 +80,6 @@ export const build: Command = { options.manifestFile, defaultPolywrapManifest ), - clientConfig: await parseClientConfigOption(options.clientConfig), outputDir: parseDirOption(options.outputDir, defaultOutputDir), strategy: options.strategy, }); @@ -139,7 +136,8 @@ async function run(options: BuildCommandOptions) { const logger = createLogger({ verbose, quiet }); // Get Client - const client = new PolywrapClient(clientConfig); + const config = await parseClientConfigOption(clientConfig); + const client = new PolywrapClient(config); const project = new PolywrapProject({ rootDir: path.dirname(manifestFile), diff --git a/packages/cli/src/commands/codegen.ts b/packages/cli/src/commands/codegen.ts index ba9d2e6215..70d1947780 100644 --- a/packages/cli/src/commands/codegen.ts +++ b/packages/cli/src/commands/codegen.ts @@ -1,5 +1,5 @@ /* eslint-disable @typescript-eslint/no-unused-vars */ -import { Command, Program } from "./types"; +import { Command, Program, BaseCommandOptions } from "./types"; import { createLogger } from "./utils/createLogger"; import { CodeGenerator, @@ -17,7 +17,7 @@ import { } from "../lib"; import { ScriptCodegenerator } from "../lib/codegen/ScriptCodeGenerator"; -import { PolywrapClient, PolywrapClientConfig } from "@polywrap/client-js"; +import { PolywrapClient } from "@polywrap/client-js"; import path from "path"; import fs from "fs"; @@ -27,14 +27,12 @@ const defaultPublishDir = "./build"; const pathStr = intlMsg.commands_codegen_options_o_path(); const defaultManifestStr = defaultPolywrapManifest.join(" | "); -export type CodegenCommandOptions = { +export interface CodegenCommandOptions extends BaseCommandOptions { manifestFile: string; codegenDir: string; publishDir: string; script?: string; - clientConfig: Partial; - verbose?: boolean; - quiet?: boolean; + clientConfig: string; }; export const codegen: Command = { @@ -74,7 +72,6 @@ export const codegen: Command = { .action(async (options) => { await run({ ...options, - clientConfig: await parseClientConfigOption(options.clientConfig), codegenDir: parseDirOption(options.codegenDir, defaultCodegenDir), script: parseCodegenScriptOption(options.script), manifestFile: parseManifestFileOption( @@ -100,7 +97,8 @@ async function run(options: CodegenCommandOptions) { const logger = createLogger({ verbose, quiet }); // Get Client - const client = new PolywrapClient(clientConfig); + const config = await parseClientConfigOption(clientConfig); + const client = new PolywrapClient(config); const project = await getProjectFromManifest(manifestFile, logger); diff --git a/packages/cli/src/commands/create.ts b/packages/cli/src/commands/create.ts index b80d8adeeb..ed7e395162 100644 --- a/packages/cli/src/commands/create.ts +++ b/packages/cli/src/commands/create.ts @@ -1,4 +1,4 @@ -import { Command, Program } from "./types"; +import { Command, Program, BaseCommandOptions } from "./types"; import { createLogger } from "./utils/createLogger"; import { generateProjectTemplate, intlMsg } from "../lib"; @@ -31,12 +31,21 @@ type SupportedLangs = | SupportedAppLangs | SupportedPluginLangs; -export type CreateCommandOptions = { +export interface CreateCommandOptions< + TLangs extends SupportedLangs +> extends BaseCommandOptions { + language: TLangs; + name: string; outputDir?: string; - verbose?: boolean; - quiet?: boolean; }; +export type CreateAppCommandOptions = + CreateCommandOptions; +export type CreatePluginCommandOptions = + CreateCommandOptions; +export type CreateWasmCommandOptions = + CreateCommandOptions; + export const create: Command = { setup: (program: Program) => { const createCommand = program @@ -61,8 +70,12 @@ export const create: Command = { ) .option("-v, --verbose", intlMsg.commands_common_options_verbose()) .option("-q, --quiet", intlMsg.commands_common_options_quiet()) - .action(async (langStr, nameStr, options) => { - await run("wasm", langStr, nameStr, options); + .action(async (language, name, options) => { + await run("wasm", { + ...options, + language, + name, + }); }); createCommand @@ -82,8 +95,12 @@ export const create: Command = { ) .option("-v, --verbose", intlMsg.commands_common_options_verbose()) .option("-q, --quiet", intlMsg.commands_common_options_quiet()) - .action(async (langStr, nameStr, options) => { - await run("app", langStr, nameStr, options); + .action(async (language, name, options) => { + await run("app", { + ...options, + language, + name + }); }); createCommand @@ -103,19 +120,21 @@ export const create: Command = { ) .option("-v, --verbose", intlMsg.commands_common_options_verbose()) .option("-q, --quiet", intlMsg.commands_common_options_quiet()) - .action(async (langStr, nameStr, options) => { - await run("plugin", langStr, nameStr, options); + .action(async (language, name, options) => { + await run("plugin", { + ...options, + language, + name + }); }); }, }; async function run( command: ProjectType, - lang: SupportedLangs, - name: string, - options: CreateCommandOptions + options: CreateCommandOptions ) { - const { outputDir, verbose, quiet } = options; + const { language, name, outputDir, verbose, quiet } = options; const logger = createLogger({ verbose, quiet }); const projectDir = path.resolve(outputDir ? `${outputDir}/${name}` : name); @@ -143,7 +162,7 @@ async function run( } } - await generateProjectTemplate(command, lang, projectDir) + await generateProjectTemplate(command, language, projectDir) .then(() => { let readyMessage; if (command === "wasm") { diff --git a/packages/cli/src/commands/deploy.ts b/packages/cli/src/commands/deploy.ts index 853f733b85..26117401dc 100644 --- a/packages/cli/src/commands/deploy.ts +++ b/packages/cli/src/commands/deploy.ts @@ -1,5 +1,5 @@ /* eslint-disable prefer-const */ -import { Command, Program } from "./types"; +import { Command, Program, BaseCommandOptions } from "./types"; import { createLogger } from "./utils/createLogger"; import { defaultPolywrapManifest, @@ -20,11 +20,9 @@ import { validate } from "jsonschema"; const defaultManifestStr = defaultPolywrapManifest.join(" | "); const pathStr = intlMsg.commands_deploy_options_o_path(); -export type DeployCommandOptions = { +export interface DeployCommandOptions extends BaseCommandOptions { manifestFile: string; outputFile?: string; - verbose?: boolean; - quiet?: boolean; }; type ManifestJob = DeployManifest["jobs"][number]; diff --git a/packages/cli/src/commands/docgen.ts b/packages/cli/src/commands/docgen.ts index 06e517f14d..a5759c323f 100644 --- a/packages/cli/src/commands/docgen.ts +++ b/packages/cli/src/commands/docgen.ts @@ -9,14 +9,14 @@ import { defaultProjectManifestFiles, getProjectFromManifest, } from "../lib"; -import { Command, Program } from "./types"; +import { Command, Program, BaseCommandOptions } from "./types"; import { createLogger } from "./utils/createLogger"; import { scriptPath as docusaurusScriptPath } from "../lib/docgen/docusaurus"; import { scriptPath as jsdocScriptPath } from "../lib/docgen/jsdoc"; import { scriptPath as schemaScriptPath } from "../lib/docgen/schema"; import { ScriptCodegenerator } from "../lib/codegen/ScriptCodeGenerator"; -import { PolywrapClient, PolywrapClientConfig } from "@polywrap/client-js"; +import { PolywrapClient } from "@polywrap/client-js"; import chalk from "chalk"; import { Argument } from "commander"; @@ -29,21 +29,20 @@ const commandToPathMap: Record = { const defaultDocgenDir = "./docs"; const pathStr = intlMsg.commands_codegen_options_o_path(); -export type DocgenCommandOptions = { - manifestFile: string; - docgenDir: string; - clientConfig: Partial; - imports: boolean; - verbose?: boolean; - quiet?: boolean; -}; - export enum DocgenActions { SCHEMA = "schema", DOCUSAURUS = "docusaurus", JSDOC = "jsdoc", } +export interface DocgenCommandOptions extends BaseCommandOptions { + action: DocgenActions; + manifestFile: string; + docgenDir: string; + clientConfig: string; + imports: boolean; +}; + const argumentsDescription = ` ${chalk.bold( DocgenActions.SCHEMA @@ -94,21 +93,22 @@ export const docgen: Command = { .option("-v, --verbose", intlMsg.commands_common_options_verbose()) .option("-q, --quiet", intlMsg.commands_common_options_quiet()) .action(async (action, options) => { - await run(action, { + await run({ ...options, + action, manifestFile: parseManifestFileOption( options.manifestFile, defaultProjectManifestFiles ), docgenDir: parseDirOption(options.docgenDir, defaultDocgenDir), - clientConfig: await parseClientConfigOption(options.clientConfig), }); }); }, }; -async function run(command: DocgenActions, options: DocgenCommandOptions) { +async function run(options: DocgenCommandOptions) { const { + action, manifestFile, docgenDir, clientConfig, @@ -133,9 +133,10 @@ async function run(command: DocgenActions, options: DocgenCommandOptions) { await project.validate(); // Resolve custom script - const customScript = require.resolve(commandToPathMap[command]); + const customScript = require.resolve(commandToPathMap[action]); - const client = new PolywrapClient(clientConfig); + const config = await parseClientConfigOption(clientConfig); + const client = new PolywrapClient(config); const schemaComposer = new SchemaComposer({ project, diff --git a/packages/cli/src/commands/index.ts b/packages/cli/src/commands/index.ts index 679a6877ff..ab585087e7 100644 --- a/packages/cli/src/commands/index.ts +++ b/packages/cli/src/commands/index.ts @@ -2,7 +2,43 @@ export * from "./build"; export * from "./codegen"; export * from "./create"; export * from "./deploy"; -export * from "./infra"; -export * from "./run"; export * from "./docgen"; +export * from "./infra"; export * from "./manifest"; +export * from "./run"; +export * from "./types"; + +import { CommandOptionMappings } from "./types"; +import { BuildCommandOptions } from "./build"; +import { CodegenCommandOptions } from "./codegen"; +import { + CreateAppCommandOptions, + CreatePluginCommandOptions, + CreateWasmCommandOptions +} from "./create"; +import { DeployCommandOptions } from "./deploy"; +import { DocgenCommandOptions } from "./docgen"; +import { InfraCommandOptions } from "./infra"; +import { + ManifestSchemaCommandOptions, + ManifestMigrateCommandOptions +} from "./manifest"; +import { RunCommandOptions } from "./run"; + +export interface CommandOptions extends CommandOptionMappings { + "build": BuildCommandOptions; + "codegen": CodegenCommandOptions; + "create": { + "app": CreateAppCommandOptions; + "plugin": CreatePluginCommandOptions; + "wasm": CreateWasmCommandOptions; + }; + "deploy": DeployCommandOptions; + "docgen": DocgenCommandOptions; + "infra": InfraCommandOptions; + "manifest": { + "migrate": ManifestMigrateCommandOptions; + "schema": ManifestSchemaCommandOptions; + }; + "run": RunCommandOptions; +}; diff --git a/packages/cli/src/commands/infra.ts b/packages/cli/src/commands/infra.ts index 313347e63a..47fc94875e 100644 --- a/packages/cli/src/commands/infra.ts +++ b/packages/cli/src/commands/infra.ts @@ -6,7 +6,7 @@ import { resolvePathIfExists, } from "../lib"; import { createLogger } from "./utils/createLogger"; -import { Command, Program } from "./types"; +import { Command, Program, BaseCommandOptions } from "./types"; import { InfraManifest } from "@polywrap/polywrap-manifest-types-js"; import path from "path"; @@ -15,13 +15,6 @@ import chalk from "chalk"; import yaml from "yaml"; import { readdirSync } from "fs"; -export type InfraCommandOptions = { - manifestFile: string; - modules?: string[]; - verbose?: boolean; - quiet?: boolean; -}; - export enum InfraActions { UP = "up", DOWN = "down", @@ -29,6 +22,12 @@ export enum InfraActions { CONFIG = "config", } +export interface InfraCommandOptions extends BaseCommandOptions { + action: InfraActions; + manifestFile: string; + modules?: string[]; +}; + const DEFAULT_MODULES_PATH = path.join( __dirname, "..", @@ -80,7 +79,10 @@ export const infra: Command = { .option("-v, --verbose", intlMsg.commands_common_options_verbose()) .option("-q, --quiet", intlMsg.commands_common_options_quiet()) .action(async (action, options) => { - await run(action, options); + await run({ + ...options, + action + }); }); }, }; @@ -94,10 +96,9 @@ Default Modules: \n${readdirSync(DEFAULT_MODULES_PATH) Example: 'polywrap infra up --modules=eth-ens-ipfs'.`; async function run( - action: InfraActions, options: InfraCommandOptions ): Promise { - const { modules, verbose, quiet, manifestFile } = options; + const { action, modules, verbose, quiet, manifestFile } = options; const logger = createLogger({ verbose, quiet }); diff --git a/packages/cli/src/commands/manifest.ts b/packages/cli/src/commands/manifest.ts index 825ac83e7a..9781ec1d71 100644 --- a/packages/cli/src/commands/manifest.ts +++ b/packages/cli/src/commands/manifest.ts @@ -1,4 +1,4 @@ -import { Argument, Command, Program } from "./types"; +import { Argument, Command, Program, BaseCommandOptions } from "./types"; import { createLogger } from "./utils/createLogger"; import { defaultBuildManifest, @@ -76,18 +76,16 @@ const manifestTypes = [ ] as const; export type ManifestType = typeof manifestTypes[number]; -export type ManifestSchemaCommandOptions = { +export interface ManifestSchemaCommandOptions extends BaseCommandOptions { + type: ManifestType; raw: boolean; manifestFile: ManifestType; - verbose?: boolean; - quiet?: boolean; }; -export type ManifestMigrateCommandOptions = { +export interface ManifestMigrateCommandOptions extends BaseCommandOptions { + type: ManifestType; manifestFile: string; format: string; - verbose?: boolean; - quiet?: boolean; }; export const manifest: Command = { @@ -124,7 +122,10 @@ export const manifest: Command = { .option("-v, --verbose", intlMsg.commands_common_options_verbose()) .option("-q, --quiet", intlMsg.commands_common_options_quiet()) .action(async (type, options) => { - await runSchemaCommand(type, options); + await runSchemaCommand({ + ...options, + type + }); }); manifestCommand @@ -153,16 +154,18 @@ export const manifest: Command = { .option("-v, --verbose", intlMsg.commands_common_options_verbose()) .option("-q, --quiet", intlMsg.commands_common_options_quiet()) .action(async (type, options) => { - await runMigrateCommand(type, options); + await runMigrateCommand({ + ...options, + type + }); }); }, }; export const runSchemaCommand = async ( - type: ManifestType, options: ManifestSchemaCommandOptions ): Promise => { - const { verbose, quiet } = options; + const { type, verbose, quiet } = options; const logger = createLogger({ verbose, quiet }); let manifestfile = ""; @@ -367,10 +370,9 @@ export const runSchemaCommand = async ( }; const runMigrateCommand = async ( - type: ManifestType, options: ManifestMigrateCommandOptions ) => { - const { verbose, quiet } = options; + const { type, verbose, quiet } = options; const logger = createLogger({ verbose, quiet }); let manifestFile = ""; let manifestString: string; diff --git a/packages/cli/src/commands/run.ts b/packages/cli/src/commands/run.ts index 908d51ddab..062e65e9ca 100644 --- a/packages/cli/src/commands/run.ts +++ b/packages/cli/src/commands/run.ts @@ -1,4 +1,4 @@ -import { Command, Program } from "./types"; +import { Command, Program, BaseCommandOptions } from "./types"; import { intlMsg, JobResult, @@ -18,19 +18,17 @@ import { } from "../lib"; import { createLogger } from "./utils/createLogger"; -import { PolywrapClient, PolywrapClientConfig } from "@polywrap/client-js"; +import { PolywrapClient } from "@polywrap/client-js"; import path from "path"; import yaml from "yaml"; import fs from "fs"; -export type RunCommandOptions = { - clientConfig: Partial; +export interface RunCommandOptions extends BaseCommandOptions { + clientConfig: string; manifestFile: string; jobs?: string[]; validationScript?: string; outputFile?: string; - verbose?: boolean; - quiet?: boolean; }; const defaultManifestStr = defaultWorkflowManifest.join(" | "); @@ -69,7 +67,6 @@ export const run: Command = { options.manifestFile, defaultWorkflowManifest ), - clientConfig: await parseClientConfigOption(options.clientConfig), outputFile: options.outputFile ? parseWorkflowOutputFilePathOption(options.outputFile) : undefined, @@ -88,7 +85,8 @@ const _run = async (options: RunCommandOptions) => { jobs, } = options; const logger = createLogger({ verbose, quiet }); - const client = new PolywrapClient(clientConfig); + const config = await parseClientConfigOption(clientConfig) + const client = new PolywrapClient(config); const manifestPath = path.resolve(manifestFile); const workflow = await loadWorkflowManifest(manifestPath, logger); diff --git a/packages/cli/src/commands/types.ts b/packages/cli/src/commands/types.ts index 03c1f5d622..47b49613ef 100644 --- a/packages/cli/src/commands/types.ts +++ b/packages/cli/src/commands/types.ts @@ -6,3 +6,18 @@ export { Program, Argument }; export interface Command { setup: (program: Program) => MaybeAsync; } + +export interface BaseCommandOptions { + verbose?: boolean; + quiet?: boolean; +} + +export type CommandOptionsOrSubCommand< + TOptions extends BaseCommandOptions = BaseCommandOptions +> = + TOptions | + { [subCommand: string]: CommandOptionsOrSubCommand }; + +export interface CommandOptionMappings { + [name: string]: CommandOptionsOrSubCommand; +} diff --git a/packages/cli/src/index.ts b/packages/cli/src/index.ts index 4d960cea5f..f3218a25c7 100644 --- a/packages/cli/src/index.ts +++ b/packages/cli/src/index.ts @@ -1,19 +1,2 @@ -export { - BuildCommandOptions, - CodegenCommandOptions, - CreateCommandOptions, - DeployCommandOptions, - DocgenCommandOptions, - InfraCommandOptions, - ManifestMigrateCommandOptions, - ManifestSchemaCommandOptions, - RunCommandOptions, - ManifestType, - ProjectType, - SupportedWasmLangs, - SupportedPluginLangs, - SupportedAppLangs, - DocgenActions, - InfraActions, -} from "./commands"; -export { SupportedStrategies } from "./lib/build-strategies"; +export * from "./commands"; +export * from "./lib"; diff --git a/packages/js/cli-api/src/commands.ts b/packages/js/cli-api/src/commands.ts index 6aade89844..86e738d5b4 100644 --- a/packages/js/cli-api/src/commands.ts +++ b/packages/js/cli-api/src/commands.ts @@ -1,20 +1,53 @@ import { runCLI } from "./run-cli"; +import { CreateCommandOptions, ManifestCommandOptions } from "./types"; + import { - Commands, - CommandNames, + ManifestMigrateCommandOptions, + ManifestSchemaCommandOptions, CommandOptions, - ActionCommandNames, -} from "./utils"; -import { CreateCommandOptions, ManifestCommandOptions } from "./types"; + CommandOptionMappings, +} from "polywrap"; + +type CommandFn = ( + options?: TOptions, + cwd?: string, + cli?: string +) => ReturnType; + +type CommandFns< + TCommands extends CommandOptionMappings = CommandOptions +> = Required<{ + [Command in keyof TCommands]: + TCommands[Command] extends CommandOptions ? + CommandFn : + TCommands[Command] extends CommandOptionMappings ? + CommandFn : never; +}>; + +type RecurseCommands< + TFinalType, + TCommands extends CommandOptionMappings = CommandOptions, +> = Required<{ + [Command in keyof TCommands]: + TCommands[Command] extends CommandOptions ? + CommandFn : + TCommands[Command] extends CommandOptionMappings ? + CommandFn : never; +}>; -export const commands: Commands = { +// TODO: generic recusive template + +export const commands: CommandFns = { build: simpleCommandExecutorFactory("build"), codegen: simpleCommandExecutorFactory("codegen"), create: createCommandExecutor, deploy: simpleCommandExecutorFactory("deploy"), docgen: actionCommandExecutorFactory("docgen"), infra: actionCommandExecutorFactory("infra"), - manifest: manifestCommandExecutor, + manifest: { + migrate: manifestCommandExecutor, + schema: manifestCommandExecutor + }, run: simpleCommandExecutorFactory("run"), }; @@ -43,14 +76,11 @@ function parseOptions( return parsed; } -function simpleCommandExecutorFactory( - command: Command -) { - return async ( - options?: CommandOptions[Command], - cwd?: string, - cli?: string - ) => { +function simpleCommandExecutorFactory< + TCommand extends keyof CommandOptions, + TOptions = CommandOptions[TCommand] +>(command: TCommand) { + return async (options?: TOptions, cwd?: string, cli?: string) => { const args = [command, ...parseOptions(options)]; return await runCLI({ args, cwd, cli }); }; diff --git a/packages/js/cli-api/src/utils/declarations.d.ts b/packages/js/cli-api/src/declarations.d.ts similarity index 100% rename from packages/js/cli-api/src/utils/declarations.d.ts rename to packages/js/cli-api/src/declarations.d.ts diff --git a/packages/js/cli-api/src/utils/index.ts b/packages/js/cli-api/src/utils/index.ts deleted file mode 100644 index 316a1aa00e..0000000000 --- a/packages/js/cli-api/src/utils/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "./internal-types"; diff --git a/packages/js/cli-api/src/utils/internal-types.ts b/packages/js/cli-api/src/utils/internal-types.ts deleted file mode 100644 index ef6ed2479f..0000000000 --- a/packages/js/cli-api/src/utils/internal-types.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { runCLI } from "../run-cli"; -import { - BuildCommandOptions, - CodegenCommandOptions, - CreateCommandOptions, - DeployCommandOptions, - DocgenCommandOptions, - InfraCommandOptions, - ManifestCommandOptions, - RunCommandOptions, -} from "../types"; - -export type CommandNames = keyof CommandOptions; - -export type ActionCommandNames = "docgen" | "infra"; - -export type CommandOptions = { - build: BuildCommandOptions; - codegen: CodegenCommandOptions; - create: CreateCommandOptions; - deploy: DeployCommandOptions; - docgen: DocgenCommandOptions; - infra: InfraCommandOptions; - manifest: ManifestCommandOptions; - run: RunCommandOptions; -}; - -export type Commands = { - [Command in CommandNames]: ( - options?: CommandOptions[Command], - cwd?: string, - cli?: string - ) => ReturnType; -}; diff --git a/todo b/todo new file mode 100644 index 0000000000..6161e6f0ed --- /dev/null +++ b/todo @@ -0,0 +1,14 @@ +build: + x clientConfig => move to string + x strategy => BuildStrategy +codegen: + x clientConfig +create: + x wasm|plugin|app => { language + name } +docgen: + x clientConfig + x action => DocgenAction +infra: + x action => InfraAction +run: + x clientConfig From 321a1be401b033ae75acfdd1749fed70b76aa410 Mon Sep 17 00:00:00 2001 From: dOrgJelli Date: Thu, 20 Oct 2022 22:40:33 +0200 Subject: [PATCH 09/38] finish typings --- packages/cli/src/commands/create.ts | 12 +- packages/cli/src/commands/index.ts | 5 +- packages/cli/src/commands/types.ts | 10 +- packages/cli/src/lib/index.ts | 10 +- .../js/cli-api/src/__tests__/cli-js.test.ts | 7 +- packages/js/cli-api/src/commands.ts | 120 +++++------------- packages/js/cli-api/src/index.ts | 1 - packages/js/cli-api/src/types.ts | 120 ------------------ todo | 18 +-- 9 files changed, 59 insertions(+), 244 deletions(-) delete mode 100644 packages/js/cli-api/src/types.ts diff --git a/packages/cli/src/commands/create.ts b/packages/cli/src/commands/create.ts index ed7e395162..85d17898e3 100644 --- a/packages/cli/src/commands/create.ts +++ b/packages/cli/src/commands/create.ts @@ -39,12 +39,12 @@ export interface CreateCommandOptions< outputDir?: string; }; -export type CreateAppCommandOptions = - CreateCommandOptions; -export type CreatePluginCommandOptions = - CreateCommandOptions; -export type CreateWasmCommandOptions = - CreateCommandOptions; +export interface CreateAppCommandOptions + extends CreateCommandOptions { } +export interface CreatePluginCommandOptions + extends CreateCommandOptions { } +export interface CreateWasmCommandOptions + extends CreateCommandOptions { } export const create: Command = { setup: (program: Program) => { diff --git a/packages/cli/src/commands/index.ts b/packages/cli/src/commands/index.ts index ab585087e7..76ccae5092 100644 --- a/packages/cli/src/commands/index.ts +++ b/packages/cli/src/commands/index.ts @@ -8,7 +8,6 @@ export * from "./manifest"; export * from "./run"; export * from "./types"; -import { CommandOptionMappings } from "./types"; import { BuildCommandOptions } from "./build"; import { CodegenCommandOptions } from "./codegen"; import { @@ -25,7 +24,7 @@ import { } from "./manifest"; import { RunCommandOptions } from "./run"; -export interface CommandOptions extends CommandOptionMappings { +export interface CommandOptions { "build": BuildCommandOptions; "codegen": CodegenCommandOptions; "create": { @@ -41,4 +40,4 @@ export interface CommandOptions extends CommandOptionMappings { "schema": ManifestSchemaCommandOptions; }; "run": RunCommandOptions; -}; +} diff --git a/packages/cli/src/commands/types.ts b/packages/cli/src/commands/types.ts index 47b49613ef..e74c4f62dc 100644 --- a/packages/cli/src/commands/types.ts +++ b/packages/cli/src/commands/types.ts @@ -12,12 +12,6 @@ export interface BaseCommandOptions { quiet?: boolean; } -export type CommandOptionsOrSubCommand< - TOptions extends BaseCommandOptions = BaseCommandOptions -> = - TOptions | - { [subCommand: string]: CommandOptionsOrSubCommand }; - -export interface CommandOptionMappings { - [name: string]: CommandOptionsOrSubCommand; +export type CommandOptionMapping = { + [name: string]: BaseCommandOptions | CommandOptionMapping; } diff --git a/packages/cli/src/lib/index.ts b/packages/cli/src/lib/index.ts index 9be4c276bf..c68110b2cf 100644 --- a/packages/cli/src/lib/index.ts +++ b/packages/cli/src/lib/index.ts @@ -1,15 +1,17 @@ +export * from "./build-strategies"; +export * from "./codegen"; export * from "./deploy"; export * from "./helpers"; export * from "./infra"; export * from "./intl"; -export * from "./option-parsers"; +export * from "./logging"; +export * from "./manifest"; export * from "./option-defaults"; +export * from "./option-parsers"; export * from "./project"; export * from "./system"; export * from "./test-env"; +export * from "./workflow"; export * from "./CacheDirectory"; export * from "./Compiler"; -export * from "./codegen"; export * from "./SchemaComposer"; -export * from "./workflow"; -export * from "./logging"; diff --git a/packages/js/cli-api/src/__tests__/cli-js.test.ts b/packages/js/cli-api/src/__tests__/cli-js.test.ts index 89fd92bcc6..f3ced7a569 100644 --- a/packages/js/cli-api/src/__tests__/cli-js.test.ts +++ b/packages/js/cli-api/src/__tests__/cli-js.test.ts @@ -1,4 +1,5 @@ -import { awaitResponse, Commands, InfraActions, runCLI } from "../../"; +import { awaitResponse, Commands, runCLI } from "../../"; +import { SupportedStrategies } from "polywrap"; import path from "path"; import fs from "fs"; @@ -26,7 +27,9 @@ describe("cli-js tests", () => { expect(fs.existsSync(buildDir)).toBeFalsy(); // build - await Commands.build({ strategy: "image" }, wrapperPath); + await Commands.build({ + strategy: SupportedStrategies.IMAGE + }, wrapperPath); // check for build dir and artifacts const wasmPath = path.join(buildDir, "wrap.wasm"); diff --git a/packages/js/cli-api/src/commands.ts b/packages/js/cli-api/src/commands.ts index 86e738d5b4..13a5d206b7 100644 --- a/packages/js/cli-api/src/commands.ts +++ b/packages/js/cli-api/src/commands.ts @@ -1,54 +1,54 @@ import { runCLI } from "./run-cli"; -import { CreateCommandOptions, ManifestCommandOptions } from "./types"; import { - ManifestMigrateCommandOptions, - ManifestSchemaCommandOptions, + CommandOptionMapping, + BaseCommandOptions, CommandOptions, - CommandOptionMappings, } from "polywrap"; -type CommandFn = ( +type CommandFn< + TOptions extends BaseCommandOptions +> = ( options?: TOptions, cwd?: string, cli?: string ) => ReturnType; type CommandFns< - TCommands extends CommandOptionMappings = CommandOptions + TCommands > = Required<{ [Command in keyof TCommands]: - TCommands[Command] extends CommandOptions ? - CommandFn : - TCommands[Command] extends CommandOptionMappings ? - CommandFn : never; + TCommands[Command] extends BaseCommandOptions ? + CommandFn : + TCommands[Command] extends CommandOptionMapping ? + CommandFns : never; }>; -type RecurseCommands< - TFinalType, - TCommands extends CommandOptionMappings = CommandOptions, -> = Required<{ - [Command in keyof TCommands]: - TCommands[Command] extends CommandOptions ? - CommandFn : - TCommands[Command] extends CommandOptionMappings ? - CommandFn : never; -}>; - -// TODO: generic recusive template +function execCommandFn< + TOptions extends BaseCommandOptions, +>(command: string): CommandFn { + return async (options?: TOptions, cwd?: string, cli?: string) => { + const args = [command, ...parseOptions(options)]; + return await runCLI({ args, cwd, cli }); + }; +} -export const commands: CommandFns = { - build: simpleCommandExecutorFactory("build"), - codegen: simpleCommandExecutorFactory("codegen"), - create: createCommandExecutor, - deploy: simpleCommandExecutorFactory("deploy"), - docgen: actionCommandExecutorFactory("docgen"), - infra: actionCommandExecutorFactory("infra"), +export const commands: CommandFns = { + build: execCommandFn("build"), + codegen: execCommandFn("codegen"), + create: { + app: execCommandFn("create app"), + plugin: execCommandFn("create plugin"), + wasm: execCommandFn("create wasm") + }, + deploy: execCommandFn("deploy"), + docgen: execCommandFn("docgen"), + infra: execCommandFn("infra"), manifest: { - migrate: manifestCommandExecutor, - schema: manifestCommandExecutor + migrate: execCommandFn("manifest migrate"), + schema: execCommandFn("manifest schema") }, - run: simpleCommandExecutorFactory("run"), + run: execCommandFn("run"), }; function toKebabCase(camelCase: string): string { @@ -62,8 +62,8 @@ function parseValue(value: string | string[] | boolean): string { return value.toString(); } -function parseOptions( - options?: CommandOptions[Command] +function parseOptions( + options?: TOptions ): string[] { const parsed: string[] = []; if (options) { @@ -75,55 +75,3 @@ function parseOptions( } return parsed; } - -function simpleCommandExecutorFactory< - TCommand extends keyof CommandOptions, - TOptions = CommandOptions[TCommand] ->(command: TCommand) { - return async (options?: TOptions, cwd?: string, cli?: string) => { - const args = [command, ...parseOptions(options)]; - return await runCLI({ args, cwd, cli }); - }; -} - -function actionCommandExecutorFactory( - command: Command -) { - return async ( - options: CommandOptions[Command], - cwd?: string, - cli?: string - ) => { - const { action, ...cmdOptions } = options; - const args = [command, action, ...parseOptions(cmdOptions)]; - return await runCLI({ args, cwd, cli }); - }; -} - -async function createCommandExecutor( - options: CreateCommandOptions, - cwd?: string, - cli?: string -): Promise<{ - exitCode: number; - stdout: string; - stderr: string; -}> { - const { command, language, name, ...createOpts } = options; - const args = ["create", command, language, name, ...parseOptions(createOpts)]; - return await runCLI({ args, cwd, cli }); -} - -async function manifestCommandExecutor( - options: ManifestCommandOptions, - cwd?: string, - cli?: string -): Promise<{ - exitCode: number; - stdout: string; - stderr: string; -}> { - const { command, type, ...manifestOptions } = options; - const args = ["manifest", command, type, ...parseOptions(manifestOptions)]; - return await runCLI({ args, cwd, cli }); -} diff --git a/packages/js/cli-api/src/index.ts b/packages/js/cli-api/src/index.ts index 73f992f8d8..4c8ca3b047 100644 --- a/packages/js/cli-api/src/index.ts +++ b/packages/js/cli-api/src/index.ts @@ -1,4 +1,3 @@ -export * from "./types"; export { runCLI } from "./run-cli"; export { commands as Commands } from "./commands"; export * from "./awaitResponse"; diff --git a/packages/js/cli-api/src/types.ts b/packages/js/cli-api/src/types.ts deleted file mode 100644 index e44c9ec952..0000000000 --- a/packages/js/cli-api/src/types.ts +++ /dev/null @@ -1,120 +0,0 @@ -import { - BuildCommandOptions as ParsedBuildCommandOptions, - CodegenCommandOptions as ParsedCodegenCommandOptions, - CreateCommandOptions as ParsedCreateCommandOptions, - DeployCommandOptions as ParsedDeployCommandOptions, - DocgenCommandOptions as ParsedDocgenCommandOptions, - InfraCommandOptions as ParsedInfraCommandOptions, - ManifestMigrateCommandOptions as ParsedManifestMigrateCommandOptions, - ManifestSchemaCommandOptions as ParsedManifestSchemaCommandOptions, - RunCommandOptions as ParsedRunCommandOptions, - SupportedWasmLangs, - SupportedPluginLangs, - SupportedAppLangs, - DocgenActions, - InfraActions, - SupportedStrategies, - ManifestType, -} from "polywrap"; - -export { - DocgenActions, - InfraActions, - SupportedStrategies as BuildStrategies, -} from "polywrap"; - -export type DocgenAction = `${DocgenActions}`; -export type InfraAction = `${InfraActions}`; -export type BuildStrategy = `${SupportedStrategies}`; - -export type DeployCommandOptions = Partial; - -export type BuildCommandOptions = Omit< - Partial, - "watch" | "clientConfig" | "strategy" -> & { - clientConfig?: string; - strategy?: BuildStrategy; -}; - -export type CodegenCommandOptions = Omit< - Partial, - "clientConfig" -> & { - clientConfig?: string; -}; - -export type RunCommandOptions = Omit< - Partial, - "clientConfig" -> & { - clientConfig?: string; -}; - -// create - -export type CreateWasmCommandArgs = { - command: "wasm"; - language: SupportedWasmLangs; - name: string; -}; - -export type CreatePluginCommandArgs = { - command: "plugin"; - language: SupportedPluginLangs; - name: string; -}; - -export type CreateAppCommandArgs = { - command: "app"; - language: SupportedAppLangs; - name: string; -}; - -export type CreateCommandArgs = - | CreateWasmCommandArgs - | CreatePluginCommandArgs - | CreateAppCommandArgs; - -export type CreateCommandOptions = CreateCommandArgs & - Partial; - -// docgen - -export type DocgenCommandArgs = { - action: DocgenAction; -}; - -export type DocgenCommandOptions = DocgenCommandArgs & - Omit, "clientConfig"> & { - clientConfig?: string; - }; - -// infra - -export type InfraCommandArgs = { - action: InfraAction; -}; - -export type InfraCommandOptions = InfraCommandArgs & - Partial; - -// manifest - -export type ManifestSchemaCommandArgs = { - command: "schema"; - type: ManifestType; -}; - -export type ManifestMigrateCommandArgs = { - command: "migrate"; - type: ManifestType; -}; - -export type ManifestSchemaCommandOptions = Partial; - -export type ManifestMigrateCommandOptions = Partial; - -export type ManifestCommandOptions = - | (ManifestSchemaCommandArgs & ManifestSchemaCommandOptions) - | (ManifestMigrateCommandArgs & ManifestMigrateCommandOptions); diff --git a/todo b/todo index 6161e6f0ed..13174671e6 100644 --- a/todo +++ b/todo @@ -1,14 +1,4 @@ -build: - x clientConfig => move to string - x strategy => BuildStrategy -codegen: - x clientConfig -create: - x wasm|plugin|app => { language + name } -docgen: - x clientConfig - x action => DocgenAction -infra: - x action => InfraAction -run: - x clientConfig +- For all command option interfaces, make optional arguments undefine-able (i.e. `prop?: Type`), this way the cli-js library doesn't have to pass them in if they have defaults. Inside of the command's `run(...)` method, we should require all options to be defined (i.e. `run(options: Require)`). +- Make sure all CLI command options are serializable (string, number, array, etc) +- Usage of enums is awkward, and requires the user to import the enum type (see `commands.build({ strategy: ... })`). Instead, we can just use TypeScript string unions (i.e. `type BuildStrategy = "vm" | "image" | ...`). I think this will make our life easier. +- Create an automated test suite in cli-js that ensures test input is defined for all possible commands. \ No newline at end of file From 120cfc6871d4450aade5649f4f7852b8608f5699 Mon Sep 17 00:00:00 2001 From: dOrgJelli Date: Fri, 21 Oct 2022 12:04:22 +0200 Subject: [PATCH 10/38] proper argument handling --- packages/cli/src/commands/create.ts | 37 ++------ packages/cli/src/commands/docgen.ts | 7 +- packages/cli/src/commands/index.ts | 57 ++++++++++--- packages/cli/src/commands/infra.ts | 9 +- packages/cli/src/commands/manifest.ts | 18 ++-- packages/cli/src/commands/types.ts | 9 +- packages/js/cli-api/src/commands.ts | 117 +++++++++++++++++++++----- 7 files changed, 167 insertions(+), 87 deletions(-) diff --git a/packages/cli/src/commands/create.ts b/packages/cli/src/commands/create.ts index 85d17898e3..4a65baa517 100644 --- a/packages/cli/src/commands/create.ts +++ b/packages/cli/src/commands/create.ts @@ -31,21 +31,10 @@ type SupportedLangs = | SupportedAppLangs | SupportedPluginLangs; -export interface CreateCommandOptions< - TLangs extends SupportedLangs -> extends BaseCommandOptions { - language: TLangs; - name: string; +export interface CreateCommandOptions extends BaseCommandOptions { outputDir?: string; }; -export interface CreateAppCommandOptions - extends CreateCommandOptions { } -export interface CreatePluginCommandOptions - extends CreateCommandOptions { } -export interface CreateWasmCommandOptions - extends CreateCommandOptions { } - export const create: Command = { setup: (program: Program) => { const createCommand = program @@ -71,11 +60,7 @@ export const create: Command = { .option("-v, --verbose", intlMsg.commands_common_options_verbose()) .option("-q, --quiet", intlMsg.commands_common_options_quiet()) .action(async (language, name, options) => { - await run("wasm", { - ...options, - language, - name, - }); + await run("wasm", language, name, options); }); createCommand @@ -96,11 +81,7 @@ export const create: Command = { .option("-v, --verbose", intlMsg.commands_common_options_verbose()) .option("-q, --quiet", intlMsg.commands_common_options_quiet()) .action(async (language, name, options) => { - await run("app", { - ...options, - language, - name - }); + await run("app", language, name, options); }); createCommand @@ -121,20 +102,18 @@ export const create: Command = { .option("-v, --verbose", intlMsg.commands_common_options_verbose()) .option("-q, --quiet", intlMsg.commands_common_options_quiet()) .action(async (language, name, options) => { - await run("plugin", { - ...options, - language, - name - }); + await run("plugin", language, name, options); }); }, }; async function run( command: ProjectType, - options: CreateCommandOptions + language: SupportedLangs, + name: string, + options: CreateCommandOptions ) { - const { language, name, outputDir, verbose, quiet } = options; + const { outputDir, verbose, quiet } = options; const logger = createLogger({ verbose, quiet }); const projectDir = path.resolve(outputDir ? `${outputDir}/${name}` : name); diff --git a/packages/cli/src/commands/docgen.ts b/packages/cli/src/commands/docgen.ts index a5759c323f..f8a16dabfc 100644 --- a/packages/cli/src/commands/docgen.ts +++ b/packages/cli/src/commands/docgen.ts @@ -36,7 +36,6 @@ export enum DocgenActions { } export interface DocgenCommandOptions extends BaseCommandOptions { - action: DocgenActions; manifestFile: string; docgenDir: string; clientConfig: string; @@ -93,9 +92,8 @@ export const docgen: Command = { .option("-v, --verbose", intlMsg.commands_common_options_verbose()) .option("-q, --quiet", intlMsg.commands_common_options_quiet()) .action(async (action, options) => { - await run({ + await run(action, { ...options, - action, manifestFile: parseManifestFileOption( options.manifestFile, defaultProjectManifestFiles @@ -106,9 +104,8 @@ export const docgen: Command = { }, }; -async function run(options: DocgenCommandOptions) { +async function run(action: DocgenActions, options: DocgenCommandOptions) { const { - action, manifestFile, docgenDir, clientConfig, diff --git a/packages/cli/src/commands/index.ts b/packages/cli/src/commands/index.ts index 76ccae5092..1e954cca25 100644 --- a/packages/cli/src/commands/index.ts +++ b/packages/cli/src/commands/index.ts @@ -11,33 +11,62 @@ export * from "./types"; import { BuildCommandOptions } from "./build"; import { CodegenCommandOptions } from "./codegen"; import { - CreateAppCommandOptions, - CreatePluginCommandOptions, - CreateWasmCommandOptions + CreateCommandOptions, + SupportedAppLangs, + SupportedPluginLangs, + SupportedWasmLangs } from "./create"; import { DeployCommandOptions } from "./deploy"; -import { DocgenCommandOptions } from "./docgen"; -import { InfraCommandOptions } from "./infra"; +import { + DocgenCommandOptions, + DocgenActions +} from "./docgen"; +import { + InfraCommandOptions, + InfraActions +} from "./infra"; import { ManifestSchemaCommandOptions, - ManifestMigrateCommandOptions + ManifestMigrateCommandOptions, + ManifestType } from "./manifest"; import { RunCommandOptions } from "./run"; -export interface CommandOptions { +export interface CommandTypings { "build": BuildCommandOptions; "codegen": CodegenCommandOptions; "create": { - "app": CreateAppCommandOptions; - "plugin": CreatePluginCommandOptions; - "wasm": CreateWasmCommandOptions; + "app": { + options: CreateCommandOptions; + arguments: [language: SupportedAppLangs, name: string]; + }; + "plugin": { + options: CreateCommandOptions; + arguments: [language: SupportedPluginLangs, name: string]; + }; + "wasm": { + options: CreateCommandOptions; + arguments: [language: SupportedWasmLangs, name: string]; + }; }; "deploy": DeployCommandOptions; - "docgen": DocgenCommandOptions; - "infra": InfraCommandOptions; + "docgen": { + options: DocgenCommandOptions; + arguments: [action: `${DocgenActions}`]; + }; + "infra": { + options: InfraCommandOptions; + arguments: [action: `${InfraActions}`]; + }; "manifest": { - "migrate": ManifestMigrateCommandOptions; - "schema": ManifestSchemaCommandOptions; + "migrate": { + options: ManifestMigrateCommandOptions; + arguments: [type: ManifestType]; + }; + "schema": { + options: ManifestSchemaCommandOptions; + arguments: [type: ManifestType]; + }; }; "run": RunCommandOptions; } diff --git a/packages/cli/src/commands/infra.ts b/packages/cli/src/commands/infra.ts index 47fc94875e..0031d0e9b3 100644 --- a/packages/cli/src/commands/infra.ts +++ b/packages/cli/src/commands/infra.ts @@ -23,7 +23,6 @@ export enum InfraActions { } export interface InfraCommandOptions extends BaseCommandOptions { - action: InfraActions; manifestFile: string; modules?: string[]; }; @@ -79,10 +78,7 @@ export const infra: Command = { .option("-v, --verbose", intlMsg.commands_common_options_verbose()) .option("-q, --quiet", intlMsg.commands_common_options_quiet()) .action(async (action, options) => { - await run({ - ...options, - action - }); + await run(action, options); }); }, }; @@ -96,9 +92,10 @@ Default Modules: \n${readdirSync(DEFAULT_MODULES_PATH) Example: 'polywrap infra up --modules=eth-ens-ipfs'.`; async function run( + action: InfraActions, options: InfraCommandOptions ): Promise { - const { action, modules, verbose, quiet, manifestFile } = options; + const { modules, verbose, quiet, manifestFile } = options; const logger = createLogger({ verbose, quiet }); diff --git a/packages/cli/src/commands/manifest.ts b/packages/cli/src/commands/manifest.ts index 9781ec1d71..c0d8222796 100644 --- a/packages/cli/src/commands/manifest.ts +++ b/packages/cli/src/commands/manifest.ts @@ -77,13 +77,11 @@ const manifestTypes = [ export type ManifestType = typeof manifestTypes[number]; export interface ManifestSchemaCommandOptions extends BaseCommandOptions { - type: ManifestType; raw: boolean; manifestFile: ManifestType; }; export interface ManifestMigrateCommandOptions extends BaseCommandOptions { - type: ManifestType; manifestFile: string; format: string; }; @@ -122,10 +120,7 @@ export const manifest: Command = { .option("-v, --verbose", intlMsg.commands_common_options_verbose()) .option("-q, --quiet", intlMsg.commands_common_options_quiet()) .action(async (type, options) => { - await runSchemaCommand({ - ...options, - type - }); + await runSchemaCommand(type, options); }); manifestCommand @@ -154,18 +149,16 @@ export const manifest: Command = { .option("-v, --verbose", intlMsg.commands_common_options_verbose()) .option("-q, --quiet", intlMsg.commands_common_options_quiet()) .action(async (type, options) => { - await runMigrateCommand({ - ...options, - type - }); + await runMigrateCommand(type, options); }); }, }; export const runSchemaCommand = async ( + type: ManifestType, options: ManifestSchemaCommandOptions ): Promise => { - const { type, verbose, quiet } = options; + const { verbose, quiet } = options; const logger = createLogger({ verbose, quiet }); let manifestfile = ""; @@ -370,9 +363,10 @@ export const runSchemaCommand = async ( }; const runMigrateCommand = async ( + type: ManifestType, options: ManifestMigrateCommandOptions ) => { - const { type, verbose, quiet } = options; + const { verbose, quiet } = options; const logger = createLogger({ verbose, quiet }); let manifestFile = ""; let manifestString: string; diff --git a/packages/cli/src/commands/types.ts b/packages/cli/src/commands/types.ts index e74c4f62dc..0101dc6b43 100644 --- a/packages/cli/src/commands/types.ts +++ b/packages/cli/src/commands/types.ts @@ -12,6 +12,11 @@ export interface BaseCommandOptions { quiet?: boolean; } -export type CommandOptionMapping = { - [name: string]: BaseCommandOptions | CommandOptionMapping; +export interface CommandTypes { + options: BaseCommandOptions; + arguments: string[]; +} + +export type CommandTypeMapping = { + [name: string]: BaseCommandOptions | CommandTypes | CommandTypeMapping; } diff --git a/packages/js/cli-api/src/commands.ts b/packages/js/cli-api/src/commands.ts index 13a5d206b7..d424f53fae 100644 --- a/packages/js/cli-api/src/commands.ts +++ b/packages/js/cli-api/src/commands.ts @@ -1,9 +1,10 @@ import { runCLI } from "./run-cli"; import { - CommandOptionMapping, + CommandTypes, + CommandTypeMapping, BaseCommandOptions, - CommandOptions, + CommandTypings, } from "polywrap"; type CommandFn< @@ -14,43 +15,121 @@ type CommandFn< cli?: string ) => ReturnType; +type CommandFnWithArgs< + TArguments extends unknown[], + TOptions extends BaseCommandOptions +> = ( + ...args: [ + ...targs: TArguments, + options?: TOptions, + cwd?: string, + cli?: string + ] +) => ReturnType; + type CommandFns< TCommands > = Required<{ [Command in keyof TCommands]: TCommands[Command] extends BaseCommandOptions ? CommandFn : - TCommands[Command] extends CommandOptionMapping ? - CommandFns : never; + TCommands[Command] extends CommandTypes ? + CommandFnWithArgs : + TCommands[Command] extends CommandTypeMapping ? + CommandFns : never; }>; function execCommandFn< TOptions extends BaseCommandOptions, >(command: string): CommandFn { - return async (options?: TOptions, cwd?: string, cli?: string) => { - const args = [command, ...parseOptions(options)]; - return await runCLI({ args, cwd, cli }); + return async (options?: Partial, cwd?: string, cli?: string) => { + const parsedArgs = [ + ...command.split(" "), + ...parseOptions(options) + ]; + return await runCLI({ + args: parsedArgs, cwd, cli + }); }; } -export const commands: CommandFns = { - build: execCommandFn("build"), - codegen: execCommandFn("codegen"), +function execCommandWithArgsFn< + TTypes extends { + options: BaseCommandOptions, + arguments: unknown[] + }, + TArguments extends unknown[] = TTypes["arguments"], + TOptions extends BaseCommandOptions = TTypes["options"] +>(command: string): CommandFnWithArgs { + return async (...args: [...targs: TArguments, options?: Partial, cwd?: string, cli?: string]) => { + const commandArgs = []; + let options = {}; + let optionsFound = true; + let cwd: string | undefined; + let cwdFound = false; + let cli: string | undefined; + + // Iterate through the variadic arguments + for (const arg of args) { + if (!optionsFound) { + if (typeof arg === "string") { + commandArgs.push(arg); + } else if (arg === "object") { + options = arg as Record; + optionsFound = true; + } else if (typeof arg === "undefined") { + // undefined options + optionsFound = true; + } + } else { + if (typeof arg !== "string" && typeof arg !== "undefined") { + throw new Error(`Invalid "cwd" or "cli" argument type: ${arg}`); + } + if (!cwdFound) { + cwd = arg; + cwdFound = true; + } else { + cli = arg; + } + } + } + + const parsedArgs = [ + ...command.split(" "), + ...commandArgs, + ...parseOptions(options) + ]; + return await runCLI({ + args: parsedArgs, cwd, cli + }); + } +} + +export const commands: CommandFns = { + build: execCommandFn("build"), + codegen: execCommandFn("codegen"), create: { - app: execCommandFn("create app"), - plugin: execCommandFn("create plugin"), - wasm: execCommandFn("create wasm") + app: execCommandWithArgsFn("create app"), + plugin: execCommandWithArgsFn("create plugin"), + wasm: execCommandWithArgsFn("create wasm") }, - deploy: execCommandFn("deploy"), - docgen: execCommandFn("docgen"), - infra: execCommandFn("infra"), + deploy: execCommandFn("deploy"), + docgen: execCommandWithArgsFn("docgen"), + infra: execCommandWithArgsFn("infra"), manifest: { - migrate: execCommandFn("manifest migrate"), - schema: execCommandFn("manifest schema") + migrate: execCommandWithArgsFn("manifest migrate"), + schema: execCommandWithArgsFn("manifest schema") }, - run: execCommandFn("run"), + run: execCommandFn("run"), }; +// TODO: +// x clean up templates +// x remove argument-as-options +// x make all options optional +// - make all options required in run functions +// - make all option structs serializable + function toKebabCase(camelCase: string): string { return camelCase.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(); } From 97a8bb2c782f4d592328545e1a09115c867597d0 Mon Sep 17 00:00:00 2001 From: dOrgJelli Date: Fri, 21 Oct 2022 12:32:26 +0200 Subject: [PATCH 11/38] improve required/optional semantics for command options --- packages/cli/src/commands/build.ts | 17 ++++--- packages/cli/src/commands/codegen.ts | 16 +++--- packages/cli/src/commands/create.ts | 28 ++++++++--- packages/cli/src/commands/deploy.ts | 10 ++-- packages/cli/src/commands/docgen.ts | 11 +++-- packages/cli/src/commands/infra.ts | 17 ++++--- packages/cli/src/commands/manifest.ts | 49 +++++++++++-------- packages/cli/src/commands/run.ts | 20 ++++---- packages/cli/src/commands/types.ts | 4 +- .../src/lib/option-parsers/client-config.ts | 2 +- .../cli/src/lib/option-parsers/codegen.ts | 6 +-- .../src/lib/option-parsers/manifestFile.ts | 4 +- packages/js/cli-api/src/commands.ts | 2 +- 13 files changed, 112 insertions(+), 74 deletions(-) diff --git a/packages/cli/src/commands/build.ts b/packages/cli/src/commands/build.ts index 6fa177217a..d6a36a20d2 100644 --- a/packages/cli/src/commands/build.ts +++ b/packages/cli/src/commands/build.ts @@ -36,7 +36,7 @@ const pathStr = intlMsg.commands_build_options_o_path(); export interface BuildCommandOptions extends BaseCommandOptions { manifestFile: string; outputDir: string; - clientConfig: string; + clientConfig?: string | false; skipCodegen?: boolean; watch?: boolean; strategy: SupportedStrategies; @@ -67,21 +67,24 @@ export const build: Command = { .option(`-n, --skip-codegen`, `${intlMsg.commands_build_options_n()}`) .option( `-s, --strategy <${strategyStr}>`, - `${intlMsg.commands_build_options_s()}`, - defaultStrategy + `${intlMsg.commands_build_options_s()}` ) .option(`-w, --watch`, `${intlMsg.commands_build_options_w()}`) .option("-v, --verbose", intlMsg.commands_common_options_verbose()) .option("-q, --quiet", intlMsg.commands_common_options_quiet()) - .action(async (options) => { + .action(async (options: Partial) => { await run({ - ...options, manifestFile: parseManifestFileOption( options.manifestFile, defaultPolywrapManifest ), outputDir: parseDirOption(options.outputDir, defaultOutputDir), - strategy: options.strategy, + clientConfig: options.clientConfig || false, + skipCodegen: options.skipCodegen || false, + strategy: options.strategy || defaultStrategy, + watch: options.watch || false, + verbose: options.verbose || false, + quiet: options.quiet || false }); }); }, @@ -122,7 +125,7 @@ function createBuildStrategy( } } -async function run(options: BuildCommandOptions) { +async function run(options: Required) { const { watch, manifestFile, diff --git a/packages/cli/src/commands/codegen.ts b/packages/cli/src/commands/codegen.ts index 70d1947780..bee79de3b3 100644 --- a/packages/cli/src/commands/codegen.ts +++ b/packages/cli/src/commands/codegen.ts @@ -31,8 +31,8 @@ export interface CodegenCommandOptions extends BaseCommandOptions { manifestFile: string; codegenDir: string; publishDir: string; - script?: string; - clientConfig: string; + script: string | false; + clientConfig: string | false; }; export const codegen: Command = { @@ -69,22 +69,24 @@ export const codegen: Command = { ) .option("-v, --verbose", intlMsg.commands_common_options_verbose()) .option("-q, --quiet", intlMsg.commands_common_options_quiet()) - .action(async (options) => { + .action(async (options: Partial) => { await run({ - ...options, - codegenDir: parseDirOption(options.codegenDir, defaultCodegenDir), - script: parseCodegenScriptOption(options.script), manifestFile: parseManifestFileOption( options.manifestFile, defaultProjectManifestFiles ), + codegenDir: parseDirOption(options.codegenDir, defaultCodegenDir), publishDir: parseDirOption(options.publishDir, defaultPublishDir), + script: parseCodegenScriptOption(options.script), + clientConfig: options.clientConfig || false, + verbose: options.verbose || false, + quiet: options.quiet || false }); }); }, }; -async function run(options: CodegenCommandOptions) { +async function run(options: Required) { const { manifestFile, codegenDir, diff --git a/packages/cli/src/commands/create.ts b/packages/cli/src/commands/create.ts index 4a65baa517..19ebf11295 100644 --- a/packages/cli/src/commands/create.ts +++ b/packages/cli/src/commands/create.ts @@ -32,7 +32,7 @@ type SupportedLangs = | SupportedPluginLangs; export interface CreateCommandOptions extends BaseCommandOptions { - outputDir?: string; + outputDir: string | false; }; export const create: Command = { @@ -59,8 +59,12 @@ export const create: Command = { ) .option("-v, --verbose", intlMsg.commands_common_options_verbose()) .option("-q, --quiet", intlMsg.commands_common_options_quiet()) - .action(async (language, name, options) => { - await run("wasm", language, name, options); + .action(async (language, name, options: Partial) => { + await run("wasm", language, name, { + outputDir: options.outputDir || false, + verbose: options.verbose || false, + quiet: options.quiet || false, + }); }); createCommand @@ -80,8 +84,12 @@ export const create: Command = { ) .option("-v, --verbose", intlMsg.commands_common_options_verbose()) .option("-q, --quiet", intlMsg.commands_common_options_quiet()) - .action(async (language, name, options) => { - await run("app", language, name, options); + .action(async (language, name, options: Partial) => { + await run("app", language, name, { + outputDir: options.outputDir || false, + verbose: options.verbose || false, + quiet: options.quiet || false, + }); }); createCommand @@ -101,8 +109,12 @@ export const create: Command = { ) .option("-v, --verbose", intlMsg.commands_common_options_verbose()) .option("-q, --quiet", intlMsg.commands_common_options_quiet()) - .action(async (language, name, options) => { - await run("plugin", language, name, options); + .action(async (language, name, options: Partial) => { + await run("plugin", language, name, { + outputDir: options.outputDir || false, + verbose: options.verbose || false, + quiet: options.quiet || false, + }); }); }, }; @@ -111,7 +123,7 @@ async function run( command: ProjectType, language: SupportedLangs, name: string, - options: CreateCommandOptions + options: Required ) { const { outputDir, verbose, quiet } = options; const logger = createLogger({ verbose, quiet }); diff --git a/packages/cli/src/commands/deploy.ts b/packages/cli/src/commands/deploy.ts index 26117401dc..7d1b8656b8 100644 --- a/packages/cli/src/commands/deploy.ts +++ b/packages/cli/src/commands/deploy.ts @@ -22,7 +22,7 @@ const pathStr = intlMsg.commands_deploy_options_o_path(); export interface DeployCommandOptions extends BaseCommandOptions { manifestFile: string; - outputFile?: string; + outputFile: string | false; }; type ManifestJob = DeployManifest["jobs"][number]; @@ -46,19 +46,21 @@ export const deploy: Command = { ) .option("-v, --verbose", intlMsg.commands_common_options_verbose()) .option("-q, --quiet", intlMsg.commands_common_options_quiet()) - .action(async (options) => { + .action(async (options: Partial) => { await run({ - ...options, manifestFile: parseManifestFileOption( options.manifestFile, defaultPolywrapManifest ), + outputFile: options.outputFile || false, + verbose: options.verbose || false, + quiet: options.quiet || false }); }); }, }; -async function run(options: DeployCommandOptions): Promise { +async function run(options: Required): Promise { const { manifestFile, outputFile, verbose, quiet } = options; const logger = createLogger({ verbose, quiet }); diff --git a/packages/cli/src/commands/docgen.ts b/packages/cli/src/commands/docgen.ts index f8a16dabfc..3dcfdc77ed 100644 --- a/packages/cli/src/commands/docgen.ts +++ b/packages/cli/src/commands/docgen.ts @@ -38,7 +38,7 @@ export enum DocgenActions { export interface DocgenCommandOptions extends BaseCommandOptions { manifestFile: string; docgenDir: string; - clientConfig: string; + clientConfig: string | false; imports: boolean; }; @@ -91,20 +91,23 @@ export const docgen: Command = { .option(`-i, --imports`, `${intlMsg.commands_docgen_options_i()}`) .option("-v, --verbose", intlMsg.commands_common_options_verbose()) .option("-q, --quiet", intlMsg.commands_common_options_quiet()) - .action(async (action, options) => { + .action(async (action, options: Partial) => { await run(action, { - ...options, manifestFile: parseManifestFileOption( options.manifestFile, defaultProjectManifestFiles ), docgenDir: parseDirOption(options.docgenDir, defaultDocgenDir), + clientConfig: options.clientConfig || false, + imports: options.imports || false, + verbose: options.verbose || false, + quiet: options.quiet || false, }); }); }, }; -async function run(action: DocgenActions, options: DocgenCommandOptions) { +async function run(action: DocgenActions, options: Required) { const { manifestFile, docgenDir, diff --git a/packages/cli/src/commands/infra.ts b/packages/cli/src/commands/infra.ts index 0031d0e9b3..1bf66aa871 100644 --- a/packages/cli/src/commands/infra.ts +++ b/packages/cli/src/commands/infra.ts @@ -23,8 +23,8 @@ export enum InfraActions { } export interface InfraCommandOptions extends BaseCommandOptions { - manifestFile: string; - modules?: string[]; + manifestFile: string | false; + modules: string[] | false; }; const DEFAULT_MODULES_PATH = path.join( @@ -77,8 +77,13 @@ export const infra: Command = { ) .option("-v, --verbose", intlMsg.commands_common_options_verbose()) .option("-q, --quiet", intlMsg.commands_common_options_quiet()) - .action(async (action, options) => { - await run(action, options); + .action(async (action, options: Partial) => { + await run(action, { + manifestFile: options.manifestFile || false, + modules: options.modules || false, + verbose: options.verbose || false, + quiet: options.quiet || false + }); }); }, }; @@ -93,13 +98,13 @@ Example: 'polywrap infra up --modules=eth-ens-ipfs'.`; async function run( action: InfraActions, - options: InfraCommandOptions + options: Required ): Promise { const { modules, verbose, quiet, manifestFile } = options; const logger = createLogger({ verbose, quiet }); - const modulesArray: string[] = modules ?? []; + const modulesArray: string[] = modules ? modules : []; const manifest: string[] = manifestFile ? [manifestFile] diff --git a/packages/cli/src/commands/manifest.ts b/packages/cli/src/commands/manifest.ts index c0d8222796..723ae41e42 100644 --- a/packages/cli/src/commands/manifest.ts +++ b/packages/cli/src/commands/manifest.ts @@ -78,12 +78,12 @@ export type ManifestType = typeof manifestTypes[number]; export interface ManifestSchemaCommandOptions extends BaseCommandOptions { raw: boolean; - manifestFile: ManifestType; + manifestFile: string | false; }; export interface ManifestMigrateCommandOptions extends BaseCommandOptions { - manifestFile: string; - format: string; + manifestFile: string | false; + format: string | false; }; export const manifest: Command = { @@ -108,8 +108,7 @@ export const manifest: Command = { ) .option( `-r, --raw`, - intlMsg.commands_manifest_command_s_option_r(), - false + intlMsg.commands_manifest_command_s_option_r() ) .option( `-m, --manifest-file <${pathStr}>`, @@ -119,8 +118,13 @@ export const manifest: Command = { ) .option("-v, --verbose", intlMsg.commands_common_options_verbose()) .option("-q, --quiet", intlMsg.commands_common_options_quiet()) - .action(async (type, options) => { - await runSchemaCommand(type, options); + .action(async (type, options: Partial) => { + await runSchemaCommand(type, { + raw: options.raw || false, + manifestFile: options.manifestFile || false, + verbose: options.verbose || false, + quiet: options.quiet || false + }); }); manifestCommand @@ -148,15 +152,20 @@ export const manifest: Command = { ) .option("-v, --verbose", intlMsg.commands_common_options_verbose()) .option("-q, --quiet", intlMsg.commands_common_options_quiet()) - .action(async (type, options) => { - await runMigrateCommand(type, options); + .action(async (type, options: Partial) => { + await runMigrateCommand(type, { + manifestFile: options.manifestFile || false, + format: options.format || false, + verbose: options.verbose || false, + quiet: options.quiet || false + }); }); }, }; export const runSchemaCommand = async ( type: ManifestType, - options: ManifestSchemaCommandOptions + options: Required ): Promise => { const { verbose, quiet } = options; const logger = createLogger({ verbose, quiet }); @@ -364,7 +373,7 @@ export const runSchemaCommand = async ( const runMigrateCommand = async ( type: ManifestType, - options: ManifestMigrateCommandOptions + options: Required ) => { const { verbose, quiet } = options; const logger = createLogger({ verbose, quiet }); @@ -399,7 +408,7 @@ const runMigrateCommand = async ( return migrateManifestFile( manifestFile, migratePolywrapProjectManifest, - options.format ?? latestPolywrapManifestFormat, + options.format || latestPolywrapManifestFormat, logger ); } else if (isAppManifestLanguage(language)) { @@ -411,7 +420,7 @@ const runMigrateCommand = async ( return migrateManifestFile( manifestFile, migrateAppProjectManifest, - options.format ?? latestPolywrapManifestFormat, + options.format || latestPolywrapManifestFormat, logger ); } else if (isPluginManifestLanguage(language)) { @@ -423,7 +432,7 @@ const runMigrateCommand = async ( return migrateManifestFile( manifestFile, migratePluginProjectManifest, - options.format ?? latestPolywrapManifestFormat, + options.format || latestPolywrapManifestFormat, logger ); } @@ -441,7 +450,7 @@ const runMigrateCommand = async ( migrateManifestFile( parseManifestFileOption(options.manifestFile, defaultBuildManifest), migrateBuildExtensionManifest, - options.format ?? latestBuildManifestFormat, + options.format || latestBuildManifestFormat, logger ); break; @@ -455,7 +464,7 @@ const runMigrateCommand = async ( migrateManifestFile( parseManifestFileOption(options.manifestFile, defaultMetaManifest), migrateMetaExtensionManifest, - options.format ?? latestMetaManifestFormat, + options.format || latestMetaManifestFormat, logger ); break; @@ -469,7 +478,7 @@ const runMigrateCommand = async ( migrateManifestFile( parseManifestFileOption(options.manifestFile, defaultDeployManifest), migrateDeployExtensionManifest, - options.format ?? latestDeployManifestFormat, + options.format || latestDeployManifestFormat, logger ); break; @@ -483,7 +492,7 @@ const runMigrateCommand = async ( migrateManifestFile( parseManifestFileOption(options.manifestFile, defaultInfraManifest), migrateInfraExtensionManifest, - options.format ?? latestInfraManifestFormat, + options.format || latestInfraManifestFormat, logger ); break; @@ -497,7 +506,7 @@ const runMigrateCommand = async ( migrateManifestFile( parseManifestFileOption(options.manifestFile, defaultWorkflowManifest), migrateWorkflow, - options.format ?? latestPolywrapWorkflowFormat, + options.format || latestPolywrapWorkflowFormat, logger ); break; @@ -572,7 +581,7 @@ function maybeFailOnUnsupportedManifestFormat( } function maybeFailOnUnsupportedTargetFormat( - format: string | undefined, + format: string | undefined | false, formats: string[], logger: Logger ) { diff --git a/packages/cli/src/commands/run.ts b/packages/cli/src/commands/run.ts index 062e65e9ca..378e62a9a2 100644 --- a/packages/cli/src/commands/run.ts +++ b/packages/cli/src/commands/run.ts @@ -24,11 +24,10 @@ import yaml from "yaml"; import fs from "fs"; export interface RunCommandOptions extends BaseCommandOptions { - clientConfig: string; + clientConfig: string | false; manifestFile: string; - jobs?: string[]; - validationScript?: string; - outputFile?: string; + jobs: string[] | false; + outputFile: string | false; }; const defaultManifestStr = defaultWorkflowManifest.join(" | "); @@ -60,22 +59,25 @@ export const run: Command = { ) .option("-v, --verbose", intlMsg.commands_common_options_verbose()) .option("-q, --quiet", intlMsg.commands_common_options_quiet()) - .action(async (options) => { + .action(async (options: Partial) => { await _run({ - ...options, manifestFile: parseManifestFileOption( options.manifestFile, defaultWorkflowManifest ), + clientConfig: options.clientConfig || false, outputFile: options.outputFile ? parseWorkflowOutputFilePathOption(options.outputFile) - : undefined, + : false, + jobs: options.jobs || false, + verbose: options.verbose || false, + quiet: options.quiet || false }); }); }, }; -const _run = async (options: RunCommandOptions) => { +const _run = async (options: Required) => { const { manifestFile, clientConfig, @@ -118,7 +120,7 @@ const _run = async (options: RunCommandOptions) => { }; const jobRunner = new JobRunner(client, onExecution); - await jobRunner.run(workflow.jobs, jobs ?? Object.keys(workflow.jobs)); + await jobRunner.run(workflow.jobs, jobs || Object.keys(workflow.jobs)); if (outputFile) { const outputFileExt = path.extname(outputFile).substring(1); diff --git a/packages/cli/src/commands/types.ts b/packages/cli/src/commands/types.ts index 0101dc6b43..9efc7ecf5a 100644 --- a/packages/cli/src/commands/types.ts +++ b/packages/cli/src/commands/types.ts @@ -8,8 +8,8 @@ export interface Command { } export interface BaseCommandOptions { - verbose?: boolean; - quiet?: boolean; + verbose: boolean; + quiet: boolean; } export interface CommandTypes { diff --git a/packages/cli/src/lib/option-parsers/client-config.ts b/packages/cli/src/lib/option-parsers/client-config.ts index 0f3f464d03..4a73e07940 100644 --- a/packages/cli/src/lib/option-parsers/client-config.ts +++ b/packages/cli/src/lib/option-parsers/client-config.ts @@ -7,7 +7,7 @@ import { PolywrapClientConfig } from "@polywrap/client-js"; import path from "path"; export async function parseClientConfigOption( - clientConfig: string | undefined + clientConfig: string | undefined | false ): Promise> { let finalClientConfig: Partial; diff --git a/packages/cli/src/lib/option-parsers/codegen.ts b/packages/cli/src/lib/option-parsers/codegen.ts index 4adf2c617a..07332b1a47 100644 --- a/packages/cli/src/lib/option-parsers/codegen.ts +++ b/packages/cli/src/lib/option-parsers/codegen.ts @@ -1,7 +1,7 @@ import path from "path"; export function parseCodegenScriptOption( - script: string | undefined -): string | undefined { - return script ? path.resolve(script) : undefined; + script: string | undefined | false +): string | false { + return script ? path.resolve(script) : false; } diff --git a/packages/cli/src/lib/option-parsers/manifestFile.ts b/packages/cli/src/lib/option-parsers/manifestFile.ts index 00eceaa262..bf22c4b45b 100644 --- a/packages/cli/src/lib/option-parsers/manifestFile.ts +++ b/packages/cli/src/lib/option-parsers/manifestFile.ts @@ -10,11 +10,11 @@ const deprecatedDefaultManifests = [ ]; export function parseManifestFileOption( - manifestFile: string | undefined, + manifestFile: string | undefined | false, defaults: string[] ): string { const didUserProvideManifestFile = - manifestFile != undefined && !!manifestFile.length; + manifestFile && !!manifestFile.length; const manifestPaths = manifestFile ? [manifestFile as string] : defaults; diff --git a/packages/js/cli-api/src/commands.ts b/packages/js/cli-api/src/commands.ts index d424f53fae..1acabf7540 100644 --- a/packages/js/cli-api/src/commands.ts +++ b/packages/js/cli-api/src/commands.ts @@ -127,7 +127,7 @@ export const commands: CommandFns = { // x clean up templates // x remove argument-as-options // x make all options optional -// - make all options required in run functions +// x make all options required in run functions // - make all option structs serializable function toKebabCase(camelCase: string): string { From e4c3fc6324717a4cc7b5e8092c44817a335dcf6e Mon Sep 17 00:00:00 2001 From: dOrgJelli Date: Fri, 21 Oct 2022 12:38:21 +0200 Subject: [PATCH 12/38] ensure all option prop types are serializable --- packages/cli/src/commands/build.ts | 6 +++--- packages/cli/src/commands/types.ts | 3 +++ packages/js/cli-api/src/commands.ts | 9 +-------- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/packages/cli/src/commands/build.ts b/packages/cli/src/commands/build.ts index d6a36a20d2..1af9fab035 100644 --- a/packages/cli/src/commands/build.ts +++ b/packages/cli/src/commands/build.ts @@ -36,9 +36,9 @@ const pathStr = intlMsg.commands_build_options_o_path(); export interface BuildCommandOptions extends BaseCommandOptions { manifestFile: string; outputDir: string; - clientConfig?: string | false; - skipCodegen?: boolean; - watch?: boolean; + clientConfig: string | false; + skipCodegen: boolean; + watch: boolean; strategy: SupportedStrategies; }; diff --git a/packages/cli/src/commands/types.ts b/packages/cli/src/commands/types.ts index 9efc7ecf5a..8e73967e02 100644 --- a/packages/cli/src/commands/types.ts +++ b/packages/cli/src/commands/types.ts @@ -7,9 +7,12 @@ export interface Command { setup: (program: Program) => MaybeAsync; } +type SerializableOption = string | number | boolean; + export interface BaseCommandOptions { verbose: boolean; quiet: boolean; + [prop: string]: SerializableOption | SerializableOption[]; } export interface CommandTypes { diff --git a/packages/js/cli-api/src/commands.ts b/packages/js/cli-api/src/commands.ts index 1acabf7540..7e34e2389b 100644 --- a/packages/js/cli-api/src/commands.ts +++ b/packages/js/cli-api/src/commands.ts @@ -123,13 +123,6 @@ export const commands: CommandFns = { run: execCommandFn("run"), }; -// TODO: -// x clean up templates -// x remove argument-as-options -// x make all options optional -// x make all options required in run functions -// - make all option structs serializable - function toKebabCase(camelCase: string): string { return camelCase.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(); } @@ -142,7 +135,7 @@ function parseValue(value: string | string[] | boolean): string { } function parseOptions( - options?: TOptions + options?: Partial ): string[] { const parsed: string[] = []; if (options) { From 0b45580d26d2365b39124ef525e8632b4d98a3e4 Mon Sep 17 00:00:00 2001 From: dOrgJelli Date: Fri, 21 Oct 2022 12:44:34 +0200 Subject: [PATCH 13/38] chore: rename js/cli-api to js/cli --- packages/js/{cli-api => cli}/README.md | 0 packages/js/{cli-api => cli}/jest.config.js | 0 packages/js/{cli-api => cli}/package.json | 0 packages/js/{cli-api => cli}/src/__tests__/awaitResponse.test.ts | 0 packages/js/{cli-api => cli}/src/__tests__/cli-js.test.ts | 0 .../src/__tests__/wrapper/local-ipfs-node/docker-compose.yaml | 0 .../src/__tests__/wrapper/local-ipfs-node/ipfs/Dockerfile | 0 .../src/__tests__/wrapper/local-ipfs-node/ipfs/config_ipfs | 0 .../src/__tests__/wrapper/local-ipfs-node/ipfs/start_ipfs | 0 packages/js/{cli-api => cli}/src/__tests__/wrapper/package.json | 0 .../js/{cli-api => cli}/src/__tests__/wrapper/polywrap.build.yaml | 0 .../{cli-api => cli}/src/__tests__/wrapper/polywrap.deploy.yaml | 0 .../js/{cli-api => cli}/src/__tests__/wrapper/polywrap.infra.yaml | 0 packages/js/{cli-api => cli}/src/__tests__/wrapper/polywrap.yaml | 0 packages/js/{cli-api => cli}/src/__tests__/wrapper/src/index.ts | 0 .../js/{cli-api => cli}/src/__tests__/wrapper/src/schema.graphql | 0 packages/js/{cli-api => cli}/src/awaitResponse.ts | 0 packages/js/{cli-api => cli}/src/commands.ts | 0 packages/js/{cli-api => cli}/src/declarations.d.ts | 0 packages/js/{cli-api => cli}/src/index.ts | 0 packages/js/{cli-api => cli}/src/run-cli.ts | 0 packages/js/{cli-api => cli}/tsconfig.build.json | 0 packages/js/{cli-api => cli}/tsconfig.json | 0 23 files changed, 0 insertions(+), 0 deletions(-) rename packages/js/{cli-api => cli}/README.md (100%) rename packages/js/{cli-api => cli}/jest.config.js (100%) rename packages/js/{cli-api => cli}/package.json (100%) rename packages/js/{cli-api => cli}/src/__tests__/awaitResponse.test.ts (100%) rename packages/js/{cli-api => cli}/src/__tests__/cli-js.test.ts (100%) rename packages/js/{cli-api => cli}/src/__tests__/wrapper/local-ipfs-node/docker-compose.yaml (100%) rename packages/js/{cli-api => cli}/src/__tests__/wrapper/local-ipfs-node/ipfs/Dockerfile (100%) rename packages/js/{cli-api => cli}/src/__tests__/wrapper/local-ipfs-node/ipfs/config_ipfs (100%) rename packages/js/{cli-api => cli}/src/__tests__/wrapper/local-ipfs-node/ipfs/start_ipfs (100%) rename packages/js/{cli-api => cli}/src/__tests__/wrapper/package.json (100%) rename packages/js/{cli-api => cli}/src/__tests__/wrapper/polywrap.build.yaml (100%) rename packages/js/{cli-api => cli}/src/__tests__/wrapper/polywrap.deploy.yaml (100%) rename packages/js/{cli-api => cli}/src/__tests__/wrapper/polywrap.infra.yaml (100%) rename packages/js/{cli-api => cli}/src/__tests__/wrapper/polywrap.yaml (100%) rename packages/js/{cli-api => cli}/src/__tests__/wrapper/src/index.ts (100%) rename packages/js/{cli-api => cli}/src/__tests__/wrapper/src/schema.graphql (100%) rename packages/js/{cli-api => cli}/src/awaitResponse.ts (100%) rename packages/js/{cli-api => cli}/src/commands.ts (100%) rename packages/js/{cli-api => cli}/src/declarations.d.ts (100%) rename packages/js/{cli-api => cli}/src/index.ts (100%) rename packages/js/{cli-api => cli}/src/run-cli.ts (100%) rename packages/js/{cli-api => cli}/tsconfig.build.json (100%) rename packages/js/{cli-api => cli}/tsconfig.json (100%) diff --git a/packages/js/cli-api/README.md b/packages/js/cli/README.md similarity index 100% rename from packages/js/cli-api/README.md rename to packages/js/cli/README.md diff --git a/packages/js/cli-api/jest.config.js b/packages/js/cli/jest.config.js similarity index 100% rename from packages/js/cli-api/jest.config.js rename to packages/js/cli/jest.config.js diff --git a/packages/js/cli-api/package.json b/packages/js/cli/package.json similarity index 100% rename from packages/js/cli-api/package.json rename to packages/js/cli/package.json diff --git a/packages/js/cli-api/src/__tests__/awaitResponse.test.ts b/packages/js/cli/src/__tests__/awaitResponse.test.ts similarity index 100% rename from packages/js/cli-api/src/__tests__/awaitResponse.test.ts rename to packages/js/cli/src/__tests__/awaitResponse.test.ts diff --git a/packages/js/cli-api/src/__tests__/cli-js.test.ts b/packages/js/cli/src/__tests__/cli-js.test.ts similarity index 100% rename from packages/js/cli-api/src/__tests__/cli-js.test.ts rename to packages/js/cli/src/__tests__/cli-js.test.ts diff --git a/packages/js/cli-api/src/__tests__/wrapper/local-ipfs-node/docker-compose.yaml b/packages/js/cli/src/__tests__/wrapper/local-ipfs-node/docker-compose.yaml similarity index 100% rename from packages/js/cli-api/src/__tests__/wrapper/local-ipfs-node/docker-compose.yaml rename to packages/js/cli/src/__tests__/wrapper/local-ipfs-node/docker-compose.yaml diff --git a/packages/js/cli-api/src/__tests__/wrapper/local-ipfs-node/ipfs/Dockerfile b/packages/js/cli/src/__tests__/wrapper/local-ipfs-node/ipfs/Dockerfile similarity index 100% rename from packages/js/cli-api/src/__tests__/wrapper/local-ipfs-node/ipfs/Dockerfile rename to packages/js/cli/src/__tests__/wrapper/local-ipfs-node/ipfs/Dockerfile diff --git a/packages/js/cli-api/src/__tests__/wrapper/local-ipfs-node/ipfs/config_ipfs b/packages/js/cli/src/__tests__/wrapper/local-ipfs-node/ipfs/config_ipfs similarity index 100% rename from packages/js/cli-api/src/__tests__/wrapper/local-ipfs-node/ipfs/config_ipfs rename to packages/js/cli/src/__tests__/wrapper/local-ipfs-node/ipfs/config_ipfs diff --git a/packages/js/cli-api/src/__tests__/wrapper/local-ipfs-node/ipfs/start_ipfs b/packages/js/cli/src/__tests__/wrapper/local-ipfs-node/ipfs/start_ipfs similarity index 100% rename from packages/js/cli-api/src/__tests__/wrapper/local-ipfs-node/ipfs/start_ipfs rename to packages/js/cli/src/__tests__/wrapper/local-ipfs-node/ipfs/start_ipfs diff --git a/packages/js/cli-api/src/__tests__/wrapper/package.json b/packages/js/cli/src/__tests__/wrapper/package.json similarity index 100% rename from packages/js/cli-api/src/__tests__/wrapper/package.json rename to packages/js/cli/src/__tests__/wrapper/package.json diff --git a/packages/js/cli-api/src/__tests__/wrapper/polywrap.build.yaml b/packages/js/cli/src/__tests__/wrapper/polywrap.build.yaml similarity index 100% rename from packages/js/cli-api/src/__tests__/wrapper/polywrap.build.yaml rename to packages/js/cli/src/__tests__/wrapper/polywrap.build.yaml diff --git a/packages/js/cli-api/src/__tests__/wrapper/polywrap.deploy.yaml b/packages/js/cli/src/__tests__/wrapper/polywrap.deploy.yaml similarity index 100% rename from packages/js/cli-api/src/__tests__/wrapper/polywrap.deploy.yaml rename to packages/js/cli/src/__tests__/wrapper/polywrap.deploy.yaml diff --git a/packages/js/cli-api/src/__tests__/wrapper/polywrap.infra.yaml b/packages/js/cli/src/__tests__/wrapper/polywrap.infra.yaml similarity index 100% rename from packages/js/cli-api/src/__tests__/wrapper/polywrap.infra.yaml rename to packages/js/cli/src/__tests__/wrapper/polywrap.infra.yaml diff --git a/packages/js/cli-api/src/__tests__/wrapper/polywrap.yaml b/packages/js/cli/src/__tests__/wrapper/polywrap.yaml similarity index 100% rename from packages/js/cli-api/src/__tests__/wrapper/polywrap.yaml rename to packages/js/cli/src/__tests__/wrapper/polywrap.yaml diff --git a/packages/js/cli-api/src/__tests__/wrapper/src/index.ts b/packages/js/cli/src/__tests__/wrapper/src/index.ts similarity index 100% rename from packages/js/cli-api/src/__tests__/wrapper/src/index.ts rename to packages/js/cli/src/__tests__/wrapper/src/index.ts diff --git a/packages/js/cli-api/src/__tests__/wrapper/src/schema.graphql b/packages/js/cli/src/__tests__/wrapper/src/schema.graphql similarity index 100% rename from packages/js/cli-api/src/__tests__/wrapper/src/schema.graphql rename to packages/js/cli/src/__tests__/wrapper/src/schema.graphql diff --git a/packages/js/cli-api/src/awaitResponse.ts b/packages/js/cli/src/awaitResponse.ts similarity index 100% rename from packages/js/cli-api/src/awaitResponse.ts rename to packages/js/cli/src/awaitResponse.ts diff --git a/packages/js/cli-api/src/commands.ts b/packages/js/cli/src/commands.ts similarity index 100% rename from packages/js/cli-api/src/commands.ts rename to packages/js/cli/src/commands.ts diff --git a/packages/js/cli-api/src/declarations.d.ts b/packages/js/cli/src/declarations.d.ts similarity index 100% rename from packages/js/cli-api/src/declarations.d.ts rename to packages/js/cli/src/declarations.d.ts diff --git a/packages/js/cli-api/src/index.ts b/packages/js/cli/src/index.ts similarity index 100% rename from packages/js/cli-api/src/index.ts rename to packages/js/cli/src/index.ts diff --git a/packages/js/cli-api/src/run-cli.ts b/packages/js/cli/src/run-cli.ts similarity index 100% rename from packages/js/cli-api/src/run-cli.ts rename to packages/js/cli/src/run-cli.ts diff --git a/packages/js/cli-api/tsconfig.build.json b/packages/js/cli/tsconfig.build.json similarity index 100% rename from packages/js/cli-api/tsconfig.build.json rename to packages/js/cli/tsconfig.build.json diff --git a/packages/js/cli-api/tsconfig.json b/packages/js/cli/tsconfig.json similarity index 100% rename from packages/js/cli-api/tsconfig.json rename to packages/js/cli/tsconfig.json From f8aeedce4d4b257587dd042cd8f4be1e4f4cdcf1 Mon Sep 17 00:00:00 2001 From: dOrgJelli Date: Fri, 21 Oct 2022 17:25:23 +0200 Subject: [PATCH 14/38] feat: JS based SDK for the Polywrap CLI --- package.json | 2 +- packages/cli/src/commands/build.ts | 2 +- packages/js/cli/README.md | 29 +- packages/js/cli/package.json | 1 - .../cli/src/__tests__/awaitResponse.test.ts | 38 --- packages/js/cli/src/__tests__/cli-js.test.ts | 92 ------ .../js/cli/src/__tests__/commands.spec.ts | 286 ++++++++++++++++++ .../local-ipfs-node/docker-compose.yaml | 8 - .../wrapper/local-ipfs-node/ipfs/Dockerfile | 4 - .../wrapper/local-ipfs-node/ipfs/config_ipfs | 4 - .../wrapper/local-ipfs-node/ipfs/start_ipfs | 58 ---- .../js/cli/src/__tests__/wrapper/package.json | 8 - .../src/__tests__/wrapper/polywrap.build.yaml | 6 - .../__tests__/wrapper/polywrap.deploy.yaml | 7 - .../src/__tests__/wrapper/polywrap.infra.yaml | 4 - .../cli/src/__tests__/wrapper/polywrap.yaml | 10 - .../js/cli/src/__tests__/wrapper/src/index.ts | 5 - .../src/__tests__/wrapper/src/schema.graphql | 3 - packages/js/cli/src/awaitResponse.ts | 28 -- packages/js/cli/src/commands.ts | 149 --------- packages/js/cli/src/commands/exec.ts | 106 +++++++ packages/js/cli/src/commands/index.ts | 43 +++ packages/js/cli/src/index.ts | 3 +- packages/js/cli/src/run-cli.ts | 35 +-- .../cases/cli/manifest/samples/polywrap.yaml | 19 +- .../test/Module/index.ts | 7 + .../test/Module/serialization.ts | 98 ++++++ .../test/Module/wrapped.ts | 20 ++ .../001-sanity-assemblyscript/test/entry.ts | 38 +++ .../001-sanity-assemblyscript/test/index.ts | 6 + todo | 4 - 31 files changed, 647 insertions(+), 476 deletions(-) delete mode 100644 packages/js/cli/src/__tests__/awaitResponse.test.ts delete mode 100644 packages/js/cli/src/__tests__/cli-js.test.ts create mode 100644 packages/js/cli/src/__tests__/commands.spec.ts delete mode 100644 packages/js/cli/src/__tests__/wrapper/local-ipfs-node/docker-compose.yaml delete mode 100644 packages/js/cli/src/__tests__/wrapper/local-ipfs-node/ipfs/Dockerfile delete mode 100755 packages/js/cli/src/__tests__/wrapper/local-ipfs-node/ipfs/config_ipfs delete mode 100755 packages/js/cli/src/__tests__/wrapper/local-ipfs-node/ipfs/start_ipfs delete mode 100644 packages/js/cli/src/__tests__/wrapper/package.json delete mode 100644 packages/js/cli/src/__tests__/wrapper/polywrap.build.yaml delete mode 100644 packages/js/cli/src/__tests__/wrapper/polywrap.deploy.yaml delete mode 100644 packages/js/cli/src/__tests__/wrapper/polywrap.infra.yaml delete mode 100644 packages/js/cli/src/__tests__/wrapper/polywrap.yaml delete mode 100644 packages/js/cli/src/__tests__/wrapper/src/index.ts delete mode 100644 packages/js/cli/src/__tests__/wrapper/src/schema.graphql delete mode 100644 packages/js/cli/src/awaitResponse.ts delete mode 100644 packages/js/cli/src/commands.ts create mode 100644 packages/js/cli/src/commands/exec.ts create mode 100644 packages/js/cli/src/commands/index.ts create mode 100644 packages/test-cases/cases/cli/wasm/codegen/001-sanity-assemblyscript/test/Module/index.ts create mode 100644 packages/test-cases/cases/cli/wasm/codegen/001-sanity-assemblyscript/test/Module/serialization.ts create mode 100644 packages/test-cases/cases/cli/wasm/codegen/001-sanity-assemblyscript/test/Module/wrapped.ts create mode 100644 packages/test-cases/cases/cli/wasm/codegen/001-sanity-assemblyscript/test/entry.ts create mode 100644 packages/test-cases/cases/cli/wasm/codegen/001-sanity-assemblyscript/test/index.ts delete mode 100644 todo diff --git a/package.json b/package.json index 9b1625fd50..822edf832f 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "build:config": "lerna run build --scope @polywrap/client-config-builder-js", "build:client": "lerna run build --scope @polywrap/client-js --scope @polywrap/react", "build:test-env": "lerna run build --scope @polywrap/test-env-js", - "build:cli": "lerna run build --scope polywrap", + "build:cli": "lerna run build --scope polywrap --scope @polywrap/cli-js", "link:interface:deps": "yarn link:manifests && yarn link:schema", "link:manifests": "yarn link:manifests:polywrap && yarn link:manifests:wrap", "link:manifests:polywrap": "cd packages/js/manifests/polywrap && (yarn unlink || true) && yarn link && cd ../../../../dependencies && yarn link @polywrap/polywrap-manifest-types-js && cd ../", diff --git a/packages/cli/src/commands/build.ts b/packages/cli/src/commands/build.ts index 1af9fab035..c8fe098237 100644 --- a/packages/cli/src/commands/build.ts +++ b/packages/cli/src/commands/build.ts @@ -39,7 +39,7 @@ export interface BuildCommandOptions extends BaseCommandOptions { clientConfig: string | false; skipCodegen: boolean; watch: boolean; - strategy: SupportedStrategies; + strategy: `${SupportedStrategies}`; }; export const build: Command = { diff --git a/packages/js/cli/README.md b/packages/js/cli/README.md index a5db385a07..5bb0cf8ef9 100644 --- a/packages/js/cli/README.md +++ b/packages/js/cli/README.md @@ -8,29 +8,22 @@ It allows user execute Polywrap CLI commands programmatically, with simple and t # Usage -Start infra and build a wrapper - +Build a wrapper: ``` typescript import { Commands } from "@polywrap/cli-js; -import path from "path"; - -// test wrapper in a test environment -export async function foo({ - // spin up infra modules defined in a polywrap.infra.yaml manifest - await Commands.infra({ verbose: true }); - - // wait for infra to be ready to go - await awaitResponse("http://localhost:5001"); - // get path to the wrapper - const wrapperPath: string = path.join(path.resolve(__dirname), ".."); +async function main() { + const wrapperPath = "/path/to/wrapper"; - // build current wrapper with CLI - await Commands.build(undefined, wrapperPath); + const res = await Commands.build( + { }, // build command options + { cwd: wrapperPath } + ); - // get invokable URI to the local wrapper build - const wrapperUri = `fs/${wrapperPath}/build`; -}); + console.log(res.stdout); + console.log(res.stderr); + console.log(res.exitCode); +} ``` # Reference diff --git a/packages/js/cli/package.json b/packages/js/cli/package.json index a32678c63b..9b0bb09252 100644 --- a/packages/js/cli/package.json +++ b/packages/js/cli/package.json @@ -18,7 +18,6 @@ "test:ci": "jest --passWithNoTests --runInBand --detectOpenHandles --verbose" }, "dependencies": { - "axios": "0.21.2", "polywrap": "0.9.2", "spawn-command": "0.0.2-1" }, diff --git a/packages/js/cli/src/__tests__/awaitResponse.test.ts b/packages/js/cli/src/__tests__/awaitResponse.test.ts deleted file mode 100644 index 952b09529e..0000000000 --- a/packages/js/cli/src/__tests__/awaitResponse.test.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { awaitResponse, runCLI } from "../../"; - -import path from "path"; - -jest.setTimeout(60_000); - -describe("awaitResponse", () => { - - const localIpfsNode = "http://localhost:5001"; - const wrapperPath = path.resolve(path.join(__dirname, "wrapper")); - - afterAll(async () => { - await runCLI({ - args: ["infra", "down"], - cwd: wrapperPath, - }); - }); - - it("returns false when infra is unavailable", async () => { - const isInfraUp = await awaitResponse(localIpfsNode); - expect(isInfraUp).toBeFalsy(); - }); - - it("returns true when infra is available", async () => { - await runCLI({ - args: ["infra", "up", "--verbose"], - cwd: wrapperPath, - }); - - const isInfraUp = await awaitResponse(localIpfsNode); - expect(isInfraUp).toBeTruthy(); - - await runCLI({ - args: ["infra", "down", "--verbose"], - cwd: wrapperPath, - }); - }); -}); \ No newline at end of file diff --git a/packages/js/cli/src/__tests__/cli-js.test.ts b/packages/js/cli/src/__tests__/cli-js.test.ts deleted file mode 100644 index f3ced7a569..0000000000 --- a/packages/js/cli/src/__tests__/cli-js.test.ts +++ /dev/null @@ -1,92 +0,0 @@ -import { awaitResponse, Commands, runCLI } from "../../"; -import { SupportedStrategies } from "polywrap"; - -import path from "path"; -import fs from "fs"; - -jest.setTimeout(300_000); - -describe("cli-js tests", () => { - - const localIpfsNode = "http://localhost:5001"; - const wrapperPath = path.resolve(path.join(__dirname, "wrapper")); - - afterAll(async () => { - await runCLI({ - args: ["infra", "down"], - cwd: wrapperPath, - }); - }); - - it("build", async () => { - // clear build dir - const buildDir = path.join(wrapperPath, "build"); - if (fs.existsSync(buildDir)) { - fs.rmSync(buildDir, { recursive: true }); - } - expect(fs.existsSync(buildDir)).toBeFalsy(); - - // build - await Commands.build({ - strategy: SupportedStrategies.IMAGE - }, wrapperPath); - - // check for build dir and artifacts - const wasmPath = path.join(buildDir, "wrap.wasm"); - const manifestPath = path.join(buildDir, "wrap.info"); - expect(fs.existsSync(buildDir)).toBeTruthy(); - expect(fs.existsSync(wasmPath)).toBeTruthy(); - expect(fs.existsSync(manifestPath)).toBeTruthy(); - }); - - it("codegen", async () => { - // clear wrap dir - const wrapDir = path.join(wrapperPath, "src", "wrap"); - if (fs.existsSync(wrapDir)) { - fs.rmSync(wrapDir, { recursive: true }); - } - expect(fs.existsSync(wrapDir)).toBeFalsy(); - - // codegen - await Commands.codegen(undefined, wrapperPath); - - // check output - expect(fs.existsSync(wrapDir)).toBeTruthy(); - }); - - it("infra", async () => { - // start infra - await Commands.infra({ action: InfraActions.UP, verbose: true }, wrapperPath); - const isInfraUp = await awaitResponse(localIpfsNode); - expect(isInfraUp).toBeTruthy(); - - // stop infra - await Commands.infra({ action: InfraActions.DOWN, verbose: true }, wrapperPath); - await new Promise((r) => setTimeout(r, 5000)); - const isInfraStillUp = await awaitResponse(localIpfsNode); - expect(isInfraStillUp).toBeFalsy(); - }); - - it("deploy", async () => { - // start infra - await Commands.infra({ action: InfraActions.UP }, wrapperPath); - const isInfraUp = await awaitResponse(localIpfsNode); - expect(isInfraUp).toBeTruthy(); - - // clear output - const outputFile = path.join(wrapperPath, "ipfs.json"); - if (fs.existsSync(outputFile)) { - fs.rmSync(outputFile); - } - expect(fs.existsSync(outputFile)).toBeFalsy(); - - // deploy wrapper - await Commands.deploy({ outputFile }, wrapperPath); - - // check output - expect(fs.existsSync(outputFile)).toBeTruthy(); - - // stop infra - await Commands.infra({ action: InfraActions.DOWN }, wrapperPath); - }); -}); \ No newline at end of file diff --git a/packages/js/cli/src/__tests__/commands.spec.ts b/packages/js/cli/src/__tests__/commands.spec.ts new file mode 100644 index 0000000000..7afb7a8d40 --- /dev/null +++ b/packages/js/cli/src/__tests__/commands.spec.ts @@ -0,0 +1,286 @@ +import { Commands, CliConfig } from "../../"; + +import { + CommandTypes, + CommandTypings, + CommandTypeMapping, + BaseCommandOptions, +} from "polywrap"; +import { + initTestEnvironment, + stopTestEnvironment, + ensAddresses, + providers +} from "@polywrap/test-env-js"; +import { GetPathToCliTestFiles } from "@polywrap/test-cases"; +import fs from "fs"; +import os from "os"; +import path from "path"; + +jest.setTimeout(300_000); + +type CommandTestCase = CliConfig & { + options?: Partial; + before?: (test: CommandTestCase) => Promise | void; + after: ( + test: CommandTestCase, + stdout: string, + stderr: string, + exitCode: number + ) => Promise | void; +}; + +type CommandTestCases = CommandTestCase[]; + +type CommandTestCasesWithArgs = + (CommandTestCase & + { arguments: TArgs; })[]; + +type CommandTestCaseData< + TCommands +> = Required<{ + [Command in keyof TCommands]: + TCommands[Command] extends BaseCommandOptions ? + CommandTestCases : + TCommands[Command] extends CommandTypes ? + CommandTestCasesWithArgs : + TCommands[Command] extends CommandTypeMapping ? + CommandTestCaseData : never; +}>; + +const clearDir = (dir: string) => { + if (fs.existsSync(dir)) { + fs.rmSync(dir, { recursive: true }); + } + expect(fs.existsSync(dir)).toBeFalsy(); +} + +const testData: CommandTestCaseData = { + build: [{ + options: { strategy: "vm" }, + cwd: path.join(GetPathToCliTestFiles(), "wasm/build-cmd/assemblyscript/001-sanity"), + before: (test) => { + // clear build dir + if (!test.cwd) throw Error("This shouldn't happen"); + clearDir(path.join(test.cwd, "build")); + }, + after: (test) => { + // check for build dir and artifacts + if (!test.cwd) throw Error("This shouldn't happen"); + const buildDir = path.join(test.cwd, "build"); + const wasmPath = path.join(buildDir, "wrap.wasm"); + const manifestPath = path.join(buildDir, "wrap.info"); + expect(fs.existsSync(buildDir)).toBeTruthy(); + expect(fs.existsSync(wasmPath)).toBeTruthy(); + expect(fs.existsSync(manifestPath)).toBeTruthy(); + } + }], + codegen: [{ + options: { codegenDir: "./test" }, + cwd: path.join(GetPathToCliTestFiles(), "wasm/codegen/001-sanity-assemblyscript"), + before: (test) => { + // clear build dir + if (!test.cwd || !test.options?.codegenDir) + throw Error("This shouldn't happen"); + const outputDir = path.join(test.cwd, test.options?.codegenDir); + clearDir(outputDir); + }, + after: (test) => { + // check for build dir and artifacts + if (!test.cwd || !test.options?.codegenDir) + throw Error("This shouldn't happen"); + const outputDir = path.join(test.cwd, test.options?.codegenDir); + expect(fs.existsSync(outputDir)).toBeTruthy(); + } + }], + create: { + app: [{ + cwd: fs.mkdtempSync(path.join(os.tmpdir(), "cli-js-create-test")), + arguments: ["typescript-node", "test-app"], + after: (test) => { + if (!test.cwd) + throw Error("This shouldn't happen"); + const outputDir = path.join(test.cwd, "test-app"); + const packagePath = path.join(outputDir, "package.json"); + expect(fs.existsSync(outputDir)).toBeTruthy(); + expect(fs.existsSync(packagePath)).toBeTruthy(); + clearDir(test.cwd); + } + }], + plugin: [{ + cwd: fs.mkdtempSync(path.join(os.tmpdir(), "cli-js-create-test")), + arguments: ["typescript", "test-plugin"], + after: (test) => { + if (!test.cwd) + throw Error("This shouldn't happen"); + const outputDir = path.join(test.cwd, "test-plugin"); + const packagePath = path.join(outputDir, "package.json"); + expect(fs.existsSync(outputDir)).toBeTruthy(); + expect(fs.existsSync(packagePath)).toBeTruthy(); + clearDir(test.cwd); + } + }], + wasm: [{ + cwd: fs.mkdtempSync(path.join(os.tmpdir(), "cli-js-create-test")), + arguments: ["rust", "test-wasm"], + after: (test, stdout, stderr, exitCode) => { + if (!test.cwd) + throw Error("This shouldn't happen"); + const outputDir = path.join(test.cwd, "test-wasm"); + const packagePath = path.join(outputDir, "Cargo.toml"); + expect(fs.existsSync(outputDir)).toBeTruthy(); + expect(fs.existsSync(packagePath)).toBeTruthy(); + clearDir(test.cwd); + } + }] + }, + deploy: [{ + cwd: path.join(GetPathToCliTestFiles(), "wasm/deploy/001-sanity"), + env: { + PATH: process.env.PATH || "", + IPFS_GATEWAY_URI: providers.ipfs, + DOMAIN_NAME: "test1.eth", + ENS_REG_ADDR: ensAddresses.ensAddress, + ENS_REGISTRAR_ADDR: ensAddresses.registrarAddress, + ENS_RESOLVER_ADDR: ensAddresses.resolverAddress, + }, + before: async () => { + await stopTestEnvironment(); + await initTestEnvironment(); + + // Wait a little longer just in case + await new Promise((resolve) => setTimeout(resolve, 3000)); + }, + after: async (_, stdout) => { + expect(stdout).toContain( + "Successfully executed" + ); + await stopTestEnvironment(); + } + }], + docgen: [{ + cwd: path.join(GetPathToCliTestFiles(), "docgen", "001-sanity"), + arguments: ["docusaurus"], + after: (_, stdout) => { + expect(stdout).toContain("Docs were generated successfully"); + } + }], + infra: [{ + cwd: path.join(GetPathToCliTestFiles(), "infra/001-sanity"), + env: { + PATH: process.env.PATH || "", + ENV_IPFS_PORT: "5001", + }, + arguments: ["config"], + after: (_, stdout) => { + expect(stdout).toContain("services:"); + } + }], + manifest: { + migrate: [{ + cwd: path.join(GetPathToCliTestFiles(), "manifest/samples"), + arguments: ["project"], + after: (_, stdout) => { + expect(stdout).toContain("Migrating polywrap.yaml to version"); + } + }], + schema: [{ + cwd: path.join(GetPathToCliTestFiles(), "manifest/samples"), + arguments: ["build"], + after: (_, stdout) => { + expect(stdout).toContain("format: "); + } + }] + }, + run: [{ + cwd: path.join(GetPathToCliTestFiles(), "run/001-yaml-workflow"), + before: async (test) => { + if (!test.cwd) + throw Error("This shouldn't happen"); + const wrapperPath = path.join(test.cwd, "../run-test-wrapper"); + await Commands.build(undefined, { cwd: wrapperPath }); + }, + after: (_, stdout, __, exitCode) => { + expect(stdout).toContain("Data: "); + expect(exitCode).toBe(0); + } + }] +}; + +describe("Commands", () => { + const resolvePropPath = (props: string[], obj: any) => { + let resolved = obj; + for (const prop of props) { + if (!resolved) { + return undefined; + } + resolved = resolved[prop]; + } + return resolved; + } + + const runCommandTests = (props: string[]) => { + const command = resolvePropPath(props, Commands); + + if (!command) { + throw Error(`Invalid command path: ${props.join(".")}`); + } + + if ( + typeof command !== "function" && + typeof command === "object" + ) { + for (const prop of Object.keys(command)) { + runCommandTests([...props, prop]); + } + } + + describe(props.join("."), () => { + const tests = + resolvePropPath(props, testData) as + CommandTestCasesWithArgs; + + if (!tests) { + throw Error(`Test data for Commands.${props.join(".")} not defined.`); + } + + for (let i = 0; i < tests.length; ++i) { + let test = tests[i]; + + it(`test #${i}`, async () => { + let result: { + exitCode: number; + stdout: string; + stderr: string; + }; + const cliConfig = { + cwd: test.cwd, + cli: test.cli, + env: test.env + }; + + if (test.before) { + await test.before(test); + } + + if (test.arguments) { + result = await command(...test.arguments, test.options, cliConfig); + } else { + result = await command(test.options, cliConfig); + } + + await test.after( + test, + result.stdout, + result.stderr, + result.exitCode + ); + }); + } + }); + } + + for (const command of Object.keys(Commands)) { + runCommandTests([command]); + } +}); diff --git a/packages/js/cli/src/__tests__/wrapper/local-ipfs-node/docker-compose.yaml b/packages/js/cli/src/__tests__/wrapper/local-ipfs-node/docker-compose.yaml deleted file mode 100644 index fb5d495a6a..0000000000 --- a/packages/js/cli/src/__tests__/wrapper/local-ipfs-node/docker-compose.yaml +++ /dev/null @@ -1,8 +0,0 @@ -version: '3' -services: - ipfs: - build: ./ipfs - ports: - - '${IPFS_PORT:-5001}:5001' - - '8080:8080' - - '4001:4001' diff --git a/packages/js/cli/src/__tests__/wrapper/local-ipfs-node/ipfs/Dockerfile b/packages/js/cli/src/__tests__/wrapper/local-ipfs-node/ipfs/Dockerfile deleted file mode 100644 index 7a277d85f8..0000000000 --- a/packages/js/cli/src/__tests__/wrapper/local-ipfs-node/ipfs/Dockerfile +++ /dev/null @@ -1,4 +0,0 @@ -FROM ipfs/go-ipfs:v0.4.23 - -COPY ./start_ipfs /usr/local/bin -COPY ./config_ipfs /usr/local/bin diff --git a/packages/js/cli/src/__tests__/wrapper/local-ipfs-node/ipfs/config_ipfs b/packages/js/cli/src/__tests__/wrapper/local-ipfs-node/ipfs/config_ipfs deleted file mode 100755 index 0935f84c2d..0000000000 --- a/packages/js/cli/src/__tests__/wrapper/local-ipfs-node/ipfs/config_ipfs +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh - -ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin '["*"]' -ipfs config --json API.HTTPHeaders.Access-Control-Allow-Methods '["GET", "POST", "PUT", "DELETE"]' diff --git a/packages/js/cli/src/__tests__/wrapper/local-ipfs-node/ipfs/start_ipfs b/packages/js/cli/src/__tests__/wrapper/local-ipfs-node/ipfs/start_ipfs deleted file mode 100755 index f2ca2a2c07..0000000000 --- a/packages/js/cli/src/__tests__/wrapper/local-ipfs-node/ipfs/start_ipfs +++ /dev/null @@ -1,58 +0,0 @@ -#!/bin/sh -set -e -user=ipfs -repo="$IPFS_PATH" - -if [ `id -u` -eq 0 ]; then - echo "Changing user to $user" - # ensure folder is writable - su-exec "$user" test -w "$repo" || chown -R -- "$user" "$repo" - # restart script with new privileges - exec su-exec "$user" "$0" "$@" -fi - -# 2nd invocation with regular user -ipfs version - -if [ -e "$repo/config" ]; then - echo "Found IPFS fs-repo at $repo" -else - case "$IPFS_PROFILE" in - "") INIT_ARGS="" ;; - *) INIT_ARGS="--profile=$IPFS_PROFILE" ;; - esac - ipfs init $INIT_ARGS - ipfs config Addresses.API /ip4/0.0.0.0/tcp/5001 - ipfs config Addresses.Gateway /ip4/0.0.0.0/tcp/8080 - - # Set up the swarm key, if provided - - SWARM_KEY_FILE="$repo/swarm.key" - SWARM_KEY_PERM=0400 - - # Create a swarm key from a given environment variable - if [ ! -z "$IPFS_SWARM_KEY" ] ; then - echo "Copying swarm key from variable..." - echo -e "$IPFS_SWARM_KEY" >"$SWARM_KEY_FILE" || exit 1 - chmod $SWARM_KEY_PERM "$SWARM_KEY_FILE" - fi - - # Unset the swarm key variable - unset IPFS_SWARM_KEY - - # Check during initialization if a swarm key was provided and - # copy it to the ipfs directory with the right permissions - # WARNING: This will replace the swarm key if it exists - if [ ! -z "$IPFS_SWARM_KEY_FILE" ] ; then - echo "Copying swarm key from file..." - install -m $SWARM_KEY_PERM "$IPFS_SWARM_KEY_FILE" "$SWARM_KEY_FILE" || exit 1 - fi - - # Unset the swarm key file variable - unset IPFS_SWARM_KEY_FILE - -fi - -$(dirname $0)/config_ipfs - -exec ipfs "$@" diff --git a/packages/js/cli/src/__tests__/wrapper/package.json b/packages/js/cli/src/__tests__/wrapper/package.json deleted file mode 100644 index 2e565b4de7..0000000000 --- a/packages/js/cli/src/__tests__/wrapper/package.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "name": "test-case-simple", - "private": true, - "dependencies": { - "@polywrap/wasm-as": "0.9.2", - "assemblyscript": "0.19.23" - } -} diff --git a/packages/js/cli/src/__tests__/wrapper/polywrap.build.yaml b/packages/js/cli/src/__tests__/wrapper/polywrap.build.yaml deleted file mode 100644 index 6418278821..0000000000 --- a/packages/js/cli/src/__tests__/wrapper/polywrap.build.yaml +++ /dev/null @@ -1,6 +0,0 @@ -format: 0.2.0 -config: - node_version: "16.13.0" - include: - - ./src - - ./package.json diff --git a/packages/js/cli/src/__tests__/wrapper/polywrap.deploy.yaml b/packages/js/cli/src/__tests__/wrapper/polywrap.deploy.yaml deleted file mode 100644 index fe51063194..0000000000 --- a/packages/js/cli/src/__tests__/wrapper/polywrap.deploy.yaml +++ /dev/null @@ -1,7 +0,0 @@ -format: 0.1.0 -stages: - local_ipfs_deploy: - package: ipfs - uri: fs/./build - config: - gatewayUri: "http://localhost:5001" \ No newline at end of file diff --git a/packages/js/cli/src/__tests__/wrapper/polywrap.infra.yaml b/packages/js/cli/src/__tests__/wrapper/polywrap.infra.yaml deleted file mode 100644 index 0589334529..0000000000 --- a/packages/js/cli/src/__tests__/wrapper/polywrap.infra.yaml +++ /dev/null @@ -1,4 +0,0 @@ -format: 0.1.0 -modules: - local-ipfs-node: - path: ./local-ipfs-node \ No newline at end of file diff --git a/packages/js/cli/src/__tests__/wrapper/polywrap.yaml b/packages/js/cli/src/__tests__/wrapper/polywrap.yaml deleted file mode 100644 index 76f8327359..0000000000 --- a/packages/js/cli/src/__tests__/wrapper/polywrap.yaml +++ /dev/null @@ -1,10 +0,0 @@ -format: 0.2.0 -project: - name: Simple - type: wasm/assemblyscript -source: - schema: ./src/schema.graphql - module: ./src/index.ts -extensions: - build: ./polywrap.build.yaml - deploy: ./polywrap.deploy.yaml diff --git a/packages/js/cli/src/__tests__/wrapper/src/index.ts b/packages/js/cli/src/__tests__/wrapper/src/index.ts deleted file mode 100644 index 65c1f47ee4..0000000000 --- a/packages/js/cli/src/__tests__/wrapper/src/index.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { Args_simpleMethod } from "./wrap"; - -export function simpleMethod(args: Args_simpleMethod): string { - return args.arg; -} diff --git a/packages/js/cli/src/__tests__/wrapper/src/schema.graphql b/packages/js/cli/src/__tests__/wrapper/src/schema.graphql deleted file mode 100644 index 1fa8e36696..0000000000 --- a/packages/js/cli/src/__tests__/wrapper/src/schema.graphql +++ /dev/null @@ -1,3 +0,0 @@ -type Module { - simpleMethod(arg: String!): String! -} diff --git a/packages/js/cli/src/awaitResponse.ts b/packages/js/cli/src/awaitResponse.ts deleted file mode 100644 index c5893338fe..0000000000 --- a/packages/js/cli/src/awaitResponse.ts +++ /dev/null @@ -1,28 +0,0 @@ -import axios from "axios"; - -export async function awaitResponse( - url: string, - timeout = 2000, - maxTimeout = 20000 -): Promise { - let time = 0; - - while (time < maxTimeout) { - const request = axios.get(url, { timeout }); - const success = await request - .then(() => true) - .catch((e) => e.code !== "ECONNRESET" && e.code !== "ECONNREFUSED"); - - if (success) { - return true; - } - - await new Promise(function (resolve) { - setTimeout(() => resolve(), timeout); - }); - - time += timeout; - } - - return false; -} diff --git a/packages/js/cli/src/commands.ts b/packages/js/cli/src/commands.ts deleted file mode 100644 index 7e34e2389b..0000000000 --- a/packages/js/cli/src/commands.ts +++ /dev/null @@ -1,149 +0,0 @@ -import { runCLI } from "./run-cli"; - -import { - CommandTypes, - CommandTypeMapping, - BaseCommandOptions, - CommandTypings, -} from "polywrap"; - -type CommandFn< - TOptions extends BaseCommandOptions -> = ( - options?: TOptions, - cwd?: string, - cli?: string -) => ReturnType; - -type CommandFnWithArgs< - TArguments extends unknown[], - TOptions extends BaseCommandOptions -> = ( - ...args: [ - ...targs: TArguments, - options?: TOptions, - cwd?: string, - cli?: string - ] -) => ReturnType; - -type CommandFns< - TCommands -> = Required<{ - [Command in keyof TCommands]: - TCommands[Command] extends BaseCommandOptions ? - CommandFn : - TCommands[Command] extends CommandTypes ? - CommandFnWithArgs : - TCommands[Command] extends CommandTypeMapping ? - CommandFns : never; -}>; - -function execCommandFn< - TOptions extends BaseCommandOptions, ->(command: string): CommandFn { - return async (options?: Partial, cwd?: string, cli?: string) => { - const parsedArgs = [ - ...command.split(" "), - ...parseOptions(options) - ]; - return await runCLI({ - args: parsedArgs, cwd, cli - }); - }; -} - -function execCommandWithArgsFn< - TTypes extends { - options: BaseCommandOptions, - arguments: unknown[] - }, - TArguments extends unknown[] = TTypes["arguments"], - TOptions extends BaseCommandOptions = TTypes["options"] ->(command: string): CommandFnWithArgs { - return async (...args: [...targs: TArguments, options?: Partial, cwd?: string, cli?: string]) => { - const commandArgs = []; - let options = {}; - let optionsFound = true; - let cwd: string | undefined; - let cwdFound = false; - let cli: string | undefined; - - // Iterate through the variadic arguments - for (const arg of args) { - if (!optionsFound) { - if (typeof arg === "string") { - commandArgs.push(arg); - } else if (arg === "object") { - options = arg as Record; - optionsFound = true; - } else if (typeof arg === "undefined") { - // undefined options - optionsFound = true; - } - } else { - if (typeof arg !== "string" && typeof arg !== "undefined") { - throw new Error(`Invalid "cwd" or "cli" argument type: ${arg}`); - } - if (!cwdFound) { - cwd = arg; - cwdFound = true; - } else { - cli = arg; - } - } - } - - const parsedArgs = [ - ...command.split(" "), - ...commandArgs, - ...parseOptions(options) - ]; - return await runCLI({ - args: parsedArgs, cwd, cli - }); - } -} - -export const commands: CommandFns = { - build: execCommandFn("build"), - codegen: execCommandFn("codegen"), - create: { - app: execCommandWithArgsFn("create app"), - plugin: execCommandWithArgsFn("create plugin"), - wasm: execCommandWithArgsFn("create wasm") - }, - deploy: execCommandFn("deploy"), - docgen: execCommandWithArgsFn("docgen"), - infra: execCommandWithArgsFn("infra"), - manifest: { - migrate: execCommandWithArgsFn("manifest migrate"), - schema: execCommandWithArgsFn("manifest schema") - }, - run: execCommandFn("run"), -}; - -function toKebabCase(camelCase: string): string { - return camelCase.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(); -} - -function parseValue(value: string | string[] | boolean): string { - if (Array.isArray(value)) { - return value.join(" "); - } - return value.toString(); -} - -function parseOptions( - options?: Partial -): string[] { - const parsed: string[] = []; - if (options) { - for (const [key, value] of Object.entries(options)) { - if (value === undefined) continue; - parsed.push(`--${toKebabCase(key)}`); - parsed.push(parseValue(value)); - } - } - return parsed; -} diff --git a/packages/js/cli/src/commands/exec.ts b/packages/js/cli/src/commands/exec.ts new file mode 100644 index 0000000000..92693f0d0c --- /dev/null +++ b/packages/js/cli/src/commands/exec.ts @@ -0,0 +1,106 @@ +import { runCli, CliConfig } from "../run-cli"; + +import { BaseCommandOptions } from "polywrap"; + +export type CommandFn< + TOptions extends BaseCommandOptions +> = ( + options?: Partial, + config?: CliConfig +) => ReturnType; + +export type CommandWithArgsFn< + TArguments extends unknown[], + TOptions extends BaseCommandOptions +> = ( + ...args: [ + ...targs: TArguments, + options?: Partial, + config?: CliConfig + ] +) => ReturnType; + +export function execCommandFn< + TOptions extends BaseCommandOptions, +>(command: string): CommandFn { + return async (options?: Partial, config?: CliConfig) => { + const parsedArgs = [ + ...command.split(" "), + ...parseOptions(options) + ]; + return await runCli({ + args: parsedArgs, config + }); + }; +} + +export function execCommandWithArgsFn< + TTypes extends { + options: BaseCommandOptions, + arguments: unknown[] + }, + TArguments extends unknown[] = TTypes["arguments"], + TOptions extends BaseCommandOptions = TTypes["options"] +>(command: string): CommandWithArgsFn { + return async (...args: [...targs: TArguments, options?: Partial, config?: CliConfig]) => { + const commandArgs = []; + let options = {}; + let optionsFound = false; + let config: CliConfig | undefined = { }; + + // Iterate through the variadic arguments + for (const arg of args) { + if (!optionsFound) { + if (typeof arg === "string") { + commandArgs.push(arg); + } else if (arg === "object") { + options = arg as Record; + optionsFound = true; + } else if (typeof arg === "undefined") { + // undefined options + optionsFound = true; + } + } else { + if (typeof arg !== "object" && typeof arg !== "undefined") { + throw new Error(`Invalid CliConfig argument type: ${arg}`); + } + config = arg as CliConfig | undefined; + break; + } + } + + const parsedArgs = [ + ...command.split(" "), + ...commandArgs, + ...parseOptions(options) + ]; + return await runCli({ + args: parsedArgs, config + }); + } +} + +function toKebabCase(camelCase: string): string { + return camelCase.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(); +} + +function parseValue(value: string | string[] | boolean): string { + if (Array.isArray(value)) { + return value.join(" "); + } + return value.toString(); +} + +function parseOptions( + options?: Partial +): string[] { + const parsed: string[] = []; + if (options) { + for (const [key, value] of Object.entries(options)) { + if (value === undefined) continue; + parsed.push(`--${toKebabCase(key)}`); + parsed.push(parseValue(value)); + } + } + return parsed; +} diff --git a/packages/js/cli/src/commands/index.ts b/packages/js/cli/src/commands/index.ts new file mode 100644 index 0000000000..104c549cb2 --- /dev/null +++ b/packages/js/cli/src/commands/index.ts @@ -0,0 +1,43 @@ +import { + CommandFn, + CommandWithArgsFn, + execCommandFn, + execCommandWithArgsFn, +} from "./exec"; + +import { + CommandTypes, + CommandTypings, + CommandTypeMapping, + BaseCommandOptions, +} from "polywrap"; + +type CommandFns< + TCommands +> = Required<{ + [Command in keyof TCommands]: + TCommands[Command] extends BaseCommandOptions ? + CommandFn : + TCommands[Command] extends CommandTypes ? + CommandWithArgsFn : + TCommands[Command] extends CommandTypeMapping ? + CommandFns : never; +}>; + +export const commands: CommandFns = { + build: execCommandFn("build"), + codegen: execCommandFn("codegen"), + create: { + app: execCommandWithArgsFn("create app"), + plugin: execCommandWithArgsFn("create plugin"), + wasm: execCommandWithArgsFn("create wasm") + }, + deploy: execCommandFn("deploy"), + docgen: execCommandWithArgsFn("docgen"), + infra: execCommandWithArgsFn("infra"), + manifest: { + migrate: execCommandWithArgsFn("manifest migrate"), + schema: execCommandWithArgsFn("manifest schema") + }, + run: execCommandFn("run"), +}; diff --git a/packages/js/cli/src/index.ts b/packages/js/cli/src/index.ts index 4c8ca3b047..7765a894e0 100644 --- a/packages/js/cli/src/index.ts +++ b/packages/js/cli/src/index.ts @@ -1,3 +1,2 @@ -export { runCLI } from "./run-cli"; export { commands as Commands } from "./commands"; -export * from "./awaitResponse"; +export * from "./run-cli"; diff --git a/packages/js/cli/src/run-cli.ts b/packages/js/cli/src/run-cli.ts index 457a94304f..b6b7bd067d 100644 --- a/packages/js/cli/src/run-cli.ts +++ b/packages/js/cli/src/run-cli.ts @@ -5,36 +5,43 @@ import spawn from "spawn-command"; const monorepoCli = `${__dirname}/../../../cli/bin/polywrap`; const npmCli = `${__dirname}/../../../polywrap/bin/polywrap`; -export const runCLI = async (options: { - args: string[]; +export interface CliConfig { cwd?: string; cli?: string; env?: Record; +} + +export const runCli = async (options: { + args: string[]; + config?: CliConfig; }): Promise<{ exitCode: number; stdout: string; stderr: string; }> => { - const [exitCode, stdout, stderr] = await new Promise((resolve, reject) => { - if (!options.cwd) { + const config: CliConfig = options.config || { }; + const args = options.args; + + return new Promise((resolve, reject) => { + if (!config.cwd) { // Make sure to set an absolute working directory const cwd = process.cwd(); - options.cwd = cwd[0] !== "/" ? path.resolve(__dirname, cwd) : cwd; + config.cwd = cwd[0] !== "/" ? path.resolve(__dirname, cwd) : cwd; } // Resolve the CLI - if (!options.cli) { + if (!config.cli) { if (fs.existsSync(monorepoCli)) { - options.cli = monorepoCli; + config.cli = monorepoCli; } else if (fs.existsSync(npmCli)) { - options.cli = npmCli; + config.cli = npmCli; } else { throw Error(`runCli is missing a valid CLI path, please provide one`); } } - const command = `node ${options.cli} ${options.args.join(" ")}`; - const child = spawn(command, { cwd: options.cwd, env: options.env }); + const command = `node ${config.cli} ${args.join(" ")}`; + const child = spawn(command, { cwd: config.cwd, env: config.env }); let stdout = ""; let stderr = ""; @@ -52,13 +59,7 @@ export const runCLI = async (options: { }); child.on("exit", (exitCode: number) => { - resolve([exitCode, stdout, stderr]); + resolve({ exitCode, stdout, stderr }); }); }); - - return { - exitCode, - stdout, - stderr, - }; }; diff --git a/packages/test-cases/cases/cli/manifest/samples/polywrap.yaml b/packages/test-cases/cases/cli/manifest/samples/polywrap.yaml index 71d27b5e8e..3280d4d861 100644 --- a/packages/test-cases/cases/cli/manifest/samples/polywrap.yaml +++ b/packages/test-cases/cases/cli/manifest/samples/polywrap.yaml @@ -1,8 +1,11 @@ -format: 0.1.0 -name: sample-wasm-as -language: wasm/assemblyscript -schema: ./src/schema.graphql -module: ./src/index.ts -build: ./polywrap.build.yaml -deploy: ./polywrap.deploy.yaml -meta: ./polywrap.meta.yaml +format: 0.2.0 +project: + name: sample-wasm-as + type: wasm/assemblyscript +source: + schema: ./src/schema.graphql + module: ./src/index.ts +extensions: + build: ./polywrap.build.yaml + deploy: ./polywrap.deploy.yaml + meta: ./polywrap.meta.yaml diff --git a/packages/test-cases/cases/cli/wasm/codegen/001-sanity-assemblyscript/test/Module/index.ts b/packages/test-cases/cases/cli/wasm/codegen/001-sanity-assemblyscript/test/Module/index.ts new file mode 100644 index 0000000000..d2d088d314 --- /dev/null +++ b/packages/test-cases/cases/cli/wasm/codegen/001-sanity-assemblyscript/test/Module/index.ts @@ -0,0 +1,7 @@ +import { + Args_method +} from "./serialization"; + +export { + Args_method +}; diff --git a/packages/test-cases/cases/cli/wasm/codegen/001-sanity-assemblyscript/test/Module/serialization.ts b/packages/test-cases/cases/cli/wasm/codegen/001-sanity-assemblyscript/test/Module/serialization.ts new file mode 100644 index 0000000000..805669d825 --- /dev/null +++ b/packages/test-cases/cases/cli/wasm/codegen/001-sanity-assemblyscript/test/Module/serialization.ts @@ -0,0 +1,98 @@ +import { + Read, + ReadDecoder, + Write, + WriteSizer, + WriteEncoder, + Box, + BigInt, + BigNumber, + JSON, + Context +} from "@polywrap/wasm-as"; +import * as Types from ".."; + +export class Args_method { + arg: string; +} + +export function deserializemethodArgs(argsBuf: ArrayBuffer): Args_method { + const context: Context = new Context("Deserializing module-type: method Args"); + const reader = new ReadDecoder(argsBuf, context); + let numFields = reader.readMapLength(); + + let _arg: string = ""; + let _argSet: bool = false; + + while (numFields > 0) { + numFields--; + const field = reader.readString(); + + reader.context().push(field, "unknown", "searching for property type"); + if (field == "arg") { + reader.context().push(field, "string", "type found, reading property"); + _arg = reader.readString(); + _argSet = true; + reader.context().pop(); + } + reader.context().pop(); + } + + if (!_argSet) { + throw new Error(reader.context().printWithContext("Missing required argument: 'arg: String'")); + } + + return { + arg: _arg + }; +} + +export function serializemethodArgs(args: Args_method): ArrayBuffer { + const sizerContext: Context = new Context("Serializing (sizing) module-type: method Args"); + const sizer = new WriteSizer(sizerContext); + writemethodArgs(sizer, args); + const buffer = new ArrayBuffer(sizer.length); + const encoderContext: Context = new Context("Serializing (encoding) module-type: method Args"); + const encoder = new WriteEncoder(buffer, sizer, encoderContext); + writemethodArgs(encoder, args); + return buffer; +} + +export function writemethodArgs( + writer: Write, + args: Args_method +): void { + writer.writeMapLength(1); + writer.context().push("arg", "string", "writing property"); + writer.writeString("arg"); + writer.writeString(args.arg); + writer.context().pop(); +} + +export function serializemethodResult(result: string): ArrayBuffer { + const sizerContext: Context = new Context("Serializing (sizing) module-type: method Result"); + const sizer = new WriteSizer(sizerContext); + writemethodResult(sizer, result); + const buffer = new ArrayBuffer(sizer.length); + const encoderContext: Context = new Context("Serializing (encoding) module-type: method Result"); + const encoder = new WriteEncoder(buffer, sizer, encoderContext); + writemethodResult(encoder, result); + return buffer; +} + +export function writemethodResult(writer: Write, result: string): void { + writer.context().push("method", "string", "writing property"); + writer.writeString(result); + writer.context().pop(); +} + +export function deserializemethodResult(buffer: ArrayBuffer): string { + const context: Context = new Context("Deserializing module-type: method Result"); + const reader = new ReadDecoder(buffer, context); + + reader.context().push("method", "string", "reading function output"); + const res: string = reader.readString(); + reader.context().pop(); + + return res; +} diff --git a/packages/test-cases/cases/cli/wasm/codegen/001-sanity-assemblyscript/test/Module/wrapped.ts b/packages/test-cases/cases/cli/wasm/codegen/001-sanity-assemblyscript/test/Module/wrapped.ts new file mode 100644 index 0000000000..8e4165a27c --- /dev/null +++ b/packages/test-cases/cases/cli/wasm/codegen/001-sanity-assemblyscript/test/Module/wrapped.ts @@ -0,0 +1,20 @@ +import { wrap_load_env } from "@polywrap/wasm-as"; +import { + method +} from "../../index"; +import { + deserializemethodArgs, + serializemethodResult +} from "./serialization"; +import * as Types from ".."; + +export function methodWrapped(argsBuf: ArrayBuffer, env_size: u32): ArrayBuffer { + const args = deserializemethodArgs(argsBuf); + + const result = method( + { + arg: args.arg + } + ); + return serializemethodResult(result); +} diff --git a/packages/test-cases/cases/cli/wasm/codegen/001-sanity-assemblyscript/test/entry.ts b/packages/test-cases/cases/cli/wasm/codegen/001-sanity-assemblyscript/test/entry.ts new file mode 100644 index 0000000000..22db213cd6 --- /dev/null +++ b/packages/test-cases/cases/cli/wasm/codegen/001-sanity-assemblyscript/test/entry.ts @@ -0,0 +1,38 @@ +import { + wrap_invoke_args, + wrap_invoke, + wrap_abort, + InvokeArgs +} from "@polywrap/wasm-as"; + +import { + methodWrapped +} from "./Module/wrapped"; + +export function _wrap_invoke(method_size: u32, args_size: u32, env_size: u32): bool { + const args: InvokeArgs = wrap_invoke_args( + method_size, + args_size + ); + + if (args.method == "method") { + return wrap_invoke(args, env_size, methodWrapped); + } + else { + return wrap_invoke(args, env_size, null); + } +} + +export function wrapAbort( + msg: string | null, + file: string | null, + line: u32, + column: u32 +): void { + wrap_abort( + msg ? msg : "", + file ? file : "", + line, + column + ); +} diff --git a/packages/test-cases/cases/cli/wasm/codegen/001-sanity-assemblyscript/test/index.ts b/packages/test-cases/cases/cli/wasm/codegen/001-sanity-assemblyscript/test/index.ts new file mode 100644 index 0000000000..1965fa09c7 --- /dev/null +++ b/packages/test-cases/cases/cli/wasm/codegen/001-sanity-assemblyscript/test/index.ts @@ -0,0 +1,6 @@ +import { + Args_method +} from "./Module"; +export { + Args_method +}; diff --git a/todo b/todo deleted file mode 100644 index 13174671e6..0000000000 --- a/todo +++ /dev/null @@ -1,4 +0,0 @@ -- For all command option interfaces, make optional arguments undefine-able (i.e. `prop?: Type`), this way the cli-js library doesn't have to pass them in if they have defaults. Inside of the command's `run(...)` method, we should require all options to be defined (i.e. `run(options: Require)`). -- Make sure all CLI command options are serializable (string, number, array, etc) -- Usage of enums is awkward, and requires the user to import the enum type (see `commands.build({ strategy: ... })`). Instead, we can just use TypeScript string unions (i.e. `type BuildStrategy = "vm" | "image" | ...`). I think this will make our life easier. -- Create an automated test suite in cli-js that ensures test input is defined for all possible commands. \ No newline at end of file From 7975972a9ea1e0eae5971de74ec5926e84205ec8 Mon Sep 17 00:00:00 2001 From: dOrgJelli Date: Fri, 21 Oct 2022 17:30:20 +0200 Subject: [PATCH 15/38] chore: remove files generated by test --- .../js/cli/src/__tests__/commands.spec.ts | 1 + .../test/Module/index.ts | 7 -- .../test/Module/serialization.ts | 98 ------------------- .../test/Module/wrapped.ts | 20 ---- .../001-sanity-assemblyscript/test/entry.ts | 38 ------- .../001-sanity-assemblyscript/test/index.ts | 6 -- 6 files changed, 1 insertion(+), 169 deletions(-) delete mode 100644 packages/test-cases/cases/cli/wasm/codegen/001-sanity-assemblyscript/test/Module/index.ts delete mode 100644 packages/test-cases/cases/cli/wasm/codegen/001-sanity-assemblyscript/test/Module/serialization.ts delete mode 100644 packages/test-cases/cases/cli/wasm/codegen/001-sanity-assemblyscript/test/Module/wrapped.ts delete mode 100644 packages/test-cases/cases/cli/wasm/codegen/001-sanity-assemblyscript/test/entry.ts delete mode 100644 packages/test-cases/cases/cli/wasm/codegen/001-sanity-assemblyscript/test/index.ts diff --git a/packages/js/cli/src/__tests__/commands.spec.ts b/packages/js/cli/src/__tests__/commands.spec.ts index 7afb7a8d40..d29a09532d 100644 --- a/packages/js/cli/src/__tests__/commands.spec.ts +++ b/packages/js/cli/src/__tests__/commands.spec.ts @@ -91,6 +91,7 @@ const testData: CommandTestCaseData = { throw Error("This shouldn't happen"); const outputDir = path.join(test.cwd, test.options?.codegenDir); expect(fs.existsSync(outputDir)).toBeTruthy(); + clearDir(outputDir); } }], create: { diff --git a/packages/test-cases/cases/cli/wasm/codegen/001-sanity-assemblyscript/test/Module/index.ts b/packages/test-cases/cases/cli/wasm/codegen/001-sanity-assemblyscript/test/Module/index.ts deleted file mode 100644 index d2d088d314..0000000000 --- a/packages/test-cases/cases/cli/wasm/codegen/001-sanity-assemblyscript/test/Module/index.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { - Args_method -} from "./serialization"; - -export { - Args_method -}; diff --git a/packages/test-cases/cases/cli/wasm/codegen/001-sanity-assemblyscript/test/Module/serialization.ts b/packages/test-cases/cases/cli/wasm/codegen/001-sanity-assemblyscript/test/Module/serialization.ts deleted file mode 100644 index 805669d825..0000000000 --- a/packages/test-cases/cases/cli/wasm/codegen/001-sanity-assemblyscript/test/Module/serialization.ts +++ /dev/null @@ -1,98 +0,0 @@ -import { - Read, - ReadDecoder, - Write, - WriteSizer, - WriteEncoder, - Box, - BigInt, - BigNumber, - JSON, - Context -} from "@polywrap/wasm-as"; -import * as Types from ".."; - -export class Args_method { - arg: string; -} - -export function deserializemethodArgs(argsBuf: ArrayBuffer): Args_method { - const context: Context = new Context("Deserializing module-type: method Args"); - const reader = new ReadDecoder(argsBuf, context); - let numFields = reader.readMapLength(); - - let _arg: string = ""; - let _argSet: bool = false; - - while (numFields > 0) { - numFields--; - const field = reader.readString(); - - reader.context().push(field, "unknown", "searching for property type"); - if (field == "arg") { - reader.context().push(field, "string", "type found, reading property"); - _arg = reader.readString(); - _argSet = true; - reader.context().pop(); - } - reader.context().pop(); - } - - if (!_argSet) { - throw new Error(reader.context().printWithContext("Missing required argument: 'arg: String'")); - } - - return { - arg: _arg - }; -} - -export function serializemethodArgs(args: Args_method): ArrayBuffer { - const sizerContext: Context = new Context("Serializing (sizing) module-type: method Args"); - const sizer = new WriteSizer(sizerContext); - writemethodArgs(sizer, args); - const buffer = new ArrayBuffer(sizer.length); - const encoderContext: Context = new Context("Serializing (encoding) module-type: method Args"); - const encoder = new WriteEncoder(buffer, sizer, encoderContext); - writemethodArgs(encoder, args); - return buffer; -} - -export function writemethodArgs( - writer: Write, - args: Args_method -): void { - writer.writeMapLength(1); - writer.context().push("arg", "string", "writing property"); - writer.writeString("arg"); - writer.writeString(args.arg); - writer.context().pop(); -} - -export function serializemethodResult(result: string): ArrayBuffer { - const sizerContext: Context = new Context("Serializing (sizing) module-type: method Result"); - const sizer = new WriteSizer(sizerContext); - writemethodResult(sizer, result); - const buffer = new ArrayBuffer(sizer.length); - const encoderContext: Context = new Context("Serializing (encoding) module-type: method Result"); - const encoder = new WriteEncoder(buffer, sizer, encoderContext); - writemethodResult(encoder, result); - return buffer; -} - -export function writemethodResult(writer: Write, result: string): void { - writer.context().push("method", "string", "writing property"); - writer.writeString(result); - writer.context().pop(); -} - -export function deserializemethodResult(buffer: ArrayBuffer): string { - const context: Context = new Context("Deserializing module-type: method Result"); - const reader = new ReadDecoder(buffer, context); - - reader.context().push("method", "string", "reading function output"); - const res: string = reader.readString(); - reader.context().pop(); - - return res; -} diff --git a/packages/test-cases/cases/cli/wasm/codegen/001-sanity-assemblyscript/test/Module/wrapped.ts b/packages/test-cases/cases/cli/wasm/codegen/001-sanity-assemblyscript/test/Module/wrapped.ts deleted file mode 100644 index 8e4165a27c..0000000000 --- a/packages/test-cases/cases/cli/wasm/codegen/001-sanity-assemblyscript/test/Module/wrapped.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { wrap_load_env } from "@polywrap/wasm-as"; -import { - method -} from "../../index"; -import { - deserializemethodArgs, - serializemethodResult -} from "./serialization"; -import * as Types from ".."; - -export function methodWrapped(argsBuf: ArrayBuffer, env_size: u32): ArrayBuffer { - const args = deserializemethodArgs(argsBuf); - - const result = method( - { - arg: args.arg - } - ); - return serializemethodResult(result); -} diff --git a/packages/test-cases/cases/cli/wasm/codegen/001-sanity-assemblyscript/test/entry.ts b/packages/test-cases/cases/cli/wasm/codegen/001-sanity-assemblyscript/test/entry.ts deleted file mode 100644 index 22db213cd6..0000000000 --- a/packages/test-cases/cases/cli/wasm/codegen/001-sanity-assemblyscript/test/entry.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { - wrap_invoke_args, - wrap_invoke, - wrap_abort, - InvokeArgs -} from "@polywrap/wasm-as"; - -import { - methodWrapped -} from "./Module/wrapped"; - -export function _wrap_invoke(method_size: u32, args_size: u32, env_size: u32): bool { - const args: InvokeArgs = wrap_invoke_args( - method_size, - args_size - ); - - if (args.method == "method") { - return wrap_invoke(args, env_size, methodWrapped); - } - else { - return wrap_invoke(args, env_size, null); - } -} - -export function wrapAbort( - msg: string | null, - file: string | null, - line: u32, - column: u32 -): void { - wrap_abort( - msg ? msg : "", - file ? file : "", - line, - column - ); -} diff --git a/packages/test-cases/cases/cli/wasm/codegen/001-sanity-assemblyscript/test/index.ts b/packages/test-cases/cases/cli/wasm/codegen/001-sanity-assemblyscript/test/index.ts deleted file mode 100644 index 1965fa09c7..0000000000 --- a/packages/test-cases/cases/cli/wasm/codegen/001-sanity-assemblyscript/test/index.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { - Args_method -} from "./Module"; -export { - Args_method -}; From 66c5e1afd8ee5f370b62548fc4f793d7c0c8e4be Mon Sep 17 00:00:00 2001 From: dOrgJelli Date: Fri, 21 Oct 2022 17:36:33 +0200 Subject: [PATCH 16/38] chore: revert manifest migrate --- .../js/cli/src/__tests__/commands.spec.ts | 13 +++++++++++-- .../cases/cli/manifest/samples/polywrap.yaml | 19 ++++++++----------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/packages/js/cli/src/__tests__/commands.spec.ts b/packages/js/cli/src/__tests__/commands.spec.ts index d29a09532d..3005c310fd 100644 --- a/packages/js/cli/src/__tests__/commands.spec.ts +++ b/packages/js/cli/src/__tests__/commands.spec.ts @@ -179,10 +179,19 @@ const testData: CommandTestCaseData = { }], manifest: { migrate: [{ - cwd: path.join(GetPathToCliTestFiles(), "manifest/samples"), + cwd: fs.mkdtempSync(path.join(os.tmpdir(), "manifest-migrate")), arguments: ["project"], - after: (_, stdout) => { + before: (test) => { + if (!test.cwd) + throw Error("This shouldn't happen"); + fs.copyFileSync( + path.join(GetPathToCliTestFiles(), "manifest/samples/polywrap.yaml"), + path.join(test.cwd, "polywrap.yaml") + ); + }, + after: (_, stdout, __, exitCode) => { expect(stdout).toContain("Migrating polywrap.yaml to version"); + expect(exitCode).toBe(0); } }], schema: [{ diff --git a/packages/test-cases/cases/cli/manifest/samples/polywrap.yaml b/packages/test-cases/cases/cli/manifest/samples/polywrap.yaml index 3280d4d861..71d27b5e8e 100644 --- a/packages/test-cases/cases/cli/manifest/samples/polywrap.yaml +++ b/packages/test-cases/cases/cli/manifest/samples/polywrap.yaml @@ -1,11 +1,8 @@ -format: 0.2.0 -project: - name: sample-wasm-as - type: wasm/assemblyscript -source: - schema: ./src/schema.graphql - module: ./src/index.ts -extensions: - build: ./polywrap.build.yaml - deploy: ./polywrap.deploy.yaml - meta: ./polywrap.meta.yaml +format: 0.1.0 +name: sample-wasm-as +language: wasm/assemblyscript +schema: ./src/schema.graphql +module: ./src/index.ts +build: ./polywrap.build.yaml +deploy: ./polywrap.deploy.yaml +meta: ./polywrap.meta.yaml From 601a78a020fff62e9d141f7773fedf7245551cec Mon Sep 17 00:00:00 2001 From: dOrgJelli Date: Wed, 26 Oct 2022 15:38:44 +0200 Subject: [PATCH 17/38] chore: revert --skip-codegen changes --- packages/cli/src/__tests__/e2e/build.spec.ts | 2 +- packages/cli/src/commands/build.ts | 14 +- packages/js/cli/package.json | 4 +- .../assemblyscript/012-no-codegen/cmd.json | 2 +- yarn.lock | 319 ------------------ 5 files changed, 11 insertions(+), 330 deletions(-) diff --git a/packages/cli/src/__tests__/e2e/build.spec.ts b/packages/cli/src/__tests__/e2e/build.spec.ts index 86931b599b..24275ff75e 100644 --- a/packages/cli/src/__tests__/e2e/build.spec.ts +++ b/packages/cli/src/__tests__/e2e/build.spec.ts @@ -17,7 +17,7 @@ Options: (default: ./build) -c, --client-config Add custom configuration to the PolywrapClient - -n, --skip-codegen Skip code generation + -n, --no-codegen Skip code generation -s, --strategy Strategy to use for building the wrapper (default: "vm") -w, --watch Automatically rebuild when changes are diff --git a/packages/cli/src/commands/build.ts b/packages/cli/src/commands/build.ts index 5cd64f1451..0d510aab2c 100644 --- a/packages/cli/src/commands/build.ts +++ b/packages/cli/src/commands/build.ts @@ -38,7 +38,7 @@ export interface BuildCommandOptions extends BaseCommandOptions { manifestFile: string; outputDir: string; clientConfig: string | false; - skipCodegen: boolean; + codegen: boolean; watch: boolean; strategy: `${SupportedStrategies}`; }; @@ -65,7 +65,7 @@ export const build: Command = { `-c, --client-config <${intlMsg.commands_common_options_configPath()}>`, `${intlMsg.commands_common_options_config()}` ) - .option(`-n, --skip-codegen`, `${intlMsg.commands_build_options_n()}`) + .option(`-n, --no-codegen`, `${intlMsg.commands_build_options_n()}`) .option( `-s, --strategy <${strategyStr}>`, `${intlMsg.commands_build_options_s()}` @@ -85,7 +85,7 @@ export const build: Command = { ), outputDir: parseDirOption(options.outputDir, defaultOutputDir), clientConfig: options.clientConfig || false, - skipCodegen: options.skipCodegen || false, + codegen: options.codegen || true, strategy: options.strategy || defaultStrategy, watch: options.watch || false, verbose: options.verbose || false, @@ -138,7 +138,7 @@ async function run(options: Required) { outputDir, clientConfig, strategy, - skipCodegen, + codegen, verbose, quiet, logFile, @@ -167,9 +167,9 @@ async function run(options: Required) { }); const execute = async (): Promise => { - const codeGenerator = skipCodegen - ? undefined - : new CodeGenerator({ project, schemaComposer }); + const codeGenerator = codegen + ? new CodeGenerator({ project, schemaComposer }) + : undefined; const compiler = new Compiler({ project, diff --git a/packages/js/cli/package.json b/packages/js/cli/package.json index 9b0bb09252..bca393ba14 100644 --- a/packages/js/cli/package.json +++ b/packages/js/cli/package.json @@ -1,7 +1,7 @@ { "name": "@polywrap/cli-js", "description": "Programmatically execute the Polywrap CLI", - "version": "0.9.2", + "version": "0.9.3", "license": "MIT", "repository": { "type": "git", @@ -18,7 +18,7 @@ "test:ci": "jest --passWithNoTests --runInBand --detectOpenHandles --verbose" }, "dependencies": { - "polywrap": "0.9.2", + "polywrap": "0.9.3", "spawn-command": "0.0.2-1" }, "devDependencies": { diff --git a/packages/test-cases/cases/cli/wasm/build-cmd/assemblyscript/012-no-codegen/cmd.json b/packages/test-cases/cases/cli/wasm/build-cmd/assemblyscript/012-no-codegen/cmd.json index eca753fdab..0fa14b3655 100644 --- a/packages/test-cases/cases/cli/wasm/build-cmd/assemblyscript/012-no-codegen/cmd.json +++ b/packages/test-cases/cases/cli/wasm/build-cmd/assemblyscript/012-no-codegen/cmd.json @@ -1,3 +1,3 @@ { - "args": ["--skip-codegen"] + "args": ["--no-codegen"] } \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index b74dc332d9..ac3952781e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3283,124 +3283,6 @@ resolved "https://registry.yarnpkg.com/@opentelemetry/semantic-conventions/-/semantic-conventions-1.6.0.tgz#ed410c9eb0070491cff9fe914246ce41f88d6f74" integrity sha512-aPfcBeLErM/PPiAuAbNFLN5sNbZLc3KZlar27uohllN8Zs6jJbHyJU1y7cMA6W/zuq+thkaG8mujiS+3iD/FWQ== -"@polywrap/asyncify-js@0.9.2": - version "0.9.2" - resolved "https://registry.yarnpkg.com/@polywrap/asyncify-js/-/asyncify-js-0.9.2.tgz#d588a45190f4158fb78b45dab1420bca1ca18647" - integrity sha512-Qdyk+cy0UIaewDnKphT+iTByKL5FJP1dWNWJNU9udhf0t1Bq/THiCAezN9ZJe74GTvWVQQkVYYCbUtiz+2/zyQ== - -"@polywrap/client-config-builder-js@0.9.2": - version "0.9.2" - resolved "https://registry.yarnpkg.com/@polywrap/client-config-builder-js/-/client-config-builder-js-0.9.2.tgz#3a7590d5e774a23ea2f864a387ddabfc6f1b9fd5" - integrity sha512-wyhkwO4w71vIWz3JgLCtJMHKhVzM/Wv/Phu7FkQztDFi20mBTGJN8/s0HgXYaebIwYqyiubJWHYpjTkV+5OBpw== - dependencies: - "@polywrap/core-js" "0.9.2" - "@polywrap/ens-resolver-plugin-js" "0.9.2" - "@polywrap/ethereum-plugin-js" "0.9.2" - "@polywrap/fs-plugin-js" "0.9.2" - "@polywrap/fs-resolver-plugin-js" "0.9.2" - "@polywrap/http-plugin-js" "0.9.2" - "@polywrap/http-resolver-plugin-js" "0.9.2" - "@polywrap/ipfs-plugin-js" "0.9.2" - "@polywrap/ipfs-resolver-plugin-js" "0.9.2" - "@polywrap/logger-plugin-js" "0.9.2" - "@polywrap/tracing-js" "0.9.2" - "@polywrap/uri-resolver-extensions-js" "0.9.2" - "@polywrap/uri-resolvers-js" "0.9.2" - "@polywrap/wasm-js" "0.9.2" - "@polywrap/wrap-manifest-types-js" "0.9.2" - -"@polywrap/client-js@0.9.2": - version "0.9.2" - resolved "https://registry.yarnpkg.com/@polywrap/client-js/-/client-js-0.9.2.tgz#136d558f09ef3dc2a199cf277701a51322e5139d" - integrity sha512-x97JPskyRjmEfqkVKtCRQd81whY9RAZtu5JHoI0NN7wDyG3EC5eBJ82rV5C+bB29eKAH+reSj/Wj7BAlQZtR3g== - dependencies: - "@polywrap/asyncify-js" "0.9.2" - "@polywrap/client-config-builder-js" "0.9.2" - "@polywrap/core-js" "0.9.2" - "@polywrap/ens-resolver-plugin-js" "0.9.2" - "@polywrap/ethereum-plugin-js" "0.9.2" - "@polywrap/fs-plugin-js" "0.9.2" - "@polywrap/fs-resolver-plugin-js" "0.9.2" - "@polywrap/http-plugin-js" "0.9.2" - "@polywrap/http-resolver-plugin-js" "0.9.2" - "@polywrap/ipfs-plugin-js" "0.9.2" - "@polywrap/ipfs-resolver-plugin-js" "0.9.2" - "@polywrap/logger-plugin-js" "0.9.2" - "@polywrap/msgpack-js" "0.9.2" - "@polywrap/result" "0.9.2" - "@polywrap/schema-parse" "0.9.2" - "@polywrap/tracing-js" "0.9.2" - "@polywrap/uri-resolvers-js" "0.9.2" - "@polywrap/wrap-manifest-types-js" "0.9.2" - graphql "15.5.0" - yaml "2.1.3" - -"@polywrap/core-js@0.9.2": - version "0.9.2" - resolved "https://registry.yarnpkg.com/@polywrap/core-js/-/core-js-0.9.2.tgz#59dac88b6a722b82c80e2248cc5d638470b739c1" - integrity sha512-TgC8ucd33N4mUdRMnnLkFiieGBpz1ToSas6yexE5bQJCN+GZrwqMYPkiWGAvDQrNU0CbRpBukSHeZ/34RzhlxA== - dependencies: - "@polywrap/asyncify-js" "0.9.2" - "@polywrap/msgpack-js" "0.9.2" - "@polywrap/result" "0.9.2" - "@polywrap/tracing-js" "0.9.2" - "@polywrap/wrap-manifest-types-js" "0.9.2" - graphql "15.5.0" - graphql-tag "2.10.4" - jsonschema "1.4.0" - semver "7.3.5" - yaml "2.1.3" - -"@polywrap/ens-resolver-plugin-js@0.9.2": - version "0.9.2" - resolved "https://registry.yarnpkg.com/@polywrap/ens-resolver-plugin-js/-/ens-resolver-plugin-js-0.9.2.tgz#e21fa34a7f1e6b9e63ebe9409657af5865f14abe" - integrity sha512-9yZnRi1ccncOHvL4/joTzNio8QJlED7gFIop0Y5COVXOJ0L7wRbN3krCbjdH9SqoiLojSiq4Fekd/9h8gBUIaA== - dependencies: - "@ethersproject/address" "5.0.7" - "@ethersproject/basex" "5.0.7" - "@polywrap/core-js" "0.9.2" - ethers "5.0.7" - -"@polywrap/ethereum-plugin-js@0.9.2": - version "0.9.2" - resolved "https://registry.yarnpkg.com/@polywrap/ethereum-plugin-js/-/ethereum-plugin-js-0.9.2.tgz#ae396cefb4e472ec6b2efcc28020bbf4af56ac25" - integrity sha512-K1UxcV0GoT4uAwWZn7lnY+CFl3S8r9jgJNgCpHlVDl/kgLLqfcF1JExIozacoh08EjgAHyEMklSySG+14L4FFA== - dependencies: - "@ethersproject/address" "5.0.7" - "@ethersproject/providers" "5.0.7" - "@polywrap/core-js" "0.9.2" - ethers "5.0.7" - -"@polywrap/fs-plugin-js@0.9.2": - version "0.9.2" - resolved "https://registry.yarnpkg.com/@polywrap/fs-plugin-js/-/fs-plugin-js-0.9.2.tgz#7c05da1cf539f290f2efcf7109307a33e573ebb0" - integrity sha512-BIQglBPKP98jVOpC7eoK6KzT/6Ku1NiD85CC5IVAUnKalEl+PaGVdHoPTrMpLuBokiR1Z3jWMp0QupAv7WnyTg== - dependencies: - "@polywrap/core-js" "0.9.2" - -"@polywrap/fs-resolver-plugin-js@0.9.2": - version "0.9.2" - resolved "https://registry.yarnpkg.com/@polywrap/fs-resolver-plugin-js/-/fs-resolver-plugin-js-0.9.2.tgz#1d468e7999afd7c2e9ccbec9cf7c71ac4662c0c3" - integrity sha512-vWRlXIEQX7JIANgDSGmYvuJnZGd6GT/TW7r5bcN8qlDKb5VCAwcY2qCzhfGZ2Rj8p8jPFSDFfoS9rGufGOhDBw== - dependencies: - "@polywrap/core-js" "0.9.2" - -"@polywrap/http-plugin-js@0.9.2": - version "0.9.2" - resolved "https://registry.yarnpkg.com/@polywrap/http-plugin-js/-/http-plugin-js-0.9.2.tgz#e2349950af3c41ef71177640471b95898d37a8b9" - integrity sha512-DCklD0GBYq6u6BuJHOvC3lgKSeT3eXNqhQmavIXwg41yjVKPipMkQ6U38Hs+NbIgJ+yFzagBreYVPZ2zysiDig== - dependencies: - "@polywrap/core-js" "0.9.2" - axios "0.21.4" - -"@polywrap/http-resolver-plugin-js@0.9.2": - version "0.9.2" - resolved "https://registry.yarnpkg.com/@polywrap/http-resolver-plugin-js/-/http-resolver-plugin-js-0.9.2.tgz#fcf60430015fa3f995f2311d2e7da7980ab22341" - integrity sha512-MN86IaWe+TFNqIiSyoBlAItrzJxrMY1cf2Z6PzOTg3EvHP7Am+CMQdVZ5nkJA2+jqPYczwXv48z8OVczd/a1pg== - dependencies: - "@polywrap/core-js" "0.9.2" - abort-controller "3.0.0" - "@polywrap/ipfs-http-client-lite@0.3.0": version "0.3.0" resolved "https://registry.yarnpkg.com/@polywrap/ipfs-http-client-lite/-/ipfs-http-client-lite-0.3.0.tgz#b8caf4b4f39413e591aff4367023a04cb6df83a1" @@ -3417,160 +3299,6 @@ pull-stream-to-async-iterator "^1.0.2" querystring "^0.2.0" -"@polywrap/ipfs-plugin-js@0.9.2": - version "0.9.2" - resolved "https://registry.yarnpkg.com/@polywrap/ipfs-plugin-js/-/ipfs-plugin-js-0.9.2.tgz#c6005b22bfbecf4479a228a5c1eb398043587ac4" - integrity sha512-IFezQWzKCTR2jRhirYk3OB8bUT+4Sd9fCCyZMHjvuW9htjkTHjNNWteUfn4wvGp0xQ8N7sohxylsrlvO8V589Q== - dependencies: - "@polywrap/core-js" "0.9.2" - "@polywrap/ipfs-http-client-lite" "0.3.0" - abort-controller "3.0.0" - is-ipfs "1.0.3" - multiformats "9.7.0" - -"@polywrap/ipfs-resolver-plugin-js@0.9.2": - version "0.9.2" - resolved "https://registry.yarnpkg.com/@polywrap/ipfs-resolver-plugin-js/-/ipfs-resolver-plugin-js-0.9.2.tgz#d742542ebfdecc16a6be09e7d684649d8887992f" - integrity sha512-kjGu/fQFLQ5O3UNeSj0Apc8tWUf7LURUGbZURpO35mSX7+pLaZUAa6JdoS3/CxlAL5UC9XIu+oF/05hkOC9fIQ== - dependencies: - "@polywrap/core-js" "0.9.2" - "@polywrap/ipfs-http-client-lite" "0.3.0" - abort-controller "3.0.0" - is-ipfs "1.0.3" - -"@polywrap/logger-plugin-js@0.9.2": - version "0.9.2" - resolved "https://registry.yarnpkg.com/@polywrap/logger-plugin-js/-/logger-plugin-js-0.9.2.tgz#17ba96f47f41dd73ad731d57881fc6fb068b9d8a" - integrity sha512-UJ9wvOnZp2MU05FX9aHc4t8/aNBMqgxhx9VHotJa0QdeZ5nAbxf0g2USkX5PMYY7Ug4yx0IGMJuro2uE8G9i9Q== - dependencies: - "@polywrap/core-js" "0.9.2" - -"@polywrap/msgpack-js@0.9.2": - version "0.9.2" - resolved "https://registry.yarnpkg.com/@polywrap/msgpack-js/-/msgpack-js-0.9.2.tgz#c1073d3e43d343061429966f6b42a95966a388e0" - integrity sha512-hjrc+32oApLtlcpUD+P7xNjdoNx0jt4DgWRt0ksCdJUTNxDrUSUVzXpqOMWpHV2pqHEwwa7iD09jE8hcpk09Ug== - dependencies: - "@msgpack/msgpack" "2.7.2" - -"@polywrap/os-js@0.9.2": - version "0.9.2" - resolved "https://registry.yarnpkg.com/@polywrap/os-js/-/os-js-0.9.2.tgz#da7b14364f74fe83a4c85b3677ad0f7b4c10dade" - integrity sha512-JGQjiUlX2oEl9U+Q+FlzpmbUN8fgBLKw2CSxJdeURj41J2zzul3hPANdvEu4zh+LFqTCn1iojPkTf8Vs02dWyA== - -"@polywrap/polywrap-manifest-schemas@0.9.2": - version "0.9.2" - resolved "https://registry.yarnpkg.com/@polywrap/polywrap-manifest-schemas/-/polywrap-manifest-schemas-0.9.2.tgz#fd593a6ea613a2b5d09502ffa82e36d84075a0b1" - integrity sha512-5SsJooCRJ3kL2nEaqYFETUabrO8UkwvzLco+tQAQJB3dI0u1msu+R4tYd7tr+LRgrjLASITu3XYbtWm2lIKIiw== - -"@polywrap/polywrap-manifest-types-js@0.9.2": - version "0.9.2" - resolved "https://registry.yarnpkg.com/@polywrap/polywrap-manifest-types-js/-/polywrap-manifest-types-js-0.9.2.tgz#59d9303adf92c2a8c6c69591decc3274407ccb3b" - integrity sha512-sJCezGHH9m/aGTsQwPP4aPAmdpPedEwnu0abBFTnWuW1gsub4I80q4Tm5Itr0mlZ+Og+7sGG9J73Wtyu3auFEA== - dependencies: - "@polywrap/polywrap-manifest-schemas" "0.9.2" - jsonschema "1.4.0" - semver "7.3.5" - yaml "2.1.3" - -"@polywrap/result@0.9.2": - version "0.9.2" - resolved "https://registry.yarnpkg.com/@polywrap/result/-/result-0.9.2.tgz#c6e4cfcdf46813eff1b06729f99b3fdbccb9f97f" - integrity sha512-ZUTOrsBNrlOD/fDpwlBz5laCs0TfDOVveXR4fEOOhbxzC7JQERzjpEjFXy49OLS+aLs7vsOYZL/BXFqQO3GvFA== - -"@polywrap/schema-bind@0.9.2": - version "0.9.2" - resolved "https://registry.yarnpkg.com/@polywrap/schema-bind/-/schema-bind-0.9.2.tgz#8860079bfe966dc11153b6d67b9b635c5471370f" - integrity sha512-3+Bflf/31xkUJ6sT/n1X0ria0v18tcuryAycusbpnaVEDxhW622fqVZgmtFZCUdsXz8A+cW4bqDbE5VxpPZrUQ== - dependencies: - "@polywrap/os-js" "0.9.2" - "@polywrap/schema-parse" "0.9.2" - "@polywrap/wrap-manifest-types-js" "0.9.2" - mustache "4.0.1" - -"@polywrap/schema-compose@0.9.2": - version "0.9.2" - resolved "https://registry.yarnpkg.com/@polywrap/schema-compose/-/schema-compose-0.9.2.tgz#70488059651873ea25bcae0aada44e2ad0d3884a" - integrity sha512-MCxYlez0yXBlgpyi3YBQZQvnT5Ly9/hkndZY6UUl1NW2qD+dDpyeczFksdG9JzASlqyc3wLgyzeJbSFrK2S5Hg== - dependencies: - "@polywrap/schema-parse" "0.9.2" - "@polywrap/wrap-manifest-types-js" "0.9.2" - graphql "15.5.0" - mustache "4.0.1" - -"@polywrap/schema-parse@0.9.2": - version "0.9.2" - resolved "https://registry.yarnpkg.com/@polywrap/schema-parse/-/schema-parse-0.9.2.tgz#6fde706177e080dd6e4b7ba000fa3de9231fc95e" - integrity sha512-9lQfQsFHtUPyxi4LD4H+yYhT57Ex+qbINx8jIfZV0dZQf5LijbLi8nSpPHSJSYJRkdiQtveRFezQ2F3eWgPq1w== - dependencies: - "@dorgjelli/graphql-schema-cycles" "1.1.4" - "@polywrap/wrap-manifest-types-js" "0.9.2" - graphql "15.5.0" - -"@polywrap/test-env-js@0.9.2": - version "0.9.2" - resolved "https://registry.yarnpkg.com/@polywrap/test-env-js/-/test-env-js-0.9.2.tgz#a96e27706bedf760fb0ffdf60f4cb55efb8633f8" - integrity sha512-Nzr0NollEsmEQc2QdJfzuopPT6rvuMD07I9TzhIlNdi4jk3yk8S6igH99/VIoz7e0XDiYKmcanTtzb3ZJPVKuQ== - dependencies: - "@polywrap/core-js" "0.9.2" - "@polywrap/polywrap-manifest-types-js" "0.9.2" - axios "0.21.2" - spawn-command "0.0.2-1" - yaml "2.1.3" - -"@polywrap/tracing-js@0.9.2": - version "0.9.2" - resolved "https://registry.yarnpkg.com/@polywrap/tracing-js/-/tracing-js-0.9.2.tgz#5135824c2ce834779b0feec52f97f1e34193e8a8" - integrity sha512-GVXv7ckdPr7sOFszKgeYimkeALjmjaWk183S6Bv1jliuAGVZRjReJ1q48hms4fPTp9JtSvEfVNpy6kEwW1ChHg== - dependencies: - "@fetsorn/opentelemetry-console-exporter" "0.0.3" - "@opentelemetry/api" "1.2.0" - "@opentelemetry/exporter-trace-otlp-http" "0.32.0" - "@opentelemetry/resources" "1.6.0" - "@opentelemetry/sdk-trace-base" "1.6.0" - "@opentelemetry/sdk-trace-web" "1.6.0" - -"@polywrap/uri-resolver-extensions-js@0.9.2": - version "0.9.2" - resolved "https://registry.yarnpkg.com/@polywrap/uri-resolver-extensions-js/-/uri-resolver-extensions-js-0.9.2.tgz#da75cddbf9f2d934361ffc1d28612d6867501555" - integrity sha512-tK+QaAPGneiMTL6kk49UM0Ep/CROZNUPPjwB91VXligD4NpcJfXLU9HKWY1EJgq6jvfZ05OhY8S1xP0l3OkpeQ== - dependencies: - "@polywrap/core-js" "0.9.2" - "@polywrap/result" "0.9.2" - "@polywrap/uri-resolvers-js" "0.9.2" - "@polywrap/wasm-js" "0.9.2" - "@polywrap/wrap-manifest-types-js" "0.9.2" - -"@polywrap/uri-resolvers-js@0.9.2": - version "0.9.2" - resolved "https://registry.yarnpkg.com/@polywrap/uri-resolvers-js/-/uri-resolvers-js-0.9.2.tgz#ecaddf6b44ac6b902fe0a1bb38c50a2ed96a5fc5" - integrity sha512-NY9gYBcTC0c7fnaN2OftmD6HAdQcSXUt33XqzhFw1+L8jW6ZUEDsraw5gYjDhMwBk8VvcsexZKv9T1pd8gnrjQ== - dependencies: - "@polywrap/core-js" "0.9.2" - "@polywrap/result" "0.9.2" - "@polywrap/wrap-manifest-types-js" "0.9.2" - -"@polywrap/wasm-js@0.9.2": - version "0.9.2" - resolved "https://registry.yarnpkg.com/@polywrap/wasm-js/-/wasm-js-0.9.2.tgz#ae5e1065a86c4916e94be4109e0df6df729467ea" - integrity sha512-ZiUw5z4PZs2lO91/msrIAmfbS+vKli0WPZumK/2Devym9UUO2YNrODnFJWrVX1b1+i6HkJ2W6xcmOxz4+ON7tA== - dependencies: - "@polywrap/asyncify-js" "0.9.2" - "@polywrap/core-js" "0.9.2" - "@polywrap/msgpack-js" "0.9.2" - "@polywrap/result" "0.9.2" - "@polywrap/tracing-js" "0.9.2" - "@polywrap/wrap-manifest-types-js" "0.9.2" - -"@polywrap/wrap-manifest-types-js@0.9.2": - version "0.9.2" - resolved "https://registry.yarnpkg.com/@polywrap/wrap-manifest-types-js/-/wrap-manifest-types-js-0.9.2.tgz#b5ff4836a83677fecf2f0a24b9a697721a955a88" - integrity sha512-qceuKhszle/Ew/OtAQYz7g0JL34bbLD7sHuGNndD58bCtdqRsU454uEwkbV/QawQtmgVUEkCnSB6gJUen4EClQ== - dependencies: - "@polywrap/msgpack-js" "0.9.2" - json-schema-ref-parser "9.0.9" - jsonschema "1.4.0" - semver "7.3.5" - "@sinclair/typebox@^0.24.1": version "0.24.51" resolved "https://registry.yarnpkg.com/@sinclair/typebox/-/typebox-0.24.51.tgz#645f33fe4e02defe26f2f5c0410e1c094eac7f5f" @@ -13898,53 +13626,6 @@ pnp-webpack-plugin@1.6.4: dependencies: ts-pnp "^1.1.6" -polywrap@0.9.2: - version "0.9.2" - resolved "https://registry.yarnpkg.com/polywrap/-/polywrap-0.9.2.tgz#c0e21ea84c4cf9d7080338a15d414367843053e2" - integrity sha512-y9l8DMmLdkCytV7+zV+K+BCL/oZfmF3EUGgEKWj6H4DWQIPvyndNTX56LK2ph40Uc1H4QAK9TsePOK+nolTlKQ== - dependencies: - "@ethersproject/providers" "5.6.8" - "@ethersproject/wallet" "5.6.2" - "@formatjs/intl" "1.8.2" - "@polywrap/asyncify-js" "0.9.2" - "@polywrap/client-config-builder-js" "0.9.2" - "@polywrap/client-js" "0.9.2" - "@polywrap/core-js" "0.9.2" - "@polywrap/ens-resolver-plugin-js" "0.9.2" - "@polywrap/ethereum-plugin-js" "0.9.2" - "@polywrap/ipfs-plugin-js" "0.9.2" - "@polywrap/msgpack-js" "0.9.2" - "@polywrap/os-js" "0.9.2" - "@polywrap/polywrap-manifest-types-js" "0.9.2" - "@polywrap/schema-bind" "0.9.2" - "@polywrap/schema-compose" "0.9.2" - "@polywrap/schema-parse" "0.9.2" - "@polywrap/test-env-js" "0.9.2" - "@polywrap/wasm-js" "0.9.2" - "@polywrap/wrap-manifest-types-js" "0.9.2" - axios "0.21.2" - chalk "4.1.0" - chokidar "3.5.1" - commander "9.2.0" - content-hash "2.5.2" - copyfiles "2.4.1" - docker-compose "0.23.17" - extract-zip "2.0.1" - form-data "4.0.0" - fs-extra "9.0.1" - ipfs-http-client "48.1.3" - json-schema "0.4.0" - json-schema-ref-parser "9.0.9" - jsonschema "1.4.0" - mustache "4.0.1" - os-locale "5.0.0" - regex-parser "2.2.11" - rimraf "3.0.2" - toml "3.0.0" - typescript "4.1.6" - yaml "2.1.3" - yesno "0.4.0" - portfinder@^1.0.25: version "1.0.32" resolved "https://registry.yarnpkg.com/portfinder/-/portfinder-1.0.32.tgz#2fe1b9e58389712429dc2bea5beb2146146c7f81" From 37c577eab8b7b25b4e938bc11b7a8a3c759dae6c Mon Sep 17 00:00:00 2001 From: dOrgJelli Date: Wed, 26 Oct 2022 15:40:44 +0200 Subject: [PATCH 18/38] chore: update js cli commands tests --- packages/js/cli/src/__tests__/commands.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/js/cli/src/__tests__/commands.spec.ts b/packages/js/cli/src/__tests__/commands.spec.ts index 3005c310fd..accae6de5d 100644 --- a/packages/js/cli/src/__tests__/commands.spec.ts +++ b/packages/js/cli/src/__tests__/commands.spec.ts @@ -202,8 +202,8 @@ const testData: CommandTestCaseData = { } }] }, - run: [{ - cwd: path.join(GetPathToCliTestFiles(), "run/001-yaml-workflow"), + test: [{ + cwd: path.join(GetPathToCliTestFiles(), "test/001-yaml-workflow"), before: async (test) => { if (!test.cwd) throw Error("This shouldn't happen"); From 9ada2cee258efb71b170517fff3d67e92ea22466 Mon Sep 17 00:00:00 2001 From: dOrgJelli Date: Wed, 26 Oct 2022 15:42:52 +0200 Subject: [PATCH 19/38] chore: update cli-js readme --- packages/js/cli/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/js/cli/README.md b/packages/js/cli/README.md index 5bb0cf8ef9..34e66ace2b 100644 --- a/packages/js/cli/README.md +++ b/packages/js/cli/README.md @@ -10,7 +10,7 @@ It allows user execute Polywrap CLI commands programmatically, with simple and t Build a wrapper: ``` typescript -import { Commands } from "@polywrap/cli-js; +import { Commands } from "@polywrap/cli-js"; async function main() { const wrapperPath = "/path/to/wrapper"; From 0ad0609ccef1fcd4c5b399611d49f414e0edd5fb Mon Sep 17 00:00:00 2001 From: dOrgJelli Date: Wed, 26 Oct 2022 15:51:04 +0200 Subject: [PATCH 20/38] chore: correct build options interface --- packages/cli/src/commands/build.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/cli/src/commands/build.ts b/packages/cli/src/commands/build.ts index 0d510aab2c..1ace5ef76e 100644 --- a/packages/cli/src/commands/build.ts +++ b/packages/cli/src/commands/build.ts @@ -38,7 +38,7 @@ export interface BuildCommandOptions extends BaseCommandOptions { manifestFile: string; outputDir: string; clientConfig: string | false; - codegen: boolean; + noCodegen: boolean; watch: boolean; strategy: `${SupportedStrategies}`; }; @@ -85,7 +85,7 @@ export const build: Command = { ), outputDir: parseDirOption(options.outputDir, defaultOutputDir), clientConfig: options.clientConfig || false, - codegen: options.codegen || true, + noCodegen: !options.codegen || false, strategy: options.strategy || defaultStrategy, watch: options.watch || false, verbose: options.verbose || false, @@ -138,7 +138,7 @@ async function run(options: Required) { outputDir, clientConfig, strategy, - codegen, + noCodegen, verbose, quiet, logFile, @@ -167,9 +167,9 @@ async function run(options: Required) { }); const execute = async (): Promise => { - const codeGenerator = codegen - ? new CodeGenerator({ project, schemaComposer }) - : undefined; + const codeGenerator = noCodegen + ? undefined + : new CodeGenerator({ project, schemaComposer }); const compiler = new Compiler({ project, From dd7198097e3b453887ce9d07b414fb3156bcb5b3 Mon Sep 17 00:00:00 2001 From: dOrgJelli Date: Wed, 26 Oct 2022 16:13:46 +0200 Subject: [PATCH 21/38] lint fix --- packages/cli/src/commands/build.ts | 2 +- packages/cli/src/commands/codegen.ts | 2 +- packages/cli/src/commands/create.ts | 56 ++++++++++--------- packages/cli/src/commands/deploy.ts | 2 +- packages/cli/src/commands/docgen.ts | 7 ++- packages/cli/src/commands/index.ts | 40 ++++++------- packages/cli/src/commands/infra.ts | 2 +- packages/cli/src/commands/manifest.ts | 9 +-- packages/cli/src/commands/test.ts | 4 +- packages/cli/src/commands/types.ts | 4 +- .../src/lib/option-parsers/manifestFile.ts | 3 +- packages/js/cli/src/commands/exec.ts | 41 +++++++------- packages/js/cli/src/commands/index.ts | 41 +++++++++----- packages/js/cli/src/run-cli.ts | 2 +- 14 files changed, 114 insertions(+), 101 deletions(-) diff --git a/packages/cli/src/commands/build.ts b/packages/cli/src/commands/build.ts index 1ace5ef76e..a54dfa1e40 100644 --- a/packages/cli/src/commands/build.ts +++ b/packages/cli/src/commands/build.ts @@ -41,7 +41,7 @@ export interface BuildCommandOptions extends BaseCommandOptions { noCodegen: boolean; watch: boolean; strategy: `${SupportedStrategies}`; -}; +} export const build: Command = { setup: (program: Program) => { diff --git a/packages/cli/src/commands/codegen.ts b/packages/cli/src/commands/codegen.ts index e1ccc8a24a..00d8c4edf2 100644 --- a/packages/cli/src/commands/codegen.ts +++ b/packages/cli/src/commands/codegen.ts @@ -34,7 +34,7 @@ export interface CodegenCommandOptions extends BaseCommandOptions { publishDir: string; script: string | false; clientConfig: string | false; -}; +} export const codegen: Command = { setup: (program: Program) => { diff --git a/packages/cli/src/commands/create.ts b/packages/cli/src/commands/create.ts index d8e3c8d729..953a8f80a2 100644 --- a/packages/cli/src/commands/create.ts +++ b/packages/cli/src/commands/create.ts @@ -33,7 +33,7 @@ type SupportedLangs = export interface CreateCommandOptions extends BaseCommandOptions { outputDir: string | false; -}; +} export const create: Command = { setup: (program: Program) => { @@ -63,14 +63,16 @@ export const create: Command = { `-l, --log-file [${pathStr}]`, `${intlMsg.commands_build_options_l()}` ) - .action(async (language, name, options: Partial) => { - await run("wasm", language, name, { - outputDir: options.outputDir || false, - verbose: options.verbose || false, - quiet: options.quiet || false, - logFile: parseLogFileOption(options.logFile), - }); - }); + .action( + async (language, name, options: Partial) => { + await run("wasm", language, name, { + outputDir: options.outputDir || false, + verbose: options.verbose || false, + quiet: options.quiet || false, + logFile: parseLogFileOption(options.logFile), + }); + } + ); createCommand .command("app") @@ -93,14 +95,16 @@ export const create: Command = { `-l, --log-file [${pathStr}]`, `${intlMsg.commands_build_options_l()}` ) - .action(async (language, name, options: Partial) => { - await run("app", language, name, { - outputDir: options.outputDir || false, - verbose: options.verbose || false, - quiet: options.quiet || false, - logFile: parseLogFileOption(options.logFile), - }); - }); + .action( + async (language, name, options: Partial) => { + await run("app", language, name, { + outputDir: options.outputDir || false, + verbose: options.verbose || false, + quiet: options.quiet || false, + logFile: parseLogFileOption(options.logFile), + }); + } + ); createCommand .command(`plugin`) @@ -123,14 +127,16 @@ export const create: Command = { `-l, --log-file [${pathStr}]`, `${intlMsg.commands_build_options_l()}` ) - .action(async (language, name, options: Partial) => { - await run("plugin", language, name, { - outputDir: options.outputDir || false, - verbose: options.verbose || false, - quiet: options.quiet || false, - logFile: parseLogFileOption(options.logFile), - }); - }); + .action( + async (language, name, options: Partial) => { + await run("plugin", language, name, { + outputDir: options.outputDir || false, + verbose: options.verbose || false, + quiet: options.quiet || false, + logFile: parseLogFileOption(options.logFile), + }); + } + ); }, }; diff --git a/packages/cli/src/commands/deploy.ts b/packages/cli/src/commands/deploy.ts index 0798cd917c..01f635a6fc 100644 --- a/packages/cli/src/commands/deploy.ts +++ b/packages/cli/src/commands/deploy.ts @@ -24,7 +24,7 @@ const pathStr = intlMsg.commands_deploy_options_o_path(); export interface DeployCommandOptions extends BaseCommandOptions { manifestFile: string; outputFile: string | false; -}; +} type ManifestJob = DeployManifest["jobs"][number]; type ManifestStep = ManifestJob["steps"][number]; diff --git a/packages/cli/src/commands/docgen.ts b/packages/cli/src/commands/docgen.ts index ca9a3be4af..4016799c3f 100644 --- a/packages/cli/src/commands/docgen.ts +++ b/packages/cli/src/commands/docgen.ts @@ -41,7 +41,7 @@ export interface DocgenCommandOptions extends BaseCommandOptions { docgenDir: string; clientConfig: string | false; imports: boolean; -}; +} const argumentsDescription = ` ${chalk.bold( @@ -113,7 +113,10 @@ export const docgen: Command = { }, }; -async function run(action: DocgenActions, options: Required) { +async function run( + action: DocgenActions, + options: Required +) { const { manifestFile, docgenDir, diff --git a/packages/cli/src/commands/index.ts b/packages/cli/src/commands/index.ts index 73c3df8188..768450707f 100644 --- a/packages/cli/src/commands/index.ts +++ b/packages/cli/src/commands/index.ts @@ -14,59 +14,53 @@ import { CreateCommandOptions, SupportedAppLangs, SupportedPluginLangs, - SupportedWasmLangs + SupportedWasmLangs, } from "./create"; import { DeployCommandOptions } from "./deploy"; -import { - DocgenCommandOptions, - DocgenActions -} from "./docgen"; -import { - InfraCommandOptions, - InfraActions -} from "./infra"; +import { DocgenCommandOptions, DocgenActions } from "./docgen"; +import { InfraCommandOptions, InfraActions } from "./infra"; import { ManifestSchemaCommandOptions, ManifestMigrateCommandOptions, - ManifestType + ManifestType, } from "./manifest"; import { TestCommandOptions } from "./test"; export interface CommandTypings { - "build": BuildCommandOptions; - "codegen": CodegenCommandOptions; - "create": { - "app": { + build: BuildCommandOptions; + codegen: CodegenCommandOptions; + create: { + app: { options: CreateCommandOptions; arguments: [language: SupportedAppLangs, name: string]; }; - "plugin": { + plugin: { options: CreateCommandOptions; arguments: [language: SupportedPluginLangs, name: string]; }; - "wasm": { + wasm: { options: CreateCommandOptions; arguments: [language: SupportedWasmLangs, name: string]; }; }; - "deploy": DeployCommandOptions; - "docgen": { + deploy: DeployCommandOptions; + docgen: { options: DocgenCommandOptions; arguments: [action: `${DocgenActions}`]; }; - "infra": { + infra: { options: InfraCommandOptions; arguments: [action: `${InfraActions}`]; }; - "manifest": { - "migrate": { + manifest: { + migrate: { options: ManifestMigrateCommandOptions; arguments: [type: ManifestType]; }; - "schema": { + schema: { options: ManifestSchemaCommandOptions; arguments: [type: ManifestType]; }; }; - "test": TestCommandOptions; + test: TestCommandOptions; } diff --git a/packages/cli/src/commands/infra.ts b/packages/cli/src/commands/infra.ts index eedd378249..8fc7c2ac9e 100644 --- a/packages/cli/src/commands/infra.ts +++ b/packages/cli/src/commands/infra.ts @@ -26,7 +26,7 @@ export enum InfraActions { export interface InfraCommandOptions extends BaseCommandOptions { manifestFile: string | false; modules: string[] | false; -}; +} const DEFAULT_MODULES_PATH = path.join( __dirname, diff --git a/packages/cli/src/commands/manifest.ts b/packages/cli/src/commands/manifest.ts index 6ba9d513b5..9f884558b4 100644 --- a/packages/cli/src/commands/manifest.ts +++ b/packages/cli/src/commands/manifest.ts @@ -80,12 +80,12 @@ export type ManifestType = typeof manifestTypes[number]; export interface ManifestSchemaCommandOptions extends BaseCommandOptions { raw: boolean; manifestFile: string | false; -}; +} export interface ManifestMigrateCommandOptions extends BaseCommandOptions { manifestFile: string | false; format: string | false; -}; +} export const manifest: Command = { setup: (program: Program) => { @@ -107,10 +107,7 @@ export const manifest: Command = { .choices(manifestTypes) .default(manifestTypes[0]) ) - .option( - `-r, --raw`, - intlMsg.commands_manifest_command_s_option_r() - ) + .option(`-r, --raw`, intlMsg.commands_manifest_command_s_option_r()) .option( `-m, --manifest-file <${pathStr}>`, `${intlMsg.commands_manifest_options_m({ diff --git a/packages/cli/src/commands/test.ts b/packages/cli/src/commands/test.ts index 61d71939fe..7b37cd442d 100644 --- a/packages/cli/src/commands/test.ts +++ b/packages/cli/src/commands/test.ts @@ -28,7 +28,7 @@ export interface TestCommandOptions extends BaseCommandOptions { jobs: string[] | false; validationScript: string | false; outputFile: string | false; -}; +} const defaultManifestStr = defaultWorkflowManifest.join(" | "); const pathStr = intlMsg.commands_test_options_m_path(); @@ -94,7 +94,7 @@ const _run = async (options: Required) => { logFile, } = options; const logger = createLogger({ verbose, quiet, logFile }); - const config = await parseClientConfigOption(clientConfig) + const config = await parseClientConfigOption(clientConfig); const manifestPath = path.resolve(manifestFile); const workflow = await loadWorkflowManifest(manifestPath, logger); diff --git a/packages/cli/src/commands/types.ts b/packages/cli/src/commands/types.ts index ef2e42c3db..3bff93fda0 100644 --- a/packages/cli/src/commands/types.ts +++ b/packages/cli/src/commands/types.ts @@ -10,10 +10,10 @@ export interface Command { type SerializableOption = string | number | boolean; export interface BaseCommandOptions { + [prop: string]: SerializableOption | SerializableOption[]; verbose: boolean; quiet: boolean; logFile: string | false; - [prop: string]: SerializableOption | SerializableOption[]; } export interface CommandTypes { @@ -23,4 +23,4 @@ export interface CommandTypes { export type CommandTypeMapping = { [name: string]: BaseCommandOptions | CommandTypes | CommandTypeMapping; -} +}; diff --git a/packages/cli/src/lib/option-parsers/manifestFile.ts b/packages/cli/src/lib/option-parsers/manifestFile.ts index bf22c4b45b..e744d9fc35 100644 --- a/packages/cli/src/lib/option-parsers/manifestFile.ts +++ b/packages/cli/src/lib/option-parsers/manifestFile.ts @@ -13,8 +13,7 @@ export function parseManifestFileOption( manifestFile: string | undefined | false, defaults: string[] ): string { - const didUserProvideManifestFile = - manifestFile && !!manifestFile.length; + const didUserProvideManifestFile = manifestFile && !!manifestFile.length; const manifestPaths = manifestFile ? [manifestFile as string] : defaults; diff --git a/packages/js/cli/src/commands/exec.ts b/packages/js/cli/src/commands/exec.ts index 92693f0d0c..baae2fc309 100644 --- a/packages/js/cli/src/commands/exec.ts +++ b/packages/js/cli/src/commands/exec.ts @@ -2,9 +2,7 @@ import { runCli, CliConfig } from "../run-cli"; import { BaseCommandOptions } from "polywrap"; -export type CommandFn< - TOptions extends BaseCommandOptions -> = ( +export type CommandFn = ( options?: Partial, config?: CliConfig ) => ReturnType; @@ -20,40 +18,44 @@ export type CommandWithArgsFn< ] ) => ReturnType; -export function execCommandFn< - TOptions extends BaseCommandOptions, ->(command: string): CommandFn { +export function execCommandFn( + command: string +): CommandFn { return async (options?: Partial, config?: CliConfig) => { - const parsedArgs = [ - ...command.split(" "), - ...parseOptions(options) - ]; + const parsedArgs = [...command.split(" "), ...parseOptions(options)]; return await runCli({ - args: parsedArgs, config + args: parsedArgs, + config, }); }; } export function execCommandWithArgsFn< TTypes extends { - options: BaseCommandOptions, - arguments: unknown[] + options: BaseCommandOptions; + arguments: unknown[]; }, TArguments extends unknown[] = TTypes["arguments"], TOptions extends BaseCommandOptions = TTypes["options"] >(command: string): CommandWithArgsFn { - return async (...args: [...targs: TArguments, options?: Partial, config?: CliConfig]) => { + return async ( + ...args: [ + ...targs: TArguments, + options?: Partial, + config?: CliConfig + ] + ) => { const commandArgs = []; let options = {}; let optionsFound = false; - let config: CliConfig | undefined = { }; + let config: CliConfig | undefined = {}; // Iterate through the variadic arguments for (const arg of args) { if (!optionsFound) { if (typeof arg === "string") { commandArgs.push(arg); - } else if (arg === "object") { + } else if (typeof arg === "object") { options = arg as Record; optionsFound = true; } else if (typeof arg === "undefined") { @@ -72,12 +74,13 @@ export function execCommandWithArgsFn< const parsedArgs = [ ...command.split(" "), ...commandArgs, - ...parseOptions(options) + ...parseOptions(options), ]; return await runCli({ - args: parsedArgs, config + args: parsedArgs, + config, }); - } + }; } function toKebabCase(camelCase: string): string { diff --git a/packages/js/cli/src/commands/index.ts b/packages/js/cli/src/commands/index.ts index 474dceddd4..06ff32f5de 100644 --- a/packages/js/cli/src/commands/index.ts +++ b/packages/js/cli/src/commands/index.ts @@ -12,32 +12,43 @@ import { BaseCommandOptions, } from "polywrap"; -type CommandFns< - TCommands -> = Required<{ - [Command in keyof TCommands]: - TCommands[Command] extends BaseCommandOptions ? - CommandFn : - TCommands[Command] extends CommandTypes ? - CommandWithArgsFn : - TCommands[Command] extends CommandTypeMapping ? - CommandFns : never; -}>; +type CommandFns = Required< + { + [Command in keyof TCommands]: TCommands[Command] extends BaseCommandOptions + ? CommandFn + : TCommands[Command] extends CommandTypes + ? CommandWithArgsFn< + TCommands[Command]["arguments"], + TCommands[Command]["options"] + > + : TCommands[Command] extends CommandTypeMapping + ? CommandFns + : never; + } +>; export const commands: CommandFns = { build: execCommandFn("build"), codegen: execCommandFn("codegen"), create: { app: execCommandWithArgsFn("create app"), - plugin: execCommandWithArgsFn("create plugin"), - wasm: execCommandWithArgsFn("create wasm") + plugin: execCommandWithArgsFn( + "create plugin" + ), + wasm: execCommandWithArgsFn( + "create wasm" + ), }, deploy: execCommandFn("deploy"), docgen: execCommandWithArgsFn("docgen"), infra: execCommandWithArgsFn("infra"), manifest: { - migrate: execCommandWithArgsFn("manifest migrate"), - schema: execCommandWithArgsFn("manifest schema") + migrate: execCommandWithArgsFn( + "manifest migrate" + ), + schema: execCommandWithArgsFn( + "manifest schema" + ), }, test: execCommandFn("test"), }; diff --git a/packages/js/cli/src/run-cli.ts b/packages/js/cli/src/run-cli.ts index b6b7bd067d..4ee3d55232 100644 --- a/packages/js/cli/src/run-cli.ts +++ b/packages/js/cli/src/run-cli.ts @@ -19,7 +19,7 @@ export const runCli = async (options: { stdout: string; stderr: string; }> => { - const config: CliConfig = options.config || { }; + const config: CliConfig = options.config || {}; const args = options.args; return new Promise((resolve, reject) => { From f616b09d8d24fd5ad69d32ecbd2b3969cbaca367 Mon Sep 17 00:00:00 2001 From: dOrgJelli Date: Wed, 26 Oct 2022 16:31:33 +0200 Subject: [PATCH 22/38] chore: fix help cli help text tests --- packages/cli/lang/en.json | 2 +- packages/cli/lang/es.json | 2 +- packages/cli/src/__tests__/e2e/build.spec.ts | 30 +++++++++---------- packages/cli/src/__tests__/e2e/help.spec.ts | 4 +-- .../cli/src/__tests__/e2e/manifest.spec.ts | 2 +- .../cli/src/__tests__/e2e/no-command.spec.ts | 4 +-- packages/cli/src/commands/build.ts | 6 ++-- packages/cli/src/commands/infra.ts | 2 +- 8 files changed, 27 insertions(+), 25 deletions(-) diff --git a/packages/cli/lang/en.json b/packages/cli/lang/en.json index 1bebb1c26e..69e7765b90 100644 --- a/packages/cli/lang/en.json +++ b/packages/cli/lang/en.json @@ -17,7 +17,7 @@ "commands_build_options_t": "Use the development server's ENS instance", "commands_build_options_n": "Skip code generation", "commands_build_options_w": "Automatically rebuild when changes are made (default: false)", - "commands_build_options_s": "Strategy to use for building the wrapper", + "commands_build_options_s": "Strategy to use for building the wrapper (default: {default})", "commands_build_options_s_strategy": "strategy", "commands_build_options_l": "Log file to save console output to", "commands_infra_description": "Modular Infrastructure-As-Code Orchestrator", diff --git a/packages/cli/lang/es.json b/packages/cli/lang/es.json index 1bebb1c26e..69e7765b90 100644 --- a/packages/cli/lang/es.json +++ b/packages/cli/lang/es.json @@ -17,7 +17,7 @@ "commands_build_options_t": "Use the development server's ENS instance", "commands_build_options_n": "Skip code generation", "commands_build_options_w": "Automatically rebuild when changes are made (default: false)", - "commands_build_options_s": "Strategy to use for building the wrapper", + "commands_build_options_s": "Strategy to use for building the wrapper (default: {default})", "commands_build_options_s_strategy": "strategy", "commands_build_options_l": "Log file to save console output to", "commands_infra_description": "Modular Infrastructure-As-Code Orchestrator", diff --git a/packages/cli/src/__tests__/e2e/build.spec.ts b/packages/cli/src/__tests__/e2e/build.spec.ts index 24275ff75e..6a0a634964 100644 --- a/packages/cli/src/__tests__/e2e/build.spec.ts +++ b/packages/cli/src/__tests__/e2e/build.spec.ts @@ -11,21 +11,21 @@ const HELP = `Usage: polywrap build|b [options] Build Polywrap Projects (type: interface, wasm) Options: - -m, --manifest-file Path to the Polywrap Build manifest file - (default: polywrap.yaml | polywrap.yml) - -o, --output-dir Output directory for build results - (default: ./build) - -c, --client-config Add custom configuration to the - PolywrapClient - -n, --no-codegen Skip code generation - -s, --strategy Strategy to use for building the wrapper - (default: "vm") - -w, --watch Automatically rebuild when changes are - made (default: false) - -v, --verbose Verbose output (default: false) - -q, --quiet Suppress output (default: false) - -l, --log-file [path] Log file to save console output to - -h, --help display help for command + -m, --manifest-file Path to the Polywrap Build manifest file + (default: polywrap.yaml | polywrap.yml) + -o, --output-dir Output directory for build results + (default: ./build) + -c, --client-config Add custom configuration to the + PolywrapClient + -n, --no-codegen Skip code generation + -s, --strategy Strategy to use for building the wrapper + (default: vm) + -w, --watch Automatically rebuild when changes are + made (default: false) + -v, --verbose Verbose output (default: false) + -q, --quiet Suppress output (default: false) + -l, --log-file [path] Log file to save console output to + -h, --help display help for command `; jest.setTimeout(500000); diff --git a/packages/cli/src/__tests__/e2e/help.spec.ts b/packages/cli/src/__tests__/e2e/help.spec.ts index 455940204e..31560e6802 100644 --- a/packages/cli/src/__tests__/e2e/help.spec.ts +++ b/packages/cli/src/__tests__/e2e/help.spec.ts @@ -13,10 +13,10 @@ Commands: codegen|g [options] Generate Code For Polywrap Projects create|c Create New Projects deploy|d [options] Deploys Polywrap Projects - infra|i [options] Modular Infrastructure-As-Code Orchestrator - test|t [options] Execute Tests docgen|o [options] Generate wrapper documentation + infra|i [options] Modular Infrastructure-As-Code Orchestrator manifest|m Inspect & Migrade Polywrap Manifests + test|t [options] Execute Tests help [command] display help for command `; diff --git a/packages/cli/src/__tests__/e2e/manifest.spec.ts b/packages/cli/src/__tests__/e2e/manifest.spec.ts index c3a5136ec7..e2926c075b 100644 --- a/packages/cli/src/__tests__/e2e/manifest.spec.ts +++ b/packages/cli/src/__tests__/e2e/manifest.spec.ts @@ -51,7 +51,7 @@ Arguments: \"infra\", \"meta\", \"workflow\", default: \"project\") Options: - -r, --raw Output raw JSON Schema (default: false) + -r, --raw Output raw JSON Schema -m, --manifest-file Path to the manifest file (default: polywrap.yaml | polywrap.yml) -v, --verbose Verbose output (default: false) diff --git a/packages/cli/src/__tests__/e2e/no-command.spec.ts b/packages/cli/src/__tests__/e2e/no-command.spec.ts index c870cb2ee6..d1d3204cbc 100644 --- a/packages/cli/src/__tests__/e2e/no-command.spec.ts +++ b/packages/cli/src/__tests__/e2e/no-command.spec.ts @@ -13,10 +13,10 @@ Commands: codegen|g [options] Generate Code For Polywrap Projects create|c Create New Projects deploy|d [options] Deploys Polywrap Projects - infra|i [options] Modular Infrastructure-As-Code Orchestrator - test|t [options] Execute Tests docgen|o [options] Generate wrapper documentation + infra|i [options] Modular Infrastructure-As-Code Orchestrator manifest|m Inspect & Migrade Polywrap Manifests + test|t [options] Execute Tests help [command] display help for command `; diff --git a/packages/cli/src/commands/build.ts b/packages/cli/src/commands/build.ts index a54dfa1e40..5b809137fa 100644 --- a/packages/cli/src/commands/build.ts +++ b/packages/cli/src/commands/build.ts @@ -30,7 +30,7 @@ import { PolywrapManifest } from "@polywrap/polywrap-manifest-types-js"; const defaultOutputDir = "./build"; const defaultStrategy = SupportedStrategies.VM; -const strategyStr = intlMsg.commands_build_options_s_strategy(); +const strategyStr = Object.values(SupportedStrategies).join(" | "); const defaultManifestStr = defaultPolywrapManifest.join(" | "); const pathStr = intlMsg.commands_build_options_o_path(); @@ -68,7 +68,9 @@ export const build: Command = { .option(`-n, --no-codegen`, `${intlMsg.commands_build_options_n()}`) .option( `-s, --strategy <${strategyStr}>`, - `${intlMsg.commands_build_options_s()}` + `${intlMsg.commands_build_options_s({ + default: defaultStrategy + })}` ) .option(`-w, --watch`, `${intlMsg.commands_build_options_w()}`) .option("-v, --verbose", intlMsg.commands_common_options_verbose()) diff --git a/packages/cli/src/commands/infra.ts b/packages/cli/src/commands/infra.ts index 8fc7c2ac9e..bfefced83b 100644 --- a/packages/cli/src/commands/infra.ts +++ b/packages/cli/src/commands/infra.ts @@ -73,7 +73,7 @@ export const infra: Command = { }) ) .option( - `-o, --modules <${moduleNameStr}...>`, + `-o, --modules <${moduleNameStr},${moduleNameStr}>`, intlMsg.commands_infra_options_o() ) .option("-v, --verbose", intlMsg.commands_common_options_verbose()) From 6d3eee57c4b0b2eb97f781d63ed7b5367469b3e9 Mon Sep 17 00:00:00 2001 From: dOrgJelli Date: Wed, 26 Oct 2022 17:03:56 +0200 Subject: [PATCH 23/38] chore: improved exec child_process security --- .../strategies/DockerImageStrategy.ts | 54 +++++++++++++------ .../strategies/DockerVMStrategy.ts | 30 ++++++----- .../strategies/LocalStrategy.ts | 18 +++++-- .../cli/src/lib/helpers/workflow-validator.ts | 5 +- .../infra/fetchers/NodeDependencyFetcher.ts | 13 +++-- packages/cli/src/lib/system/child-process.ts | 27 ++++++---- packages/cli/src/lib/system/docker.ts | 4 +- 7 files changed, 101 insertions(+), 50 deletions(-) diff --git a/packages/cli/src/lib/build-strategies/strategies/DockerImageStrategy.ts b/packages/cli/src/lib/build-strategies/strategies/DockerImageStrategy.ts index 4f134eb469..0577317858 100644 --- a/packages/cli/src/lib/build-strategies/strategies/DockerImageStrategy.ts +++ b/packages/cli/src/lib/build-strategies/strategies/DockerImageStrategy.ts @@ -149,7 +149,8 @@ export class DockerImageBuildStrategy extends BuildStrategy { useBuildx &&= await this._isDockerBuildxInstalled(); const { stdout: containerLsOutput } = runCommandSync( - "docker container ls -a", + "docker", + ["container", "ls", "-a"], this.project.logger ); @@ -157,18 +158,24 @@ export class DockerImageBuildStrategy extends BuildStrategy { containerLsOutput && containerLsOutput.indexOf(`root-${imageName}`) > -1 ) { - await runCommand(`docker rm -f root-${imageName}`, this.project.logger); + await runCommand( + "docker", + ["rm", "-f", `root-${imageName}`], + this.project.logger + ); } // Create a new interactive terminal await runCommand( - `docker create -ti --name root-${imageName} ${imageName}`, + "docker", + ["create", "-ti", "--name", `root-${imageName}`, imageName], this.project.logger ); // Make sure the "project" directory exists const { stdout: projectLsOutput } = runCommandSync( - `docker run --rm ${imageName} /bin/bash -c "ls /project"`, + "docker", + ["run", "--rm", imageName, "/bin/bash", "-c", '"ls /project"'], this.project.logger ); @@ -179,7 +186,8 @@ export class DockerImageBuildStrategy extends BuildStrategy { } const { stdout: buildLsOutput } = runCommandSync( - `docker run --rm ${imageName} /bin/bash -c "ls /project/build"`, + "docker", + ["run", "--rm", imageName, "/bin/bash", "-c", '"ls /project/build"'], this.project.logger ); @@ -193,22 +201,32 @@ export class DockerImageBuildStrategy extends BuildStrategy { } await runCommand( - `docker cp root-${imageName}:/project/build/${buildArtifact} ${outputDir}`, + "docker", + ["cp", `root-${imageName}:/project/build/${buildArtifact}`, outputDir], this.project.logger ); - await runCommand(`docker rm -f root-${imageName}`, this.project.logger); + await runCommand( + "docker", + ["rm", "-f", `root-${imageName}`], + this.project.logger + ); if (useBuildx) { if (removeBuilder) { await runCommand( - `docker buildx rm ${imageName}`, + "docker", + ["buildx", "rm", imageName], this.project.logger ); } } if (removeImage) { - await runCommand(`docker rmi ${imageName}`, this.project.logger); + await runCommand( + "docker", + ["rmi", imageName], + this.project.logger + ); } }; @@ -250,7 +268,8 @@ export class DockerImageBuildStrategy extends BuildStrategy { let buildxUseFailed: boolean; try { const { stderr } = runCommandSync( - `docker buildx use ${imageName}`, + "docker", + ["buildx", "use", imageName], this.project.logger ); buildxUseFailed = !!stderr; @@ -260,12 +279,14 @@ export class DockerImageBuildStrategy extends BuildStrategy { if (buildxUseFailed) { await runCommand( - `docker buildx create --use --name ${imageName}`, + "docker", + ["buildx", "create", "--use", "--name", imageName], this.project.logger ); } await runCommand( - `docker buildx build -f ${dockerfile} -t ${imageName} ${rootDir} ${cacheFrom} ${cacheTo} --output=type=docker`, + "docker", + ["buildx", "build", "-f", dockerfile, "-t", imageName, rootDir, cacheFrom, cacheTo, "--output=type=docker"], this.project.logger, undefined, undefined, @@ -273,7 +294,8 @@ export class DockerImageBuildStrategy extends BuildStrategy { ); } else { await runCommand( - `docker build -f ${dockerfile} -t ${imageName} ${rootDir}`, + "docker", + ["build", "-f", dockerfile, "-t", imageName, rootDir], this.project.logger, isWin() ? undefined @@ -288,7 +310,8 @@ export class DockerImageBuildStrategy extends BuildStrategy { // Get the docker image ID const { stdout } = runCommandSync( - `docker image inspect ${imageName} -f "{{.ID}}"`, + "docker", + ["image", "inspect", imageName, "-f", "{{.ID}}"], this.project.logger ); @@ -319,7 +342,8 @@ export class DockerImageBuildStrategy extends BuildStrategy { private async _isDockerBuildxInstalled(): Promise { const { stdout: version } = runCommandSync( - "docker buildx version", + "docker", + ["buildx", "version"], this.project.logger ); return version && version.startsWith("github.com/docker/buildx") diff --git a/packages/cli/src/lib/build-strategies/strategies/DockerVMStrategy.ts b/packages/cli/src/lib/build-strategies/strategies/DockerVMStrategy.ts index 2f17d440d7..93e36960c3 100644 --- a/packages/cli/src/lib/build-strategies/strategies/DockerVMStrategy.ts +++ b/packages/cli/src/lib/build-strategies/strategies/DockerVMStrategy.ts @@ -183,13 +183,14 @@ export class DockerVMBuildStrategy extends BuildStrategy { try { await runCommand( - `docker run --rm -v ${path.resolve( - this._volumePaths.project - )}:/project -v ${path.resolve( - this._volumePaths.linkedPackages - )}:/linked-packages ${cacheVolume} ${ - CONFIGS[language].baseImage - }:latest /bin/bash --verbose /project/polywrap-build.sh`, + "docker", + [ + "run", "--rm", + "-v", `${path.resolve(this._volumePaths.project)}:/project`, + "-v", `${path.resolve(this._volumePaths.linkedPackages)}:/linked-packages`, + cacheVolume, `${CONFIGS[language].baseImage}:latest`, + "/bin/bash", "--verbose", "/project/polywrap-build.sh" + ], this.project.logger, undefined, undefined, @@ -202,13 +203,14 @@ export class DockerVMBuildStrategy extends BuildStrategy { } await runCommand( - `docker run --rm -v ${path.resolve( - this._volumePaths.project - )}:/project -v ${path.resolve( - this._volumePaths.linkedPackages - )}:/linked-packages ${ - CONFIGS[language].baseImage - }:latest /bin/bash -c "chmod -R 777 /project && chmod -R 777 /linked-packages"`, + "docker", + [ + "run", "--rm", + "-v", `${path.resolve(this._volumePaths.project)}:/project`, + "-v", `${path.resolve(this._volumePaths.linkedPackages)}:/linked-packages`, + `${CONFIGS[language].baseImage}:latest`, + "/bin/bash", "-c", '"chmod -R 777 /project && chmod -R 777 /linked-packages"' + ], this.project.logger ); } catch (e) { diff --git a/packages/cli/src/lib/build-strategies/strategies/LocalStrategy.ts b/packages/cli/src/lib/build-strategies/strategies/LocalStrategy.ts index 799587f48b..cbb126632c 100644 --- a/packages/cli/src/lib/build-strategies/strategies/LocalStrategy.ts +++ b/packages/cli/src/lib/build-strategies/strategies/LocalStrategy.ts @@ -16,6 +16,7 @@ export class LocalBuildStrategy extends BuildStrategy { const buildManifestConfig = buildManifest.config as BuildManifestConfig; if (buildManifestConfig.polywrap_module) { + const polywrapModuleDir = buildManifestConfig.polywrap_module.dir; let scriptPath = `${__dirname}/../../defaults/build-strategies/${bindLanguage}/${this.getStrategyName()}/local.sh`; if (bindLanguage.startsWith("wasm")) { @@ -23,15 +24,26 @@ export class LocalBuildStrategy extends BuildStrategy { scriptPath = customScript ?? scriptPath; } - const command = `chmod +x ${scriptPath} && ${scriptPath} ${buildManifestConfig.polywrap_module.dir} ${this.outputDir}`; - await logActivity( this.project.logger, intlMsg.lib_helpers_buildText(), intlMsg.lib_helpers_buildError(), intlMsg.lib_helpers_buildWarning(), async (logger) => { - return await runCommand(command, logger, undefined, process.cwd()); + return await + runCommand( + "chmod", + ["+x", scriptPath], + logger, + undefined, + process.cwd() + ).then(() => + runCommand( + scriptPath, + [polywrapModuleDir, this.outputDir], + logger + ) + ); } ); } diff --git a/packages/cli/src/lib/helpers/workflow-validator.ts b/packages/cli/src/lib/helpers/workflow-validator.ts index b75c9fdd88..a4a8fe5486 100644 --- a/packages/cli/src/lib/helpers/workflow-validator.ts +++ b/packages/cli/src/lib/helpers/workflow-validator.ts @@ -10,7 +10,7 @@ import os from "os"; const TMPDIR = fs.mkdtempSync(path.join(os.tmpdir(), `polywrap-cli`)); export function cueExists(logger: Logger): boolean { - const { stdout } = runCommandSync("cue version", logger); + const { stdout } = runCommandSync("cue", ["version"], logger); return stdout ? stdout.startsWith("cue version ") : false; } @@ -38,7 +38,8 @@ export function validateOutput( ); const { stderr } = runCommandSync( - `cue vet -d ${selector} ${validateScriptPath} ${jsonOutput}`, + "cue", + ["vet", "-d", selector, validateScriptPath, jsonOutput], logger ); diff --git a/packages/cli/src/lib/infra/fetchers/NodeDependencyFetcher.ts b/packages/cli/src/lib/infra/fetchers/NodeDependencyFetcher.ts index b33795c7db..d329a89433 100644 --- a/packages/cli/src/lib/infra/fetchers/NodeDependencyFetcher.ts +++ b/packages/cli/src/lib/infra/fetchers/NodeDependencyFetcher.ts @@ -10,8 +10,10 @@ export class NodeDependencyFetcher extends InfraDependencyFetcher { public async installPackages(packages: InfraPackageArg[]): Promise { this.composePackageJson(packages); await runCommand( - `cd ${this.config.installationDirectory} && npm i`, - this.config.logger + "npm", ["i"], + this.config.logger, + undefined, + this.config.installationDirectory ); } @@ -48,8 +50,11 @@ export class YarnDependencyFetcher extends NodeDependencyFetcher { public async installPackages(packages: InfraPackageArg[]): Promise { this.composePackageJson(packages); await runCommand( - `cd ${this.config.installationDirectory} && yarn`, - this.config.logger + "yarn", + [], + this.config.logger, + undefined, + this.config.installationDirectory ); } } diff --git a/packages/cli/src/lib/system/child-process.ts b/packages/cli/src/lib/system/child-process.ts index 1f67338071..b90549c45b 100644 --- a/packages/cli/src/lib/system/child-process.ts +++ b/packages/cli/src/lib/system/child-process.ts @@ -1,23 +1,28 @@ import { Logger } from "../logging"; -import { exec, ExecException, execSync, SpawnSyncReturns } from "child_process"; +import { execFile, ExecException, execFileSync, SpawnSyncReturns } from "child_process"; export function runCommandSync( command: string, + args: string[], logger: Logger, env: Record | undefined = undefined ): { stdout?: string; stderr?: SpawnSyncReturns & Error } { logger.info(`> ${command}`); try { - const stdout = execSync(command, { - cwd: __dirname, - env: { - ...process.env, - ...env, - }, - encoding: "utf-8", - }); + const stdout = execFileSync( + command, + args, + { + cwd: __dirname, + env: { + ...process.env, + ...env, + }, + encoding: "utf-8", + } + ); return { stdout: stdout }; } catch (e) { return { stderr: e }; @@ -26,6 +31,7 @@ export function runCommandSync( export async function runCommand( command: string, + args: string[], logger: Logger, env: Record | undefined = undefined, cwd: string | undefined = undefined, @@ -46,8 +52,9 @@ export async function runCommand( } }; - const childObj = exec( + const childObj = execFile( command, + args, { cwd: cwd ?? __dirname, env: { diff --git a/packages/cli/src/lib/system/docker.ts b/packages/cli/src/lib/system/docker.ts index 46aac1aff5..ec599aa427 100644 --- a/packages/cli/src/lib/system/docker.ts +++ b/packages/cli/src/lib/system/docker.ts @@ -8,13 +8,13 @@ import path from "path"; import fs from "fs"; export function isDockerInstalled(logger: Logger): boolean { - const { stdout } = runCommandSync("docker version", logger); + const { stdout } = runCommandSync("docker", ["version"], logger); return stdout ? stdout.includes("Version") : false; } export async function ensureDockerDaemonRunning(logger: Logger): Promise { try { - runCommandSync("docker stats --no-stream", logger); + runCommandSync("docker", ["stats", "--no-stream"], logger); } catch (e) { throw new Error(intlMsg.lib_helpers_docker_couldNotConnect()); } From 3c5f2e1f2f998fd12c193537e97faf17dc3ad147 Mon Sep 17 00:00:00 2001 From: dOrgJelli Date: Wed, 26 Oct 2022 17:16:01 +0200 Subject: [PATCH 24/38] fix: infra --modules parsing --- packages/cli/src/__tests__/e2e/infra.spec.ts | 18 +++++++++--------- packages/cli/src/commands/infra.ts | 4 +++- packages/cli/src/lib/system/child-process.ts | 4 ++-- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/packages/cli/src/__tests__/e2e/infra.spec.ts b/packages/cli/src/__tests__/e2e/infra.spec.ts index 86328ed8c1..059e38de5c 100644 --- a/packages/cli/src/__tests__/e2e/infra.spec.ts +++ b/packages/cli/src/__tests__/e2e/infra.spec.ts @@ -19,7 +19,7 @@ const HELP = `Usage: polywrap infra|i [options] Modular Infrastructure-As-Code Orchestrator Arguments: - action + action Infra allows you to execute the following commands: up Start Polywrap infrastructure down Stop Polywrap infrastructure @@ -28,14 +28,14 @@ Arguments: (choices: "up", "down", "vars", "config") Options: - -m, --manifest-file Path to the Polywrap Infra manifest file - (default: polywrap.infra.yaml | - polywrap.infra.yml) - -o, --modules Use only specified modules - -v, --verbose Verbose output (default: false) - -q, --quiet Suppress output (default: false) - -l, --log-file [path] Log file to save console output to - -h, --help display help for command + -m, --manifest-file Path to the Polywrap Infra manifest file + (default: polywrap.infra.yaml | + polywrap.infra.yml) + -o, --modules Use only specified modules + -v, --verbose Verbose output (default: false) + -q, --quiet Suppress output (default: false) + -l, --log-file [path] Log file to save console output to + -h, --help display help for command `; const portInUse = (port: number) => { diff --git a/packages/cli/src/commands/infra.ts b/packages/cli/src/commands/infra.ts index bfefced83b..b46c2c84e3 100644 --- a/packages/cli/src/commands/infra.ts +++ b/packages/cli/src/commands/infra.ts @@ -73,7 +73,7 @@ export const infra: Command = { }) ) .option( - `-o, --modules <${moduleNameStr},${moduleNameStr}>`, + `-o, --modules <${moduleNameStr}...>`, intlMsg.commands_infra_options_o() ) .option("-v, --verbose", intlMsg.commands_common_options_verbose()) @@ -112,6 +112,8 @@ async function run( const modulesArray: string[] = modules ? modules : []; + console.log(modulesArray); + const manifest: string[] = manifestFile ? [manifestFile] : defaultInfraManifest; diff --git a/packages/cli/src/lib/system/child-process.ts b/packages/cli/src/lib/system/child-process.ts index b90549c45b..d497f1ee26 100644 --- a/packages/cli/src/lib/system/child-process.ts +++ b/packages/cli/src/lib/system/child-process.ts @@ -8,7 +8,7 @@ export function runCommandSync( logger: Logger, env: Record | undefined = undefined ): { stdout?: string; stderr?: SpawnSyncReturns & Error } { - logger.info(`> ${command}`); + logger.info(`> ${command} ${args.join(" ")}`); try { const stdout = execFileSync( @@ -37,7 +37,7 @@ export async function runCommand( cwd: string | undefined = undefined, redirectStderr = false ): Promise<{ stdout: string; stderr: string }> { - logger.info(`> ${command}`); + logger.info(`> ${command} ${args.join(" ")}`); return new Promise<{ stdout: string; stderr: string }>((resolve, reject) => { const callback = ( From 3c5e4007a991e89bfe8558e05e743931a366dc3b Mon Sep 17 00:00:00 2001 From: dOrgJelli Date: Wed, 26 Oct 2022 17:25:54 +0200 Subject: [PATCH 25/38] chore: lint fix --- packages/cli/src/commands/build.ts | 2 +- .../strategies/DockerImageStrategy.ts | 19 +++++++---- .../strategies/DockerVMStrategy.ts | 33 ++++++++++++++----- .../strategies/LocalStrategy.ts | 25 +++++++------- .../infra/fetchers/NodeDependencyFetcher.ts | 3 +- packages/cli/src/lib/system/child-process.ts | 27 +++++++-------- 6 files changed, 66 insertions(+), 43 deletions(-) diff --git a/packages/cli/src/commands/build.ts b/packages/cli/src/commands/build.ts index 5b809137fa..0ed1cb2166 100644 --- a/packages/cli/src/commands/build.ts +++ b/packages/cli/src/commands/build.ts @@ -69,7 +69,7 @@ export const build: Command = { .option( `-s, --strategy <${strategyStr}>`, `${intlMsg.commands_build_options_s({ - default: defaultStrategy + default: defaultStrategy, })}` ) .option(`-w, --watch`, `${intlMsg.commands_build_options_w()}`) diff --git a/packages/cli/src/lib/build-strategies/strategies/DockerImageStrategy.ts b/packages/cli/src/lib/build-strategies/strategies/DockerImageStrategy.ts index 0577317858..159a54de69 100644 --- a/packages/cli/src/lib/build-strategies/strategies/DockerImageStrategy.ts +++ b/packages/cli/src/lib/build-strategies/strategies/DockerImageStrategy.ts @@ -222,11 +222,7 @@ export class DockerImageBuildStrategy extends BuildStrategy { } } if (removeImage) { - await runCommand( - "docker", - ["rmi", imageName], - this.project.logger - ); + await runCommand("docker", ["rmi", imageName], this.project.logger); } }; @@ -286,7 +282,18 @@ export class DockerImageBuildStrategy extends BuildStrategy { } await runCommand( "docker", - ["buildx", "build", "-f", dockerfile, "-t", imageName, rootDir, cacheFrom, cacheTo, "--output=type=docker"], + [ + "buildx", + "build", + "-f", + dockerfile, + "-t", + imageName, + rootDir, + cacheFrom, + cacheTo, + "--output=type=docker", + ], this.project.logger, undefined, undefined, diff --git a/packages/cli/src/lib/build-strategies/strategies/DockerVMStrategy.ts b/packages/cli/src/lib/build-strategies/strategies/DockerVMStrategy.ts index 93e36960c3..779121b9c1 100644 --- a/packages/cli/src/lib/build-strategies/strategies/DockerVMStrategy.ts +++ b/packages/cli/src/lib/build-strategies/strategies/DockerVMStrategy.ts @@ -185,11 +185,19 @@ export class DockerVMBuildStrategy extends BuildStrategy { await runCommand( "docker", [ - "run", "--rm", - "-v", `${path.resolve(this._volumePaths.project)}:/project`, - "-v", `${path.resolve(this._volumePaths.linkedPackages)}:/linked-packages`, - cacheVolume, `${CONFIGS[language].baseImage}:latest`, - "/bin/bash", "--verbose", "/project/polywrap-build.sh" + "run", + "--rm", + "-v", + `${path.resolve(this._volumePaths.project)}:/project`, + "-v", + `${path.resolve( + this._volumePaths.linkedPackages + )}:/linked-packages`, + cacheVolume, + `${CONFIGS[language].baseImage}:latest`, + "/bin/bash", + "--verbose", + "/project/polywrap-build.sh", ], this.project.logger, undefined, @@ -205,11 +213,18 @@ export class DockerVMBuildStrategy extends BuildStrategy { await runCommand( "docker", [ - "run", "--rm", - "-v", `${path.resolve(this._volumePaths.project)}:/project`, - "-v", `${path.resolve(this._volumePaths.linkedPackages)}:/linked-packages`, + "run", + "--rm", + "-v", + `${path.resolve(this._volumePaths.project)}:/project`, + "-v", + `${path.resolve( + this._volumePaths.linkedPackages + )}:/linked-packages`, `${CONFIGS[language].baseImage}:latest`, - "/bin/bash", "-c", '"chmod -R 777 /project && chmod -R 777 /linked-packages"' + "/bin/bash", + "-c", + '"chmod -R 777 /project && chmod -R 777 /linked-packages"', ], this.project.logger ); diff --git a/packages/cli/src/lib/build-strategies/strategies/LocalStrategy.ts b/packages/cli/src/lib/build-strategies/strategies/LocalStrategy.ts index cbb126632c..51c8f3bffc 100644 --- a/packages/cli/src/lib/build-strategies/strategies/LocalStrategy.ts +++ b/packages/cli/src/lib/build-strategies/strategies/LocalStrategy.ts @@ -30,20 +30,19 @@ export class LocalBuildStrategy extends BuildStrategy { intlMsg.lib_helpers_buildError(), intlMsg.lib_helpers_buildWarning(), async (logger) => { - return await + return await runCommand( + "chmod", + ["+x", scriptPath], + logger, + undefined, + process.cwd() + ).then(() => runCommand( - "chmod", - ["+x", scriptPath], - logger, - undefined, - process.cwd() - ).then(() => - runCommand( - scriptPath, - [polywrapModuleDir, this.outputDir], - logger - ) - ); + scriptPath, + [polywrapModuleDir, this.outputDir], + logger + ) + ); } ); } diff --git a/packages/cli/src/lib/infra/fetchers/NodeDependencyFetcher.ts b/packages/cli/src/lib/infra/fetchers/NodeDependencyFetcher.ts index d329a89433..c78df18fc7 100644 --- a/packages/cli/src/lib/infra/fetchers/NodeDependencyFetcher.ts +++ b/packages/cli/src/lib/infra/fetchers/NodeDependencyFetcher.ts @@ -10,7 +10,8 @@ export class NodeDependencyFetcher extends InfraDependencyFetcher { public async installPackages(packages: InfraPackageArg[]): Promise { this.composePackageJson(packages); await runCommand( - "npm", ["i"], + "npm", + ["i"], this.config.logger, undefined, this.config.installationDirectory diff --git a/packages/cli/src/lib/system/child-process.ts b/packages/cli/src/lib/system/child-process.ts index d497f1ee26..db377f78ed 100644 --- a/packages/cli/src/lib/system/child-process.ts +++ b/packages/cli/src/lib/system/child-process.ts @@ -1,6 +1,11 @@ import { Logger } from "../logging"; -import { execFile, ExecException, execFileSync, SpawnSyncReturns } from "child_process"; +import { + execFile, + ExecException, + execFileSync, + SpawnSyncReturns, +} from "child_process"; export function runCommandSync( command: string, @@ -11,18 +16,14 @@ export function runCommandSync( logger.info(`> ${command} ${args.join(" ")}`); try { - const stdout = execFileSync( - command, - args, - { - cwd: __dirname, - env: { - ...process.env, - ...env, - }, - encoding: "utf-8", - } - ); + const stdout = execFileSync(command, args, { + cwd: __dirname, + env: { + ...process.env, + ...env, + }, + encoding: "utf-8", + }); return { stdout: stdout }; } catch (e) { return { stderr: e }; From 8ff66f7752f4ccc792c480e3f9d602cf67a91a82 Mon Sep 17 00:00:00 2001 From: krisbitney Date: Tue, 20 Dec 2022 12:51:49 +0530 Subject: [PATCH 26/38] fix merge conflicts --- packages/cli/src/commands/build.ts | 23 +- packages/cli/src/commands/codegen.ts | 21 +- packages/cli/src/commands/docgen.ts | 21 +- packages/cli/src/commands/test.ts | 19 +- .../src/lib/option-parsers/client-config.ts | 2 +- .../src/lib/option-parsers/wrapper-envs.ts | 2 +- yarn.lock | 374 ++++++++++++++++++ 7 files changed, 423 insertions(+), 39 deletions(-) diff --git a/packages/cli/src/commands/build.ts b/packages/cli/src/commands/build.ts index 47d02be57f..8b7f92fbf4 100644 --- a/packages/cli/src/commands/build.ts +++ b/packages/cli/src/commands/build.ts @@ -28,7 +28,7 @@ import path from "path"; import readline from "readline"; import { Env, PolywrapClient } from "@polywrap/client-js"; import { PolywrapManifest } from "@polywrap/polywrap-manifest-types-js"; -import { IClientConfigBuilder } from "@polywrap/client-config-builder-js"; +import { Uri } from "@polywrap/core-js"; const defaultOutputDir = "./build"; const defaultStrategy = SupportedStrategies.VM; @@ -39,11 +39,11 @@ const pathStr = intlMsg.commands_build_options_o_path(); export interface BuildCommandOptions extends BaseCommandOptions { manifestFile: string; outputDir: string; - configBuilder: IClientConfigBuilder; - wrapperEnvs: Env[]; + clientConfig: string | false; + wrapperEnvs: string | false; noCodegen: boolean; watch: boolean; - strategy: SupportedStrategies; + strategy: `${SupportedStrategies}`; } export const build: Command = { @@ -92,8 +92,8 @@ export const build: Command = { options.manifestFile, defaultPolywrapManifest ), - configBuilder: await parseClientConfigOption(options.clientConfig), - wrapperEnvs: await parseWrapperEnvsOption(options.wrapperEnvs), + clientConfig: options.clientConfig || false, + wrapperEnvs: options.wrapperEnvs || false, outputDir: parseDirOption(options.outputDir, defaultOutputDir), noCodegen: !options.codegen || false, strategy: options.strategy || defaultStrategy, @@ -145,9 +145,9 @@ async function run(options: Required) { const { watch, manifestFile, - outputDir, - configBuilder, + clientConfig, wrapperEnvs, + outputDir, strategy, noCodegen, verbose, @@ -156,8 +156,11 @@ async function run(options: Required) { } = options; const logger = createLogger({ verbose, quiet, logFile }); - if (wrapperEnvs) { - configBuilder.addEnvs(wrapperEnvs); + const envs = await parseWrapperEnvsOption(wrapperEnvs); + const configBuilder = await parseClientConfigOption(clientConfig); + + if (envs) { + configBuilder.addEnvs(envs as Env[]); } // Get Client diff --git a/packages/cli/src/commands/codegen.ts b/packages/cli/src/commands/codegen.ts index 6829ec74e5..241865f3a0 100644 --- a/packages/cli/src/commands/codegen.ts +++ b/packages/cli/src/commands/codegen.ts @@ -22,7 +22,7 @@ import { ScriptCodegenerator } from "../lib/codegen/ScriptCodeGenerator"; import { Env, PolywrapClient } from "@polywrap/client-js"; import path from "path"; import fs from "fs"; -import { IClientConfigBuilder } from "@polywrap/client-config-builder-js"; +import { Uri } from "@polywrap/core-js"; const defaultCodegenDir = "./src/wrap"; const defaultPublishDir = "./build"; @@ -35,8 +35,8 @@ export interface CodegenCommandOptions extends BaseCommandOptions { codegenDir: string; publishDir: string; script: string | false; - configBuilder: IClientConfigBuilder; - wrapperEnvs: Env[]; + clientConfig: string | false; + wrapperEnvs: string | false; } export const codegen: Command = { @@ -84,8 +84,8 @@ export const codegen: Command = { .action(async (options: Partial) => { await run({ ...options, - configBuilder: await parseClientConfigOption(options.clientConfig), - wrapperEnvs: await parseWrapperEnvsOption(options.wrapperEnvs), + clientConfig: options.clientConfig || false, + wrapperEnvs: options.wrapperEnvs || false, codegenDir: parseDirOption(options.codegenDir, defaultCodegenDir), script: parseCodegenScriptOption(options.script), manifestFile: parseManifestFileOption( @@ -104,10 +104,10 @@ export const codegen: Command = { async function run(options: Required) { const { manifestFile, + clientConfig, + wrapperEnvs, codegenDir, script, - configBuilder, - wrapperEnvs, publishDir, verbose, quiet, @@ -115,8 +115,11 @@ async function run(options: Required) { } = options; const logger = createLogger({ verbose, quiet, logFile }); - if (wrapperEnvs) { - configBuilder.addEnvs(wrapperEnvs); + const envs = await parseWrapperEnvsOption(wrapperEnvs); + const configBuilder = await parseClientConfigOption(clientConfig); + + if (envs) { + configBuilder.addEnvs(envs as Env[]); } // Get Client diff --git a/packages/cli/src/commands/docgen.ts b/packages/cli/src/commands/docgen.ts index 6636f61965..62f50ce0ee 100644 --- a/packages/cli/src/commands/docgen.ts +++ b/packages/cli/src/commands/docgen.ts @@ -21,7 +21,7 @@ import { ScriptCodegenerator } from "../lib/codegen/ScriptCodeGenerator"; import { Env, PolywrapClient } from "@polywrap/client-js"; import chalk from "chalk"; import { Argument } from "commander"; -import { IClientConfigBuilder } from "@polywrap/client-config-builder-js"; +import { Uri } from "@polywrap/core-js"; const commandToPathMap: Record = { schema: schemaScriptPath, @@ -41,8 +41,8 @@ export enum DocgenActions { export interface DocgenCommandOptions extends BaseCommandOptions { manifestFile: string; docgenDir: string; - configBuilder: IClientConfigBuilder; - wrapperEnvs: Env[]; + clientConfig: string | false; + wrapperEnvs: string | false; imports: boolean; } @@ -110,8 +110,8 @@ export const docgen: Command = { defaultProjectManifestFiles ), docgenDir: parseDirOption(options.docgenDir, defaultDocgenDir), - configBuilder: await parseClientConfigOption(options.clientConfig), - wrapperEnvs: await parseWrapperEnvsOption(options.wrapperEnvs), + clientConfig: options.clientConfig || false, + wrapperEnvs: options.wrapperEnvs || false, imports: options.imports || false, verbose: options.verbose || false, quiet: options.quiet || false, @@ -127,9 +127,9 @@ async function run( ) { const { manifestFile, - docgenDir, - configBuilder, + clientConfig, wrapperEnvs, + docgenDir, imports, verbose, quiet, @@ -137,8 +137,11 @@ async function run( } = options; const logger = createLogger({ verbose, quiet, logFile }); - if (wrapperEnvs) { - configBuilder.addEnvs(wrapperEnvs); + const envs = await parseWrapperEnvsOption(wrapperEnvs); + const configBuilder = await parseClientConfigOption(clientConfig); + + if (envs) { + configBuilder.addEnvs(envs as Env[]); } let project = await getProjectFromManifest(manifestFile, logger); diff --git a/packages/cli/src/commands/test.ts b/packages/cli/src/commands/test.ts index 87f20847f2..693f8b151c 100644 --- a/packages/cli/src/commands/test.ts +++ b/packages/cli/src/commands/test.ts @@ -23,13 +23,11 @@ import { createLogger } from "./utils/createLogger"; import path from "path"; import yaml from "yaml"; import fs from "fs"; -import { IClientConfigBuilder } from "@polywrap/client-config-builder-js"; -import { Env } from "@polywrap/core-js"; +import { Env, Uri } from "@polywrap/core-js"; export interface TestCommandOptions extends BaseCommandOptions { - configBuilder: IClientConfigBuilder; - wrapperEnvs: Env[]; clientConfig: string | false; + wrapperEnvs: string | false; manifestFile: string; jobs: string[] | false; validationScript: string | false; @@ -79,8 +77,8 @@ export const test: Command = { options.manifestFile, defaultWorkflowManifest ), - configBuilder: await parseClientConfigOption(options.clientConfig), - wrapperEnvs: await parseWrapperEnvsOption(options.wrapperEnvs), + clientConfig: options.clientConfig || false, + wrapperEnvs: options.wrapperEnvs || false, outputFile: options.outputFile ? parseWorkflowOutputFilePathOption(options.outputFile) : false, @@ -97,7 +95,7 @@ export const test: Command = { const _run = async (options: Required) => { const { manifestFile, - configBuilder, + clientConfig, wrapperEnvs, outputFile, jobs, @@ -107,8 +105,11 @@ const _run = async (options: Required) => { } = options; const logger = createLogger({ verbose, quiet, logFile }); - if (wrapperEnvs) { - configBuilder.addEnvs(wrapperEnvs); + const envs = await parseWrapperEnvsOption(wrapperEnvs); + const configBuilder = await parseClientConfigOption(clientConfig); + + if (envs) { + configBuilder.addEnvs(envs as Env[]); } const manifestPath = path.resolve(manifestFile); diff --git a/packages/cli/src/lib/option-parsers/client-config.ts b/packages/cli/src/lib/option-parsers/client-config.ts index b845cc801c..6d57d580e8 100644 --- a/packages/cli/src/lib/option-parsers/client-config.ts +++ b/packages/cli/src/lib/option-parsers/client-config.ts @@ -8,7 +8,7 @@ import { IClientConfigBuilder } from "@polywrap/client-config-builder-js"; export async function parseClientConfigOption( clientConfig: string | undefined | false -): Promise> { +): Promise { const builder = new ClientConfigBuilder().addDefaults(); try { diff --git a/packages/cli/src/lib/option-parsers/wrapper-envs.ts b/packages/cli/src/lib/option-parsers/wrapper-envs.ts index 283ac10dde..f64c6fc08f 100644 --- a/packages/cli/src/lib/option-parsers/wrapper-envs.ts +++ b/packages/cli/src/lib/option-parsers/wrapper-envs.ts @@ -8,7 +8,7 @@ import YAML from "yaml"; type WrapperEnvs = Record>; export async function parseWrapperEnvsOption( - wrapperEnvsPath: string | undefined + wrapperEnvsPath: string | false | undefined ): Promise[]> | undefined> { if (!wrapperEnvsPath) { return undefined; diff --git a/yarn.lock b/yarn.lock index f1ebe84a09..8eabd65afc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3288,6 +3288,135 @@ resolved "https://registry.yarnpkg.com/@opentelemetry/semantic-conventions/-/semantic-conventions-1.6.0.tgz#ed410c9eb0070491cff9fe914246ce41f88d6f74" integrity sha512-aPfcBeLErM/PPiAuAbNFLN5sNbZLc3KZlar27uohllN8Zs6jJbHyJU1y7cMA6W/zuq+thkaG8mujiS+3iD/FWQ== +"@polywrap/asyncify-js@0.9.3": + version "0.9.3" + resolved "https://registry.yarnpkg.com/@polywrap/asyncify-js/-/asyncify-js-0.9.3.tgz#6871f9ce4fb66e3b7d77e450a1064b352b876826" + integrity sha512-SSWlRBNYyvYAjk52Gur20KI1UyrTipF1KiPUmAbsCHfH5pFxsT6v1b2xrOuhQCIye4xIMw0nKdx+NEhFUyPe0Q== + +"@polywrap/client-config-builder-js@0.9.3": + version "0.9.3" + resolved "https://registry.yarnpkg.com/@polywrap/client-config-builder-js/-/client-config-builder-js-0.9.3.tgz#4481168454a8d27acf9e7b3200776aea0ca9fb46" + integrity sha512-ECCFV1+pr04LD1r562Ezu27TFfcAzbpEOtZz62fHD7QNZfIlVhCXbRU5x1jEj0keL4JDcS+lIfaqfyoIc8AHVA== + dependencies: + "@polywrap/core-js" "0.9.3" + "@polywrap/ens-resolver-plugin-js" "0.9.3" + "@polywrap/ethereum-plugin-js" "0.9.3" + "@polywrap/fs-plugin-js" "0.9.3" + "@polywrap/fs-resolver-plugin-js" "0.9.3" + "@polywrap/http-plugin-js" "0.9.3" + "@polywrap/http-resolver-plugin-js" "0.9.3" + "@polywrap/ipfs-plugin-js" "0.9.3" + "@polywrap/ipfs-resolver-plugin-js" "0.9.3" + "@polywrap/logger-plugin-js" "0.9.3" + "@polywrap/tracing-js" "0.9.3" + "@polywrap/uri-resolver-extensions-js" "0.9.3" + "@polywrap/uri-resolvers-js" "0.9.3" + "@polywrap/wasm-js" "0.9.3" + "@polywrap/wrap-manifest-types-js" "0.9.3" + +"@polywrap/client-js@0.9.3": + version "0.9.3" + resolved "https://registry.yarnpkg.com/@polywrap/client-js/-/client-js-0.9.3.tgz#8ab4ea62e60799c602237bbde1d82b61bb3be42a" + integrity sha512-UbX5iGjigHysB1qBVg0lLV8tuA9WlMFzJqI/VahoUv+yryHUwFkQh601kZ/UlKI1T+ZLMIksAMTJwuPQvZagJA== + dependencies: + "@polywrap/asyncify-js" "0.9.3" + "@polywrap/client-config-builder-js" "0.9.3" + "@polywrap/core-js" "0.9.3" + "@polywrap/ens-resolver-plugin-js" "0.9.3" + "@polywrap/ethereum-plugin-js" "0.9.3" + "@polywrap/fs-plugin-js" "0.9.3" + "@polywrap/fs-resolver-plugin-js" "0.9.3" + "@polywrap/http-plugin-js" "0.9.3" + "@polywrap/http-resolver-plugin-js" "0.9.3" + "@polywrap/ipfs-plugin-js" "0.9.3" + "@polywrap/ipfs-resolver-plugin-js" "0.9.3" + "@polywrap/logger-plugin-js" "0.9.3" + "@polywrap/msgpack-js" "0.9.3" + "@polywrap/result" "0.9.3" + "@polywrap/schema-parse" "0.9.3" + "@polywrap/tracing-js" "0.9.3" + "@polywrap/uri-resolvers-js" "0.9.3" + "@polywrap/wrap-manifest-types-js" "0.9.3" + graphql "15.5.0" + yaml "2.1.3" + +"@polywrap/core-js@0.10.0-pre.5": + version "0.10.0-pre.5" + resolved "https://registry.yarnpkg.com/@polywrap/core-js/-/core-js-0.10.0-pre.5.tgz#8457f168235faae19342a87aed6ddce44a56fb59" + integrity sha512-E92OGSBN5EdeYMj8wtZq4Hibh5qnAAzfSbDE40/LH6tWkrCv/gvJxtlA8gPDiMHXZFSx02zETrz7AZawCg8UXA== + dependencies: + "@polywrap/result" "0.10.0-pre.5" + "@polywrap/tracing-js" "0.10.0-pre.5" + "@polywrap/wrap-manifest-types-js" "0.10.0-pre.5" + graphql "15.5.0" + graphql-tag "2.10.4" + +"@polywrap/core-js@0.9.3": + version "0.9.3" + resolved "https://registry.yarnpkg.com/@polywrap/core-js/-/core-js-0.9.3.tgz#fd87b64e050791b9c4e1f39d95f318c638c05610" + integrity sha512-PhaoL9vlkHL4ttBga2r33Vs30wziz4hmGHWfjUMx7bxGFpnW3QQVI0dJGavaP1ZKgDKI58Dkewtk/FI8VRxyUQ== + dependencies: + "@polywrap/asyncify-js" "0.9.3" + "@polywrap/msgpack-js" "0.9.3" + "@polywrap/result" "0.9.3" + "@polywrap/tracing-js" "0.9.3" + "@polywrap/wrap-manifest-types-js" "0.9.3" + graphql "15.5.0" + graphql-tag "2.10.4" + jsonschema "1.4.0" + semver "7.3.5" + yaml "2.1.3" + +"@polywrap/ens-resolver-plugin-js@0.9.3": + version "0.9.3" + resolved "https://registry.yarnpkg.com/@polywrap/ens-resolver-plugin-js/-/ens-resolver-plugin-js-0.9.3.tgz#74c1e23ef70cb5e07170c4c5212e62dcd65d2534" + integrity sha512-DZwMgNFdTDZUh436K9cWn4t5zdePwF1UuPuAQ7MJW8fhs9m5qELhB8rMNpZUTZDG1ridxW2gRWQDeHfuTC/HtQ== + dependencies: + "@ethersproject/address" "5.0.7" + "@ethersproject/basex" "5.0.7" + "@polywrap/core-js" "0.9.3" + ethers "5.0.7" + +"@polywrap/ethereum-plugin-js@0.9.3": + version "0.9.3" + resolved "https://registry.yarnpkg.com/@polywrap/ethereum-plugin-js/-/ethereum-plugin-js-0.9.3.tgz#e982ae7dbf1f737f90b66a46c3fcf8abc3d339c4" + integrity sha512-NouMpmlZV6axfLlbRH/yBr4Btpw90QVodlx9huDD8SkXRsW9N19U3/8besQWODoC5Gmv6WajNrPYY0GoNykosg== + dependencies: + "@ethersproject/address" "5.0.7" + "@ethersproject/providers" "5.0.7" + "@polywrap/core-js" "0.9.3" + ethers "5.0.7" + +"@polywrap/fs-plugin-js@0.9.3": + version "0.9.3" + resolved "https://registry.yarnpkg.com/@polywrap/fs-plugin-js/-/fs-plugin-js-0.9.3.tgz#811d248d9bf8c3bc4607512d6c040e763fd47c2e" + integrity sha512-5o9S2nmE1poK3wHu0LdFeJn75BiNrLiJ36tJoZqmg/qQHjSFYVc0wDnVKwnea3rKtijoUC+AJvXH573ZPxu0mw== + dependencies: + "@polywrap/core-js" "0.9.3" + +"@polywrap/fs-resolver-plugin-js@0.9.3": + version "0.9.3" + resolved "https://registry.yarnpkg.com/@polywrap/fs-resolver-plugin-js/-/fs-resolver-plugin-js-0.9.3.tgz#88b7438758acf2dc2b53f78fe5c81314c07cc3c9" + integrity sha512-yyGkHhWL/zJARkwgHXS4eUH6V2yD2lx++nPD/DBLJZwQUS9PYgKJ7qSRLO9HdleY00jZUTvDDrlul2IKh6PTgw== + dependencies: + "@polywrap/core-js" "0.9.3" + +"@polywrap/http-plugin-js@0.9.3": + version "0.9.3" + resolved "https://registry.yarnpkg.com/@polywrap/http-plugin-js/-/http-plugin-js-0.9.3.tgz#11ffdcc0f6df372511ac00a69b0edca02bc78505" + integrity sha512-mpX1+YKGHDpCaJH0lHOU9aCpKHPUBg/swozSxBWyoRWRCPr1FGTougNLfL5KwYFvCFWN9oxQ+yd56W9EO83GOA== + dependencies: + "@polywrap/core-js" "0.9.3" + axios "0.21.4" + +"@polywrap/http-resolver-plugin-js@0.9.3": + version "0.9.3" + resolved "https://registry.yarnpkg.com/@polywrap/http-resolver-plugin-js/-/http-resolver-plugin-js-0.9.3.tgz#5be833c5df0f6da5b531e7166316e122d538e970" + integrity sha512-txQFmI040x4+QoYRr2hDbusNOuCKtk7MmtSE2qJv/4bS1cFZShh2pAjT2PemxwHIdM9c3AdNl7OUDZ4ibdAVVQ== + dependencies: + "@polywrap/core-js" "0.9.3" + abort-controller "3.0.0" + "@polywrap/ipfs-http-client-lite@0.3.0": version "0.3.0" resolved "https://registry.yarnpkg.com/@polywrap/ipfs-http-client-lite/-/ipfs-http-client-lite-0.3.0.tgz#b8caf4b4f39413e591aff4367023a04cb6df83a1" @@ -3304,6 +3433,27 @@ pull-stream-to-async-iterator "^1.0.2" querystring "^0.2.0" +"@polywrap/ipfs-plugin-js@0.9.3": + version "0.9.3" + resolved "https://registry.yarnpkg.com/@polywrap/ipfs-plugin-js/-/ipfs-plugin-js-0.9.3.tgz#e21117fdde673f9903640252f24b7eca3a67e51b" + integrity sha512-Rv4MixX0k8V7iujFwoEpeYVqo54Zfk/EurfsGdp8mSXuDKTFppruV5Ol4aMAe/hB4LAM/KZRbcEKocNQftbtiw== + dependencies: + "@polywrap/core-js" "0.9.3" + "@polywrap/ipfs-http-client-lite" "0.3.0" + abort-controller "3.0.0" + is-ipfs "1.0.3" + multiformats "9.7.0" + +"@polywrap/ipfs-resolver-plugin-js@0.9.3": + version "0.9.3" + resolved "https://registry.yarnpkg.com/@polywrap/ipfs-resolver-plugin-js/-/ipfs-resolver-plugin-js-0.9.3.tgz#d97fde62ba1d70c561ec26ec99a27c2d814e3b67" + integrity sha512-kr+QG7rl/5kihbVuykNhFRF+mAFG0K/7CLYzRCeylvFv98bsW3e4geDx0904IpG29bf0XX3C1WkJ1MKR2PLRlA== + dependencies: + "@polywrap/core-js" "0.9.3" + "@polywrap/ipfs-http-client-lite" "0.3.0" + abort-controller "3.0.0" + is-ipfs "1.0.3" + "@polywrap/logger-plugin-js@0.10.0": version "0.10.0" resolved "https://registry.yarnpkg.com/@polywrap/logger-plugin-js/-/logger-plugin-js-0.10.0.tgz#9fc10532e86642d7e8eb3fc7a34494cb077610bd" @@ -3312,11 +3462,188 @@ "@polywrap/core-js" "0.10.0-pre.5" "@polywrap/plugin-js" "0.10.0-pre.5" +"@polywrap/logger-plugin-js@0.9.3": + version "0.9.3" + resolved "https://registry.yarnpkg.com/@polywrap/logger-plugin-js/-/logger-plugin-js-0.9.3.tgz#602a5d30fabbe63ea2f8497a40ed8e3b0f9148d1" + integrity sha512-sNBConRr+jPnAGuuinXlX7B7zqgNel/Rji7rAI+ycUnZDFnll8zg4qJgrrVyriJpKmiosmMgxWd7uM06ahsYKw== + dependencies: + "@polywrap/core-js" "0.9.3" + +"@polywrap/msgpack-js@0.10.0-pre.5": + version "0.10.0-pre.5" + resolved "https://registry.yarnpkg.com/@polywrap/msgpack-js/-/msgpack-js-0.10.0-pre.5.tgz#c7295e2f5b299654462426afd05a02737de839c6" + integrity sha512-R0NCooOY3d4JPVz7CP6rCmOTraQe6us+b9i213z+Dgu9y8lIEZGEmX+ipCULGvAbcDrSxWHBc8ImtkX0oNv+2g== + dependencies: + "@msgpack/msgpack" "2.7.2" + +"@polywrap/msgpack-js@0.9.3": + version "0.9.3" + resolved "https://registry.yarnpkg.com/@polywrap/msgpack-js/-/msgpack-js-0.9.3.tgz#ac7925eb52918beb5ea715a584bd523507bd3b23" + integrity sha512-bWYN5fzxbnLAgInxb6KgMYJsDzcEXSmsfXO5yzOPD2mHX/x7+bqMo0c548ot06hP5RD8LfayG8Zz4ttHIUKMRA== + dependencies: + "@msgpack/msgpack" "2.7.2" + +"@polywrap/os-js@0.9.3": + version "0.9.3" + resolved "https://registry.yarnpkg.com/@polywrap/os-js/-/os-js-0.9.3.tgz#f3ffed686ab716f8d51340aee5fa356934768a9c" + integrity sha512-ypuTTtUB4gTE6jGYWhjpD6DKbuVzOXpVLdbIqIHfGmyGf3ouoNVqPsnfJ5ropN4qlpq9vnGRR9UgOUWguUmmgQ== + +"@polywrap/plugin-js@0.10.0-pre.5": + version "0.10.0-pre.5" + resolved "https://registry.yarnpkg.com/@polywrap/plugin-js/-/plugin-js-0.10.0-pre.5.tgz#5bd416cb7f52f001144222e5bc83d1e94ff23cb4" + integrity sha512-WQXJs0AOQKr+mZ4jNFECiOTpjrZCdJnKkwa5QcgyTh8Ni7qgDbDfpVbR0SsiuqdJjqFbc8aSivGnubZcg/resg== + dependencies: + "@polywrap/core-js" "0.10.0-pre.5" + "@polywrap/msgpack-js" "0.10.0-pre.5" + "@polywrap/result" "0.10.0-pre.5" + "@polywrap/tracing-js" "0.10.0-pre.5" + "@polywrap/wrap-manifest-types-js" "0.10.0-pre.5" + +"@polywrap/polywrap-manifest-schemas@0.9.3": + version "0.9.3" + resolved "https://registry.yarnpkg.com/@polywrap/polywrap-manifest-schemas/-/polywrap-manifest-schemas-0.9.3.tgz#78e8328b4971fb801758a72ca096314797a16266" + integrity sha512-VYPc9/ojZc60ly4OHjzCl/hdEw/N4DVXJ/0lljSVjR0O3bLpHfrKnaLv4WEt6mmWQhmYVylHcEWslYrIi8UinQ== + +"@polywrap/polywrap-manifest-types-js@0.9.3": + version "0.9.3" + resolved "https://registry.yarnpkg.com/@polywrap/polywrap-manifest-types-js/-/polywrap-manifest-types-js-0.9.3.tgz#7fafc57da6fd767f1d830896a5ed5a1da0f53908" + integrity sha512-0+XMYRrlIiaNByGSBSG+V6GbCsOY1Ds8pgAtGsOz8/kIV4263YQWApfRpCfPWUYqAg7zUwlfMP4o3AHh/TQ/QA== + dependencies: + "@polywrap/polywrap-manifest-schemas" "0.9.3" + jsonschema "1.4.0" + semver "7.3.5" + yaml "2.1.3" + +"@polywrap/result@0.10.0-pre.5": + version "0.10.0-pre.5" + resolved "https://registry.yarnpkg.com/@polywrap/result/-/result-0.10.0-pre.5.tgz#b703878cf7426dee0edc1a2649f79a06153b403e" + integrity sha512-5ATKBdqSS/qmSfJDrQBBq4d34b3Al381bJWJ8nWlcyt8ybo2CqHwQuv/dD02elmhS2G3EK/p/sZCbD1st8CZYw== + +"@polywrap/result@0.9.3": + version "0.9.3" + resolved "https://registry.yarnpkg.com/@polywrap/result/-/result-0.9.3.tgz#b17b2db2fd19e9740bad835e980d0e52248270ac" + integrity sha512-UJZKRxjyna5phsVIHaIPDO164siWhwCe3GhyNLhDq5RMhG3asAkhqQ8wxs09Q8e2fVBpuCtB8h9K52l5g+LPKA== + +"@polywrap/schema-bind@0.9.3": + version "0.9.3" + resolved "https://registry.yarnpkg.com/@polywrap/schema-bind/-/schema-bind-0.9.3.tgz#01f3b60af504232ba48ef812a00c04ffeb52230d" + integrity sha512-gIGmx/p5NMxgHvyJPEBVbzuzV6FZIMIWHOBA+D7aArGx/ztBSyrjPUYVD2v/x1OG7IHxSeSwlOmoHSJblA763A== + dependencies: + "@polywrap/os-js" "0.9.3" + "@polywrap/schema-parse" "0.9.3" + "@polywrap/wrap-manifest-types-js" "0.9.3" + mustache "4.0.1" + +"@polywrap/schema-compose@0.9.3": + version "0.9.3" + resolved "https://registry.yarnpkg.com/@polywrap/schema-compose/-/schema-compose-0.9.3.tgz#f697b3bdc10c29094efb264e634bcfd5008c8f3d" + integrity sha512-jWbbh7PuT2x7tCuMzzWeTQXyajLPx8Ighxbfu2JHTSb1cDTUehIbSXgznFpQkCgTQMNQwF+mL2gC1biNm8+Tdg== + dependencies: + "@polywrap/schema-parse" "0.9.3" + "@polywrap/wrap-manifest-types-js" "0.9.3" + graphql "15.5.0" + mustache "4.0.1" + +"@polywrap/schema-parse@0.9.3": + version "0.9.3" + resolved "https://registry.yarnpkg.com/@polywrap/schema-parse/-/schema-parse-0.9.3.tgz#8bdbc3d0f406554acaa2ea82a9cdc2a2a3f3d05e" + integrity sha512-Zu7CxsyPNeY4yG2eFdoO1p3Ryn8+G2FQ26X5HvIdiVP6OU2yutUec5SdgtCsZkQD7b7WpSZtQExOYUIWxHH8Cg== + dependencies: + "@dorgjelli/graphql-schema-cycles" "1.1.4" + "@polywrap/wrap-manifest-types-js" "0.9.3" + graphql "15.5.0" + +"@polywrap/test-env-js@0.9.3": + version "0.9.3" + resolved "https://registry.yarnpkg.com/@polywrap/test-env-js/-/test-env-js-0.9.3.tgz#e127786fed63b15ac3e456880c6072d694f733b9" + integrity sha512-N5IxbmKAbQPdgzPFd+gLZHLuWe3dGSRmbCAvdme5uIs36MofuE3aARVmenp6w907n1+y54zu6EwXkh0jGa+98g== + dependencies: + "@polywrap/core-js" "0.9.3" + "@polywrap/polywrap-manifest-types-js" "0.9.3" + axios "0.21.2" + spawn-command "0.0.2-1" + yaml "2.1.3" + +"@polywrap/tracing-js@0.10.0-pre.5": + version "0.10.0-pre.5" + resolved "https://registry.yarnpkg.com/@polywrap/tracing-js/-/tracing-js-0.10.0-pre.5.tgz#3408c469c64a1f4e6f059f40d04c6b6e6328e76f" + integrity sha512-7sUl3K1rCuCxr6LJ2mucf4KcvUgpNbyhiv7Q68BOFEzFgJCpai6IGi4domgYvz/MPsanqVhkMwdf5D1iuK6PwQ== + dependencies: + "@fetsorn/opentelemetry-console-exporter" "0.0.3" + "@opentelemetry/api" "1.2.0" + "@opentelemetry/exporter-trace-otlp-http" "0.32.0" + "@opentelemetry/resources" "1.6.0" + "@opentelemetry/sdk-trace-base" "1.6.0" + "@opentelemetry/sdk-trace-web" "1.6.0" + +"@polywrap/tracing-js@0.9.3": + version "0.9.3" + resolved "https://registry.yarnpkg.com/@polywrap/tracing-js/-/tracing-js-0.9.3.tgz#3071edf1b61799617174ed49ffca3936437aca92" + integrity sha512-IuAn14WeV/dm/e3LUI3DF4fx2ohbEF8m09G7dhupII0jgSi1LnMuv0+VEqTqZuJ17nosq0SaRyG3eKKa6JROMA== + dependencies: + "@fetsorn/opentelemetry-console-exporter" "0.0.3" + "@opentelemetry/api" "1.2.0" + "@opentelemetry/exporter-trace-otlp-http" "0.32.0" + "@opentelemetry/resources" "1.6.0" + "@opentelemetry/sdk-trace-base" "1.6.0" + "@opentelemetry/sdk-trace-web" "1.6.0" + +"@polywrap/uri-resolver-extensions-js@0.9.3": + version "0.9.3" + resolved "https://registry.yarnpkg.com/@polywrap/uri-resolver-extensions-js/-/uri-resolver-extensions-js-0.9.3.tgz#65c3cf7126fe813aa23b81de2abcfefd63101126" + integrity sha512-WPT7nHi7AjwIRGpmdWefR0pxCkSt+p3fWdHuNvhol63+LrZoM+tfTPFYVQZpj9I8Cw+rVf0ZDWBbvSIHkFugpA== + dependencies: + "@polywrap/core-js" "0.9.3" + "@polywrap/result" "0.9.3" + "@polywrap/uri-resolvers-js" "0.9.3" + "@polywrap/wasm-js" "0.9.3" + "@polywrap/wrap-manifest-types-js" "0.9.3" + +"@polywrap/uri-resolvers-js@0.9.3": + version "0.9.3" + resolved "https://registry.yarnpkg.com/@polywrap/uri-resolvers-js/-/uri-resolvers-js-0.9.3.tgz#f3670395bc987c82d4662fe2fbaadb3e7a41f436" + integrity sha512-ziCHgRT6VlrJqX0bepyLFxtTIs6AItiBBNBKDamOF3Xt8qkjJ1tdyLN1j5N8EPtwjXVLyMgQ+pnxbDDMFBeXMg== + dependencies: + "@polywrap/core-js" "0.9.3" + "@polywrap/result" "0.9.3" + "@polywrap/wrap-manifest-types-js" "0.9.3" + +"@polywrap/wasm-js@0.9.3": + version "0.9.3" + resolved "https://registry.yarnpkg.com/@polywrap/wasm-js/-/wasm-js-0.9.3.tgz#5d77c3b5526d60153dedee35c84efeea831ac3e1" + integrity sha512-OyMIJ+OqEGrfUCsTgZ9QzK2kwNY+1/Cq/Vwt6maEN1z3buIu68VqIqiS3bYZ43XpRp+Wq+ud3edVThP6zN88cQ== + dependencies: + "@polywrap/asyncify-js" "0.9.3" + "@polywrap/core-js" "0.9.3" + "@polywrap/msgpack-js" "0.9.3" + "@polywrap/result" "0.9.3" + "@polywrap/tracing-js" "0.9.3" + "@polywrap/wrap-manifest-types-js" "0.9.3" + "@polywrap/wrap-manifest-schemas@0.9.3": version "0.9.3" resolved "https://registry.yarnpkg.com/@polywrap/wrap-manifest-schemas/-/wrap-manifest-schemas-0.9.3.tgz#cdf950bb8951fba72afd8300aaf9a0a8159d7c37" integrity sha512-+IW/NEnJUlZKIL+UCpiTThHbvgEek6qWjkTCX1glPh6Q6sryFZ/X37sb9PkRuxiHi7ZMWBZt9hnNPhvTAdgL3A== +"@polywrap/wrap-manifest-types-js@0.10.0-pre.5": + version "0.10.0-pre.5" + resolved "https://registry.yarnpkg.com/@polywrap/wrap-manifest-types-js/-/wrap-manifest-types-js-0.10.0-pre.5.tgz#bf37741becd9856458400f4f972f8c4a4fc1ac5e" + integrity sha512-7IbPpt76PXjhBkd8SPJARw4P9bpekb44YdrnsKXTeT5d8JQ5OgY4syiMVsmTraMdmHJxkJTZ/raqSZHLAxWLiw== + dependencies: + json-schema-ref-parser "9.0.9" + jsonschema "1.4.0" + semver "7.3.5" + +"@polywrap/wrap-manifest-types-js@0.9.3": + version "0.9.3" + resolved "https://registry.yarnpkg.com/@polywrap/wrap-manifest-types-js/-/wrap-manifest-types-js-0.9.3.tgz#72a80661f3f2fc29902c6c6ee7953bd2699bb691" + integrity sha512-InAHrO9jchtcK3hZshRezPTSpDb+ZI8MiKB6r50BqiC2LkHnNHShKARcCQPAEOFrc0RZnlf6t21LIutwkMuibw== + dependencies: + "@polywrap/msgpack-js" "0.9.3" + json-schema-ref-parser "9.0.9" + jsonschema "1.4.0" + semver "7.3.5" + "@sinclair/typebox@^0.24.1": version "0.24.51" resolved "https://registry.yarnpkg.com/@sinclair/typebox/-/typebox-0.24.51.tgz#645f33fe4e02defe26f2f5c0410e1c094eac7f5f" @@ -13667,6 +13994,53 @@ pnp-webpack-plugin@1.6.4: dependencies: ts-pnp "^1.1.6" +polywrap@0.9.3: + version "0.9.3" + resolved "https://registry.yarnpkg.com/polywrap/-/polywrap-0.9.3.tgz#335d75d0b2c0350732649f004c5e67b252120e35" + integrity sha512-ALBN5d74tgf8FjEFS9yz9F7SJBkP7cOEnjix8KmtkUmT6NfnGuVlsF1jTVBLlbmc75uvJGfv0kGJTXaFyOYUxQ== + dependencies: + "@ethersproject/providers" "5.6.8" + "@ethersproject/wallet" "5.6.2" + "@formatjs/intl" "1.8.2" + "@polywrap/asyncify-js" "0.9.3" + "@polywrap/client-config-builder-js" "0.9.3" + "@polywrap/client-js" "0.9.3" + "@polywrap/core-js" "0.9.3" + "@polywrap/ens-resolver-plugin-js" "0.9.3" + "@polywrap/ethereum-plugin-js" "0.9.3" + "@polywrap/ipfs-plugin-js" "0.9.3" + "@polywrap/msgpack-js" "0.9.3" + "@polywrap/os-js" "0.9.3" + "@polywrap/polywrap-manifest-types-js" "0.9.3" + "@polywrap/schema-bind" "0.9.3" + "@polywrap/schema-compose" "0.9.3" + "@polywrap/schema-parse" "0.9.3" + "@polywrap/test-env-js" "0.9.3" + "@polywrap/wasm-js" "0.9.3" + "@polywrap/wrap-manifest-types-js" "0.9.3" + axios "0.21.2" + chalk "4.1.0" + chokidar "3.5.1" + commander "9.2.0" + content-hash "2.5.2" + copyfiles "2.4.1" + docker-compose "0.23.17" + extract-zip "2.0.1" + form-data "4.0.0" + fs-extra "9.0.1" + ipfs-http-client "48.1.3" + json-schema "0.4.0" + json-schema-ref-parser "9.0.9" + jsonschema "1.4.0" + mustache "4.0.1" + os-locale "5.0.0" + regex-parser "2.2.11" + rimraf "3.0.2" + toml "3.0.0" + typescript "4.1.6" + yaml "2.1.3" + yesno "0.4.0" + portfinder@^1.0.25: version "1.0.32" resolved "https://registry.yarnpkg.com/portfinder/-/portfinder-1.0.32.tgz#2fe1b9e58389712429dc2bea5beb2146146c7f81" From 7a17f16220f75d93eabbe9f55bbfbc44ce882601 Mon Sep 17 00:00:00 2001 From: Jordan Ellis <5522128+dOrgJelli@users.noreply.github.com> Date: Wed, 21 Dec 2022 22:19:55 -0600 Subject: [PATCH 27/38] Update package.json --- packages/js/cli/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/js/cli/package.json b/packages/js/cli/package.json index bca393ba14..9a7d1a1498 100644 --- a/packages/js/cli/package.json +++ b/packages/js/cli/package.json @@ -1,7 +1,7 @@ { "name": "@polywrap/cli-js", "description": "Programmatically execute the Polywrap CLI", - "version": "0.9.3", + "version": "0.10.0-pre.6", "license": "MIT", "repository": { "type": "git", @@ -18,7 +18,7 @@ "test:ci": "jest --passWithNoTests --runInBand --detectOpenHandles --verbose" }, "dependencies": { - "polywrap": "0.9.3", + "polywrap": "0.10.0-pre.6", "spawn-command": "0.0.2-1" }, "devDependencies": { From 1871844fcf3e5408d270ce70ed1cf28d127aa82e Mon Sep 17 00:00:00 2001 From: krisbitney Date: Fri, 30 Dec 2022 16:20:54 +0530 Subject: [PATCH 28/38] using execSync and exec in CLI instead of execFileSync and execFile --- packages/cli/src/lib/system/child-process.ts | 14 ++-- yarn.lock | 68 -------------------- 2 files changed, 4 insertions(+), 78 deletions(-) diff --git a/packages/cli/src/lib/system/child-process.ts b/packages/cli/src/lib/system/child-process.ts index db377f78ed..1c86c0f855 100644 --- a/packages/cli/src/lib/system/child-process.ts +++ b/packages/cli/src/lib/system/child-process.ts @@ -1,11 +1,6 @@ import { Logger } from "../logging"; -import { - execFile, - ExecException, - execFileSync, - SpawnSyncReturns, -} from "child_process"; +import { ExecException, SpawnSyncReturns, execSync, exec } from "child_process"; export function runCommandSync( command: string, @@ -16,7 +11,7 @@ export function runCommandSync( logger.info(`> ${command} ${args.join(" ")}`); try { - const stdout = execFileSync(command, args, { + const stdout = execSync(`${command} ${args.join(" ")}`, { cwd: __dirname, env: { ...process.env, @@ -53,9 +48,8 @@ export async function runCommand( } }; - const childObj = execFile( - command, - args, + const childObj = exec( + `${command} ${args.join(" ")}`, { cwd: cwd ?? __dirname, env: { diff --git a/yarn.lock b/yarn.lock index 3e62bbbeba..f0b7604aae 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3315,27 +3315,6 @@ pull-stream-to-async-iterator "^1.0.2" querystring "^0.2.0" -"@polywrap/ipfs-plugin-js@0.9.3": - version "0.9.3" - resolved "https://registry.yarnpkg.com/@polywrap/ipfs-plugin-js/-/ipfs-plugin-js-0.9.3.tgz#e21117fdde673f9903640252f24b7eca3a67e51b" - integrity sha512-Rv4MixX0k8V7iujFwoEpeYVqo54Zfk/EurfsGdp8mSXuDKTFppruV5Ol4aMAe/hB4LAM/KZRbcEKocNQftbtiw== - dependencies: - "@polywrap/core-js" "0.9.3" - "@polywrap/ipfs-http-client-lite" "0.3.0" - abort-controller "3.0.0" - is-ipfs "1.0.3" - multiformats "9.7.0" - -"@polywrap/ipfs-resolver-plugin-js@0.9.3": - version "0.9.3" - resolved "https://registry.yarnpkg.com/@polywrap/ipfs-resolver-plugin-js/-/ipfs-resolver-plugin-js-0.9.3.tgz#d97fde62ba1d70c561ec26ec99a27c2d814e3b67" - integrity sha512-kr+QG7rl/5kihbVuykNhFRF+mAFG0K/7CLYzRCeylvFv98bsW3e4geDx0904IpG29bf0XX3C1WkJ1MKR2PLRlA== - dependencies: - "@polywrap/core-js" "0.9.3" - "@polywrap/ipfs-http-client-lite" "0.3.0" - abort-controller "3.0.0" - is-ipfs "1.0.3" - "@polywrap/logger-plugin-js@0.10.0": version "0.10.0" resolved "https://registry.yarnpkg.com/@polywrap/logger-plugin-js/-/logger-plugin-js-0.10.0.tgz#9fc10532e86642d7e8eb3fc7a34494cb077610bd" @@ -13683,53 +13662,6 @@ pnp-webpack-plugin@1.6.4: dependencies: ts-pnp "^1.1.6" -polywrap@0.9.3: - version "0.9.3" - resolved "https://registry.yarnpkg.com/polywrap/-/polywrap-0.9.3.tgz#335d75d0b2c0350732649f004c5e67b252120e35" - integrity sha512-ALBN5d74tgf8FjEFS9yz9F7SJBkP7cOEnjix8KmtkUmT6NfnGuVlsF1jTVBLlbmc75uvJGfv0kGJTXaFyOYUxQ== - dependencies: - "@ethersproject/providers" "5.6.8" - "@ethersproject/wallet" "5.6.2" - "@formatjs/intl" "1.8.2" - "@polywrap/asyncify-js" "0.9.3" - "@polywrap/client-config-builder-js" "0.9.3" - "@polywrap/client-js" "0.9.3" - "@polywrap/core-js" "0.9.3" - "@polywrap/ens-resolver-plugin-js" "0.9.3" - "@polywrap/ethereum-plugin-js" "0.9.3" - "@polywrap/ipfs-plugin-js" "0.9.3" - "@polywrap/msgpack-js" "0.9.3" - "@polywrap/os-js" "0.9.3" - "@polywrap/polywrap-manifest-types-js" "0.9.3" - "@polywrap/schema-bind" "0.9.3" - "@polywrap/schema-compose" "0.9.3" - "@polywrap/schema-parse" "0.9.3" - "@polywrap/test-env-js" "0.9.3" - "@polywrap/wasm-js" "0.9.3" - "@polywrap/wrap-manifest-types-js" "0.9.3" - axios "0.21.2" - chalk "4.1.0" - chokidar "3.5.1" - commander "9.2.0" - content-hash "2.5.2" - copyfiles "2.4.1" - docker-compose "0.23.17" - extract-zip "2.0.1" - form-data "4.0.0" - fs-extra "9.0.1" - ipfs-http-client "48.1.3" - json-schema "0.4.0" - json-schema-ref-parser "9.0.9" - jsonschema "1.4.0" - mustache "4.0.1" - os-locale "5.0.0" - regex-parser "2.2.11" - rimraf "3.0.2" - toml "3.0.0" - typescript "4.1.6" - yaml "2.1.3" - yesno "0.4.0" - portfinder@^1.0.25: version "1.0.32" resolved "https://registry.yarnpkg.com/portfinder/-/portfinder-1.0.32.tgz#2fe1b9e58389712429dc2bea5beb2146146c7f81" From e90e312447364b2ac5a0999b98c017054e1c5b47 Mon Sep 17 00:00:00 2001 From: krisbitney Date: Mon, 2 Jan 2023 21:39:35 +0530 Subject: [PATCH 29/38] fixed cwd used in local build strategy and help text from build cmd --- packages/cli/src/__tests__/e2e/build.spec.ts | 6 +++--- .../src/lib/build-strategies/strategies/LocalStrategy.ts | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/cli/src/__tests__/e2e/build.spec.ts b/packages/cli/src/__tests__/e2e/build.spec.ts index bebe53750a..ff029ae06f 100644 --- a/packages/cli/src/__tests__/e2e/build.spec.ts +++ b/packages/cli/src/__tests__/e2e/build.spec.ts @@ -21,7 +21,7 @@ Options: envs -n, --no-codegen Skip code generation -s, --strategy Strategy to use for building the wrapper - (default: "vm") + (default: vm) -w, --watch Automatically rebuild when changes are made (default: false) -v, --verbose Verbose output (default: false) @@ -108,7 +108,7 @@ describe("e2e tests for build command", () => { } }; - it("Should show help text", async () => { + it.only("Should show help text", async () => { const { exitCode: code, stdout: output, stderr: error } = await runCLI({ args: ["build", "--help"], cwd: getTestCaseDir(0), @@ -229,7 +229,7 @@ describe("e2e tests for build command", () => { }); }) - describe("Local strategy", () => { + describe.only("Local strategy", () => { // Local strategy runs `yarn` by default, so we need to ensure that we clean up lockfiles const cleanupYarnLockfiles = async () => { diff --git a/packages/cli/src/lib/build-strategies/strategies/LocalStrategy.ts b/packages/cli/src/lib/build-strategies/strategies/LocalStrategy.ts index 51c8f3bffc..7813527a98 100644 --- a/packages/cli/src/lib/build-strategies/strategies/LocalStrategy.ts +++ b/packages/cli/src/lib/build-strategies/strategies/LocalStrategy.ts @@ -40,7 +40,9 @@ export class LocalBuildStrategy extends BuildStrategy { runCommand( scriptPath, [polywrapModuleDir, this.outputDir], - logger + logger, + undefined, + process.cwd() ) ); } From 9eeae0ae0d4892b4a55c5634a3bb466a58bce3e8 Mon Sep 17 00:00:00 2001 From: krisbitney Date: Mon, 2 Jan 2023 22:20:05 +0530 Subject: [PATCH 30/38] removed console log form infra command and updated infra test to use updated syntax for listing multiple modules --- packages/cli/src/__tests__/e2e/infra.spec.ts | 10 +++++----- packages/cli/src/commands/infra.ts | 2 -- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/packages/cli/src/__tests__/e2e/infra.spec.ts b/packages/cli/src/__tests__/e2e/infra.spec.ts index 059e38de5c..a9a5be9cbc 100644 --- a/packages/cli/src/__tests__/e2e/infra.spec.ts +++ b/packages/cli/src/__tests__/e2e/infra.spec.ts @@ -316,7 +316,7 @@ describe("e2e tests for infra command", () => { [ "infra", "config", - "--modules=notExistingModule,alsoNotExisting", + "--modules notExistingModule alsoNotExisting", ], getTestCaseDir(0), ); @@ -430,7 +430,7 @@ describe("e2e tests for infra command", () => { [ "infra", "up", - "--modules=ganache,dev-server" + "--modules=ganache dev-server" ], getTestCaseDir(1), ); @@ -441,7 +441,7 @@ describe("e2e tests for infra command", () => { ]); await runPolywrapCli( - ["infra", "down", "--modules=ganache,dev-server"], + ["infra", "down", "--modules=ganache dev-server"], getTestCaseDir(1), ); }); @@ -451,7 +451,7 @@ describe("e2e tests for infra command", () => { [ "infra", "up", - "--modules=ipfs,ipfs-duplicate" + "--modules=ipfs ipfs-duplicate" ], getTestCaseDir(1), ); @@ -461,7 +461,7 @@ describe("e2e tests for infra command", () => { ]); await runPolywrapCli( - ["infra", "down", "--modules=ipfs,ipfs-duplicate"], + ["infra", "down", "--modules=ipfs ipfs-duplicate"], getTestCaseDir(1), ); }); diff --git a/packages/cli/src/commands/infra.ts b/packages/cli/src/commands/infra.ts index b46c2c84e3..8fc7c2ac9e 100644 --- a/packages/cli/src/commands/infra.ts +++ b/packages/cli/src/commands/infra.ts @@ -112,8 +112,6 @@ async function run( const modulesArray: string[] = modules ? modules : []; - console.log(modulesArray); - const manifest: string[] = manifestFile ? [manifestFile] : defaultInfraManifest; From f2c71b98220b387655910ffb05b80f23f3fa89f0 Mon Sep 17 00:00:00 2001 From: krisbitney Date: Mon, 2 Jan 2023 22:21:18 +0530 Subject: [PATCH 31/38] removed leftover .only markers from cli build.spec.ts --- packages/cli/src/__tests__/e2e/build.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/__tests__/e2e/build.spec.ts b/packages/cli/src/__tests__/e2e/build.spec.ts index ff029ae06f..e8eeabf4b6 100644 --- a/packages/cli/src/__tests__/e2e/build.spec.ts +++ b/packages/cli/src/__tests__/e2e/build.spec.ts @@ -108,7 +108,7 @@ describe("e2e tests for build command", () => { } }; - it.only("Should show help text", async () => { + it("Should show help text", async () => { const { exitCode: code, stdout: output, stderr: error } = await runCLI({ args: ["build", "--help"], cwd: getTestCaseDir(0), @@ -229,7 +229,7 @@ describe("e2e tests for build command", () => { }); }) - describe.only("Local strategy", () => { + describe("Local strategy", () => { // Local strategy runs `yarn` by default, so we need to ensure that we clean up lockfiles const cleanupYarnLockfiles = async () => { From 265b9b329bc714c585fd13a5f8b3dfe6b05c535f Mon Sep 17 00:00:00 2001 From: dOrgJelli Date: Tue, 3 Jan 2023 19:09:16 -0500 Subject: [PATCH 32/38] fix: infra tests --- packages/cli/src/__tests__/e2e/infra.spec.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/cli/src/__tests__/e2e/infra.spec.ts b/packages/cli/src/__tests__/e2e/infra.spec.ts index a9a5be9cbc..f8017beb58 100644 --- a/packages/cli/src/__tests__/e2e/infra.spec.ts +++ b/packages/cli/src/__tests__/e2e/infra.spec.ts @@ -436,8 +436,7 @@ describe("e2e tests for infra command", () => { ); await waitForPorts([ - { port: 8546, expected: true }, - { port: 8545, expected: true } + { port: 8546, expected: true } ]); await runPolywrapCli( From ece1d33f7af4b9f22b7405fc15ac4d3435667a2c Mon Sep 17 00:00:00 2001 From: dOrgJelli Date: Tue, 3 Jan 2023 22:25:55 -0500 Subject: [PATCH 33/38] fix: js cli build test --- packages/js/cli/src/__tests__/commands.spec.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/js/cli/src/__tests__/commands.spec.ts b/packages/js/cli/src/__tests__/commands.spec.ts index accae6de5d..1e2eaa8a60 100644 --- a/packages/js/cli/src/__tests__/commands.spec.ts +++ b/packages/js/cli/src/__tests__/commands.spec.ts @@ -59,10 +59,14 @@ const testData: CommandTestCaseData = { build: [{ options: { strategy: "vm" }, cwd: path.join(GetPathToCliTestFiles(), "wasm/build-cmd/assemblyscript/001-sanity"), - before: (test) => { + before: async (test) => { // clear build dir if (!test.cwd) throw Error("This shouldn't happen"); clearDir(path.join(test.cwd, "build")); + await Commands.codegen( + undefined, + { cwd: test.cwd, cli: test.cli } + ); }, after: (test) => { // check for build dir and artifacts From a910c1eeeb59ad5b8577670cc1d87c5ce360133d Mon Sep 17 00:00:00 2001 From: dOrgJelli Date: Tue, 3 Jan 2023 22:39:10 -0500 Subject: [PATCH 34/38] chore: use codegen option --- packages/js/cli/src/__tests__/commands.spec.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/packages/js/cli/src/__tests__/commands.spec.ts b/packages/js/cli/src/__tests__/commands.spec.ts index 1e2eaa8a60..e8050eb8c2 100644 --- a/packages/js/cli/src/__tests__/commands.spec.ts +++ b/packages/js/cli/src/__tests__/commands.spec.ts @@ -57,16 +57,12 @@ const clearDir = (dir: string) => { const testData: CommandTestCaseData = { build: [{ - options: { strategy: "vm" }, + options: { strategy: "vm", codegen: true }, cwd: path.join(GetPathToCliTestFiles(), "wasm/build-cmd/assemblyscript/001-sanity"), before: async (test) => { // clear build dir if (!test.cwd) throw Error("This shouldn't happen"); clearDir(path.join(test.cwd, "build")); - await Commands.codegen( - undefined, - { cwd: test.cwd, cli: test.cli } - ); }, after: (test) => { // check for build dir and artifacts From 9ac70e97e844159dd854866965b1e5bc21f52950 Mon Sep 17 00:00:00 2001 From: dOrgJelli Date: Tue, 3 Jan 2023 22:43:49 -0500 Subject: [PATCH 35/38] chore: fix pre-step for test command --- packages/js/cli/src/__tests__/commands.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/js/cli/src/__tests__/commands.spec.ts b/packages/js/cli/src/__tests__/commands.spec.ts index e8050eb8c2..56edc81552 100644 --- a/packages/js/cli/src/__tests__/commands.spec.ts +++ b/packages/js/cli/src/__tests__/commands.spec.ts @@ -208,7 +208,7 @@ const testData: CommandTestCaseData = { if (!test.cwd) throw Error("This shouldn't happen"); const wrapperPath = path.join(test.cwd, "../run-test-wrapper"); - await Commands.build(undefined, { cwd: wrapperPath }); + await Commands.build({ codegen: true }, { cwd: wrapperPath }); }, after: (_, stdout, __, exitCode) => { expect(stdout).toContain("Data: "); From bc61e97b0e094004cd375b6bb5ea7fa8fe79d0d9 Mon Sep 17 00:00:00 2001 From: dOrgJelli Date: Wed, 4 Jan 2023 13:03:25 -0500 Subject: [PATCH 36/38] fix tests --- packages/cli/src/__tests__/e2e/build-rs.spec.ts | 2 +- packages/cli/src/__tests__/e2e/build.wasm.spec.ts | 2 +- packages/js/client/src/__tests__/core/sanity.spec.ts | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/cli/src/__tests__/e2e/build-rs.spec.ts b/packages/cli/src/__tests__/e2e/build-rs.spec.ts index 0238e7a15b..a2c767b6c9 100644 --- a/packages/cli/src/__tests__/e2e/build-rs.spec.ts +++ b/packages/cli/src/__tests__/e2e/build-rs.spec.ts @@ -5,7 +5,7 @@ import { GetPathToCliTestFiles } from "@polywrap/test-cases"; import fs from "fs"; import path from "path"; -jest.setTimeout(700000); +jest.setTimeout(1200000); describe("e2e tests for build command", () => { const testCaseRoot = path.join(GetPathToCliTestFiles(), "wasm/build-cmd/rust"); diff --git a/packages/cli/src/__tests__/e2e/build.wasm.spec.ts b/packages/cli/src/__tests__/e2e/build.wasm.spec.ts index 2ddd7e0b6f..f15b9eb65e 100644 --- a/packages/cli/src/__tests__/e2e/build.wasm.spec.ts +++ b/packages/cli/src/__tests__/e2e/build.wasm.spec.ts @@ -24,7 +24,7 @@ Options: --wrapper-envs Path to a JSON file containing wrapper envs -s, --strategy Strategy to use for building the wrapper - (default: "vm") + (default: vm) -w, --watch Automatically rebuild when changes are made (default: false) -v, --verbose Verbose output (default: false) diff --git a/packages/js/client/src/__tests__/core/sanity.spec.ts b/packages/js/client/src/__tests__/core/sanity.spec.ts index 143a5455d8..88e9e9c956 100644 --- a/packages/js/client/src/__tests__/core/sanity.spec.ts +++ b/packages/js/client/src/__tests__/core/sanity.spec.ts @@ -11,7 +11,7 @@ import { buildWrapper } from "@polywrap/test-env-js"; import { ResultErr } from "@polywrap/result"; import { StaticResolver, UriResolverLike } from "@polywrap/uri-resolvers-js"; import { WasmPackage } from "@polywrap/wasm-js"; -import { defaultWrappers } from "@polywrap/client-config-builder-js"; +import { defaultInterfaces } from "@polywrap/client-config-builder-js"; jest.setTimeout(200000); @@ -36,7 +36,7 @@ describe("sanity", () => { implementations: [new Uri("wrap://plugin/logger")], }, { - interface: new Uri(defaultWrappers.concurrentInterface), + interface: new Uri(defaultInterfaces.concurrent), implementations: [new Uri("wrap://plugin/concurrent")], }, ]); From ea446fc7b2a24f1e942ccc01eac597778b179a2a Mon Sep 17 00:00:00 2001 From: dOrgJelli Date: Wed, 4 Jan 2023 13:28:14 -0500 Subject: [PATCH 37/38] fix: properly parse option arrays --- packages/cli/src/__tests__/e2e/infra.spec.ts | 29 ++++++++++---------- packages/cli/src/commands/infra.ts | 7 ++++- packages/cli/src/commands/test.ts | 15 +++++++++- 3 files changed, 35 insertions(+), 16 deletions(-) diff --git a/packages/cli/src/__tests__/e2e/infra.spec.ts b/packages/cli/src/__tests__/e2e/infra.spec.ts index f8017beb58..f844e49f3e 100644 --- a/packages/cli/src/__tests__/e2e/infra.spec.ts +++ b/packages/cli/src/__tests__/e2e/infra.spec.ts @@ -119,7 +119,7 @@ describe("e2e tests for infra command", () => { ); await runPolywrapCli( - ["infra", "down", "-v", "--modules=eth-ens-ipfs"], + ["infra", "down", "-v", "--modules eth-ens-ipfs"], getTestCaseDir(0), ); @@ -222,7 +222,7 @@ describe("e2e tests for infra command", () => { it("Should correctly open one process for default module because modules flag overwrites it", async () => { await runPolywrapCli( - ["infra", "up", "--modules=eth-ens-ipfs"], + ["infra", "up", "--modules eth-ens-ipfs"], getTestCaseDir(4), ); @@ -231,7 +231,7 @@ describe("e2e tests for infra command", () => { ]); await runPolywrapCli( - ["infra", "down", "--modules=eth-ens-ipfs"], + ["infra", "down", "--modules eth-ens-ipfs"], getTestCaseDir(4), ); }); @@ -291,7 +291,7 @@ describe("e2e tests for infra command", () => { it("Should set environment up with only selected modules", async () => { await runPolywrapCli( - ["infra", "up", "--modules=ipfs"], + ["infra", "up", "--modules ipfs"], getTestCaseDir(0), ); @@ -302,7 +302,7 @@ describe("e2e tests for infra command", () => { ]); await runPolywrapCli( - ["infra", "down", "--modules=ipfs"], + ["infra", "down", "--modules ipfs"], getTestCaseDir(0), ); @@ -332,7 +332,7 @@ describe("e2e tests for infra command", () => { [ "infra", "up", - "--modules=eth-ens-ipfs", + "--modules eth-ens-ipfs", "--verbose" ], getTestCaseDir(0), @@ -349,7 +349,7 @@ describe("e2e tests for infra command", () => { [ "infra", "config", - "--modules=eth-ens-ipfs", + "--modules eth-ens-ipfs", "--verbose" ], getTestCaseDir(2), @@ -363,7 +363,7 @@ describe("e2e tests for infra command", () => { [ "infra", "config", - "--modules=eth-ens-ipfs", + "--modules eth-ens-ipfs", "--verbose" ], getTestCaseDir(0), @@ -380,7 +380,7 @@ describe("e2e tests for infra command", () => { [ "infra", "up", - "--modules=eth-ens-ipfs", + "--modules eth-ens-ipfs", "--verbose" ], getTestCaseDir(3), @@ -430,17 +430,18 @@ describe("e2e tests for infra command", () => { [ "infra", "up", - "--modules=ganache dev-server" + "--modules ganache,dev-server" ], getTestCaseDir(1), ); await waitForPorts([ - { port: 8546, expected: true } + { port: 8546, expected: true }, + { port: 8545, expected: true } ]); await runPolywrapCli( - ["infra", "down", "--modules=ganache dev-server"], + ["infra", "down", "--modules ganache,dev-server"], getTestCaseDir(1), ); }); @@ -450,7 +451,7 @@ describe("e2e tests for infra command", () => { [ "infra", "up", - "--modules=ipfs ipfs-duplicate" + "--modules ipfs,ipfs-duplicate" ], getTestCaseDir(1), ); @@ -460,7 +461,7 @@ describe("e2e tests for infra command", () => { ]); await runPolywrapCli( - ["infra", "down", "--modules=ipfs ipfs-duplicate"], + ["infra", "down", "--modules ipfs,ipfs-duplicate"], getTestCaseDir(1), ); }); diff --git a/packages/cli/src/commands/infra.ts b/packages/cli/src/commands/infra.ts index 8fc7c2ac9e..15a92a4301 100644 --- a/packages/cli/src/commands/infra.ts +++ b/packages/cli/src/commands/infra.ts @@ -110,7 +110,12 @@ async function run( const logger = createLogger({ verbose, quiet, logFile }); - const modulesArray: string[] = modules ? modules : []; + const modulesArray: string[] = []; + if (modules) { + modules.forEach((x) => modulesArray.push( + ...(x.includes(",") ? x.split(",") : [x]) + )); + } const manifest: string[] = manifestFile ? [manifestFile] diff --git a/packages/cli/src/commands/test.ts b/packages/cli/src/commands/test.ts index 693f8b151c..fdb5f143a7 100644 --- a/packages/cli/src/commands/test.ts +++ b/packages/cli/src/commands/test.ts @@ -114,7 +114,20 @@ const _run = async (options: Required) => { const manifestPath = path.resolve(manifestFile); const workflow = await loadWorkflowManifest(manifestPath, logger); + validateJobNames(workflow.jobs); + + const jobsArray: string[] = []; + if (jobs) { + jobs.forEach((x) => jobsArray.push( + ...(x.includes(",") ? x.split(",") : [x]) + )); + } else { + jobsArray.push( + ...Object.keys(workflow.jobs) + ); + } + const validationScript = workflow.validation ? loadValidationScript(manifestPath, workflow.validation) : undefined; @@ -144,7 +157,7 @@ const _run = async (options: Required) => { }; const jobRunner = new JobRunner(configBuilder, onExecution); - await jobRunner.run(workflow.jobs, jobs || Object.keys(workflow.jobs)); + await jobRunner.run(workflow.jobs, jobsArray); if (outputFile) { const outputFileExt = path.extname(outputFile).substring(1); From 1434836e41e1141a20b7bc72054b338bbb08a60f Mon Sep 17 00:00:00 2001 From: dOrgJelli Date: Wed, 4 Jan 2023 13:35:24 -0500 Subject: [PATCH 38/38] lint fix --- packages/cli/src/commands/infra.ts | 6 +++--- packages/cli/src/commands/test.ts | 10 ++++------ 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/packages/cli/src/commands/infra.ts b/packages/cli/src/commands/infra.ts index 15a92a4301..3841bcc13d 100644 --- a/packages/cli/src/commands/infra.ts +++ b/packages/cli/src/commands/infra.ts @@ -112,9 +112,9 @@ async function run( const modulesArray: string[] = []; if (modules) { - modules.forEach((x) => modulesArray.push( - ...(x.includes(",") ? x.split(",") : [x]) - )); + modules.forEach((x) => + modulesArray.push(...(x.includes(",") ? x.split(",") : [x])) + ); } const manifest: string[] = manifestFile diff --git a/packages/cli/src/commands/test.ts b/packages/cli/src/commands/test.ts index fdb5f143a7..842253561f 100644 --- a/packages/cli/src/commands/test.ts +++ b/packages/cli/src/commands/test.ts @@ -119,13 +119,11 @@ const _run = async (options: Required) => { const jobsArray: string[] = []; if (jobs) { - jobs.forEach((x) => jobsArray.push( - ...(x.includes(",") ? x.split(",") : [x]) - )); - } else { - jobsArray.push( - ...Object.keys(workflow.jobs) + jobs.forEach((x) => + jobsArray.push(...(x.includes(",") ? x.split(",") : [x])) ); + } else { + jobsArray.push(...Object.keys(workflow.jobs)); } const validationScript = workflow.validation