sewing_kit 0.114.2 → 0.125.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0134a2424e936702521db2dcbc10e900862ca6720e459fffabf0309d4d4823c3
4
- data.tar.gz: b72bed1c690ada5e98756632634c0eb7988351c933ff9c5f26a33984f107c0d1
3
+ metadata.gz: 564314c05cfa0473a306cf5fbb6564a6e1761705009aa0e1db2510a0133ab3ff
4
+ data.tar.gz: 50694443b9a1ef590f2968186864bdaedca0c0537fedde76be889a1297ff7770
5
5
  SHA512:
6
- metadata.gz: 1f68e6f089f390d7f615d5d11d4bfda4884430ce4f6d79510e083089cfd9e7e26c82bad02e35da42a68ebaabad41cd2ea2342ec432745368f772ca92bc6b2cb8
7
- data.tar.gz: 3bef3f7fa71412e2cda8768e0f1c65137798fe0c729c664ccc7f9343d053955b8625e4a6f4d3f562e0f2f3acf792cbba3774ca7233a3515df7a0c37f73188776
6
+ metadata.gz: 67d879b2d836ed5a77e71e7950c9179451b644fc65140265efb28c179d576d153584da2b9f7d28809a8cdfe45ff910a2cf8aa58502063ae2fabf34a0e9a63209
7
+ data.tar.gz: d8bef03cd01d4b708a8dd956769c8a42cd008c41f5d9dbf3a7275cb6ed0eb351a2ac8ce1b87b8c2895df06916b1720a81b2364fbfcb07f6a21f3ba2f50f58541
data/README.md CHANGED
@@ -19,6 +19,12 @@ yarn
19
19
  dev up
20
20
  ```
21
21
 
22
+ ### Run generator
23
+
24
+ `rails generate sewing_kit:install`
25
+
26
+ will generate a package.json file with common sewing-kit script tasks, default lint, format configuration; a sewing-kit configuration file, and other project default configurations.
27
+
22
28
  ### Add JavaScript
23
29
 
24
30
  sewing_kit looks for JavaScript in `app/ui/index.js`. The code in `index.js` (and any imported JS/CSS) will be built into a `main` bundle.
@@ -146,7 +152,7 @@ If sewing-kit makes a breaking change, this gem's minor version will be bumped t
146
152
 
147
153
  By moving everything into `package.json#dependencies`. This is necessary because Rails 5.2 prunes `devDependencies` during asset compilation.
148
154
 
149
- ### How can I test a production verison of my changes?
155
+ ### How can I test a production version of my changes?
150
156
 
151
157
  Ideally, by deploying to a `staging` environment. If that is not possible, a production-like local development experience is available via:
152
158
 
@@ -155,6 +161,9 @@ NODE_ENV=production SK_SIMULATE_PRODUCTION=1 bundle exec rake assets:precompile
155
161
  NODE_ENV=production SK_SIMULATE_PRODUCTION=1 dev run
156
162
  ```
157
163
 
164
+ If your application includes a node server (eg. uses `quilt_rails`), you can run the node server in a separate terminal window with:
165
+ `bin/rails sewing_kit:server:start`
166
+
158
167
  Note:
159
168
 
160
169
  - Code changes will not be automatically recompiled in this state
@@ -176,3 +185,15 @@ SewingKit.configure do |config|
176
185
  config.log_level = :warn # may be `:inherit`, `:debug`, `:info`, `:warn`, or `:error`
177
186
  end
178
187
  ```
