flg 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 663c87bc1f95f17f643121e0cbe88de798293a8e
4
- data.tar.gz: '08ed9ca079f0d6e2b00448772a906881e13c8087'
3
+ metadata.gz: eef4be82e88bd546068afc336e09d92eaa08b375
4
+ data.tar.gz: a2799ada8fe16609bc16b34797c175c36525484d
5
5
  SHA512:
6
- metadata.gz: 196a0b77fc362b7b079309e1c22720a12d74130457c8b362f0a09d3ce97eb91fcfd721137faecb9f9e26cee185199ada3b889d119046548caf1ec5db3dbee3de
7
- data.tar.gz: 8533051e075b20fcddc24f80f5b499d11e1b4b121dc565b165c4426882217e6f06d768bc61768fbe9efc22180642fc5ba03b95c74e079260fb1bd2c64ca578bd
6
+ metadata.gz: e0d22edd2c4c63c6e183fc9d3ea9750e8bc5c8053293799e5d039fd1454f968c0906ad06dbc6d547a2dc843ed7921700f5d82b49a8ab8936313bb7248359d232
7
+ data.tar.gz: bf5137399932681b80f6e49308c1c907bd3a07d811c9fe232cb6639e4623da2d0ea7aca6df27645004e182dd3bb85d2ed45a001d12a443cf3326e0e2935fef42
data/README.md CHANGED
@@ -1,14 +1,37 @@
1
1
  # Flg
2
2
 
3
- 一个简单的生成器工具
3
+ 本工具是一个团队效率工具,快速构建非rails项目的脚手架,兼容其他语言。
4
4
 
5
- ## File API
6
- http://ruby-doc.org/stdlib-2.4.1/libdoc/fileutils/rdoc/FileUtils.html
5
+ ## 安装
7
6
 
7
+ 1. 安装 Ruby 版本要求2.0以上
8
+ 2. gem install flg
8
9
 
