Here are some examples of how to make scripts: either adhoc with ‘run’ or by modifying laoban.json
For example compile
{
"compile": {
"description": "Compiles the projects",
"guard": {"value": "${packageDetails.details.compile}", "default": true},
"commands": [{"name": "tsc", "command": "tsc --noEmit false --outDir dist", "status": true}]
}
}
When I make a command like this I often also include
"ls-compile": {
"description": "lists projects that will be compiled",
"guard": "${packageDetails.details.compile}",
"commands": ["js:process.cwd()"]
}
Here we have a command that is executed in the ‘dist’ subdirectory of each package
{
"demosRunningInADifferentDirectory": {
"description": "shows how to run a script in a different directory",
"commands": [
{"command": "js:process.cwd()", "directory": "dist"}
]
}
}
This depending on the language defined in the package.details.json file. If the language is not defined then nothing
will be executed
{
"compile": {
"description": "Compiles the project (either java or typescript)",
"commands": [
{
"name": "compile", "command": "tsc", "status": true,
"guard": {"value": "${packageDetails.details.language}", "equals": "typescript"}
},
{
"name": "compile", "command": "mvn compile", "status": true,
"guard": {"value": "${packageDetails.details.language}", "equals": "java"}
}
]
}
}
For example we want to test projects unless the project has test set to false. Thus if it’s not defined the tests will
still run
{
"test": {
"description": "runs ${packageManager} test",
"guard": {"value": "${projectDetails.details.test}", "default": true},
"commands": [{"name": "test", "command": "${packageManager} test", "status": true}]
}
}
For example we want to run a script differently on windows or linux.
{
"clean": {
"description": "Compiles the project (either java or typescript)",
"commands": [
{
"name": "compile", "command": "echo Linux ${packageDirectory}", "status": true,
"guard": {"value": "${os}", "equals": "Windows_NT"}
},
{
"name": "compile", "command": "echo Windows ${packageDirectory}", "status": true,
"guard": {"value": "${os}", "equals": "Linux"}
}
]
}
}
A good example here is the npm install command which on yarn is just yarn. There is no real point doing yarn in each
package if you are using workspaces, but not everyone does.
{
"install": {
"description": "Installs the project",
"commands": [
{
"name": "install", "command": "yarn", "status": true,
"guard": {"value": "${packageManager}", "equals": "yarn"}
},
{
"name": "install", "command": "npm install", "status": true,
"guard": {"value": "${packageManager}", "equals": "npm"}
}
]
}
}
| Purpose | Command |
|---|---|
| Copy a license file to each project | laoban run 'cp ${laobanDirectory}/LICENSE.md ${packageDirectory}' |
| remove the dist directories | laoban run 'file:rmDir(dist)' |
| remove the target directories | laoban run 'file:rmDir(target)' |
| remove node_modules directories | laoban run 'file:rmDir(node_modules)' |