@znemz/cfn-include 4.3.1 → 4.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/INSTALL.md +117 -0
- package/bin/cfn +112 -0
- package/package.json +17 -4
- package/scripts/postinstall.js +18 -0
package/INSTALL.md
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
# Installation Guide — Executable YAML
|
|
2
|
+
|
|
3
|
+
## Quick Start
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm install -g @znemz/cfn-include
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
That's it! The `cfn`, `yml`, and `yaml` commands are now available globally.
|
|
10
|
+
|
|
11
|
+
## What Gets Installed
|
|
12
|
+
|
|
13
|
+
npm automatically creates symlinks in your PATH for:
|
|
14
|
+
- `cfn` → executable YAML wrapper
|
|
15
|
+
- `yml` → alias to cfn
|
|
16
|
+
- `yaml` → alias to cfn
|
|
17
|
+
- `cfn-include` → original CLI
|
|
18
|
+
|
|
19
|
+
## Verify Installation
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
which cfn yml yaml
|
|
23
|
+
# Should show paths like:
|
|
24
|
+
# /usr/local/bin/cfn
|
|
25
|
+
# /usr/local/bin/yml
|
|
26
|
+
# /usr/local/bin/yaml
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Make Your First Executable Template
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
# Create a template
|
|
33
|
+
cat > my-stack.yaml << 'TEMPLATE'
|
|
34
|
+
#!/usr/bin/env yaml
|
|
35
|
+
Resources:
|
|
36
|
+
Bucket:
|
|
37
|
+
Type: AWS::S3::Bucket
|
|
38
|
+
TEMPLATE
|
|
39
|
+
|
|
40
|
+
# Make it executable
|
|
41
|
+
chmod +x my-stack.yaml
|
|
42
|
+
|
|
43
|
+
# Run it!
|
|
44
|
+
./my-stack.yaml # Preview
|
|
45
|
+
./my-stack.yaml --deploy # Deploy to AWS
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Troubleshooting
|
|
49
|
+
|
|
50
|
+
### "command not found: cfn"
|
|
51
|
+
|
|
52
|
+
**Cause:** npm bin directory not in PATH
|
|
53
|
+
|
|
54
|
+
**Fix:**
|
|
55
|
+
```bash
|
|
56
|
+
# Find npm bin directory
|
|
57
|
+
npm bin -g
|
|
58
|
+
# Example output: /usr/local/bin
|
|
59
|
+
|
|
60
|
+
# Add to PATH (in ~/.zshrc or ~/.bashrc)
|
|
61
|
+
export PATH="$(npm bin -g):$PATH"
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### "./my-stack.yaml: bad interpreter: /usr/bin/env: cfn: No such file or directory"
|
|
65
|
+
|
|
66
|
+
**Cause:** npm global install location not in PATH, or cfn not executable
|
|
67
|
+
|
|
68
|
+
**Fix:**
|
|
69
|
+
```bash
|
|
70
|
+
# Reinstall globally
|
|
71
|
+
npm install -g @znemz/cfn-include
|
|
72
|
+
|
|
73
|
+
# Verify cfn is executable
|
|
74
|
+
ls -la $(npm bin -g)/cfn
|
|
75
|
+
|
|
76
|
+
# Should show: lrwxr-xr-x ... /usr/local/bin/cfn -> ../lib/node_modules/@znemz/cfn-include/bin/cfn
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Windows Support
|
|
80
|
+
|
|
81
|
+
Shebang (`#!`) is Unix/Linux/macOS only. On Windows:
|
|
82
|
+
|
|
83
|
+
**Option 1: WSL (Recommended)**
|
|
84
|
+
```bash
|
|
85
|
+
# Install in WSL
|
|
86
|
+
npm install -g @znemz/cfn-include
|
|
87
|
+
|
|
88
|
+
# Executable YAML works normally
|
|
89
|
+
chmod +x template.yaml
|
|
90
|
+
./template.yaml --deploy
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
**Option 2: Direct CLI**
|
|
94
|
+
```bash
|
|
95
|
+
# Use cfn-include directly (no shebang)
|
|
96
|
+
cfn-include template.yaml --deploy
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Examples
|
|
100
|
+
|
|
101
|
+
See `examples/` directory:
|
|
102
|
+
- `executable-simple.yaml` — Basic S3 bucket
|
|
103
|
+
- `executable-template.yaml` — Full auto-scaling web stack
|
|
104
|
+
|
|
105
|
+
Both are ready to run:
|
|
106
|
+
```bash
|
|
107
|
+
cd examples
|
|
108
|
+
./executable-simple.yaml
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## Uninstall
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
npm uninstall -g @znemz/cfn-include
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
This removes all bin symlinks automatically.
|
package/bin/cfn
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# cfn - Execute CloudFormation templates with cfn-include preprocessing
|
|
3
|
+
# Makes CloudFormation templates directly executable via shebang
|
|
4
|
+
set -eo pipefail
|
|
5
|
+
|
|
6
|
+
# Find cfn-include - try local dist first, then PATH
|
|
7
|
+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
8
|
+
if [ -f "${SCRIPT_DIR}/../dist/cli.js" ]; then
|
|
9
|
+
# Local installation (development or npm install in project)
|
|
10
|
+
CFN_INCLUDE="${SCRIPT_DIR}/../dist/cli.js"
|
|
11
|
+
USE_NODE=true
|
|
12
|
+
elif command -v cfn-include &> /dev/null; then
|
|
13
|
+
# Global installation (npm install -g)
|
|
14
|
+
CFN_INCLUDE="cfn-include"
|
|
15
|
+
USE_NODE=false
|
|
16
|
+
else
|
|
17
|
+
echo "Error: cfn-include not found. Install with: npm install -g @znemz/cfn-include" >&2
|
|
18
|
+
exit 1
|
|
19
|
+
fi
|
|
20
|
+
|
|
21
|
+
TEMPLATE="$1"
|
|
22
|
+
|
|
23
|
+
if [ -z "$TEMPLATE" ]; then
|
|
24
|
+
echo "Usage: cfn <template.yaml> [options]" >&2
|
|
25
|
+
echo "" >&2
|
|
26
|
+
echo "Options:" >&2
|
|
27
|
+
echo " --deploy Deploy to AWS after processing" >&2
|
|
28
|
+
echo " --stack-name <name> Override stack name (default: filename)" >&2
|
|
29
|
+
echo " --profile <profile> AWS profile to use" >&2
|
|
30
|
+
echo " --region <region> AWS region" >&2
|
|
31
|
+
echo "" >&2
|
|
32
|
+
echo "Environment:" >&2
|
|
33
|
+
echo " STACK_NAME Override stack name" >&2
|
|
34
|
+
echo " AWS_PROFILE AWS profile" >&2
|
|
35
|
+
echo " AWS_REGION AWS region" >&2
|
|
36
|
+
exit 1
|
|
37
|
+
fi
|
|
38
|
+
|
|
39
|
+
# Shift past the template argument
|
|
40
|
+
shift
|
|
41
|
+
|
|
42
|
+
# Parse arguments
|
|
43
|
+
DEPLOY=false
|
|
44
|
+
STACK_NAME=""
|
|
45
|
+
AWS_ARGS=()
|
|
46
|
+
|
|
47
|
+
while [[ $# -gt 0 ]]; do
|
|
48
|
+
case "$1" in
|
|
49
|
+
--deploy)
|
|
50
|
+
DEPLOY=true
|
|
51
|
+
shift
|
|
52
|
+
;;
|
|
53
|
+
--stack-name)
|
|
54
|
+
STACK_NAME="$2"
|
|
55
|
+
shift 2
|
|
56
|
+
;;
|
|
57
|
+
--profile)
|
|
58
|
+
AWS_ARGS+=(--profile "$2")
|
|
59
|
+
shift 2
|
|
60
|
+
;;
|
|
61
|
+
--region)
|
|
62
|
+
AWS_ARGS+=(--region "$2")
|
|
63
|
+
shift 2
|
|
64
|
+
;;
|
|
65
|
+
*)
|
|
66
|
+
# Pass through to cfn-include
|
|
67
|
+
CFN_ARGS+=("$1")
|
|
68
|
+
shift
|
|
69
|
+
;;
|
|
70
|
+
esac
|
|
71
|
+
done
|
|
72
|
+
|
|
73
|
+
# Process with cfn-include
|
|
74
|
+
OUTPUT=$(mktemp -t cfn-exec.XXXXXX.json)
|
|
75
|
+
trap "rm -f '$OUTPUT'" EXIT
|
|
76
|
+
|
|
77
|
+
if [ "$USE_NODE" = true ]; then
|
|
78
|
+
# Local installation - use node to run the script
|
|
79
|
+
if ! node "$CFN_INCLUDE" "$TEMPLATE" -o "$OUTPUT" "${CFN_ARGS[@]}"; then
|
|
80
|
+
echo "❌ cfn-include processing failed" >&2
|
|
81
|
+
exit 1
|
|
82
|
+
fi
|
|
83
|
+
else
|
|
84
|
+
# Global installation - use cfn-include command
|
|
85
|
+
if ! "$CFN_INCLUDE" "$TEMPLATE" -o "$OUTPUT" "${CFN_ARGS[@]}"; then
|
|
86
|
+
echo "❌ cfn-include processing failed" >&2
|
|
87
|
+
exit 1
|
|
88
|
+
fi
|
|
89
|
+
fi
|
|
90
|
+
|
|
91
|
+
# If not deploying, just print processed template
|
|
92
|
+
if [ "$DEPLOY" = false ]; then
|
|
93
|
+
cat "$OUTPUT"
|
|
94
|
+
exit 0
|
|
95
|
+
fi
|
|
96
|
+
|
|
97
|
+
# Determine stack name
|
|
98
|
+
if [ -z "$STACK_NAME" ]; then
|
|
99
|
+
STACK_NAME=$(basename "$TEMPLATE" .yaml)
|
|
100
|
+
STACK_NAME=$(basename "$STACK_NAME" .yml)
|
|
101
|
+
fi
|
|
102
|
+
|
|
103
|
+
echo "🚀 Deploying stack: $STACK_NAME" >&2
|
|
104
|
+
|
|
105
|
+
# Deploy to AWS
|
|
106
|
+
aws cloudformation deploy \
|
|
107
|
+
--template-file "$OUTPUT" \
|
|
108
|
+
--stack-name "$STACK_NAME" \
|
|
109
|
+
--capabilities CAPABILITY_IAM CAPABILITY_NAMED_IAM CAPABILITY_AUTO_EXPAND \
|
|
110
|
+
"${AWS_ARGS[@]}"
|
|
111
|
+
|
|
112
|
+
echo "✅ Stack deployed: $STACK_NAME" >&2
|
package/package.json
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@znemz/cfn-include",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.4.0",
|
|
4
4
|
"description": "Preprocessor for CloudFormation templates with support for loops and flexible include statements",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"aws",
|
|
7
7
|
"cfn",
|
|
8
8
|
"cloudformation",
|
|
9
|
-
"include"
|
|
9
|
+
"include",
|
|
10
|
+
"executable-yaml",
|
|
11
|
+
"shebang",
|
|
12
|
+
"yaml",
|
|
13
|
+
"preprocessor",
|
|
14
|
+
"devops-tools",
|
|
15
|
+
"infrastructure-as-code"
|
|
10
16
|
],
|
|
11
17
|
"homepage": "https://github.com/brickhouse-tech/cfn-include#readme",
|
|
12
18
|
"bugs": {
|
|
@@ -35,15 +41,22 @@
|
|
|
35
41
|
"main": "./dist/index.js",
|
|
36
42
|
"types": "./dist/index.d.ts",
|
|
37
43
|
"bin": {
|
|
38
|
-
"cfn
|
|
44
|
+
"cfn": "./bin/cfn",
|
|
45
|
+
"cfn-include": "./dist/cli.js",
|
|
46
|
+
"yaml": "./bin/yaml",
|
|
47
|
+
"yml": "./bin/yml"
|
|
39
48
|
},
|
|
40
49
|
"files": [
|
|
41
|
-
"dist/"
|
|
50
|
+
"dist/",
|
|
51
|
+
"bin/",
|
|
52
|
+
"scripts/postinstall.js",
|
|
53
|
+
"INSTALL.md"
|
|
42
54
|
],
|
|
43
55
|
"scripts": {
|
|
44
56
|
"better-audit": "better-npm-audit audit",
|
|
45
57
|
"build": "tsc",
|
|
46
58
|
"build:clean": "rm -rf dist && npm run build",
|
|
59
|
+
"postinstall": "node scripts/postinstall.js",
|
|
47
60
|
"lint": "eslint .",
|
|
48
61
|
"lint:fix": "eslint . --fix",
|
|
49
62
|
"prepare": "sort-package-json",
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Post-install message for executable YAML feature
|
|
3
|
+
|
|
4
|
+
const isGlobalInstall = process.env.npm_config_global === 'true';
|
|
5
|
+
|
|
6
|
+
if (isGlobalInstall) {
|
|
7
|
+
console.log('\n✨ cfn-include installed successfully!\n');
|
|
8
|
+
console.log('🔥 NEW: Executable YAML support is now available!\n');
|
|
9
|
+
console.log('Three shebang options to choose from:');
|
|
10
|
+
console.log(' #!/usr/bin/env cfn (CloudFormation-specific)');
|
|
11
|
+
console.log(' #!/usr/bin/env yml (short & clean)');
|
|
12
|
+
console.log(' #!/usr/bin/env yaml (explicit)\n');
|
|
13
|
+
console.log('Quick start:');
|
|
14
|
+
console.log(' 1. Add shebang to your template: #!/usr/bin/env yaml');
|
|
15
|
+
console.log(' 2. Make it executable: chmod +x template.yaml');
|
|
16
|
+
console.log(' 3. Run it: ./template.yaml --deploy\n');
|
|
17
|
+
console.log('📚 Full guide: https://github.com/brickhouse-tech/cfn-include#executable-yaml\n');
|
|
18
|
+
}
|