Skip to content

Commit 0363541

Browse files
committed
[vue2] upload publish.py
1 parent 78ec946 commit 0363541

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

publish.py

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

0 commit comments

Comments
 (0)