-
Notifications
You must be signed in to change notification settings - Fork 223
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add programs and content scripts (#11419)
- Loading branch information
Showing
8 changed files
with
490 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
#!/bin/bash | ||
|
||
set -o errexit -o pipefail | ||
|
||
source ./scripts/common.sh | ||
source ./scripts/programs/common.sh | ||
|
||
cloud="" | ||
example_name="" | ||
example_description="" | ||
examples_dir="static/programs" | ||
|
||
prompt_for_cloud() { | ||
read -p "Cloud (e.g., aws): " cloud | ||
|
||
if [[ ! -z "$cloud" ]]; then | ||
return | ||
fi | ||
|
||
echo "Enter a cloud name that exists in pulumi/templates, like 'aws-native' or 'scaleway'." | ||
echo | ||
prompt_for_cloud | ||
} | ||
|
||
prompt_for_example_name() { | ||
read -p "Example name (e.g., awsx-apigateway-lambda): " example_name | ||
|
||
if [ ! -z "$example_name" ]; then | ||
return | ||
fi | ||
|
||
echo "Please give the example a name." | ||
prompt_for_example_name | ||
} | ||
|
||
prompt_for_example_description() { | ||
read -p "Example description (e.g., 'An example that deploys an API Gateway REST API on AWS.'): " example_description | ||
|
||
if [ ! -z "$example_description" ]; then | ||
return | ||
fi | ||
|
||
echo "Please give the example a description." | ||
prompt_for_example_description | ||
} | ||
|
||
generate_example() { | ||
languages=(javascript typescript python go csharp java yaml) | ||
echo | ||
|
||
for language in "${languages[@]}"; do | ||
example_dir="${examples_dir}/${example_name}-${language}" | ||
|
||
rm -rf "${example_dir}" | ||
mkdir -p "${example_dir}" | ||
|
||
pushd "$example_dir" > /dev/null | ||
echo "Creating ${example_dir} ..." | ||
pulumi new "${cloud}-${language}" --description="${example_description}" --yes --force --generate-only > /dev/null | ||
pulumi install > /dev/null | ||
popd > /dev/null | ||
done | ||
|
||
unsuffix_gomods | ||
} | ||
|
||
echo | ||
echo "So, you want to make a new example program? Awesome! 🙌" | ||
echo | ||
echo "Step 1: Choose a cloud. Your example will be built from an existing Pulumi template, | ||
so choose a cloud/provider that we have an existing <cloud>-<language> template for, like | ||
'aws', 'azure', 'gcp', or 'digitalocean'." | ||
echo | ||
prompt_for_cloud | ||
|
||
echo | ||
echo "Step 2: Give the example a descriptive, Pulumi project-friendly name. This name will | ||
be used for the project prefix. Try to choose a name that succinctly describes the content | ||
of the example, rather than the specific page you're building it for, as this'll make the | ||
example more easily findable and reusable." | ||
echo | ||
prompt_for_example_name | ||
|
||
echo | ||
echo "Step 3: Give the example a project description. This will be used for the description | ||
field in Pulumi.yaml." | ||
echo | ||
prompt_for_example_description | ||
|
||
generate_example | ||
echo | ||
echo "✨ Done! Your new projects are now available at ${examples_dir}/${example_name}. To | ||
include them in any Markdown file (blog post, doc, whatever), use the '{{< example-program >}}' | ||
shortcode thusly: | ||
{{< example-program path=\"${example_name}\" >}} | ||
Enjoy!" | ||
echo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#!/bin/bash | ||
|
||
set -o errexit -o pipefail | ||
|
||
module="" | ||
topic="" | ||
|
||
content_dir="content" | ||
|
||
prompt_for_module_name() { | ||
read -p "Module name (e.g., pulumi-101-aws): " module | ||
|
||
if [ ! -z "$module" ]; then | ||
hugo new --kind learn/module --contentDir "${content_dir}" "learn/${module}" | ||
return | ||
fi | ||
|
||
echo "Please give the module a name." | ||
prompt_for_module_name | ||
} | ||
|
||
prompt_for_topic_name() { | ||
read -p "Topic name (e.g., basics): " topic | ||
|
||
if [ ! -z "$topic" ]; then | ||
hugo new --kind learn/topic --contentDir "${content_dir}" "learn/${module}/${topic}" | ||
return | ||
fi | ||
|
||
echo "Please give the topic a name." | ||
prompt_for_topic_name | ||
} | ||
|
||
echo "So, you want to make a new Learn Pulumi module? Awesome! 🙌" | ||
echo | ||
echo "Step 1:" | ||
echo "First, give the module a URL- and SEO-friendly name. | ||
For example, to create a new module that'll live at | ||
https://pulumi.com/learn/pulumi-101, type 'pulumi-101'." | ||
echo | ||
prompt_for_module_name | ||
|
||
echo | ||
echo "Step 2:" | ||
echo "Now give your new module at least one new topic, also expressed | ||
as a URL-friendly name. For example, to create a new topic under ${module} | ||
that'll live at https://pulumi.com/learn/${module}/basics, type 'basics'." | ||
echo | ||
prompt_for_topic_name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#!/bin/bash | ||
|
||
set -o errexit -o pipefail | ||
|
||
module="" | ||
topic="" | ||
content_dir="content" | ||
|
||
prompt_for_module_name() { | ||
read -p "Module name (e.g., pulumi-101-aws): " module | ||
|
||
if [[ ! -z "$module" && -d "${content_dir}/learn/${module}" ]]; then | ||
return | ||
fi | ||
|
||
echo "Couldn't find a module with that name. Make sure you're using the path as listed under content/learn." | ||
echo | ||
prompt_for_module_name | ||
} | ||
|
||
prompt_for_topic_name() { | ||
read -p "Topic name (e.g., basics): " topic | ||
|
||
if [ ! -z "$topic" ]; then | ||
hugo new --kind learn/topic --contentDir "${content_dir}" "learn/${module}/${topic}" | ||
return | ||
fi | ||
|
||
echo "Please give the topic a name." | ||
echo | ||
prompt_for_topic_name | ||
} | ||
|
||
echo "So, you want to make a new Learn Pulumi topic? Great! 🙌" | ||
echo | ||
echo "Step 1:" | ||
echo "What is the path name of the module you want to write for?" | ||
echo | ||
prompt_for_module_name | ||
|
||
echo | ||
echo "Step 2:" | ||
echo "Now give your new topic a URL-friendly name. For example, to | ||
create a new topic under ${module} that'll live at | ||
https://pulumi.com/learn/${module}/basics, type 'basics'." | ||
echo | ||
prompt_for_topic_name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#!/bin/bash | ||
|
||
set -o errexit -o pipefail | ||
|
||
type="" | ||
template="" | ||
content_dir="content" | ||
|
||
prompt_for_template_type() { | ||
read -p "Template type (e.g., static-website): " type | ||
|
||
if [[ ! -z "$type" && -d "${content_dir}/templates/${type}" ]]; then | ||
return | ||
fi | ||
|
||
create_template_type | ||
} | ||
|
||
create_template_type() { | ||
echo | ||
read -e -p "Template type '${type}' doesn't exist in '${content_dir}/templates'. Create it [y/n]? " choice | ||
|
||
if [[ "$choice" == [Yy]* ]]; then | ||
hugo new --kind templates/type --contentDir "${content_dir}" "templates/${type}" | ||
return | ||
fi | ||
|
||
echo "Ok, exiting." | ||
exit 0 | ||
} | ||
|
||
prompt_for_template_name() { | ||
read -p "Template name (e.g., azure): " template | ||
|
||
if [ ! -z "$template" ]; then | ||
hugo new --kind templates/template --contentDir "${content_dir}" "templates/${type}/${template}" | ||
return | ||
fi | ||
|
||
echo "Please give the template a name." | ||
echo | ||
prompt_for_template_name | ||
} | ||
|
||
echo "So, you want to make a new Pulumi template? Great! 🙌" | ||
echo | ||
echo "Step 1:" | ||
echo "What type of template would you like to create?" | ||
echo | ||
prompt_for_template_type | ||
|
||
echo | ||
echo "Step 2:" | ||
echo "Now give your new template a URL-friendly name. For example, to | ||
create a new template under ${type} that'll live at | ||
https://pulumi.com/templates/${type}/azure, type 'azure'." | ||
echo | ||
prompt_for_template_name && echo && echo "Done! You can now run 'make serve' to get started." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/bin/bash | ||
|
||
suffix_gomods() { | ||
for file in $(find ./static/programs/* -name 'go.mod' -not -path "**/node_modules/**") | ||
do | ||
cp $file $(echo "$file" | sed -r 's|.mod|.mod.txt|g') | ||
done | ||
} | ||
|
||
unsuffix_gomods() { | ||
for file in $(find ./static/programs/* -name 'go.mod.txt' -not -path "**/node_modules/**" ) | ||
do | ||
cp $file $(echo "$file" | sed -r 's|.mod.txt|.mod|g') | ||
done | ||
} | ||
|
||
clean_gomods() { | ||
local requires=0 | ||
local i=0 | ||
|
||
for file in $(find ./static/programs/* -name 'go.mod*' -not -path "**/node_modules/**" ) | ||
do | ||
new_file="$(cat $file)" | ||
split_at="$(awk '/require/{i++; if (i==2) { print NR-1; exit }}' $file)" | ||
|
||
if [[ "$split_at" != "" ]]; then | ||
new_file="$(cat $file | head -n $split_at)" | ||
fi | ||
|
||
echo "$new_file" > "$file" | ||
done | ||
} |
Oops, something went wrong.