188
+
189
+ ### How do I run sewing-kit in debug mode?
190
+
191
+ You can launch sewing-kit in debug mode by setting the `SK_DEBUG` environment flag.
192
+
193
+ ```bash
194
+ $ SK_DEBUG=1 dev run
195
+ ```
196
+
197
+ This runs your rails app with the sewing-kit development server in debug mode. This is useful for when you want to debug sewing-kit from a rails app.
198
+
199
+ Tip: Install the [Node.js V8 --inspector Manager (NiM)](https://chrome.google.com/webstore/detail/nodejs-v8-inspector-manag/gnhhdgbaldcilmgcpfddgdbkhjohddkj?hl=en) Chrome extension. This will launch a chrome debugger automatically for you.
@@ -0,0 +1,5 @@
1
+ Description:
2
+ This generator creates a sewing-kit config file.
3
+
4
+ Example:
5
+ rails generate sewing_kit:install
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SewingKit
4
+ class InstallGenerator < Rails::Generators::Base
5
+ source_root File.expand_path('templates', __dir__)
6
+
7
+ desc "This generator creates a sewing-kit config file."
8
+
9
+ def initialize(args, *options)
10
+ @application_name = Rails.application.class.module_parent.to_s.underscore
11
+ super(args, *options)
12
+ end
13
+
14
+ def create_package_json
15
+ package_json_path = "package.json"
16
+
17
+ copy_file(package_json_path)
18
+ gsub_file(package_json_path, "\${application_name}", @application_name)
19
+ end
20
+
21
+ def install_js_dependencies
22
+ say "Installing react and types dependencies"
23
+ system("yarn add @shopify/sewing-kit") unless Rails.env.test?
24
+ end
25
+
26
+ def create_sk_config
27
+ sk_config_path = "config/sewing-kit.config.ts"
28
+
29
+ copy_file("sewing-kit.config.ts", sk_config_path)
30
+ gsub_file(sk_config_path, "\${application_name}", @application_name)
31
+ end
32
+
33
+ def create_config_files
34
+ copy_file("editorconfig", ".editorconfig")
35
+ copy_file("eslintignore", ".eslintignore")
36
+ copy_file("prettierignore", ".prettierignore")
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,15 @@
1
+ # editorconfig.org
2
+ root = true
3
+
4
+ [*]
5
+ charset = utf-8
6
+ indent_size = 2
7
+ indent_style = space
8
+ insert_final_newline = true
9
+ trim_trailing_whitespace = true
10
+
11
+ # Markdown syntax specifies that trailing whitespaces can be meaningful,
12
+ # so let’s not trim those. e.g. 2 trailing spaces = linebreak (<br />)
13
+ # See https://daringfireball.net/projects/markdown/syntax#p
14
+ [*.md]
15
+ trim_trailing_whitespace = false
@@ -0,0 +1,2 @@
1
+ node_modules
2
+ build
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "${application_name}",
3
+ "private": true,
4
+ "sideEffects": false,
5
+ "scripts": {
6
+ "dev": "sewing-kit dev",
7
+ "check": "sewing-kit check",
8
+ "lint": "sewing-kit lint",
9
+ "type-check": "sewing-kit type-check",
10
+ "nuke": "sewing-kit nuke",
11
+ "test": "sewing-kit test"
12
+ },
13
+ "eslintConfig": {
14
+ "extends": [
15
+ "plugin:@shopify/typescript",
16
+ "plugin:@shopify/react",
17
+ "plugin:@shopify/prettier",
18
+ "plugin:@shopify/jest",
19
+ "plugin:@shopify/polaris"
20
+ ]
21
+ },
22
+ "prettier": "@shopify/prettier-config",
23
+ "stylelint": {
24
+ "extends": [
25
+ "@shopify/stylelint-plugin/prettier"
26
+ ]
27
+ },
28
+ "resolutions": {
29
+ "babel-plugin-dynamic-import-node": "2.3.0"
30
+ }
31
+ }
@@ -0,0 +1,7 @@
1
+ package.json
2
+ .sewing-kit
3
+ .dev
4
+ node_modules
5
+ tmp
6
+ public
7
+ *.svg
@@ -0,0 +1,11 @@
1
+ /* eslint-env node */
2
+
3
+ import {Plugins, Env} from '@shopify/sewing-kit';
4
+
5
+ export default function sewingKitConfig(plugins: Plugins, env: Env) {
6
+ return {
7
+ name: '${application_name}',
8
+ // remove cdn plugin when using dev
9
+ plugins: [plugins.cdn(env.isDevelopment ? 'http://localhost:8080/webpack/assets/' : undefined)],
10
+ };
11
+ }
@@ -1,18 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
  require 'rails'
3
3
  require 'rails/railtie'
4
- begin
5
- # Force assets:precompile to be defined before sewing_kit's railtie tries to
6
- # extend it.
7
- require "sprockets/railtie" if defined? Rails
8
- # rubocop:disable Lint/HandleExceptions
9
- rescue
10
- #
11
- end
12
- # rubocop:enable Lint/HandleExceptions
4
+
13
5
  require 'sewing_kit/webpack/compiler'
14
6
  require 'sewing_kit/webpack/helper'
15
7
  require 'sewing_kit/webpack/dev'
8
+ require 'sewing_kit/webpack/server'
16
9
 
17
10
  module SewingKit
18
11
  class Railtie < ::Rails::Railtie
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module SewingKit
3
- VERSION = "0.114.2"
3
+ VERSION = "0.125.0"
4
4
  end
@@ -22,7 +22,7 @@ module SewingKit
22
22
  raise NodeSewingKitNotRunnable, node_env unless File.exist?('node_modules/.bin/sewing-kit')
23
23
 
24
24
  result = Kernel.system(
25
- { 'NODE_ENV' => node_env },
25
+ environment,
26
26
  *command,
27
27
  chdir: Rails.root.to_s,
28
28
  out: $stdout,
@@ -47,6 +47,18 @@ module SewingKit
47
47
  ].concat(options).reject(&:empty?)
48
48
  end
49
49
 
