-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1911 from polywrap/kris/manifest-defaults
project manifest: default source paths
- Loading branch information
Showing
80 changed files
with
4,169 additions
and
202 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { defaultSchemaPath } from "../defaults"; | ||
|
||
import { AppManifest } from "@polywrap/polywrap-manifest-types-js"; | ||
|
||
export function applyAppManifestDefaults( | ||
manifest: AppManifest, | ||
manifestPath: string | ||
): AppManifest { | ||
if (!manifest.source) { | ||
manifest.source = {}; | ||
} | ||
if (!manifest.source.schema) { | ||
manifest.source.schema = defaultSchemaPath(manifestPath); | ||
} | ||
return manifest; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { intlMsg } from "../../intl"; | ||
|
||
import path from "path"; | ||
import fs from "fs"; | ||
|
||
export function defaultSchemaPath(manifestPath: string): string { | ||
const defaultSchemaPaths = [ | ||
"polywrap.graphql", | ||
"src/polywrap.graphql", | ||
"schema.graphql", | ||
"src/schema.graphql", | ||
]; | ||
const manifestDir = path.dirname(manifestPath); | ||
for (const relPath of defaultSchemaPaths) { | ||
const absPath = path.resolve(manifestDir, relPath); | ||
if (fs.existsSync(absPath)) { | ||
return absPath; | ||
} | ||
} | ||
|
||
throw Error(intlMsg.lib_project_no_default_schema()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { defaultSchemaPath } from "../defaults"; | ||
import { isPluginManifestLanguage, pluginManifestLanguages } from "./languages"; | ||
import { intlMsg } from "../../../intl"; | ||
|
||
import fs from "fs"; | ||
import path from "path"; | ||
import { PluginManifest } from "@polywrap/polywrap-manifest-types-js"; | ||
|
||
export function applyPluginManifestDefaults( | ||
manifest: PluginManifest, | ||
manifestPath: string | ||
): PluginManifest { | ||
if (!manifest.source) { | ||
manifest.source = {}; | ||
} | ||
if (!manifest.source?.module) { | ||
const language = manifest.project.type; | ||
manifest.source.module = defaultModulePath(language, manifestPath); | ||
} | ||
if (!manifest.source.schema) { | ||
manifest.source.schema = defaultSchemaPath(manifestPath); | ||
} | ||
return manifest; | ||
} | ||
|
||
function defaultModulePath( | ||
language: string, | ||
manifestPath: string | ||
): string | undefined { | ||
if (!isPluginManifestLanguage(language)) { | ||
throw Error( | ||
intlMsg.lib_language_unsupportedManifestLanguage({ | ||
language: language, | ||
supported: Object.keys(pluginManifestLanguages).join(", "), | ||
}) | ||
); | ||
} | ||
|
||
let relEntryPoint: string; | ||
if (language === "plugin/typescript") { | ||
relEntryPoint = "src/index.ts"; | ||
} else if (language == "plugin/rust") { | ||
relEntryPoint = "Cargo.toml"; | ||
} else if (language == "plugin/python") { | ||
relEntryPoint = "src/__init__.py"; | ||
} else if (language == "plugin/swift") { | ||
relEntryPoint = "Package.swift"; | ||
} else if (language == "plugin/kotlin") { | ||
relEntryPoint = "src/commonMain/kotlin"; | ||
} else { | ||
throw Error(intlMsg.lib_project_no_default_module()); | ||
} | ||
|
||
const manifestDir = path.dirname(manifestPath); | ||
const absEntryPoint = path.resolve(manifestDir, relEntryPoint); | ||
if (fs.existsSync(absEntryPoint)) { | ||
return relEntryPoint; | ||
} | ||
|
||
throw Error(intlMsg.lib_project_no_default_module()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
packages/cli/src/lib/project/manifests/polywrap/defaults.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { | ||
isPolywrapManifestLanguage, | ||
polywrapManifestLanguages, | ||
} from "./languages"; | ||
import { defaultSchemaPath } from "../defaults"; | ||
import { intlMsg } from "../../../intl"; | ||
|
||
import fs from "fs"; | ||
import path from "path"; | ||
import { PolywrapManifest } from "@polywrap/polywrap-manifest-types-js"; | ||
|
||
export function applyPolywrapManifestDefaults( | ||
manifest: PolywrapManifest, | ||
manifestPath: string | ||
): PolywrapManifest { | ||
if (!manifest.source) { | ||
manifest.source = {}; | ||
} | ||
if (!manifest.source.module) { | ||
const language = manifest.project.type; | ||
manifest.source.module = defaultModulePath(language, manifestPath); | ||
} | ||
if (!manifest.source.schema) { | ||
manifest.source.schema = defaultSchemaPath(manifestPath); | ||
} | ||
return manifest; | ||
} | ||
|
||
function defaultModulePath( | ||
language: string, | ||
manifestPath: string | ||
): string | undefined { | ||
if (!isPolywrapManifestLanguage(language)) { | ||
throw Error( | ||
intlMsg.lib_language_unsupportedManifestLanguage({ | ||
language: language, | ||
supported: Object.keys(polywrapManifestLanguages).join(", "), | ||
}) | ||
); | ||
} | ||
|
||
let relEntryPoint: string; | ||
if (language === "wasm/typescript" || language === "wasm/assemblyscript") { | ||
relEntryPoint = "src/index.ts"; | ||
} else if (language == "wasm/rust") { | ||
relEntryPoint = "Cargo.toml"; | ||
} else if (language == "wasm/golang") { | ||
relEntryPoint = "go.mod"; | ||
} else if (language == "interface") { | ||
return undefined; | ||
} else { | ||
throw Error(intlMsg.lib_project_no_default_module()); | ||
} | ||
|
||
const manifestDir = path.dirname(manifestPath); | ||
const absEntryPoint = path.resolve(manifestDir, relEntryPoint); | ||
if (fs.existsSync(absEntryPoint)) { | ||
return absEntryPoint; | ||
} | ||
|
||
throw Error(intlMsg.lib_project_no_default_module()); | ||
} |
Oops, something went wrong.