sewing_kit 0.123.0 → 0.128.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: ad8a311afdf9ea5efa60527866ac02247e3c91189a636aa78c9dde602f304e0f
4
- data.tar.gz: 65e3897e31a73ae2ec5b3756672a35ccfda44df1d3cffa22a7473193aaf40b3a
3
+ metadata.gz: a461122bbd1f59afece53f1695188abeb57f7a70bf397c9871a1389a5c3dace0
4
+ data.tar.gz: 606ece89a71cf2748dd13bf2a1884e428d41365cbdabb9fe98dbbe2c7184e143
5
5
  SHA512:
6
- metadata.gz: 9c0706c23cb462eb4240def360fcfc0d2afd158f3b3db2846290ddcbea176ea94b00ec3a9cbf2471c372ea8cef7668a625bb55fca2f0e8429c8514ee59cc2d65
7
- data.tar.gz: d255523fbb50e830708ac1dfaec86aede73ab3b815e0653627cf51488c16f25a234effceea37b177dd9cb28d46a30fa4bff5c7c4160820c7d610eff2796d1ea4
6
+ metadata.gz: 9725a50c0872da10cb36d7882d446d9606177af40055bd309c7874f78de953768c201aacaf02853ce9b83f8ed6c80462e3df81552a225d5c1727e66a64e2df5a
7
+ data.tar.gz: 14f2b69ef3a1afc0b2cc99275933dd219767dcf9784026fd79d01d3b33c52f2a6adc36fcc2d3b88fc97dad481293f34cc9959e0400c59cf3ee71590721f468a4
data/README.md CHANGED
@@ -161,6 +161,9 @@ NODE_ENV=production SK_SIMULATE_PRODUCTION=1 bundle exec rake assets:precompile
161
161
  NODE_ENV=production SK_SIMULATE_PRODUCTION=1 dev run
162
162
  ```
163
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
+
164
167
  Note:
165
168
 
166
169
  - Code changes will not be automatically recompiled in this state
@@ -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
+ }
@@ -5,6 +5,7 @@ require 'rails/railtie'
5
5
  require 'sewing_kit/webpack/compiler'
6
6
  require 'sewing_kit/webpack/helper'
7
7
  require 'sewing_kit/webpack/dev'
8
+ require 'sewing_kit/webpack/server'
8
9
 
9
10
  module SewingKit
10
11
  class Railtie < ::Rails::Railtie
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module SewingKit
3
- VERSION = "0.123.0"
3
+ VERSION = "0.128.0"
4
4
  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
@@ -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"
@@ -12,6 +12,14 @@ 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
25
  if Rake::Task.task_defined?("assets:precompile")
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.123.0
4
+ version: 0.128.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-08 00:00:00.000000000 Z
11
+ date: 2020-07-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -106,9 +106,10 @@ files:
106
106
  - lib/generators/sewing_kit/install_generator.rb
107
107
  - lib/generators/sewing_kit/templates/editorconfig
108
108
  - lib/generators/sewing_kit/templates/eslintignore
109
- - lib/generators/sewing_kit/templates/package.json
109
+ - lib/generators/sewing_kit/templates/package.json.erb
110
110
  - lib/generators/sewing_kit/templates/prettierignore
111
- - lib/generators/sewing_kit/templates/sewing-kit.config.ts
111
+ - lib/generators/sewing_kit/templates/sewing-kit.config.ts.erb
112
+ - lib/generators/sewing_kit/templates/tsconfig.json.erb
112
113
  - lib/hacks/user_agent_parser.rb
113
114
  - lib/sewing_kit.rb
114
115
  - lib/sewing_kit/configuration.rb
@@ -123,6 +124,7 @@ files:
123
124
  - lib/sewing_kit/webpack/manifest/development.rb
124
125
  - lib/sewing_kit/webpack/manifest/production.rb
125
126
  - lib/sewing_kit/webpack/manifest/test_with_no_assets.rb
127
+ - lib/sewing_kit/webpack/server.rb
126
128
  - lib/sewing_kit/webpack/webpack.rb
127
129
  - lib/tasks/sewing_kit.rake
128
130
  homepage: https://github.com/Shopify/sewing-kit/tree/master/gems/sewing_kit
@@ -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
- }