-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathpublish.py
36 lines (32 loc) · 1.31 KB
/
publish.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# encoding=utf8
import subprocess
import platform
NPM_REPOSITORY="https://registry.npmjs.org"
NPM_REPOSITORY_MIRROR="https://registry.npmmirror.com"
NODE_VERSION = 18
ENCODING = "gbk" if platform.system().lower() == 'windows' else 'utf-8'
def execute(command, with_result = False,encoding = ENCODING):
print(f"[calling]: {command}")
if with_result:
p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, encoding=encoding)
stdout,stderr = p.communicate()
if p.returncode == 0:
return stdout
else:
raise Exception(f"exit with {p.returncode}, stderr: {stderr}")
else:
returncode = subprocess.call(command, shell=True, encoding=encoding)
if returncode != 0:
raise Exception(f"exit with {returncode}")
if __name__ == '__main__':
registry = execute(f'npm config get registry', with_result=True)
node_version = execute(f'node -v', with_result=True)
if not node_version.startswith(f'v{NODE_VERSION}'):
raise Exception(f'Node version must be {NODE_VERSION}')
try:
execute(f'pnpm install')
execute(f'pnpm run build')
execute(f'npm config set registry {NPM_REPOSITORY}')
execute(f'npm publish')
finally:
execute(f'npm config set registry {registry}')