Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 | import * as glob from 'glob';
import path from 'path';
import fs from 'fs-extra';
import { fileURLToPath } from 'url';
import postcss from 'postcss';
import postcssAtImport from 'postcss-import';
import postcssNesting from 'postcss-nested';
import postcssFor from 'postcss-for';
import postcssEach from 'postcss-each';
import postcssRemoveComments from 'postcss-discard-comments';
import arg from 'arg';
import chokidar from 'chokidar';
import postCssDeprecatedSelector from './plugins/postcss-deprecated-selector.js';
import postCssFigletComment from './plugins/postcss-figlet-comment.js';
import postCssHeaderComment from './plugins/postcss-header-comment.js';
import postCssAddScope from './plugins/postcss-add-scope.js';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const root = path.resolve(__dirname, '../');
const args = arg({
'--system': String,
'--watch': Boolean,
'--production': Boolean,
'--scoped': Boolean,
'--scope-class-name': String,
});
if (!args['--system']) {
console.error(`Please provide a subsystem name.`);
}
const FILENAME = `${args['--system']}${args['--scoped'] ? '.scoped' : ''}${args['--production'] ? '.cosmos' : ''}`;
const config = {
// Directory paths (used by chokidar for watching)
directories: {
input: path.resolve(root, `src/${args['--system']}`),
subThemes: path.resolve(root, `src/sub-themes`),
},
// Input sources (CSS files to be processed)
sources: {
input: path.resolve(root, `src/${args['--system']}/**/*.css`),
hooks: path.resolve(root, `public/cosmos/**/*.css`),
subThemes: path.resolve(root, `src/sub-themes/**/*.css`),
config: path.resolve(root, `public/config/*.css`),
},
// Output files
outputs: {
css: path.resolve(root, `dist/css/${FILENAME}.css`),
imports: path.resolve(root, `build/${FILENAME}.imports.css`),
},
};
const plugins = [
postcssAtImport(),
postcssEach(),
postcssFor(),
postcssNesting(),
postCssDeprecatedSelector(),
postcssRemoveComments(),
];
/**
* Conditionally add a warning text to the slds2.css file
* when generating the slds2 for production.
*/
if (args['--system'] === 'slds2') {
// determines if a scoped version of css should be generated.
if (args['--scoped']) {
const scopeName = args['--scope-class-name'] || ''; // scope defaults to .slds-scope when left empty
plugins.push(postCssAddScope({ scope: scopeName }));
}
if (args['--production']) {
plugins.push(postCssHeaderComment());
plugins.push(postCssFigletComment());
}
}
const processCss = (css, ...plugins) => {
postcss(...plugins)
.process(css, { from: '' })
.then((result) => {
fs.outputFile(config.outputs.css, result.css);
});
console.log(`Compiling ${config.outputs.css}...`);
};
/**
* Import order needs to follow the order of design-system-internal's
* ui/components/_index.scss imports.
* https://github.com/salesforce-ux-emu/design-system-internal
*/
const importOrder = [
'cosmos.hooks.custom-props',
'cosmos.deprecated.hooks.custom-props',
'cosmos.shared.hooks.custom-props',
'cosmos.component.hooks.custom-props',
'reset',
'icon.type',
'activityTimeline',
'badge',
'breadcrumbs',
'buttonGroup',
'button.deprecated',
'button',
'buttonStateful',
'buttonDualStateful',
'buttonIcon.deprecated',
'buttonIcon',
'colorPicker',
'icon',
'accordion',
'dynamicIcons',
'dynamicMenu',
'carousel',
'card.deprecated',
'card',
'chat',
'datetimePicker',
'form-element',
'input',
'counter',
'textarea',
'radioGroup',
'radioButtonGroup',
'checkbox',
'checkboxToggle',
'checkboxButton',
'checkboxButtonGroup',
'select',
'dockedFormFooter',
'slider',
'fileSelector',
'pageHeader',
'pageHeader.deprecated',
'brandBand',
'panel',
'popover',
'popover.deprecated',
'tooltip.deprecated',
'tooltip',
'menu',
'picklist.deprecated',
'combobox',
'duelingPicklist.deprecated',
'duelingPicklist',
'datepicker.deprecated',
'datepicker',
'dockedComposer.deprecated',
'dockedComposer',
'dockedUtilityBar',
'dropZone',
'globalHeader',
'globalNavigation',
'expression',
'builderHeader',
'publisher',
'feed',
'modal',
'map',
'appLauncher',
'visualPicker',
'pill',
'wizard.deprecated',
'pathSimple.deprecated',
'path',
'progressBar',
'progressIndicator',
'progressRing',
'richTextEditor',
'spinner',
'splitView',
'tile',
'tabs',
'verticalNavigation.deprecated',
'verticalNavigation',
'alert',
'prompt',
'toast',
'scopedNotifications',
'notifications',
'trialBar',
'lookup.deprecated',
'avatar',
'avatarGroup',
'file',
'dataTable',
'trees',
'treeGrid',
'expandableSection',
'illustration',
'regions',
'welcomeMat',
'summaryDetail',
'setupAssistant',
'template',
// Utilities
'utilities.deprecated',
'grid',
'alignment',
'mediaObject',
'margin',
'padding',
'floats',
'borders',
'interactions',
'verticalList',
'horizontalList',
'descriptionList',
'nameValueList',
'truncate',
'hyphenation',
'box',
'text',
'color',
'scrolling',
'sizing',
'layout',
'position',
'print',
'visibility',
'lineClamp',
'darkMode',
// scoped-themes
'agentforce',
];
const addFiles = () => {
let imports = [];
let files;
if (args['--production']) {
files = glob.sync([
config.sources.config,
config.sources.hooks,
config.sources.input,
config.sources.subThemes,
]);
} else {
files = glob.sync([config.sources.config, config.sources.input, config.sources.subThemes]);
}
let namedImports = [];
files.map((file) => {
namedImports.push({
name: file
.split(path.sep)
[file.split(path.sep).length - 1].replace('_', '')
.replace(/\.[^/.]+$/, ''),
file,
});
});
namedImports.sort((a, b) => {
const aIndex = importOrder.indexOf(a.name);
const bIndex = importOrder.indexOf(b.name);
if (aIndex > bIndex) {
return 1;
}
if (aIndex < bIndex) {
return -1;
}
return 0;
});
namedImports.map((namedImport) => {
imports.push(`@import "${namedImport.file}";`);
});
fs.outputFileSync(config.outputs.imports, imports.join('\n'));
const css = fs.readFileSync(config.outputs.imports, 'utf8');
processCss(css, plugins);
};
if (args['--system']) addFiles();
if (args['--watch']) {
const watcher = chokidar.watch([config.directories.input, config.directories.subThemes], {
persistent: true,
ignoreInitial: true,
awaitWriteFinish: true,
});
watcher.on('add', async (file, stat) => {
console.log(`${file} has been added`);
addFiles();
});
watcher.on('change', (file) => {
console.log(`${file} has been changed`);
const css = fs.readFileSync(config.outputs.imports, 'utf8');
processCss(css, plugins);
});
watcher.on('unlink', (file) => {
console.log(`${file} has been removed`);
addFiles();
});
}
|