Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
28bab6b
CLI - remove codegen step from build command
pileks Oct 26, 2022
5ed6d35
CLI - WIP support for plugin build, remove plugin build step from cod…
pileks Oct 26, 2022
d5a2f85
CLI - build wasm & plugin support refactor WIP
pileks Oct 26, 2022
0835434
CLI build command - add hard-stop for unsupported project types
pileks Oct 27, 2022
f19ccee
CLI build command - reintroduce optional codegen step
pileks Oct 27, 2022
da26397
Merge remote-tracking branch 'origin/origin-0.10-dev' into pileks/fea…
pileks Oct 27, 2022
b636432
CLI - separate plugin codegen actions into codegen and build commands
pileks Nov 2, 2022
86d4ab0
merge with origin-0.10-dev
pileks Nov 3, 2022
14bb817
fix custom config test
pileks Nov 3, 2022
ad9919c
Merge remote-tracking branch 'origin/origin-0.10-dev' into pileks/fea…
pileks Nov 3, 2022
8ca2463
Add codegen to wasm build test case
pileks Nov 3, 2022
a9ea67a
test-env buildWrapper needs to manually codegen, add `--codegen-dir` …
pileks Nov 3, 2022
5dc62ed
chore: lint
pileks Nov 3, 2022
2d6b185
chore: lint
pileks Nov 3, 2022
0451bb8
Add codegen option to test-env buildWrapper function, properly exit e…
pileks Nov 4, 2022
6208223
Merge remote-tracking branch 'origin/origin-0.10-dev' into pileks/fea…
pileks Nov 9, 2022
6560862
add codegen before build in build tests
pileks Nov 10, 2022
18d5caa
Merge remote-tracking branch 'origin/origin-0.10-dev' into pileks/fea…
pileks Nov 14, 2022
973efa1
Merge remote-tracking branch 'origin/origin-dev' into pileks/feat/cli…
pileks Nov 28, 2022
af6e7f0
chore: refactor testBuildOutput
pileks Nov 28, 2022
6c1ae20
Merge remote-tracking branch 'origin/origin-dev' into pileks/feat/cli…
pileks Dec 5, 2022
ae18eae
chore: fix CLI tests
pileks Dec 5, 2022
c2ac4fb
patch commands for plugin build
pileks Dec 5, 2022
ba8cc29
chore: intlMsg
pileks Dec 5, 2022
9275930
fix improper build in tests
pileks Dec 5, 2022
72497d7
WS plugin cache test timing issue - delay 3rd message
pileks Dec 5, 2022
164fbf2
remove yarn.lock from test case
pileks Dec 5, 2022
11cfd50
Update CHANGELOG
pileks Dec 5, 2022
36f2158
Merge remote-tracking branch 'origin/origin-dev' into pileks/feat/cli…
pileks Dec 20, 2022
bf1854b
CLI codegen command - log error when project fails to load
pileks Dec 20, 2022
c19eb8e
fix plugin codegen test case
pileks Dec 20, 2022
17ca8dc
Merge remote-tracking branch 'origin/origin-dev' into pileks/feat/cli…
pileks Dec 26, 2022
178176d
fix: remove exclamations from output strings
dOrgJelli Jan 3, 2023
3ec2835
chore: move plugin build logic into compiler
dOrgJelli Jan 3, 2023
fe10e6a
lint fix
dOrgJelli Jan 3, 2023
966a6e6
change array.indexOf to includes
pileks Jan 3, 2023
15f20ee
Merge pull request #1467 from polywrap/dorgjelli/feat/cli-separate-bu…
pileks Jan 3, 2023
5933391
Update README
pileks Jan 3, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
* A `-l, --log-file [path]` option has been added to all commands. Its purpose is to configure a `Log file to save console output to`, useful in situations when the console log overflows.

