simpacker 1.0.0 → 1.1.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e23b7c5891f8dd786aeb87c9ffe96ffb523869165a2e7ba3f6092530f6fe555c
4
- data.tar.gz: f9c22f0d68c5642f2f8fcb7cad20811aba7a792a0f3d461da1ee177400ffee4d
3
+ metadata.gz: 91a0259d16d447c35740fe2261d8666a3f014da6e469c64cae1922465351c05f
4
+ data.tar.gz: f16ac990f0e689751069256b909afa54e41688638bfbefd5cd409b1ed6dddab9
5
5
  SHA512:
6
- metadata.gz: 84e25b65c83b399fb97fbb586d4f6bf324eeef0a93e7524a0eed978498b0f435ac56e4e3a4c16e85206f55379cd51ae685d9aa74b293840dedeb65f3b08a8e82
7
- data.tar.gz: 7e20cd2635db6e5afeabd72c98f6a3b613236f00032be79df011fe59f771c53b2441304607f154e9bba7607322c9aa87dd4f1cd337fa09fa6241c2364e557287
6
+ metadata.gz: 7f41ace4633df97ef72573dd524b3b47f9d9784b0f81db0ec19d76c5c21c4e86ae6ac0dbce60b36043fa6d346187fe6ccadd9216e5168150f603c501025db69a
7
+ data.tar.gz: 321c5eb359a553499b29272ee2067ae8ff663bf46e4171480435b65630342803c7fec06483bbaed556a610bb969efc42e9b203b7fbaa695fa96c3c542ec03a95
data/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ ## v1.1.0
2
+
3
+ - Allow `Manifest#lookup` to access nested fields.
4
+ - Drop TypeScript from default installer.
5
+ - Improve error handling.
6
+
7
+ ## v1.0.0
8
+
9
+ - Initial release
data/README.md CHANGED
@@ -41,9 +41,11 @@ $ ./node_modules/.bin/wabpack --watch
41
41
  - Webpack settings
