]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/node_modules/init-package-json/node_modules/promzard/example/npm-init/init.js
Adding integrated tile server
[simantics/district.git] / org.simantics.maps.server / node / node-v4.8.0-win-x64 / node_modules / npm / node_modules / init-package-json / node_modules / promzard / example / npm-init / init.js
1 var PZ = require('../../promzard').PromZard
2 var path = require('path')
3 var input = path.resolve(__dirname, 'init-input.js')
4
5 var fs = require('fs')
6 var package = path.resolve(__dirname, 'package.json')
7 var pkg
8
9 fs.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 })