Skip to content

Commit

Permalink
Update npmpackage to v1.1.0 and refactor package.json logic
Browse files Browse the repository at this point in the history
Bump the version from 1.0.0 to 1.1.0 in the configuration file. Refactor `generate_package_json` to modularize the creation of the package.json, improving code clarity and reusability. Adjust the path handling for entry points and ensure proper sanitization.

Contribute to NP-637
  • Loading branch information
jellespijker committed Dec 17, 2024
1 parent 5e6e7ae commit 598d045
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
23 changes: 14 additions & 9 deletions recipes/npmpackage/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
from conan import ConanFile

import os
from pathlib import Path

from conan import ConanFile

required_conan_version = ">=2.7.0"


def sanitize_version(version):
# npm will otherwise 'sanitize' the version number
return version.replace("+", "-")
# npm will otherwise 'sanitize' the version number
return version.replace("+", "-")


def conf_package_json(conanfile: ConanFile, **kwargs):
entry_point = [p.name for p in Path(conanfile.package_folder, "bin").rglob("*.js")][0]
def generate_package_json(conanfile: ConanFile, entry_point, **kwargs):
package_json = {
"name": f"@{conanfile.author.lower()}/{conanfile.name.lower()}js",
"version": f"{sanitize_version(conanfile.version)}",
"description": f"JavaScript / TypeScript bindings for {conanfile.name}, a {conanfile.description}",
"main": f"bin/{entry_point}",
"main": entry_point,
"repository": {
"type": "git",
"url": conanfile.url
Expand All @@ -25,13 +25,18 @@ def conf_package_json(conanfile: ConanFile, **kwargs):
"license": conanfile.license,
"keywords": conanfile.topics,
"files": [
"bin",
str(Path(entry_point).parent),
"package.json"
]
}
package_json |= kwargs
conanfile.output.info(f"Generated package.json: {package_json}")
return package_json


def conf_package_json(conanfile: ConanFile, **kwargs):
package_json = generate_package_json(conanfile,
os.path.join(conanfile.cpp.package.bindirs[0], conanfile.cpp.package.bin[0]),
**kwargs)
conanfile.conf_info.define(f"user.{conanfile.name.lower()}:package_json", package_json)


Expand Down
2 changes: 1 addition & 1 deletion recipes/npmpackage/config.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
versions:
"1.0.0":
"1.1.0":
folder: "all"

0 comments on commit 598d045

Please sign in to comment.