brew-npm 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 2850b9951a49300b614825dacfff9a5424dc3295cc8473d3adb8bf64f1eddaa1
4
+ data.tar.gz: 1d9df669bce66f4dedef83a89abba92b35eb38eaddaa6e1099d5d2668853ecab
5
+ SHA512:
6
+ metadata.gz: 4460702bdf8dadde0e8ebce7a9c7e43486127fc26f84aca76c3c6d5637e2fa792d8b3113d6d74830976be452e8ccb03ef0d766782f395416fb2c5a90f755a951
7
+ data.tar.gz: b8939506a5ba8efb0e091dade6bcaf30aa98e96d51c8ec2cdee58d0d0bf0ed564a8f087f5683c941f7d675ed53d6db7bb1728332f8ba2508fc9940a1bcc40d7a
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ /Gemfile.lock
11
+ /vendor/bundle
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at shuuuuuny+github@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in brew-npm.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 motoki-shun
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,69 @@
1
+ # brew-npm
2
+
3
+ `brew npm` allows you to install any npm packages as a homebrew formula.
4
+
5
+ This project was forked from [sportngin/brew-gem](https://github.com/sportngin/brew-gem) and modified for npm.
6
+
7
+
8
+ ## Installation
9
+
10
+ <!-- Via Rubygems:
11
+
12
+ gem install brew-npm
13
+ brew-npm install brew-npm -->
14
+
15
+ Via Homebrew:
16
+
17
+ brew install shuuuuun/tap/brew-npm
18
+
19
+
20
+ ## Usage
21
+
22
+ brew npm install ${NPM_PACKAGE_NAME}
23
+
24
+ To install a specific version:
25
+
26
+ brew npm install ${NPM_PACKAGE_NAME} ${VERSION}
27
+
28
+ To upgrade:
29
+
30
+ brew npm upgrade ${NPM_PACKAGE_NAME}
31
+
32
+ To uninstall:
33
+
34
+ brew npm uninstall ${NPM_PACKAGE_NAME}
35
+
36
+ To check information:
37
+
38
+ brew npm info ${NPM_PACKAGE_NAME}
39
+
40
+ Note:
41
+
42
+ Installed packages are listed in `brew list` with prefix of `npm-`.
43
+
44
+
45
+ ## Philosophy
46
+
47
+ This is not for installing development libraries, but for standalone binary tools that you want system wide.
48
+
49
+
50
+ ## Contributing
51
+
52
+ Bug reports and pull requests are welcome on GitHub at https://github.com/shuuuuun/brew-npm. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/shuuuuun/brew-npm/blob/master/CODE_OF_CONDUCT.md).
53
+
54
+
55
+ ## Development
56
+
57
+ - `bin/setup` to install dependencies.
58
+ - `bin/console` for an interactive prompt that will allow you to experiment.
59
+ - `exe/brew-npm` to exec CLI locally.
60
+
61
+
62
+ ## License
63
+
64
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
65
+
66
+
67
+ ## Code of Conduct
68
+
69
+ Everyone interacting in the Brew::Npm project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/shuuuuun/brew-npm/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "brew/npm"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/brew-npm.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ require_relative 'lib/brew/npm/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "brew-npm"
5
+ spec.version = Brew::Npm::VERSION
6
+ spec.authors = ["motoki-shun"]
7
+ spec.email = ["shuuuuuny+github@gmail.com"]
8
+
9
+ spec.summary = %q{Generate Homebrew formulas to install standalone npms.}
10
+ spec.description = %q{This gem can be installed with "brew install brew-npm" and used to install gems with "brew npm install <npm>".}
11
+ spec.homepage = "https://github.com/shuuuuun/brew-npm"
12
+ spec.license = "MIT"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
+
15
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = "https://github.com/shuuuuun/brew-npm"
18
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ end
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+ end
data/exe/brew-npm ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ BREW_NPM_HOME = File.expand_path("../..", __FILE__)
4
+ $LOAD_PATH.unshift(File.join(BREW_NPM_HOME, "lib"))
5
+
6
+ require "brew/npm"
7
+
8
+ Brew::Npm::CLI.run(ARGV)
@@ -0,0 +1,131 @@
1
+ require "json"
2
+ require "erb"
3
+ require "tempfile"
4
+ require "shellwords"
5
+
6
+ module Brew::Npm::CLI
7
+ module_function
8
+
9
+ COMMANDS = {
10
+ "install" => ("Install a brew npm, accepts an optional version argument\n" +
11
+ " (e.g. brew npm install <name> [version])"),
12
+ "upgrade" => "Upgrade to the latest version of a brew npm",
13
+ "uninstall" => "Uninstall a brew npm",
14
+ "reinstall" => "Reinstall a brew npm",
15
+ "info" => "Show information for an installed npm",
16
+ "formula" => "Print out the generated formula for a npm",
17
+ "version" => "Show version of brew-npm",
18
+ "help" => "This message"
19
+ }
20
+
21
+ class Arguments
22
+ def initialize(args)
23
+ @args = args
24
+ @args_without_flags = @args.reject {|a| a.start_with?("-") }
25
+ end
26
+
27
+ def command
28
+ @args_without_flags[0]
29
+ end
30
+
31
+ def npm
32
+ @args_without_flags[1]
33
+ end
34
+
35
+ def supplied_version
36
+ @args_without_flags[2]
37
+ end
38
+
39
+ def to_args
40
+ @args.reject {|a| a == npm || a == supplied_version }
41
+ end
42
+ end
43
+
44
+ def help_msg
45
+ (["Please specify a npm package name (e.g. brew npm command <name>)"] +
46
+ COMMANDS.map {|name, desc| " #{name} - #{desc}"}).join("\n")
47
+ end
48
+
49
+ def fetch_version(name, version = nil)
50
+ npm_info = parse_json `npm info --json "#{name}"`
51
+ abort "Could not find a valid npm '#{name}'" if npm_info.nil?
52
+ version ||= npm_info["version"]
53
+ version
54
+ end
55
+
56
+ def parse_json(str)
57
+ JSON.parse(str)
58
+ rescue JSON::ParserError => err
59
+ STDERR.puts err
60
+ nil
61
+ end
62
+
63
+ def process_args(args)
64
+ arguments = Arguments.new(args)
65
+ command = arguments.command
66
+ abort help_msg unless command
67
+ abort "unknown command: #{command}\n#{help_msg}" unless COMMANDS.keys.include?(command)
68
+
69
+ if command == 'help'
70
+ STDERR.puts help_msg
71
+ exit 0
72
+ end
73
+
74
+ if command == 'version'
75
+ STDERR.puts Brew::Npm::VERSION
76
+ exit 0
77
+ end
78
+
79
+ arguments
80
+ end
81
+
82
+ def homebrew_prefix
83
+ ENV["HOMEBREW_PREFIX"] || `brew --prefix`.chomp
84
+ end
85
+
86
+ def expand_formula(name, version)
87
+ klass = "Npm" + name.capitalize.gsub(/[-_.\s@\/]([a-zA-Z0-9])/) { $1.upcase }.gsub('+', 'x')
88
+ sanitized_name = sanitize_name(name)
89
+ user_npmrc = "#{ENV['HOME']}/.npmrc"
90
+ template_file = File.expand_path("../formula.rb.erb", __FILE__)
91
+ template = ERB.new(File.read(template_file))
92
+ template.result(binding) # TODO: avoid binding. specify variables.
93
+ end
94
+
95
+ def with_temp_formula(name, version)
96
+ sanitized_name = sanitize_name(name)
97
+ filename = File.join Dir.tmpdir, "npm-#{sanitized_name}.rb"
98
+
99
+ open(filename, "w") do |f|
100
+ f.puts expand_formula(name, version)
101
+ end
102
+
103
+ yield filename
104
+ ensure
105
+ File.unlink filename
106
+ end
107
+
108
+ def run(args = ARGV)
109
+ arguments = process_args(args)
110
+ name = arguments.npm
111
+ if name.nil?
112
+ STDERR.puts 'Package name is missing!'
113
+ STDERR.puts help_msg
114
+ exit 0
115
+ end
116
+ version = fetch_version(name, arguments.supplied_version)
117
+ with_temp_formula(name, version) do |filename|
118
+ case arguments.command
119
+ when "formula"
120
+ $stdout.puts File.read(filename)
121
+ else
122
+ system "brew #{arguments.to_args.shelljoin} --formula #{filename}"
123
+ exit $?.exitstatus unless $?.success?
124
+ end
125
+ end
126
+ end
127
+
128
+ def sanitize_name(name)
129
+ name.gsub(%r{\A@}, '').gsub('/', '-') # for Scoped packages. https://docs.npmjs.com/cli/v8/using-npm/scope
130
+ end
131
+ end
@@ -0,0 +1,77 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'formula'
4
+ require 'fileutils'
5
+ require 'json'
6
+
7
+ module NodeBin
8
+ def npm_bin
9
+ HOMEBREW_PREFIX/"bin/npm"
10
+ end
11
+ end
12
+
13
+ class NPMDownloadStrategy < AbstractDownloadStrategy
14
+ include NodeBin
15
+
16
+ def fetch
17
+ ohai "Fetching <%= name %> from npm source"
18
+ cache.cd do
19
+ ENV['NPM_CONFIG_CACHE'] = "#{cache}/npm_cache"
20
+ system "#{npm_bin}", "pack", "<%= name %>@#{npm_version}"
21
+ end
22
+ end
23
+
24
+ def cached_location
25
+ Pathname.new("#{cache}/<%= sanitized_name %>-#{npm_version}.tgz")
26
+ end
27
+
28
+ def cache
29
+ @cache ||= HOMEBREW_CACHE
30
+ end
31
+
32
+ def npm_version
33
+ return @version if defined?(@version) && @version
34
+ @version = @resource.version if defined?(@resource)
35
+ raise "Unable to determine version; did Homebrew change?" unless @version
36
+ @version
37
+ end
38
+
39
+ def clear_cache
40
+ cached_location.unlink if cached_location.exist?
41
+ end
42
+ end
43
+
44
+ class <%= klass %> < Formula
45
+ include NodeBin
46
+
47
+ url "<%= name %>", :using => NPMDownloadStrategy
48
+ version "<%= version %>"
49
+ depends_on "node"
50
+
51
+ def install
52
+ # Use /usr/local/bin at the front of the path instead of Homebrew shims,
53
+ # which mess with Ruby's own compiler config when building native extensions
54
+ if defined?(HOMEBREW_SHIMS_PATH)
55
+ ENV['PATH'] = ENV['PATH'].sub(HOMEBREW_SHIMS_PATH.to_s, '/usr/local/bin')
56
+ end
57
+
58
+ FileUtils.cd(prefix)
59
+
60
+ system "#{npm_bin}", "install", cached_download
61
+ raise "npm install '<%= name %>' failed with status #{$?.exitstatus}" unless $?.success?
62
+
63
+ bin.rmtree if bin.exist?
64
+ bin.mkpath
65
+
66
+ package_path = "#{prefix}/node_modules/<%= name %>"
67
+ package_json = JSON.parse(File.read(File.join(package_path, 'package.json'))) rescue nil
68
+ if package_json && package_json['bin']
69
+ bin_paths = package_json['bin'].is_a?(Hash) ? package_json['bin'] : { package_json['name'] => package_json['bin'] }
70
+ bin_paths.each do |name, relative_path|
71
+ FileUtils.symlink(File.join(package_path, relative_path), File.join(bin, name))
72
+ end
73
+ else
74
+ FileUtils.symlink(Dir.glob("#{package_path}/bin/*"), bin)
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,5 @@
1
+ module Brew
2
+ module Npm
3
+ VERSION = "0.3.0"
4
+ end
5
+ end
data/lib/brew/npm.rb ADDED
@@ -0,0 +1,9 @@
1
+ require "brew/npm/version"
2
+ require "brew/npm/cli"
3
+
4
+ module Brew
5
+ module Npm
6
+ class Error < StandardError; end
7
+ # Your code goes here...
8
+ end
9
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: brew-npm
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ platform: ruby
6
+ authors:
7
+ - motoki-shun
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-01-22 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: This gem can be installed with "brew install brew-npm" and used to install
14
+ gems with "brew npm install <npm>".
15
+ email:
16
+ - shuuuuuny+github@gmail.com
17
+ executables:
18
+ - brew-npm
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - ".gitignore"
23
+ - CODE_OF_CONDUCT.md
24
+ - Gemfile
25
+ - LICENSE.txt
26
+ - README.md
27
+ - Rakefile
28
+ - bin/console
29
+ - bin/setup
30
+ - brew-npm.gemspec
31
+ - exe/brew-npm
32
+ - lib/brew/npm.rb
33
+ - lib/brew/npm/cli.rb
34
+ - lib/brew/npm/formula.rb.erb
35
+ - lib/brew/npm/version.rb
36
+ homepage: https://github.com/shuuuuun/brew-npm
37
+ licenses:
38
+ - MIT
39
+ metadata:
40
+ allowed_push_host: https://rubygems.org
41
+ homepage_uri: https://github.com/shuuuuun/brew-npm
42
+ source_code_uri: https://github.com/shuuuuun/brew-npm
43
+ post_install_message:
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: 2.3.0
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ requirements: []
58
+ rubygems_version: 3.3.3
59
+ signing_key:
60
+ specification_version: 4
61
+ summary: Generate Homebrew formulas to install standalone npms.
62
+ test_files: []