simpacker 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4ac94b7ca7ff8dd46cde4e074b7f273037999f0b533703f89adc067b7786897b
4
+ data.tar.gz: 93173bafc209891df117fa2a8758f1d52e6be59c5d3c1e3d6a5b3813bc83b166
5
+ SHA512:
6
+ metadata.gz: 2674d3dfeaa7e01f431d387acd370e0830b0ed1d443f60042c7884d698f98946d3a0b5b6f98c2a8b868628f9e6d176d0741b867e1b931c8ee07118a225f84efc
7
+ data.tar.gz: 7df76f3b8759c38f350ab1371c53f1d521f50de3598c85613191c2a714454088e7dd7b88bc3abdb89ee3c1bb914f78779ac32c56bd97a51d9658a0e25f564ce9
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in simpacker.gemspec
6
+ gemspec
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # Simpacker
2
+
3
+ Yet another [webpacker](https://github.com/rails/webpacker).
4
+
5
+ ## Installation
6
+
7
+ Create a new rails application without webpacker.
8
+
9
+ ```
10
+ $ rails new myapp
11
+ ```
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'simpacker'
17
+ ```
18
+
19
+ Run the following to install Simpacker:
20
+
21
+ ```
22
+ $ rails simpacker:install
23
+ ```
24
+
25
+ Run the folloing command to build JavaScript and watch files.
26
+
27
+ ```
28
+ $ npx webpack --watch
29
+ ```
30
+
31
+ ## Usage
32
+
33
+ You can use `javascript_pack_tag` in view.
34
+
35
+ ```erb
36
+ <%= javascript_pack_tag 'application' %>
37
+ ```
38
+
39
+ ## Contributing
40
+
41
+ Bug reports and pull requests are welcome on GitHub at https://github.com/hokaccha/simpacker.
42
+
43
+ ## License
44
+
45
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "simpacker"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,14 @@
1
+ default: &default
2
+ manifest_path: public/packs/manifest.json
3
+
4
+ development:
5
+ <<: *default
6
+ cache_manifest: false
7
+
8
+ test:
9
+ <<: *default
10
+ cache_manifest: false
11
+
12
+ production:
13
+ <<: *default
14
+ cache_manifest: true
@@ -0,0 +1,3 @@
1
+ import { hello } from "~/greeter";
2
+
3
+ hello("Rails");
@@ -0,0 +1,3 @@
1
+ export function hello(name: string): void {
2
+ console.log(`Hello ${name}!`);
3
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "private": true
3
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "es5",
4
+ "lib": ["dom", "es2015"],
5
+ "module": "es2015",
6
+ "moduleResolution": "node",
7
+ "sourceMap": true,
8
+ "esModuleInterop": true,
9
+ "baseUrl": ".",
10
+ "paths": {
11
+ "~/*": ["./app/javascript/src"]
12
+ }
13
+ }
14
+ }
@@ -0,0 +1,37 @@
1
+ const path = require("path");
2
+ const WebpackAssetsManifest = require("webpack-assets-manifest");
3
+
4
+ const { NODE_ENV } = process.env;
5
+ const isProd = NODE_ENV === "production";
6
+
7
+ module.exports = {
8
+ mode: isProd ? "production" : "development",
9
+ devtool: "source-map",
10
+ entry: {
11
+ application: path.resolve(__dirname, "app/javascript/packs/application.ts")
12
+ },
13
+ output: {
14
+ path: path.resolve(__dirname, "public/packs"),
15
+ publicPath: "/packs/",
16
+ filename: isProd ? "[name]-[hash].js" : "[name].js",
17
+ chunkFilename: "[id]-[chunkhash].js"
18
+ },
19
+ resolve: {
20
+ extensions: [".tsx", ".ts", ".js"],
21
+ alias: {
22
+ "~": path.resolve(__dirname, "app/javascript/src")
23
+ }
24
+ },
25
+ module: {
26
+ rules: [
27
+ {
28
+ test: /\.tsx?$/,
29
+ loader: "ts-loader",
30
+ options: {
31
+ transpileOnly: true
32
+ }
33
+ }
34
+ ]
35
+ },
36
+ plugins: [new WebpackAssetsManifest({ publicPath: true })]
37
+ };
@@ -0,0 +1,28 @@
1
+ puts "Copying config files"
2
+ copy_file "#{__dir__}/config/simpacker.yml", "config/simpacker.yml"
3
+ copy_file "#{__dir__}/root/webpack.config.js", "webpack.config.js"
4
+ copy_file "#{__dir__}/root/tsconfig.json", "tsconfig.json"
5
+
6
+ unless File.exist?('package.json')
7
+ copy_file "#{__dir__}/root/package.json", "package.json"
8
+ end
9
+
10
+ if Dir.exist?('app/javascript')
11
+ say "The JavaScript app source directory already exists"
12
+ else
13
+ say "Creating JavaScript app source directory"
14
+ directory "#{__dir__}/javascript", 'app/javascript'
15
+ end
16
+
17
+ dep_packages = %w(
18
+ webpack
19
+ webpack-cli
20
+ webpack-assets-manifest
21
+ typescript
22
+ ts-loader
23
+ ).join(' ')
24
+
25
+ say "Installing npm packages"
26
+ run "npm install --save-dev #{dep_packages}"
27
+
28
+ say "Simpacker successfully installed 🎉 🍰", :green
@@ -0,0 +1,39 @@
1
+ require "yaml"
2
+
3
+ module Simpacker
4
+ class Configuration
5
+ attr_accessor :root_path, :config_path, :env
6
+
7
+ def initialize
8
+ @root_path = Rails.root
9
+ @config_path = @root_path.join("config/simpacker.yml")
10
+ @env = Rails.env
11
+ end
12
+
13
+ def manifest_path
14
+ root_path.join(data.fetch("manifest_path"))
15
+ end
16
+
17
+ def cache_manifest?
18
+ data.fetch("cache_manifest")
19
+ end
20
+
21
+ private
22
+
23
+ def data
24
+ @data ||= load
25
+ end
26
+
27
+ def load
28
+ YAML.load(config_path.read)[env]
29
+ rescue Errno::ENOENT => e
30
+ raise "Simpacker configuration file not found #{config_path}. " \
31
+ "Please run rails simpacker:install " \
32
+ "Error: #{e.message}"
33
+ rescue Psych::SyntaxError => e
34
+ raise "YAML syntax error occurred while parsing #{config_path}. " \
35
+ "Please note that YAML must be consistently indented using spaces. Tabs are not allowed. " \
36
+ "Error: #{e.message}"
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,29 @@
1
+ module Simpacker
2
+ module Helper
3
+ def javascript_pack_tag(*names, **options)
4
+ sources = names.map do |name|
5
+ Simpacker.manifest.lookup!("#{name}#{compute_asset_extname(name, type: :javascript)}")
6
+ end
7
+ javascript_include_tag(*sources, **options)
8
+ end
9
+
10
+ def stylesheet_pack_tag(*names, **options)
11
+ sources = names.map do |name|
12
+ Simpacker.manifest.lookup!("#{name}#{compute_asset_extname(name, type: :stylesheet)}")
13
+ end
14
+ stylesheet_link_tag(*sources, **options)
15
+ end
16
+
17
+ def asset_pack_path(name, **options)
18
+ asset_path(Simpacker.manifest.lookup!(name), **options)
19
+ end
20
+
21
+ def asset_pack_url(name, **options)
22
+ asset_url(Simpacker.manifest.lookup!(name), **options)
23
+ end
24
+
25
+ def image_pack_tag(name, **options)
26
+ image_tag(asset_path(Simpacker.manifest.lookup!(name)), **options)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,41 @@
1
+ module Simpacker
2
+ class Manifest
3
+ class MissingEntryError < StandardError; end
4
+
5
+ attr_reader :config
6
+
7
+ def initialize(config)
8
+ @config = config
9
+ end
10
+
11
+ def lookup(name)
12
+ data[name.to_s].presence
13
+ end
14
+
15
+ def lookup!(name)
16
+ lookup(name) || handle_missing_entry(name)
17
+ end
18
+
19
+ private
20
+
21
+ def handle_missing_entry(name)
22
+ raise Simpacker::Manifest::MissingEntryError
23
+ end
24
+
25
+ def data
26
+ if config.cache_manifest?
27
+ @data ||= load
28
+ else
29
+ load
30
+ end
31
+ end
32
+
33
+ def load
34
+ if config.manifest_path.exist?
35
+ JSON.parse(config.manifest_path.read)
36
+ else
37
+ {}
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,13 @@
1
+ require "rails/railtie"
2
+
3
+ class Simpacker::Engine < ::Rails::Engine
4
+ initializer "simpacker.helper" do
5
+ ActiveSupport.on_load :action_controller do
6
+ ActionController::Base.helper Simpacker::Helper
7
+ end
8
+
9
+ ActiveSupport.on_load :action_view do
10
+ include Simpacker::Helper
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module Simpacker
2
+ VERSION = "0.1.0"
3
+ end
data/lib/simpacker.rb ADDED
@@ -0,0 +1,14 @@
1
+ require "simpacker/configuration"
2
+ require "simpacker/manifest"
3
+ require "simpacker/helper"
4
+ require "simpacker/railtie" if defined?(Rails)
5
+
6
+ module Simpacker
7
+ def self.config
8
+ @config ||= Simpacker::Configuration.new
9
+ end
10
+
11
+ def self.manifest
12
+ @manifest ||= Simpacker::Manifest.new(config)
13
+ end
14
+ end
@@ -0,0 +1,9 @@
1
+ install_template_path = File.expand_path("../install/template.rb", __dir__).freeze
2
+ bin_path = ENV["BUNDLE_BIN"] || "./bin"
3
+
4
+ namespace :simpacker do
5
+ desc "Install Simpacker in this application"
6
+ task :install do
7
+ exec "#{RbConfig.ruby} #{bin_path}/rails app:template LOCATION=#{install_template_path}"
8
+ end
9
+ end
data/simpacker.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "simpacker/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "simpacker"
7
+ spec.version = Simpacker::VERSION
8
+ spec.authors = ["Kazuhito Hokamura"]
9
+ spec.email = ["k.hokamura@gmail.com"]
10
+
11
+ spec.summary = "Integrate modern JavaScript build system with Rails."
12
+ spec.description = "Integrate modern JavaScript build system with Rails."
13
+ spec.homepage = "https://github.com/hokaccha/simpacker"
14
+ spec.license = 'MIT'
15
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
16
+ f.match(%r{^(test|spec|features|examples)/})
17
+ end
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "railties", ">= 4.2"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.16"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ end
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simpacker
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kazuhito Hokamura
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-06-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: railties
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '4.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '4.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.16'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.16'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: Integrate modern JavaScript build system with Rails.
56
+ email:
57
+ - k.hokamura@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - README.md
65
+ - Rakefile
66
+ - bin/console
67
+ - bin/setup
68
+ - lib/install/config/simpacker.yml
69
+ - lib/install/javascript/packs/application.ts
70
+ - lib/install/javascript/src/greeter.ts
71
+ - lib/install/root/package.json
72
+ - lib/install/root/tsconfig.json
73
+ - lib/install/root/webpack.config.js
74
+ - lib/install/template.rb
75
+ - lib/simpacker.rb
76
+ - lib/simpacker/configuration.rb
77
+ - lib/simpacker/helper.rb
78
+ - lib/simpacker/manifest.rb
79
+ - lib/simpacker/railtie.rb
80
+ - lib/simpacker/version.rb
81
+ - lib/tasks/simpacker.rake
82
+ - simpacker.gemspec
83
+ homepage: https://github.com/hokaccha/simpacker
84
+ licenses:
85
+ - MIT
86
+ metadata: {}
87
+ post_install_message:
88
+ rdoc_options: []
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubygems_version: 3.0.3
103
+ signing_key:
104
+ specification_version: 4
105
+ summary: Integrate modern JavaScript build system with Rails.
106
+ test_files: []