Skip to content

Commit

Permalink
Merge pull request #1296 from polywrap/pileks/remove-polywrap-app-plu…
Browse files Browse the repository at this point in the history
…gin-filenames

Remove app & plugin project manifest default filenames
  • Loading branch information
dOrgJelli authored Oct 6, 2022
2 parents 04d9e2b + 11e0441 commit 8b807a7
Show file tree
Hide file tree
Showing 15 changed files with 61 additions and 100 deletions.
4 changes: 3 additions & 1 deletion packages/cli/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,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 @@ -270,5 +271,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`."
}
4 changes: 3 additions & 1 deletion packages/cli/lang/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,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 @@ -270,5 +271,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)
-f, --format <format> Target format to migrate to (defaults to latest)
-h, --help display help for command
`;
Expand All @@ -52,9 +50,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 { ScriptCodegenerator } from "../lib/codegen/ScriptCodeGenerator";

Expand All @@ -23,7 +24,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,
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 { ScriptCodegenerator } from "../lib/codegen/ScriptCodeGenerator";

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 @@ -61,7 +62,7 @@ import path from "path";
const pathStr = intlMsg.commands_manifest_options_m_path();
const formatStr = intlMsg.commands_manifest_options_m_format();

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

0 comments on commit 8b807a7

Please sign in to comment.