1 | 'use strict';
|
2 |
|
3 | const path = require('path');
|
4 | const jdfUtils = require('jdf-utils');
|
5 | const $ = jdfUtils.base;
|
6 | const f = jdfUtils.file;
|
7 | const logger = require('jdf-log');
|
8 | const jdf = require('./jdf');
|
9 | const vfs = require('./VFS/VirtualFileSystem');
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | module.exports.init = function(rSource) {
|
20 | const concatFiles = jdf.config.output.concat;
|
21 | const source = path.resolve(f.realpath(rSource), jdf.getProjectPath());
|
22 | logger.verbose(`concat: ${source}`);
|
23 |
|
24 | Object.keys(concatFiles).forEach(desFile => {
|
25 | let content = '';
|
26 | desFile.forEach(singleFile => {
|
27 |
|
28 | const singleFilePath = path.resolve(source, singleFile);
|
29 | logger.verbose(`singleFilePath is ${singleFilePath}`);
|
30 |
|
31 | const vfsFile = vfs.queryFile(singleFilePath);
|
32 | if (vfsFile) {
|
33 | content += vfsFile.targetContent;
|
34 | }
|
35 | else {
|
36 | logger.error(`${singleFilePath} is not exists`);
|
37 | }
|
38 | });
|
39 | logger.verbose(`${desFilePath} file content is ${content}`);
|
40 |
|
41 | if (content !== '') {
|
42 | const desFilePath = path.resolve(source, desFile);
|
43 | vfs.addFile(desFilePath, content);
|
44 | }
|
45 | });
|
46 | }
|