bridgetown-plugin-tailwindcss 0.1.0 → 0.1.5

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: a4ce91a98c46bff19d557ae368e8f28cdd6abffb27acb37e1a24614e9b0e649a
4
- data.tar.gz: 9244712044140697ca0278d98ccf8f300b1d5d219c35bca39b7eec4a4708282e
3
+ metadata.gz: 9986754f4c6f0a83586367fd810524cff649bef87c142982f717716c61b376c3
4
+ data.tar.gz: 582319a24342772b910fb4c548aa386ac7f36354ddbad01007e26d1f3c8109f7
5
5
  SHA512:
6
- metadata.gz: 1f50d417e22fc75c27c7f401f8f3b837b94976e6fce3c8843fd56e419106d34c1cf8a15bfbabf90261dab13c4d53f28d95fe965ca234cde5afff219c5cf6791c
7
- data.tar.gz: b7a664a5d0970ef790e2148afd38038fa5c98d1d1eb6078be0d687497dc1700f22f8ec64398e443ef447f98f29bb8406d202b9a6d77f10f5b8be79b040e96b58
6
+ metadata.gz: bd7a4d92bd480318bf7a09fe1d0ad78a92acedcf37e64fbe889e9c807776e863c7e9031ac83d45e58ecbbc81ee35bd365282ecb17e7a0f1ea249940a53ddefa6
7
+ data.tar.gz: 7781f8c310ab4834f86fb03f3b7560682f04add80d5c49b914b154d89f3f5b9166a44f574450bbd00f066fb87cc779fb2582bcdaeb1e96f6b6777fa993873f00
data/Gemfile CHANGED
@@ -4,3 +4,5 @@ source "https://rubygems.org"
4
4
  gemspec
5
5
 
6
6
  gem "bridgetown", ENV["BRIDGETOWN_VERSION"] if ENV["BRIDGETOWN_VERSION"]
7
+
8
+ gem "thor", "~> 1.0"
data/Rakefile CHANGED
@@ -2,16 +2,47 @@
2
2
 
3
3
  require "bundler/gem_tasks"
4
4
  require "rspec/core/rake_task"
5
+ require "./lib/bridgetown-plugin-tailwindcss/utils"
5
6
 
6
7
  RSpec::Core::RakeTask.new(:spec)
7
8
 
8
9
  task :default => :spec
9
10
  task :test => :spec
10
11
 
11
- task :release do
12
+ task :deploy do
12
13
  Rake.sh "./script/release"
13
14
  end
14
15
 
16
+ task :format do
17
+ Rake.sh "./script/fmt -a"
18
+ end
19
+
20
+
21
+ namespace :bump do
22
+ task :current do
23
+ puts TailwindCss::Utils::Bump.new.current_version
24
+ end
25
+
26
+ task :set do
27
+ question = "What would you like to set your version to? IE: [2.1.0] :"
28
+ value = TailwindCss::Utils::Actions.new.ask(question)
29
+
30
+ TailwindCss::Utils::Bump.new.bump_version_to_string(value)
31
+ end
32
+
33
+ task :major do
34
+ TailwindCss::Utils::Bump.new.bump_version(:major)
35
+ end
36
+
37
+ task :minor do
38
+ TailwindCss::Utils::Bump.new.bump_version(:minor)
39
+ end
40
+
41
+ task :patch do
42
+ TailwindCss::Utils::Bump.new.bump_version(:patch)
43
+ end
44
+ end
45
+
15
46
  def filelist(*strings)
16
47
  Rake::FileList.new(strings) do |fl|
17
48
  fl.exclude(/node_modules/)
@@ -5,10 +5,10 @@ require_relative "lib/bridgetown-plugin-tailwindcss/version"
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "bridgetown-plugin-tailwindcss"
7
7
  spec.version = TailwindCss::VERSION
8
- spec.author = "Bridgetown Team"
9
- spec.email = "maintainers@bridgetownrb.com"
10
- spec.summary = "Sample code for creating new Bridgetown plugins"
11
- spec.homepage = "https://github.com/bridgetownrb/bridgetown-plugin-tailwindcss"
8
+ spec.author = "Konnor Rogers"
9
+ spec.email = "konnor7414@gmail.com"
10
+ spec.summary = "A plugin to add tailwindcss to a site"
11
+ spec.homepage = "https://github.com/paramagicdev/bridgetown-plugin-tailwindcss"
12
12
  spec.license = "MIT"
