1 | // function homogenize() {
|
2 |
|
3 | // const fsp = require('fs-promise');
|
4 | // const path = require('path');
|
5 | // const chalk = require('chalk');
|
6 | // const wc = require('wordcount');
|
7 |
|
8 | // let manuscript = {};
|
9 |
|
10 | // fsp.readJson(path.join('.', 'interim', 'tmp', '.prebook'))
|
11 | // .then((prebook) => {
|
12 |
|
13 | // manuscript.START_PAGE = parseInt(prebook.START_PAGE);
|
14 |
|
15 | // delete prebook.START_PAGE;
|
16 |
|
17 | // let counter = 0;
|
18 |
|
19 | // for (var key in prebook) {
|
20 | // if (prebook.hasOwnProperty(key)) {
|
21 | // // console.log(key);
|
22 | // // console.log(prebook[key]);
|
23 | // // console.log(prebook[key].len);
|
24 |
|
25 | // if (prebook[key].len > 160) {
|
26 |
|
27 | // let elem = prebook[key];
|
28 | // for (var tag in elem) {
|
29 | // if (elem.hasOwnProperty(tag)) {
|
30 | // let source = elem[tag];
|
31 | // if (tag !== 'len') {
|
32 | // // console.log('SOURCE IS HERE', source);
|
33 | // let textArr = source.split('. ');
|
34 | // // console.log('TEXTARRAY:', textArr.length);
|
35 | // if (textArr.length > 1) {
|
36 | // for (i = 0; i < textArr.length; i++) {
|
37 | // let newParaObj = {};
|
38 |
|
39 | // newParaObj[tag] = textArr[i];
|
40 |
|
41 | // counter += i;
|
42 | // manuscript[counter] = newParaObj;
|
43 |
|
44 | // console.log(`NEW PARA-${counter} HERE `, textArr[i]);
|
45 |
|
46 |
|
47 | // }
|
48 | // } else {
|
49 | // // console.log('HOUSTON WE\'VE A sitUATION');
|
50 | // // console.log(textArr[0]);
|
51 | // }
|
52 |
|
53 | // }
|
54 | // }
|
55 | // }
|
56 |
|
57 |
|
58 |
|
59 | // } else {
|
60 |
|
61 | // let newObj = prebook[key];
|
62 | // delete newObj.len;
|
63 |
|
64 | // manuscript[counter] = newObj;
|
65 |
|
66 | // counter++;
|
67 |
|
68 | // }
|
69 | // }
|
70 | // }
|
71 |
|
72 |
|
73 | // // let bookArr = Object.keys(prebook).map(key => prebook[key]); // Obj => Array conversion. Magic is here.
|
74 |
|
75 | // // console.log(bookArr.length);
|
76 |
|
77 |
|
78 |
|
79 | // // for ( let i = 0; i < bookArr.length; i++) {
|
80 | // // // console.log(wc(bookArr[i]));
|
81 | // // console.log(bookArr[i]);
|
82 | // // }
|
83 | // }).then(() => {
|
84 | // fsp.writeFile(path.join('.', 'interim', 'tmp', '.manuscript'), JSON.stringify(manuscript, null, 2))
|
85 | // .then(() => {
|
86 | // console.log(chalk.green('.manuscript prepared'));
|
87 | // }).catch((err) => {
|
88 | // if (err)
|
89 | // return console.log(chalk.bold.red('Failed to write .manuscript json', err));
|
90 | // });
|
91 | // }).catch((err) => {
|
92 | // if (err)
|
93 | // return console.log(chalk.red('Couldn\'t read prebook', err));
|
94 |
|
95 | // });
|
96 |
|
97 |
|
98 |
|
99 |
|
100 | // }
|
101 |
|
102 | // module.exports.homogenize = homogenize;
|