%{?nodejs_find_provides_and_requires}
%global enable_tests 0
Name:                uglify-js1
Version:             1.3.4
Release:             1
Summary:             JavaScript parser, mangler/compressor and beautifier toolkit
License:             BSD
URL:                 https://github.com/mishoo/UglifyJS
Source0:             http://registry.npmjs.org/uglify-js/-/uglify-js-%{version}.tgz
BuildArch:           noarch
ExclusiveArch:       %{nodejs_arches} noarch
BuildRequires:       nodejs-packaging web-assets-devel
%if 0%{?enable_tests}
BuildRequires:       npm(nodeunit)
%endif
Requires:            js-uglify-1 = %{version}-%{release}
%description
JavaScript parser, mangler/compressor and beautifier toolkit.  This is the
classic 1.x version of uglify-js.  Consider using the new version provided
in the uglify-js package.
This package ships the uglifyjs command-line tool and a library suitable for
use within Node.js.

%package -n js-uglify-1
Summary:             JavaScript parser, mangler/compressor and beautifier toolkit - core library
Obsoletes:           uglify-js1-common < 1.3.4-4
Provides:            uglify-js1-common = %{version}-%{release}
Requires:            web-assets-filesystem
%description -n js-uglify-1
JavaScript parser, mangler/compressor and beautifier toolkit.  This is the
classic 1.x version of uglify-js.  Consider using the new version provided
in the uglify-js package.
This package ships a JavaScript library suitable for use by any JavaScript
runtime.

%prep
%setup -q -n package

%build

%install
rm -rf %buildroot
mkdir -p %{buildroot}%{_jsdir}/uglify-js-1
cp -pr lib/* %{buildroot}%{_jsdir}/uglify-js-1
mkdir -p %{buildroot}%{_datadir}
ln -sf javascript/uglify-js-1 %{buildroot}%{_datadir}/%{name}
mkdir -p %{buildroot}%{nodejs_sitelib}/uglify-js@1
cp -pr bin package.json uglify-js.js %{buildroot}%{nodejs_sitelib}/uglify-js@1
ln -sf %{_jsdir}/uglify-js-1 %{buildroot}%{nodejs_sitelib}/uglify-js@1/lib
ln -sf uglify-js@1 %{buildroot}%{nodejs_sitelib}/%{name}
mkdir -p %{buildroot}%{_bindir}
ln -sf ../lib/node_modules/uglify-js1/bin/uglifyjs %{buildroot}%{_bindir}/uglifyjs1
%if 0%{?enable_tests}

%check
%nodejs_symlink_deps --check
nodeunit test/unit/scripts.js && test/testparser.js && test/testconsolidator.js
%endif

%pretrans -p <lua>
st = posix.stat("%{nodejs_sitelib}/uglify-js1")
if st and st.type == "directory" then
  os.execute("rm -rf %{nodejs_sitelib}/uglify-js1")
end

%pretrans -n js-uglify-1 -p <lua>
st = posix.stat("%{_datadir}/%{name}")
if st and st.type == "directory" then
  os.execute("rm -rf %{_datadir}/%{name}")
end

%files
%{nodejs_sitelib}/uglify-js@1
%{nodejs_sitelib}/uglify-js1
%{_bindir}/uglifyjs1

%files -n js-uglify-1
%{_jsdir}/uglify-js-1
%{_datadir}/%{name}
%doc README.html README.org docstyle.css

%changelog
* Tue Aug 11 2020 wangyue <wangyue92@huawei.com> - 1.3.4-1
- package init