kaizen-cli 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. data/bin/kzn +59 -18
  3. data/build.sh +4 -0
  4. data/kaizen-cli.gemspec +2 -1
  5. data/lib/kaizen.rb +148 -25
  6. metadata +22 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 75fc353e0af6d9f6664095d5437dacf913c1611a
4
- data.tar.gz: f35dc5160d59b12506e14f0b21f69fe33de6e986
3
+ metadata.gz: 7bfce8103422dd725fcb537887a2acb86e947b9c
4
+ data.tar.gz: 72f9dbc794beb8b9552a75277fa83ff0dbd7ed04
5
5
  SHA512:
6
- metadata.gz: a1acd01f0030a77aadc64ec4ee76a7c5657668bff6a792fb678eedca27eb7baf17e7b21217243d735cf26519812b51e6e4b6000699ce5bdb56a556019d02b61d
7
- data.tar.gz: 0bb10c53a20bbc382ce04efb7f19a8b9fa988e97d4eb0af36b2b64e41f02e3cbe93b432b5b9b59a699b2994e21753dec3d7c1ac32c644e294f62472a55adad43
6
+ metadata.gz: 402a1b355383b84c8cb49dc9113997541149872a1e82a6c54a77e666a2dc7b928f0da7177a7380d99572b66484013a98dd52645e0604822ef06e73ef7b6fa40e
7
+ data.tar.gz: 181d33bb797feba23c9e6c7ecd72b19c5ec6859b90ff04c277787480847aafa40767bd3be50a175f7eab64bbac9bdd5e1d1555118f6c54dc57798fbfaa50eb6a
data/bin/kzn CHANGED
@@ -1,21 +1,39 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ require 'rubygems'
3
4
  require 'optparse'
4
- require 'kaizen'
5
5
  require 'date'
6
+ require 'thread'
7
+ require File.expand_path('../lib/kaizen', File.dirname(__FILE__))
8
+
9
+ def render_banner!
10
+ Kaizen::CLI.pout(:default, '> kzn [optional path] [options]')
11
+ Kaizen::CLI.pout(:default, '> kzn --help')
12
+ end
13
+
14
+ threads = []
6
15
 
7
16
  begin
8
17
  options = {
9
- watch: false,
10
18
  overwrite: false,
11
- verbose: false
19
+ verbose: false,
20
+ serve: false,
21
+ mode: nil
12
22
  }
13
23
 
14
24
  OptionParser.new do |opts|
15
25
  opts.banner = 'Usage: kzn [optional path] [options]'
16
26
 
17
- opts.on('-s', '--start', 'Start the pre-processors for the static assets') do |v|
18
- options[:watch] = v
27
+ opts.on('-w', '--watch', 'Watch the specified directory for Sass changes and compile them automatically') do |v|
28
+ options[:mode] = :watch
29
+ end
30
+
31
+ opts.on('-n', '--new', 'Create a new Kaizen project in the specified directory') do |v|
32
+ options[:mode] = :new
33
+ end
34
+
35
+ opts.on('-s', '--serve', 'Start serving the specified directory from the built-in web server') do |v|
36
+ options[:serve] = v
19
37
  end
20
38
 
21
39
  opts.on('-f', '--force', 'Overwrite files that already exist in the target directory') do |v|
@@ -34,27 +52,50 @@ begin
34
52
  Kaizen::CLI.pout(:default, "============================================")
35
53
  Kaizen::CLI.pout(:default, "+ #{Paint[kanji, :cyan]} Kaizen Framework ")
36
54
  Kaizen::CLI.pout(:default, "+ Copyright © #{year} Wixel Software Solutions ")
37
- Kaizen::CLI.pout(:default, "+ https://github.com/Wixel/Kaizen ")
55
+ Kaizen::CLI.pout(:default, "+ http://wixel.github.io/Kaizen/ ")
38
56
  Kaizen::CLI.pout(:default, "============================================")
39
57
 