50
+ def environment
51
+ environment = {
52
+ 'NODE_ENV' => node_env,
53
+ }
54
+
55
+ if defined?(ShopifyCloud)
56
+ environment['SK_ASSET_DIR'] = ShopifyCloud::AssetUploader.asset_directory
57
+ end
58
+
59
+ environment
60
+ end
61
+
50
62
  def node_env
51
63
  ENV['NODE_ENV'] || Rails.env.to_s
52
64
  end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SewingKit
4
+ module Webpack
5
+ class Server
6
+ class DefaultEntrypointMissing < StandardError
7
+ def initialize
8
+ super(
9
+ "Default entrypoint build/server/main.js is missing."
10
+ )
11
+ end
12
+ end
13
+
14
+ def start
15
+ raise DefaultEntrypointMissing unless File.exist?(default_entrypoint)
16
+
17
+ result = Kernel.system(
18
+ {},
19
+ *command,
20
+ chdir: Rails.root.to_s,
21
+ out: $stdout,
22
+ err: $stderr
23
+ )
24
+
25
+ unless result
26
+ puts "sewing_kit:server:start failed"
27
+ exit(1)
28
+ end
29
+
30
+ result
31
+ end
32
+
33
+ private
34
+
35
+ def command
36
+ command_list = [
37
+ 'node',
38
+ default_entrypoint,
39
+ ].compact
40
+
41
+ command_list.join(' ')
42
+ end
43
+
44
+ def default_entrypoint
45
+ 'build/server/main.js'
46
+ end
47
+ end
48
+ end
49
+ end
@@ -1,9 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- def highlight(message)
4
- "\u001b[1m\u001b[37m#{message}\u001b[39m\u001b[22m"
5
- end
6
-
7
3
  module SewingKit
8
4
  module Webpack
9
5
  # Raised if the node sewing-kit isn't installed/runnable.
@@ -24,6 +20,10 @@ module SewingKit
24
20
  (cause ? "Original error #{cause}" : '')
25
21
  )
26
22
  end
23
+
24
+ def highlight(message)
25
+ "\u001b[1m\u001b[37m#{message}\u001b[39m\u001b[22m"
26
+ end
27
27
  end
28
28
  end
29
29
  end
@@ -12,10 +12,20 @@ namespace :sewing_kit do
12
12
  compiler = SewingKit::Webpack::Compiler.new
13
13
  compiler.compile
14
14
  end
15
+
16
+ namespace :server do
17
+ desc "Starts the production server"
18
+ task start: :environment do
19
+ server = SewingKit::Webpack::Server.new
20
+ server.start
21
+ end
22
+ end
15
23
  end
16
24
 
17
- if Rake::Task.task_defined?('assets:precompile')
18
- Rake::Task['assets:precompile'].enhance do
25
+ if Rake::Task.task_defined?("assets:precompile")
26
+ Rake::Task["assets:precompile"].enhance do
19
27
  Rake::Task['sewing_kit:build'].invoke
20
28
  end
29
+ else
30
+ Rake::Task.define_task("assets:precompile" => %w(sewing_kit:build))
21
31
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sewing_kit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.114.2
4
+ version: 0.125.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Sauve
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-28 00:00:00.000000000 Z
11
+ date: 2020-06-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -102,6 +102,13 @@ extensions: []
102
102
  extra_rdoc_files: []
103
103
  files:
104
104
  - README.md
105
+ - lib/generators/sewing_kit/USAGE
106
+ - lib/generators/sewing_kit/install_generator.rb
107
+ - lib/generators/sewing_kit/templates/editorconfig
108
+ - lib/generators/sewing_kit/templates/eslintignore
109
+ - lib/generators/sewing_kit/templates/package.json
110
+ - lib/generators/sewing_kit/templates/prettierignore
111
+ - lib/generators/sewing_kit/templates/sewing-kit.config.ts
105
112
  - lib/hacks/user_agent_parser.rb
106
113
  - lib/sewing_kit.rb
107
114
  - lib/sewing_kit/configuration.rb
@@ -116,6 +123,7 @@ files:
116
123
  - lib/sewing_kit/webpack/manifest/development.rb
117
124
  - lib/sewing_kit/webpack/manifest/production.rb
118
125
  - lib/sewing_kit/webpack/manifest/test_with_no_assets.rb
126
+ - lib/sewing_kit/webpack/server.rb
119
127
  - lib/sewing_kit/webpack/webpack.rb
120
128
  - lib/tasks/sewing_kit.rake
121
129
  homepage: https://github.com/Shopify/sewing-kit/tree/master/gems/sewing_kit
@@ -123,6 +131,7 @@ licenses:
123
131
  - MIT
124
132
  metadata:
125
133
  changelog_uri: https://github.com/Shopify/sewing-kit/blob/master/gems/sewing_kit/CHANGELOG.md
134
+ allowed_push_host: https://rubygems.org
126
135
  post_install_message:
127
136
  rdoc_options: []
128
137
  require_paths: