transformer-pkg
Tool to automate lots of transformer module writing.
Usage
Usage: transformer-pkg <subcommand>
Subcommands:
init [<kind>] -- generate module files
src -- update transformer.jsonld
test -- src, then npm test
publish -- src, then npm publish
Flags:
-f --force Overwrite existing files.
-h --help Show these instructions. :)
Examples
transformer-pkg init type
> ls
> transformer-pkg init type
Transformer kind: type
Transformer type-id ([a-z0-9-]+): unix-time
Transformer description: Unixtime date, number of seconds since 1970.
transformer-pkg --> wrote index.js
transformer-pkg --> wrote test.js
transformer-pkg --> wrote README.md
transformer-pkg --> wrote package.json
transformer-pkg --> wrote transformer.jsonld
transformer-pkg --> init done.
Next, you should:
- run `npm install`
- modify index.js, test.js, and README.md as needed
- run `transformer-pkg test` till it works.
- run `transformer-pkg publish` to ship!
transformer-pkg publish will:
1. run `npm init` to prompt for npm package details
2. update `transformer.jsonld` with the latest src
3. run `npm publish`
> ls
README.md
index.js
package.json
test.js
transformer.jsonld
> cat * # below
package.json
type
index.js
type var transformer = ; moduleexports = // @context and type filled in automatically. 'id': 'unix-time' 'description': 'Unixtime date, number of seconds since 1970.' 'schema': "string";
test.js
type #!/usr/bin/env node
var transformer = require('dat-transformer');
var type = require('./');
// run stock type tests
var test = transformer.test.type(type);
// that should be enough, but you can also run your own tests:
/*
test('your test description', function (t) {
YOUR TEST CODE HERE
t.end();
});
*/
transformer-pkg init conversion
> ls
> transformer-pkg init conversion
Transformer kind: conversion
Transformer Convert From type-id ([a-z0-9-]+): unix-time
Transformer Convert To type-id ([a-z0-9-]+): js-date
transformer-pkg --> Transformer conversion-id: unix-time-to-js-date
Conversion is `async` or `sync`: sync
transformer-pkg --> wrote index.js
transformer-pkg --> wrote test.js
transformer-pkg --> wrote README.md
transformer-pkg --> wrote package.json
transformer-pkg --> wrote transformer.jsonld
transformer-pkg --> init done.
Next, you should:
- run `npm install`
- run `npm install --save transformer.unix-time transformer.js-date`
- modify index.js, test.js, and README.md as needed
- run `transformer-pkg test` till it works.
- run `transformer-pkg publish` to ship!
transformer-pkg publish will:
1. run `npm init` to prompt for npm package details
2. update `transformer.jsonld` with the latest src
3. run `npm publish`
> ls
README.md
index.js
package.json
test.js
transformer.jsonld
> cat * # below
package.js
conversion
index.js
conversion sync var transformer = ;var tUnixTime = ;var tJsDate = ;// require any other modules you may need here. moduleexports = transformer; // this is a synchronous conversion. { // compute the conversion output var output = YOUR CODE HERE; // if an error ocurrs, throw it. throw 'tUnixTimeToJsDate not implemented'; // else, return the result. return output;}
index.js
conversion async var transformer = ;var tUnixTime = ;var tJsDate = ;// require any other modules you may need here. moduleexports = transformer; // this is an asynchronous conversion. { // compute the conversion output var output = YOUR CODE HERE; // if an error ocurrs, send it in the callback (first arg). ; // else, call the callback with result (second arg). ;}
test.js
conversion sync #!/usr/bin/env nodevar transformer = ;var conv = ; // run stock conversion tests, and try expected input/output pairsvar test = transformertest // that should be enough, but you can also run your own tests:/* test('your test description', function (t) { YOUR TEST CODE HERE // test conversions this way: test.converts(t, conv, input, expectedOutput) t.end();}); */