sewing_kit 0.124.0 → 0.129.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: c3a05925e10dba45f77fcf36f23bf1f0d777ab6993f7994f3b216169dde31dd7
4
- data.tar.gz: ca891a9517eaca9dbcacef5c838c626e587a1111f9a58105b12abf3e8adbcab4
3
+ metadata.gz: 192f93794571de06b57d5125eec9da37d1331c3dbb47a2c530e29d6f4693cb47
4
+ data.tar.gz: d06a650795388f99d0680e007e7402b8d964562be69610aa92032e9e24abdac1
5
5
  SHA512:
6
- metadata.gz: b297f9c114a00b3925933df21d8109d04e0123b6234790c25bc136e5393543f1f8cc04d683b47f86d0999c7bf344a679fe9cb111e5add3f75e5a645d4bef3940
7
- data.tar.gz: '06347349fc9a1f1c5ef451205d9c28a7005e528282540f42c43e605ee4c6112d51c881171831100551ab793e30210b4c4d9e8075fd08d67ecfc417a5be44ea73'
6
+ metadata.gz: 773c4e613be0301501b9d8e31b12bce81027f7aaf39aabafa87c07a5a76430498b6c39d81801f4af44b1ea48e47cf127edddca88e7c2031dc22c44ffc202fe58
7
+ data.tar.gz: 056bdc1ff814b70f35ffac31bcba3b7d95560002437272f8e615ae93d8e6a4bdcb49bb08b0d8db9961c99f88488ff3cd616cb991b044c125578ca41f660455de
data/README.md CHANGED
@@ -2,7 +2,11 @@
2
2
 
3
3
  Zero configuration, high performance front end development at organization scale.
4
4
 
