Utilities to make tasks for Mrm
Node 4 is no longer supported, min Node version is 6.9.
npm install
can accept required package versions (#12, mrm#23):
const { install } = require('mrm-core')
install({ lodash: '4.17.3' }) // Install particular version
install(['lodash'], { versions: { lodash: '4.17.3', other: '1.0.0' } }) // Install particular version
Warning: Possibly breaking change: install will not read package.json
anymore, it will take installed packages by reading node_modules/pkg/package.json
.
packageJson.getScript
accepts an optional subcommand param:
const { packageJson } = require('mrm-core')
const file = packageJson({ default: 'values' })
file.getScript('test') // Return script
file.getScript('test', 'eslint') // Return a subcommand of a script
Note: subcommand is a command between &&
in an npm script. For example, prettier --write '**/*.js' && eslint . --fix
has two subcommands: prettier…
and eslint…
.
New method getExtsFromCommand
to get file extensions list from a command like eslint . --fix --ext .js,.jsx
:
const { getExtsFromCommand } = require('mrm-core')
getExtsFromCommand(`eslint . --fix --ext .js,.jsx`, 'ext')
// => ['js', 'jsx']
getExtsFromCommand(`prettier --write '**/*.js'`)
// => ['js']
install
/uninstall
will run Yarn if project is already using Yarn.
Expose EditorConfig utilities:
const { inferStyle, getStyleForFile, getIndent, format } = require('mrm-core')
inferStyle('for (;;) {\n alert(1);\n}\n')
// => { insert_final_newline: true, indent_style: 'space', indent_size: 2 }
getStyleForFile('test.js')
// => { insert_final_newline: false, indent_style: 'tab', indent_size: 'tab' }
getIndent({ indent_style: 'space', indent_size: 2 })
// => ' '
format('alert(1)\n', { insert_final_newline: false })
// => 'alert(1)'
// Only insert_final_newline is supported
insert_final_newline
is applied to all files on save.indent_size
and indent_style
options are applied to JSON files only.To add a comment:
const { json } = require('mrm-core')
json('test.json')
.set({
'// key': [['// Comment for key']],
key: 'Pizza'
})
.save()
lines()
method