Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove app & plugin project manifest default filenames #1296

Merged
merged 6 commits into from
Oct 6, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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
4 changes: 3 additions & 1 deletion packages/cli/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
"commands_docgen_options_markdown": "Generate {framework} markdown",
"commands_docgen_options_i": "Also generate docs for dependencies",
"commands_docgen_error_manifestNotFound": "Manifest not found. Search paths used: {paths}",
"commands_docgen_error_projectLoadFailed": "Could not load project form the given manifest. Manifest: `{manifestFile}`",
"commands_create_description": "Create New Projects",
"commands_create_directoryExists": "Directory with name {dir} already exists",
"commands_create_error_commandFail": "Command failed: {error}",
Expand Down Expand Up @@ -257,5 +258,6 @@
"lib_wrap_abi_not_found": "No WRAP ABI found",
"lib_helpers_wrap_manifest_outputText": "WRAP manifest written in {path}",
"lib_helpers_wrap_manifest_outputError": "Error writing WRAP manifest in {path}",
"lib_helpers_wrap_manifest_outputWarning": "Warning writing WRAP manifest in {path}"
"lib_helpers_wrap_manifest_outputWarning": "Warning writing WRAP manifest in {path}",
"lib_option_defaults_deprecated_project_manifest": "WARNING: the filename `{fileName}` is deprecated and will be removed from the default project manifest files in the future. Please rename it to `polywrap.yaml`."
}
6 changes: 4 additions & 2 deletions packages/cli/lang/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
"commands_docgen_options_markdown": "Generate {framework} markdown",
"commands_docgen_options_i": "Also generate docs for dependencies",
"commands_docgen_error_manifestNotFound": "Manifest not found. Search paths used: {paths}",
"commands_docgen_error_projectLoadFailed": "Could not load project form the given manifest. Manifest: `{manifestFile}`",
"commands_create_description": "Create New Projects",
"commands_create_directoryExists": "Directory with name {dir} already exists",
"commands_create_error_commandFail": "Command failed: {error}",
Expand Down Expand Up @@ -177,7 +178,7 @@
"commands_manifest_command_s_option_r": "Output raw JSON Schema",
"commands_manifest_command_m_preserveManifestMessage": "Saved previous version of manifest to {preservedFilePath}",
"commands_manifest_command_m_migrateManifestMessage": "Migrating {manifestFile} to version {version}",
"commands_manifest_formatError": "Could not detect manifest format. Please make sure that you have the 'format' field present in {fileName} with one of the following values: {values}",
"commands_manifest_formatError": "Unsupported manifest format. Please make sure that you have the 'format' field present in {fileName} with one of the following values: {values}",
"commands_manifest_projectTypeError": "Unsupported project type.",
"lib_codeGenerator_genCodeError": "Failed to generate types",
"lib_codeGenerator_genCodeText": "Generate types",
Expand Down Expand Up @@ -257,5 +258,6 @@
"lib_wrap_abi_not_found": "No WRAP ABI found",
"lib_helpers_wrap_manifest_outputText": "WRAP manifest written in {path}",
"lib_helpers_wrap_manifest_outputError": "Error writing WRAP manifest in {path}",
"lib_helpers_wrap_manifest_outputWarning": "Warning writing WRAP manifest in {path}"
"lib_helpers_wrap_manifest_outputWarning": "Warning writing WRAP manifest in {path}",
"lib_option_defaults_deprecated_project_manifest": "WARNING: the filename `{fileName}` is deprecated and will be removed from the default project manifest files in the future. Please rename it to `polywrap.yaml`."
}
5 changes: 1 addition & 4 deletions packages/cli/src/__tests__/e2e/codegen.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ Generate Code For Polywrap Projects

