Skip to content

Commit

Permalink
Merge pull request #115 from Confidenceman02/release
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
Confidenceman02 authored Sep 7, 2024
2 parents 7701673 + db2cdb8 commit 14e3566
Show file tree
Hide file tree
Showing 13 changed files with 192 additions and 174 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## [0.16.0] - 2024-09-08

### Breaking

- djelm_src directory removed from app

All typescript entrypoint files are now managed internally.
If you were adding custom javascript to those files then stay on the previous version.

## [0.15.0] - 2024-07-15

### Added
Expand Down Expand Up @@ -250,6 +259,7 @@ type alias A_B__

- First version to pyPI

[0.16.0]: https://github.com/Confidenceman02/django-elm/compare/0.15.0...0.16.0
[0.15.0]: https://github.com/Confidenceman02/django-elm/compare/0.14.0...0.15.0
[0.14.0]: https://github.com/Confidenceman02/django-elm/compare/0.13.0...0.14.0
[0.13.0]: https://github.com/Confidenceman02/django-elm/compare/0.12.0...0.13.0
Expand Down
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@ elm_programs
│   └── dist
├── static_src
│   ├── .gitignore
│   ├── djelm_src
│   ├── elm.json
│   ├── package.json
│   └── src
Expand Down Expand Up @@ -257,8 +256,6 @@ elm_programs
│   └── dist
├── static_src
│   ├── .gitignore
│   ├── djelm_src
│   │   └── Main.ts *
│   ├── elm.json
│   ├── package.json
│   └── src
Expand Down Expand Up @@ -348,8 +345,6 @@ elm_programs
│   │   └── Main.js.map *
├── static_src
│   ├── .gitignore
│   ├── djelm_src
│   │   └── Main.ts
│   ├── elm.json
│   ├── package.json
│   └── src
Expand Down
5 changes: 0 additions & 5 deletions README_pypi.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ elm_programs
│   └── dist
├── static_src
│   ├── .gitignore
│   ├── djelm_src
│   ├── elm.json
│   ├── package.json
│   └── src
Expand Down Expand Up @@ -251,8 +250,6 @@ elm_programs
│   └── dist
├── static_src
│   ├── .gitignore
│   ├── djelm_src
│   │   └── Main.ts *
│   ├── elm.json
│   ├── package.json
│   └── src
Expand Down Expand Up @@ -342,8 +339,6 @@ elm_programs
│   │   └── Main.js.map *
├── static_src
│   ├── .gitignore
│   ├── djelm_src
│   │   └── Main.ts
│   ├── elm.json
│   ├── package.json
│   └── src
Expand Down
227 changes: 113 additions & 114 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins = [ "mypy_django_plugin.main" ]

[tool.poetry]
name = "djelm"
version = "0.15.0"
version = "0.16.0"
description = "A framework for using Elm programs in a Django project"
authors = ["Confidenceman02"]
readme = "README_pypi.md"
Expand Down
60 changes: 45 additions & 15 deletions src/djelm/generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,15 @@ def load_flags(
watch_mode: bool,
logger,
) -> ExitSuccess[Flags] | ExitFailure[None, Exception]:
"""
Load the flag config.
Is is either going to be from a djelm app or a pre-built one.
"""
"""Support loading a python flag module"""
...


class SupportsProgramCookieCutter(Protocol):
def cookie_cutter(
self, app_name: str, program_name: str, src_path: str, version: str
) -> CookieCutter:
"""Generate a cookie cutter config"""
"""Support generating a cookie cutter config for an Elm program"""
...


Expand All @@ -64,7 +60,7 @@ def cookie_cutter(
program_name: str,
src_path: str,
) -> CookieCutter:
"""Generate a cookie cutter config"""
"""Support generating a cookie cutter config for an Elm program Model"""
...


Expand All @@ -78,15 +74,15 @@ def applicators(
app_name: str,
logger,
) -> Sequence[TemplateApplicator]:
"""Move the template files to their respective targets."""
"""Support moving template files to their respective targets."""
...


class SupportsElmDependencies(Protocol):
def install_elm_deps(
self, working_dir: str, logger
) -> ExitSuccess[None] | ExitFailure[None, NPMError]:
"""Install Elm packages for the program needs"""
"""Support installing an Elm package"""
...


