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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions packages/cli/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"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_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 @@ -90,7 +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_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 @@ -216,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 @@ -255,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
8 changes: 5 additions & 3 deletions packages/cli/lang/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"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_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 @@ -90,7 +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_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 @@ -216,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 @@ -255,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
86 changes: 20 additions & 66 deletions packages/cli/src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import {
parseLogFileOption,
getProjectFromManifest,
isPolywrapManifestLanguage,
isPluginManifestLanguage,
generateWrapFile,
polywrapManifestLanguages,
pluginManifestLanguages,
parseWrapperEnvsOption,
Expand All @@ -31,8 +29,6 @@ import {
} from "../lib/build-strategies";
import { defaultCodegenDir } from "../lib/defaults/defaultCodegenDir";

import fs from "fs";
import path from "path";
import readline from "readline";
import { Env, PolywrapClient } from "@polywrap/client-js";
import { PolywrapManifest } from "@polywrap/polywrap-manifest-types-js";
Expand Down Expand Up @@ -197,18 +193,29 @@ async function run(options: BuildCommandOptions) {
const manifest = await project.getManifest();
const language = manifest.project.type;

let execute: () => Promise<boolean>;
if (supportedProjectTypes.indexOf(language) === -1) {
logger.error(
intlMsg.commands_build_error_unsupportedProjectType({
supportedTypes: supportedProjectTypes.join(", "),
})
);
process.exit(1);
}

let buildStrategy: BuildStrategy<unknown>;

if (isPolywrapManifestLanguage(language)) {
await validateManifestModules(manifest as PolywrapManifest);

const buildStrategy = createBuildStrategy(
buildStrategy = createBuildStrategy(
strategy,
outputDir,
project as PolywrapProject
);
}

execute = async (): Promise<boolean> => {
const execute = async (): Promise<boolean> => {
try {
const schemaComposer = new SchemaComposer({
project,
client,
Expand All @@ -235,65 +242,12 @@ async function run(options: BuildCommandOptions) {
buildStrategy,
});

const result = await compiler.compile();

if (!result) {
return result;
}

return true;
};
} else if (isPluginManifestLanguage(language)) {
execute = async (): Promise<boolean> => {
const schemaComposer = new SchemaComposer({
project,
client,
});

// Output the built manifest
const manifestPath = path.join(outputDir, "wrap.info");

try {
if (codegen) {
const codeGenerator = new CodeGenerator({
project,
schemaComposer,
codegenDirAbs: codegenDir,
});
const codegenSuccess = await codeGenerator.generate();

if (!codegenSuccess) {
logger.error(intlMsg.commands_build_error_codegen_failed());
return false;
}
}

if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir);
}

await generateWrapFile(
await schemaComposer.getComposedAbis(),
await project.getName(),
"plugin",
manifestPath,
logger
);
} catch (err) {
logger.error(err.message);
return false;
}

return true;
};
} else {
logger.error(
intlMsg.commands_build_error_unsupportedProjectType({
supportedTypes: supportedProjectTypes.join(", "),
})
);
return;
}
return await compiler.compile();
} catch (err) {
logger.error(err.message);
return false;
}
};

if (!watch) {
const result = await execute();
Expand Down
38 changes: 24 additions & 14 deletions packages/cli/src/lib/Compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
generateWrapFile,
intlMsg,
PolywrapProject,
PluginProject,
resetDir,
SchemaComposer,
logActivity,
Expand All @@ -21,8 +22,8 @@ import path from "path";

export interface CompilerConfig {
outputDir: string;
project: PolywrapProject;
buildStrategy: BuildStrategy;
project: PolywrapProject | PluginProject;
buildStrategy?: BuildStrategy;
schemaComposer: SchemaComposer;
}

Expand All @@ -39,13 +40,13 @@ export class Compiler {
// Output: wrap.info
await this._outputWrapManifest();

if (!(await this._isInterface())) {
// Compile the Wrapper
if (await this._isWasm()) {
// Build & Output: wasm.wrap
await this._buildModules();
}

// Copy: Resources folder
await this._copyResourcesFolder();
// Copy: Resources folder
await this._copyResourcesFolder();
}
};

try {
Expand All @@ -64,17 +65,26 @@ export class Compiler {
}
}

private async _isInterface(): Promise<boolean> {
private async _isWasm(): Promise<boolean> {
const { project } = this._config;
const manifest = await project.getManifest();
return manifest.project.type === "interface";
return manifest.project.type.startsWith("wasm/");
}

private async _buildModules(): Promise<void> {
const { outputDir } = this._config;
const { outputDir, project } = this._config;

if (!this._config.buildStrategy) {
throw Error(intlMsg.lib_compiler_missingBuildStrategy());
}

if (await this._isInterface()) {
throw Error(intlMsg.lib_compiler_cannotBuildInterfaceModules());
if (!(await this._isWasm())) {
const manifest = await project.getManifest();
throw Error(
intlMsg.lib_compiler_cannotBuildModule({
project: manifest.project.type,
})
);
}

// Build the sources
Expand All @@ -90,7 +100,7 @@ export class Compiler {
const run = async () => {
const manifest = await project.getManifest();

const type = (await this._isInterface()) ? "interface" : "wasm";
const type = manifest.project.type.split("/")[0];
const abi = await schemaComposer.getComposedAbis();
await generateWrapFile(
abi,
Expand Down Expand Up @@ -122,7 +132,7 @@ export class Compiler {
private async _copyResourcesFolder(): Promise<void> {
const { outputDir, project } = this._config;

const projectManifest = await project.getManifest();
const projectManifest = await (project as PolywrapProject).getManifest();

if (!projectManifest || !projectManifest.resources) {
return Promise.resolve();
Expand Down
18 changes: 15 additions & 3 deletions packages/cli/src/lib/helpers/wrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,16 @@ import {
} from "@polywrap/wrap-manifest-types-js";
import { normalizePath, writeFileSync } from "@polywrap/os-js";

export const supportedWrapTypes: WrapManifest["type"][] = [
"interface",
"wasm",
"plugin",
];

const run = async (
abi: WrapAbi,
name: string,
type: "interface" | "wasm" | "plugin",
type: WrapManifest["type"],
path: string
): Promise<void> => {
const manifest: WrapManifest = {
Expand All @@ -31,10 +37,16 @@ const run = async (
export const generateWrapFile = async (
abi: WrapAbi,
name: string,
type: "interface" | "wasm" | "plugin",
type: string,
path: string,
logger: Logger
): Promise<void> => {
if (!supportedWrapTypes.includes(type as WrapManifest["type"])) {
throw Error(intlMsg.lib_helpers_wrap_unsupportedType({ type }));
}

const wrapType = type as WrapManifest["type"];

const relativePath = displayPath(path);
return await logActivity(
logger,
Expand All @@ -48,7 +60,7 @@ export const generateWrapFile = async (
path: normalizePath(relativePath),
}),
async (): Promise<void> => {
await run(abi, name, type, path);
await run(abi, name, wrapType, path);
}
);
};