News for hackers. Stuff that matters.
Re:Show HN: A Markdown based alternative to package.json scr... by divbzero on Wednesday October 16, 2024 @01:42AM (#41855954)
This is pretty cool.

For one of my projects, I tried something similar where I had code blocks in README.md like:

  Usage
  -----
  
  `pip install bar` and import `foo`:
  
  ```python
  import foo from bar
  ```
  
  Run `foo.alice` with default arguments:
  
  ```python
  foo.alice()
  ```
  
  Run `foo.bob` while specifying `baz`:
  
  ```python
  foo.bob(baz=0)
  ```
And a Makefile like:

  .PHONY: demo
  demo: venv
      @. .venv/bin/activate; sed -n '/^```python/,/^```/p' < README.md | sed '/^```/d' | python

  .PHONY: venv
  venv: .venv/bin/activate requirements.txt
      @. .venv/bin/activate; pip install -qU pip
      @. .venv/bin/activate; pip install -qUr requirements.txt
  
  .venv/bin/activate:
      @python3 -m venv .venv
So you could run all those README.md code blocks with:

  make demo
Re:Show HN: A Markdown based alternative to package.json scr... by timz on Wednesday October 16, 2024 @09:09AM (#41858668)
This is really cool approach.