forked from Netcentric/fe-build
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrenderClientLibs.js
More file actions
40 lines (32 loc) · 1.31 KB
/
Copy pathrenderClientLibs.js
File metadata and controls
40 lines (32 loc) · 1.31 KB
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
const path = require('path');
const fs = require('fs');
const { log, color } = require('./log');
const writeFile = require('./writeFile');
const mkFullPathSync = require('./mkFullPathSync');
module.exports = function renderClientLibs(clientLibObject, config) {
// extract from config
const { projectKey, destinationPath } = config.general;
const { name, folder, js, scss } = clientLibObject;
const { override } = config.clientlibs;
const { clientlibTemplate } = config.templates;
const absolutePath = path.join(destinationPath, folder);
log(__filename, `checking ${color('cyan', `${projectKey}.${name}`)}`);
// check if the folder already exist
if (!fs.existsSync(absolutePath)) {
log(__filename, `Folder for ${name} does not exist creating ${folder}`);
mkFullPathSync(absolutePath);
log(__filename, `Creating ${color('cyan', `${projectKey}.${name}`)}`);
}
// if there is a scss or js we write the css.txt
// write css.txt
if (scss) {
writeFile(path.join(absolutePath, 'css.txt'), `${scss.replace('.scss', '.css')}`, override);
}
// write css.txt
if (js) {
writeFile(path.join(absolutePath, 'js.txt'), `${js}`, override);
}
// write .content.xml
const content = clientlibTemplate(name, projectKey);
writeFile(path.join(absolutePath, '.content.xml'), content, override);
};