const fs = require('fs');
const fsExtra = require('fs-extra');
const glob = require('glob');
const crypto = require('crypto');
const path = require('path');
const cwd = path.resolve(`${process.cwd()}`)
const cssPostfixFilename = `${cwd}/src/css-postfix`;
//let lessLastHash = fs.readFileSync(cssPostfixFilename, 'utf8').toString();
let lessLastHash;
let lessFiles;
const filesLessCache = `${cwd}/build/less/file-less.json`;
//const filesLessCacheBuild = `${cwd}/public/generated/css`;
const lessSettings = (grunt) => {
return {
options: {
sourceMap: true,
compress: true,
},
get files() {
const files = glob.sync(`${cwd}/public/less/**/*.*`)
let string = ''
for (let filename of files) {
string += fs.readFileSync(filename, 'utf8')
}
const lessHash = crypto.createHash('sha256').update(string).digest("hex");
if (lessLastHash === lessHash) {
grunt.log.writeln(`less hash is the same - ${lessHash}`)
return lessFiles
}/* else if (fs.existsSync(filesLessCacheBuild) && fs.existsSync(filesLessCache) && fs.readFileSync(cssPostfixFilename, 'utf8').toString() === lessHash) {
grunt.log.writeln(`less hash is the same in different process, using file less cache - ${lessHash}`)
return fs.readFileSync(filesLessCache, 'utf8').toString();
}*/
grunt.log.writeln(`less hash generating new build - ${lessHash}`)
lessLastHash = lessHash;
fs.writeFileSync(cssPostfixFilename, lessHash)
grunt.log.writeln('The css postfix file has been saved!');
const generateLessFiles = () => {
const themeDir = './public/less/theme';
const filesLess = {}
const root = './node_modules/bootswatch';
const watches = fs.readdirSync(root);
const themes = [
'default',
'solar',
];
const excluded = ['fonts'];
// css with random
const themeCss = {