1#!/usr/bin/env bash
2# Copyright 2019 The Go Cloud Development Kit Authors
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#     https://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16# This script lists the package names that makeimports.sh would create
17# _index.md files for, one per line.
18
19
20# https://coderwall.com/p/fkfaqq/safer-bash-scripts-with-set-euxo-pipefail
21# except x is too verbose
22set -euo pipefail
23
24# Change into repository root.
25cd "$(dirname "$0")/../.."
26OUTDIR=internal/website/content
27
28shopt -s nullglob  # glob patterns that don't match turn into the empty string, instead of themselves
29
30function files_exist() {  # assumes nullglob
31  [[ ${1:-""} != "" ]]
32}
33
34# Find all directories that do not begin with '.' or '_' or contain 'testdata'. Use the %P printf
35# directive to remove the initial './'.
36for pkg in $(find . -type d \( -name '[._]?*' -prune -o -name testdata -prune -o -printf '%P ' \)); do
37  # Only consider directories that contain Go source files.
38  outfile="$OUTDIR/$pkg/_index.md"
39  if files_exist $pkg/*.go && [[ ! -e "$outfile" ]]; then
40    echo "$pkg"
41  fi
42done
43
44