42
42
  - [webpack-dev-server](https://github.com/hokaccha/simpacker/tree/master/example/webpack-dev-server)
43
43
  - [Multiple Entry Point](https://github.com/hokaccha/simpacker/tree/master/example/multiple-entry-points)
44
- - Languages
44
+ - Transpilers
45
45
  - [TypeScript](https://github.com/hokaccha/simpacker/tree/master/example/typescript)
46
46
  - [Babel](https://github.com/hokaccha/simpacker/tree/master/example/babel)
47
+ - Style Sheets
48
+ - [CSS](https://github.com/hokaccha/simpacker/tree/master/example/css)
47
49
  - [Sass](https://github.com/hokaccha/simpacker/tree/master/example/sass)
48
50
  - Frameworks
49
51
  - [React](https://github.com/hokaccha/simpacker/tree/master/example/react)
@@ -53,8 +55,10 @@ $ ./node_modules/.bin/wabpack --watch
53
55
  - [CDN](https://github.com/hokaccha/simpacker/tree/master/example/asset-host)
54
56
  - [Heroku](https://github.com/hokaccha/simpacker/tree/master/example/heroku)
55
57
  - [Docker](https://github.com/hokaccha/simpacker/tree/master/example/docker)
56
- - Others
58
+ - Advanced settings
57
59
  - [Rails Engines](https://github.com/hokaccha/simpacker/tree/master/example/engines)
60
+ - [Custom helper](https://github.com/hokaccha/simpacker/tree/master/example/custom-helper)
61
+ - Bundler
58
62
  - [Parcel](https://github.com/hokaccha/simpacker/tree/master/example/parcel)
59
63
 
60
64
  ## VS. Webpacker
@@ -0,0 +1,3 @@
1
+ export function hello(name) {
2
+ return `Hello ${name}!`;
3
+ }
@@ -8,7 +8,7 @@ module.exports = {
8
8
  mode: isProd ? "production" : "development",
9
9
  devtool: "source-map",
10
10
  entry: {
11
- application: path.resolve(__dirname, "app/javascript/application.ts")
11
+ application: path.resolve(__dirname, "app/javascript/application.js")
12
12
  },
13
13
  output: {
14
14
  path: path.resolve(__dirname, "public/packs"),
@@ -16,18 +16,7 @@ module.exports = {
16
16
  filename: isProd ? "[name]-[hash].js" : "[name].js"
17
17
  },
18
18
  resolve: {
19
- extensions: [".js", ".ts"]
20
- },
21
- module: {
22
- rules: [
23
- {
24
- test: /\.tsx?$/,
25
- loader: "ts-loader",
26
- options: {
27
- transpileOnly: true
28
- }
29
- }
30
- ]
19
+ extensions: [".js"]
31
20
  },
32
21
  plugins: [new WebpackAssetsManifest({ publicPath: true })]
33
22
  };
@@ -1,7 +1,6 @@
1
1
  puts "Copying config files"
2
2
  copy_file "#{__dir__}/config/simpacker.yml", "config/simpacker.yml"
3
3
  copy_file "#{__dir__}/root/webpack.config.js", "webpack.config.js"
4
- copy_file "#{__dir__}/root/tsconfig.json", "tsconfig.json"
5
4
 
6
5
  unless File.exist?('package.json')
7
6
  copy_file "#{__dir__}/root/package.json", "package.json"
@@ -24,8 +23,6 @@ dep_packages = %w(
24
23
  webpack
25
24
  webpack-cli
26
25
  webpack-assets-manifest
27
- typescript
28
- ts-loader
29
26
  ).join(' ')
30
27
 
31
28
  say "Installing npm packages"
@@ -1,39 +1,14 @@
1
- require "yaml"
2
-
3
1
  module Simpacker
4
2
  class Configuration
5
- attr_accessor :root_path, :config_path, :env
6
-
7
- def initialize(root_path:)
8
- @root_path = root_path
9
- @config_path = @root_path.join("config/simpacker.yml")
10
- @env = Rails.env
11
- end
3
+ attr_accessor :manifest_path, :cache_manifest
12
4
 
13
- def manifest_path
14
- root_path.join(data.fetch("manifest_path"))
5
+ def initialize(manifest_path:, cache_manifest: true)
6
+ @manifest_path = manifest_path
7
+ @cache_manifest = cache_manifest
15
8
  end
16
9
 
17
10
  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}"
11
+ !!cache_manifest
37
12
  end
38
13
  end
39
14
  end
@@ -1,10 +1,33 @@
1
+ require "yaml"
2
+
1
3
  module Simpacker
2
4
  class Context
5
+ class InvalidConfigurationError < StandardError; end
6
+
3
7
  attr_reader :config, :manifest
4
8
 
5
- def initialize(root_path: Rails.root)
6
- @config = Simpacker::Configuration.new(root_path: root_path)
7
- @manifest = Simpacker::Manifest.new(self)
9
+ def initialize(root_path: Rails.root, env: Rails.env)
10
+ config = load_config_file(root_path, env)
11
+ @config = Simpacker::Configuration.new(config)
12
+ @manifest = Simpacker::Manifest.new(@config)
13
+ end
14
+
15
+ private
16
+
17
+ def load_config_file(root_path, env)
18
+ config_path = root_path.join("config/simpacker.yml")
19
+ yaml = YAML.load(config_path.read)
20
+ config_env = yaml.fetch(env.to_s)
21
+ {
22
+ manifest_path: root_path.join(config_env.fetch('manifest_path')),
23
+ cache_manifest: config_env.fetch('cache_manifest'),
24
+ }
25
+ rescue Errno::ENOENT
26
+ raise Simpacker::Context::InvalidConfigurationError, "Simpacker configuration file not found #{config_path}"
27
+ rescue KeyError => err
28
+ raise Simpacker::Context::InvalidConfigurationError, "Missing field: `#{err.key}` in #{config_path}"
29
+ rescue Psych::SyntaxError => err
30
+ raise Simpacker::Context::InvalidConfigurationError, "YAML syntax error occurred while parsing #{config_path}. Error: #{err.message}"
8
31
  end
9
32
  end
10
33
  end
@@ -1,29 +1,30 @@
1
1
  module Simpacker
2
2
  class Manifest
3
3
  class MissingEntryError < StandardError; end
4
+ class MissingFileError < StandardError; end
4
5
 
5
- attr_reader :context
6
+ attr_reader :config
6
7
 
7
- def initialize(context)
8
- @context = context
8
+ def initialize(config)
9
+ @config = config
9
10
  end
10
11
 
11
- def lookup(name)
12
- data[name.to_s].presence
12
+ def lookup(*names)
13
+ data.dig(*names.map(&:to_s))
13
14
  end
14
15
 
15
- def lookup!(name)
16
- lookup(name) || handle_missing_entry(name)
16
+ def lookup!(*names)
17
+ lookup(*names) || handle_missing_entry(names)
17
18
  end
18
19
 
19
20
  private
20
21
 
21
- def handle_missing_entry(name)
22
- raise Simpacker::Manifest::MissingEntryError
22
+ def handle_missing_entry(names)
23
+ raise Simpacker::Manifest::MissingEntryError, "Missing field: #{names.join('.')}"
23
24
  end
24
25
 
25
26
  def data
26
- if context.config.cache_manifest?
27
+ if config.cache_manifest?
27
28
  @data ||= load
28
29
  else
29
30
  load
@@ -31,10 +32,10 @@ module Simpacker
31
32
  end
32
33
 
33
34
  def load
34
- if context.config.manifest_path.exist?
35
- JSON.parse(context.config.manifest_path.read)
35
+ if config.manifest_path.exist? && config.manifest_path.file?
36
+ JSON.parse(config.manifest_path.read)
36
37
  else
37
- {}
38
+ raise Simpacker::Manifest::MissingFileError, "Missing manifest file: #{config.manifest_path}"
38
39
  end
39
40
  end
40
41
  end
@@ -1,3 +1,3 @@
1
1
  module Simpacker
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simpacker
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kazuhito Hokamura
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-07-02 00:00:00.000000000 Z
11
+ date: 2019-07-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -89,16 +89,16 @@ extra_rdoc_files: []
89
89
  files:
90
90
  - ".gitignore"
91
91
  - ".travis.yml"
92
+ - CHANGELOG.md
92
93
  - Gemfile
93
94
  - README.md
94
95
  - Rakefile
95
96
  - bin/console
96
97
  - bin/setup
97
98
  - lib/install/config/simpacker.yml
98
- - lib/install/javascript/application.ts
99
- - lib/install/javascript/greeter.ts
99
+ - lib/install/javascript/application.js
100
+ - lib/install/javascript/greeter.js
100
101
  - lib/install/root/package.json
101
- - lib/install/root/tsconfig.json
102
102
  - lib/install/root/webpack.config.js
103
103
  - lib/install/template.rb
104
104
  - lib/simpacker.rb
@@ -1,3 +0,0 @@
1
- export function hello(name: string): string {
2
- return `Hello ${name}!`;
3
- }
@@ -1,18 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "es5",
4
- "lib": ["es2019", "dom", "dom.iterable"],
5
- "module": "es2015",
6
- "moduleResolution": "node",
7
- "esModuleInterop": true,
8
- "downlevelIteration": true,
9
- "sourceMap": true,
10
- "removeComments": false,
11
- "noImplicitAny": false,
12
- "strictNullChecks": true,
13
- "strictFunctionTypes": true,
14
- "strictBindCallApply": true,
15
- "strictPropertyInitialization": true,
16
- "noImplicitThis": true
17
- }
18
- }