Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
0d20530e
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
0d20530e
编写于
12月 08, 2016
作者:
D
David Heinemeier Hansson
提交者:
GitHub
12月 08, 2016
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make Yarn the default, drop default vendor/asset directories (#27300)
上级
17b09f4f
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
34 addition
and
111 deletion
+34
-111
railties/CHANGELOG.md
railties/CHANGELOG.md
+1
-2
railties/lib/rails/generators/app_base.rb
railties/lib/rails/generators/app_base.rb
+2
-51
railties/lib/rails/generators/rails/app/app_generator.rb
railties/lib/rails/generators/rails/app/app_generator.rb
+10
-23
railties/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt
...ls/app/templates/app/assets/javascripts/application.js.tt
+2
-2
railties/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css
...ails/app/templates/app/assets/stylesheets/application.css
+2
-2
railties/lib/rails/generators/rails/app/templates/bin/setup.tt
...ies/lib/rails/generators/rails/app/templates/bin/setup.tt
+2
-2
railties/lib/rails/generators/rails/app/templates/bin/update.tt
...es/lib/rails/generators/rails/app/templates/bin/update.tt
+2
-2
railties/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt
...tors/rails/app/templates/config/initializers/assets.rb.tt
+1
-1
railties/lib/rails/generators/rails/app/templates/gitignore
railties/lib/rails/generators/rails/app/templates/gitignore
+1
-1
railties/test/generators/api_app_generator_test.rb
railties/test/generators/api_app_generator_test.rb
+0
-1
railties/test/generators/app_generator_test.rb
railties/test/generators/app_generator_test.rb
+11
-24
未找到文件。
railties/CHANGELOG.md
浏览文件 @
0d20530e
*
Add Yarn support in new apps using --yarn option. This adds a yarn binstub, vendor/package.json,
and the settings needed to get npm modules integrated in new apps.
*
Add Yarn support in new apps with a yarn binstub and vendor/package.json. Skippable via --skip-yarn option.
*Liceth Ovalles*, *Guillermo Iguaran*, *DHH*
...
...
railties/lib/rails/generators/app_base.rb
浏览文件 @
0d20530e
...
...
@@ -33,8 +33,8 @@ def self.add_shared_options_for(name)
class_option
:javascript
,
type: :string
,
aliases:
"-j"
,
desc:
"Preconfigure for selected JavaScript library"
class_option
:
yarn
,
type: :boolean
,
default:
false
,
desc:
"
Preconfigure for assets management with Yarn
"
class_option
:
skip_yarn
,
type: :boolean
,
default:
false
,
desc:
"
Don't use Yarn for managing JavaScript dependencies
"
class_option
:skip_gemfile
,
type: :boolean
,
default:
false
,
desc:
"Don't create a Gemfile"
...
...
@@ -414,55 +414,6 @@ def run_bundle
bundle_command
(
"install"
)
if
bundle_install?
end
def
run_yarn
if
package_json_exist?
if
yarn_path
say_status
:run
,
"yarn install"
yarn_command
(
"install"
)
else
say_status
:warning
,
"yarn option passed but Yarn executable was not detected in the system."
,
:yellow
say_status
:warning
,
"Download Yarn at https://yarnpkg.com/en/docs/install"
,
:yellow
end
end
end
def
package_json_exist?
File
.
exist?
(
"vendor/package.json"
)
end
def
yarn_path
commands
=
[
"yarn"
]
if
Gem
.
win_platform?
ENV
[
"PATHEXT"
].
split
(
File
::
PATH_SEPARATOR
).
each
do
|
ext
|
commands
<<
commands
[
0
]
+
ext
end
end
yarn_path
=
commands
.
find
do
|
cmd
|
paths
=
ENV
[
"PATH"
].
split
(
File
::
PATH_SEPARATOR
)
path
=
paths
.
find
do
|
p
|
full_path
=
File
.
expand_path
(
cmd
,
p
)
File
.
executable?
(
full_path
)
&&
File
.
file?
(
full_path
)
end
path
&&
File
.
expand_path
(
cmd
,
path
)
end
yarn_path
end
def
yarn_command
(
command
)
full_command
=
"
#{
yarn_path
}
#{
command
}
"
if
options
[
:quiet
]
system
(
full_command
,
out:
File
::
NULL
)
else
system
(
full_command
)
end
end
def
generate_spring_binstubs
if
bundle_install?
&&
spring_install?
bundle_command
(
"exec spring binstub --all"
)
...
...
railties/lib/rails/generators/rails/app/app_generator.rb
浏览文件 @
0d20530e
...
...
@@ -53,10 +53,6 @@ def gitignore
template
"gitignore"
,
".gitignore"
end
def
packagejson
template
"package.json"
,
"vendor/package.json"
end
def
app
directory
"app"
...
...
@@ -155,23 +151,12 @@ def tmp
end
def
vendor
if
options
[
:yarn
]
empty_directory_with_keep_file
"vendor"
else
vendor_javascripts
vendor_stylesheets
end
end
empty_directory_with_keep_file
"vendor"
def
vendor_javascripts
unless
options
[
:skip_javascript
]
empty_directory_with_keep_file
"vendor/assets/javascripts"
unless
options
[
:skip_yarn
]
template
"package.json"
,
"vendor/package.json"
end
end
def
vendor_stylesheets
empty_directory_with_keep_file
"vendor/assets/stylesheets"
end
end
module
Generators
...
...
@@ -213,9 +198,8 @@ def create_root_files
build
(
:readme
)
build
(
:rakefile
)
build
(
:configru
)
build
(
:packagejson
)
if
options
[
:yarn
]
build
(
:gitignore
)
unless
options
[
:skip_git
]
build
(
:gemfile
)
unless
options
[
:skip_gemfile
]
build
(
:gitignore
)
unless
options
[
:skip_git
]
build
(
:gemfile
)
unless
options
[
:skip_gemfile
]
end
def
create_app_files
...
...
@@ -276,6 +260,10 @@ def create_tmp_files
def
create_vendor_files
build
(
:vendor
)
if
options
[
:skip_yarn
]
remove_file
"vendor/package.json"
end
end
def
delete_app_assets_if_api_option
...
...
@@ -283,7 +271,6 @@ def delete_app_assets_if_api_option
remove_dir
"app/assets"
remove_dir
"lib/assets"
remove_dir
"tmp/cache/assets"
remove_dir
"vendor/assets"
end
end
...
...
@@ -364,7 +351,7 @@ def finish_template
end
public_task
:apply_rails_template
,
:run_bundle
public_task
:
run_yarn
,
:
generate_spring_binstubs
public_task
:generate_spring_binstubs
def
run_after_bundle_callbacks
@after_bundle_callbacks
.
each
(
&
:call
)
...
...
railties/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt
浏览文件 @
0d20530e
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts,
vendor/assets/javascripts,
//
or any plugin's
vendor/assets/javascripts directory can be referenced here using a relative path.
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts,
or any plugin's
// vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file. JavaScript code in this file should be added after the last require_* statement.
...
...
railties/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css
浏览文件 @
0d20530e
...
...
@@ -2,8 +2,8 @@
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS and SCSS file within this directory, lib/assets/stylesheets,
vendor/assets/stylesheets,
*
or any plugin's
vendor/assets/stylesheets directory can be referenced here using a relative path.
* Any CSS and SCSS file within this directory, lib/assets/stylesheets,
or any plugin's
* vendor/assets/stylesheets directory can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
...
...
railties/lib/rails/generators/rails/app/templates/bin/setup.tt
浏览文件 @
0d20530e
...
...
@@ -16,8 +16,8 @@ chdir APP_ROOT do
puts '== Installing dependencies =='
system! 'gem install bundler --conservative'
system('bundle check') || system!('bundle install')
<%
if options[:
yarn] %>
system
! 'bin/yarn'
<%
unless options[:skip_
yarn] %>
system
('bin/yarn') # Ignore failure from yarn not being installed
<% end %>
<% unless options.skip_active_record -%>
...
...
railties/lib/rails/generators/rails/app/templates/bin/update.tt
浏览文件 @
0d20530e
...
...
@@ -16,8 +16,8 @@ chdir APP_ROOT do
puts '== Installing dependencies =='
system! 'gem install bundler --conservative'
system('bundle check') || system!('bundle install')
<%
if options[:
yarn] %>
system
! 'bin/yarn'
<%
unless options[:skip_
yarn] %>
system
('bin/yarn') # Ignore failure from yarn not being installed
<% end %>
<% unless options.skip_active_record -%>
...
...
railties/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt
浏览文件 @
0d20530e
...
...
@@ -5,7 +5,7 @@ Rails.application.config.assets.version = '1.0'
# Add additional assets to the asset load path.
# Rails.application.config.assets.paths << Emoji.images_path
<%-
if options[:
yarn] -%>
<%-
unless options[:skip_
yarn] -%>
# Add Yarn node_modules folder to the asset load path.
Rails.application.config.assets.paths << Rails.root.join('vendor/node_modules')
<%- end -%>
...
...
railties/lib/rails/generators/rails/app/templates/gitignore
浏览文件 @
0d20530e
...
...
@@ -21,7 +21,7 @@
!/tmp/.keep
<% end -%>
<%
if options[:
yarn] -%>
<%
unless options[:skip_
yarn] -%>
/vendor/node_modules
<% end -%>
...
...
railties/test/generators/api_app_generator_test.rb
浏览文件 @
0d20530e
...
...
@@ -108,7 +108,6 @@ def skipped_files
config/initializers/assets.rb
config/initializers/cookies_serializer.rb
lib/assets
vendor/assets
test/helpers
tmp/cache/assets
public/404.html
...
...
railties/test/generators/app_generator_test.rb
浏览文件 @
0d20530e
...
...
@@ -43,9 +43,6 @@
test/mailers
test/integration
vendor
vendor/assets
vendor/assets/stylesheets
vendor/assets/javascripts
tmp
tmp/cache
tmp/cache/assets
...
...
@@ -466,7 +463,6 @@ def test_javascript_is_skipped_if_required
run_generator
[
destination_root
,
"--skip-javascript"
]
assert_no_file
"app/assets/javascripts"
assert_no_file
"vendor/assets/javascripts"
assert_file
"app/views/layouts/application.html.erb"
do
|
contents
|
assert_match
(
/stylesheet_link_tag\s+'application', media: 'all' %>/
,
contents
)
...
...
@@ -492,12 +488,21 @@ def test_coffeescript_is_skipped_if_required
end
end
def
test_generator_
if_yarn_option_is_give
n
run_generator
([
destination_root
,
"--yarn"
])
def
test_generator_
for_yar
n
run_generator
([
destination_root
])
assert_file
"vendor/package.json"
,
/dependencies/
assert_file
"config/initializers/assets.rb"
,
/node_modules/
end
def
test_generator_for_yarn_skipped
run_generator
([
destination_root
])
assert_no_file
"vendor/package.json"
assert_file
"config/environments/production.rb"
do
|
content
|
assert_no_match
(
/node_modules/
,
content
)
end
end
def
test_inclusion_of_jbuilder
run_generator
assert_gem
"jbuilder"
...
...
@@ -618,10 +623,6 @@ def test_generation_runs_bundle_install
assert_generates_with_bundler
end
def
test_generation_runs_yarn_install_with_yarn_option
assert_generates_with_yarn
yarn:
true
end
def
test_dev_option
assert_generates_with_bundler
dev:
true
rails_path
=
File
.
expand_path
(
"../../.."
,
Rails
.
root
)
...
...
@@ -847,18 +848,4 @@ def assert_generates_with_bundler(options = {})
quietly
{
generator
.
invoke_all
}
end
end
def
assert_generates_with_yarn
(
options
=
{})
generator
([
destination_root
],
options
)
command_check
=
->
command
do
@install_called
||=
0
@install_called
+=
1
assert_equal
1
,
@install_called
,
"install expected to be called once, but was called
#{
@install_called
}
times"
end
generator
.
stub
:yarn_command
,
command_check
do
quietly
{
generator
.
invoke_all
}
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录