-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Relay: Improve Babel Transform Script
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
Showing
2 changed files
with
48 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); |
This file was deleted.
Oops, something went wrong.