UNPKG

2.66 kBJavaScriptView Raw
1function fetchAssets() {
2 const fsp = require('fs-promise');
3 const path = require('path');
4 const chalk = require('chalk');
5 const glob = require('glob');
6
7 let abelonerc = {};
8
9 fsp.readJson(path.join('.', '.abelonerc'))
10 .then((abelonerc) => {
11 let promiseOne = fsp.copy(path.join('.', 'interim', abelonerc.basename, 'images'), path.join('.', 'assets', 'images'))
12 .then(() => {
13 return console.log(chalk.blue(`Filling in images @bookiza: ${path.join('.', 'assets', 'images')}`));
14 }).catch((err) => {
15 if (err)
16 console.log(chalk.bold.red('Failed to move images…', err));
17 });
18
19 let promiseTwo = '';
20
21 glob(path.join('interim', abelonerc.basename, '*.htm*'), '', (er, files) => {
22
23 promiseTwo = fsp.readFile(path.join('.', files[0]), { encoding: 'utf8' })
24 .then((contents) => {
25
26 fsp.writeFile(path.join('.', 'interim', 'original.html'), contents)
27 .then(() => {
28 return console.log(chalk.blue(`Original html @interim: ${path.join('.', 'interim')}`));
29 }).catch(() => {
30 if (err)
31 console.log(chalk.bold.red('Failed to write HTML…', err));
32
33 });
34
35 }).catch((err) => {
36 if (err)
37 console.log(chalk.bold.red('Failed to pick up contents', err));
38 });
39
40 });
41
42 return Promise.all([promiseOne, promiseTwo]);
43
44 }).catch((err) => {
45 console.log(err);
46 });
47
48
49 // fsp.readFile(path.join('interim', 'normalized.html'), { encoding: 'utf8' })
50 // .then((contents) => {
51
52 // const cheerio = require('cheerio');
53 // const $ = cheerio.load(contents);
54
55
56 // let imagesNodeList = $('img');
57
58 // for (let i = 0; i < imagesNodeList.length; ++i) {
59
60 // let item = imagesNodeList[i];
61
62 // let handle = item.attribs.src;
63
64 // let newSrc = 'https://raw.githubusercontent.com/marvindanig/Milk-for-You-and-Me/master/assets/' + handle;
65
66 // imagesNodeList[i].src = newSrc;
67
68 // console.log(newSrc);
69 // }
70
71 // }).catch((err) => {
72 // if (err)
73 // console.log(chalk.bold.red('Failed to fetch images…', err));
74 // });
75
76
77}
78
79module.exports.assetize = fetchAssets;