40
- if options[:watch]
41
- path = Dir.pwd
58
+ path = Dir.pwd
59
+
60
+ if !ARGV.empty?
61
+ path = ARGV[0]
62
+ end
42
63
 
43
- if !ARGV.empty?
44
- path = ARGV[0]
64
+ serving = false
65
+
66
+ case options[:mode]
67
+ when :new
68
+ Kaizen::CLI.new(ARGV[0], options[:overwrite], options[:verbose])
69
+ when :watch
70
+ if options[:serve]
71
+ serving = true
72
+
73
+ threads << Thread.new do
74
+ Kaizen::CLI.serve(path)
75
+ end
45
76
  end
46
77
 
47
78
  Kaizen::CLI.watch(path)
79
+ else
80
+ if !options[:serve]
81
+ render_banner!
82
+ end
83
+ end
84
+
85
+ if options[:serve] && !serving
86
+ serving = true
87
+ Kaizen::CLI.serve(path)
48
88
  end
49
89
 
50
- if !options[:watch]
51
- if ARGV.empty?
52
- Kaizen::CLI.pout(:default, '> kzn [optional path] [options]')
53
- Kaizen::CLI.pout(:default, '> kzn --help')
54
- else
55
- Kaizen::CLI.new(ARGV[0], options[:overwrite], options[:verbose])
90
+ rescue SignalException, Exception => e
91
+
92
+ if threads.size > 0
93
+ Kaizen::CLI.pout(:info, "Cleaning up worker threads")
94
+
95
+ threads.each do |t|
96
+ Thread.kill(t)
56
97
  end
57
98
  end
58
- rescue SignalException => e
59
- Kaizen::CLI.pout(:debug, "お疲れ様でした (おつかれさまでした, otsukaresama deshita!")
99
+
100
+ Kaizen::CLI.pout(:debug, "otsukaresama deshita! (Good Bye)")
60
101
  end
data/build.sh ADDED
@@ -0,0 +1,4 @@
1
+ #!/bin/sh
2
+
3
+ echo "+ Building Gemspec"
4
+ rake build --trace
data/kaizen-cli.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'kaizen-cli'
3
- s.version = '0.1.0'
3
+ s.version = '0.1.1'
4
4
  s.date = '2016-06-06'
5
5
  s.summary = 'Kaizen CLI is the command line tool for the Kaizen framework'
6
6
  s.description = 'Kaizen is a simple-as-possible responsive Sass framework.'
@@ -12,6 +12,7 @@ Gem::Specification.new do |s|
12
12
  s.executables << 'kzn'
13
13
  s.require_paths = ['lib']
14
14
 
15
+ s.add_runtime_dependency 'rack', '~> 1.6', '>= 1.6.4'
15
16
  s.add_runtime_dependency 'minitest', '~> 5.7', '>= 5.7.0'
16
17
  s.add_runtime_dependency 'rake', '~> 10.4', '>= 10.4.2'
17
18
  s.add_runtime_dependency 'bundler', '~> 1.7'
data/lib/kaizen.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'rubygems'
1
2
  require 'yaml'
2
3
  require 'tmpdir'
3
4
  require 'net/http'
@@ -6,7 +7,7 @@ require 'tempfile'
6
7
  require 'zip'
7
8
  require 'paint'
8
9
  require 'bourbon'
9
- require 'thread'
10
+ require 'rack'
10
11
 
11
12
  module Kaizen
12
13
  class CLI
@@ -158,17 +159,17 @@ module Kaizen
158
159
  # Output helper
159
160
  #
160
161
  def self.pout(optn, msg)
161
- format = '%d/%m/%Y %H:%M'
162
+ date_format = '%d/%m/%Y %H:%M'
162
163
 
163
164
  case optn
164
165
  when :error
165
- puts "#{Time.now.strftime(format)} #{Paint[msg, :red]}"
166
+ puts "#{Time.now.strftime(date_format)} #{Paint[msg, :red]}"
166
167
  when :info
