You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
2.4 KiB

  1. #!/usr/bin/env node
  2. /*
  3. Copyright (C) 2012 Yusuke Suzuki <utatane.tea@gmail.com>
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions are met:
  6. * Redistributions of source code must retain the above copyright
  7. notice, this list of conditions and the following disclaimer.
  8. * Redistributions in binary form must reproduce the above copyright
  9. notice, this list of conditions and the following disclaimer in the
  10. documentation and/or other materials provided with the distribution.
  11. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  12. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  13. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  14. ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  15. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  16. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  17. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  18. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  19. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  20. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  21. */
  22. /*jslint sloppy:true node:true */
  23. var fs = require('fs'),
  24. path = require('path'),
  25. root = path.join(path.dirname(fs.realpathSync(__filename)), '..'),
  26. escodegen = require(root),
  27. optionator = require('optionator')({
  28. prepend: 'Usage: esgenerate [options] file.json ...',
  29. options: [
  30. {
  31. option: 'config',
  32. alias: 'c',
  33. type: 'String',
  34. description: 'configuration json for escodegen'
  35. }
  36. ]
  37. }),
  38. args = optionator.parse(process.argv),
  39. files = args._,
  40. options;
  41. if (files.length === 0) {
  42. console.log(optionator.generateHelp());
  43. process.exit(1);
  44. }
  45. if (args.config) {
  46. try {
  47. options = JSON.parse(fs.readFileSync(args.config, 'utf-8'))
  48. } catch (err) {
  49. console.error('Error parsing config: ', err);
  50. }
  51. }
  52. files.forEach(function (filename) {
  53. var content = fs.readFileSync(filename, 'utf-8');
  54. console.log(escodegen.generate(JSON.parse(content), options));
  55. });
  56. /* vim: set sw=4 ts=4 et tw=80 : */