1 | /*!
|
2 |
|
3 | ----------------------------------------------------------------------------
|
4 | | qewd: Quick and Easy Web Development |
|
5 | | |
|
6 | | Copyright (c) 2017-18 M/Gateway Developments Ltd, |
|
7 | | Redhill, Surrey UK. |
|
8 | | All rights reserved. |
|
9 | | |
|
10 | | http://www.mgateway.com |
|
11 | | Email: rtweed@mgateway.com |
|
12 | | |
|
13 | | |
|
14 | | Licensed under the Apache License, Version 2.0 (the "License"); |
|
15 | | you may not use this file except in compliance with the License. |
|
16 | | You may obtain a copy of the License at |
|
17 | | |
|
18 | | http://www.apache.org/licenses/LICENSE-2.0 |
|
19 | | |
|
20 | | Unless required by applicable law or agreed to in writing, software |
|
21 | | distributed under the License is distributed on an "AS IS" BASIS, |
|
22 | | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
23 | | See the License for the specific language governing permissions and |
|
24 | | limitations under the License. |
|
25 | ----------------------------------------------------------------------------
|
26 |
|
27 | 9 May 2018
|
28 |
|
29 | */
|
30 |
|
31 | var fs = require('fs-extra');
|
32 | var path = require('path');
|
33 |
|
34 | function createJSONFile(contentsObj, rootPath, fileName) {
|
35 | var packageJsonFile = path.join(rootPath, fileName);
|
36 | fs.outputJsonSync(packageJsonFile, contentsObj, {spaces: 2});
|
37 | fs.chmodSync(packageJsonFile, '0664');
|
38 | };
|
39 |
|
40 | module.exports = function(messageObj) {
|
41 | var docArray = this.db.global_directory();
|
42 | var self = this;
|
43 |
|
44 | var documentContent = {};
|
45 | var rootPath = __dirname;
|
46 | var fileName = 'documents.json';
|
47 | if (messageObj.params) {
|
48 | if (messageObj.params.rootPath) rootPath = messageObj.params.rootPath;
|
49 | if (messageObj.params.fileName) fileName = messageObj.params.fileName;
|
50 | }
|
51 |
|
52 | docArray.forEach(function(docName) {
|
53 | if (docName !== self.userDefined.config.sessionDocumentName) {
|
54 | var doc = self.db.use(docName);
|
55 | documentContent[docName] = doc.getDocument(true);
|
56 | }
|
57 | });
|
58 |
|
59 | createJSONFile(documentContent, rootPath, fileName);
|
60 |
|
61 | };
|