Expand Down Expand Up @@ -181,6 +177,8 @@ def model_cookie_cutter(


class WidgetModelGenerator(ModelBuilder):
"""Generates models for widget programs"""

def cookie_cutter(
self, flags: Flags, app_name: str, program_name: str, src_path: str
) -> CookieCutter:
Expand All @@ -200,6 +198,18 @@ def load_flags(
watch_mode: bool,
logger,
) -> ExitSuccess[Flags] | ExitFailure[None, Exception]:
"""
Load a flag class for the given program
app_path: The path of the djelm app
program_name: The Elm program name
from_source:
True = Load the flag class from a python module in the 'flags' directory
False = Load a default flag class
watch_mode:
True = In a watch mode context
False = Not in a watch mode context
"""
if from_source:
module = tag_file_name(program_name)
module_path = os.path.join(
Expand Down Expand Up @@ -248,6 +258,7 @@ def applicators(
logger.write(
f"""\n-- GENERATING WIDGET MODEL ---------------------------------------------- widget/{module_name(program_name)}"""
)
"""Move the generated Elm model to their target location"""
return [
TemplateCopyer(
os.path.join(template_dir, module_name(program_name) + ".elmf"),
Expand All @@ -263,6 +274,8 @@ def applicators(


class ModelChoiceFieldWidgetGenerator(ProgramBuilder):
"""Generate all files for the ModelChoiceField widget"""

def install_elm_deps(self, working_dir: str, logger):
deps = [
"elm-community/list-extra",
Expand Down Expand Up @@ -300,16 +313,20 @@ def applicators(
app_name: str,
logger,
) -> Sequence[TemplateApplicator]:
"""Apply all generated templates to their respective targets"""

logger.write(
"""\n-- GENERATING TEMPLATES -------------------------------------------------------- widget/ModelChoiceField"""
)
return [
# Program file
TemplateCopyer(
os.path.join(template_dir, module_name(program_name) + ".elmw"),
os.path.join(
src_dir, "src", "Widgets", module_name(program_name) + ".elm"
),
),
# Flags
TemplateCopyer(
os.path.join(template_dir, tag_file_name(program_name) + ".pyf"),
os.path.join(
Expand All @@ -319,6 +336,7 @@ def applicators(
tag_file_name(program_name) + ".py",
),
),
# Tags
TemplateCopyer(
os.path.join(template_dir, f"{tag_file_name(program_name)}_tags.py"),
os.path.join(
Expand All @@ -327,17 +345,20 @@ def applicators(
f"{tag_file_name(program_name)}_widget_tags.py",
),
),
# TS Entrypoint
TemplateCopyer(
os.path.join(template_dir, f"Widgets.{module_name(program_name)}.ts"),
os.path.join(
src_dir,
"djelm_src",
os.path.join(src_dir, *STUFF_NAMESPACE, "entrypoints"),
),
log=False,
),
]


class ProgramGenerator(ProgramBuilder):
"""Generate an Elm program"""

def install_elm_deps(
self, working_dir: str, logger
) -> ExitSuccess[None] | ExitFailure[None, NPMError]:
Expand Down Expand Up @@ -372,24 +393,29 @@ def applicators(
logger,
) -> Sequence[TemplateApplicator]:
logger.write(
f"""\n-- GENERATING TEMPLATES -------------------------------------------------------- widget/{module_name(program_name)}"""
f"""\n-- GENERATING TEMPLATES -------------------------------------------------------- {module_name(program_name)}"""
)
return [
# Program file
TemplateCopyer(
os.path.join(template_dir, module_name(program_name) + ".elm"),
os.path.join(src_dir, "src"),
),
# Template tags
TemplateCopyer(
os.path.join(template_dir, tag_file_name(program_name) + "_tags.py"),
os.path.join(app_dir, "templatetags"),
),
# Flags
TemplateCopyer(
os.path.join(template_dir, tag_file_name(program_name) + ".pyf"),
os.path.join(app_dir, "flags", tag_file_name(program_name) + ".py"),
),
# TS entry point
TemplateCopyer(
os.path.join(template_dir, module_name(program_name) + ".ts"),
os.path.join(src_dir, "djelm_src"),
os.path.join(src_dir, *STUFF_NAMESPACE, "entrypoints"),
log=False,
),
]

Expand Down Expand Up @@ -474,10 +500,14 @@ def applicators(


class TemplateCopyer(TemplateApplicator):
def __init__(self, src, destination) -> None:
"""Copy a template file to a given destination"""

def __init__(self, src: str, destination: str, log: bool = True) -> None:
self.src = src
self.destination = destination
self.log = log

def apply(self, logger) -> None:
shutil.copy(self.src, self.destination)
logger.write(f"\t\033[93m{self.destination}\033[0m")
if self.log:
logger.write(f"\t\033[93m{self.destination}\033[0m")
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import defo from "@icelab/defo";
const views = {
djelm{{cookiecutter.view_name}}: async (el: HTMLElement, data: any) => {
//@ts-ignore
const { Elm } = await import("../src/{{cookiecutter.program_name}}.elm")
const { Elm } = await import("../../../src/{{cookiecutter.program_name}}.elm")

const app = Elm.{{cookiecutter.program_name}}.init({
node: el,
Expand Down
1 change: 0 additions & 1 deletion src/djelm/project_template/hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"static/dist/.gitkeep",
"templates/.gitkeep",
"templates/{{cookiecutter.app_name}}/.gitkeep",
"static_src/djelm_src/.gitkeep",
"static_src/src/Models/.gitkeep",
"flags/.gitkeep",
]
Expand Down
Empty file.
23 changes: 13 additions & 10 deletions src/djelm/strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from typing import Iterable, cast

from django.conf import settings
from importlib.metadata import version
from typing_extensions import TypedDict
from djelm.forms.widgets.main import WIDGET_NAMES, WIDGET_NAMES_T
from djelm.generators import (
Expand All @@ -30,6 +29,8 @@
from .elm import Elm
from .npm import NPM
from .utils import (
DJELM_VERSION,
STUFF_ENTRYPOINTS,
STUFF_NAMESPACE,
get_app_path,
get_app_src_path,
Expand Down Expand Up @@ -136,7 +137,6 @@ class AddWidgetStrategy:
def run(self, logger) -> ExitSuccess[None] | ExitFailure[None, StrategyError]:
src_path = get_app_src_path(self.app_name)
app_path = get_app_path(self.app_name)
djelm_version = version("djelm")

if src_path.tag != "Success":
raise src_path.err
Expand All @@ -149,6 +149,13 @@ def run(self, logger) -> ExitSuccess[None] | ExitFailure[None, StrategyError]:
if install_deps_effect.tag != "Success":
raise install_deps_effect.err

try:
os.makedirs(os.path.join(src_path.value, *STUFF_NAMESPACE, "entrypoints"))
except FileExistsError:
pass
except FileNotFoundError as err:
raise err

# Make widgets dir in elm-stuff
try:
os.makedirs(os.path.join(src_path.value, *STUFF_NAMESPACE, "widgets"))
Expand All @@ -168,7 +175,7 @@ def run(self, logger) -> ExitSuccess[None] | ExitFailure[None, StrategyError]:
pass

cookie = self.handler.cookie_cutter(
self.app_name, self.widget_name, src_path.value, djelm_version
self.app_name, self.widget_name, src_path.value, DJELM_VERSION
)

# Cut cookie
Expand Down Expand Up @@ -220,14 +227,13 @@ class CompileStrategy:

def run(self, logger) -> ExitSuccess[None] | ExitFailure[None, StrategyError]:
src_path = get_app_src_path(self.app_name)

if src_path.tag == "Success":
try:
COMPILE_PROGRAM = f"""
"use strict";
const _core = require("@parcel/core");
let bundler = new _core.Parcel({{
entries: "./djelm_src/*.ts",
entries: "./{os.path.join(*STUFF_ENTRYPOINTS)}/*.ts",
defaultConfig: "@parcel/config-default",
mode: {"'production'" if self.build else "'development'"},
defaultTargetOptions: {{
Expand Down Expand Up @@ -301,7 +307,6 @@ def run(self, logger) -> ExitSuccess[None] | ExitFailure[None, StrategyError]:
src_path.value,
[
os.path.join(src_path.value, "src"),
os.path.join(src_path.value, "djelm_src"),
os.path.join(app_path.value, "flags"),
],
logger,
Expand Down Expand Up @@ -506,8 +511,6 @@ def run(
):
src_path = get_app_src_path(self.app_name)
app_path = get_app_path(self.app_name)
djelm_version = version("djelm")
stuff_namespace = ("elm-stuff", f"djelm_{djelm_version}")

if src_path.tag != "Success":
raise src_path.err
Expand All @@ -516,14 +519,14 @@ def run(
raise app_path.err

try:
os.makedirs(os.path.join(src_path.value, *stuff_namespace))
os.makedirs(os.path.join(src_path.value, *STUFF_NAMESPACE, "entrypoints"))
except FileExistsError:
pass
except FileNotFoundError as err:
raise err

program_ck = self.handler.cookie_cutter(
self.app_name, self.prog_name, src_path.value, djelm_version
self.app_name, self.prog_name, src_path.value, DJELM_VERSION
)

program_ck_effect = program_ck.cut(logger)
Expand Down
1 change: 1 addition & 0 deletions src/djelm/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

DJELM_VERSION = version("djelm")
STUFF_NAMESPACE = ("elm-stuff", f"djelm_{DJELM_VERSION}")
STUFF_ENTRYPOINTS = (*STUFF_NAMESPACE, "entrypoints")


def get_app_path(app_name) -> ExitSuccess[str] | ExitFailure[None, Exception]:
Expand Down
Loading

0 comments on commit 14e3566

Please sign in to comment.