UNPKG

1.41 kBJavaScriptView Raw
1#! /usr/bin/env node
2
3var fs = require('fs-extra')
4var path = require('path')
5
6var currentPath = process.cwd() // should be node_modules/@dadi/api
7var workspacePath = path.join(currentPath, 'workspace')
8var destinationDir = path.join(currentPath, '../../../workspace')
9
10// Only run if in a node_modules folder
11if (~currentPath.indexOf('node_modules')) {
12 fs.stat(destinationDir, (err, stats) => {
13 if (err && err.code && err.code === 'ENOENT') {
14 fs.copy(workspacePath, destinationDir, { overwrite: false }, (err) => {
15 if (err) return console.error(err)
16
17 fs.move(destinationDir + '/collections/vjoin', destinationDir + '/collections/1.0', { overwrite: false }, (err) => {
18 fs.move(destinationDir + '/collections/1.0/testdb', destinationDir + '/collections/1.0/library', { overwrite: false }, (err) => {
19 fs.remove(destinationDir + '/collections/vtest', err => {
20 fs.remove(destinationDir + '/endpoints/v1', err => {
21 fs.remove(destinationDir + '/media', err => {
22 fs.remove(destinationDir + '/hooks/layout.js', err => {
23 console.log('API: workspace directory created at', destinationDir)
24 })
25 })
26 })
27 })
28 })
29 })
30 })
31 } else {
32 console.log('API: Refusing to overwrite existing workspace directory')
33 }
34 })
35}