2 var path = require('path');
5 "name" : prompt('name',
6 typeof name === 'undefined'
7 ? basename.replace(/^node-|[.-]js$/g, ''): name),
8 "version" : prompt('version', typeof version !== "undefined"
10 "description" : (function () {
11 if (typeof description !== 'undefined' && description) {
16 var src = fs.readFileSync('README.md', 'utf8');
17 value = src.split('\n').filter(function (line) {
18 return /\s+/.test(line)
19 && line.trim() !== basename.replace(/^node-/, '')
20 && !line.trim().match(/^#/)
24 .replace(/^./, function (c) { return c.toLowerCase() })
30 // Wouldn't it be nice if that file mattered?
31 var d = fs.readFileSync('.git/description', 'utf8')
33 if (d.trim() && !value) value = d
35 return prompt('description', value);
37 "main" : (function () {
40 f = fs.readdirSync(dirname).filter(function (f) {
41 return f.match(/\.js$/)
43 if (f.indexOf('index.js') !== -1)
45 else if (f.indexOf('main.js') !== -1)
47 else if (f.indexOf(basename + '.js') !== -1)
53 return prompt('entry point', f || 'index.js')
55 "bin" : function (cb) {
56 fs.readdir(dirname + '/bin', function (er, d) {
59 // just take the first js file we find there, or nada
60 return cb(null, d.filter(function (f) {
61 return f.match(/\.js$/)
65 "directories" : function (cb) {
66 fs.readdir('.', function (er, dirs) {
69 dirs.forEach(function (d) {
71 case 'example': case 'examples': return res.example = d
72 case 'test': case 'tests': return res.test = d
73 case 'doc': case 'docs': return res.doc = d
74 case 'man': return res.man = d
77 if (Object.keys(res).length === 0) res = undefined
81 "dependencies" : typeof dependencies !== 'undefined' ? dependencies
83 fs.readdir('node_modules', function (er, dir) {
87 dir.forEach(function (d) {
88 if (d.match(/^\./)) return next()
89 if (d.match(/^(expresso|mocha|tap|coffee-script|coco|streamline)$/))
91 fs.readFile('node_modules/' + d + '/package.json', function (er, p) {
93 try { p = JSON.parse(p) } catch (e) { return next() }
94 if (!p.version) return next()
95 deps[d] = '~' + p.version
100 if (--n === 0) return cb(null, deps)
104 "devDependencies" : typeof devDependencies !== 'undefined' ? devDependencies
106 // same as dependencies but for dev deps
107 fs.readdir('node_modules', function (er, dir) {
111 dir.forEach(function (d) {
112 if (d.match(/^\./)) return next()
113 if (!d.match(/^(expresso|mocha|tap|coffee-script|coco|streamline)$/))
115 fs.readFile('node_modules/' + d + '/package.json', function (er, p) {
116 if (er) return next()
117 try { p = JSON.parse(p) } catch (e) { return next() }
118 if (!p.version) return next()
119 deps[d] = '~' + p.version
124 if (--n === 0) return cb(null, deps)
128 "scripts" : (function () {
129 // check to see what framework is in use, if any
130 try { var d = fs.readdirSync('node_modules') }
132 var s = typeof scripts === 'undefined' ? {} : scripts
134 if (d.indexOf('coffee-script') !== -1)
135 s.prepublish = prompt('build command',
136 s.prepublish || 'coffee src/*.coffee -o lib')
138 var notest = 'echo "Error: no test specified" && exit 1'
140 return test || notest
143 if (!s.test || s.test === notest) {
144 if (d.indexOf('tap') !== -1)
145 s.test = prompt('test command', 'tap test/*.js', tx)
146 else if (d.indexOf('expresso') !== -1)
147 s.test = prompt('test command', 'expresso test', tx)
148 else if (d.indexOf('mocha') !== -1)
149 s.test = prompt('test command', 'mocha', tx)
151 s.test = prompt('test command', tx)
158 "repository" : (function () {
159 try { var gconf = fs.readFileSync('.git/config') }
160 catch (e) { gconf = null }
162 gconf = gconf.split(/\r?\n/)
163 var i = gconf.indexOf('[remote "origin"]')
166 if (!u.match(/^\s*url =/)) u = gconf[i + 2]
167 if (!u.match(/^\s*url =/)) u = null
168 else u = u.replace(/^\s*url = /, '')
170 if (u && u.match(/^git@github.com:/))
171 u = u.replace(/^git@github.com:/, 'git://github.com/')
174 return prompt('git repository', u)
177 "keywords" : prompt(function (s) {
178 if (!s) return undefined
179 if (Array.isArray(s)) s = s.join(' ')
180 if (typeof s !== 'string') return s
181 return s.split(/[\s,]+/)
183 "author" : config['init.author.name']
185 "name" : config['init.author.name'],
186 "email" : config['init.author.email'],
187 "url" : config['init.author.url']
190 "license" : prompt('license', 'BSD')