Skip to content

Repository files navigation

Common Scripts

script namerun command
tsctsc [options]
jestjest [options]
tslinttslint [options]
depCheckdepCheck [options]
knexknex [options]
prettierprettier [options]

Commands

The script builder currently supports:

  1. Running scripts
  2. Ejecting scripts and installing dependencies in the callee repo
  3. Creating a git patch that applies user defined config options to the default config options
optioncommanddefinition
run<scriptName> [options]Run a CLI tool with options
ejecteject <scriptName>Eject a script and install dependencies in the callee repo
patchpatch <scriptName>Create a git patch applying user defined config options to default config options

Architecture

Each command for a script is represented as a series of serial steps carried out by executors. Executors are applied onto one another and transform a state object as they are called. Middleware can be added to control / introspect state entering or leaving an executor

Executors

Executors execute step-wise logic. Each executor can create side effects and modify a state object. The state object is passed from one executor to the next.

Executors have the type:

exportinterfaceIState{[state: string]: any}exporttypeExecutor=(input: IState)=>IState

Defining your own executor would look something like:

constmyExectuor=function(state){<dosomethingandormodifystate>return{ ...state}}myExecturor.prototype.name='myExecutor'

Script are defined in terms of the common executors:

  • initializeScript: input -> input
  • setOriginDir: input -> input + originDir
  • setArgsObject: input -> input + argsObject
  • setDefaultConfigPath: defaultPath -> input -> input + defaultConfigPath
  • getUserConfigPath: optionNames -> input + argsObject -> input + userSpecifiedConfigPath
  • getConfigPath: input + originDir + defaultConfigPath + userSpecifiedConfigPath -> input + configPath
  • getConfigObject: input + configPath -> input + configObject
  • removeOptionsFromArgsObj: optionNames -> input -> input
  • updateOptionsArr: input + argsObj -> input
  • handleRelativePathsInConfigObject: shouldModifyFunction, fieldsWithRelativePaths -> input + configObject + originDir -> input + - configObject
  • addFieldsToConfigObject: (updater = input -> fieldsObj) -> input + originDir -> input + configObject
  • writeConfigObjectToLocation: path -> input + configObj -> input + tempConfigObjPath
  • generateCommand: binLocation -> input + tempConfigObjPath + configObj + argsArr -> input + command
  • executeCommand -> input -> input + commandStatus

Middleware

Middleware can be added to control / introspect state entering or leaving an executor

Middleware has the type:

interfaceIState{[state: string]: any}typeExecutor=(input: IState)=>IStatetypeNext=(executor: Executor,state: IState)=>IStatetypeMiddleware=(next: Next)=>Next;

Defining your own middleware would look something like:

constmyMiddleware=((next: Next)=>(executor: Executor,state: IState)=>{<dosomethingbeforeexecutorruns>constnextState=next(executor,state)<dosomethingafterexecutorruns>returnnextState})asMiddleware

About

[WIP] Build your own `react-scripts`-like repo 🏗️ 📜

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages