You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

152 lines
4.1 KiB

  1. #!/usr/bin/expect -f
  2. # OMG THIS WAS A PAIN TO CREATE
  3. if {$argc == 0} {
  4. # No template specified, iterate over all templates.
  5. set templates [list jquery commonjs node gruntplugin gruntfile]
  6. } else {
  7. # One or more templates were specified, iterate over those.
  8. set templates [lrange $argv 0 end]
  9. }
  10. foreach template $templates {
  11. set project "grunt-init-$template-sample"
  12. # Disable git pushing when debugging.
  13. set gitpush 1
  14. # Grunt version
  15. set version [exec grunt --version]
  16. # Stop any already-running logging.
  17. log_file
  18. # Start logging fresh, saving output for later use.
  19. log_file -noappend /tmp/grunt-expect-out
  20. # Spawn bash without all my crazy dotfiles stuff.
  21. set timeout -1
  22. spawn bash --noprofile --norc
  23. match_max 100000
  24. # Make the prompt look nice.
  25. expect "$ "
  26. send "PS1='\n$ '\r"
  27. expect "\r"
  28. # Cleanup any existing session.
  29. expect "$ "
  30. send "cd /tmp\r"
  31. expect "$ "
  32. send "rm -rf /tmp/$project\r"
  33. # Session logging starts here.
  34. expect "$ "
  35. send "mkdir $project && cd $project\r"
  36. # Initialize the current directory.
  37. expect "$ "
  38. send "git init\r"
  39. expect "$ "
  40. send "git remote add origin git@github.com:gruntjs/$project.git\r"
  41. # Note that the "--no-color" will be stripped out later.
  42. expect "$ "
  43. send "grunt init:$template --no-color\r"
  44. # Don't start answering prompts until this line is encountered.
  45. expect "Please answer the following:"
  46. # Loop over all prompts.
  47. expect {
  48. "Do you need to make any changes to the above before continuing? (y/N)" {send "\r"}
  49. "Project name (grunt-init-jquery-sample)" {send "grunt-sample\r"; exp_continue}
  50. "Project title (Grunt Sample)" {send "Sample Grunt jQuery Plugin\r"; exp_continue}
  51. ") " {send "\r"; exp_continue}
  52. }
  53. # Pre-grunt file structure.
  54. expect "$ "
  55. send "tree\r"
  56. # Let grunt grunt the newly-created file structure.
  57. expect "$ "
  58. send "grunt --no-color\r"
  59. # Post-grunt file structure. Any built files should appear here.
  60. expect "$ "
  61. send "tree\r"
  62. # Commit everything.
  63. expect "$ "
  64. send "git add .\r"
  65. expect "$ "
  66. send "git commit -m 'Committing sample \"grunt init:$template\" task output.'\r"
  67. # Session logging stops here.
  68. expect "$ "
  69. send "# EOF\n"
  70. # Add meta-content to the README.
  71. expect "$ "
  72. send "echo -e '# Grunt \"init:$template\" sample
  73. This is sample output generated by the \"grunt init:$template\" task.
  74. _Note: this repository was generated dynamically using $version. Instead of
  75. reporting issues here, please report any issues with this init template as
  76. \[grunt issues\]\[issues\]. Instead of watching or forking this repository,
  77. watch \[grunt\]\[grunt\] and use the grunt \[init task\]\[init\]._
  78. ## Project Creation Transcript
  79. The following is a transcript of the session in which this project and
  80. repository were created. This is not actually a part of the \[grunt\]\[grunt\]
  81. \"init:$template\" template, this session transcript was added afterwards. The
  82. text after the `$` are the commands that were executed, and everything else is
  83. program output.
  84. **If you want to see the repository exactly as it was created by grunt, \[view
  85. the \"generated\" branch\]\[prev\].**' > README.md\r"
  86. expect "$ "
  87. send "echo -e '
  88. \[grunt\]: http://gruntjs.com/
  89. \[issues\]: https://github.com/gruntjs/grunt/issues
  90. \[init\]: https://github.com/gruntjs/grunt/blob/master/docs/task_init.md
  91. \[expect\]: https://github.com/gruntjs/grunt/blob/master/dev/init.exp
  92. \[prev\]: https://github.com/gruntjs/$project/tree/generated
  93. Note that this entire build process is automated by a rather complex \[expect
  94. script\]\[expect\], which is used to automate grunt in order to facilitate the
  95. creation of this and other \[init task\]\[init\] sample repositories.
  96. ```' >> README.md\r"
  97. expect "$ "
  98. # Strip out everything before the "mkdir" and after the "EOF". Also remove any "--no-color" bits.
  99. send "cat /tmp/grunt-expect-out | perl -ne's/ --no-color//;if(/^\\\$ mkdir/){\$x=1}elsif(/^\\\$ # EOF/){\$x=0}\$x&&print\$_' >> README.md\r"
  100. expect "$ "
  101. send "echo -e '```
  102. ' >> README.md\r"
  103. # Commit again.
  104. expect "$ "
  105. send "git branch generated\r"
  106. expect "$ "
  107. send "git add .\r"
  108. expect "$ "
  109. send "git commit -m 'Adding project creation transcript.'\r"
  110. # Push to GitHub.
  111. if {$gitpush} {
  112. expect "$ "
  113. send "git push -uf --all origin\r"
  114. }
  115. expect "$ "
  116. send "exit\r"
  117. expect eof
  118. }