The framework for transform anything
- Allow running shell script as processor
- Allow concurrent multi-processor for fast speed
- Support runtime configuration
-
Transform git commit message for your self own processor.
Use it with husky (Git hooks made easy)
{ "tranz": { "processors": ["echo \"$(cat)\n\nbranch: $(git rev-parse --abbrev-ref HEAD)\""] }, "husky": { "hooks": { "commit-msg": "npx tranz $HUSKY_GIT_PARAMS --write" } } }
Then the end of commit message would be appended with current branch name.
npm install tranz
# or use yarn
yarn add tranz
index.js
import { join } from 'path'
import tranz from 'tranz'
tranz(
'abc',
[
// function
require('./lib/wrapper')({ c: '-' }),
// return Processor[]
require('./lib/multi-wrapper')({ c: 0 }),
// [moduleId: string, options: any]
['./wrapper', { c: '_' }],
// module name with query string
'./wrapper?c=$',
// shell script
// get input from stdin
// output from stdout
'echo $(cat)-abc'
],
{
// Resolve processor path's base dir
// Default: $PWD
cwd: join(__dirname, 'lib'),
// Whether run tranz parallelly
// Note: parallel mode could enabled when all of the processor is typeof `string` (serializable)
// Default: false
parallel: false,
// Search runtime configuration.
// e.g. 1. `tranz` field in `package.json`
// 2. file named `.tranzrc`
// 3. file named `.tranzrc.js`
// Default: true
userc: true
// It's useful about below multi-config
// name: 'foo'
}
).then(output => {
console.log(output)
})
// Output:
// $_10-abc-01_$-abc
lib/wrapper.js
module.exports = ({ c }) =>
function(input) {
// this.cwd === __dirname
// this.parallel === false
// this.userc === true
// `this` is equals to options shallowly
return `${c}${input}${c}`
}
lib/multi-wrapper.js
module.exports = ({ c }) => [input => `${c}${input}${c}`, input => Promise.resolve(`${c + 1}${input}${c + 1}`)]
npm i tranz -D
npx tranz -h
tranz -i $PWD -p ./upper
cat $PWD | tranz -p ./upper
package.json
{
"tranz": {
"processors": [
[
"../processor-wrapper",
{
"char": "abc"
}
],
"../processor-upper",
"module-p-fix?q=halala"
],
"parallel": false
}
}
See source code
- _json-parse - run
JSON.parse(input, reviver?)
- _json-stringify - run
JSON.stringify(input, replacer?, space?)
tranz({ key: 'foo' }, [['_json-stringify', { space: 2 }]]).then(output => {
// {
// "key": "foo"
// }
})
Write the processor as follow:
// This processor depends `./upper` and `./trimLeft` processor
module.exports = opts => [require('./upper')({}), [require.resolve('./trimLeft'), {}]]
-
package.json
{ "tranz": { "foo": { "processors": ["echo foo"], "parallel": true }, "processors": ["echo default"], "parallel": false } }
-
Run command in shell
tranz --input="" # echo default tranz --input="" --name="foo" # echo foo
npm test
npm run benchmark
- file write [tranz-globs]
- file glob [tranz-globs]
- ignore files [tranz-globs]
This library is written and maintained by imcuttle, [email protected].
MIT