%{?nodejs_find_provides_and_requires}
%global enable_tests 0
Name:                nodejs-escodegen
Version:             2.1.0
Release:             1
Summary:             ECMAScript code generator
License:             BSD-2-Clause
URL:                 https://github.com/Constellation/escodegen
Source0:             https://github.com/estools/escodegen/archive/refs/tags/v%{version}.tar.gz
Source10:            dl-tests.sh
BuildArch:           noarch
ExclusiveArch:       %{nodejs_arches} noarch
BuildRequires:       nodejs-packaging
%if 0%{?enable_tests}
BuildRequires:       npm(mocha) npm(chai) npm(estraverse) npm(esutils) npm(source-map)
%endif
%description
%{summary}.

%prep
%autosetup -n escodegen-%{version}
%nodejs_fixdep esprima
%nodejs_fixdep estraverse
%nodejs_fixdep source-map "^0.5.2"
%nodejs_fixdep optionator "^0.8.1"
rm -f *.min.js
sed -i '1s/env //' bin/*.js

%build

%install
mkdir -p %{buildroot}%{nodejs_sitelib}/escodegen
cp -pr package.json escodegen.js \
    %{buildroot}%{nodejs_sitelib}/escodegen
mkdir -p %{buildroot}%{nodejs_sitelib}/escodegen/bin
install -p -D -m0755 bin/escodegen.js \
    %{buildroot}%{nodejs_sitelib}/escodegen/bin/escodegen.js
install -p -D -m0755 bin/esgenerate.js \
    %{buildroot}%{nodejs_sitelib}/escodegen/bin/esgenerate.js
mkdir -p %{buildroot}%{_bindir}
ln -sf %{nodejs_sitelib}/escodegen/bin/escodegen.js \
    %{buildroot}%{_bindir}/escodegen.js
ln -sf %{nodejs_sitelib}/escodegen/bin/esgenerate.js \
    %{buildroot}%{_bindir}/esgenerate.js
%nodejs_symlink_deps
%if 0%{?enable_tests}

%check
%nodejs_symlink_deps --check
%{_bindir}/mocha --reporter spec --timeout 30000
%endif

%files
%{!?_licensedir:%global license %doc}
%license LICENSE.BSD
%{nodejs_sitelib}/escodegen
%{_bindir}/escodegen.js
%{_bindir}/esgenerate.js

%changelog
* Thu Sep 14 2023 wulei <wu_lei@hoperun.com> - 2.1.0-1
- Update to 2.1.0

* Mon May 9 2022 liyanan <liyanan32@h-partners.com> - 1.9.0-2
- License compliance rectification

* Thu Aug 20 2020 Anan Fu <fuanan3@huawei.com> - 1.9.0-1
- package init
