Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Ken Payne committed Feb 10, 2023
2 parents bc07f56 + 5092b57 commit db1d3e3
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 13 deletions.
32 changes: 24 additions & 8 deletions evidence_ext/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ def __init__(self) -> None:
)
sys.exit(1)
self.config = EvidenceConfig(evidence_home=self.evidence_home)
self.npm = Invoker("npm")
self.npx = Invoker("npx")
self._npm = Invoker("npm")
self._npx = Invoker("npx")

def initialize(self, force: bool):
"""Initialize a new project."""
try:
self.npx.run_and_log(
self._npx.run_and_log(
*["degit", "evidence-dev/template", self.evidence_home]
)
except subprocess.CalledProcessError as err:
Expand All @@ -53,7 +53,11 @@ def invoke(self, command_name: str | None, *command_args: Any) -> None:
command_args: The arguments to pass to the command.
"""
try:
self.npm.run_and_log(*command_args)
command_args = (
"--prefix",
self.evidence_home,
) + command_args
self._npm.run_and_log(*command_args)
except subprocess.CalledProcessError as err:
log_subprocess_error(f"npm {command_name}", err, "npm invocation failed")
sys.exit(err.returncode)
Expand All @@ -72,14 +76,26 @@ def describe(self) -> models.Describe:
]
)

def npm(self, *command_args: Any) -> None:
"""Run 'npm' inside Evidence home with args."""
try:
command_args = (
"--prefix",
self.evidence_home,
) + command_args
self._npm.run_and_log(*command_args)
except subprocess.CalledProcessError as err:
log_subprocess_error("npm error", err, "npm invocation failed")
sys.exit(err.returncode)

def build(self):
"""Run 'npm run build' in the Evidence home dir."""
with self.config.suppress_config_file():
self.npm.run_and_log(*["install", "--prefix", self.evidence_home])
self.npm.run_and_log(*["run", "build", "--prefix", self.evidence_home])
self._npm.run_and_log(*["--prefix", self.evidence_home, "install"])
self._npm.run_and_log(*["--prefix", self.evidence_home, "run", "build"])

def dev(self):
"""Run 'npm run dev' in the Evidence home dir."""
with self.config.suppress_config_file():
self.npm.run_and_log(*["install", "--prefix", self.evidence_home])
self.npm.run_and_log(*["run", "dev", "--prefix", self.evidence_home])
self._npm.run_and_log(*["--prefix", self.evidence_home, "install"])
self._npm.run_and_log(*["--prefix", self.evidence_home, "run", "dev"])
14 changes: 12 additions & 2 deletions evidence_ext/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,21 @@ def describe(
sys.exit(1)


@app.command(
context_settings={"allow_extra_args": True, "ignore_unknown_options": True}
)
def npm(ctx: typer.Context, command_args: List[str]) -> None:
"""Run npm commands inside the Evidence project directory."""
ext.npm(*command_args)


@app.command()
def build(ctx: typer.Context):
def build(ctx: typer.Context) -> None:
"""Build the Evidence project."""
ext.build()


@app.command()
def dev(ctx: typer.Context):
def dev(ctx: typer.Context) -> None:
"""Launch the Evidence dev server."""
ext.dev()
3 changes: 0 additions & 3 deletions meltano.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ plugins:
initialize:
executable: evidence_extension
args: initialize
invoke:
executable: evidence_extension
args: invoke
settings_group_validation:
- - home_dir
# duckdb
Expand Down

0 comments on commit db1d3e3

Please sign in to comment.