Skip to content

Commit

Permalink
Codestyle config option added
Browse files Browse the repository at this point in the history
  • Loading branch information
miripiruni committed Jan 12, 2017
1 parent f856bf4 commit 78737aa
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
9 changes: 9 additions & 0 deletions migration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ where

Notice that templates in `./path-to-templates` will be overwritten.

## Codestyle config

You can create json file with several
[options](https://github.com/benjamn/recast/blob/52a7ec3eaaa37e78436841ed8afc948033a86252/lib/options.js#L1) that have recast.

Using `config` option you can pass path to json config:

`./migration/lib/index.js --input ./path-to-templates-dir --from 4 --to 8 --config ./codestyle-config.json`

# Static Lint


Expand Down
16 changes: 16 additions & 0 deletions migration/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ var argv = require('yargs')
default: false,
alias: 'l'
})
.option('config', {
describe: 'path to codestyle config for jscodeshift output',
alias: 'c'
})
.help('h')
.alias('help', 'h')
.argv;
Expand Down Expand Up @@ -57,6 +61,18 @@ for (var i = 0; i < transformers.length; i++) {
if (argv.lint)
cmd.push('--lint=true');

if (argv.config) {
try {
var config = require(argv.config);
} catch(e) {
console.error('Error: cannot require config file from ' + argv.config);
console.error(e);
process.exit(1);
}

cmd.push('--config=' + argv.config);
}

cmd = cmd.join(' ');

execSync(cmd, { stdio: 'inherit', encoding: 'utf8' })
Expand Down
7 changes: 6 additions & 1 deletion migration/lib/transformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,18 @@ Transformer.prototype.run = function(file, api, opts) {
var j = api.jscodeshift;
var ret = this.find(file, j);

var config = require(opts.config);

if (!config.quote)
config.quote = 'single';

if (opts.lint) {
if (ret.length === 0) return;
this.log(ret, file);
return;
}

return this.replace(ret, j).toSource({ quote: 'single' });
return this.replace(ret, j).toSource(config);
};

Transformer.prototype.log = function(ret, file) {
Expand Down

0 comments on commit 78737aa

Please sign in to comment.