Simple email application for Android. Original source code: https://framagit.org/dystopia-project/simple-email
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.

117 lines
2.8 KiB

  1. #!/usr/bin/env node
  2. 'use strict'
  3. var conventionalChangelogWriter = require('./')
  4. var forEach = require('lodash').forEach
  5. var fs = require('fs')
  6. var meow = require('meow')
  7. var path = require('path')
  8. var split = require('split')
  9. var cli = meow(`
  10. Usage
  11. conventional-changelog-writer <path> [<path> ...]
  12. cat <path> | conventional-changelog-writer
  13. ,
  14. Example
  15. conventional-changelog-writer commits.ldjson
  16. cat commits.ldjson | conventional-changelog-writer
  17. ,
  18. Options
  19. -c, --context A filepath of a json that is used to define template variables
  20. -o, --options A filepath of a javascript object that is used to define options
  21. `, {
  22. flags: {
  23. context: {
  24. alias: `c`
  25. },
  26. options: {
  27. alias: `o`
  28. }
  29. }
  30. })
  31. var filePaths = []
  32. var flags = cli.flags
  33. forEach(cli.input, function (input) {
  34. filePaths.push(input)
  35. })
  36. var length = filePaths.length
  37. var templateContext
  38. var contextPath = flags.context
  39. if (contextPath) {
  40. try {
  41. templateContext = require(path.resolve(process.cwd(), contextPath))
  42. } catch (err) {
  43. console.error('Failed to get context from file ' + contextPath + '\n' + err)
  44. process.exit(1)
  45. }
  46. }
  47. var options
  48. var optionsPath = flags.options
  49. if (optionsPath) {
  50. try {
  51. options = require(path.resolve(process.cwd(), optionsPath))
  52. } catch (err) {
  53. console.error('Failed to get options from file ' + optionsPath + '\n' + err)
  54. process.exit(1)
  55. }
  56. }
  57. try {
  58. var stream = conventionalChangelogWriter(templateContext, options)
  59. } catch (err) {
  60. console.error(err.toString())
  61. process.exit(1)
  62. }
  63. function processFile (fileIndex) {
  64. var filePath = filePaths[fileIndex]
  65. fs.createReadStream(filePath)
  66. .on('error', function (err) {
  67. console.warn('Failed to read file ' + filePath + '\n' + err)
  68. if (++fileIndex < length) {
  69. processFile(fileIndex)
  70. }
  71. })
  72. .pipe(split(JSON.parse))
  73. .on('error', function (err) {
  74. console.warn('Failed to split commits in file ' + filePath + '\n' + err)
  75. })
  76. .pipe(stream)
  77. .on('error', function (err) {
  78. console.warn('Failed to process file ' + filePath + '\n' + err)
  79. if (++fileIndex < length) {
  80. processFile(fileIndex)
  81. }
  82. })
  83. .on('end', function () {
  84. if (++fileIndex < length) {
  85. processFile(fileIndex)
  86. }
  87. })
  88. .pipe(process.stdout)
  89. }
  90. if (!process.stdin.isTTY) {
  91. process.stdin
  92. .pipe(split(JSON.parse))
  93. .on('error', function (err) {
  94. console.error('Failed to split commits\n' + err)
  95. process.exit(1)
  96. })
  97. .pipe(stream)
  98. .on('error', function (err) {
  99. console.error('Failed to process file\n' + err)
  100. process.exit(1)
  101. })
  102. .pipe(process.stdout)
  103. } else if (length === 0) {
  104. console.error('You must specify at least one line delimited json file')
  105. process.exit(1)
  106. } else {
  107. processFile(0)
  108. }