This is my first draft of a script, and corresponding spec file changes.
Feedback is welcome.
Bundling Script:
#!/bin/bash
PACKAGE="node-static"
VERSION="$(npm view ${PACKAGE} version)"
TMP_DIR=$(mktemp -d -t ci-XXXXXXXXXX)
mkdir ${TMP_DIR}
pushd ${TMP_DIR}
npm pack ${PACKAGE}
tar xfz *.tgz
cd package
npm install --no-optional --only=prod
# FIND SOMEWHERE TO PUT LICENSES
# FOR NOW JUST PRINT THEM OUT
find . -name "package.json" -exec jq .license {} \; | sort -u
mv node_modules/ node_modules_prod
npm install --no-optional --only=dev
mv node_modules/ node_modules_dev
tar cfz ../${PACKAGE}-${VERSION}-nm-prod.tgz node_modules_prod
tar cfz ../${PACKAGE}-${VERSION}-nm-dev.tgz node_modules_dev
cd ..
cp ${PACKAGE}-${VERSION}* $HOME/rpmbuild/SOURCES
popd
rm -rf ${TMP_DIR}
Spec File Changes:
...
License: <license1> and <license2> and <license3>
...
Source1: %{npm_name}-%{version}-nm-prod.tgz
Source2: %{npm_name}-%{version}-nm-dev.tgz
...
%install
...
# Setup bundled node modules
tar xfz %{SOURCE1}
mkdir -p node_modules
pushd node_modules
ln -s ../node_modules_prod/* .
ln -s ../node_modules_prod/.bin .
popd
cp -pr node_modules node_modules_prod %{buildroot}%{nodejs_sitelib}/%{npm_name}
...
%check
%nodejs_symlink_deps --check
%if 0%{?enable_tests}
tar xfz %{SOURCE2}
pushd node_modules
ln -s ../node_modules_dev/* .
popd
pushd node_modules/.bin
ln -s ../../node_modules_dev/.bin/* .
popd
# Example test run using the binary in ./node_modules/.bin/
./node_modules/.bin/vows --spec --isolate
%endif
...
Known Issues:
- Hard coded package name, make that a variable.
- License - Tells you what they are, doesn't put them in nice format.
- Only for no-arch packages. Doesn't deal with packages that need to
be compiled.
- Spec file stuff is a bit ugly. Possibly write some macros once
things are finalized.
Notes:
- I used npm-install instead of yarn because npm because npm is in
RHEL, and when people think of nodejs modules, npm is usually what
they first thing ok.
- Although this has only been tested on one package, I believe it
should work on most no-arch nodejs packages.
Any changes and/or improvements that people think should be made?
Troy