-
Notifications
You must be signed in to change notification settings - Fork 3
/
pre_build.js
134 lines (115 loc) · 3.69 KB
/
pre_build.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/* eslint no-console: 0 */
require('dotenv').config();
// Assume production if not set
if (!process.env.NODE_ENV) {
process.env.NODE_ENV = 'production';
}
// Set Debugging up
if (!process.env.DEBUG) {
process.env.DEBUG = '*:info,*:warn,*:error';
}
// Debugging
const { debug, info, error } = require('./modules/debugger')('nuxeo-pre-build');
// npm packages
const Promise = require('bluebird');
const co = require('co');
const extend = require('lodash.defaultsdeep');
const fs = require('fs');
const path = require('path');
const yaml_config = require('node-yaml-config');
// Promisified
const writeFile = Promise.promisify(fs.writeFile);
// local packages
const pre_builder = require('./lib/pre_builder');
const metadata = {};
const get_repo_branches = function (config) {
const repo_branches = [];
Object.keys(config.repositories).forEach(function (repo_id) {
const repo = config.repositories[repo_id];
const target_base = path.join(__dirname, 'temp');
Object.keys(repo.branches).forEach(function (branch) {
info('Adding - repo: %s, branch: %s', repo_id, branch);
repo_branches.push({
target_source_path: path.join(target_base, repo_id, branch, 'src'),
target_build_path: path.join(target_base, repo_id, branch, 'site'),
repo_id: repo_id,
branch: branch,
});
});
});
return repo_branches;
};
const config = yaml_config.load(path.join(__dirname, 'config.yml'));
const branches = get_repo_branches(config);
debug('branches: %o', branches);
// npm packages
co(function* () {
console.time('Pre-Build');
// yield algoliaClearIndex();
// Copy Branches
const pre_build = [];
for (let i = 0; i < branches.length; i++) {
const { repo_id, branch, target_source_path: source_path } = branches[i];
info('Preparing Pre-Build - repo: %s, branch: %s', repo_id, branch);
pre_build.push(pre_builder({ repo_id, source_path, branch }));
}
// Pre-build
// console.time('prebuild');
const pre_build_result = yield pre_build;
// console.timeEnd('prebuild');
pre_build_result.forEach(function (data) {
extend(metadata, data);
});
debug('metadata keys: %o', Object.keys(metadata));
writeFile(
path.join(__dirname, 'temp/metadata.json'),
JSON.stringify(metadata)
)
.then(() => info('Created `temp/metadata.json`'))
.catch((err) => {
error('There was an issue creating `temp/metadata.json`');
throw err;
});
// Create Flat JSON list of files and assets
var flat_json = Object.keys(metadata.pages)
.filter((page_path) => !metadata.pages[page_path].is_redirect)
.map((page_path) => metadata.pages[page_path]);
flat_json = flat_json.concat(
Object.keys(metadata.assets).map(
(asset_path) => metadata.assets[asset_path]
)
);
writeFile(path.join(__dirname, 'editor.json'), JSON.stringify(flat_json))
.then(() => info('Created `editor.json`'))
.catch((err) => {
error('There was an issue creating `editor.json`');
throw err;
});
// writeFile(
// path.join(__dirname, 'search.json'),
// JSON.stringify(
// Object.keys(metadata.pages).map(id => {
// const { title, url, space, version, version_label, version_path, space_path } = metadata.pages[id];
// return {
// objectID: url,
// title,
// url,
// space,
// version,
// version_label,
// version_path,
// space_path
// };
// })
// )
// )
// .then(() => info('Created `search.json`'))
// .catch(err => {
// error('There was an issue creating `search.json`');
// throw err;
// });
console.timeEnd('Pre-Build');
}).catch(function (err) {
error(err);
throw err;
});