Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

init-input.js 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. var fs = require('fs')
  2. var path = require('path');
  3. module.exports = {
  4. "name" : prompt('name',
  5. typeof name === 'undefined'
  6. ? basename.replace(/^node-|[.-]js$/g, ''): name),
  7. "version" : prompt('version', typeof version !== "undefined"
  8. ? version : '0.0.0'),
  9. "description" : (function () {
  10. if (typeof description !== 'undefined' && description) {
  11. return description
  12. }
  13. var value;
  14. try {
  15. var src = fs.readFileSync('README.md', 'utf8');
  16. value = src.split('\n').filter(function (line) {
  17. return /\s+/.test(line)
  18. && line.trim() !== basename.replace(/^node-/, '')
  19. && !line.trim().match(/^#/)
  20. ;
  21. })[0]
  22. .trim()
  23. .replace(/^./, function (c) { return c.toLowerCase() })
  24. .replace(/\.$/, '')
  25. ;
  26. }
  27. catch (e) {
  28. try {
  29. // Wouldn't it be nice if that file mattered?
  30. var d = fs.readFileSync('.git/description', 'utf8')
  31. } catch (e) {}
  32. if (d.trim() && !value) value = d
  33. }
  34. return prompt('description', value);
  35. })(),
  36. "main" : (function () {
  37. var f
  38. try {
  39. f = fs.readdirSync(dirname).filter(function (f) {
  40. return f.match(/\.js$/)
  41. })
  42. if (f.indexOf('index.js') !== -1)
  43. f = 'index.js'
  44. else if (f.indexOf('main.js') !== -1)
  45. f = 'main.js'
  46. else if (f.indexOf(basename + '.js') !== -1)
  47. f = basename + '.js'
  48. else
  49. f = f[0]
  50. } catch (e) {}
  51. return prompt('entry point', f || 'index.js')
  52. })(),
  53. "bin" : function (cb) {
  54. fs.readdir(dirname + '/bin', function (er, d) {
  55. // no bins
  56. if (er) return cb()
  57. // just take the first js file we find there, or nada
  58. return cb(null, d.filter(function (f) {
  59. return f.match(/\.js$/)
  60. })[0])
  61. })
  62. },
  63. "directories" : function (cb) {
  64. fs.readdir('.', function (er, dirs) {
  65. if (er) return cb(er)
  66. var res = {}
  67. dirs.forEach(function (d) {
  68. switch (d) {
  69. case 'example': case 'examples': return res.example = d
  70. case 'test': case 'tests': return res.test = d
  71. case 'doc': case 'docs': return res.doc = d
  72. case 'man': return res.man = d
  73. }
  74. })
  75. if (Object.keys(res).length === 0) res = undefined
  76. return cb(null, res)
  77. })
  78. },
  79. "dependencies" : typeof dependencies !== 'undefined' ? dependencies
  80. : function (cb) {
  81. fs.readdir('node_modules', function (er, dir) {
  82. if (er) return cb()
  83. var deps = {}
  84. var n = dir.length
  85. dir.forEach(function (d) {
  86. if (d.match(/^\./)) return next()
  87. if (d.match(/^(expresso|mocha|tap|coffee-script|coco|streamline)$/))
  88. return next()
  89. fs.readFile('node_modules/' + d + '/package.json', function (er, p) {
  90. if (er) return next()
  91. try { p = JSON.parse(p) } catch (e) { return next() }
  92. if (!p.version) return next()
  93. deps[d] = '~' + p.version
  94. return next()
  95. })
  96. })
  97. function next () {
  98. if (--n === 0) return cb(null, deps)
  99. }
  100. })
  101. },
  102. "devDependencies" : typeof devDependencies !== 'undefined' ? devDependencies
  103. : function (cb) {
  104. // same as dependencies but for dev deps
  105. fs.readdir('node_modules', function (er, dir) {
  106. if (er) return cb()
  107. var deps = {}
  108. var n = dir.length
  109. dir.forEach(function (d) {
  110. if (d.match(/^\./)) return next()
  111. if (!d.match(/^(expresso|mocha|tap|coffee-script|coco|streamline)$/))
  112. return next()
  113. fs.readFile('node_modules/' + d + '/package.json', function (er, p) {
  114. if (er) return next()
  115. try { p = JSON.parse(p) } catch (e) { return next() }
  116. if (!p.version) return next()
  117. deps[d] = '~' + p.version
  118. return next()
  119. })
  120. })
  121. function next () {
  122. if (--n === 0) return cb(null, deps)
  123. }
  124. })
  125. },
  126. "scripts" : (function () {
  127. // check to see what framework is in use, if any
  128. try { var d = fs.readdirSync('node_modules') }
  129. catch (e) { d = [] }
  130. var s = typeof scripts === 'undefined' ? {} : scripts
  131. if (d.indexOf('coffee-script') !== -1)
  132. s.prepublish = prompt('build command',
  133. s.prepublish || 'coffee src/*.coffee -o lib')
  134. var notest = 'echo "Error: no test specified" && exit 1'
  135. function tx (test) {
  136. return test || notest
  137. }
  138. if (!s.test || s.test === notest) {
  139. if (d.indexOf('tap') !== -1)
  140. s.test = prompt('test command', 'tap test/*.js', tx)
  141. else if (d.indexOf('expresso') !== -1)
  142. s.test = prompt('test command', 'expresso test', tx)
  143. else if (d.indexOf('mocha') !== -1)
  144. s.test = prompt('test command', 'mocha', tx)
  145. else
  146. s.test = prompt('test command', tx)
  147. }
  148. return s
  149. })(),
  150. "repository" : (function () {
  151. try { var gconf = fs.readFileSync('.git/config') }
  152. catch (e) { gconf = null }
  153. if (gconf) {
  154. gconf = gconf.split(/\r?\n/)
  155. var i = gconf.indexOf('[remote "origin"]')
  156. if (i !== -1) {
  157. var u = gconf[i + 1]
  158. if (!u.match(/^\s*url =/)) u = gconf[i + 2]
  159. if (!u.match(/^\s*url =/)) u = null
  160. else u = u.replace(/^\s*url = /, '')
  161. }
  162. if (u && u.match(/^git@github.com:/))
  163. u = u.replace(/^git@github.com:/, 'git://github.com/')
  164. }
  165. return prompt('git repository', u)
  166. })(),
  167. "keywords" : prompt(function (s) {
  168. if (!s) return undefined
  169. if (Array.isArray(s)) s = s.join(' ')
  170. if (typeof s !== 'string') return s
  171. return s.split(/[\s,]+/)
  172. }),
  173. "author" : config['init.author.name']
  174. ? {
  175. "name" : config['init.author.name'],
  176. "email" : config['init.author.email'],
  177. "url" : config['init.author.url']
  178. }
  179. : undefined,
  180. "license" : prompt('license', 'BSD')
  181. }