sbs 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
+ SHA256:
3
+ metadata.gz: dc6b624b555bb310e09ba012cfda9b69c670eb88c6fa0d9e2e0878795e9492aa
4
+ data.tar.gz: 37d1af43a758bf6c692e5ffa84413e7fed0bf068842e4b71343ba1e986946c2d
5
+ SHA512:
6
+ metadata.gz: 67bee44426b6038d1f9fdf3dde87fe7c0b02bcba4877213c967ae01569bbfb2c9575062ab07ba9cef9d794f9fc1cb2e2834e46b4be4fcc045730be09d94d0b68
7
+ data.tar.gz: b1e6d601ee2cfa9e3121f4246cc64fdff9893b03386474759a31aea097c8e70d9b76ea7a918ff811a683012307042f2399dd70871fdb1ab605f57c4544dfff9e
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in sbs.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,35 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ sbs (0.1.0)
5
+ activesupport (~> 5.2.3)
6
+ thor (~> 0.20.3)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activesupport (5.2.3)
12
+ concurrent-ruby (~> 1.0, >= 1.0.2)
13
+ i18n (>= 0.7, < 2)
14
+ minitest (~> 5.1)
15
+ tzinfo (~> 1.1)
16
+ concurrent-ruby (1.1.5)
17
+ i18n (1.6.0)
18
+ concurrent-ruby (~> 1.0)
19
+ minitest (5.11.3)
20
+ rake (10.5.0)
21
+ thor (0.20.3)
22
+ thread_safe (0.3.6)
23
+ tzinfo (1.2.5)
24
+ thread_safe (~> 0.1)
25
+
26
+ PLATFORMS
27
+ ruby
28
+
29
+ DEPENDENCIES
30
+ bundler (~> 2.0)
31
+ rake (~> 10.0)
32
+ sbs!
33
+
34
+ BUNDLED WITH
35
+ 2.0.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Wu Minzhe
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,51 @@
1
+ # sbs
2
+
3
+ A better cli tool for substrate development.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'sbs'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install sbs
20
+
21
+ ## Usage
22
+
23
+ ```shell
24
+ # default branch is master
25
+ sbs new testchain
26
+
27
+ sbs new testchain -b v1.0
28
+
29
+ sbs new testchain -b v1.0 -a author_name
30
+
31
+ # Check the substrate version used by your project. Do it in your project directory.
32
+ sbs check
33
+
34
+ # details in helper
35
+ sbs -h
36
+
37
+ ```
38
+
39
+ ## Development
40
+
41
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
42
+
43
+ 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).
44
+
45
+ ## Contributing
46
+
47
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/subs.
48
+
49
+ ## License
50
+
51
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
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 "sbs"
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/exe/sbs ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "sbs"
@@ -0,0 +1,3 @@
1
+ module Sbs
2
+ VERSION = "0.1.0"
3
+ end
data/lib/sbs.rb ADDED
@@ -0,0 +1,157 @@
1
+ require "subs/version"
2
+ require "thor"
3
+ require "fileutils"
4
+ require "find"
5
+ require "active_support/core_ext/string"
6
+
7
+ module Sbs
8
+ class Error < StandardError; end
9
+
10
+ class Cli < Thor
11
+ desc "new CHAIN_NAME", "Create a new blockchain from substrate node template by branch."
12
+ option :author, :aliases => :a, :default => "Wu Minzhe"
13
+ option :branch, :aliases => :b, :default => "master"
14
+ def new(chain_name)
15
+
16
+ home = File.join(Dir.home, ".subs")
17
+ Dir.mkdir(home) if not Dir.exist?(home)
18
+ substrate_dir = File.join(home, "substrate")
19
+
20
+ puts "1. Preparing substrate..."
21
+ if not Dir.exist?(substrate_dir)
22
+ `git clone https://github.com/paritytech/substrate #{substrate_dir}`
23
+ end
24
+
25
+ # checkout branch
26
+ Dir.chdir substrate_dir do
27
+ `git checkout #{options[:branch]}`
28
+
29
+ if `git show-ref refs/heads/#{options[:branch]}`.strip == ""
30
+ puts "Branch #{options[:branch]} not exist!"
31
+ return
32
+ end
33
+
34
+ `git pull`
35
+ end
36
+
37
+ puts "2. Copying node-template..."
38
+ if not Dir.exist?("./#{chain_name}")
39
+ `cp -R #{substrate_dir}/node-template ./#{chain_name}`
40
+ end
41
+
42
+ Dir.chdir("./#{chain_name}") do
43
+ puts "3. Customizing..."
44
+ Find.find(".") do |path|
45
+ if not File.directory? path
46
+ content = `sed "s/Substrate Node Template/#{chain_name.titleize} Node/g" "#{path}"`
47
+ File.open(path, "w") do |f| f.write(content) end
48
+
49
+ content = `sed "s/Substrate Node/#{chain_name.titleize} Node/g" "#{path}"`
50
+ File.open(path, "w") do |f| f.write(content) end
51
+
52
+ content = `sed "s/Substrate node/#{chain_name.titleize} node/g" "#{path}"`
53
+ File.open(path, "w") do |f| f.write(content) end
54
+
55
+ content = `sed "s/node_template/#{chain_name.titleize.gsub(" ", "").underscore}/g" "#{path}"`
56
+ File.open(path, "w") do |f| f.write(content) end
57
+
58
+ content = `sed "s/node-template/#{chain_name.titleize.downcase.gsub(" ", "-")}/g" "#{path}"`
59
+ File.open(path, "w") do |f| f.write(content) end
60
+
61
+ if path.end_with?("toml")
62
+ content = `sed "s/Anonymous/#{options[:author]}/g" "#{path}"`
63
+ File.open(path, "w") do |f| f.write(content) end
64
+
65
+ sed = "sed \"s/path = \\\"\\\.\\\.\\\/.*\\\"/git = 'https:\\\/\\\/github.com\\\/paritytech\\\/substrate.git', branch='#{options[:branch]}'/g\" #{path}"
66
+ content = `#{sed}`
67
+ File.open(path, "w") do |f| f.write(content) end
68
+ end
69
+ end
70
+ end
71
+
72
+ puts "4. Initializing repository..."
73
+ `git init 2>/dev/null >/dev/null`
74
+ `touch .gitignore`
75
+ File.open(".gitignore", "w") do |f|
76
+ gitignore = %q(# Generated by Cargo
77
+ # will have compiled files and executables
78
+ **/target/
79
+ # These are backup files generated by rustfmt
80
+ **/*.rs.bk)
81
+ f.write(gitignore)
82
+ end
83
+
84
+ puts "5. Initializing WebAssembly build environment..."
85
+ `./scripts/init.sh`
86
+
87
+ puts "6. Building..."
88
+ if File.exist?("./scripts/build.sh")
89
+ `./scripts/build.sh`
90
+ end
91
+ `cargo build`
92
+ end
93
+
94
+ puts ""
95
+ puts "blockchain #{chain_name} created by #{options[:author]}"
96
+ puts ""
97
+ end
98
+
99
+ desc "check", "Check the substrate version used by your project. Do it in your project directory."
100
+ def check
101
+ puts get_versions
102
+ end
103
+
104
+ desc "diff", "Show the difference between your substrate version and branch head. Do it in your project directory."
105
+ def diff
106
+ versions = get_versions
107
+ if versions.length > 1
108
+ puts "Your project seems to depend on more than one substrate version"
109
+ return
110
+ end
111
+
112
+ # get branch and commit
113
+ version = versions[0]
114
+ scan_branch = version.scan(/branch=(.+),/)[0]
115
+ branch = scan_branch.nil? ? "master" : scan_branch[0]
116
+ commit = version.scan(/commit=(.+)/)[0][0]
117
+
118
+
119
+ end
120
+
121
+ private
122
+ def get_versions
123
+ if not File.exist?("./Cargo.lock")
124
+ puts "There is no Cargo.lock in current directory!"
125
+ return
126
+ end
127
+
128
+ content = File.open("./Cargo.lock").read
129
+ result = content.scan(/substrate\.git(.*#.+)"$/).uniq
130
+
131
+ versions = []
132
+ result.each do |item|
133
+ splits = item[0].split("#")
134
+ if splits[0].start_with?("?")
135
+ versions << "#{splits[0][1 ..]}, commit=#{splits[1].strip}"
136
+ else
137
+ commit = splits[1].strip
138
+ versions << "commit=#{commit}"
139
+ end
140
+ end
141
+
142
+ versions = versions.uniq
143
+ versions.select do |version|
144
+ included = false
145
+ versions.each do |v|
146
+ if v != version && v.include?(version)
147
+ included = true
148
+ end
149
+ end
150
+ not included
151
+ end
152
+ end
153
+
154
+ end
155
+ end
156
+
157
+ Sbs::Cli.start(ARGV)
data/sbs.gemspec ADDED
@@ -0,0 +1,35 @@
1
+ lib = File.expand_path("lib", __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "sbs/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "sbs"
7
+ spec.version = Sbs::VERSION
8
+ spec.authors = ["Wu Minzhe"]
9
+ spec.email = ["wuminzhe@gmail.com"]
10
+
11
+ spec.summary = %q{A better cli tool for substrate development}
12
+ spec.description = %q{A better cli tool for substrate development}
13
+ spec.homepage = "https://github.com/wuminzhe/sbs"
14
+ spec.license = "MIT"
15
+
16
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
17
+
18
+ spec.metadata["homepage_uri"] = spec.homepage
19
+ spec.metadata["source_code_uri"] = "https://github.com/wuminzhe/sbs"
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ end
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "bundler", "~> 2.0"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+
33
+ spec.add_dependency "thor", "~> 0.20.3"
34
+ spec.add_dependency "activesupport", "~> 5.2.3"
35
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sbs
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Wu Minzhe
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-09-05 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: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: thor
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.20.3
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.20.3
55
+ - !ruby/object:Gem::Dependency
56
+ name: activesupport
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 5.2.3
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 5.2.3
69
+ description: A better cli tool for substrate development
70
+ email:
71
+ - wuminzhe@gmail.com
72
+ executables:
73
+ - sbs
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - Gemfile
79
+ - Gemfile.lock
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - bin/console
84
+ - bin/setup
85
+ - exe/sbs
86
+ - lib/sbs.rb
87
+ - lib/sbs/version.rb
88
+ - sbs.gemspec
89
+ homepage: https://github.com/wuminzhe/sbs
90
+ licenses:
91
+ - MIT
92
+ metadata:
93
+ allowed_push_host: https://rubygems.org
94
+ homepage_uri: https://github.com/wuminzhe/sbs
95
+ source_code_uri: https://github.com/wuminzhe/sbs
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubygems_version: 3.0.6
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: A better cli tool for substrate development
115
+ test_files: []