purgetss 6.1.0 → 6.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/purgetss +1 -0
- package/index.js +29 -16
- package/package.json +1 -1
package/bin/purgetss
CHANGED
|
@@ -72,6 +72,7 @@ program
|
|
|
72
72
|
.option('-q, --quotes', 'Keep double quotes in config.js')
|
|
73
73
|
.option('-r, --random', 'Generates shades from a random color')
|
|
74
74
|
.option('-l, --log', `Log the generated shades instead of saving them`)
|
|
75
|
+
.option('-j, --json', `Log a JSON compatible structure, to use it in ${chalk.yellow('app/config.json')}`)
|
|
75
76
|
.description(`Color shades generator from a given hexcolor`)
|
|
76
77
|
.help(`Generates color shades from a given hexcolor to use in your project`)
|
|
77
78
|
.action((args, options, logger) => {
|
package/index.js
CHANGED
|
@@ -375,39 +375,52 @@ function shades(args, options) {
|
|
|
375
375
|
});
|
|
376
376
|
|
|
377
377
|
let colorFamily = (options.random || !args.hexcode) ? generateColorShades(chroma.random(), referenceColorFamilies) : generateColorShades(args.hexcode, referenceColorFamilies);
|
|
378
|
-
if (args.name) colorFamily.name = args.name;
|
|
379
|
-
colorFamily.name = colorFamily.name.replace(/'/g, '');
|
|
380
378
|
|
|
381
|
-
|
|
379
|
+
if (args.name) colorFamily.name = args.name;
|
|
380
|
+
colorFamily.name = colorFamily.name.replace(/'/g, '').replace(/\//g, '').replace(' ', ' ');
|
|
382
381
|
|
|
383
|
-
|
|
384
|
-
configFile['theme']['extend']['colors'][colorObject.name] = colorObject.shades;
|
|
382
|
+
let colorObject = createColorObject(colorFamily, colorFamily.hexcode, options);
|
|
385
383
|
|
|
386
|
-
if (alloyProject() && !options.log) {
|
|
387
|
-
|
|
388
|
-
|
|
384
|
+
if (alloyProject() && !options.log && !options.json) {
|
|
385
|
+
if (!configFile['theme']['extend']['colors']) configFile['theme']['extend']['colors'] = {};
|
|
386
|
+
configFile['theme']['extend']['colors'][colorObject.name] = colorObject.shades;
|
|
387
|
+
fs.writeFileSync(projectsConfigJS, 'module.exports = ' + cleanDoubleQuotes(configFile, options), 'utf8', err => { throw err; });
|
|
388
|
+
logger.info(`${chalk.hex(colorFamily.hexcode).bold(`“${colorFamily.name}”`)} (${chalk.bgHex(colorFamily.hexcode)(`${colorFamily.hexcode}`)}) saved in`, chalk.yellow('config.js'));
|
|
389
|
+
} else if (options.json) {
|
|
390
|
+
logger.info(`${chalk.hex(colorFamily.hexcode).bold(`“${colorFamily.name}”`)} (${chalk.bgHex(colorFamily.hexcode)(`${colorFamily.hexcode}`)})\n${JSON.stringify(colorObject, null, 2)}`);
|
|
389
391
|
} else {
|
|
390
|
-
logger.info(`${chalk.
|
|
392
|
+
logger.info(`${chalk.hex(colorFamily.hexcode).bold(`“${colorFamily.name}”`)} (${chalk.bgHex(colorFamily.hexcode)(`${colorFamily.hexcode}`)})\n${cleanDoubleQuotes({ colors: { [colorObject.name]: colorObject.shades } }, options)}`);
|
|
391
393
|
}
|
|
392
394
|
}
|
|
393
395
|
exports.shades = shades;
|
|
394
396
|
|
|
395
|
-
function cleanDoubleQuotes(configFile,
|
|
397
|
+
function cleanDoubleQuotes(configFile, options) {
|
|
396
398
|
let json = JSON.stringify(configFile, null, 2);
|
|
397
399
|
|
|
398
|
-
if (quotes) return json;
|
|
400
|
+
if (options.quotes) return json;
|
|
399
401
|
|
|
400
402
|
json = json.replace(/"([^"]+)":/g, (match, p1) => (p1.match(/[._-]/)) ? `'${p1}':` : `${p1}:`);
|
|
401
403
|
|
|
402
404
|
return json.replaceAll("\"", "'");
|
|
403
405
|
}
|
|
404
406
|
|
|
405
|
-
function createColorObject(family, hexcode) {
|
|
407
|
+
function createColorObject(family, hexcode, options) {
|
|
406
408
|
let colors = {};
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
409
|
+
|
|
410
|
+
if (options.json) {
|
|
411
|
+
let shades = {};
|
|
412
|
+
colors.global = {};
|
|
413
|
+
let name = family.name.toLowerCase().split(" ").join("-");
|
|
414
|
+
shades[name] = hexcode;
|
|
415
|
+
family.shades.forEach((shade) => shades[`${name}-${shade.number}`] = shade.hexcode);
|
|
416
|
+
colors.global.colors = shades;
|
|
417
|
+
} else {
|
|
418
|
+
let shades = { default: hexcode };
|
|
419
|
+
family.shades.forEach((shade) => shades[shade.number] = shade.hexcode);
|
|
420
|
+
colors.name = family.name.toLowerCase().split(" ").join("-");
|
|
421
|
+
colors.shades = shades;
|
|
422
|
+
}
|
|
423
|
+
|
|
411
424
|
return colors;
|
|
412
425
|
}
|
|
413
426
|
|
package/package.json
CHANGED