-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall_node_packages
executable file
·43 lines (34 loc) · 1.05 KB
/
install_node_packages
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
37
38
39
40
41
42
43
#!/usr/bin/env python3
#
# Install Node packages in the install_node_packages.txt package list.
import sys
import subprocess
import shutil
def emulate_run(args, env=None):
p = subprocess.Popen(args, env=env)
if p.wait() == 0:
return True
return False
node = shutil.which('node')
if sys.platform.startswith('win32'):
npm = 'npm.cmd'
else:
npm = shutil.which('npm')
if __name__ == '__main__':
if not node:
node = shutil.which('nodejs')
if not node:
print('error: node is not installed, skipping node module installation')
sys.exit(1)
if not npm:
print('error: npm is not installed, skipping node module installation')
sys.exit(1)
error = False
with open('install_node_packages.txt', 'r') as f:
for line in f:
line = line.strip()
line = line.rstrip('\n')
if line != '' and line[0] != '#':
if not emulate_run([npm, 'install', '--global', line]):
error = True
sys.exit(1 if error else 0)