go_script 0.0.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6a33d0f56a637c8da9a53652adc002a7a9f1b58a
4
+ data.tar.gz: c696612e2b13fd0188cdfdd4262aaf46ebd35f58
5
+ SHA512:
6
+ metadata.gz: 256d24a8a8c2a325dda36883717296185664c91e9d4a619bb56504f54467ddae3906db7e8303881f9fd6d95cd6273e73b1e6d830717221d1df47cf26e09b870e
7
+ data.tar.gz: 136735601a89dd6c735a0393663f505f46a004f3ab4383ea5409eb58273653ae168b5cafd13b722b0dffd33f6510191fa3102bfdfc0b1e953ce0c522cef9c9a8
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,19 @@
1
+ ## Welcome!
2
+
3
+ We're so glad you're thinking about contributing to an 18F open source project! If you're unsure about anything, just ask -- or submit the issue or pull request anyway. The worst that can happen is you'll be politely asked to change something. We love all friendly contributions.
4
+
5
+ We want to ensure a welcoming environment for all of our projects. Our staff follow the [18F Code of Conduct](https://github.com/18F/code-of-conduct/blob/master/code-of-conduct.md) and all contributors should do the same.
6
+
7
+ We encourage you to read this project's CONTRIBUTING policy (you are here), its [LICENSE](LICENSE.md), and its [README](README.md).
8
+
9
+ If you have any questions or want to read more, check out the [18F Open Source Policy GitHub repository]( https://github.com/18f/open-source-policy), or just [shoot us an email](mailto:18f@gsa.gov).
10
+
11
+ ## Public domain
12
+
13
+ This project is in the public domain within the United States, and
14
+ copyright and related rights in the work worldwide are waived through
15
+ the [CC0 1.0 Universal public domain dedication](https://creativecommons.org/publicdomain/zero/1.0/).
16
+
17
+ All contributions to this project will be released under the CC0
18
+ dedication. By submitting a pull request, you are agreeing to comply
19
+ with this waiver of copyright interest.
data/LICENSE.md ADDED
@@ -0,0 +1,31 @@
1
+ As a work of the United States Government, this project is in the
2
+ public domain within the United States.
3
+
4
+ Additionally, we waive copyright and related rights in the work
5
+ worldwide through the CC0 1.0 Universal public domain dedication.
6
+
7
+ ## CC0 1.0 Universal Summary
8
+
9
+ This is a human-readable summary of the [Legal Code (read the full text)](https://creativecommons.org/publicdomain/zero/1.0/legalcode).
10
+
11
+ ### No Copyright
12
+
13
+ The person who associated a work with this deed has dedicated the work to
14
+ the public domain by waiving all of his or her rights to the work worldwide
15
+ under copyright law, including all related and neighboring rights, to the
16
+ extent allowed by law.
17
+
18
+ You can copy, modify, distribute and perform the work, even for commercial
19
+ purposes, all without asking permission.
20
+
21
+ ### Other Information
22
+
23
+ In no way are the patent or trademark rights of any person affected by CC0,
24
+ nor are the rights that other persons may have in the work or in how the
25
+ work is used, such as publicity or privacy rights.
26
+
27
+ Unless expressly stated otherwise, the person who associated a work with
28
+ this deed makes no warranties about the work, and disclaims liability for
29
+ all uses of the work, to the fullest extent permitted by applicable law.
30
+ When using or citing the work, you should not imply endorsement by the
31
+ author or the affirmer.
data/README.md ADDED
@@ -0,0 +1,149 @@
1
+ ## The `./go` script: a unified development environment interface.
2
+
3
+ A `./go` script aims to abstract away all of the steps needed to develop (and
4
+ sometimes deploy) a software project. It is a replacement for READMEs and
5
+ other documents that may become out-of-date, and when maintained properly,
6
+ should provide a cohesive and discoverable interface for common project tasks.
7
+
8
+ This gem abstracts common functionality used in the Ruby-based `./go` scripts
9
+ of several 18F projects, and provides a `./go` script generator for new
10
+ projects.
11
+
12
+ This gem was inspired by the blog articles [In Praise of the ./go Script -
13
+ Part I](http://www.thoughtworks.com/insights/blog/praise-go-script-part-i) and
14
+ [In Praise of the ./go Script - Part
15
+ II](http://www.thoughtworks.com/insights/blog/praise-go-script-part-ii) by
16
+ Pete Hodgson.
17
+
18
+ **Note:** Not to be confused with the [Go programming
19
+ language](https://golang.org). This convention is completely unrelated,
20
+ though it does bear a great deal of resemblance to the Go language's `go`
21
+ command.
22
+
23
+ ### Installation
24
+
25
+ Install [the Ruby programming language](https://www.ruby-lang.org/) if it
26
+ isn't already present on your system. We recommend using a Ruby version
27
+ manager such as [rbenv](https://github.com/sstephenson/rbenv) or
28
+ [rvm](https://rvm.io/) to do this.
29
+
30
+ Install [Bundler](http://bundler.io/) via `gem install bundler`.
31
+
32
+ Finally, install the `go_script` gem via `gem install go_script`. You may also
33
+ wish to add it to the [`Gemfile`](http://bundler.io/gemfile.html) of your
34
+ project to ensure version consistency.
35
+
36
+ ### Creating a `./go` script
37
+
38
+ To create a fresh new `./go` script for your project, run:
39
+
40
+ ```shell
41
+ $ cd path/to/the/project/repository
42
+
43
+ $ go-script-template > ./go
44
+
45
+ # Alternately, if you installed go_script using Bundler:
46
+ $ bundle exec go-script-template > ./go
47
+
48
+ # Make the script executable:
49
+ $ chmod 700 ./go
50
+ ```
51
+
52
+ ### Listing commands
53
+
54
+ To see the list of available commands for a script: run `./go help` (or one of
55
+ the common variations thereon, such as `./go -h` or `./go --help`). For
56
+ example, the output of `./go help` for this repository's `./go` script is:
57
+
58
+ ```
59
+ Usage: ./go [option|command] [optional command arguments...]
60
+
61
+ options:
62
+ -h,--help Show this help
63
+ -v,--version Show the version of the go_script gem
64
+
65
+ Development commands
66
+ init Set up the development environment
67
+ update_gems Update Ruby gems
68
+ update_js Update JavaScript components
69
+ test Execute automated tests
70
+ lint Run style-checking tools
71
+ ci_build Execute continuous integration build
72
+ release Test, build, and release a new gem
73
+ ```
74
+
75
+ ### Defining commands
76
+
77
+ The `def_command` directive defines the individual `./go` commands that
78
+ comprise the `./go` script interface. Its arguments are:
79
+
80
+ - *id*: A [Ruby symbol](http://ruby-doc.org/core-2.2.3/Symbol.html)
81
+ (basically, a string starting with `:` with no quotes around it) defining
82
+ the name of the command.
83
+ - *command_group*: A `CommandGroup` instance associated with the command.
84
+ - *description*: A very brief description of the command that appears in the
85
+ usage text.
86
+
87
+ These `def_command` definitions often use the `exec_cmd` directive
88
+ that runs a shell command and exits on error. There are also additional
89
+ directives from [`lib/go_script/go.rb`](lib/go_script/go.rb) that may be used
90
+ to define commands, and commands may be built up from other commands defined
91
+ in the `./go` script itself.
92
+
93
+ #### Command groups
94
+
95
+ A `CommandGroup` instance clusters a set of commands together.
96
+ `go-script-template` generates a default `CommandGroup` instance called
97
+ `dev_commands`; you are free to edit this definition, or to add additional
98
+ `CommandGroup` instances to organize your individual command definitions and
99
+ affect how they are displayed in the help/usage message.
100
+
101
+ #### Command arguments
102
+
103
+ Commands may take command-line arguments, which are passed in as block
104
+ variables. In the following example, the `./go init` command takes no
105
+ arguments, and the `./go test` command takes an argument list that is appended
106
+ as additional command line arguments to `rake test`. For example, `./go test`
107
+ runs `bundle exec rate test` without any further arguments, while running
108
+ `./go test TEST=_test/go_test.rb` ultimately runs `bundle exec rake test
109
+ TEST=_test/go_test.rb`.
110
+
111
+ ```ruby
112
+ dev_commands = GoScript::CommandGroup.add_group 'Development commands'
113
+
114
+ def_command :init, dev_commands, 'Set up the development environment' do
115
+ install_bundle
116
+ end
117
+
118
+ def_command :test, dev_commands, 'Execute automated tests' do |args|
119
+ exec_cmd "bundle exec rake test #{args.join ' '}"
120
+ end
121
+ ```
122
+
123
+ Command blocks may take more than one parameter, corresponding to a specific
124
+ number of additional command line arguments for a specific command.
125
+
126
+ ### Contributing
127
+
128
+ 1. Fork the repo (or just clone it if you're an 18F team member)
129
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
130
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
131
+ 4. Push to the branch (`git push origin my-new-feature`)
132
+ 5. Create a new Pull Request
133
+
134
+ Feel free to ping [@mbland](https://github.com/mbland) with any questions you
135
+ may have, especially if the current documentation should've addressed your
136
+ needs, but didn't.
137
+
138
+ ### Public domain
139
+
140
+ This project is in the worldwide [public domain](LICENSE.md). As stated in
141
+ [CONTRIBUTING](CONTRIBUTING.md):
142
+
143
+ > This project is in the public domain within the United States, and copyright
144
+ > and related rights in the work worldwide are waived through the
145
+ > [CC0 1.0 Universal public domain dedication](https://creativecommons.org/publicdomain/zero/1.0/).
146
+ >
147
+ > All contributions to this project will be released under the CC0 dedication.
148
+ > By submitting a pull request, you are agreeing to comply with this waiver of
149
+ > copyright interest.
@@ -0,0 +1,48 @@
1
+ #! /usr/bin/env ruby
2
+ # Author: Mike Bland <michael.bland@gsa.gov>
3
+
4
+ require_relative '../lib/go_script'
5
+
6
+ puts <<END_OF_TEMPLATE
7
+ #! /usr/bin/env ruby
8
+
9
+ require 'English'
10
+
11
+ begin
12
+ require 'go_script'
13
+ rescue LoadError
14
+ puts 'Installing go_script gem...'
15
+ exit $CHILD_STATUS.exitstatus unless system 'gem install go_script'
16
+ end
17
+
18
+ GoScript::Version.check_ruby_version '#{RUBY_VERSION}'
19
+
20
+ extend GoScript
21
+
22
+ BASEDIR = File.dirname(__FILE__)
23
+ dev_commands = GoScript::CommandGroup.add_group 'Development commands'
24
+
25
+ def_command :init, dev_commands, 'Set up the development environment' do
26
+ install_bundle
27
+ end
28
+
29
+ def_command :update_gems, dev_commands, 'Update Ruby gems' do |gems|
30
+ update_gems gems
31
+ end
32
+
33
+ def_command :update_js, dev_commands, 'Update JavaScript components' do
34
+ update_node_modules
35
+ end
36
+
37
+ def_command :test, dev_commands, 'Execute automated tests' do |args|
38
+ exec_cmd "bundle exec rake test \#{args.join ' '}"
39
+ end
40
+
41
+ def_command :lint, dev_commands, 'Run style-checking tools' do |files|
42
+ files = files.group_by { |f| File.extname f }
43
+ lint_ruby files['.rb']
44
+ lint_javascript BASEDIR, files['.js']
45
+ end
46
+
47
+ execute_command ARGV
48
+ END_OF_TEMPLATE
data/lib/go_script.rb ADDED
@@ -0,0 +1,5 @@
1
+ # @author Mike Bland (michael.bland@gsa.gov)
2
+
3
+ require_relative './go_script/go'
4
+ require_relative './go_script/command_group'
5
+ require_relative './go_script/version'
@@ -0,0 +1,51 @@
1
+ # Author: Mike Bland <michael.bland@gsa.gov>
2
+
3
+ module GoScript
4
+ # Groups a set of commands by common function.
5
+ class CommandGroup
6
+ attr_accessor :description, :commands
7
+ private_class_method :new
8
+
9
+ # @param description [String] short description of the group
10
+ def initialize(description)
11
+ @description = description
12
+ @commands = {}
13
+ end
14
+
15
+ def to_s
16
+ padding = (commands.keys.max_by(&:size) || '').size + 2
17
+ command_descriptions = commands.map do |name, desc|
18
+ format " %-#{padding}s#{desc}", name
19
+ end
20
+ ["\n#{@description}"].concat(command_descriptions).join("\n")
21
+ end
22
+
23
+ class <<self
24
+ attr_reader :groups
25
+ def add_group(description)
26
+ (@groups ||= []).push(new(description)).last
27
+ end
28
+
29
+ def command(command_sym)
30
+ if (groups || []).flat_map { |g| g.commands.keys }.include? command_sym
31
+ return command_sym
32
+ end
33
+ puts "Unknown option or command: #{command_sym}"
34
+ usage exitstatus: 1
35
+ end
36
+
37
+ def usage(exitstatus: 0)
38
+ output_stream = exitstatus == 0 ? $stdout : $stderr
39
+ output_stream.puts <<END_OF_USAGE
40
+ Usage: #{$PROGRAM_NAME} [option|command] [optional command arguments...]
41
+
42
+ options:
43
+ -h,--help Show this help
44
+ -v,--version Show the version of the go_script gem
45
+ END_OF_USAGE
46
+ (groups || []).each { |group| output_stream.puts group }
47
+ exit exitstatus
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,81 @@
1
+ # Author: Mike Bland <michael.bland@gsa.gov>
2
+
3
+ require_relative './command_group'
4
+ require_relative './version'
5
+ require 'English'
6
+
7
+ module GoScript
8
+ def def_command(id, command_group, description, &command_block)
9
+ abort "Command ID must be a symbol: #{id}" unless id.instance_of? Symbol
10
+ self.class.send :define_method, id, ->(argv) { command_block.call argv }
11
+ command_group.commands[id] = description
12
+ end
13
+
14
+ def execute_command(argv)
15
+ command = argv.shift
16
+ CommandGroup.usage exitstatus: 1 if command.nil?
17
+ CommandGroup.usage if ['-h', '--help', '-help', 'help'].include? command
18
+ send version if ['-v', '--version', 'version'].include? command
19
+ send CommandGroup.command(command.to_sym), argv
20
+ end
21
+
22
+ def version
23
+ puts "go_script version #{VERSION}"
24
+ exit 0
25
+ end
26
+
27
+ def exec_cmd(cmd)
28
+ exit $CHILD_STATUS.exitstatus unless system cmd
29
+ end
30
+
31
+ def install_bundle
32
+ begin
33
+ require 'bundler'
34
+ rescue LoadError
35
+ puts 'Installing Bundler gem...'
36
+ exec_cmd 'gem install bundler'
37
+ puts 'Bundler installed; installing gems'
38
+ end
39
+ exec_cmd 'bundle install'
40
+ end
41
+
42
+ def update_gems(gems)
43
+ exec_cmd "bundle update #{gems}"
44
+ exec_cmd 'git add Gemfile.lock'
45
+ end
46
+
47
+ def update_node_modules
48
+ abort 'Install npm to update JavaScript components: ' \
49
+ 'http://nodejs.org/download/' unless system 'which npm > /dev/null'
50
+
51
+ exec_cmd 'npm update'
52
+ exec_cmd 'npm install'
53
+ end
54
+
55
+ JEKYLL_BUILD_CMD = 'bundle exec jekyll build --trace'
56
+ JEKYLL_SERVE_CMD = 'bundle exec jekyll serve -w --trace'
57
+
58
+ def serve_jekyll(extra_args)
59
+ exec "#{JEKYLL_SERVE_CMD} #{extra_args}"
60
+ end
61
+
62
+ def build_jekyll(extra_args)
63
+ exec_cmd "#{JEKYLL_BUILD_CMD} #{extra_args}"
64
+ end
65
+
66
+ def git_sync_and_deploy(commands)
67
+ exec_cmd 'git stash'
68
+ exec_cmd 'git pull'
69
+ commands.each { |command| exec_cmd command }
70
+ end
71
+
72
+ def lint_ruby(files)
73
+ files ||= []
74
+ exec_cmd "bundle exec rubocop #{files.join ' '}"
75
+ end
76
+
77
+ def lint_javascript(basedir, files)
78
+ files ||= []
79
+ exec_cmd "#{basedir}/node_modules/jshint/bin/jshint #{files.join ' '}"
80
+ end
81
+ end
@@ -0,0 +1,22 @@
1
+ # @author Mike Bland (michael.bland@gsa.gov)
2
+
3
+ module GoScript
4
+ VERSION = '0.0.0'
5
+
6
+ class Version
7
+ def self.check_ruby_version(min_version)
8
+ unless RUBY_VERSION >= min_version
9
+ abort <<END_OF_ABORT_MESSAGE
10
+
11
+ *** ABORTING: Unsupported Ruby version ***
12
+
13
+ Ruby version #{min_version} or greater is required, but this Ruby is version
14
+ #{RUBY_VERSION}. Consider using a version manager such as rbenv
15
+ (https://github.com/sstephenson/rbenv) or rvm (https://rvm.io/) to install a
16
+ Ruby version specifically for development.
17
+
18
+ END_OF_ABORT_MESSAGE
19
+ end
20
+ end
21
+ end
22
+ end
metadata ADDED
@@ -0,0 +1,152 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: go_script
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Mike Bland
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-08-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: safe_yaml
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.4'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.4'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: codeclimate-test-reporter
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: coveralls
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Abstracts common functionality used in the `./go` scripts of several
112
+ 18F projects, and provides a `./go` script generator for new projects.
113
+ email:
114
+ - michael.bland@gsa.gov
115
+ executables:
116
+ - go-script-template
117
+ extensions: []
118
+ extra_rdoc_files: []
119
+ files:
120
+ - CONTRIBUTING.md
121
+ - LICENSE.md
122
+ - README.md
123
+ - bin/go-script-template
124
+ - lib/go_script.rb
125
+ - lib/go_script/command_group.rb
126
+ - lib/go_script/go.rb
127
+ - lib/go_script/version.rb
128
+ homepage: https://github.com/18F/go_script
129
+ licenses:
130
+ - CC0
131
+ metadata: {}
132
+ post_install_message:
133
+ rdoc_options: []
134
+ require_paths:
135
+ - lib
136
+ required_ruby_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ required_rubygems_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ requirements: []
147
+ rubyforge_project:
148
+ rubygems_version: 2.4.5.1
149
+ signing_key:
150
+ specification_version: 4
151
+ summary: "./go script: a unified development environment interface"
152
+ test_files: []