Genesis Foundation UI CLI
This repo contains our foundation-cli tool for rapid code scaffolding that adheres to best practices.

App Taks
Seeds can optionally define tasks in .genx/tasks.json
.
A task contains one or more steps, which can execute various commands.
{
"tasks": {
"hello": {
"name": "hello",
"description": "Sample task",
"steps": [
{
"say": "hello"
}
]
}
}
}
Run foundation-cli app
to see available tasks:
$ foundation-cli app
$ foundation-cli app <task>
Apps: Apps are seed instances. Tasks are commands provided by a seed.
$ foundation-cli app List all tasks
$ foundation-cli app hello Sample task
Run foundation-cli app hello
:
$ foundation-cli app hello
hello | hello
Executing commands
You can execute commands in a step as follows:
"exec": "gradle assemble"
runs a program or a script"spawn": "taskname"
runs another task (see below)"builtin": "hello"
runs a builtin task provided by CLI. Available tasks are in tasks folder."say": "text"
prints output
When using exec
check that your command works on different platforms (Windows, Linux, OS X).
Directories
You can provide cwd
option to set the working directory for a task or for an invidual task step.
{
"tasks": {
"build": {
"name": "build",
"description": "Build project",
"cwd": ".genx/generated",
"steps": [
{
"exec": "gradle assemble"
},
{
"exec": "npm run build"
},
{
"say": "all done"
}
]
}
}
}
Environment variables
You can set environment variables for a task or for an individual step.
You can add requiredEnv
array to a task to specify environment variables which must be set for it to run.
Note: in this example we could have simply done "exec": "git branch --show-current"
instead - it just illustrates environment variable use.
{
"tasks": {
"env": {
"name": "env",
"description": "Print current branch",
"env": {
"BRANCH": "$(git branch --show-current)"
},
"steps": [
{
"exec": "node -e \"console.log(process.env.BRANCH)\""
}
]
}
}
}
$ foundation-cli app env
env | node -e "console.log(process.env.BRANCH)"
master
Conditions
You can define a condition to determine whether a task should be executed. If it returns a zero exit code, steps will be executed, otherwise skipped.
{
"tasks": {
"diff": {
"name": "diff",
"description": "Detect changes",
"steps": [
{
"exec": "echo 'working tree contains changes'"
}
],
"condition": "git diff --exit-code"
}
}
}
Note: we could have done git diff --exit-code > /dev/null
to turn off Git output on Linux/OS X, but that's not supported on Windows.
Assuming we have some changes in the working directory, which haven't beedn added to Git yet:
$ foundation-cli app diff
diff | condition: git diff --exit-code
diff | condition exited with non-zero - skipping
After running Git add command:
$ foundation-cli app diff
diff | condition: git diff --exit-code
diff | echo 'working tree contains changes'
working tree contains changes
Dependent tasks
You can define dependent tasks:
{
"tasks": {
"first": {
"name": "first",
"description": "First task",
"steps": [
{
"say": "first"
}
]
},
"second": {
"name": "second",
"description": "Second task",
"steps": [
{
"spawn": "first"
},
{
"say": "second"
}
]
}
}
}
$ foundation-cli app second
second » first | first
second | second
Installation
To enable this module in your application, follow the steps below.
- Add
@genesislcap/foundation-cli
as a dependency in your package.json
file. Whenever you change the dependencies of your project, ensure you run the $ npm run bootstrap
command again. You can find more information in the package.json basics page.
{
...
"dependencies": {
...
"@genesislcap/foundation-cli": "latest"
...
},
...
}
License
Note: this project provides front-end dependencies and uses licensed components listed in the next section; thus, licenses for those components are required during development. Contact Genesis Global for more details.
Licensed components
Genesis low-code platform