fix(dev-install): resolve CLI entrypoint from metadata with fallbacks
Co-authored-by: Aditya Advani <aditya@moltpod.com>
This commit is contained in:
parent
2c6e22e746
commit
4cc27b4993
@ -83,27 +83,78 @@
|
||||
msg: "Build failed - dist directory not found"
|
||||
when: not dist_dir.stat.exists
|
||||
|
||||
- name: Resolve openclaw CLI entrypoint path
|
||||
ansible.builtin.shell:
|
||||
cmd: |
|
||||
set -euo pipefail
|
||||
for rel in openclaw.mjs bin/openclaw.js dist/index.js; do
|
||||
if [ -f "{{ openclaw_repo_dir }}/$rel" ]; then
|
||||
printf '%s\n' "{{ openclaw_repo_dir }}/$rel"
|
||||
exit 0
|
||||
fi
|
||||
done
|
||||
exit 1
|
||||
executable: /bin/bash
|
||||
register: openclaw_cli_entry
|
||||
- name: Check for package metadata
|
||||
ansible.builtin.stat:
|
||||
path: "{{ openclaw_repo_dir }}/package.json"
|
||||
register: openclaw_package_json_stat
|
||||
|
||||
- name: Read package metadata
|
||||
ansible.builtin.slurp:
|
||||
src: "{{ openclaw_repo_dir }}/package.json"
|
||||
register: openclaw_package_json_raw
|
||||
when: openclaw_package_json_stat.stat.exists
|
||||
|
||||
- name: Parse package metadata
|
||||
ansible.builtin.set_fact:
|
||||
openclaw_package_json: "{{ openclaw_package_json_raw.content | b64decode | from_json }}"
|
||||
when: openclaw_package_json_stat.stat.exists
|
||||
|
||||
- name: Resolve metadata-defined CLI entrypoint
|
||||
ansible.builtin.set_fact:
|
||||
openclaw_package_bin_entry: >-
|
||||
{{
|
||||
openclaw_package_json.bin
|
||||
if openclaw_package_json.bin is string else
|
||||
(
|
||||
openclaw_package_json.bin.openclaw
|
||||
if openclaw_package_json.bin is mapping and 'openclaw' in openclaw_package_json.bin else
|
||||
(
|
||||
(openclaw_package_json.bin | dict2items | map(attribute='value') | list | first)
|
||||
if openclaw_package_json.bin is mapping else
|
||||
''
|
||||
)
|
||||
)
|
||||
}}
|
||||
when: openclaw_package_json_stat.stat.exists
|
||||
|
||||
- name: Build CLI entrypoint candidate list
|
||||
ansible.builtin.set_fact:
|
||||
openclaw_cli_candidate_paths: >-
|
||||
{{
|
||||
[
|
||||
openclaw_package_bin_entry | default(''),
|
||||
'openclaw.mjs',
|
||||
'bin/openclaw.js',
|
||||
'dist/index.js'
|
||||
] | reject('equalto', '') | unique | list
|
||||
}}
|
||||
|
||||
- name: Check possible OpenClaw CLI entrypoints
|
||||
ansible.builtin.stat:
|
||||
path: "{{ openclaw_repo_dir }}/{{ item }}"
|
||||
loop: "{{ openclaw_cli_candidate_paths }}"
|
||||
register: openclaw_cli_candidates
|
||||
|
||||
- name: Resolve OpenClaw CLI entrypoint path
|
||||
ansible.builtin.set_fact:
|
||||
openclaw_cli_entry: >-
|
||||
{{
|
||||
(
|
||||
openclaw_cli_candidates.results
|
||||
| selectattr('stat.exists')
|
||||
| map(attribute='stat.path')
|
||||
| list
|
||||
| first
|
||||
) | default('')
|
||||
}}
|
||||
changed_when: false
|
||||
|
||||
- name: Fail if openclaw CLI entrypoint is missing
|
||||
ansible.builtin.fail:
|
||||
msg: >-
|
||||
Unable to locate OpenClaw CLI entrypoint in {{ openclaw_repo_dir }}.
|
||||
Expected one of: openclaw.mjs, bin/openclaw.js, dist/index.js
|
||||
when: (openclaw_cli_entry.stdout | trim) == ""
|
||||
Expected one of: {{ openclaw_cli_candidate_paths | join(', ') }}
|
||||
when: openclaw_cli_entry == ""
|
||||
|
||||
- name: Remove existing global openclaw symlink (if any)
|
||||
ansible.builtin.file:
|
||||
@ -112,7 +163,7 @@
|
||||
|
||||
- name: Create symlink to openclaw binary
|
||||
ansible.builtin.file:
|
||||
src: "{{ openclaw_cli_entry.stdout | trim }}"
|
||||
src: "{{ openclaw_cli_entry }}"
|
||||
dest: "{{ openclaw_home }}/.local/bin/openclaw"
|
||||
state: link
|
||||
owner: "{{ openclaw_user }}"
|
||||
@ -121,7 +172,7 @@
|
||||
|
||||
- name: Make openclaw binary executable
|
||||
ansible.builtin.file:
|
||||
path: "{{ openclaw_cli_entry.stdout | trim }}"
|
||||
path: "{{ openclaw_cli_entry }}"
|
||||
mode: '0755'
|
||||
owner: "{{ openclaw_user }}"
|
||||
group: "{{ openclaw_user }}"
|
||||
@ -144,7 +195,7 @@
|
||||
msg: |
|
||||
OpenClaw installed from source: {{ openclaw_dev_version.stdout }}
|
||||
Repository: {{ openclaw_repo_dir }}
|
||||
Binary: {{ openclaw_home }}/.local/bin/openclaw -> {{ openclaw_cli_entry.stdout | trim }}
|
||||
Binary: {{ openclaw_home }}/.local/bin/openclaw -> {{ openclaw_cli_entry }}
|
||||
|
||||
- name: Add development mode info to .bashrc
|
||||
ansible.builtin.blockinfile:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user