diff --git a/recipes/npmpackage/all/conanfile.py b/recipes/npmpackage/all/conanfile.py new file mode 100644 index 0000000..066f94f --- /dev/null +++ b/recipes/npmpackage/all/conanfile.py @@ -0,0 +1,45 @@ +from conan import ConanFile +from conan.tools.scm import Version + +from pathlib import Path + +required_conan_version = ">=2.7.0" + + +def sanitize_version(version: Version): + if version.pre: + return str(version) + else: + # npm will otherwise 'sanitize' the version number + return str(version).replace("+", "_") + + +def conf_package_json(conanfile: ConanFile, **kwargs): + entry_point = [p.name for p in Path(conanfile.package_folder, "bin").rglob("*.js")][0] + package_json = { + "name": f"@{conanfile.author.lower()}/{conanfile.name.lower()}js", + "version": f"{sanitize_version(Version(conanfile.version))}", + "description": f"JavaScript / TypeScript bindings for {conanfile.name}, a {conanfile.description}", + "main": f"bin/{entry_point}", + "repository": { + "type": "git", + "url": conanfile.url + }, + "author": conanfile.author, + "license": conanfile.license, + "keywords": conanfile.topics, + "files": [ + "bin", + "package.json" + ] + } + package_json |= kwargs + conanfile.output.info(f"Generated package.json: {package_json}") + + conanfile.conf_info.define(f"user.{conanfile.name.lower()}:package_json", package_json) + + +class PyReq(ConanFile): + name = "npmpackage" + description = "This is a base conan file description for C++ libraries/applications that use the npm generator" + package_type = "python-require" diff --git a/recipes/npmpackage/config.yml b/recipes/npmpackage/config.yml new file mode 100644 index 0000000..c7f1363 --- /dev/null +++ b/recipes/npmpackage/config.yml @@ -0,0 +1,3 @@ +versions: + "1.0.0": + folder: "all"