Skip to main content

jko.js

jko.js defines the ecosystem for running tasks.

  • The jko.js file must default export an object that can contain any number of fields.
  • jko.js defines a small set of fields:
    • scripts: Specifies the tasks or commands available.
    • dependencies: Lists the packages that the project depends on.
    • devDependencies: Lists the packages required for development.
    • envFile: Points to a file containing default environment variables.
    • logLevel: Sets the default verbosity level for logging.
    • packageManager: Sets the default package manager to be used.
  • All these fields are optional and can be included based on your needs.
  • Any field not defined in this set will be silently ignored, so you can add additional properties as desired.
export default {
scripts: {
yourScript1: "someCommand",
yourScript2: function (param1, paramN) {
// do something
}
},
envFile: './path/to/.env',
dependencies: {
packageName1: "#.#.#",
packageNameN: "#.#.#"
},
devDependencies: {
devPackageName1: "#.#.#",
devPackageNameN: "#.#.#"
},
packageManager: 'npm',
logLevel: 'error',
}
info

All these options can be overridden in one way or another through command line options.

warning

jko.js takes precedence over package.json.

tip

Although envFile and logLevel are not predefined in package.json, you can add them to the file, where they will be recognized by jko.

Extending Scripts with External Files

Leveraging the dynamic capabilities of JavaScript, jko.js files allow you to extend scripts and easily create dependency trees using external files—capabilities that package.json cannot accommodate due to its static JSON structure.

Steps:

  1. Create an External File: Define your additional scripts in a separate file and ensure that the file exports a default object containing a scripts field.

extra-scripts.js:

export default {
scripts: {
yourScript: "someCommand"
}
}
  1. Reference the File in Your jko.js file: Import or require the external file in jko.js.

jko.js:

import extraScripts from './extra-scripts'

This step links the external definitions to your main script setup.

  1. Merge the Script Definitions: Combine the scripts from the external file with your main set of scripts in the jko.js. You can do this manually or use a merging strategy (such as object spreading or a deep merge function) to consolidate all script definitions into one cohesive configuration.
 project-folder/
├── jko.js
├── extra-scripts.js
└── node_modules/somePackage/index.js

jko.js:

  import extraScripts from './extra-scripts'
import fromSomePackageScripts from 'somePackage'

export default {
scripts: {
...extraScripts.scripts,
...fromSomePackageScripts.scripts
}
}
  1. Test and Validate: Run jko to ensure that the extended scripts integrate seamlessly and work as expected. Adjust any configurations as needed.
$ jko

A similar approach can be applied to dependencies. Check out the example below!

Create a Custom Tree of Dependencies

 project-folder/
├── jko.js
├── dependencies.js
├── some/path/dependencies.js
├── another/path/dependencies.js
└── node_modules/package/dependencies.js

jko.js:

import { dependencies as dependencies1 } from './some/path/dependencies'
import { devDependencies } from './another/path/dependencies'
import { dependencies as dependencies2 } from 'package/dependencies'


export default {
dependencies: {
...dependencies1,
...dependencies2,
},
devDependencies
}