kitno 0.1.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: 5bf13d6f203e40637f201524eecab7a7de5750a3
4
+ data.tar.gz: 70ae3923597b1a1b9d4fd80b025fba54e2e4a41c
5
+ SHA512:
6
+ metadata.gz: 45a304b3d95ee87d6bfa1edd24bdd460a5849bba481e6e23978b48805956c2e08618f81256dfba1ce4ebe0f384d29ab5756799a8817a4ae96b9635c54749bb1f
7
+ data.tar.gz: c15dfaa57cf0b1f426dd452787db8306ce5a698618552230afc58c1d3d3b91c97dc8e4601f466b88146ef5228def68ad7c1bb31cf45afa99c7fcdd73cabed0cb
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ *.gem
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.3.1
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,24 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ kitno (0.1.0)
5
+ thor (~> 0.19.1)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ minitest (5.9.0)
11
+ rake (10.5.0)
12
+ thor (0.19.1)
13
+
14
+ PLATFORMS
15
+ ruby
16
+
17
+ DEPENDENCIES
18
+ bundler (~> 1.12)
19
+ kitno!
20
+ minitest (~> 5.0)
21
+ rake (~> 10.0)
22
+
23
+ BUNDLED WITH
24
+ 1.12.5
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Jamie Rolfs
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,41 @@
1
+ # Kitno
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/kitno`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'kitno'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install kitno
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/kitno. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "kitno"
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
data/bin/kitno ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby -U
2
+
3
+ require 'kitno'
4
+
5
+ Kitno::CLI.start(ARGV)
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/kitno.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ #
3
+ lib = File.expand_path('../lib', __FILE__)
4
+
5
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
+
7
+ require 'kitno/version'
8
+
9
+ Gem::Specification.new do |spec|
10
+ spec.name = 'kitno'
11
+ spec.version = Kitno::VERSION
12
+ spec.authors = ['Jamie Rolfs']
13
+ spec.email = ['jamie@mavenlink.com', 'alan@mavenlink.com']
14
+
15
+ spec.summary = 'Convert projects that use JavaScript namespace module structures to CommonJS'
16
+ spec.description = ''
17
+ spec.homepage = 'https://github.com/jrolfs/killing-in-the-namespace-of'
18
+ spec.license = 'MIT'
19
+
20
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ spec.bindir = 'bin'
22
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
23
+ spec.require_paths = ['lib']
24
+
25
+ spec.add_dependency 'thor', '~> 0.19.1'
26
+
27
+ spec.add_development_dependency 'bundler', '~> 1.12'
28
+ spec.add_development_dependency 'rake', '~> 10.0'
29
+ spec.add_development_dependency 'minitest', '~> 5.0'
30
+ end
data/lib/kitno.rb ADDED
@@ -0,0 +1,128 @@
1
+ require 'kitno/version'
2
+ require 'kitno/cli'
3
+
4
+ require 'find'
5
+ require 'fileutils'
6
+
7
+ module Kitno
8
+ class KillingInTheNamespaceOf
9
+ CLASS_EXPRESSION = /^class\s(?:@)?([A-Z][\w\.]*)/
10
+ REQUIRE_TEMPLATE = "%{short_name} = require '%{path}'"
11
+
12
+ def initialize(options = {})
13
+ @namespace, @directory = options.values_at(:namespace, :directory)
14
+
15
+ @class_map = {}
16
+ @files = []
17
+
18
+ @dependency_expression = /^(?!(\s\*|#)).*(?:new|extends)\s(#{Regexp.escape(@namespace)}[\w\.]*)/
19
+ end
20
+
21
+ def run
22
+ enumerate_files
23
+
24
+ @class_map.each_value do |descriptor|
25
+ path = descriptor[:path]
26
+
27
+ require_dependencies!(path, descriptor[:dependencies])
28
+
29
+ FileUtils.mv "#{path}.module", path
30
+ end
31
+ end
32
+
33
+ def enumerate
34
+ enumerate_files
35
+
36
+ puts @class_map.to_s
37
+ end
38
+
39
+ private
40
+
41
+ def enumerate_files
42
+ Find.find(@directory) do |path|
43
+ if FileTest.directory?(path)
44
+ next
45
+ elsif path.match(/\.coffee$/).nil?
46
+ Find.prune
47
+ end
48
+
49
+ @files << path
50
+
51
+ contents = File.open(path, 'rb').read
52
+
53
+ class_name = parse_class_name contents
54
+ dependencies = parse_dependencies contents
55
+
56
+ unless class_name.nil?
57
+ @class_map[path] = {
58
+ path: path,
59
+ class_name: class_name,
60
+ dependencies: dependencies
61
+ }
62
+ end
63
+ end
64
+ end
65
+
66
+ def parse_class_name(contents)
67
+ match = CLASS_EXPRESSION.match(contents)
68
+
69
+ match[1] if match
70
+ end
71
+
72
+ def parse_dependencies(contents)
73
+ contents.scan(@dependency_expression).flatten.compact
74
+ end
75
+
76
+ def get_descriptor(class_name)
77
+ @class_map.select{ |k, v| v[:class_name] == class_name }.values.first
78
+ end
79
+
80
+ def get_directory(path)
81
+ path.split('/')[0...-1].join('/')
82
+ end
83
+
84
+ def get_module_mappings(filename, descriptor)
85
+ path = descriptor[:path]
86
+ class_name = descriptor[:class_name]
87
+ short_name = class_name.split('.').last
88
+
89
+ path_directory = Pathname.new(get_directory(path))
90
+ filename_directory = Pathname.new(get_directory(filename))
91
+
92
+ relative_directory = path_directory.relative_path_from(filename_directory).to_s
93
+ relative_path = "#{relative_directory}/#{path.split('/').pop().split('.').shift}"
94
+
95
+ return relative_path, short_name
96
+ end
97
+
98
+ def require_dependencies!(filename, dependencies)
99
+ File.open("#{filename}.module", 'w') do |file|
100
+ dependencies.each do |dependency|
101
+ relative_path, short_name = get_module_mappings(filename, get_descriptor(dependency))
102
+
103
+ file.puts REQUIRE_TEMPLATE % { short_name: short_name, path: relative_path }
104
+ end
105
+
106
+ file.puts "\n\n"
107
+
108
+ short_class_name = @class_map[filename][:class_name].split('.').last
109
+
110
+ File.foreach(filename) do |line|
111
+ line.gsub!(CLASS_EXPRESSION, "class #{short_class_name}")
112
+
113
+ dependencies.each do |dependency|
114
+ descriptor = get_descriptor(dependency)
115
+ class_name = descriptor[:class_name]
116
+ relative_path, short_name = get_module_mappings(filename, descriptor)
117
+
118
+ line.gsub!(class_name, short_name)
119
+ end
120
+
121
+ file.puts line
122
+ end
123
+
124
+ file.puts "\nmodule.exports = #{short_class_name}\n"
125
+ end
126
+ end
127
+ end
128
+ end
data/lib/kitno/cli.rb ADDED
@@ -0,0 +1,15 @@
1
+ require 'thor'
2
+
3
+ module Kitno
4
+ class CLI < Thor
5
+ desc 'enumerate', 'Enumrate files that will be transformed'
6
+ long_desc <<-ENUMERATE
7
+ ENUMERATE
8
+
9
+ option :namespace, aliases: '-n', type: :string, required: true, desc: 'Base namespace to migrate from'
10
+ option :directory, aliases: '-d', type: :string, default: '.', desc: 'Directory to target for transformation'
11
+ def enumerate
12
+ KillingInTheNamespaceOf.new(options).enumerate
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ module Kitno
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kitno
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jamie Rolfs
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-06-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.19.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.19.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.12'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.12'
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.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.0'
69
+ description: ''
70
+ email:
71
+ - jamie@mavenlink.com
72
+ - alan@mavenlink.com
73
+ executables:
74
+ - console
75
+ - kitno
76
+ - setup
77
+ extensions: []
78
+ extra_rdoc_files: []
79
+ files:
80
+ - ".gitignore"
81
+ - ".ruby-version"
82
+ - Gemfile
83
+ - Gemfile.lock
84
+ - LICENSE.txt
85
+ - README.md
86
+ - Rakefile
87
+ - bin/console
88
+ - bin/kitno
89
+ - bin/setup
90
+ - kitno.gemspec
91
+ - lib/kitno.rb
92
+ - lib/kitno/cli.rb
93
+ - lib/kitno/version.rb
94
+ homepage: https://github.com/jrolfs/killing-in-the-namespace-of
95
+ licenses:
96
+ - MIT
97
+ metadata: {}
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 2.5.1
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: Convert projects that use JavaScript namespace module structures to CommonJS
118
+ test_files: []