2
0
mirror of https://github.com/frappe/bench.git synced 2024-09-23 04:29:02 +00:00

[fix] update_npm_packages, patch to install yarn (#572)

This commit is contained in:
Faris Ansari 2018-02-19 13:11:21 +05:30 committed by GitHub
parent 9c834bc561
commit 5d0a453ccb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 49 deletions

View File

@ -1,18 +0,0 @@
{
"name": "frappe",
"description": "Default package.json for frappe apps",
"dependencies": {
"babel-core": "^6.24.1",
"babel-preset-babili": "0.0.12",
"babel-preset-es2015": "^6.24.1",
"babel-preset-es2016": "^6.24.1",
"babel-preset-es2017": "^6.24.1",
"chokidar": "^1.7.0",
"cookie": "^0.3.1",
"express": "^4.15.3",
"less": "^2.7.2",
"redis": "^2.7.1",
"socket.io": "^2.0.1",
"superagent": "^3.5.2"
}
}

View File

@ -3,4 +3,4 @@ bench.patches.v3.celery_to_rq
bench.patches.v3.redis_bind_ip bench.patches.v3.redis_bind_ip
bench.patches.v4.update_node bench.patches.v4.update_node
bench.patches.v4.update_socketio bench.patches.v4.update_socketio
bench.patches.v4.install_yarn

View File

@ -0,0 +1,4 @@
import subprocess
def execute(bench_path):
subprocess.check_output(['npm', 'install', '-g', 'yarn'])

View File

@ -144,7 +144,7 @@ def exec_cmd(cmd, cwd='.'):
def which(executable, raise_err = False): def which(executable, raise_err = False):
from distutils.spawn import find_executable from distutils.spawn import find_executable
exec_ = find_executable(executable) exec_ = find_executable(executable)
if not exec_ and raise_err: if not exec_ and raise_err:
raise ValueError('{executable} not found.'.format( raise ValueError('{executable} not found.'.format(
executable = executable executable = executable
@ -430,34 +430,11 @@ def update_requirements(bench_path='.'):
def update_npm_packages(bench_path='.'): def update_npm_packages(bench_path='.'):
print('Updating node libraries...') print('Updating node libraries...')
apps_dir = os.path.join(bench_path, 'apps') apps_dir = os.path.join(bench_path, 'apps')
package_json = {}
for app in os.listdir(apps_dir): for app in os.listdir(apps_dir):
package_json_path = os.path.join(apps_dir, app, 'package.json') app_path = os.path.join(apps_dir, app)
exec_cmd('yarn install', cwd=app_path)
if os.path.exists(package_json_path):
with open(package_json_path, "r") as f:
app_package_json = json.loads(f.read())
# package.json is usually a dict in a dict
for key, value in iteritems(app_package_json):
if not key in package_json:
package_json[key] = value
else:
if isinstance(value, dict):
package_json[key].update(value)
elif isinstance(value, list):
package_json[key].extend(value)
else:
package_json[key] = value
if package_json is {}:
with open(os.path.join(os.path.dirname(__file__), 'package.json'), 'r') as f:
package_json = json.loads(f.read())
with open(os.path.join(bench_path, 'package.json'), 'w') as f:
f.write(json.dumps(package_json, indent=1, sort_keys=True))
exec_cmd('npm install', cwd=bench_path)
def install_requirements(pip, req_file): def install_requirements(pip, req_file):
if os.path.exists(req_file): if os.path.exists(req_file):
@ -784,12 +761,11 @@ def run_playbook(playbook_name, extra_vars=None, tag=None):
print("Ansible is needed to run this command, please install it using 'pip install ansible'") print("Ansible is needed to run this command, please install it using 'pip install ansible'")
sys.exit(1) sys.exit(1)
args = ['ansible-playbook', '-c', 'local', playbook_name] args = ['ansible-playbook', '-c', 'local', playbook_name]
if extra_vars: if extra_vars:
args.extend(['-e', json.dumps(extra_vars)]) args.extend(['-e', json.dumps(extra_vars)])
if tag: if tag:
args.extend(['-t', tag]) args.extend(['-t', tag])
subprocess.check_call(args, cwd=os.path.join(os.path.dirname(bench.__path__[0]), 'playbooks')) subprocess.check_call(args, cwd=os.path.join(os.path.dirname(bench.__path__[0]), 'playbooks'))