13
13
 
14
14
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r!^(test|script|spec|features|frontend)/!) }
@@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.required_ruby_version = ">= 2.5.0"
20
20
 
21
21
  spec.add_dependency "bridgetown", ">= 0.14", "< 2.0"
22
+ spec.add_dependency "thor", "~> 1.0"
22
23
 
23
24
  spec.add_development_dependency "bundler"
24
25
  spec.add_development_dependency "nokogiri", "~> 1.6"
@@ -1,8 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "bridgetown"
4
- require "bridgetown-plugin-tailwindcss/builder"
4
+ require "bridgetown-plugin-tailwindcss/command.rb"
5
+ require "bridgetown-plugin-tailwindcss/utils.rb"
5
6
 
6
7
  Bridgetown::PluginManager.new_source_manifest(
7
- origin: TailwindCss,
8
+ origin: TailwindCss
8
9
  )
@@ -1,115 +1,170 @@
1
- require 'bridgetown'
2
- require 'utils'
3
-
4
- class Command < Bridgetown::Command
5
- include Utils
6
-
7
- class << self
8
- def init_with_program(prog)
9
- prog.command(:init) do |c|
10
- c.syntax "init"
11
- c.description 'Initialize config for Tailwind'
12
- # c.option 'path', '--path', 'Choose the path to install tailwind'
13
-
14
- c.action do |args, options|
15
- generate_tailwind
1
+ # frozen_string_literal: true
2
+
3
+ require "bridgetown"
4
+ require_relative "utils"
5
+
6
+ module Bridgetown
7
+ module Commands
8
+ class TailwindInit < Bridgetown::Command
9
+ ACTIONS = TailwindCss::Utils::Actions.new
10
+
11
+ class << self
12
+ def init_with_program(prog)
13
+ prog.command(:tailwind_init) do |c|
14
+ c.syntax "tailwind_init"
15
+ c.description "Initialize config for Tailwind"
16
+ # c.option 'path', '--path', 'Choose the path to install tailwind'
17
+
18
+ c.action do |_args, _options|
19
+ run
20
+ end
21
+ end
16
22
  end
17
- end
18
- end
19
-
20
- private
21
-
22
- def generate_tailwind
23
- install_tailwind
24
- write_files
25
- end
26
23
 
27
- def install_tailwind
28
- yarn_add = "yarn add -D"
29
- packages = "tailwindcss postcss-import postcss-loader"
30
- Bridgetown::Utils::Exec.run(yarn_add, packages)
31
- end
24
+ private
32
25
 
33
- def write_files
34
- webpack_config = File.expand_path("webpack.config.js")
35
- tailwind_config = File.expand_path("tailwind.config.js")
26
+ def run
27
+ write_files
28
+ end
36
29
 
37
- File.open(webpack_config) do |f|
38
- f.write(webpack_file_contents)
39
- end
30
+ def write_files
31
+ webpack_config = File.expand_path("webpack.config.js")
32
+ tailwind_config = File.expand_path("tailwind.config.js")
40
33
 
41
- File.open(tailwind_config) do |f|
42
- f.write(tailwind_config_contents)
43
- end
34
+ ACTIONS.create_file(webpack_config, webpack_file_contents)
35
+ ACTIONS.create_file(tailwind_config, tailwind_config_contents)
36
+ prepend_to_stylesheet
37
+ end
44
38
 
45
- prepend_to_stylesheet
46
- end
39
+ def prepend_to_stylesheet
40
+ frontend_stylesheet = File.join("frontend", "styles", "index.scss")
41
+ frontend_stylesheet = File.expand_path(frontend_stylesheet)
47
42
 
48
- def prepend_to_stylesheet
49
- frontend_stylesheet = File.join("frontend", "styles", "index.scss")
50
- frontend_stylesheet = File.expand_path(frontend_stylesheet)
43
+ return unless File.exist?(frontend_stylesheet)
51
44
 