9
- ## Data handle
10
+ 如果安装很慢的话,请使用国内[ruby源](https://gems.ruby-china.org/)
11
+
12
+ ## 使用
13
+
14
+ 你可以使用 flg start 来新建一个项目,或者 flg start url 来同步已经有的模板库
15
+
16
+ 1. 在你的项目里新建 generators 文件夹
17
+ 2. 在 generators 里面创建 flg 目录
18
+ 3. 上面的 generators 是一个例子
19
+
20
+ ## API 备忘
21
+
22
+ ### commod
23
+
24
+ [link](http://naildrivin5.com/gli/)
25
+
26
+ ### TTY
27
+ [link]()
28
+
29
+ ### File API
30
+
31
+ [link](https://github.com/piotrmurach/tty-file)
32
+
33
+ ### Data handle
10
34
 
11
- support active_support
12
35
 
13
36
  ```ruby
14
37
  'active_record'.camelize # => "ActiveRecord"
@@ -28,33 +51,10 @@ support active_support
28
51
  ```
29
52
 
30
53
  ```ruby
31
- ActiveModel'.underscore # => "active_model"
54
+ 'ActiveModel'.underscore # => "active_model"
32
55
  'ActiveModel::Errors'.underscore # => "active_model/errors"
33
56
  ```
34
57
 
35
- ```ruby
36
- "13-12-2012".to_time # => 2012-12-13 00:00:00 +0100
37
- "06:12".to_time # => 2012-12-13 06:12:00 +0100
38
- "2012-12-13 06:12".to_time # => 2012-12-13 06:12:00 +0100
39
- "2012-12-13T06:12".to_time # => 2012-12-13 06:12:00 +0100
40
- "2012-12-13T06:12".to_time(:utc) # => 2012-12-13 06:12:00 UTC
41
- "12/13/2012".to_time # => ArgumentError: argument out of range
42
- ```
43
-
44
- ```ruby
45
- "1-1-2012".to_datetime # => Sun, 01 Jan 2012 00:00:00 +0000
46
- "01/01/2012 23:59:59".to_datetime # => Sun, 01 Jan 2012 23:59:59 +0000
47
- "2012-12-13 12:50".to_datetime # => Thu, 13 Dec 2012 12:50:00 +0000
48
- "12/13/2012".to_datetime # => ArgumentError: invalid date
49
- ```
50
-
51
- ```ruby
52
- "1-1-2012".to_date # => Sun, 01 Jan 2012
53
- "01/01/2012".to_date # => Sun, 01 Jan 2012
54
- "2012-12-13".to_date # => Thu, 13 Dec 2012
55
- "12/13/2012".to_date # => ArgumentError: invalid date
56
- ```
57
-
58
58
  ```ruby
59
59
  'RawScaledScorer'.tableize # => "raw_scaled_scorers"
60
60
  'ham_and_egg'.tableize # => "ham_and_eggs"
@@ -83,37 +83,3 @@ ActiveModel'.underscore # => "active_model"
83
83
  'ley'.pluralize(:es) # => "leyes"
84
84
  'ley'.pluralize(1, :es) # => "ley"
85
85
  ```
86
-
87
- ```ruby
88
-
89
- ```
90
- ## Installation
91
-
92
- Add this line to your application's Gemfile:
93
-
94
- ```ruby
95
- gem 'flg'
96
- ```
97
-
98
- And then execute:
99
-
100
- $ bundle
101
-
102
- Or install it yourself as:
103
-
104
- $ gem install flg
105
-
106
- ## Usage
107
-
108
- TODO: Write usage instructions here
109
-
110
- ## Development
111
-
112
- 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.
113
-
114
- 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).
115
-
116
- ## Contributing
117
-
118
- Bug reports and pull requests are welcome on GitHub at https://github.com/mj/flg.
119
-
data/bin/flg CHANGED
@@ -8,7 +8,47 @@ include GLI::App
8
8
  include Flg::Shell
9
9
  include Flg::Template
10
10
 
11
- _source = open('./generators/flg').read
12
- eval(_source)
11
+ begin
12
+ _source = open('./generators/flg.rb').read
13
+ eval(_source)
14
+ rescue Errno::ENOENT => e
15
+ nil
16
+ end
17
+
18
+
19
+ demo_str = """
20
+ program_desc '命令行描述'
21
+
22
+ desc '简短说明'
23
+ long_desc '长说明'
24
+ command :add do |c|
25
+ c.action do |global, options, args|
26
+ say 'hello word'
27
+ end
28
+ end
29
+ """
30
+
31
+ desc 'start project'
32
+ long_desc """
33
+ flg start
34
+ flg start git@github.com:oxoooo/demo.git
35
+ """
36
+ command :start do |c|
37
+ c.action do |global, options, args|
38
+ if args.first.blank?
39
+ tree = {
40
+ 'generators' => [
41
+ ['flg', demo_str],
42
+ 'templates' => [],
43
+ 'assets' => []
44
+ ]
45
+ }
46
+ TTY::File.create_dir(tree)
47
+ else
48
+ shell "git clone #{args.first} generators"
49
+ remove_file "./generators/.git"
50
+ end
51
+ end
52
+ end
13
53
 
14
54
  exit run(ARGV)
data/demo.js ADDED
@@ -0,0 +1,13 @@
1
+ import React from 'react';
2
+
3
+ class DemoController extends React.Component {
4
+ constructor(props) {
5
+ super(props);
6
+ }
7
+
8
+ render() {
9
+ return (
10
+ <div></div>
11
+ );
12
+ }
13
+ }
File without changes
@@ -4,7 +4,7 @@ desc '简短说明'
4
4
  long_desc '长说明'
5
5
  command :add do |c|
6
6
  c.action do |global, options, args|
7
- puts args
7
+ say 'active_record'.camelize
8
8
  end
9
9
  end
10
10
 
@@ -16,13 +16,13 @@ end
16
16
 
17
17
  command :mkdir do |c|
18
18
  c.action do |global, options, args|
19
- mkdir_p "./demo"
19
+ copy_file "a.text", "./app.txt"
20
20
  end
21
21
  end
22
22
 
23
23
  command :t do |c|
24
24
  c.action do |global, options, args|
25
- render name: 'demo.js.erb',
25
+ template name: 'demo.js.erb',
26
26
  data: {
27
27
  class_name: args.first.camelize
28
28
  },
data/lib/flg.rb CHANGED
@@ -1,7 +1,8 @@
1
1
  require "flg/version"
2
- require "flg/shell"
3
- require 'flg/template'
2
+
4
3
  require 'active_support/all'
4
+ require 'flg/shell'
5
+ require 'flg/template'
5
6
  require 'tty'
6
7
 
7
8
  module Flg
@@ -1,12 +1,12 @@
1
1
  require 'pathname'
2
2
  require 'fileutils'
3
-
3
+ require 'irb'
4
4
 
5
5
  module Flg
6
6
  module Shell
7
- def shell(str)
7
+ def shell(str, &black)
8
8
  cmd = TTY::Command.new
9
- cmd.run str
9
+ cmd.run str, &black
10
10
  end
11
11
 
12
12
  def file(path)
@@ -14,5 +14,60 @@ module Flg
14
14
  FileUtils.mkdir_p pathname.dirname.to_s
15
15
  File.open(path, 'w+')
16
16
  end
17
+
18
+ def say(str)
19
+ prompt = TTY::Prompt.new
20
+ prompt.say str
21
+ end
22
+
23
+ def ok(str)
24
+ prompt = TTY::Prompt.new
25
+ prompt.ok str
26
+ end
27
+
28
+ def warn(str)
29
+ prompt = TTY::Prompt.new
30
+ prompt.warn str
31
+ end
32
+
33
+ def error(str)
34
+ prompt = TTY::Prompt.new
35
+ prompt.warn str
36
+ end
37
+
38
+ def copy_file(name, path)
39
+ pathname = "./generators/assets/#{name}"
40
+ TTY::File.copy_file pathname, path
41
+ end
42
+
43
+ def copy_dir(name, path)
44
+ pathname = "./generators/assets/#{name}"
45
+ TTY::File.copy_directory pathname, path
46
+ end
47
+
48
+ def create_file(path, str)
49
+ TTY::File.create_file path, str
50
+ end
51
+
52
+ def create_dir(path)
53
+ TTY::File.create_dir path
54
+ end
55
+
56
+ def download_file(url, path)
57
+ TTY::File.download_file url, path
58
+ end
59
+
60
+ def append_to_file(name, str)
61
+ TTY::File.append_to_file name, str
62
+ end
63
+
64
+ def prepend_to_file(name, str)
65
+ TTY::File.prepend_to_file name, str
66
+ end
67
+
68
+ def remove_file(path)
69
+ TTY::File.remove_file path
70
+ end
71
+
17
72
  end
18
73
  end
@@ -5,39 +5,12 @@ require 'pathname'
5
5
 
6
6
  module Flg
7
7
  module Template
8
- class ErbalT < OpenStruct
9
- def self.render_from_hash(t, h)
10
- ErbalT.new(h).render(t)
11
- end
12
-
13
- def render(template)
14
- ERB.new(template).result(binding)
15
- end
16
- end
17
-
18
- def render(name: nil, data: nil, path: nil)
19
- template = File.read("./generators/templates/#{name}")
20
- str = ErbalT::render_from_hash(template, data)
21
- if File.exist?(path)
22
- prompt = TTY::Prompt.new
23
- if prompt.no?("#{path} replace?")
24
- puts 'ignore: ' + path
25
- save_file(path, str)
26
- else
27
- return
28
- end
29
- else
30
- save_file(path, str)
31
- puts 'created: ' + path
32
- end
33
- end
34
-
35
- def save_file(path, str)
36
- pathname = Pathname.new path
37
- FileUtils.mkdir_p pathname.dirname.to_s
38
- File.open(path, 'w+') do |f|
39
- f.puts str
40
- end
8
+ def template(name: nil, data: nil, path: nil)
9
+ TTY::File.copy_file(
10
+ "./generators/templates/#{name}",
11
+ path,
12
+ context: OpenStruct.new(data)
13
+ )
41
14
  end
42
15
  end
43
16
  end
@@ -1,3 +1,3 @@
1
1
  module Flg
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - mj
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-18 00:00:00.000000000 Z
11
+ date: 2017-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -95,8 +95,10 @@ files:
95
95
  - bin/console
96
96
  - bin/flg
97
97
  - bin/setup
98
+ - demo.js
98
99
  - flg.gemspec
99
- - generators/flg
100
+ - generators/assets/a.text
101
+ - generators/flg.rb
100
102
  - generators/templates/demo.js.erb
101
103
  - lib/flg.rb
102
104
  - lib/flg/shell.rb