Comparing version 2.3.0 to 2.3.1
{ | ||
"name": "mrm-core", | ||
"version": "2.3.0", | ||
"version": "2.3.1", | ||
"description": "Utilities to make tasks for mrm", | ||
@@ -32,5 +32,5 @@ "author": { | ||
"babel-code-frame": "^6.26.0", | ||
"chalk": "^2.1.0", | ||
"fs-extra": "^4.0.1", | ||
"js-yaml": "^3.9.1", | ||
"chalk": "^2.3.0", | ||
"fs-extra": "^4.0.2", | ||
"js-yaml": "^3.10.0", | ||
"listify": "^1.0.0", | ||
@@ -43,11 +43,11 @@ "lodash": "^4.17.4", | ||
"strip-json-comments": "^2.0.1", | ||
"webpack-merge": "^4.1.0" | ||
"webpack-merge": "^4.1.1" | ||
}, | ||
"devDependencies": { | ||
"eslint": "^4.5.0", | ||
"eslint-config-tamia": "^4.2.0", | ||
"eslint-plugin-prettier": "^2.2.0", | ||
"jest": "^20.0.4", | ||
"memfs": "^2.5.0", | ||
"prettier": "^1.6.1", | ||
"eslint": "^4.11.0", | ||
"eslint-config-tamia": "^4.2.3", | ||
"eslint-plugin-prettier": "^2.3.1", | ||
"jest": "^21.2.1", | ||
"memfs": "^2.5.8", | ||
"prettier": "~1.8.2", | ||
"semantic-release": "^6.3.6", | ||
@@ -75,2 +75,2 @@ "semantic-release-tamia": "^1.1.1" | ||
} | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
# Marmot (mrm) core utils | ||
# Mrm core utils | ||
@@ -7,3 +7,3 @@ [![npm](https://img.shields.io/npm/v/mrm-core.svg)](https://www.npmjs.com/package/mrm-core) | ||
Utilities to write codemods for config files (JSON, YAML, INI, Markdown, etc.). Can be used to make tasks for [mrm](https://github.com/sapegin/mrm). | ||
Utilities to write codemods for config files (JSON, YAML, INI, Markdown, etc.). Can be used to make tasks for [Mrm](https://github.com/sapegin/mrm). | ||
@@ -10,0 +10,0 @@ ## Example |
@@ -88,3 +88,6 @@ // @ts-check | ||
// Remove a subcommand from a script | ||
const newCommand = command.split(/\s*&&\s*/).filter(cmd => !cmd.match(match)).join(' && '); | ||
const newCommand = command | ||
.split(/\s*&&\s*/) | ||
.filter(cmd => !cmd.match(match)) | ||
.join(' && '); | ||
pkg.set(['scripts', name], newCommand); | ||
@@ -91,0 +94,0 @@ return this; |
@@ -45,3 +45,7 @@ 'use strict'; | ||
it('methods should be chainable', () => { | ||
const result = ini(filename).set('foo', { b: 1 }).unset('foo').save().get(); | ||
const result = ini(filename) | ||
.set('foo', { b: 1 }) | ||
.unset('foo') | ||
.save() | ||
.get(); | ||
expect(result).toEqual([]); | ||
@@ -112,3 +116,5 @@ }); | ||
it('should create file', () => { | ||
ini(filename).set('foo', { bar: 'xxx' }).save(); | ||
ini(filename) | ||
.set('foo', { bar: 'xxx' }) | ||
.save(); | ||
expect(vol.toJSON()).toMatchSnapshot(); | ||
@@ -118,3 +124,5 @@ }); | ||
it('should create file with a comment', () => { | ||
ini(filename, 'comment').set('foo', { bar: 'xxx' }).save(); | ||
ini(filename, 'comment') | ||
.set('foo', { bar: 'xxx' }) | ||
.save(); | ||
expect(vol.toJSON()).toMatchSnapshot(); | ||
@@ -125,3 +133,5 @@ }); | ||
vol.fromJSON(json); | ||
ini(filename).set('foo', { bar: 'xxx' }).save(); | ||
ini(filename) | ||
.set('foo', { bar: 'xxx' }) | ||
.save(); | ||
expect(vol.toJSON()).toMatchSnapshot(); | ||
@@ -131,3 +141,5 @@ }); | ||
it('should print a message that file was created', () => { | ||
ini(filename).set('foo', { bar: 'xxx' }).save(); | ||
ini(filename) | ||
.set('foo', { bar: 'xxx' }) | ||
.save(); | ||
expect(log.added).toBeCalledWith('Create /test.ini'); | ||
@@ -138,3 +150,5 @@ }); | ||
vol.fromJSON(json); | ||
ini(filename).set('foo', { bar: 'xxx' }).save(); | ||
ini(filename) | ||
.set('foo', { bar: 'xxx' }) | ||
.save(); | ||
expect(log.added).toBeCalledWith('Update /test.ini'); | ||
@@ -141,0 +155,0 @@ }); |
@@ -48,3 +48,8 @@ 'use strict'; | ||
it('methods should be chainable', () => { | ||
const result = json(filename).set('a', 1).unset('a').merge({ a: 1 }).save().get(); | ||
const result = json(filename) | ||
.set('a', 1) | ||
.unset('a') | ||
.merge({ a: 1 }) | ||
.save() | ||
.get(); | ||
expect(result).toEqual({ a: 1 }); | ||
@@ -157,3 +162,5 @@ }); | ||
it('should create file', () => { | ||
json(filename).set('foo', 1).save(); | ||
json(filename) | ||
.set('foo', 1) | ||
.save(); | ||
expect(vol.toJSON()).toMatchSnapshot(); | ||
@@ -164,3 +171,5 @@ }); | ||
vol.fromJSON(fsJson); | ||
json(filename).set('foo', 1).save(); | ||
json(filename) | ||
.set('foo', 1) | ||
.save(); | ||
expect(vol.toJSON()).toMatchSnapshot(); | ||
@@ -170,3 +179,5 @@ }); | ||
it('should print a message that file was created', () => { | ||
json(filename).set('foo', 1).save(); | ||
json(filename) | ||
.set('foo', 1) | ||
.save(); | ||
expect(log.added).toBeCalledWith('Create /test.json'); | ||
@@ -177,3 +188,5 @@ }); | ||
vol.fromJSON(fsJson); | ||
json(filename).set('foo', 1).save(); | ||
json(filename) | ||
.set('foo', 1) | ||
.save(); | ||
expect(log.added).toBeCalledWith('Update /test.json'); | ||
@@ -180,0 +193,0 @@ }); |
@@ -41,3 +41,7 @@ 'use strict'; | ||
it('methods should be chainable', () => { | ||
const result = lines(filename).add(['a']).remove(['a']).save().get(); | ||
const result = lines(filename) | ||
.add(['a']) | ||
.remove(['a']) | ||
.save() | ||
.get(); | ||
expect(result).toEqual([]); | ||
@@ -67,2 +71,14 @@ }); | ||
it('should return empty lines as separate array items', () => { | ||
vol.fromJSON({ '/test.lines': 'a\n\n\nb' }); | ||
const file = lines(filename); | ||
expect(file.get()).toEqual(['a', '', '', 'b']); | ||
}); | ||
it('should ignore empty line at the end of file', () => { | ||
vol.fromJSON({ '/test.lines': 'a\nb\n' }); | ||
const file = lines(filename); | ||
expect(file.get()).toEqual(['a', 'b']); | ||
}); | ||
it('should accept default value', () => { | ||
@@ -142,9 +158,13 @@ const array = ['one', 'two']; | ||
it('should create file', () => { | ||
lines(filename).add(['foo', 'bar']).save(); | ||
lines(filename) | ||
.add(['foo', 'bar']) | ||
.save(); | ||
expect(vol.toJSON()).toMatchSnapshot(); | ||
}); | ||
it('should save file without empty lines', () => { | ||
it('should save file with empty lines', () => { | ||
vol.fromJSON({ '/new.lines': 'one\n\n\ntwo\n' }); | ||
lines('/new.lines').add(['foo', 'bar']).save(); | ||
lines('/new.lines') | ||
.add(['foo', 'bar']) | ||
.save(); | ||
expect(vol.toJSON()).toMatchSnapshot(); | ||
@@ -154,3 +174,5 @@ }); | ||
it('should print a message that file was created', () => { | ||
lines(filename).add(['foo']).save(); | ||
lines(filename) | ||
.add(['foo']) | ||
.save(); | ||
expect(log.added).toBeCalledWith('Create /test.lines'); | ||
@@ -161,3 +183,5 @@ }); | ||
vol.fromJSON(json); | ||
lines(filename).add(['foo']).save(); | ||
lines(filename) | ||
.add(['foo']) | ||
.save(); | ||
expect(log.added).toBeCalledWith('Update /test.lines'); | ||
@@ -168,5 +192,7 @@ }); | ||
vol.fromJSON(json); | ||
lines(filename).add(['one']).save(); | ||
lines(filename) | ||
.add(['one']) | ||
.save(); | ||
expect(log.added).toHaveBeenCalledTimes(0); | ||
}); | ||
}); |
@@ -57,3 +57,6 @@ 'use strict'; | ||
vol.fromJSON(json); | ||
const result = markdown(filename).addBadge('http://a.b/c.svg', 'http://a.b', 'c').save().get(); | ||
const result = markdown(filename) | ||
.addBadge('http://a.b/c.svg', 'http://a.b', 'c') | ||
.save() | ||
.get(); | ||
expect(result).toMatch('http://a.b/c.svg'); | ||
@@ -60,0 +63,0 @@ }); |
@@ -51,3 +51,6 @@ 'use strict'; | ||
}); | ||
const result = template('/text.txt', '/tmpl.txt').apply({}).save().get(); | ||
const result = template('/text.txt', '/tmpl.txt') | ||
.apply({}) | ||
.save() | ||
.get(); | ||
expect(result).toEqual(''); | ||
@@ -125,3 +128,5 @@ }); | ||
}); | ||
template('/text.txt', '/tmpl.txt').apply({ foo: 'Bar' }).save(); | ||
template('/text.txt', '/tmpl.txt') | ||
.apply({ foo: 'Bar' }) | ||
.save(); | ||
expect(vol.toJSON()).toMatchSnapshot(); | ||
@@ -134,3 +139,5 @@ }); | ||
}); | ||
template('/text.txt', '/tmpl.txt').apply({ foo: 'Bar' }).save(); | ||
template('/text.txt', '/tmpl.txt') | ||
.apply({ foo: 'Bar' }) | ||
.save(); | ||
expect(vol.toJSON()).toMatchSnapshot(); | ||
@@ -148,3 +155,5 @@ }); | ||
}); | ||
template('/text.txt', '/tmpl.txt').apply({}).save(); | ||
template('/text.txt', '/tmpl.txt') | ||
.apply({}) | ||
.save(); | ||
expect(log.added).toBeCalledWith('Create /text.txt'); | ||
@@ -158,3 +167,5 @@ }); | ||
}); | ||
template('/text.txt', '/tmpl.txt').apply({}).save(); | ||
template('/text.txt', '/tmpl.txt') | ||
.apply({}) | ||
.save(); | ||
expect(log.added).toBeCalledWith('Update /text.txt'); | ||
@@ -168,5 +179,7 @@ }); | ||
}); | ||
template('/text.txt', '/tmpl.txt').apply({ foo: 'Bar' }).save(); | ||
template('/text.txt', '/tmpl.txt') | ||
.apply({ foo: 'Bar' }) | ||
.save(); | ||
expect(log.added).toHaveBeenCalledTimes(0); | ||
}); | ||
}); |
@@ -47,3 +47,8 @@ 'use strict'; | ||
it('methods should be chainable', () => { | ||
const result = yaml(filename).set('a', 1).unset('a').merge({ a: 1 }).save().get(); | ||
const result = yaml(filename) | ||
.set('a', 1) | ||
.unset('a') | ||
.merge({ a: 1 }) | ||
.save() | ||
.get(); | ||
expect(result).toEqual({ a: 1 }); | ||
@@ -156,3 +161,5 @@ }); | ||
it('save() should create file', () => { | ||
yaml(filename).set('foo', 1).save(); | ||
yaml(filename) | ||
.set('foo', 1) | ||
.save(); | ||
expect(vol.toJSON()).toMatchSnapshot(); | ||
@@ -163,3 +170,5 @@ }); | ||
vol.fromJSON(json); | ||
yaml(filename).set('foo', 1).save(); | ||
yaml(filename) | ||
.set('foo', 1) | ||
.save(); | ||
expect(vol.toJSON()).toMatchSnapshot(); | ||
@@ -169,3 +178,5 @@ }); | ||
it('should print a message that file was created', () => { | ||
yaml(filename).set('foo', 1).save(); | ||
yaml(filename) | ||
.set('foo', 1) | ||
.save(); | ||
expect(log.added).toBeCalledWith('Create /test.yml'); | ||
@@ -176,3 +187,5 @@ }); | ||
vol.fromJSON(json); | ||
yaml(filename).set('foo', 1).save(); | ||
yaml(filename) | ||
.set('foo', 1) | ||
.save(); | ||
expect(log.added).toBeCalledWith('Update /test.yml'); | ||
@@ -179,0 +192,0 @@ }); |
@@ -16,3 +16,3 @@ // @ts-check | ||
originalContent = core.readFile(filename); | ||
lines = splitLines(originalContent); | ||
lines = splitLines(originalContent.trim()); | ||
} | ||
@@ -54,3 +54,3 @@ | ||
save() { | ||
const content = lines.filter(value => value.trim()).join('\n'); | ||
const content = lines.join('\n'); | ||
core.updateFile(filename, content, originalContent, exists); | ||
@@ -57,0 +57,0 @@ return this; |
@@ -43,3 +43,5 @@ // @ts-check | ||
throw Error( | ||
`Attempt to save the template "${filename}" without expanding: it doesn’t make sense. Call apply() before save().` | ||
`Attempt to save the template "${ | ||
filename | ||
}" without expanding: it doesn’t make sense. Call apply() before save().` | ||
); | ||
@@ -46,0 +48,0 @@ } |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 4 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
102251
46
2350
5
Updatedchalk@^2.3.0
Updatedfs-extra@^4.0.2
Updatedjs-yaml@^3.10.0
Updatedwebpack-merge@^4.1.1