5
- `sewing_kit` facilitates legacy Rails integration using ERB tags. For a more complete modern stack with performance-as-a-feature, consider [quilt_rails](https://github.com/Shopify/quilt/tree/master/gems/quilt_rails). For details of the `sewing-kit` node package's configuration and usage, see the [sewing-kit README](/README.md).
5
+ `sewing_kit` can be used in a Rails application instead of [Webpacker](https://github.com/rails/webpacker), allowing to embed bundled/compiled javascript in erb pages.
6
+
7
+ For a more complete and modern stack with performance-as-a-feature, consider [quilt_rails](https://github.com/Shopify/quilt/tree/master/gems/quilt_rails).
8
+
9
+ For details on configuring and usage of the `sewing-kit` node package, see the [sewing-kit README](/README.md).
6
10
 
7
11
  ## Quick Start
8
12
 
@@ -4,31 +4,58 @@ module SewingKit
4
4
  class InstallGenerator < Rails::Generators::Base
5
5
  source_root File.expand_path('templates', __dir__)
6
6
 
7
- desc "This generator creates a sewing-kit config file."
7
+ desc "Adds the configuration files for a sewing-kit powered front-end."
8
8
 
9
- def initialize(args, *options)
10
- @application_name = Rails.application.class.module_parent.to_s.underscore
11
- super(args, *options)
12
- end
9
+ class_option :skip_yarn, type: :boolean, default: false
10
+ class_option :javascript_path, type: :string, default: 'app/ui'
13
11
 
14
- def create_package_json
15
- package_json_path = "package.json"
12
+ # We don't specify a default here because we want to fallback dynamically
13
+ class_option :uses_dev, type: :boolean
16
14
 
17
- copy_file(package_json_path)
18
- gsub_file(package_json_path, "\${application_name}", @application_name)
19
- end
15
+ def initialize(args, *opts)
16
+ super(args, *opts)
20
17
 
21
- def create_sk_config
22
- sk_config_path = "config/sewing-kit.config.ts"
18
+ @application_name = Project.app_name
19
+ @javascript_path = options[:javascript_path]
23
20
 
24
- copy_file("sewing-kit.config.ts", sk_config_path)
25
- gsub_file(sk_config_path, "\${application_name}", @application_name)
21
+ if Project.uses_webpacker?
22
+ warn("
23
+ WARNING: We've detected you currently have webpacker config at config/webpacker.yml.
24
+ You may experience conflicts between sewing-kit and webpacker's behaviour as build tools.
25
+ If your app was made with `rails new`, try rerunning it with `--skip-webpack-install --skip-javascript`
26
+ ")
27
+ end
26
28
  end
27
29
 
28
30
  def create_config_files
31
+ say("Creating JS tooling config files")
29
32
  copy_file("editorconfig", ".editorconfig")
30
33
  copy_file("eslintignore", ".eslintignore")
31
34
  copy_file("prettierignore", ".prettierignore")
35
+ template("package.json.erb", "package.json")
36
+ template("tsconfig.json.erb", "tsconfig.json")
37
+ template("sewing-kit.config.ts.erb", "config/sewing-kit.config.ts")
38
+ end
39
+
40
+ def install_js_dependencies
41
+ return if options.skip_yarn?
42
+ say("Installing javascript dependencies")
43
+ system("yarn add @shopify/sewing-kit")
44
+ system("yarn add typescript")
45
+ end
46
+
47
+ class Project
48
+ def self.app_name
49
+ Rails.application.class.module_parent.to_s.underscore
50
+ end
51
+
52
+ def self.uses_dev?
53
+ File.exist?('dev.yml')
54
+ end
55
+
56
+ def self.uses_webpacker?
57
+ File.exist?('config/webpacker.yml')
58
+ end
32
59
  end
33
60
  end
34
61
  end
@@ -1,2 +1,4 @@
1
1
  node_modules
2
2
  build
3
+ **/schema.graphql
4
+ **/*.graphql.d.ts
@@ -1,5 +1,5 @@
1
1
  {
2
- "name": "${application_name}",
2
+ "name": "<%= @application_name %>",
3
3
  "private": true,
4
4
  "sideEffects": false,
5
5
  "scripts": {
@@ -16,7 +16,8 @@
16
16
  "plugin:@shopify/react",
17
17
  "plugin:@shopify/prettier",
18
18
  "plugin:@shopify/jest",
19
- "plugin:@shopify/polaris"
19
+ "plugin:@shopify/polaris",
20
+ "plugin:@shopify/graphql"
20
21
  ]
21
22
  },
22
23
  "prettier": "@shopify/prettier-config",
@@ -1,7 +1,10 @@
1
1
  package.json
2
+ .runix
2
3
  .sewing-kit
3
4
  .dev
4
5
  node_modules
5
6
  tmp
6
7
  public
7
8
  *.svg
9
+ *.graphql.d.ts
10
+ build
@@ -0,0 +1,47 @@
1
+ /* eslint-env node */
2
+ import {resolve} from 'path';
3
+
4
+ import {Plugins, Env} from '@shopify/sewing-kit';
5
+
6
+ const ROOT_PATH = resolve(__dirname, '..');
7
+
8
+ export default function sewingKitConfig(plugins: Plugins, env: Env) {
9
+ return {
10
+ name: '<%= @application_name %>',
11
+ plugins: [
12
+ plugins.paths({
13
+ // Determines where the root directory for front-end code is
14
+ app: resolve(ROOT_PATH, '<%= @javascript_path %>'),
15
+ // Determines where test setup should go for front-end code
16
+ tests: resolve(ROOT_PATH, '<%= @javascript_path %>', 'tests'),
17
+ }),
18
+
19
+ <% unless @uses_dev %>
20
+ // Sets up the app to get its assets from the default webpack endpoint in development.
21
+ // You will need to change this to use your actual production cdn to get it working in production.
22
+ // NOTE: If you are using dev and shopify-cloud gem you can delete this.
23
+ plugins.cdn(
24
+ env.isDevelopment ? 'http://localhost:8080/webpack/assets/' : undefined,
25
+ ),
26
+ <% end %>
27
+ // Sets up sewing-kit to generate type definitions for GraphQL using the given schema(s)
28
+ // Uncomment the following if you are using GraphQL and make sure the path points to your generated schema
29
+ // plugins.graphql({
30
+ // schema: resolve(__dirname, '..', 'app', 'graphql', 'schema.graphql'),
31
+ // }),
32
+
33
+ // Sets up sass mixins to be automatically imported.
34
+ // Uncomment if you are using Polaris and want access to the sass mixins in your custom SCSS
35
+ // plugins.sass({
36
+ // autoInclude: [
37
+ // path.join(
38
+ // __dirname,
39
+ // 'node_modules/@shopify/polaris/dist/styles/_public-api.scss',
40
+ // ),
41
+ // ],
42
+ // }),
43
+
44
+ // configure additional sewing-kit plugins here
45
+ ],
46
+ };
47
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "extends": "@shopify/typescript-configs/application.json",
3
+ "compilerOptions": {
4
+ "baseUrl": ".",
5
+ "rootDir": ".",
6
+ "paths": {
7
+ "*": ["<%= @javascript_path %>*"]
8
+ }
9
+ },
10
+ "include": ["./config/*.ts", "./<%= @javascript_path %>**/*"]
11
+ }
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module SewingKit
3
- VERSION = "0.124.0"
3
+ VERSION = "0.129.0"
4
4
  end
@@ -8,7 +8,7 @@ module SewingKit
8
8
  def initialize
9
9
  super(
10
10
  "nodejs is not installed. " \
11
- "Try creating a `.buildpack` file in the root of the project with following content:
11
+ "Try creating a `.buildpacks` file in the root of the project with following content:
12
12
 
13
13
  https://github.com/heroku/heroku-buildpack-nodejs.git
14
14
  https://github.com/heroku/heroku-buildpack-ruby.git
@@ -39,13 +39,13 @@ module SewingKit
39
39
 
40
40
  def handle_exit
41
41
  return if $ERROR_INFO.nil?
42
- Process.kill 'SIGTERM', pid
42
+ Process.kill('SIGTERM', pid)
43
43
  rescue Errno::ESRCH
44
44
  nil
45
45
  end
46
46
 
47
47
  def detach
48
- Process.detach pid
48
+ Process.detach(pid)
49
49
  end
50
50
 
51
51
  def command
@@ -54,7 +54,7 @@ module SewingKit
54
54
  heap_config,
55
55
  sewing_kit_bin,
56
56
  'dev',
57
- '--logLevel',
57
+ '--log-level',
58
58
  log_level,
59
59
  ].compact.concat(options)
60
60
 
@@ -16,7 +16,7 @@ module SewingKit
16
16
 
17
17
  assets = SewingKit::Webpack::Manifest.asset_dependencies(entrypoint_name, request.user_agent)
18
18
 
19
- raise UnknownAssetError, "#{entrypoint_name} was not found in manifest." if raise_unknown_error? assets
19
+ raise UnknownAssetError, "#{entrypoint_name} was not found in manifest." if raise_unknown_error?(assets)
20
20
  return [] unless assets && assets[extension]
21
21
 
22
22
  dependencies = assets[extension]
@@ -56,7 +56,7 @@ module SewingKit
56
56
  private
57
57
 
58
58
  def create_asset_tag(tag_type, asset, tag_options)
59
- raise ArgumentError, "Invalid tag type: #{tag_type}" unless [:script, :link].include? tag_type
59
+ raise ArgumentError, "Invalid tag type: #{tag_type}" unless [:script, :link].include?(tag_type)
60
60
 
61
61
  options = tag_options.clone
62
62
 
@@ -24,14 +24,14 @@ module SewingKit
24
24
  # Raised if the node-generated manifest cannot be read from the filesystem.
25
25
  class ManifestLoadError < StandardError
26
26
  def initialize(path, cause)
27
- super "Could not load manifest from #{path} (original error #{cause})"
27
+ super("Could not load manifest from #{path} (original error #{cause})")
28
28
  end
29
29
  end
30
30
 
31
31
  # Raised if the node-generated manifest returns unparseable JSON.
32
32
  class ManifestParseError < StandardError
33
33
  def initialize(cause)
34
- super "Could not parse manifest JSON (original error #{cause})"
34
+ super("Could not parse manifest JSON (original error #{cause})")
35
35
  end
36
36
  end
37
37
 
@@ -43,7 +43,9 @@ module SewingKit
43
43
  return normalize_metadata(result)
44
44
  end
45
45
  rescue => e
46
- Rails.logger.warn "[sewing_kit] could not read manifest from #{@metadata_path}; falling back to node. #{e}"
46
+ Rails.logger.warn(
47
+ "[sewing_kit] could not read manifest from #{@metadata_path}; falling back to node. #{e}"
48
+ )
47
49
  @metadata_path = nil
48
50
  end
49
51
 
@@ -81,8 +83,8 @@ module SewingKit
81
83
 
82
84
  class OnlyUseInProductionError < StandardError
83
85
  def initialize
84
- super "The SewingKit::Webpack::Manifest#manifest is intended "\
85
- "for deploying assets to a CDN. Do not use it in development."
86
+ super("The SewingKit::Webpack::Manifest#manifest is intended "\
87
+ "for deploying assets to a CDN. Do not use it in development.")
86
88
  end
87
89
  end
88
90
  end
@@ -8,8 +8,8 @@ module SewingKit
8
8
  class Manifest
9
9
  class Production < Base
10
10
  def initialize
11
+ super
11
12
  @cache_by_user_agent = {}
12
- @metadata = nil
13
13
  @metadata_path = nil
14
14
  end
15
15
 
@@ -4,7 +4,7 @@ TEMPLATE_PATH = File.expand_path("../install/template.rb", File.dirname(__FILE__
4
4
  namespace :sewing_kit do
5
5
  desc "Install all of Shopify’s modern FED tooling"
6
6
  task :install do
7
- exec "./bin/rails app:template LOCATION=#{TEMPLATE_PATH}"
7
+ exec "bundle exec rails generate sewing_kit:install"
8
8
  end
9
9
 
10
10
  desc "Build webpack asset bundles"
@@ -29,3 +29,11 @@ if Rake::Task.task_defined?("assets:precompile")
29
29
  else
30
30
  Rake::Task.define_task("assets:precompile" => %w(sewing_kit:build))
31
31
  end
32
+
33
+ unless Rake::Task.task_defined?('assets:clean')
34
+ namespace :assets do
35
+ task :clean do
36
+ # This empty task is to offer the same interface than sprockets and webpacker
37
+ end
38
+ end
39
+ 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.124.0
4
+ version: 0.129.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-06-10 00:00:00.000000000 Z
11
+ date: 2020-11-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0.56'
75
+ version: 0.89.1
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '0.56'
82
+ version: 0.89.1
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rubocop-git
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: 0.1.3
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop-shopify
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 1.0.5
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 1.0.5
97
111
  description:
98
112
  email:
99
113
  - chris.sauve@shopify.com
@@ -106,9 +120,10 @@ files:
106
120
  - lib/generators/sewing_kit/install_generator.rb
107
121
  - lib/generators/sewing_kit/templates/editorconfig
108
122
  - lib/generators/sewing_kit/templates/eslintignore
109
- - lib/generators/sewing_kit/templates/package.json
123
+ - lib/generators/sewing_kit/templates/package.json.erb
110
124
  - lib/generators/sewing_kit/templates/prettierignore
111
- - lib/generators/sewing_kit/templates/sewing-kit.config.ts
125
+ - lib/generators/sewing_kit/templates/sewing-kit.config.ts.erb
126
+ - lib/generators/sewing_kit/templates/tsconfig.json.erb
112
127
  - lib/hacks/user_agent_parser.rb
113
128
  - lib/sewing_kit.rb
114
129
  - lib/sewing_kit/configuration.rb
@@ -1,11 +0,0 @@
1
- /* eslint-env node */
2
-
3
- import {Plugins} from '@shopify/sewing-kit';
4
-
5
- export default function sewingKitConfig(plugins: Plugins) {
6
- return {
7
- name: "${application_name}",
8
- plugins: [
9
- ],
10
- };
11
- }