52
- return unless File.exist?(frontend_stylesheet)
45
+ ACTIONS.prepend_to_file(frontend_stylesheet, import_tailwind_contents)
46
+ end
53
47
 
54
- prepend_to_file(frontend_stylesheet, import_tailwind_contents)
55
- end
48
+ def import_tailwind_contents
49
+ <<~IMPORT
50
+ @import 'tailwindcss/base';
51
+ @import 'tailwindcss/components';
52
+ @import 'tailwindcss/utilities';
56
53
 
57
- def import_tailwind_contents
58
- <<~IMPORT
59
- @import 'tailwindcss/base';
60
- @import 'tailwindcss/components';
61
- @import 'tailwindcss/utilities';
62
- IMPORT
63
- end
54
+ IMPORT
55
+ end
64
56
 
65
- def tailwind_config_contents
66
- <<~TAILWIND
67
- module.exports = {
68
- purge: {
69
- enabled: true,
70
- content: ['./src/**/*.html'],
71
- },
72
- theme: {
73
- extend: {},
74
- },
75
- variants: {},
76
- plugins: [],
77
- }
78
- TAILWIND
79
- end
57
+ def tailwind_config_contents
58
+ <<~TAILWIND
59
+ module.exports = {
60
+ purge: {
61
+ enabled: true,
62
+ content: ['./src/**/*.html'],
63
+ },
64
+ theme: {
65
+ extend: {},
66
+ },
67
+ variants: {},
68
+ plugins: [],
69
+ }
70
+ TAILWIND
71
+ end
80
72
 
