Skip to content

Commit

Permalink
Unified script-css functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
goransle authored and TorsteinHonsi committed Dec 12, 2023
1 parent c7b6c22 commit 48edb89
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 56 deletions.
File renamed without changes.
File renamed without changes.
63 changes: 22 additions & 41 deletions tools/gulptasks/dashboards/scripts-css.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,6 @@

const gulp = require('gulp');

/* *
*
* Constants
*
* */

const COPY_DIRECTORIES = [
'css',
'gfx'
];

const TARGET_DIRECTORY = 'code';

/* *
*
* Tasks
Expand All @@ -30,39 +17,33 @@ const TARGET_DIRECTORY = 'code';
* Promise to keep
*/
function dashboardsScriptsCSS() {

const fslib = require('../lib/fs');
const log = require('../lib/log');
const path = require('path');
const { copyCSS } = require('../scripts-css');

const TARGET_DIRECTORY = 'code';

const dashboardsConfig = {
sources: [
'css/dashboards/',
'gfx/dashboards-icons/'
],
target: TARGET_DIRECTORY + '/dashboards',
replacePath: 'dashboards/',
exclude: []
};

const datagridConfig = {
sources: 'css/datagrid/',
target: TARGET_DIRECTORY + '/datagrid',
replacePath: 'datagrid/',
exclude: []
};

return new Promise(resolve => {
log.message('Copy css and gfx ...');

const dashboardsCSS = path.join('css', 'dashboards.css');
const dashboardsGFX = path.join('gfx', 'dashboards-icons');

fslib.copyFile(
dashboardsCSS,
path.join('code', 'dashboards', dashboardsCSS)
);

fslib.copyAllFiles(
dashboardsGFX,
path.join('code', 'dashboards', dashboardsGFX),
true
);

const dataGridCSS = path.join('css', 'datagrid.css');

fslib.copyFile(
dataGridCSS,
path.join('code', 'dashboards', dataGridCSS)
);

fslib.copyFile(
dataGridCSS,
path.join('code', 'datagrid', dataGridCSS)
);
copyCSS(dashboardsConfig);
copyCSS(datagridConfig);

log.success('Done.');

Expand Down
70 changes: 55 additions & 15 deletions tools/gulptasks/scripts-css.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,56 @@ const COPY_DIRECTORIES = [

const TARGET_DIRECTORY = 'code';

const highchartsConfig = {
sources: COPY_DIRECTORIES,
target: TARGET_DIRECTORY,
replacePath: '',
exclude: [
'dashboards/',
'datagrid/',
'dashboards-icons/'
]
};

function handleConfig(config) {
const defaultConfig = {
sources: [], // Directories to copy over
target: 'code', // Directory to copy to
exclude: [], // Files and directories to exclude. Uses strubg.include()
replacePath: '' // String to replace from the path of the original file when copying
};

// Ensure sources is an array
if (typeof config.sources === 'string') {
config.sources = [config.sources];
}

// Merge the defaultConfig with the provided config
return { ...defaultConfig, ...config };
}

function copyCSS(config) {
const fslib = require('./lib/fs');
const path = require('path');

config = handleConfig(config);

config.sources.forEach(
copyPath => fslib.copyAllFiles(
copyPath,
path.join(
config.target,
config.replacePath ?
copyPath.replace(config.replacePath, '') :
copyPath
),
true,
fileName => !config.exclude
.some(name => fileName.includes(name))
)
);
}

/* *
*
* Tasks
Expand All @@ -30,26 +80,12 @@ const TARGET_DIRECTORY = 'code';
* Promise to keep
*/
function task() {

const fslib = require('./lib/fs');
const log = require('./lib/log');
const path = require('path');

return new Promise(resolve => {

log.message('Generating css ...');

COPY_DIRECTORIES.forEach(
copyPath => fslib.copyAllFiles(
copyPath,
path.join(TARGET_DIRECTORY, copyPath),
true,
fileName =>
!['dashboards', 'datagrid']
.some(name => fileName.includes(`${name}.css`))

)
);
copyCSS(highchartsConfig);

log.success('Copied CSS');

Expand All @@ -58,3 +94,7 @@ function task() {
}

gulp.task('scripts-css', task);

module.exports = {
copyCSS
};

0 comments on commit 48edb89

Please sign in to comment.