Skip to content

Commit 87451c0

Browse files
committed
set package version
1 parent 340c12f commit 87451c0

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

TODO.md

-1
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-
- patch NPM version before publishing

src/npm_utils.py

+17-3
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,21 @@
1010
from .version_utils import get_version
1111

1212

13-
def get_npm_package_name(root_path: Path):
13+
def get_package_name(root_path: Path):
1414
with open(root_path / 'package.json', 'r') as file:
1515
package_data = json.load(file)
16-
return package_data['name']
16+
17+
return package_data['name']
18+
19+
20+
def set_package_version(root_path: Path, version: int):
21+
with open(root_path / 'package.json', 'r') as file:
22+
package_data = json.load(file)
23+
24+
package_data['version'] = f'{version}.0.0'
25+
26+
with open('package.json', 'w') as file:
27+
json.dump(package_data, file, indent=2)
1728

1829

1930
def authenticate(src: Path, npm_access_token: str):
@@ -32,7 +43,6 @@ def publish_npm_package(
3243
github_access_token: str,
3344
ignore: List[str] = [],
3445
):
35-
package_name = get_npm_package_name(src)
3646

3747
if not npm_access_token:
3848
print('NPM access token is missing', flush=True, file=sys.stderr)
@@ -48,8 +58,12 @@ def publish_npm_package(
4858
if not changed:
4959
return
5060

61+
package_name = get_package_name(src)
62+
5163
authenticate(src, npm_access_token)
5264

65+
set_package_version(src, version)
66+
5367
run(['npm', 'publish', '--access=public'], cwd=src, check=True)
5468

5569
create_release(

0 commit comments

Comments
 (0)