saku
saku copied to clipboard
Run code blocks as scripts
Currently each command in a code block is executed separately which makes a different process. This prevents using variables and only shell commands are easily used. For example:
export TEST="Hello World"
echo $TEST
The result will be empty:
+ export TEST="Hello World"
+ echo $TEST
I'm not sure whether this is possible in a cross-platform way. I'd like to keep saku as cross-platform as possible.
On the other hand, I'm planning to support sort of variable or environment variable in a new syntax.
# build
- NODE_ENV=production
npx browserify main.js
(NODE_ENV=production is set as env var.) This might solve your problem.
The main difference between Unix based OS (Linux\Mac) and Windows is how they identify the file to be executable or interpreted. I think by default it could be a bash\batch script, for example:
yarn install
It will create a temporary file tmp32423.sh
with executable bit (chmod +x) in Unix:
#!/bin/bash
yarn install
For Windows it will be tmp32423.bat
:
yarn install
Then it will let the operating system to figure out the rest. This can be extended to other types of scripts with Markdown highligh support, for example:
print('hello')
It will create a python file tmp3123.py
on all operating systems. In Unix it will add executable bit and the content will have a starter:
#!/usr/bin/env python
print('hello')
I think this will cover most of the common cases.
That said, I like the idea of environment variable syntax support. With #28 it will reduce data duplication and have cleaner code blocks. I would suggest it will just look for specific word structurce, that is: <Capital var name>=<value>
, to keep Markdown document flexibility. For example:
# build
> some description
To build .... `NODE_ENV=production` ... more text.
npx browserify main.js
Another example:
# production
In production you need the following environment variables set:
- NODE_ENV=production
## build
npx browserify main.js