Options:
-m, --manifest-file <path> Path to the Polywrap manifest file
(default: polywrap.yaml | polywrap.yml |
polywrap.app.yaml | polywrap.app.yml |
polywrap.plugin.yaml |
polywrap.plugin.yml)
(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
Expand Down
5 changes: 1 addition & 4 deletions packages/cli/src/__tests__/e2e/docgen.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ Arguments:

Options:
-m, --manifest-file <path> Path to the project manifest file
(default: polywrap.yaml | polywrap.yml |
polywrap.app.yaml | polywrap.app.yml |
polywrap.plugin.yaml |
polywrap.plugin.yml)
(default: polywrap.yaml | polywrap.yml)
-g, --docgen-dir <path> Output directory for generated docs
(default: ./docs)
-c, --client-config <config-path> Add custom configuration to the
Expand Down
8 changes: 2 additions & 6 deletions packages/cli/src/__tests__/e2e/manifest.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ Arguments:

Options:
-m, --manifest-file <path> Path to the manifest file (default: polywrap.yaml
| polywrap.yml | polywrap.app.yaml |
polywrap.app.yml | polywrap.plugin.yaml |
polywrap.plugin.yml)
| polywrap.yml)
-h, --help display help for command
`;

Expand All @@ -51,9 +49,7 @@ Arguments:
Options:
-r, --raw Output raw JSON Schema (default: false)
-m, --manifest-file <path> Path to the manifest file (default: polywrap.yaml
| polywrap.yml | polywrap.app.yaml |
polywrap.app.yml | polywrap.plugin.yaml |
polywrap.plugin.yml)
| polywrap.yml)
-h, --help display help for command
`;

Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/commands/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
isPluginManifestLanguage,
generateWrapFile,
defaultProjectManifestFiles,
defaultPolywrapManifest,
} from "../lib";

import { PolywrapClient, PolywrapClientConfig } from "@polywrap/client-js";
Expand All @@ -22,7 +23,7 @@ const defaultCodegenDir = "./src/wrap";
const defaultPublishDir = "./build";

const pathStr = intlMsg.commands_codegen_options_o_path();
const defaultManifestStr = defaultProjectManifestFiles.join(" | ");
const defaultManifestStr = defaultPolywrapManifest.join(" | ");

