UNPKG

1.05 kBJavaScriptView Raw
1#! /usr/bin/env node
2
3var fs = require('fs')
4var mkdirp = require('mkdirp')
5var path = require('path')
6
7var currentPath = process.cwd() // should be node_modules/@dadi/api
8var configPath = path.join(__dirname, '../config/config.development.json.sample')
9var destinationDir = path.join(currentPath, '../../../config')
10var destinationFile = path.join(destinationDir, 'config.development.json')
11
12// Only run if in a node_modules folder
13if (~currentPath.indexOf('node_modules')) {
14 // mkdirp only creates the directory if it doesn't exist
15 mkdirp(destinationDir, (err, made) => {
16 if (err) throw err
17
18 fs.stat(destinationFile, (err, stats) => {
19 if (err && err.code && err.code === 'ENOENT') {
20 // destinationFile doesn't exist, so ok to write
21 fs.readFile(configPath, (err, data) => {
22 if (err) throw err
23
24 fs.writeFile(destinationFile, data, (err) => {
25 if (err) throw err
26
27 console.log('API configuration created at', destinationFile)
28 })
29 })
30 }
31 })
32 })
33}