wishthis/node_modules/fomantic-ui/tasks/config/tasks.js

186 lines
5.3 KiB
JavaScript
Raw Normal View History

2023-08-17 09:47:40 +00:00
const
browserslist = require('browserslist'),
console = require('better-console'),
config = require('./user'),
release = require('./project/release')
2022-01-13 13:00:31 +00:00
;
2023-08-17 09:47:40 +00:00
let defaultBrowsers = browserslist(browserslist.defaults);
let userBrowsers = browserslist();
let hasBrowserslistConfig = JSON.stringify(defaultBrowsers) !== JSON.stringify(userBrowsers);
let prefix = config.prefix || {};
2023-08-17 09:47:40 +00:00
if (!prefix.overrideBrowserslist && !hasBrowserslistConfig) {
prefix.overrideBrowserslist = [
'last 2 Chrome versions',
'last 2 Firefox versions',
'last 2 Safari versions',
'last 4 iOS major versions',
'last 4 Android major versions',
'last 4 ChromeAndroid versions',
'Edge 12',
'ie 11',
];
}
// Node 12 does not support ??, so a little polyfill
let nullish = (value, fallback) => (value !== undefined && value !== null ? value : fallback);
2022-01-13 13:00:31 +00:00
module.exports = {
2023-08-17 09:47:40 +00:00
banner: nullish(config.banner, release.banner),
2022-01-13 13:00:31 +00:00
2023-08-17 09:47:40 +00:00
log: {
created: function (file) {
return 'Created: ' + file;
},
modified: function (file) {
return 'Modified: ' + file;
},
2022-01-13 13:00:31 +00:00
},
2023-08-17 09:47:40 +00:00
filenames: {
concatenatedCSS: 'semantic.css',
concatenatedJS: 'semantic.js',
concatenatedMinifiedCSS: 'semantic.min.css',
concatenatedMinifiedJS: 'semantic.min.js',
concatenatedRTLCSS: 'semantic.rtl.css',
concatenatedMinifiedRTLCSS: 'semantic.rtl.min.css',
2022-01-13 13:00:31 +00:00
},
2023-08-17 09:47:40 +00:00
regExp: {
2022-01-13 13:00:31 +00:00
2023-08-17 09:47:40 +00:00
comments: {
// remove all component headers in concatenated file
header: {
in: /\/\*!(?:(?!\/\*).)*# Fomantic-UI \d+\.\d+\.(?:(?!\/\*).)*MIT license(?:(?!\/\*).)*\*\/\n?/gs,
out: '',
},
2022-01-13 13:00:31 +00:00
2023-08-17 09:47:40 +00:00
// remove all comments from config files (.variable)
variables: {
in: /(\/\*[\S\s]+?\*\/+)[\S\s]+?\/\* End Config \*\//,
out: '$1',
2022-01-13 13:00:31 +00:00
},
2023-08-17 09:47:40 +00:00
// add version to first comment
license: {
in: /(^\/\*[\S\s]+)(# Fomantic-UI )([\S\s]+?\*\/)/,
out: '$1$2' + release.version + ' $3',
},
2022-01-13 13:00:31 +00:00
2023-08-17 09:47:40 +00:00
// adds uniform spacing around comments
large: {
in: /(\/\*{4}[\S\s]+?\*\/)/gm,
out: '\n\n$1\n',
},
small: {
in: /(\/\*---[\S\s]+?\*\/)/gm,
out: '\n$1\n',
},
tiny: {
in: /(\/\* [\S\s]+? \*\/)/gm,
out: '\n$1',
},
},
2022-01-13 13:00:31 +00:00
2023-08-17 09:47:40 +00:00
theme: /.*(\/|\\)themes(\/|\\).*?(?=(\/|\\))/gm,
2022-01-13 13:00:31 +00:00
},
2023-08-17 09:47:40 +00:00
settings: {
/* Remove Files in Clean */
del: {
silent: true,
},
concatCSS: {
rebaseUrls: false,
},
/* Comment Banners */
header: {
year: nullish(config.header.year, new Date().getFullYear()),
title: nullish(config.header.title, release.title),
version: nullish(config.header.version, release.version),
repository: nullish(config.header.repository, release.repository),
url: nullish(config.header.url, release.url),
},
plumber: {
less: {
errorHandler: function (error) {
let
regExp = {
variable: /@(\S.*?)\s/,
},
element
;
if (error && error.filename && /theme.less/.test(error.filename)) {
if (error.line === 9) {
element = regExp.variable.exec(error.message)[1];
if (element) {
console.error('Missing theme.config value for', element);
}
console.error('Most likely new UI was added in an update. You will need to add missing elements from theme.config.example');
} else {
console.error(error);
}
} else {
throw new Error(error);
}
this.emit('end');
},
},
},
/* Browserslist Prefix config */
prefix: prefix,
/* File Renames */
rename: {
minJS: { extname: '.min.js' },
minCSS: { extname: '.min.css' },
rtlCSS: { extname: '.rtl.css' },
rtlMinCSS: { extname: '.rtl.min.css' },
},
/* Minified CSS Concat */
minify: {
level: {
1: {
inline: false,
},
},
},
/* Minified JS Settings */
uglify: {
mangle: true,
output: {
comments: 'some',
},
},
/* Minified Concat CSS Settings */
concatMinify: {
level: {
1: {
inline: false,
specialComments: false,
},
},
},
2022-01-13 13:00:31 +00:00
2023-08-17 09:47:40 +00:00
/* Minified Concat JS */
concatUglify: {
mangle: true,
output: {
comments: 'some',
},
},
2022-01-13 13:00:31 +00:00
2023-08-17 09:47:40 +00:00
},
2022-01-13 13:00:31 +00:00
};