Skip to content

Commit

Permalink
issue/116 Generate compile files on Compile command
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaime Terreu authored and Jaime Terreu committed Sep 18, 2024
1 parent db2cdb8 commit a98c089
Show file tree
Hide file tree
Showing 10 changed files with 251 additions and 43 deletions.
4 changes: 2 additions & 2 deletions .run/compile_dev.run.xml → .run/compile.run.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="compile:dev" type="PythonConfigurationType" factoryName="Python">
<configuration default="false" name="compile" type="PythonConfigurationType" factoryName="Python">
<module name="django-elm" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
Expand All @@ -14,7 +14,7 @@
<option name="ADD_SOURCE_ROOTS" value="true" />
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
<option name="SCRIPT_NAME" value="manage.py" />
<option name="PARAMETERS" value="djelm npm test_elm run compile:dev" />
<option name="PARAMETERS" value="djelm compile elm_programs" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
<option name="MODULE_MODE" value="false" />
Expand Down
13 changes: 7 additions & 6 deletions example/elm_programs/static_src/package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
{
"name": "elm_programs",
"version": "1.0.0",
"version": "1.0.0",
"license": "MIT",
"devDependencies": {
"@parcel/config-default": "^2.10.0",
"@parcel/core": "^2.10.0",
"@parcel/transformer-elm": "^2.10.0",
"elm": "^0.19.1-5",
"@parcel/config-default": "^2.12.0",
"@parcel/core": "^2.12.0",
"@parcel/transformer-elm": "^2.12.0",
"elm": "^0.19.1-6",
"elm-json": "^0.2.13",
"parcel": "^2.9.3",
"typescript": "^5.2.2"
"parcel": "^2.12.0",
"typescript": "^5.4.4"
},
"dependencies": {
"@icelab/defo": "^0.0.3"
Expand Down
15 changes: 9 additions & 6 deletions example/elm_programs/static_src/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions src/djelm/cookiecutters/entrypoint_template/cookiecutter.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"base_name": "",
"base_path": "",
"dir": "",
"program_name": "",
"scope": "",
"view_name": ""
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
Do not manually edit this file, it was auto-generated by djelm
https://github.com/Confidenceman02/djelm
*/
import defo from "@icelab/defo";

const views = {
djelmwidget{{cookiecutter.view_name}}: async (el: HTMLElement, data: any) => {
//@ts-ignore
const { Elm } = await import("../../../src/{{cookiecutter.base_path}}{{cookiecutter.program_name}}.elm")

const app = Elm.Widgets.{{cookiecutter.program_name}}.init({
node: el,
flags: data,
});

return {
// Called whenever the value of the `djelm` attribute changes
update: (newData, oldData) => {},
// Called when the element (or its djelm attribute) is removed from the DOM
destroy: () => {},
};
}
}

defo({ views, prefix: "{{cookiecutter.scope}}" })
30 changes: 30 additions & 0 deletions src/djelm/generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,17 @@ class ProgramBuilder(
"version": str,
},
)
EntrypointCookieExtra = TypedDict(
"EntrypointCookieExtra",
{
"base_name": str,
"base_path": str,
"dir": str,
"program_name": str,
"scope": str,
"view_name": str,
},
)

ModelCookieExtra = TypedDict(
"ModelCookieExtra",
Expand Down Expand Up @@ -158,6 +169,25 @@ def widget_cookie_cutter(
)


def entrypoint_cookie_cutter(
base_name: str, base_path: str, src_path: str, program_name: str, scope: str
) -> CookieCutter:
return CookieCutter[EntrypointCookieExtra](
file_dir=os.path.join(os.path.dirname(__file__), "cookiecutters"),
output_dir=os.path.join(src_path, *STUFF_NAMESPACE),
cookie_dir_name="entrypoint_template",
extra={
"base_name": base_name,
"base_path": base_path,
"dir": "entrypoints",
"program_name": program_name,
"scope": scope,
"view_name": view_name(program_name),
},
overwrite=True,
)


def model_cookie_cutter(
flags: Flags, program_name: str, tmp_dir: str, output_dir: str, module_path: str
):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
"version": "1.0.0",
"license": "MIT",
"devDependencies": {
"@parcel/config-default": "^2.10.0",
"@parcel/core": "^2.10.0",
"@parcel/transformer-elm": "^2.10.0",
"elm": "^0.19.1-5",
"@parcel/config-default": "^2.12.0",
"@parcel/core": "^2.12.0",
"@parcel/transformer-elm": "^2.12.0",
"elm": "^0.19.1-6",
"elm-json": "^0.2.13",
"parcel": "^2.9.3",
"typescript": "^5.2.2"
"parcel": "^2.12.0",
"typescript": "^5.4.4"
},
"dependencies": {
"@icelab/defo": "^0.0.3"
Expand Down
Loading

0 comments on commit a98c089

Please sign in to comment.