opal-webpack-loader 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/owl-install +8 -0
- data/lib/opal-webpack-loader/compile_server.rb +6 -5
- data/lib/opal-webpack-loader/installer_cli.rb +305 -0
- data/lib/opal-webpack-loader/rails_view_helper.rb +4 -0
- data/lib/opal-webpack-loader/templates/Procfile.erb +1 -0
- data/lib/opal-webpack-loader/templates/application.js.erb +25 -0
- data/lib/opal-webpack-loader/templates/application_common.js.erb +8 -0
- data/lib/opal-webpack-loader/templates/application_debug.js.erb +13 -0
- data/lib/opal-webpack-loader/templates/application_ssr.js.erb +23 -0
- data/lib/opal-webpack-loader/templates/debug.js.erb +145 -0
- data/lib/opal-webpack-loader/templates/development.js.erb +130 -0
- data/lib/opal-webpack-loader/templates/initializer.rb.erb +11 -0
- data/lib/opal-webpack-loader/templates/opal_loader.rb.erb +9 -0
- data/lib/opal-webpack-loader/templates/package.json.erb +17 -0
- data/lib/opal-webpack-loader/templates/production.js.erb +107 -0
- data/lib/opal-webpack-loader/version.rb +1 -1
- data/lib/opal-webpack-loader/view_helper.rb +4 -0
- data/lib/opal-webpack-loader.rb +26 -24
- data/spec/fixtures/flattering/Gemfile +10 -0
- data/spec/fixtures/flattering/app_loader.rb +8 -0
- data/spec/fixtures/flattering/config.ru +22 -0
- data/spec/installer_spec.rb +96 -0
- data/spec/owl_spec.rb +86 -0
- data/spec/spec_helper.rb +16 -0
- metadata +105 -8
@@ -0,0 +1,130 @@
|
|
1
|
+
// require requirements used below
|
2
|
+
const path = require('path');
|
3
|
+
const webpack = require('webpack');
|
4
|
+
const OwlResolver = require('opal-webpack-loader/resolver'); // to resolve ruby files
|
5
|
+
|
6
|
+
module.exports = {
|
7
|
+
context: path.resolve(__dirname, '<%= opal_directory %>'),
|
8
|
+
mode: "development",
|
9
|
+
optimization: {
|
10
|
+
minimize: false // dont minimize in development, to speed up hot reloads
|
11
|
+
},
|
12
|
+
performance: {
|
13
|
+
maxAssetSize: 20000000,
|
14
|
+
maxEntrypointSize: 20000000
|
15
|
+
},
|
16
|
+
entry: {
|
17
|
+
application: [path.resolve(__dirname, '<%= js_entry %>')],
|
18
|
+
application_ssr: [path.resolve(__dirname, '<%= js_ssr_entry %>')]
|
19
|
+
},
|
20
|
+
output: {
|
21
|
+
// webpack-dev-server keeps the output in memory
|
22
|
+
filename: '[name].js',
|
23
|
+
path: path.resolve(__dirname, '<%= asset_output_directory %>'),
|
24
|
+
publicPath: 'http://localhost:3035/assets/'
|
25
|
+
},
|
26
|
+
resolve: {
|
27
|
+
plugins: [
|
28
|
+
// this makes it possible for webpack to find ruby files
|
29
|
+
new OwlResolver('resolve', 'resolved')
|
30
|
+
]
|
31
|
+
},
|
32
|
+
plugins: [
|
33
|
+
// both for hot reloading
|
34
|
+
new webpack.NamedModulesPlugin(),
|
35
|
+
new webpack.HotModuleReplacementPlugin()
|
36
|
+
],
|
37
|
+
module: {
|
38
|
+
rules: [
|
39
|
+
{
|
40
|
+
// loader for .scss files
|
41
|
+
// test means "test for for file endings"
|
42
|
+
test: /.scss$/,
|
43
|
+
use: [
|
44
|
+
{
|
45
|
+
loader: "style-loader",
|
46
|
+
options: {
|
47
|
+
hmr: true
|
48
|
+
}
|
49
|
+
},
|
50
|
+
{
|
51
|
+
loader: "css-loader",
|
52
|
+
options: {
|
53
|
+
minimize: false // set to false to speed up hot reloads
|
54
|
+
}
|
55
|
+
},
|
56
|
+
{
|
57
|
+
loader: "sass-loader",
|
58
|
+
options: {
|
59
|
+
includePaths: [path.resolve(__dirname, '<%= stylesheets_directory %>')],
|
60
|
+
}
|
61
|
+
}
|
62
|
+
]
|
63
|
+
},
|
64
|
+
{
|
65
|
+
// loader for .css files
|
66
|
+
test: /.css$/,
|
67
|
+
use: [
|
68
|
+
{
|
69
|
+
loader: "style-loader",
|
70
|
+
options: {
|
71
|
+
hmr: true
|
72
|
+
}
|
73
|
+
},
|
74
|
+
{
|
75
|
+
loader: "css-loader",
|
76
|
+
options: {
|
77
|
+
minimize: false // set to false to speed up hot reloads
|
78
|
+
}
|
79
|
+
}
|
80
|
+
]
|
81
|
+
},
|
82
|
+
{
|
83
|
+
test: /.(png|svg|jpg|gif)$/,
|
84
|
+
use: [
|
85
|
+
'file-loader'
|
86
|
+
]
|
87
|
+
},
|
88
|
+
{
|
89
|
+
test: /.(woff|woff2|eot|ttf|otf)$/,
|
90
|
+
use: [
|
91
|
+
'file-loader'
|
92
|
+
]
|
93
|
+
},
|
94
|
+
{
|
95
|
+
// opal-webpack-loader will compile and include ruby files in the pack
|
96
|
+
test: /.(rb|js.rb)$/,
|
97
|
+
use: [
|
98
|
+
{
|
99
|
+
loader: 'opal-webpack-loader',
|
100
|
+
}
|
101
|
+
]
|
102
|
+
}
|
103
|
+
]
|
104
|
+
},
|
105
|
+
// configuration for webpack-dev-server
|
106
|
+
devServer: {
|
107
|
+
open: false,
|
108
|
+
lazy: false,
|
109
|
+
port: 3035,
|
110
|
+
hot: true,
|
111
|
+
// hotOnly: true,
|
112
|
+
inline: true,
|
113
|
+
https: false,
|
114
|
+
disableHostCheck: true,
|
115
|
+
headers: {
|
116
|
+
"Access-Control-Allow-Origin": "*",
|
117
|
+
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, PATCH, OPTIONS",
|
118
|
+
"Access-Control-Allow-Headers": "X-Requested-With, content-type, Authorization"
|
119
|
+
},
|
120
|
+
watchOptions: {
|
121
|
+
// in case of problems with hot reloading uncomment the following two lines:
|
122
|
+
// aggregateTimeout: 250,
|
123
|
+
// poll: 50,
|
124
|
+
ignored: /\bnode_modules\b/
|
125
|
+
},
|
126
|
+
contentBase: path.resolve(__dirname, 'public')
|
127
|
+
// watchContentBase: true
|
128
|
+
}
|
129
|
+
};
|
130
|
+
|
@@ -0,0 +1,11 @@
|
|
1
|
+
env = defined? Rails ? Rails.env : 'development'
|
2
|
+
|
3
|
+
if env != 'development'
|
4
|
+
OpalWebpackLoader.client_asset_path = '' # the full path is in the manifest already, like: /packs/website_packs-97fd9c2b7e7bdb112fc1.js
|
5
|
+
OpalWebpackLoader.manifest_path = 'public/assets/manifest.json'
|
6
|
+
OpalWebpackLoader.use_manifest = true
|
7
|
+
else
|
8
|
+
OpalWebpackLoader.client_asset_path = 'http://localhost:3035/assets/'
|
9
|
+
OpalWebpackLoader.manifest_path = nil
|
10
|
+
OpalWebpackLoader.use_manifest = false
|
11
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'opal'
|
2
|
+
|
3
|
+
# the gem opal-autoloader may be used, so its not necessary to use 'require' all the time,
|
4
|
+
# just using 'require_tree' to bundle everything is enough:
|
5
|
+
#
|
6
|
+
# require 'opal-autoloader'
|
7
|
+
# require_tree 'my_app' # for a sub directory 'my_app'
|
8
|
+
|
9
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
{
|
2
|
+
"dependencies": {
|
3
|
+
},
|
4
|
+
"scripts": {
|
5
|
+
"debug": "<%= debug_script %>",
|
6
|
+
"development": "<%= development_script %>",
|
7
|
+
"production_build": "<%= production_script %>"
|
8
|
+
},
|
9
|
+
"devDependencies": {
|
10
|
+
"compression-webpack-plugin": "^2.0.0",
|
11
|
+
"opal-webpack-loader": "^<%= owl_version %>",
|
12
|
+
"webpack": "^4.30.0",
|
13
|
+
"webpack-cli": "^3.3.0",
|
14
|
+
"webpack-dev-server": "^3.3.1",
|
15
|
+
"webpack-manifest-plugin": "^2.0.4"
|
16
|
+
}
|
17
|
+
}
|
@@ -0,0 +1,107 @@
|
|
1
|
+
const path = require('path');
|
2
|
+
const OwlResolver = require('opal-webpack-loader/resolver');
|
3
|
+
const CompressionPlugin = require("compression-webpack-plugin"); // for gzipping the packs
|
4
|
+
const ManifestPlugin = require('webpack-manifest-plugin'); // for generating the manifest
|
5
|
+
|
6
|
+
module.exports = {
|
7
|
+
context: path.resolve(__dirname, '<%= opal_directory %>'),
|
8
|
+
mode: "production",
|
9
|
+
optimization: {
|
10
|
+
minimize: true // minimize
|
11
|
+
},
|
12
|
+
performance: {
|
13
|
+
maxAssetSize: 20000000,
|
14
|
+
maxEntrypointSize: 20000000
|
15
|
+
},
|
16
|
+
entry: {
|
17
|
+
application: [path.resolve(__dirname, '<%= js_entry %>')],
|
18
|
+
application_ssr: [path.resolve(__dirname, '<%= js_ssr_entry %>')]
|
19
|
+
},
|
20
|
+
output: {
|
21
|
+
filename: '[name]-[chunkhash].js', // include fingerprint in file name, so browsers get the latest
|
22
|
+
path: path.resolve(__dirname, '<%= asset_output_directory %>'),
|
23
|
+
publicPath: '/assets/'
|
24
|
+
},
|
25
|
+
resolve: {
|
26
|
+
plugins: [
|
27
|
+
new OwlResolver('resolve', 'resolved') // resolve ruby files
|
28
|
+
]
|
29
|
+
},
|
30
|
+
plugins: [
|
31
|
+
new CompressionPlugin({ test: /^((?!application_ssr).)*$/ }), // gzip compress, exclude application_ssr.js
|
32
|
+
new ManifestPlugin({ fileName: 'manifest.json' }) // generate manifest
|
33
|
+
],
|
34
|
+
module: {
|
35
|
+
rules: [
|
36
|
+
{
|
37
|
+
test: /.scss$/,
|
38
|
+
use: [
|
39
|
+
{
|
40
|
+
loader: "style-loader",
|
41
|
+
options: {
|
42
|
+
hmr: false
|
43
|
+
}
|
44
|
+
},
|
45
|
+
{
|
46
|
+
loader: "css-loader",
|
47
|
+
options: {
|
48
|
+
sourceMap: false, // set to false to speed up hot reloads
|
49
|
+
minimize: true // set to false to speed up hot reloads
|
50
|
+
}
|
51
|
+
},
|
52
|
+
{
|
53
|
+
loader: "sass-loader",
|
54
|
+
options: {
|
55
|
+
includePath: [path.resolve(__dirname, '<%= stylesheets_directory %>')],
|
56
|
+
sourceMap: false // set to false to speed up hot reloads
|
57
|
+
}
|
58
|
+
}
|
59
|
+
]
|
60
|
+
},
|
61
|
+
{
|
62
|
+
// loader for .css files
|
63
|
+
test: /.css$/,
|
64
|
+
use: [
|
65
|
+
{
|
66
|
+
loader: "style-loader",
|
67
|
+
options: {
|
68
|
+
hmr: false
|
69
|
+
}
|
70
|
+
},
|
71
|
+
{
|
72
|
+
loader: "css-loader",
|
73
|
+
options: {
|
74
|
+
sourceMap: false, // set to false to speed up hot reloads
|
75
|
+
minimize: true // set to false to speed up hot reloads
|
76
|
+
}
|
77
|
+
}
|
78
|
+
]
|
79
|
+
},
|
80
|
+
{
|
81
|
+
test: /.(png|svg|jpg|gif)$/,
|
82
|
+
use: [
|
83
|
+
'file-loader'
|
84
|
+
]
|
85
|
+
},
|
86
|
+
{
|
87
|
+
test: /.(woff|woff2|eot|ttf|otf)$/,
|
88
|
+
use: [
|
89
|
+
'file-loader'
|
90
|
+
]
|
91
|
+
},
|
92
|
+
{
|
93
|
+
// opal-webpack-loader will compile and include ruby files in the pack
|
94
|
+
test: /.(rb|js.rb)$/,
|
95
|
+
use: [
|
96
|
+
{
|
97
|
+
loader: 'opal-webpack-loader',
|
98
|
+
options: {
|
99
|
+
sourceMap: false
|
100
|
+
}
|
101
|
+
}
|
102
|
+
]
|
103
|
+
}
|
104
|
+
]
|
105
|
+
}
|
106
|
+
};
|
107
|
+
|
@@ -8,5 +8,9 @@ module OpalWebpackLoader
|
|
8
8
|
"<script type=\"application/javascript\" src=\"#{OpalWebpackLoader.client_asset_path}#{path}\"></script>"
|
9
9
|
end
|
10
10
|
end
|
11
|
+
|
12
|
+
def application_script_tag
|
13
|
+
"<script type=\"application/javascript\" src=\"#{OpalWebpackLoader.application_js_path}\"></script>"
|
14
|
+
end
|
11
15
|
end
|
12
16
|
end
|
data/lib/opal-webpack-loader.rb
CHANGED
@@ -3,28 +3,28 @@ require 'opal-webpack-loader/version'
|
|
3
3
|
require 'opal-webpack-loader/manifest'
|
4
4
|
|
5
5
|
module OpalWebpackLoader
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
6
|
+
class << self
|
7
|
+
attr_accessor :client_asset_path
|
8
|
+
attr_accessor :manifest_path
|
9
|
+
attr_accessor :use_manifest
|
10
|
+
|
11
|
+
def application_js_path
|
12
|
+
if OpalWebpackLoader.use_manifest
|
13
|
+
asset_path = OpalWebpackLoader::Manifest.lookup_path_for("application.js")
|
14
|
+
"OpalWebpackLoader.client_asset_path}#{asset_path}"
|
15
|
+
else
|
16
|
+
"#{OpalWebpackLoader.client_asset_path}application.js"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def application_ssr_js_path
|
21
|
+
if OpalWebpackLoader.use_manifest
|
22
|
+
asset_path = OpalWebpackLoader::Manifest.lookup_path_for("application_ssr.js")
|
23
|
+
"OpalWebpackLoader.client_asset_path}#{asset_path}"
|
24
|
+
else
|
25
|
+
"#{OpalWebpackLoader.client_asset_path}application_ssr.js"
|
26
|
+
end
|
27
|
+
end
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
@@ -38,18 +38,20 @@ OpalWebpackLoader.manifest_path = File.join(Dir.getwd, 'public', 'assets', 'mani
|
|
38
38
|
OpalWebpackLoader.client_asset_path = 'http://localhost:3035/assets/'
|
39
39
|
OpalWebpackLoader.use_manifest = false
|
40
40
|
|
41
|
+
# TODO require yarn instead of npm
|
42
|
+
# TODO don't depend on which for non unixes
|
41
43
|
npm = `which npm`.chop
|
42
44
|
|
43
45
|
if npm != ''
|
44
46
|
bin_dir = `npm bin`.chop
|
45
47
|
begin
|
46
|
-
owl_npm_version = `#{bin_dir
|
48
|
+
owl_npm_version = `#{File.join(bin_dir, 'opal-webpack-loader-npm-version')}`.chop
|
47
49
|
rescue
|
48
50
|
owl_npm_version = nil
|
49
51
|
end
|
50
52
|
|
51
53
|
if owl_npm_version != OpalWebpackLoader::VERSION
|
52
|
-
|
54
|
+
STDERR.puts "opal-webpack-loader: Incorrect version of npm package found or npm package not installed.\n" +
|
53
55
|
"Please install the npm package for opal-webpack-loader:\n" +
|
54
56
|
"\twith npm:\tnpm install opal-webpack-loader@#{OpalWebpackLoader::VERSION} --save-dev\n" +
|
55
57
|
"\tor with yarn:\tyarn add opal-webpack-loader@#{OpalWebpackLoader::VERSION} --dev\n"
|
@@ -0,0 +1,8 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
if ENV['FLATTERING_ENV'] && ENV['FLATTERING_ENV'] == 'test'
|
3
|
+
Bundler.require(:default, :test)
|
4
|
+
elsif ENV['FLATTERING_ENV'] && ENV['FLATTERING_ENV'] == 'production'
|
5
|
+
Bundler.require(:default, :production)
|
6
|
+
else
|
7
|
+
Bundler.require(:default, :development)
|
8
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require './app_loader.rb'
|
2
|
+
|
3
|
+
class App < Roda
|
4
|
+
|
5
|
+
|
6
|
+
route do |r|
|
7
|
+
r.root do
|
8
|
+
<<~HTML
|
9
|
+
<html>
|
10
|
+
<head>
|
11
|
+
<title>Welcome</title>
|
12
|
+
</head>
|
13
|
+
<body>
|
14
|
+
<div>Hello world!</div>
|
15
|
+
</body>
|
16
|
+
</html>
|
17
|
+
HTML
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
run App.app
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe 'owl installer' do
|
4
|
+
context 'structure: :app' do
|
5
|
+
before do
|
6
|
+
Dir.chdir('spec')
|
7
|
+
Dir.chdir('test_apps')
|
8
|
+
FileUtils.rm_rf('railing') if Dir.exist?('railing')
|
9
|
+
end
|
10
|
+
|
11
|
+
after do
|
12
|
+
Dir.chdir('..') if Dir.pwd.end_with?('railing')
|
13
|
+
FileUtils.rm_rf('railing') if Dir.exist?('railing')
|
14
|
+
Dir.chdir('..')
|
15
|
+
Dir.chdir('..')
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'can install in a rails app without sprockets and webpacker gem' do
|
19
|
+
`bundle exec rails new railing --skip-git --skip-bundle --skip-sprockets --skip-spring --skip-bootsnap`
|
20
|
+
expect(Dir.exist?('railing')).to be true
|
21
|
+
Dir.chdir('railing')
|
22
|
+
arg_val = %w[rails]
|
23
|
+
expect(Dir.exist?(File.join('railing', 'config', 'webpack'))).to be false
|
24
|
+
OpalWebpackLoader::Installer::CLI.start(arg_val)
|
25
|
+
|
26
|
+
expect(File.exist?(File.join('app', 'assets', 'javascripts', 'application.js'))).to be true
|
27
|
+
expect(File.exist?(File.join('app', 'assets', 'javascripts', 'application.js_owl_new'))).to be true
|
28
|
+
expect(File.exist?(File.join('app', 'assets', 'javascripts', 'application_common.js'))).to be true
|
29
|
+
expect(File.exist?(File.join('app', 'assets', 'javascripts', 'application_debug.js'))).to be true
|
30
|
+
expect(File.exist?(File.join('app', 'assets', 'javascripts', 'application_ssr.js'))).to be true
|
31
|
+
expect(File.exist?(File.join('app', 'opal', 'opal_loader.rb'))).to be true
|
32
|
+
expect(File.exist?(File.join('config', 'initializers', 'opal_webpack_loader.rb'))).to be true
|
33
|
+
expect(File.exist?(File.join('config', 'webpack', 'debug.js'))).to be true
|
34
|
+
expect(File.exist?(File.join('config', 'webpack', 'development.js'))).to be true
|
35
|
+
expect(File.exist?(File.join('config', 'webpack', 'production.js'))).to be true
|
36
|
+
expect(File.exist?('package.json')).to be true
|
37
|
+
expect(File.exist?('Procfile')).to be true
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'can install in a rails app without sprockets and webpacker gem specifying another opal files dir' do
|
41
|
+
`bundle exec rails new railing --skip-git --skip-bundle --skip-sprockets --skip-spring --skip-bootsnap`
|
42
|
+
expect(Dir.exist?('railing')).to be true
|
43
|
+
Dir.chdir('railing')
|
44
|
+
arg_val = %w[rails -o hyperhyper]
|
45
|
+
expect(Dir.exist?(File.join('railing', 'config', 'webpack'))).to be false
|
46
|
+
OpalWebpackLoader::Installer::CLI.start(arg_val)
|
47
|
+
|
48
|
+
expect(File.exist?(File.join('app', 'assets', 'javascripts', 'application.js'))).to be true
|
49
|
+
expect(File.exist?(File.join('app', 'assets', 'javascripts', 'application.js_owl_new'))).to be true
|
50
|
+
expect(File.exist?(File.join('app', 'assets', 'javascripts', 'application_common.js'))).to be true
|
51
|
+
expect(File.exist?(File.join('app', 'assets', 'javascripts', 'application_debug.js'))).to be true
|
52
|
+
expect(File.exist?(File.join('app', 'assets', 'javascripts', 'application_ssr.js'))).to be true
|
53
|
+
expect(File.exist?(File.join('app', 'hyperhyper', 'hyperhyper_loader.rb'))).to be true
|
54
|
+
expect(File.exist?(File.join('config', 'initializers', 'opal_webpack_loader.rb'))).to be true
|
55
|
+
expect(File.exist?(File.join('config', 'webpack', 'debug.js'))).to be true
|
56
|
+
expect(File.exist?(File.join('config', 'webpack', 'development.js'))).to be true
|
57
|
+
expect(File.exist?(File.join('config', 'webpack', 'production.js'))).to be true
|
58
|
+
expect(File.exist?('package.json')).to be true
|
59
|
+
expect(File.exist?('Procfile')).to be true
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'structure: :flat' do
|
64
|
+
before do
|
65
|
+
Dir.chdir('spec')
|
66
|
+
Dir.chdir('test_apps')
|
67
|
+
FileUtils.rm_rf('flattering') if Dir.exist?('flattering')
|
68
|
+
end
|
69
|
+
|
70
|
+
after do
|
71
|
+
Dir.chdir('..') if Dir.pwd.end_with?('flattering')
|
72
|
+
FileUtils.rm_rf('flattering') if Dir.exist?('flattering')
|
73
|
+
Dir.chdir('..')
|
74
|
+
Dir.chdir('..')
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'can install in a roda app' do
|
78
|
+
FileUtils.cp_r(File.join('..', 'fixtures', 'flattering'), File.join('.'))
|
79
|
+
expect(Dir.exist?('flattering')).to be true
|
80
|
+
Dir.chdir('flattering')
|
81
|
+
arg_val = %w[flat]
|
82
|
+
OpalWebpackLoader::Installer::CLI.start(arg_val)
|
83
|
+
expect(File.exist?(File.join('javascripts', 'application.js'))).to be true
|
84
|
+
expect(File.exist?(File.join('javascripts', 'application_common.js'))).to be true
|
85
|
+
expect(File.exist?(File.join('javascripts', 'application_debug.js'))).to be true
|
86
|
+
expect(File.exist?(File.join('javascripts', 'application_ssr.js'))).to be true
|
87
|
+
expect(File.exist?(File.join('opal', 'opal_loader.rb'))).to be true
|
88
|
+
expect(File.exist?(File.join('owl_init.rb'))).to be true
|
89
|
+
expect(File.exist?(File.join('webpack', 'debug.js'))).to be true
|
90
|
+
expect(File.exist?(File.join('webpack', 'development.js'))).to be true
|
91
|
+
expect(File.exist?(File.join('webpack', 'production.js'))).to be true
|
92
|
+
expect(File.exist?('package.json')).to be true
|
93
|
+
expect(File.exist?('Procfile')).to be true
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
data/spec/owl_spec.rb
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe 'owl' do
|
4
|
+
context 'in a rails app' do
|
5
|
+
before do
|
6
|
+
Dir.chdir('spec')
|
7
|
+
Dir.chdir('test_apps')
|
8
|
+
FileUtils.rm_rf('railing') if Dir.exist?('railing')
|
9
|
+
end
|
10
|
+
|
11
|
+
after do
|
12
|
+
Dir.chdir('..') if Dir.pwd.end_with?('railing')
|
13
|
+
FileUtils.rm_rf('railing') if Dir.exist?('railing')
|
14
|
+
Dir.chdir('..')
|
15
|
+
Dir.chdir('..')
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'can run the production build script' do
|
19
|
+
`bundle exec rails new railing --skip-git --skip-bundle --skip-sprockets --skip-spring --skip-bootsnap`
|
20
|
+
expect(Dir.exist?('railing')).to be true
|
21
|
+
Dir.chdir('railing')
|
22
|
+
arg_val = %w[rails]
|
23
|
+
expect(Dir.exist?(File.join('railing', 'config', 'webpack'))).to be false
|
24
|
+
OpalWebpackLoader::Installer::CLI.start(arg_val)
|
25
|
+
FileUtils.mv(File.join('app', 'assets', 'javascripts', 'application.js_owl_new'), File.join('app', 'assets', 'javascripts', 'application.js´'))
|
26
|
+
gemfile = File.read('Gemfile')
|
27
|
+
gemfile << <<~GEMS
|
28
|
+
|
29
|
+
gem 'opal', github: 'janbiedermann/opal', branch: 'es6_import_export'
|
30
|
+
gem 'opal-webpack-loader', path: '#{File.realpath(File.join('..','..', '..', '..', 'opal-webpack-loader'))}'
|
31
|
+
|
32
|
+
GEMS
|
33
|
+
File.write('Gemfile', gemfile)
|
34
|
+
`yarn install`
|
35
|
+
# bundler set some environment things, but we need a clean environment, so things don't get mixed up, use env
|
36
|
+
`env -i PATH="#{ENV['PATH']}" bundle install`
|
37
|
+
expect(File.exist?('Gemfile.lock')).to be true
|
38
|
+
`env -i PATH="#{ENV['PATH']}" yarn run production_build`
|
39
|
+
expect(File.exist?(File.join('public', 'assets', 'manifest.json'))).to be true
|
40
|
+
manifest = Oj.load(File.read(File.join('public', 'assets', 'manifest.json')), mode: :strict)
|
41
|
+
application_js = manifest['application.js']
|
42
|
+
expect(File.exist?(File.join('public', application_js))).to be true
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context 'in a roda app' do
|
47
|
+
before do
|
48
|
+
Dir.chdir('spec')
|
49
|
+
Dir.chdir('test_apps')
|
50
|
+
FileUtils.rm_rf('flattering') if Dir.exist?('flattering')
|
51
|
+
end
|
52
|
+
|
53
|
+
after do
|
54
|
+
Dir.chdir('..') if Dir.pwd.end_with?('flattering')
|
55
|
+
FileUtils.rm_rf('flattering') if Dir.exist?('flattering')
|
56
|
+
Dir.chdir('..')
|
57
|
+
Dir.chdir('..')
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'can install in a roda app' do
|
61
|
+
FileUtils.cp_r(File.join('..', 'fixtures', 'flattering'), File.join('.'))
|
62
|
+
expect(Dir.exist?('flattering')).to be true
|
63
|
+
Dir.chdir('flattering')
|
64
|
+
arg_val = %w[flat]
|
65
|
+
OpalWebpackLoader::Installer::CLI.start(arg_val)
|
66
|
+
|
67
|
+
gemfile = File.read('Gemfile')
|
68
|
+
gemfile << <<~GEMS
|
69
|
+
|
70
|
+
gem 'opal', github: 'janbiedermann/opal', branch: 'es6_import_export'
|
71
|
+
gem 'opal-webpack-loader', path: '#{File.realpath(File.join('..','..', '..', '..', 'opal-webpack-loader'))}'
|
72
|
+
|
73
|
+
GEMS
|
74
|
+
File.write('Gemfile', gemfile)
|
75
|
+
`yarn install`
|
76
|
+
# bundler set some environment things, but we need a clean environment, so things don't get mixed up, use env
|
77
|
+
`env -i PATH="#{ENV['PATH']}" bundle install`
|
78
|
+
expect(File.exist?('Gemfile.lock')).to be true
|
79
|
+
`env -i PATH="#{ENV['PATH']}" yarn run production_build`
|
80
|
+
expect(File.exist?(File.join('public', 'assets', 'manifest.json'))).to be true
|
81
|
+
manifest = Oj.load(File.read(File.join('public', 'assets', 'manifest.json')), mode: :strict)
|
82
|
+
application_js = manifest['application.js']
|
83
|
+
expect(File.exist?(File.join('public', application_js))).to be true
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'oj'
|
3
|
+
require 'thor'
|
4
|
+
require_relative '../lib/opal-webpack-loader/installer_cli'
|
5
|
+
|
6
|
+
RSpec.configure do |config|
|
7
|
+
config.expect_with :rspec do |expectations|
|
8
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
9
|
+
end
|
10
|
+
|
11
|
+
config.mock_with :rspec do |mocks|
|
12
|
+
mocks.verify_partial_doubles = true
|
13
|
+
end
|
14
|
+
|
15
|
+
config.shared_context_metadata_behavior = :apply_to_host_groups
|
16
|
+
end
|