UNPKG

686 BJavaScriptView Raw
1/*
2* preinstall.js - preinstall code for node-a2p3
3*
4* Copyright (C) Province of British Columbia, 2013
5*/
6
7var fs = require('fs')
8 , util = require('util')
9 , crypto = require('crypto')
10
11var CONFIG_FILE = process.cwd() + '/config.json'
12
13function randomString () {
14 return crypto.randomBytes( 8 ).toString( 'hex' )
15}
16
17if ( fs.existsSync( CONFIG_FILE ) ) {
18 console.log('Using existing config.json')
19} else {
20 console.log( 'Creating config.json' )
21 var data = fs.readFileSync( __dirname + '/default.config.json' ).toString()
22 // prepend random string so that AppID is unique if not changed
23 data = data.replace( /XXX/g , randomString() )
24 fs.writeFileSync( CONFIG_FILE, data )
25}
\No newline at end of file