-
Notifications
You must be signed in to change notification settings - Fork 59
/
generate.exp
executable file
·156 lines (121 loc) · 4.35 KB
/
generate.exp
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/usr/bin/expect -f
# OMG THIS WAS A PAIN TO CREATE
if {$argc == 0} {
# No template specified, iterate over all templates.
set templates [list jquery commonjs node gruntplugin gruntfile]
} else {
# One or more templates were specified, iterate over those.
set templates [lrange $argv 0 end]
}
foreach template $templates {
set project "grunt-init-$template-sample"
# Disable git pushing when debugging.
set gitpush 1
# grunt-init version
set version [exec grunt-init --version | grep grunt-init]
# Stop any already-running logging.
log_file
# Start logging fresh, saving output for later use.
log_file -noappend /tmp/grunt-init-expect-out
# Spawn bash without all my crazy dotfiles stuff.
set timeout -1
spawn bash --noprofile --norc
match_max 100000
# Make the prompt look nice.
expect "$ "
send "PS1='\n$ '\r"
expect "\r"
# Cleanup any existing session.
expect "$ "
send "cd /tmp\r"
expect "$ "
send "rm -rf /tmp/$project\r"
# Session logging starts here.
expect "$ "
send "mkdir $project && cd $project\r"
# Initialize the current directory.
expect "$ "
send "git init\r"
expect "$ "
send "git remote add origin [email protected]:gruntjs/$project.git\r"
# Note that the "--no-color" will be stripped out later.
expect "$ "
send "grunt-init $template --no-color\r"
# Don't start answering prompts until this line is encountered.
expect "Please answer the following:"
# Loop over all prompts.
expect {
"Do you need to make any changes to the above before continuing? (y/N)" {send "\r"}
"Project name (grunt-init-jquery-sample)" {send "grunt-sample\r"; exp_continue}
"Project title (Grunt Sample)" {send "Sample Grunt jQuery Plugin\r"; exp_continue}
") " {send "\r"; exp_continue}
}
# Pre-grunt file structure.
expect "$ "
send "tree -I node_modules\r"
# Install dependencies.
expect "$ "
send "npm install >/dev/null 2>&1 # You typically want to see the output of this command.\r"
# Let grunt grunt the newly-created file structure.
expect "$ "
send "grunt --no-color\r"
# Post-grunt file structure. Any built files should appear here.
expect "$ "
send "tree -I node_modules\r"
# Commit everything.
expect "$ "
send "git add .\r"
expect "$ "
send "git commit -m 'Committing sample grunt-init \"$template\" template output.'\r"
# Session logging stops here.
expect "$ "
send "# EOF\n"
# Add meta-content to the README.
expect "$ "
send "echo -e '# grunt-init \"$template\" sample
This is sample output generated by the grunt-init \"$template\" template.
_Note: this repository was generated dynamically using $version. Instead of
reporting issues here, please report any issues with this init template as
\[grunt-init issues\]\[issues\]. Instead of watching or forking this repository,
watch \[grunt-init\]\[\] instead._
## Project Creation Transcript
The following is a transcript of the session in which this project and
repository were created. This is not actually a part of the \[grunt-init\]\[\]
\"$template\" template, this session transcript was added afterwards. The
text after the `$` are the commands that were executed, and everything else is
program output.
**If you want to see the repository exactly as it was created by grunt-init, \[view
the \"generated\" branch\]\[generated\].**' > README.md\r"
expect "$ "
send "echo -e '
\[grunt-init\]: https://github.com/gruntjs/grunt-init
\[issues\]: https://github.com/gruntjs/grunt-init/issues
\[init\]: https://github.com/gruntjs/grunt/blob/master/docs/task_init.md
\[expect\]: https://github.com/gruntjs/grunt-init/blob/master/dev/generate.exp
\[generated\]: https://github.com/gruntjs/$project/tree/generated
Note that this entire build process is automated by a rather complex \[expect
script\]\[expect\], which is used to automate \[grunt-init\]\[\] in order to
facilitate the creation of this and other sample repositories.
```' >> README.md\r"
expect "$ "
# Strip out everything before the "mkdir" and after the "EOF". Also remove any "--no-color" bits.
send "cat /tmp/grunt-init-expect-out | perl -ne's/ --no-color//;if(/^\\\$ mkdir/){\$x=1}elsif(/^\\\$ # EOF/){\$x=0}\$x&&print\$_' >> README.md\r"
expect "$ "
send "echo -e '```
' >> README.md\r"
# Commit again.
expect "$ "
send "git branch generated\r"
expect "$ "
send "git add .\r"
expect "$ "
send "git commit -m 'Adding project creation transcript.'\r"
# Push to GitHub.
if {$gitpush} {
expect "$ "
send "git push -uf --all origin\r"
}
expect "$ "
send "exit\r"
expect eof
}