167
- puts "#{Time.now.strftime(format)} #{Paint[msg, :green]}"
168
+ puts "#{Time.now.strftime(date_format)} #{Paint[msg, :green]}"
168
169
  when :warn
169
- puts "#{Time.now.strftime(format)} #{Paint[msg, :yellow]}"
170
+ puts "#{Time.now.strftime(date_format)} #{Paint[msg, :yellow]}"
170
171
  when :debug
171
- puts "#{Time.now.strftime(format)} #{Paint[msg, :cyan]}"
172
+ puts "#{Time.now.strftime(date_format)} #{Paint[msg, :cyan]}"
172
173
  when :default
173
174
  puts msg
174
175
  end
@@ -180,7 +181,7 @@ module Kaizen
180
181
  def self.watch(path)
181
182
  path = File.expand_path(path)
182
183
 
183
- if File.exist? path
184
+ CLI.path_exists?(path) do
184
185
  Kaizen::CLI.pout(:info, "Watching: #{path}")
185
186
 
186
187
  options = {
@@ -202,32 +203,154 @@ module Kaizen
202
203
 
203
204
  has_error = false
204
205
 
205
- loop do
206
- css = Sass::Engine.new(
207
- File.read("#{path}/scss/main.scss"), options
208
- )
206
+ main_file = "#{path}/scss/main.scss"
209
207
 
210
- begin
211
- File.open("#{css_directory}/main.css", "w") do |f|
212
- f.write css.render
213
- end
208
+ CLI.path_exists?(main_file) do
209
+ loop do
210
+ css = Sass::Engine.new(File.read(main_file), options)
214
211
 
215
- if has_error
216
- Kaizen::CLI.pout(:debug, "You fixed the issue, thanks :)")
217
- has_error = false
212
+ begin
213
+ File.open("#{css_directory}/main.css", "w") do |f|
214
+ f.write css.render
215
+ end
216
+
217
+ if has_error
218
+ Kaizen::CLI.pout(:debug, "You fixed the issue, thanks :)")
219
+ has_error = false
220
+ end
221
+
222
+ sleep 3
223
+ rescue Sass::SyntaxError => e
224
+ Kaizen::CLI.pout(:error, e.message)
225
+ has_error = true
226
+ sleep 10
218
227
  end
219
-
220
- sleep 3
221
- rescue Sass::SyntaxError => e
222
- Kaizen::CLI.pout(:error, e.message)
223
- has_error = true
224
- sleep 10
225
228
  end
226
229
  end
230
+ end
231
+ end
232
+
233
+ ##
234
+ # Serve the specified path via the web server
235
+ #
236
+ def self.serve(path)
237
+ path = File.expand_path(path)
238
+
239
+ CLI.path_exists?(path) do
240
+ Kaizen::KZNServer.set_load_path(path)
241
+
242
+ Rack::Server.start({
243
+ :app => Kaizen::KZNServer,
244
+ :Port => 9191
245
+ })
246
+ end
247
+ end
248
+
249
+ ##
250
+ # Helper to clean up path checking
251
+ #
252
+ def self.path_exists?(path)
253
+ if File.exist? path
254
+ yield
227
255
  else
228
- Kaizen::CLI.pout(:error, "Path does not exist: #{path}")
256
+ Kaizen::CLI.pout(:error, "'#{path}' does not exist")
229
257
  end
230
258
  end
259
+ end
260
+
261
+ class KZNServer
262
+
263
+ def self.set_load_path(p)
264
+ @@server_path = p
265
+ end
266
+
267
+ def self.request_path(path)
268
+ parts = path.split('/')
269
+
270
+ if parts.size == 0
271
+ parts << "index.html"
272
+ end
273
+
274
+ return "#{@@server_path}/#{parts.join('/')}"
275
+ end
276
+
277
+ def self.mime_for(file)
278
+ supported_mimes = {
279
+ ".avi" => :"video/x-msvideo",
280
+ ".bmp" => :"image/bmp",
281
+ ".css" => :"text/css",
282
+ ".csv" => :"text/csv",
283
+ ".doc" => :"application/msword",
284
+ ".docm" => :"application/vnd.ms-word.document.macroEnabled.12",
285
+ ".docx" => :"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
286
+ ".flv" => :"video/x-flv",
287
+ ".gz" => :"application/x-gzip",
288
+ ".htm" => :"text/html",
289
+ ".html" => :"text/html",
290
+ ".ico" => :"image/x-icon",
291
+ ".jpe" => :"image/jpeg",
292
+ ".jpeg" => :"image/jpeg",
293
+ ".jpg" => :"image/jpeg",
294
+ ".js" => :"application/x-javascript",
295
+ ".m4a" => :"audio/m4a",
296
+ ".m4v" => :"video/x-m4v",
297
+ ".mov" => :"video/quicktime",
298
+ ".movie" => :"video/x-sgi-movie",
299
+ ".mp2" => :"video/mpeg",
300
+ ".mp2v" => :"video/mpeg",
301
+ ".mp3" => :"audio/mpeg",
302
+ ".mp4" => :"video/mp4",
303
+ ".mp4v" => :"video/mp4",
304
+ ".mpa" => :"video/mpeg",
305
+ ".mpeg" => :"video/mpeg",
306
+ ".mpg" => :"video/mpeg",
307
+ ".png" => :"image/png",
308
+ ".rar" => :"application/octet-stream",
309
+ ".tar" => :"application/x-tar",
310
+ ".tif" => :"image/tiff",
311
+ ".tiff" => :"image/tiff",
312
+ ".ttf" => :"application/octet-stream",
313
+ ".tts" => :"video/vnd.dlna.mpeg-tts",
314
+ ".txt" => :"text/plain",
315
+ ".wav" => :"audio/wav",
316
+ ".wsdl" => :"text/xml",
317
+ ".xhtml" => :"application/xhtml+xml",
318
+ ".xml" => :"text/xml",
319
+ ".xsd" => :"text/xml",
320
+ ".xsf" => :"text/xml",
321
+ ".xsl" => :"text/xml",
322
+ ".xslt" => :"text/xml",
323
+ ".xsn" => :"application/octet-stream",
324
+ ".zip" => :"application/x-zip-compressed"
325
+ }
326
+
327
+ ext = File.extname(file)
328
+
329
+ if supported_mimes.key?(ext)
330
+ supported_mimes[ext].to_s
331
+ else
332
+ 'text/html'
333
+ end
334
+ end
335
+
336
+ def self.call(env)
337
+ requested_file = request_path(Rack::Request.new(env).path)
338
+
339
+ response = Rack::Response.new
231
340
 
341
+ response['Content-Type'] = mime_for(requested_file)
342
+ response['Cache-Control'] = "no-cache, no-store, must-revalidate"
343
+ response['Pragma'] = "no-cache"
344
+ response['Expires'] = "0"
345
+
346
+ if File.file?(requested_file)
347
+ response.write(File.read(requested_file))
348
+ response.status = 200
349
+ else
350
+ response.status = 404
351
+ end
352
+
353
+ response.finish
354
+ end
232
355
  end
233
356
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kaizen-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nico Van Zyl
@@ -11,6 +11,26 @@ bindir: bin
11
11
  cert_chain: []
12
12
  date: 2016-06-06 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rack
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.6'
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.6.4
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ requirements:
28
+ - - "~>"
29
+ - !ruby/object:Gem::Version
30
+ version: '1.6'
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.6.4
14
34
  - !ruby/object:Gem::Dependency
15
35
  name: minitest
16
36
  requirement: !ruby/object:Gem::Requirement
@@ -193,6 +213,7 @@ files:
193
213
  - README.md
194
214
  - Rakefile
195
215
  - bin/kzn
216
+ - build.sh
196
217
  - install.sh
197
218
  - kaizen-cli.gemspec
198
219
  - lib/kaizen.rb