Skip to content
Raphael Kieling edited this page Oct 22, 2023 · 5 revisions

Doctorenv is a checklist tool that helps developers to check if they have everything to contribute in a project.

In the end the goal is Save time, nothing more! 🚀

Configuration File:

There are 2 ways to create your config that should be called doctorenv.config.js:

  • Returning an array
  • Returning a function

Check the examples in the root folder

Returning an array

// doctorenv.config.js
module.exports = [
    {
      title: 'NPM',
      task: async ({ bash }) => {
        await bash`npm --version`
      },
    }
]

Returning a function

This function is to facilitate the usage of the builder or other context parameters. Obviusly, you can return a function that returns an array:

// doctorenv.config.js
module.exports = () => [
    {
      title: 'NPM',
      task: async ({ bash }) => {
        await bash`npm --version`
      },
    }
]

But the recommended way would be:

// doctorenv.config.js
module.exports = ({ builder }) => {
  return builder
    .task('check package manager')
    .subTask('has npm', ({ bash }) => bash`npm --version`)
    .subTask('has yarn', ({ bash }) => bash`yarn --version`)
    .build()
}

Task:

A task if nothing more than a function that can fails or not. Fail means throw an error.

// doctorenv.config.js
module.exports = ({ builder }) => {
  return builder
    .task('will fail', () => {
      throw Error('any error')
    })
    .task('wont fail', () => {
      console.log('hello world!')
    })
    .build()
}

The advantage of being a function is that we can inject some context properties to make your life a little bit easier during the creation of the tasks.

// doctorenv.config.js
module.exports = ({ builder }) => {
  return builder
    .task('with context', (context) => {
      context.bash`cat my_file` // execute a bash command
      context.checkEnv('NODE_ENV') // check if the ENV exists
      context.delay(2000) // wait for 2 seconds
    })
    .build()
}

Suggestion and Fixable Suggestion

 builder
    .task('npm', (context) => ...)
    // It will show a suggestion message but will not fix for him
    .setSuggestion('fix it installing the npm')
    .task('check env', (context) => ...)
    // It will show a suggestion for the user with a yes/no prompt to fix it for him
    .setFixableSuggestion('fix it running the file bin', ({ bash }) => bash`source ./bin`)
    .build()
Clone this wiki locally