81
- def webpack_file_contents
82
- <<~WEBPACK
83
- {
84
- test: /\.(s[ac]|c)ss$/,
85
- use: [
86
- MiniCssExtractPlugin.loader,
87
- "css-loader",
88
- {
89
- loader: "sass-loader",
90
- options: {
91
- sassOptions: {
92
- includePaths: [
93
- path.resolve(__dirname, "src/_components"),
94
- path.resolve(__dirname, "src/_includes"),
95
- ],
96
- },
73
+ def webpack_file_contents
74
+ <<~WEBPACK
75
+ const path = require("path");
76
+ const MiniCssExtractPlugin = require("mini-css-extract-plugin");
77
+ const ManifestPlugin = require("webpack-manifest-plugin");
78
+
79
+ module.exports = {
80
+ entry: "./frontend/javascript/index.js",
81
+ devtool: "source-map",
82
+ // Set some or all of these to true if you want more verbose logging:
83
+ stats: {
84
+ modules: false,
85
+ builtAt: false,
86
+ timings: false,
87
+ children: false,
88
+ },
89
+ output: {
90
+ path: path.resolve(__dirname, "output", "_bridgetown", "static", "js"),
91
+ filename: "all.[contenthash].js",
92
+ },
93
+ resolve: {
94
+ extensions: [".js", ".jsx"],
97
95
  },
98
- },
99
- {
100
- loader: "postcss-loader",
101
- options: {
102
- ident: "postcss",
103
- plugins: [
104
- require("postcss-import"),
105
- require("tailwindcss"),
106
- require("autoprefixer"),
96
+ plugins: [
97
+ new MiniCssExtractPlugin({
98
+ filename: "../css/all.[contenthash].css",
99
+ }),
100
+ new ManifestPlugin({
101
+ fileName: path.resolve(__dirname, ".bridgetown-webpack", "manifest.json"),
102
+ }),
103
+ ],
104
+ module: {
105
+ rules: [
106
+ {
107
+ test: /\.(js|jsx)/,
108
+ use: {
109
+ loader: "babel-loader",
110
+ options: {
111
+ presets: ["@babel/preset-env"],
112
+ plugins: [
113
+ "@babel/plugin-proposal-class-properties",
114
+ [
115
+ "@babel/plugin-transform-runtime",
116
+ {
117
+ helpers: false,
118
+ },
119
+ ],
120
+ ],
121
+ },
122
+ },
123
+ },
124
+ {
125
+ test: /\.(s[ac]|c)ss$/,
126
+ use: [
127
+ MiniCssExtractPlugin.loader,
128
+ "css-loader",
129
+ {
130
+ loader: "sass-loader",
131
+ options: {
132
+ sassOptions: {
133
+ includePaths: [
134
+ path.resolve(__dirname, "src/_components"),
135
+ path.resolve(__dirname, "src/_includes"),
136
+ ],
137
+ },
138
+ },
139
+ },
140
+ ],
141
+ },
142
+ {
143
+ loader: "postcss-loader",
144
+ options: {
145
+ ident: "postcss",
146
+ plugins: [
147
+ require("postcss-import"),
148
+ require("tailwindcss"),
149
+ require("autoprefixer"),
150
+ ],
151
+ },
152
+ },
153
+ {
154
+ test: /\.woff2?$|\.ttf$|\.eot$|\.svg$/,
155
+ loader: "file-loader",
156
+ options: {
157
+ outputPath: "../fonts",
158
+ publicPath: "../fonts",
159
+ },
160
+ },
107
161
  ],
108
162
  },
109
- },
110
- ],
111
- },
112
- WEBPACK
163
+ };
164
+
165
+ WEBPACK
166
+ end
167
+ end
113
168
  end
114
169
  end
115
170
  end
@@ -1,10 +1,88 @@
1
- module Utils
2
- def prepend_to_file(file, str)
3
- File.open(file, 'w') do |open_file|
4
- open_file.puts(str)
5
- File.foreach(file) do |line|
6
- open_file.puts(line)
1
+ # frozen_string_literal: true
2
+
3
+ require "thor"
4
+
5
+ module TailwindCss
6
+ module Utils
7
+ class Actions < Thor
8
+ include Thor::Actions
9
+ end
10
+ # @see https://ruby-doc.org/core-2.7.1/Regexp.html#class-Regexp-label-Capturing
11
+ # capture groups
12
+ class Bump < Thor
13
+ include Thor::Actions
14
+
15
+ VERSION_REGEX = %r!(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)!.freeze
16
+
17
+ # rubocop:disable Metrics/BlockLength
18
+ no_commands do
19
+ def current_version
20
+ VERSION
21
+ end
22
+
23
+ def bump_version_to_string(string)
24
+ say("Bumping from #{VERSION} to #{string}", :red)
25
+
26
+ version_files.each do |file|
27
+ gsub_file(file, VERSION_REGEX, string)
28
+ end
29
+ end
30
+
31
+ def bump_version(type, version: VERSION, value: nil)
32
+ say(version_change(type, version: version, value: value), :red)
33
+
34
+ version_files.each do |file|
35
+ gsub_file(file, VERSION_REGEX,
36
+ to_version(type, version: version, value: value))
37
+ end
38
+ end
39
+
40
+ private
41
+
42
+ def version_files
43
+ @package_json = File.expand_path("package.json")
44
+ @version_file = File.expand_path(File.join(__dir__, "version.rb"))
45
+
46
+ [@package_json, @version_file]
47
+ end
48
+
49
+ def to_version(type, version: nil, value: nil)
50
+ from = version
51
+ match = VERSION_REGEX.match(from)
52
+
53
+ groups = {
54
+ major: match[:major],
55
+ minor: match[:minor],
56
+ patch: match[:patch],
57
+ }
58
+
59
+ unless groups.key?(type)
60
+ raise "\nYou gave #{type} but the only accepted types are
61
+ #{groups.keys}"
62
+ end
63
+
64
+ groups[type] = value || (groups[type].to_i + 1).to_s
65
+
66
+ bump_to_zero(type, groups)
67
+
68
+ "#{groups[:major]}.#{groups[:minor]}.#{groups[:patch]}"
69
+ end
70
+
71
+ def bump_to_zero(type, groups)
72
+ return if type == :patch
73
+
74
+ groups[:patch] = "0"
75
+
76
+ return if type == :minor
77
+
78
+ groups[:minor] = "0"
79
+ end
80
+
81
+ def version_change(type, version: nil, value: nil)
82
+ "Bumping from #{version} to #{to_version(type, version: version, value: value)}"
83
+ end
7
84
  end
85
+ # rubocop:enable Metrics/BlockLength
8
86
  end
9
87
  end
10
88
  end