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

default-input.js 6.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. var fs = require('fs')
  2. var glob = require('glob')
  3. var path = require('path')
  4. var validateLicense = require('validate-npm-package-license')
  5. var validateName = require('validate-npm-package-name')
  6. var npa = require('npm-package-arg')
  7. var semver = require('semver')
  8. // more popular packages should go here, maybe?
  9. function isTestPkg (p) {
  10. return !!p.match(/^(expresso|mocha|tap|coffee-script|coco|streamline)$/)
  11. }
  12. function niceName (n) {
  13. return n.replace(/^node-|[.-]js$/g, '').replace(' ', '-').toLowerCase()
  14. }
  15. function readDeps (test, excluded) { return function (cb) {
  16. fs.readdir('node_modules', function (er, dir) {
  17. if (er) return cb()
  18. var deps = {}
  19. var n = dir.length
  20. if (n === 0) return cb(null, deps)
  21. dir.forEach(function (d) {
  22. if (d.match(/^\./)) return next()
  23. if (test !== isTestPkg(d) || excluded[d])
  24. return next()
  25. var dp = path.join(dirname, 'node_modules', d, 'package.json')
  26. fs.readFile(dp, 'utf8', function (er, p) {
  27. if (er) return next()
  28. try { p = JSON.parse(p) }
  29. catch (e) { return next() }
  30. if (!p.version) return next()
  31. if (p._requiredBy) {
  32. if (!p._requiredBy.some(function (req) { return req === '#USER' })) return next()
  33. }
  34. deps[d] = config.get('save-exact') ? p.version : config.get('save-prefix') + p.version
  35. return next()
  36. })
  37. })
  38. function next () {
  39. if (--n === 0) return cb(null, deps)
  40. }
  41. })
  42. }}
  43. var name = package.name || basename
  44. var spec
  45. try {
  46. spec = npa(name)
  47. } catch (e) {
  48. spec = {}
  49. }
  50. var scope = config.get('scope')
  51. if (scope) {
  52. if (scope.charAt(0) !== '@') scope = '@' + scope
  53. if (spec.scope) {
  54. name = scope + '/' + spec.name.split('/')[1]
  55. } else {
  56. name = scope + '/' + name
  57. }
  58. }
  59. exports.name = yes ? name : prompt('package name', niceName(name), function (data) {
  60. var its = validateName(data)
  61. if (its.validForNewPackages) return data
  62. var errors = (its.errors || []).concat(its.warnings || [])
  63. var er = new Error('Sorry, ' + errors.join(' and ') + '.')
  64. er.notValid = true
  65. return er
  66. })
  67. var version = package.version ||
  68. config.get('init.version') ||
  69. config.get('init-version') ||
  70. '1.0.0'
  71. exports.version = yes ?
  72. version :
  73. prompt('version', version, function (version) {
  74. if (semver.valid(version)) return version
  75. var er = new Error('Invalid version: "' + version + '"')
  76. er.notValid = true
  77. return er
  78. })
  79. if (!package.description) {
  80. exports.description = yes ? '' : prompt('description')
  81. }
  82. if (!package.main) {
  83. exports.main = function (cb) {
  84. fs.readdir(dirname, function (er, f) {
  85. if (er) f = []
  86. f = f.filter(function (f) {
  87. return f.match(/\.js$/)
  88. })
  89. if (f.indexOf('index.js') !== -1)
  90. f = 'index.js'
  91. else if (f.indexOf('main.js') !== -1)
  92. f = 'main.js'
  93. else if (f.indexOf(basename + '.js') !== -1)
  94. f = basename + '.js'
  95. else
  96. f = f[0]
  97. var index = f || 'index.js'
  98. return cb(null, yes ? index : prompt('entry point', index))
  99. })
  100. }
  101. }
  102. if (!package.bin) {
  103. exports.bin = function (cb) {
  104. fs.readdir(path.resolve(dirname, 'bin'), function (er, d) {
  105. // no bins
  106. if (er) return cb()
  107. // just take the first js file we find there, or nada
  108. return cb(null, d.filter(function (f) {
  109. return f.match(/\.js$/)
  110. })[0])
  111. })
  112. }
  113. }
  114. exports.directories = function (cb) {
  115. fs.readdir(dirname, function (er, dirs) {
  116. if (er) return cb(er)
  117. var res = {}
  118. dirs.forEach(function (d) {
  119. switch (d) {
  120. case 'example': case 'examples': return res.example = d
  121. case 'test': case 'tests': return res.test = d
  122. case 'doc': case 'docs': return res.doc = d
  123. case 'man': return res.man = d
  124. case 'lib': return res.lib = d
  125. }
  126. })
  127. if (Object.keys(res).length === 0) res = undefined
  128. return cb(null, res)
  129. })
  130. }
  131. if (!package.dependencies) {
  132. exports.dependencies = readDeps(false, package.devDependencies || {})
  133. }
  134. if (!package.devDependencies) {
  135. exports.devDependencies = readDeps(true, package.dependencies || {})
  136. }
  137. // MUST have a test script!
  138. var s = package.scripts || {}
  139. var notest = 'echo "Error: no test specified" && exit 1'
  140. if (!package.scripts) {
  141. exports.scripts = function (cb) {
  142. fs.readdir(path.join(dirname, 'node_modules'), function (er, d) {
  143. setupScripts(d || [], cb)
  144. })
  145. }
  146. }
  147. function setupScripts (d, cb) {
  148. // check to see what framework is in use, if any
  149. function tx (test) {
  150. return test || notest
  151. }
  152. if (!s.test || s.test === notest) {
  153. var commands = {
  154. 'tap':'tap test/*.js'
  155. , 'expresso':'expresso test'
  156. , 'mocha':'mocha'
  157. }
  158. var command
  159. Object.keys(commands).forEach(function (k) {
  160. if (d.indexOf(k) !== -1) command = commands[k]
  161. })
  162. var ps = 'test command'
  163. if (yes) {
  164. s.test = command || notest
  165. } else {
  166. s.test = command ? prompt(ps, command, tx) : prompt(ps, tx)
  167. }
  168. }
  169. return cb(null, s)
  170. }
  171. if (!package.repository) {
  172. exports.repository = function (cb) {
  173. fs.readFile('.git/config', 'utf8', function (er, gconf) {
  174. if (er || !gconf) {
  175. return cb(null, yes ? '' : prompt('git repository'))
  176. }
  177. gconf = gconf.split(/\r?\n/)
  178. var i = gconf.indexOf('[remote "origin"]')
  179. if (i !== -1) {
  180. var u = gconf[i + 1]
  181. if (!u.match(/^\s*url =/)) u = gconf[i + 2]
  182. if (!u.match(/^\s*url =/)) u = null
  183. else u = u.replace(/^\s*url = /, '')
  184. }
  185. if (u && u.match(/^git@github.com:/))
  186. u = u.replace(/^git@github.com:/, 'https://github.com/')
  187. return cb(null, yes ? u : prompt('git repository', u))
  188. })
  189. }
  190. }
  191. if (!package.keywords) {
  192. exports.keywords = yes ? '' : prompt('keywords', function (s) {
  193. if (!s) return undefined
  194. if (Array.isArray(s)) s = s.join(' ')
  195. if (typeof s !== 'string') return s
  196. return s.split(/[\s,]+/)
  197. })
  198. }
  199. if (!package.author) {
  200. exports.author = config.get('init.author.name') ||
  201. config.get('init-author-name')
  202. ? {
  203. "name" : config.get('init.author.name') ||
  204. config.get('init-author-name'),
  205. "email" : config.get('init.author.email') ||
  206. config.get('init-author-email'),
  207. "url" : config.get('init.author.url') ||
  208. config.get('init-author-url')
  209. }
  210. : yes ? '' : prompt('author')
  211. }
  212. var license = package.license ||
  213. config.get('init.license') ||
  214. config.get('init-license') ||
  215. 'ISC'
  216. exports.license = yes ? license : prompt('license', license, function (data) {
  217. var its = validateLicense(data)
  218. if (its.validForNewPackages) return data
  219. var errors = (its.errors || []).concat(its.warnings || [])
  220. var er = new Error('Sorry, ' + errors.join(' and ') + '.')
  221. er.notValid = true
  222. return er
  223. })