-
Notifications
You must be signed in to change notification settings - Fork 0
/
install-npm.sh
47 lines (35 loc) · 1.87 KB
/
install-npm.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/bash
# This file is designed to be included in other scripts, and assumes you are currently in the pluginade root directory.
# Check if there's package.json file in the plugin root already, and if its name is different than "pluginade-scripts"
cd $plugindir;
if ([ -f package.json ] && [ "$(jq -r '.name' package.json)" = "pluginade-scripts" ]) || [ ! -f package.json ]; then
# Copy the package.json file from .pluginade to the plugin directory root.
cp /usr/src/pluginade/pluginade-scripts/package.json package.json
fi
# Install pluginade npm dependencies in the plugin root.
if [ ! -d node_modules ] || [ -z "$(ls -A "node_modules")" ]; then
echo "Running npm install in pluginade root at $PWD..."
# Sync the WP external global packages (like react, etc) in package.json with the WordPress version defined in the plugin's readme.txt file.
# See external packages https://github.com/WordPress/gutenberg/tree/trunk/packages/dependency-extraction-webpack-plugin
. /usr/src/pluginade/pluginade-scripts/sync-wp-global-packages.sh
npm install
fi
cd - > /dev/null
# Loop through each wp-module in the plugin, and install their dependencies.
for DIR in "$plugindir"/wp-modules/*; do
# If this module has a package.json file.
if [ -f "$DIR"/package.json ]; then
# Go to the directory of this wp-module.
cd "$DIR";
echo "Confirming npm dependencies for $DIR"
# Sync the WP external global packages (like react, etc) in package.json with the WordPress version defined in the plugin's readme.txt file.
# See external packages https://github.com/WordPress/gutenberg/tree/trunk/packages/dependency-extraction-webpack-plugin
. /usr/src/pluginade/pluginade-scripts/sync-wp-global-packages.sh
# Run npm install for this module.
if [ ! -d node_modules ] || [ -z "$(ls -A "$DIR/node_modules")" ]; then
echo "Running npm install..."
npm install
fi
cd - > /dev/null
fi
done