## Breaking Changes
* [PR-1385](https://github.com/polywrap/toolchain/pull/1385) `polywrap` CLI:
* Running `polywrap build` no longer automatically generates code bindings (`codegen`). You need to either run `polywrap codegen` before running `polywrap build`, or run `polywrap build` with the `--codegen` flag.
* Running `polywrap codegen` in Plugin Projects will no longer output the WRAP ABI (`wrap.info`) file into a build folder. To output the WRAP ABI, you need to run `polywrap build` within your Plugin Project.
* [PR-1432](https://github.com/polywrap/toolchain/pull/1432) `polywrap` CLI:
* Remove the `polywrap.meta.yaml` manifest.
* [PR-1436](https://github.com/polywrap/toolchain/pull/1436) `@polywrap/client-config-builder-js`:
Expand Down
15 changes: 8 additions & 7 deletions packages/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,11 @@ polywrap codegen --help
### `build | b`

Build Wasm and Interface Polywrap projects.

This outputs the project's ABI schema (Wasm and Interface) and binary package (Wasm) into the `./build` directory.

Currently, `build` can be run for Wasm, Plugin and Interface projects.

#### Options
- `-m, --manifest-file <path>`
Specify your project's manifest file.
Expand All @@ -82,9 +85,9 @@ This outputs the project's ABI schema (Wasm and Interface) and binary package (W
- `--wrapper-envs <envs-path>`
Configure wrapper environment values using the provided file.

- `-n, --no-codegen`
Don't perform codegen before building.
By default, `build` performs a `codegen` step before building your Project. This option skips this step. This is especially useful when you are testing manual changes to your types/bindings.
- `--codegen`
Perform codegen before building.
By default, `build` doesn't perform a `codegen` step before building your Project. This option includes this step. This is especially useful when used in conjunction with the `--watch` option.

- `-s, --strategy <strategy>`
Specify which build strategy to use. By default, the `vm` build strategy is used.
Expand All @@ -102,6 +105,8 @@ Generate code bindings for Polywrap projects.

This command generates types and bindings for your project based on your project's schema (found in `schema.graphql`).

Currently, `codegen` can be run for App, Plugin and Wasm projects.

#### Options
- `-m, --manifest-file <path>`
Specify your project's manifest file.
Expand All @@ -125,10 +130,6 @@ This command generates types and bindings for your project based on your project
- `--wrapper-envs <envs-path>`
Configure wrapper environment values using the provided file.

#### Special note

When running `codegen` for Plugin Projects, the Polywrap CLI will also output an ABI schema for your plugin into the `./build` directory. You can override this output directory by specifying `-p, --publish-dir <path>`.

### `create | c`

Create a Polywrap project.
Expand Down
10 changes: 8 additions & 2 deletions packages/cli/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"commands_build_error_manifestPathMissing": "{option} option missing {argument} argument",
"commands_build_error_manifestNotFound": "Manifest not found. Search paths used: {paths}",
"commands_build_error_outputDirMissingPath": "{option} option missing {argument} argument",
"commands_build_error_unsupportedProjectType": "Unsupported project type. You can only build the following project types: {supportedTypes}",
"commands_build_keypressListener_exit": "Exit: [CTRL + C], [ESC], or [Q]",
"commands_build_keypressListener_watching": "Watching",
"commands_build_options_h": "Show usage information",
Expand All @@ -17,11 +18,13 @@
"commands_build_options_o_path": "path",
"commands_build_options_options": "options",
"commands_build_options_t": "Use the development server's ENS instance",
"commands_build_options_n": "Skip code generation",
"commands_build_options_codegen": "Perform code generation before build",
"commands_build_options_codegen_dir": "Codegen output directory (default: {default})",
"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": "strategy",
"commands_build_options_l": "Log file to save console output to",
"commands_build_error_codegen_failed": "Code generation failed",
"commands_infra_description": "Modular Infrastructure-As-Code Orchestrator",
"commands_infra_actions_subtitle": "Infra allows you to execute the following commands:",
"commands_infra_options_options": "options",
Expand Down Expand Up @@ -87,6 +90,7 @@
"commands_codegen_options_o": "Output directory for custom generated types (default: 'types/')",
"commands_codegen_options_o_path": "path",
"commands_codegen_success": "Types were generated successfully",
"commands_codegen_project_load_error": "Failed to load project, please make sure {manifestPath} is a valid Project manifest",
"commands_codegen_options_publish": "Output path for the built schema and manifest (default: {default})",
"commands_docgen_description": "Generate wrapper documentation",
"commands_docgen_success": "Docs were generated successfully",
Expand Down Expand Up @@ -212,7 +216,8 @@
"lib_compiler_noNodeModules": "could not locate {folder} in parent directories of polywrap manifest",
"lib_compiler_noInvoke": "WASM module is missing the _wrap_invoke export. This should never happen...",
"lib_compiler_invalid_module": "Invalid Wasm module found. {modulePath} is invalid. Error: {error}",
"lib_compiler_cannotBuildInterfaceModules": "Cannot build modules for an Interface Polywrap",
"lib_compiler_cannotBuildModule": "Cannot build the module for a project of type {project}",
"lib_compiler_missingBuildStrategy": "The compiler is missing a build strategy",
"lib_compiler_copyResourcesFolderText": "Copying resources folder: {folder}",
"lib_compiler_copyResourcesFolderError": "Failed to copy resources folder: {folder}",
"lib_compiler_copyResourcesFolderWarning": "Warnings copying resources folder: {folder}",
Expand Down Expand Up @@ -251,6 +256,7 @@
"lib_helpers_docker_projectFolderMissing": "Build image `{image}` missing /project folder",
"lib_helpers_docker_projectBuildFolderMissing": "Build image `{image}` missing build artifact `{artifact}` in folder /project/build",
"lib_helpers_parameters_unexpectedValue": "Unexpected value provided for one or more of {options}. See --help for more information.",
"lib_helpers_wrap_unsupportedType": "Unsupported WRAP type {type}",
"lib_language_unsupportedManifestLanguage": "The manifest's language {language} is not supported. Please use one of the supported lanauges: {supported}",
"lib_language_noInterfaceCodegen": "Code generation cannot be run for Polywrap Interface projects",
"lib_system_env_var_not_found": "Environment variable not found: `{variableName}`",
Expand Down
10 changes: 8 additions & 2 deletions packages/cli/lang/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"commands_build_error_manifestPathMissing": "{option} option missing {argument} argument",
"commands_build_error_manifestNotFound": "Manifest not found. Search paths used: {paths}",
"commands_build_error_outputDirMissingPath": "{option} option missing {argument} argument",
"commands_build_error_unsupportedProjectType": "Unsupported project type. You can only build the following project types: {supportedTypes}",
"commands_build_keypressListener_exit": "Exit: [CTRL + C], [ESC], or [Q]",
"commands_build_keypressListener_watching": "Watching",
"commands_build_options_h": "Show usage information",
Expand All @@ -17,11 +18,13 @@
"commands_build_options_o_path": "path",
"commands_build_options_options": "options",
"commands_build_options_t": "Use the development server's ENS instance",
"commands_build_options_n": "Skip code generation",
"commands_build_options_codegen": "Perform code generation before build",
"commands_build_options_codegen_dir": "Codegen output directory (default: {default})",
"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": "strategy",
"commands_build_options_l": "Log file to save console output to",
"commands_build_error_codegen_failed": "Code generation failed",
"commands_infra_description": "Modular Infrastructure-As-Code Orchestrator",
"commands_infra_actions_subtitle": "Infra allows you to execute the following commands:",
"commands_infra_options_options": "options",
Expand Down Expand Up @@ -87,6 +90,7 @@
"commands_codegen_options_o": "Output directory for custom generated types (default: 'types/')",
"commands_codegen_options_o_path": "path",
"commands_codegen_success": "Types were generated successfully",
"commands_codegen_project_load_error": "Failed to load project, please make sure {manifestPath} is a valid Project manifest",
"commands_codegen_options_publish": "Output path for the built schema and manifest (default: {default})",
"commands_docgen_description": "Generate wrapper documentation",
"commands_docgen_success": "Docs were generated successfully",
Expand Down Expand Up @@ -212,7 +216,8 @@
"lib_compiler_noNodeModules": "could not locate {folder} in parent directories of polywrap manifest",
"lib_compiler_noInvoke": "WASM module is missing the _wrap_invoke export. This should never happen...",
"lib_compiler_invalid_module": "Invalid Wasm module found. {modulePath} is invalid. Error: {error}",
"lib_compiler_cannotBuildInterfaceModules": "Cannot build modules for an Interface Polywrap",
"lib_compiler_cannotBuildModule": "Cannot build the module for a project of type {project}",
"lib_compiler_missingBuildStrategy": "The compiler is missing a build strategy",
"lib_compiler_copyResourcesFolderText": "Copying resources folder: {folder}",
"lib_compiler_copyResourcesFolderError": "Failed to copy resources folder: {folder}",
"lib_compiler_copyResourcesFolderWarning": "Warnings copying resources folder: {folder}",
Expand Down Expand Up @@ -251,6 +256,7 @@
"lib_helpers_docker_projectFolderMissing": "Build image `{image}` missing /project folder",
"lib_helpers_docker_projectBuildFolderMissing": "Build image `{image}` missing build artifact `{artifact}` in folder /project/build",
"lib_helpers_parameters_unexpectedValue": "Unexpected value provided for one or more of {options}. See --help for more information.",
"lib_helpers_wrap_unsupportedType": "Unsupported WRAP type {type}",
"lib_language_unsupportedManifestLanguage": "The manifest's language {language} is not supported. Please use one of the supported lanauges: {supported}",
"lib_language_noInterfaceCodegen": "Code generation cannot be run for Polywrap Interface projects",
"lib_system_env_var_not_found": "Environment variable not found: `{variableName}`",
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/__tests__/e2e/build-rs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe("e2e tests for build command", () => {
describe("Image strategy", () => {
it("Builds for rust", async () => {
const { exitCode: code, stdout: output } = await runCLI({
args: ["build", "-v", "-s", "image"],
args: ["build", "-v", "--codegen", "-s", "image"],
cwd: getTestCaseDir(0),
cli: polywrapCli,
});
Expand All @@ -37,7 +37,7 @@ describe("e2e tests for build command", () => {
describe.skip("Local strategy", () => {
it("Builds for rust", async () => {
const { exitCode: code, stdout: output } = await runCLI({
args: ["build", "-v", "-s", "local"],
args: ["build", "-v", "--codegen", "-s", "local"],
cwd: getTestCaseDir(0),
cli: polywrapCli,
});
Expand All @@ -53,7 +53,7 @@ describe("e2e tests for build command", () => {
describe("VM strategy", () => {
it("Builds for rust", async () => {
const { exitCode: code, stdout: output } = await runCLI({
args: ["build", "-v", "-s", "vm"],
args: ["build", "-v", "--codegen", "-s", "vm"],
cwd: getTestCaseDir(0),
cli: polywrapCli,
});
Expand Down
47 changes: 47 additions & 0 deletions packages/cli/src/__tests__/e2e/build.plugin.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { runCLI } from "@polywrap/test-env-js";
import { GetPathToCliTestFiles } from "@polywrap/test-cases";
import path from "path";
import fs from "fs";
import { testCliOutput } from "./helpers/testCliOutput";
import { testBuildOutput } from "./helpers/testBuildOutput";

describe("e2e tests for build command - plugin project", () => {
const testCaseRoot = path.join(GetPathToCliTestFiles(), "plugin/build-cmd");
const testCases = fs
.readdirSync(testCaseRoot, { withFileTypes: true })
.filter((dirent) => dirent.isDirectory())
.map((dirent) => dirent.name);
const getTestCaseDir = (index: number) =>
path.join(testCaseRoot, testCases[index]);

describe("test-cases", () => {
for (let i = 0; i < testCases.length; ++i) {
const testCaseName = testCases[i];
const testCaseDir = getTestCaseDir(i);

let buildDir = path.join(testCaseDir, "build");
let cmdArgs: string[] = [];
let cmdFile = path.join(testCaseDir, "cmd.json");
if (fs.existsSync(cmdFile)) {
const cmdConfig = JSON.parse(fs.readFileSync(cmdFile, "utf-8"));
if (cmdConfig.args) {
cmdArgs.push(...cmdConfig.args);
}

if (cmdConfig.buildDir) {
buildDir = path.join(testCaseDir, cmdConfig.buildDir);
}
}

test(testCaseName, async () => {
const { exitCode: code, stdout: output, stderr: error } = await runCLI({
args: ["build", ...cmdArgs],
cwd: testCaseDir,
});

testCliOutput(testCaseDir, code, output, error);
testBuildOutput(testCaseDir, buildDir);
});
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { GetPathToCliTestFiles } from "@polywrap/test-cases";
import fs from "fs";
import os from "os";
import path from "path";
import { testBuildOutput } from "./helpers/testBuildOutput";

const HELP = `Usage: polywrap build|b [options]

Expand All @@ -17,9 +18,11 @@ Options:
(default: ./build)
-c, --client-config <config-path> Add custom configuration to the
PolywrapClient
--codegen Perform code generation before build
--codegen-dir Codegen output directory (default:
./src/wrap)
--wrapper-envs <envs-path> Path to a JSON file containing wrapper
envs
-n, --no-codegen Skip code generation
-s, --strategy <strategy> Strategy to use for building the wrapper
(default: "vm")
-w, --watch Automatically rebuild when changes are
Expand Down Expand Up @@ -89,25 +92,6 @@ describe("e2e tests for build command", () => {
}
};

const testBuildOutput = (testCaseDir: string, buildDir: string) => {
const expectedOutputFile = path.join(
testCaseDir,
"expected",
"output.json"
);
if (fs.existsSync(expectedOutputFile)) {
const expectedFiles = JSON.parse(
fs.readFileSync(expectedOutputFile, { encoding: "utf8" })
);

for (const file of expectedFiles) {
if (!fs.existsSync(path.join(buildDir, file))) {
fail(`Did not find expected file: ${path.join(buildDir, file)}`);
}
}
}
};

it("Should show help text", async () => {
const { exitCode: code, stdout: output, stderr: error } = await runCLI({
args: ["build", "--help"],
Expand Down Expand Up @@ -176,7 +160,7 @@ describe("e2e tests for build command", () => {
);
const testCaseDir = getTestCaseDir(0);
const { exitCode: code, stdout: output } = await runCLI({
args: ["build", "-v", "--output-dir", outputDir],
args: ["build", "-v", "--output-dir", outputDir, "--codegen"],
cwd: testCaseDir,
cli: polywrapCli,
});
Expand Down Expand Up @@ -251,7 +235,7 @@ describe("e2e tests for build command", () => {

it("Builds for assemblyscript", async () => {
const { exitCode: code, stdout: output } = await runCLI({
args: ["build", "-v", "-s", "local"],
args: ["build", "-v", "-s", "local", "--codegen"],
cwd: getTestCaseDir(0),
cli: polywrapCli,
});
Expand All @@ -263,7 +247,7 @@ describe("e2e tests for build command", () => {
expect(output).toContain(`WRAP manifest written in ${buildDir}/wrap.info`);
});
})

describe("test-cases", () => {
for (let i = 0; i < testCases.length; i++) {
const testCaseName = testCases[i];
Expand All @@ -280,7 +264,7 @@ describe("e2e tests for build command", () => {

test(testCaseName, async () => {
let { exitCode, stdout, stderr } = await runCLI({
args: ["build", "-v", ...cmdArgs],
args: ["build", "-v", "--codegen", ...cmdArgs],
cwd: testCaseDir,
cli: polywrapCli,
});
Expand Down
7 changes: 1 addition & 6 deletions packages/cli/src/__tests__/e2e/codegen.plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ describe("e2e tests for codegen command - plugin project", () => {
const testCaseDir = getTestCaseDir(i);

let codegenDir = path.join(testCaseDir, "src", "wrap");
let buildDir = path.join(testCaseDir, "build");
let cmdArgs: string[] = [];
let cmdFile = path.join(testCaseDir, "cmd.json");
if (fs.existsSync(cmdFile)) {
Expand All @@ -32,10 +31,6 @@ describe("e2e tests for codegen command - plugin project", () => {
if (cmdConfig.codegenDir) {
codegenDir = path.join(testCaseDir, cmdConfig.codegenDir);
}

if (cmdConfig.buildDir) {
buildDir = path.join(testCaseDir, cmdConfig.buildDir);
}
}

test(testCaseName, async () => {
Expand All @@ -44,7 +39,7 @@ describe("e2e tests for codegen command - plugin project", () => {
cwd: testCaseDir,
});
testCliOutput(testCaseDir, code, output, error);
testCodegenOutput(testCaseDir, codegenDir, buildDir);
testCodegenOutput(testCaseDir, codegenDir);
});
}
});
Expand Down
2 changes: 0 additions & 2 deletions packages/cli/src/__tests__/e2e/codegen.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ Options:
(default: polywrap.yaml | polywrap.yml)
-g, --codegen-dir <path> Output directory for the generated code
(default: ./src/wrap)
-p, --publish-dir <path> Output path for the built schema and
manifest (default: ./build)
-s, --script <path> Path to a custom generation script
(JavaScript | TypeScript)
-c, --client-config <config-path> Add custom configuration to the
Expand Down
17 changes: 17 additions & 0 deletions packages/cli/src/__tests__/e2e/helpers/testBuildOutput.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import path from "path";
import fs from "fs";

export const testBuildOutput = (testCaseDir: string, buildDir: string) => {
const expectedOutputFile = path.join(testCaseDir, "expected", "output.json");
if (fs.existsSync(expectedOutputFile)) {
const expectedFiles = JSON.parse(
fs.readFileSync(expectedOutputFile, { encoding: "utf8" })
);

for (const file of expectedFiles) {
if (!fs.existsSync(path.join(buildDir, file))) {
fail(`Did not find expected file: ${path.join(buildDir, file)}`);
}
}
}
};
13 changes: 0 additions & 13 deletions packages/cli/src/__tests__/e2e/helpers/testCodegenOutput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { compareSync } from "dir-compare";
export const testCodegenOutput = (
testCaseDir: string,
codegenDir: string,
buildDir?: string
) => {
if (fs.existsSync(path.join(testCaseDir, "expected", "wrap"))) {
const expectedCodegenResult = compareSync(
Expand All @@ -15,16 +14,4 @@ export const testCodegenOutput = (
);
expect(expectedCodegenResult.differences).toBe(0);
}

// HACK for testing plugin codegen output, as it outputs ABI to a build folder
if (buildDir) {
if (fs.existsSync(path.join(testCaseDir, "expected", "build-artifacts"))) {
const expectedBuildResult = compareSync(
buildDir,
path.join(testCaseDir, "expected", "build-artifacts"),
{ compareContent: true }
);
expect(expectedBuildResult.differences).toBe(0);
}
}
};
2 changes: 1 addition & 1 deletion packages/cli/src/__tests__/e2e/test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe("e2e tests for test command", () => {

beforeAll(async () => {
const wrapperPath = path.join(testCaseRoot, "run-test-wrapper");
await buildWrapper(wrapperPath);
await buildWrapper(wrapperPath, undefined, true);
});

it("Should show help text", async () => {
Expand Down
Loading