type CodegenCommandOptions = {
manifestFile: string;
Expand Down
68 changes: 22 additions & 46 deletions packages/cli/src/commands/docgen.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
/* eslint-disable prefer-const */
import {
AnyProjectManifest,
AppProject,
CodeGenerator,
defaultAppManifest,
defaultPolywrapManifest,
Project,
SchemaComposer,
PolywrapProject,
intlMsg,
PluginProject,
parseClientConfigOption,
defaultPluginManifest,
parseDirOption,
parseDocgenManifestFileOption,
parseManifestFileOption,
defaultProjectManifestFiles,
getProjectFromManifest,
} from "../lib";
import { Command, Program } from "./types";
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 path from "path";
import { PolywrapClient, PolywrapClientConfig } from "@polywrap/client-js";
import chalk from "chalk";
import { Argument } from "commander";
Expand All @@ -33,11 +27,6 @@ const commandToPathMap: Record<string, string> = {

export type DocType = keyof typeof commandToPathMap;

// A list of UNIQUE possible default filenames for the polywrap manifest
const defaultManifest = defaultPolywrapManifest
.concat(defaultAppManifest)
.concat(defaultPluginManifest)
.filter((value, index, self) => self.indexOf(value) === index);
const defaultDocgenDir = "./docs";
const pathStr = intlMsg.commands_codegen_options_o_path();

Expand Down Expand Up @@ -85,7 +74,7 @@ export const docgen: Command = {
.option(
`-m, --manifest-file <${pathStr}>`,
intlMsg.commands_docgen_options_m({
default: defaultManifest.join(" | "),
default: defaultPolywrapManifest.join(" | "),
})
)
.option(
Expand All @@ -102,7 +91,10 @@ export const docgen: Command = {
.action(async (action, options) => {
await run(action, {
...options,
manifestFile: parseDocgenManifestFileOption(options.manifestFile),
manifestFile: parseManifestFileOption(
options.manifestFile,
defaultProjectManifestFiles
),
docgenDir: parseDirOption(options.docgenDir, defaultDocgenDir),
clientConfig: await parseClientConfigOption(options.clientConfig),
});
Expand All @@ -113,42 +105,26 @@ export const docgen: Command = {
async function run(command: DocType, options: DocgenCommandOptions) {
const { manifestFile, docgenDir, clientConfig, imports } = options;

const isAppManifest: boolean =
(<string>manifestFile).toLowerCase().endsWith("polywrap.app.yaml") ||
(<string>manifestFile).toLowerCase().endsWith("polywrap.app.yml");
const isPluginManifest: boolean =
(<string>manifestFile).toLowerCase().endsWith("polywrap.plugin.yaml") ||
(<string>manifestFile).toLowerCase().endsWith("polywrap.plugin.yml");
let project = await getProjectFromManifest(manifestFile);

if (!project) {
console.log(
intlMsg.commands_docgen_error_projectLoadFailed({
manifestFile: manifestFile,
})
);

process.exitCode = 1;
return;
}

await project.validate();

// Resolve custom script
const customScript = require.resolve(commandToPathMap[command]);

// Get client
const client = new PolywrapClient(clientConfig);

// Get project
let project: Project<AnyProjectManifest>;
if (isAppManifest) {
project = new AppProject({
rootDir: path.dirname(manifestFile),
appManifestPath: manifestFile,
quiet: true,
});
} else if (isPluginManifest) {
project = new PluginProject({
rootDir: path.dirname(manifestFile),
pluginManifestPath: manifestFile,
quiet: true,
});
} else {
project = new PolywrapProject({
rootDir: path.dirname(manifestFile),
polywrapManifestPath: manifestFile,
quiet: true,
});
}
await project.validate();

const schemaComposer = new SchemaComposer({
project,
client,
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/commands/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
maybeGetManifestFormatVersion,
parseManifestFileOption,
CacheDirectory,
defaultPolywrapManifest,
} from "../lib";
import {
getYamlishSchemaForManifestJsonSchemaObject,
Expand Down Expand Up @@ -60,7 +61,7 @@ import path from "path";

const pathStr = intlMsg.commands_manifest_options_m_path();

const defaultProjectManifestStr = defaultProjectManifestFiles.join(" | ");
const defaultProjectManifestStr = defaultPolywrapManifest.join(" | ");

const manifestTypes = [
"project",
Expand Down
29 changes: 0 additions & 29 deletions packages/cli/src/lib/option-parsers/docgen.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/cli/src/lib/option-parsers/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export * from "./client-config";
export * from "./codegen";
export * from "./dir";
export * from "./docgen";
export * from "./run";
export * from "./manifestFile";
24 changes: 24 additions & 0 deletions packages/cli/src/lib/option-parsers/manifestFile.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
import { intlMsg } from "../intl";
import { defaultAppManifest, defaultPluginManifest } from "../project";
import { resolvePathIfExists } from "../system";

import path from "path";

const deprecatedDefaultManifests = [
...defaultAppManifest,
...defaultPluginManifest,
];

export function parseManifestFileOption(
manifestFile: string | undefined,
defaults: string[]
): string {
const didUserProvideManifestFile =
manifestFile != undefined && !!manifestFile.length;

const manifestPaths = manifestFile ? [manifestFile as string] : defaults;

manifestFile = resolvePathIfExists(manifestPaths);
Expand All @@ -18,5 +29,18 @@ export function parseManifestFileOption(
process.exit(1);
}

const fileName = path.basename(manifestFile);

if (
!didUserProvideManifestFile &&
deprecatedDefaultManifests.includes(fileName)
) {
console.warn(
intlMsg.lib_option_defaults_deprecated_project_manifest({
fileName: path.basename(fileName),
})
);
}

return manifestFile;
}
6 changes: 1 addition & 5 deletions packages/cli/src/lib/project/manifests/app/load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ import {
} from "@polywrap/polywrap-manifest-types-js";
import fs from "fs";

export const defaultAppManifest = [
"polywrap.yaml",
"polywrap.app.yaml",
"polywrap.app.yml",
];
export const defaultAppManifest = ["polywrap.app.yaml", "polywrap.app.yml"];

export async function loadAppManifest(
manifestPath: string,
Expand Down
1 change: 0 additions & 1 deletion packages/cli/src/lib/project/manifests/plugin/load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
import fs from "fs";

export const defaultPluginManifest = [
"polywrap.yaml",
"polywrap.plugin.yaml",
"polywrap.plugin.yml",
];
Expand Down