Welcome to mirror list, hosted at ThFree Co, Russian Federation.

init-input.js « npm-init « example « promzard « node_modules - github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ba7781b3539e4d9743d2d21a36734c776c282eb9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
var fs = require('fs')
var path = require('path');

module.exports = {
  "name" : prompt('name',
    typeof name === 'undefined'
    ? basename.replace(/^node-|[.-]js$/g, ''): name),
  "version" : prompt('version', typeof version !== "undefined"
                              ? version : '0.0.0'),
  "description" : (function () {
      if (typeof description !== 'undefined' && description) {
        return description
      }
      var value;
      try {
          var src = fs.readFileSync('README.md', 'utf8');
          value = src.split('\n').filter(function (line) {
              return /\s+/.test(line)
                  && line.trim() !== basename.replace(/^node-/, '')
                  && !line.trim().match(/^#/)
              ;
          })[0]
              .trim()
              .replace(/^./, function (c) { return c.toLowerCase() })
              .replace(/\.$/, '')
          ;
      }
      catch (e) {
        try {
          // Wouldn't it be nice if that file mattered?
          var d = fs.readFileSync('.git/description', 'utf8')
        } catch (e) {}
        if (d.trim() && !value) value = d
      }
      return prompt('description', value);
  })(),
  "main" : (function () {
    var f
    try {
      f = fs.readdirSync(dirname).filter(function (f) {
        return f.match(/\.js$/)
      })
      if (f.indexOf('index.js') !== -1)
        f = 'index.js'
      else if (f.indexOf('main.js') !== -1)
        f = 'main.js'
      else if (f.indexOf(basename + '.js') !== -1)
        f = basename + '.js'
      else
        f = f[0]
    } catch (e) {}

    return prompt('entry point', f || 'index.js')
  })(),
  "bin" : function (cb) {
    fs.readdir(dirname + '/bin', function (er, d) {
      // no bins
      if (er) return cb()
      // just take the first js file we find there, or nada
      return cb(null, d.filter(function (f) {
        return f.match(/\.js$/)
      })[0])
    })
  },
  "directories" : function (cb) {
    fs.readdir('.', function (er, dirs) {
      if (er) return cb(er)
      var res = {}
      dirs.forEach(function (d) {
        switch (d) {
          case 'example': case 'examples': return res.example = d
          case 'test': case 'tests': return res.test = d
          case 'doc': case 'docs': return res.doc = d
          case 'man': return res.man = d
        }
      })
      if (Object.keys(res).length === 0) res = undefined
      return cb(null, res)
    })
  },
  "dependencies" : typeof dependencies !== 'undefined' ? dependencies
    : function (cb) {
      fs.readdir('node_modules', function (er, dir) {
        if (er) return cb()
        var deps = {}
        var n = dir.length
        dir.forEach(function (d) {
          if (d.match(/^\./)) return next()
          if (d.match(/^(expresso|mocha|tap|coffee-script|coco|streamline)$/))
            return next()
          fs.readFile('node_modules/' + d + '/package.json', function (er, p) {
            if (er) return next()
            try { p = JSON.parse(p) } catch (e) { return next() }
            if (!p.version) return next()
            deps[d] = '~' + p.version
            return next()
          })
        })
        function next () {
          if (--n === 0) return cb(null, deps)
        }
      })
    },
  "devDependencies" : typeof devDependencies !== 'undefined' ? devDependencies
    : function (cb) {
      // same as dependencies but for dev deps
      fs.readdir('node_modules', function (er, dir) {
        if (er) return cb()
        var deps = {}
        var n = dir.length
        dir.forEach(function (d) {
          if (d.match(/^\./)) return next()
          if (!d.match(/^(expresso|mocha|tap|coffee-script|coco|streamline)$/))
            return next()
          fs.readFile('node_modules/' + d + '/package.json', function (er, p) {
            if (er) return next()
            try { p = JSON.parse(p) } catch (e) { return next() }
            if (!p.version) return next()
            deps[d] = '~' + p.version
            return next()
          })
        })
        function next () {
          if (--n === 0) return cb(null, deps)
        }
      })
    },
  "scripts" : (function () {
    // check to see what framework is in use, if any
    try { var d = fs.readdirSync('node_modules') }
    catch (e) { d = [] }
    var s = typeof scripts === 'undefined' ? {} : scripts

    if (d.indexOf('coffee-script') !== -1)
      s.prepublish = prompt('build command',
                            s.prepublish || 'coffee src/*.coffee -o lib')

    var notest = 'echo "Error: no test specified" && exit 1'
    function tx (test) {
      return test || notest
    }

    if (!s.test || s.test === notest) {
      if (d.indexOf('tap') !== -1)
        s.test = prompt('test command', 'tap test/*.js', tx)
      else if (d.indexOf('expresso') !== -1)
        s.test = prompt('test command', 'expresso test', tx)
      else if (d.indexOf('mocha') !== -1)
        s.test = prompt('test command', 'mocha', tx)
      else
        s.test = prompt('test command', tx)
    }

    return s

  })(),

  "repository" : (function () {
    try { var gconf = fs.readFileSync('.git/config') }
    catch (e) { gconf = null }
    if (gconf) {
      gconf = gconf.split(/\r?\n/)
      var i = gconf.indexOf('[remote "origin"]')
      if (i !== -1) {
        var u = gconf[i + 1]
        if (!u.match(/^\s*url =/)) u = gconf[i + 2]
        if (!u.match(/^\s*url =/)) u = null
        else u = u.replace(/^\s*url = /, '')
      }
      if (u && u.match(/^git@github.com:/))
        u = u.replace(/^git@github.com:/, 'git://github.com/')
    }

    return prompt('git repository', u)
  })(),

  "keywords" : prompt(function (s) {
    if (!s) return undefined
    if (Array.isArray(s)) s = s.join(' ')
    if (typeof s !== 'string') return s
    return s.split(/[\s,]+/)
  }),
  "author" : config['init.author.name']
    ? {
        "name" : config['init.author.name'],
        "email" : config['init.author.email'],
        "url" : config['init.author.url']
      }
    : undefined,
  "license" : prompt('license', 'BSD')
}