Skip to content

Commit b48a52a

Browse files
authored
Merge pull request #67 from nimblehq/feature/59-add-tailwind-addon
#59 Add Tailwind Add-on
2 parents 79a53b8 + ad10217 commit b48a52a

File tree

10 files changed

+163
-8
lines changed

10 files changed

+163
-8
lines changed

cmd/create_test.go

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -874,4 +874,130 @@ var _ = Describe("Create template", func() {
874874
Expect(content).NotTo(ContainSubstring(expectedContent))
875875
})
876876
})
877+
878+
Context("given tailwind add-on", func() {
879+
It("contains lib/web/assets/stylesheets/vendors/tailwind folder", func() {
880+
cookiecutter := tests.Cookiecutter{
881+
Variant: tests.Web,
882+
CssAddon: tests.Tailwind,
883+
}
884+
cookiecutter.CreateProjectFromGinTemplate(currentTemplatePath)
885+
_, err := os.Stat("lib/web/assets/stylesheets/vendors/tailwind")
886+
887+
Expect(os.IsNotExist(err)).To(BeFalse())
888+
})
889+
890+
It("contains tailwind.config.js file", func() {
891+
cookiecutter := tests.Cookiecutter{
892+
Variant: tests.Web,
893+
CssAddon: tests.Tailwind,
894+
}
895+
cookiecutter.CreateProjectFromGinTemplate(currentTemplatePath)
896+
_, err := os.Stat("tailwind.config.js")
897+
898+
Expect(os.IsNotExist(err)).To(BeFalse())
899+
})
900+
901+
It("contains tailwind package in package.json", func() {
902+
cookiecutter := tests.Cookiecutter{
903+
Variant: tests.Web,
904+
CssAddon: tests.Tailwind,
905+
}
906+
cookiecutter.CreateProjectFromGinTemplate(currentTemplatePath)
907+
content := tests.ReadFile("package.json")
908+
909+
expectedContent := "\"tailwindcss\": \"2.2.7\""
910+
911+
Expect(content).To(ContainSubstring(expectedContent))
912+
})
913+
914+
It("contains tailwind scss import in lib/web/assets/stylesheets/application.scss", func() {
915+
cookiecutter := tests.Cookiecutter{
916+
Variant: tests.Web,
917+
CssAddon: tests.Tailwind,
918+
}
919+
cookiecutter.CreateProjectFromGinTemplate(currentTemplatePath)
920+
content := tests.ReadFile("lib/web/assets/stylesheets/application.scss")
921+
922+
expectedContent := "@import \"./vendors/tailwind\";"
923+
924+
Expect(content).To(ContainSubstring(expectedContent))
925+
})
926+
927+
It("contains tailwind requirement in postcss.config.js", func() {
928+
cookiecutter := tests.Cookiecutter{
929+
Variant: tests.Web,
930+
CssAddon: tests.Tailwind,
931+
}
932+
cookiecutter.CreateProjectFromGinTemplate(currentTemplatePath)
933+
content := tests.ReadFile("postcss.config.js")
934+
935+
expectedContent := "require(\"tailwindcss\")"
936+
937+
Expect(content).To(ContainSubstring(expectedContent))
938+
})
939+
})
940+
941+
Context("given NO tailwind add-on", func() {
942+
It("does NOT contain lib/web/assets/stylesheets/vendors/tailwind folder", func() {
943+
cookiecutter := tests.Cookiecutter{
944+
Variant: tests.Web,
945+
CssAddon: tests.None,
946+
}
947+
cookiecutter.CreateProjectFromGinTemplate(currentTemplatePath)
948+
_, err := os.Stat("lib/web/assets/stylesheets/vendors/tailwind")
949+
950+
Expect(os.IsNotExist(err)).To(BeTrue())
951+
})
952+
953+
It("does NOT contain tailwind.config.js file", func() {
954+
cookiecutter := tests.Cookiecutter{
955+
Variant: tests.Web,
956+
CssAddon: tests.None,
957+
}
958+
cookiecutter.CreateProjectFromGinTemplate(currentTemplatePath)
959+
_, err := os.Stat("tailwind.config.js")
960+
961+
Expect(os.IsNotExist(err)).To(BeTrue())
962+
})
963+
964+
It("does NOT contain tailwind package in package.json", func() {
965+
cookiecutter := tests.Cookiecutter{
966+
Variant: tests.Web,
967+
CssAddon: tests.None,
968+
}
969+
cookiecutter.CreateProjectFromGinTemplate(currentTemplatePath)
970+
content := tests.ReadFile("package.json")
971+
972+
expectedContent := "\"tailwindcss\":"
973+
974+
Expect(content).NotTo(ContainSubstring(expectedContent))
975+
})
976+
977+
It("does NOT contain tailwind scss import in lib/web/assets/stylesheets/application.scss", func() {
978+
cookiecutter := tests.Cookiecutter{
979+
Variant: tests.Web,
980+
CssAddon: tests.None,
981+
}
982+
cookiecutter.CreateProjectFromGinTemplate(currentTemplatePath)
983+
content := tests.ReadFile("lib/web/assets/stylesheets/application.scss")
984+
985+
expectedContent := "@import \"./vendors/tailwind\";"
986+
987+
Expect(content).NotTo(ContainSubstring(expectedContent))
988+
})
989+
990+
It("does NOT contain tailwind requirement in postcss.config.js", func() {
991+
cookiecutter := tests.Cookiecutter{
992+
Variant: tests.Web,
993+
CssAddon: tests.None,
994+
}
995+
cookiecutter.CreateProjectFromGinTemplate(currentTemplatePath)
996+
content := tests.ReadFile("postcss.config.js")
997+
998+
expectedContent := "require(\"tailwindcss\")"
999+
1000+
Expect(content).NotTo(ContainSubstring(expectedContent))
1001+
})
1002+
})
8771003
})

