forked from WordPress/gutenberg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-create-block.sh
executable file
·86 lines (66 loc) · 2.05 KB
/
test-create-block.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/bash
# This script validates whether `npm init @wordpress/block` works properly
# with the latest changes applied to the `trunk` branch. It purposefully
# avoids installing `@wordpress/scripts` package from npm when scaffolding
# a test block and uses the local package by executing everything from the
# root of the project.
# Exit if any command fails.
set -e
DIRECTORY="$PWD"
status () {
echo -e "\n\033[1;34m$1\033[0m\n"
}
error () {
echo -e "\n\033[1;31m$1\033[0m\n"
}
cleanup() {
rm -rf "$DIRECTORY/example-static-es5"
rm -rf "$DIRECTORY/example-static"
}
trap cleanup EXIT
# First test block
status "Scaffolding Example Static (ES5) block..."
npx wp-create-block example-static-es5 -t es5
cd example-static-es5
status "Verifying project..."
expected=8
actual=$( find . -maxdepth 1 -type f | wc -l )
if [ "$expected" -ne "$actual" ]; then
error "Expected $expected files in the project root, but found $actual."
exit 1
fi
cd ..
# Second test block
status "Scaffolding Example Static block..."
npx wp-create-block example-static --no-wp-scripts
cd example-static
status "Verifying project..."
expected=5
actual=$( find . -maxdepth 1 -type f | wc -l )
if [ "$expected" -ne "$actual" ]; then
error "Expected $expected files in the project root, but found $actual."
exit 1
fi
expected=6
actual=$( find src -maxdepth 1 -type f | wc -l )
if [ "$expected" -ne "$actual" ]; then
error "Expected $expected files in the \`src\` directory, but found $actual."
exit 1
fi
status "Formatting files..."
../node_modules/.bin/wp-scripts format
status "Building block..."
../node_modules/.bin/wp-scripts build
status "Verifying build..."
expected=5
actual=$( find build -maxdepth 1 -type f | wc -l )
if [ "$expected" -ne "$actual" ]; then
error "Expected $expected files in the \`build\` directory, but found $actual."
exit 1
fi
status "Linting CSS files..."
../node_modules/.bin/wp-scripts lint-style
status "Linting JavaScript files..."
../node_modules/.bin/wp-scripts lint-js
status "Creating a plugin zip file..."
../node_modules/.bin/wp-scripts plugin-zip