blacksmith-js 0.0.1
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.
- data/.gitignore +1 -0
- data/.rspec +2 -0
- data/.rvmrc +1 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +45 -0
- data/Rakefile +5 -0
- data/bin/blacksmith +5 -0
- data/blacksmith.gemspec +16 -0
- data/lib/blacksmith.rb +18 -0
- data/lib/blacksmith/application.rb +37 -0
- data/lib/blacksmith/cli.rb +15 -0
- data/lib/blacksmith/cli/build.rb +8 -0
- data/lib/blacksmith/cli/init.rb +12 -0
- data/lib/blacksmith/cli/watch.rb +6 -0
- data/lib/blacksmith/configure.rb +31 -0
- data/lib/blacksmith/preprocessor.rb +53 -0
- data/lib/blacksmith/template/config.rb.erb +2 -0
- data/lib/version.rb +3 -0
- data/spec/application_spec.rb +7 -0
- data/spec/configure_spec.rb +23 -0
- data/spec/tmp/config.rb +1 -0
- metadata +98 -0
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
*.gem
|
data/.rspec
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use 1.9.3@blacksmith --create
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
diff-lcs (1.1.3)
|
5
|
+
execjs (1.4.0)
|
6
|
+
multi_json (~> 1.0)
|
7
|
+
file-tail (1.0.12)
|
8
|
+
tins (~> 0.5)
|
9
|
+
gzip (1.0)
|
10
|
+
listen (0.5.3)
|
11
|
+
multi_json (1.3.6)
|
12
|
+
rspec (2.11.0)
|
13
|
+
rspec-core (~> 2.11.0)
|
14
|
+
rspec-expectations (~> 2.11.0)
|
15
|
+
rspec-mocks (~> 2.11.0)
|
16
|
+
rspec-core (2.11.1)
|
17
|
+
rspec-expectations (2.11.3)
|
18
|
+
diff-lcs (~> 1.1.3)
|
19
|
+
rspec-mocks (2.11.3)
|
20
|
+
ruby2ruby (1.3.1)
|
21
|
+
ruby_parser (~> 2.0)
|
22
|
+
sexp_processor (~> 3.0)
|
23
|
+
ruby_parser (2.3.1)
|
24
|
+
sexp_processor (~> 3.0)
|
25
|
+
sexp_processor (3.2.0)
|
26
|
+
sourcify (0.4.2)
|
27
|
+
file-tail (>= 1.0.5)
|
28
|
+
ruby2ruby (>= 1.2.5)
|
29
|
+
sexp_processor (>= 3.0.5)
|
30
|
+
thor (0.16.0)
|
31
|
+
tins (0.6.0)
|
32
|
+
uglifier (1.3.0)
|
33
|
+
execjs (>= 0.3.0)
|
34
|
+
multi_json (~> 1.0, >= 1.0.2)
|
35
|
+
|
36
|
+
PLATFORMS
|
37
|
+
ruby
|
38
|
+
|
39
|
+
DEPENDENCIES
|
40
|
+
gzip
|
41
|
+
listen
|
42
|
+
rspec
|
43
|
+
sourcify
|
44
|
+
thor
|
45
|
+
uglifier
|
data/Rakefile
ADDED
data/bin/blacksmith
ADDED
data/blacksmith.gemspec
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require File.expand_path("../lib/version.rb", __FILE__)
|
2
|
+
Gem::Specification.new do |s|
|
3
|
+
s.name = 'blacksmith-js'
|
4
|
+
s.version = Blacksmith::VERSION
|
5
|
+
s.date = '2012-10-14'
|
6
|
+
s.summary = "build js library, extensions with blacksmith"
|
7
|
+
s.description = "build js library, extensions with blacksmith"
|
8
|
+
s.authors = ["Eugene Varlamov"]
|
9
|
+
s.email = 'varlamoved@gmail.com'
|
10
|
+
s.files = `git ls-files`.split("\n")
|
11
|
+
s.homepage = 'http://varlamoved.ru/blacksmith'
|
12
|
+
s.executables << 'blacksmith'
|
13
|
+
s.add_dependency("listen", ["~> 0.5.3"])
|
14
|
+
s.add_dependency("uglifier", ["~> 1.3.0"])
|
15
|
+
end
|
16
|
+
|
data/lib/blacksmith.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'blacksmith/cli'
|
2
|
+
require 'blacksmith/configure'
|
3
|
+
require 'blacksmith/application'
|
4
|
+
require 'blacksmith/preprocessor'
|
5
|
+
|
6
|
+
module Blacksmith
|
7
|
+
|
8
|
+
class << self
|
9
|
+
def config
|
10
|
+
@config ||= Blacksmith::Configure.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def app
|
14
|
+
@app ||= Blacksmith::Application.new
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'uglifier'
|
2
|
+
#require 'gzip'
|
3
|
+
|
4
|
+
module Blacksmith
|
5
|
+
class Application
|
6
|
+
|
7
|
+
def root
|
8
|
+
@root ||= Dir.pwd
|
9
|
+
end
|
10
|
+
|
11
|
+
|
12
|
+
def build
|
13
|
+
files = Blacksmith.config.build_files
|
14
|
+
|
15
|
+
files.each do |f|
|
16
|
+
output = Preprocessor.proccess(f)
|
17
|
+
|
18
|
+
if Blacksmith.config.env == :production
|
19
|
+
output = Uglifier.compile(output)
|
20
|
+
end
|
21
|
+
|
22
|
+
output_file = File.new(output_filename_helper(f), 'w')
|
23
|
+
output_file.write(output)
|
24
|
+
#output_file_gzip = File.new(output_filename_helper(file, :gzip => true), 'w')
|
25
|
+
#output_file_gzip.write(output.gzip)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
protected
|
31
|
+
|
32
|
+
def output_filename_helper(file, options ={})
|
33
|
+
suffix = options[:gzip] ? '.gz' : ''
|
34
|
+
"#{Blacksmith.config.build_folder}/#{file.gsub('_', '-')}.js#{suffix}"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'thor'
|
2
|
+
module Blacksmith
|
3
|
+
class Cli < Thor
|
4
|
+
def self.source_root
|
5
|
+
File.dirname(__FILE__)
|
6
|
+
end
|
7
|
+
def self.pwd
|
8
|
+
Dir.pwd
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
require 'blacksmith/cli/init'
|
14
|
+
require 'blacksmith/cli/build'
|
15
|
+
require 'blacksmith/cli/watch'
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'thor'
|
2
|
+
class Blacksmith::Cli
|
3
|
+
include Thor::Actions
|
4
|
+
desc 'init', 'create project [name]'
|
5
|
+
def init(project_name)
|
6
|
+
create_file "#{project_name}/config.rb" do
|
7
|
+
"set :build_files, ['#{project_name}']"
|
8
|
+
end
|
9
|
+
create_file "#{project_name}/source/#{project_name}.js"
|
10
|
+
create_file "#{project_name}/build/.gitkeep"
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Blacksmith
|
2
|
+
class Configure
|
3
|
+
attr_accessor :build_files
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
exec_config_file
|
7
|
+
end
|
8
|
+
|
9
|
+
|
10
|
+
def set(k, v)
|
11
|
+
instance_variable_set(:"@#{k}", v)
|
12
|
+
end
|
13
|
+
|
14
|
+
def exec_config_file(&block)
|
15
|
+
instance_eval(File.read(File.join(Dir.pwd, 'config.rb')))
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
def build_folder
|
20
|
+
Blacksmith.app.root + '/build'
|
21
|
+
end
|
22
|
+
def source_folder
|
23
|
+
Blacksmith.app.root + '/source'
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
def env
|
28
|
+
:production
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Blacksmith
|
2
|
+
class Preprocessor
|
3
|
+
|
4
|
+
class << self
|
5
|
+
|
6
|
+
def get_file(filename)
|
7
|
+
File.open("#{Blacksmith.config.source_folder}/#{filename}.js")
|
8
|
+
end
|
9
|
+
|
10
|
+
|
11
|
+
def proccess(filename)
|
12
|
+
file = get_file(filename)
|
13
|
+
input_file = file.readlines
|
14
|
+
output = input_file.map { |line|
|
15
|
+
if line =~ /\/\/#/
|
16
|
+
#line.gsub!(/\/\/#/, '').strip!
|
17
|
+
case line
|
18
|
+
when /include/
|
19
|
+
included_filename = line.match(/include\s+(.*)/)[1].strip
|
20
|
+
proccess(included_filename)
|
21
|
+
when /insert/
|
22
|
+
include_arg = line.match(/insert\s+(.*)/)[1].strip
|
23
|
+
get_file(include_arg).read
|
24
|
+
when /if_env/
|
25
|
+
env = line.match(/if_env\s+(.*)/)[1].strip
|
26
|
+
if Blacksmith.config.env == env
|
27
|
+
line
|
28
|
+
else
|
29
|
+
''
|
30
|
+
end
|
31
|
+
else
|
32
|
+
line
|
33
|
+
end
|
34
|
+
else
|
35
|
+
line
|
36
|
+
end
|
37
|
+
}.join()
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
class CommandShell
|
43
|
+
class << self
|
44
|
+
|
45
|
+
def parse(line)
|
46
|
+
nil or Object
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
attr_accessor :command
|
51
|
+
attr_accessor :options
|
52
|
+
end
|
53
|
+
end
|
data/lib/version.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.expand_path('../../lib/blacksmith/configure.rb', __FILE__)
|
2
|
+
require 'sourcify'
|
3
|
+
require 'tempfile'
|
4
|
+
|
5
|
+
describe Blacksmith::Configure do
|
6
|
+
it 'set' do
|
7
|
+
|
8
|
+
Dir.stub!(:pwd) { File.dirname(File.expand_path('tmp', __FILE__))}
|
9
|
+
f = create_tempfile_with_block do
|
10
|
+
set :qwe, 'qwe'
|
11
|
+
end
|
12
|
+
config = Blacksmith::Configure.new
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
def create_tempfile_with_block(&block)
|
17
|
+
f = File.new(File.expand_path('../tmp/config.rb', __FILE__), 'w')
|
18
|
+
f.write block.to_source(:strip_enclosure => true)
|
19
|
+
f
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
|
data/spec/tmp/config.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
set(:qwe, "qwe")
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: blacksmith-js
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Eugene Varlamov
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-10-14 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: listen
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.5.3
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.5.3
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: uglifier
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 1.3.0
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.3.0
|
46
|
+
description: build js library, extensions with blacksmith
|
47
|
+
email: varlamoved@gmail.com
|
48
|
+
executables:
|
49
|
+
- blacksmith
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- .gitignore
|
54
|
+
- .rspec
|
55
|
+
- .rvmrc
|
56
|
+
- Gemfile
|
57
|
+
- Gemfile.lock
|
58
|
+
- Rakefile
|
59
|
+
- bin/blacksmith
|
60
|
+
- blacksmith.gemspec
|
61
|
+
- lib/blacksmith.rb
|
62
|
+
- lib/blacksmith/application.rb
|
63
|
+
- lib/blacksmith/cli.rb
|
64
|
+
- lib/blacksmith/cli/build.rb
|
65
|
+
- lib/blacksmith/cli/init.rb
|
66
|
+
- lib/blacksmith/cli/watch.rb
|
67
|
+
- lib/blacksmith/configure.rb
|
68
|
+
- lib/blacksmith/preprocessor.rb
|
69
|
+
- lib/blacksmith/template/config.rb.erb
|
70
|
+
- lib/version.rb
|
71
|
+
- spec/application_spec.rb
|
72
|
+
- spec/configure_spec.rb
|
73
|
+
- spec/tmp/config.rb
|
74
|
+
homepage: http://varlamoved.ru/blacksmith
|
75
|
+
licenses: []
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
88
|
+
requirements:
|
89
|
+
- - ! '>='
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
requirements: []
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 1.8.24
|
95
|
+
signing_key:
|
96
|
+
specification_version: 3
|
97
|
+
summary: build js library, extensions with blacksmith
|
98
|
+
test_files: []
|