cookiecutter.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
{
22
"app_name": "default-app-name",
33
"variant": ["API only", "Web only", "Both"],
4-
"css_addon": ["Bootstrap", "None"],
4+
"css_addon": ["Bootstrap", "Tailwind", "None"],
55
"use_logrus": ["yes", "no"],
66
"use_heroku": ["yes", "no"],
77

88
"_api_variant": "no",
99
"_web_variant": "no",
10-
"_bootstrap_addon": "no"
10+
"_bootstrap_addon": "no",
11+
"_tailwind_addon": "no"
1112
}

hooks/post_gen_project.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ def remove_empty_folders():
5959
print_log('Removing bootstrap add-on')
6060
remove_files("lib/web/assets/stylesheets/vendors/bootstrap")
6161

62+
# Remove tailwind add-on if not seleted
63+
if '{{ cookiecutter._tailwind_addon }}' == 'no':
64+
print_log('Removing tailwind add-on')
65+
remove_files("lib/web/assets/stylesheets/vendors/tailwind")
66+
remove_file("tailwind.config.js")
67+
6268
# Remove web variant if not selected
6369
if '{{ cookiecutter._web_variant }}' == 'no':
6470
print_log('Removing web variant related files')

hooks/pre_gen_project.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,14 @@
1818
-----------
1919
CSS Addons
2020
cookiecutter._bootstrap_addon
21+
cookiecutter._tailwind_addon
2122
-----------
2223
Only project with web:
2324
{% if cookiecutter._web_variant == 'yes' %}
2425
{% if cookiecutter.css_addon == 'Bootstrap' %}
2526
{{ cookiecutter.update({ '_bootstrap_addon': 'yes' }) }}
27+
{% elif cookiecutter.css_addon == 'Tailwind' %}
28+
{{ cookiecutter.update({ '_tailwind_addon': 'yes' }) }}
2629
{% endif %}
2730
{% endif %}
2831
'''

tests/cookiecutter.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ const (
1919
Both Variants = "3"
2020

2121
Bootstrap CssAddons = "1"
22-
None CssAddons = "2"
22+
Tailwind CssAddons = "2"
23+
None CssAddons = "3"
2324
)
2425

2526
// Field and order MUST be the same as cookiecutter.json
@@ -44,7 +45,7 @@ func (c *Cookiecutter) fillDefaultValue() {
4445
c.UseHeroku = No
4546
}
4647

47-
if c.CssAddon != Bootstrap && c.CssAddon != None {
48+
if c.CssAddon != Bootstrap && c.CssAddon != Tailwind && c.CssAddon != None {
4849
c.CssAddon = None
4950
}
5051

{{cookiecutter.app_name}}/lib/web/assets/stylesheets/application.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
@import './variables';
33

44
// Vendors
5-
{% if cookiecutter._bootstrap_addon == "yes" %}@import "./vendors/bootstrap";
6-
{% endif %}
5+
{% if cookiecutter._bootstrap_addon == "yes" %}@import "./vendors/bootstrap";{% endif %}{% if cookiecutter._tailwind_addon == "yes" %}@import "./vendors/tailwind";{% endif %}
6+
77
// Functions
88
@import './functions/sizing';
99

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@tailwind base;
2+
@tailwind components;
3+
@tailwind utilities;

{{cookiecutter.app_name}}/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"eslint-plugin-prettier": "3.4.0",
2222
"postcss": "8.3.5",
2323
"prettier": "2.3.2",
24-
"snowpack": "3.7.1"
24+
"snowpack": "3.7.1"{% if cookiecutter._tailwind_addon == "yes" %},
25+
"tailwindcss": "2.2.7"{% endif %}
2526
}
2627
}
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
module.exports = {
2-
plugins: [require("autoprefixer")],
2+
plugins: [
3+
require("autoprefixer"){% if cookiecutter._tailwind_addon == "yes" %},
4+
require("tailwindcss"){% endif %}
5+
],
36
};
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module.exports = {
2+
purge: [],
3+
darkMode: false, // or 'media' or 'class'
4+
theme: {
5+
extend: {},
6+
},
7+
variants: {
8+
extend: {},
9+
},
10+
plugins: [],
11+
}

0 commit comments

Comments
 (0)