From bdd99e93741474016bc12953ad5da07f60c43837 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Lov=C3=A9n?= Date: Tue, 26 Dec 2023 13:22:45 +0100 Subject: [PATCH] Try cookiecutter --- .gitattributes | 2 -- .gitignore | 1 - cookiecutter.json | 6 ++++ hacs.json | 4 --- package.json | 28 ------------------- test/.env | 4 --- src/main.ts => zipup.sh | 0 .../.devcontainer}/devcontainer.json | 5 ++-- .../.gitattributes | 2 ++ {{ cookiecutter.project_slug }}/.gitignore | 2 ++ .../.vscode}/tasks.json | 0 .../LICENSE.txt | 2 +- .../README.md | 2 +- {{ cookiecutter.project_slug }}/hacs.json | 4 +++ {{ cookiecutter.project_slug }}/package.json | 27 ++++++++++++++++++ .../rollup.config.mjs | 8 ++---- .../src/main.ts | 0 {{ cookiecutter.project_slug }}/test/.env | 4 +++ .../test}/configuration.yaml | 0 .../test}/docker-compose.yml | 1 + .../test/lovelace.yaml | 0 .../tsconfig.json | 0 22 files changed, 54 insertions(+), 48 deletions(-) delete mode 100644 .gitattributes delete mode 100644 .gitignore create mode 100644 cookiecutter.json delete mode 100644 hacs.json delete mode 100644 package.json delete mode 100644 test/.env rename src/main.ts => zipup.sh (100%) rename {.devcontainer => {{ cookiecutter.project_slug }}/.devcontainer}/devcontainer.json (84%) create mode 100644 {{ cookiecutter.project_slug }}/.gitattributes create mode 100644 {{ cookiecutter.project_slug }}/.gitignore rename {.vscode => {{ cookiecutter.project_slug }}/.vscode}/tasks.json (100%) rename LICENSE.txt => {{ cookiecutter.project_slug }}/LICENSE.txt (96%) rename README.md => {{ cookiecutter.project_slug }}/README.md (93%) create mode 100644 {{ cookiecutter.project_slug }}/hacs.json create mode 100644 {{ cookiecutter.project_slug }}/package.json rename rollup.config.js => {{ cookiecutter.project_slug }}/rollup.config.mjs (71%) rename test/lovelace.yaml => {{ cookiecutter.project_slug }}/src/main.ts (100%) create mode 100644 {{ cookiecutter.project_slug }}/test/.env rename {test => {{ cookiecutter.project_slug }}/test}/configuration.yaml (100%) rename {test => {{ cookiecutter.project_slug }}/test}/docker-compose.yml (85%) create mode 100644 {{ cookiecutter.project_slug }}/test/lovelace.yaml rename tsconfig.json => {{ cookiecutter.project_slug }}/tsconfig.json (100%) diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 4744557..0000000 --- a/.gitattributes +++ /dev/null @@ -1,2 +0,0 @@ -.js binary -package-lock.json.binary diff --git a/.gitignore b/.gitignore deleted file mode 100644 index c2658d7..0000000 --- a/.gitignore +++ /dev/null @@ -1 +0,0 @@ -node_modules/ diff --git a/cookiecutter.json b/cookiecutter.json new file mode 100644 index 0000000..1115ecc --- /dev/null +++ b/cookiecutter.json @@ -0,0 +1,6 @@ +{ + "project_name": "Lovelace Custom Card", + "project_slug": "{{ cookiecutter.project_name.lower().replace(' ', '-') ", + "project_file": "{{ cookiecutter.project_slug.replace('lovelace-', '') ", + "author": "Thomas Lovén" +} \ No newline at end of file diff --git a/hacs.json b/hacs.json deleted file mode 100644 index 05a58a5..0000000 --- a/hacs.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "name": "", - "render_readme": true -} diff --git a/package.json b/package.json deleted file mode 100644 index 7ef04bb..0000000 --- a/package.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "name": "", - "private": true, - "version": "1.0.0", - "description": "", - "scripts": { - "build": "rollup -c", - "watch": "rollup -c --watch", - "update-card-tools": "npm uninstall card-tools && npm install thomasloven/lovelace-card-tools" - }, - "author": "Thomas Lovén", - "license": "MIT", - "devDependencies": { - "@babel/core": "^7.13.1", - "@rollup/plugin-babel": "^5.3.0", - "@rollup/plugin-json": "^4.1.0", - "@rollup/plugin-node-resolve": "^11.2.0", - "rollup": "^2.39.0", - "rollup-plugin-terser": "^7.0.2", - "rollup-plugin-typescript2": "^0.30.0", - "typescript": "^4.1.5" - }, - "dependencies": { - "card-tools": "github:thomasloven/lovelace-card-tools", - "lit": "^2.0.0-rc.2", - "tslib": "^2.1.0" - } -} diff --git a/test/.env b/test/.env deleted file mode 100644 index 7bfe784..0000000 --- a/test/.env +++ /dev/null @@ -1,4 +0,0 @@ -HASS_USERNAME=dev -HASS_PASSWORD=dev -LOVELACE_LOCAL_FILES=.js -LOVELACE_PLUGINS=thomasloven/lovelace-card-mod \ No newline at end of file diff --git a/src/main.ts b/zipup.sh similarity index 100% rename from src/main.ts rename to zipup.sh diff --git a/.devcontainer/devcontainer.json b/{{ cookiecutter.project_slug }}/.devcontainer/devcontainer.json similarity index 84% rename from .devcontainer/devcontainer.json rename to {{ cookiecutter.project_slug }}/.devcontainer/devcontainer.json index 254e5f0..963ea93 100644 --- a/.devcontainer/devcontainer.json +++ b/{{ cookiecutter.project_slug }}/.devcontainer/devcontainer.json @@ -1,5 +1,5 @@ { - "name": " Dev", + "name": "{{ cookiecutter.project_slug }} Dev", "image": "thomasloven/hass-custom-devcontainer", "postCreateCommand": "sudo -E container setup-dev && npm add", "containerEnv": { @@ -9,7 +9,8 @@ "mounts": [ "source=${localWorkspaceFolder},target=/config/www/workspace,type=bind", "source=${localWorkspaceFolder}/test,target=/config/test,type=bind", - "source=${localWorkspaceFolder}/test/configuration.yaml,target=/config/configuration.yaml,type=bind" + "source=${localWorkspaceFolder}/test/configuration.yaml,target=/config/configuration.yaml,type=bind", + "source=${localWorkspaceFolder}/custom_components,target=/config/custom_components,type=bind" ], "runArgs": ["--env-file", "${localWorkspaceFolder}/test/.env"], "extensions": [ diff --git a/{{ cookiecutter.project_slug }}/.gitattributes b/{{ cookiecutter.project_slug }}/.gitattributes new file mode 100644 index 0000000..a690dbd --- /dev/null +++ b/{{ cookiecutter.project_slug }}/.gitattributes @@ -0,0 +1,2 @@ +{{ cookiecutter.project_file }}.js binary +package-lock.json.binary diff --git a/{{ cookiecutter.project_slug }}/.gitignore b/{{ cookiecutter.project_slug }}/.gitignore new file mode 100644 index 0000000..ffe20ec --- /dev/null +++ b/{{ cookiecutter.project_slug }}/.gitignore @@ -0,0 +1,2 @@ +node_modules/ +custom_components/ \ No newline at end of file diff --git a/.vscode/tasks.json b/{{ cookiecutter.project_slug }}/.vscode/tasks.json similarity index 100% rename from .vscode/tasks.json rename to {{ cookiecutter.project_slug }}/.vscode/tasks.json diff --git a/LICENSE.txt b/{{ cookiecutter.project_slug }}/LICENSE.txt similarity index 96% rename from LICENSE.txt rename to {{ cookiecutter.project_slug }}/LICENSE.txt index cc7cc84..9ef2775 100644 --- a/LICENSE.txt +++ b/{{ cookiecutter.project_slug }}/LICENSE.txt @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2021 Thomas Lovén +Copyright (c) 2023 Thomas Lovén Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/{{ cookiecutter.project_slug }}/README.md similarity index 93% rename from README.md rename to {{ cookiecutter.project_slug }}/README.md index cdc3dfb..6e65e9e 100644 --- a/README.md +++ b/{{ cookiecutter.project_slug }}/README.md @@ -1,4 +1,4 @@ -# +# {{ cookiecutter.project_name }} [![hacs_badge](https://img.shields.io/badge/HACS-Default-orange.svg)](https://github.com/custom-components/hacs) diff --git a/{{ cookiecutter.project_slug }}/hacs.json b/{{ cookiecutter.project_slug }}/hacs.json new file mode 100644 index 0000000..0f41953 --- /dev/null +++ b/{{ cookiecutter.project_slug }}/hacs.json @@ -0,0 +1,4 @@ +{ + "name": "{{ cookiecutter.project_name }}", + "render_readme": true +} diff --git a/{{ cookiecutter.project_slug }}/package.json b/{{ cookiecutter.project_slug }}/package.json new file mode 100644 index 0000000..92c00d4 --- /dev/null +++ b/{{ cookiecutter.project_slug }}/package.json @@ -0,0 +1,27 @@ +{ + "name": "{{ cookiecutter.project_name }}", + "private": true, + "version": "0.1.0", + "description": "", + "scripts": { + "build": "rollup -c", + "watch": "rollup -c --watch" + }, + "author": "{{ cookiecutter.author }}", + "license": "MIT", + "devDependencies": { + "@babel/core": "^7.23.6", + "@babel/preset-env": "^7.23.6", + "@rollup/plugin-babel": "^6.0.4", + "@rollup/plugin-json": "^6.1.0", + "@rollup/plugin-node-resolve": "^15.2.3", + "rollup": "^2.79.1", + "rollup-plugin-terser": "^7.0.2", + "rollup-plugin-typescript2": "^0.36.0", + "typescript": "^5.3.3" + }, + "dependencies": { + "lit": "^3.1.0", + "tslib": "^2.6.2" + } +} diff --git a/rollup.config.js b/{{ cookiecutter.project_slug }}/rollup.config.mjs similarity index 71% rename from rollup.config.js rename to {{ cookiecutter.project_slug }}/rollup.config.mjs index 79cd270..b6b4375 100644 --- a/rollup.config.js +++ b/{{ cookiecutter.project_slug }}/rollup.config.mjs @@ -2,23 +2,21 @@ import nodeResolve from "@rollup/plugin-node-resolve"; import json from "@rollup/plugin-json"; import typescript from "rollup-plugin-typescript2"; import { terser } from "rollup-plugin-terser"; -import babel from "@rollup/plugin-babel"; +import { getBabelOutputPlugin } from "@rollup/plugin-babel"; const dev = process.env.ROLLUP_WATCH; export default { input: "src/main.ts", output: { - file: ".js", + file: "{{ cookiecutter.project_file }}.js", format: "es", }, plugins: [ nodeResolve(), json(), typescript(), - babel({ - exclude: "node_modules/**", - }), + getBabelOutputPlugin({ presets: ["@babel/preset-env"] }), !dev && terser({ format: { comments: false } }), ], }; diff --git a/test/lovelace.yaml b/{{ cookiecutter.project_slug }}/src/main.ts similarity index 100% rename from test/lovelace.yaml rename to {{ cookiecutter.project_slug }}/src/main.ts diff --git a/{{ cookiecutter.project_slug }}/test/.env b/{{ cookiecutter.project_slug }}/test/.env new file mode 100644 index 0000000..48351b9 --- /dev/null +++ b/{{ cookiecutter.project_slug }}/test/.env @@ -0,0 +1,4 @@ +HASS_USERNAME=dev +HASS_PASSWORD=dev +LOVELACE_LOCAL_FILES={{ cookiecutter.project_file }}.js +LOVELACE_PLUGINS="thomasloven/lovelace-card-mod" \ No newline at end of file diff --git a/test/configuration.yaml b/{{ cookiecutter.project_slug }}/test/configuration.yaml similarity index 100% rename from test/configuration.yaml rename to {{ cookiecutter.project_slug }}/test/configuration.yaml diff --git a/test/docker-compose.yml b/{{ cookiecutter.project_slug }}/test/docker-compose.yml similarity index 85% rename from test/docker-compose.yml rename to {{ cookiecutter.project_slug }}/test/docker-compose.yml index 10dfa7b..758a7e7 100644 --- a/test/docker-compose.yml +++ b/{{ cookiecutter.project_slug }}/test/docker-compose.yml @@ -12,5 +12,6 @@ services: - ./configuration.yaml:/config/configuration.yaml:ro - .:/config/test:ro - ..:/config/www/workspace + - ../custom_components,target=/config/custom_components ports: - 8125:8123 diff --git a/{{ cookiecutter.project_slug }}/test/lovelace.yaml b/{{ cookiecutter.project_slug }}/test/lovelace.yaml new file mode 100644 index 0000000..e69de29 diff --git a/tsconfig.json b/{{ cookiecutter.project_slug }}/tsconfig.json similarity index 100% rename from tsconfig.json rename to {{ cookiecutter.project_slug }}/tsconfig.json