Skip to content

Instantly share code, notes, and snippets.

@kcnaiamh
Created December 20, 2023 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kcnaiamh/50c50c16be1862b59959029eaefbb534 to your computer and use it in GitHub Desktop.
Save kcnaiamh/50c50c16be1862b59959029eaefbb534 to your computer and use it in GitHub Desktop.
This script will setup the tailwind environment
import os
import subprocess
import json
def create_folder(folder_name: str):
if not os.path.exists(folder_name):
os.makedirs(folder_name)
def create_file(file_name: str, content: str = ""):
with open(file_name, "w") as file:
file.write(content)
def exe_command(cmd: str):
result = subprocess.run(
cmd,
shell=True,
check=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
)
print(result.stdout)
create_folder(".vscode")
create_file(
".vscode/settings.json",
'{\t"css.validate": false,\n\t"tailwindCSS.emmetCompletion": true\n}',
)
create_folder("src")
create_folder("output")
create_file(
"./src/tailwind.css", "@tailwind base;\n@tailwind components;\n@tailwind utilities;"
)
create_file("./output/tailwind.css")
create_file("index.html")
exe_command("npm init -y")
exe_command("npm i -D tailwindcss postcss autoprefixer")
exe_command("npx tailwindcss init -p")
# Updating package.json
with open("./package.json", "r") as fp:
data = json.load(fp)
data["scripts"].update(
{"build": "tailwindcss -i ./src/tailwind.css -o ./output/tailwind.css -w"}
)
if "test" in data["scripts"]:
del data["scripts"]["test"]
with open("./package.json", "w", encoding="utf-8") as file:
json.dump(data, file, indent=2)
print(
"""Now go to "tailwind.config.js" file. Add those file paths in content array that will use tailwind.
For example "content: ["./index.html", "./src/**/*.{js,ts,jsx,tsx,css}"]."""
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment