• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1var PZ = require('../../promzard').PromZard
2var path = require('path')
3var input = path.resolve(__dirname, 'init-input.js')
4
5var fs = require('fs')
6var package = path.resolve(__dirname, 'package.json')
7var pkg
8
9fs.readFile(package, 'utf8', function (er, d) {
10  if (er) ctx = {}
11  try { ctx = JSON.parse(d); pkg = JSON.parse(d) }
12  catch (e) { ctx = {} }
13
14  ctx.dirname = path.dirname(package)
15  ctx.basename = path.basename(ctx.dirname)
16  if (!ctx.version) ctx.version = undefined
17
18  // this should be replaced with the npm conf object
19  ctx.config = {}
20
21  console.error('ctx=', ctx)
22
23  var pz = new PZ(input, ctx)
24
25  pz.on('data', function (data) {
26    console.error('pz data', data)
27    if (!pkg) pkg = {}
28    Object.keys(data).forEach(function (k) {
29      if (data[k] !== undefined && data[k] !== null) pkg[k] = data[k]
30    })
31    console.error('package data %s', JSON.stringify(data, null, 2))
32    fs.writeFile(package, JSON.stringify(pkg, null, 2), function (er) {
33      if (er) throw er
34      console.log('ok')
35    })
36  })
37})
38