diff --git a/bench/app.py b/bench/app.py index 281a0f8f..f5fd8fa4 100755 --- a/bench/app.py +++ b/bench/app.py @@ -253,7 +253,7 @@ def get_repo_dir(app, bench_path='.'): return os.path.join(bench_path, 'apps', app) def switch_branch(branch, apps=None, bench_path='.', upgrade=False, check_upgrade=True): - from .utils import update_requirements, backup_all_sites, patch_sites, build_assets, pre_upgrade, post_upgrade + from .utils import update_requirements, update_npm_packages, backup_all_sites, patch_sites, build_assets, pre_upgrade, post_upgrade from . import utils apps_dir = os.path.join(bench_path, 'apps') version_upgrade = (False,) @@ -293,6 +293,7 @@ def switch_branch(branch, apps=None, bench_path='.', upgrade=False, check_upgrad if version_upgrade[0] and upgrade: update_requirements() + update_npm_packages() pre_upgrade(version_upgrade[1], version_upgrade[2]) reload(utils) backup_all_sites() diff --git a/bench/commands/setup.py b/bench/commands/setup.py index 76921023..e8975eb0 100755 --- a/bench/commands/setup.py +++ b/bench/commands/setup.py @@ -117,6 +117,12 @@ def setup_socketio(): from bench.utils import setup_socketio setup_socketio() +@click.command('requirements') +def setup_requirements(): + "Setup python and node requirements" + from bench.utils import update_requirements, update_npm_packages + update_requirements() + update_npm_packages() @click.command('config') def setup_config(): @@ -185,6 +191,7 @@ setup.add_command(setup_backups) setup.add_command(setup_env) setup.add_command(setup_procfile) setup.add_command(setup_socketio) +setup.add_command(setup_requirements) setup.add_command(setup_config) setup.add_command(setup_fonts) setup.add_command(add_domain) diff --git a/bench/commands/update.py b/bench/commands/update.py index b3bcc383..d38e82e0 100755 --- a/bench/commands/update.py +++ b/bench/commands/update.py @@ -3,7 +3,7 @@ import sys, os from bench.config.common_site_config import get_config from bench.app import pull_all_apps, is_version_upgrade from bench.utils import (update_bench, validate_upgrade, pre_upgrade, post_upgrade, before_update, - update_requirements, backup_all_sites, patch_sites, build_assets, restart_supervisor_processes) + update_requirements, update_npm_packages, backup_all_sites, patch_sites, build_assets, restart_supervisor_processes) from bench import patches #TODO: Not DRY @@ -62,7 +62,8 @@ def update(pull=False, patch=False, build=False, bench=False, auto=False, restar _update(pull, patch, build, bench, auto, restart_supervisor, requirements, no_backup, upgrade, force=force, reset=reset) -def _update(pull=False, patch=False, build=False, update_bench=False, auto=False, restart_supervisor=False, requirements=False, no_backup=False, upgrade=False, bench_path='.', force=False, reset=False): +def _update(pull=False, patch=False, build=False, update_bench=False, auto=False, restart_supervisor=False, + requirements=False, no_backup=False, upgrade=False, bench_path='.', force=False, reset=False): conf = get_config(bench_path=bench_path) version_upgrade = is_version_upgrade(bench_path=bench_path) @@ -78,8 +79,8 @@ def _update(pull=False, patch=False, build=False, update_bench=False, auto=False pull_all_apps(bench_path=bench_path, reset=reset) if requirements: - print('Updating Python libraries...') update_requirements(bench_path=bench_path) + update_npm_packages(bench_path=bench_path) if upgrade and (version_upgrade[0] or (not version_upgrade[0] and force)): pre_upgrade(version_upgrade[1], version_upgrade[2], bench_path=bench_path) diff --git a/bench/package.json b/bench/package.json new file mode 100644 index 00000000..31121283 --- /dev/null +++ b/bench/package.json @@ -0,0 +1,18 @@ +{ + "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" + } +} diff --git a/bench/utils.py b/bench/utils.py index 6cc26a1f..50040f33 100755 --- a/bench/utils.py +++ b/bench/utils.py @@ -61,7 +61,7 @@ def init(path, apps_path=None, no_procfile=False, no_backups=False, bench.set_frappe_version(bench_path=path) if bench.FRAPPE_VERSION > 5: - setup_socketio(bench_path=path) + update_npm_packages(bench_path=path) set_all_patches_executed(bench_path=path) build_assets(bench_path=path) @@ -382,6 +382,7 @@ def set_default_site(site, bench_path='.'): cwd=os.path.join(bench_path, 'sites')) def update_requirements(bench_path='.'): + print('Updating Python libraries...') pip = os.path.join(bench_path, 'env', 'bin', 'pip') # upgrade pip to latest @@ -397,6 +398,38 @@ def update_requirements(bench_path='.'): req_file = os.path.join(apps_dir, app, 'requirements.txt') install_requirements(pip, req_file) +def update_npm_packages(bench_path='.'): + print('Updating node libraries...') + apps_dir = os.path.join(bench_path, 'apps') + package_json = {} + + for app in os.listdir(apps_dir): + package_json_path = os.path.join(apps_dir, app, 'package.json') + + 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 app_package_json.iteritems(): + 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): if os.path.exists(req_file): exec_cmd("{pip} install -q -r {req_file}".format(pip=pip, req_file=req_file)) diff --git a/playbooks/develop/includes/setup_dev_env.yml b/playbooks/develop/includes/setup_dev_env.yml index 3b54c2af..4e07360e 100644 --- a/playbooks/develop/includes/setup_dev_env.yml +++ b/playbooks/develop/includes/setup_dev_env.yml @@ -1,10 +1,4 @@ --- - # Setup Socketio - - name: setup procfile - command: bench setup socketio - args: - creates: "{{ bench_path }}/node_modules" - chdir: "{{ bench_path }}" # Setup Procfile - name: setup procfile