Skip to content

Commit

Permalink
Relay: Improve Babel Transform Script
Browse files Browse the repository at this point in the history
Summary: Makes a few improvements to the transform script in `babel-relay-plugin`:

 - Trims off `.js` extension and makes it executable.
 - More precise error messages for invalid input paths.
 - Accept source to transform via stdin.
 - Fix bug with path to dependent module.

Closes #424

Reviewed By: @kassens

Differential Revision: D2507189

fb-gh-sync-id: 97c71561cd5862735001632cdc8cbe7e491baf88
  • Loading branch information
yungsters authored and facebook-github-bot-2 committed Oct 6, 2015
1 parent 245df1e commit 1e0eb52
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 31 deletions.
48 changes: 48 additions & 0 deletions scripts/babel-relay-plugin/scripts/transform
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env node
/**
* Copyright 2013-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/

const minimist = require('minimist');
const fs = require('fs');
const transformGraphQL = require('../src/tools/transformGraphQL');

function main(argv) {
if (!argv.schema) {
console.warn('Usage: transform --file [file] --schema [schema]');
process.exit(1);
}
if (!fs.existsSync(argv.schema)) {
console.warn('Invalid schema: %s', argv.schema);
process.exit(1);
}

if (argv.file) {
if (!fs.existsSync(argv.file)) {
console.warn('Invalid file: %s', argv.schema);
process.exit(1);
}
transformSource(fs.readFileSync(argv.file, 'utf8'), argv.file);
} else {
var input = '';
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
input += chunk;
});
process.stdin.on('end', function() {
transformSource(input, 'stdin');
});
}

function transformSource(source, name) {
process.stdout.write(transformGraphQL(argv.schema, source, name));
}
}

main(minimist(process.argv));
31 changes: 0 additions & 31 deletions scripts/babel-relay-plugin/scripts/transform.js

This file was deleted.

0 comments on commit 1e0eb52

Please sign in to comment.