purgetss 6.2.7 → 6.2.9

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 CHANGED
@@ -72,6 +72,7 @@ program
72
72
  .option('-n, --name', 'Name of the color')
73
73
  .option('-q, --quotes', 'Keep double quotes in config.js')
74
74
  .option('-r, --random', 'Generates shades from a random color')
75
+ .option('-s, --single', 'Generate a single color definition')
75
76
  .option('-l, --log', `Log the generated shades instead of saving them`)
76
77
  .option('-j, --json', `Log a JSON compatible structure, to use it in ${chalk.yellow('app/config.json')}`)
77
78
  .description(`Color shades generator from a given hexcolor`)
@@ -33,7 +33,6 @@ const srcConfigFile = path.resolve(__dirname, '../lib/templates/purgetss.config.
33
33
  const configFile = (fs.existsSync(projectsConfigJS)) ? require(projectsConfigJS) : require(srcConfigFile);
34
34
  configFile.purge = configFile.purge ?? { mode: 'all' };
35
35
  configFile.theme.extend = configFile.theme.extend ?? {};
36
- configFile.fonts = configFile.fonts ?? { mode: 'fileName' };
37
36
 
38
37
  const configOptions = (configFile.purge && configFile.purge.options) ? configFile.purge.options : false;
39
38
  if (configOptions) {
package/index.js CHANGED
@@ -102,7 +102,6 @@ const srcConfigFile = path.resolve(__dirname, './lib/templates/purgetss.config.j
102
102
  const configFile = (fs.existsSync(projectsConfigJS)) ? require(projectsConfigJS) : require(srcConfigFile);
103
103
  configFile.purge = configFile.purge ?? { mode: 'all' };
104
104
  configFile.theme.extend = configFile.theme.extend ?? {};
105
- configFile.fonts = configFile.fonts ?? { mode: 'fileName' };
106
105
 
107
106
  const configOptions = (configFile.purge && configFile.purge.options) ? configFile.purge.options : false;
108
107
  if (configOptions) {
@@ -396,8 +395,6 @@ exports.create = create;
396
395
 
397
396
  //! Command: shades
398
397
  function shades(args, options) {
399
- delete configFile.fonts;
400
-
401
398
  let chroma = require('chroma-js');
402
399
  let generateColorShades = require('./lib/color-shades/generateColorShades');
403
400
  let referenceColorFamilies = require('./lib/color-shades/tailwind').filter((item) => {
@@ -421,11 +418,9 @@ function shades(args, options) {
421
418
  if (!configFile['theme']['extend']['colors']) configFile['theme']['extend']['colors'] = {};
422
419
  configFile['theme']['extend']['colors'][colorObject.name] = colorObject.shades;
423
420
  fs.writeFileSync(projectsConfigJS, 'module.exports = ' + cleanDoubleQuotes(configFile, options), 'utf8', err => { throw err; });
421
+ checkIfColorModule();
424
422
  logger.info(`${chalk.hex(colorFamily.hexcode).bold(`“${colorFamily.name}”`)} (${chalk.bgHex(colorFamily.hexcode)(`${colorFamily.hexcode}`)}) saved in`, chalk.yellow('config.js'));
425
-
426
- if (options.module) {
427
- colorModule();
428
- }
423
+ // if (options.module) colorModule();
429
424
  } else if (options.json) {
430
425
  logger.info(`${chalk.hex(colorFamily.hexcode).bold(`“${colorFamily.name}”`)} (${chalk.bgHex(colorFamily.hexcode)(`${colorFamily.hexcode}`)})\n${JSON.stringify(colorObject, null, 2)}`);
431
426
  } else {
@@ -435,15 +430,19 @@ function shades(args, options) {
435
430
  exports.shades = shades;
436
431
 
437
432
  function colorModule() {
438
- // read config.js
439
- let configFile = require(projectsConfigJS);
433
+ initIfNotConfig();
434
+ let colorModuleConfigFile = require(projectsConfigJS);
440
435
  makeSureFolderExists(projectsLibFolder);
441
- let mainColors = { ...configFile.theme.colors, ...configFile.theme.extend.colors };
436
+ let mainColors = { ...colorModuleConfigFile.theme.colors, ...colorModuleConfigFile.theme.extend.colors };
442
437
  fs.writeFileSync(`${projectsLibFolder}/purgetss.colors.js`, 'module.exports = ' + cleanDoubleQuotes(mainColors, {}), 'utf8', err => { throw err; });
443
- logger.info(`All colors copied to ${chalk.yellow('lib/purgetss.colors.js')} module`);
438
+ logger.info(`All colors copied to ${chalk.yellow('lib/purgetss.colors.js')}`);
444
439
  }
445
440
  exports.colorModule = colorModule;
446
441
 
442
+ function checkIfColorModule() {
443
+ if (fs.existsSync(`${projectsLibFolder}/purgetss.colors.js`)) colorModule();
444
+ }
445
+
447
446
  function cleanDoubleQuotes(configFile, options) {
448
447
  const regexUnicode = /[^\u0000-\u00FF]/g;
449
448
 
@@ -459,18 +458,21 @@ function cleanDoubleQuotes(configFile, options) {
459
458
 
460
459
  function createColorObject(family, hexcode, options) {
461
460
  let colors = {};
461
+ let name = family.name.toLowerCase().split(" ").join("-");
462
462
 
463
463
  if (options.json) {
464
464
  let shades = {};
465
465
  colors.global = {};
466
- let name = family.name.toLowerCase().split(" ").join("-");
467
466
  shades[name] = hexcode;
468
467
  family.shades.forEach((shade) => shades[`${name}-${shade.number}`] = shade.hexcode);
469
- colors.global.colors = shades;
468
+ colors.global.colors = (options.single) ? { [name]: hexcode } : shades;
469
+ } else if (options.single) {
470
+ colors.name = name;
471
+ colors.shades = hexcode;
470
472
  } else {
471
473
  let shades = { default: hexcode };
472
474
  family.shades.forEach((shade) => shades[shade.number] = shade.hexcode);
473
- colors.name = family.name.toLowerCase().split(" ").join("-");
475
+ colors.name = name;
474
476
  colors.shades = shades;
475
477
  }
476
478
 
@@ -581,7 +583,7 @@ function buildFonts(options) {
581
583
 
582
584
  let fontFamilyName = fontMeta.postScriptName.replace(/\//g, '');
583
585
  //! Maybe this is deprecated
584
- if (configFile.fonts.mode.toLowerCase() === 'postscriptname' || configFile.fonts.mode.toLowerCase() === 'postscript' || configFile.fonts.mode.toLowerCase() === 'ps') {
586
+ if (configFile.fonts && (configFile.fonts.mode.toLowerCase() === 'postscriptname' || configFile.fonts.mode.toLowerCase() === 'postscript' || configFile.fonts.mode.toLowerCase() === 'ps')) {
585
587
  tssClasses += `\n'.${fontFamilyName.toLowerCase()}': { font: { fontFamily: '${fontFamilyName}' } }\n`;
586
588
  } else {
587
589
  tssClasses += `\n'.${getFileName(file)}': { font: { fontFamily: '${fontFamilyName}' } }\n`;
@@ -2396,6 +2398,7 @@ function purgeTailwind(uniqueClasses) {
2396
2398
 
2397
2399
  if (`// config.js file updated on: ${getFileUpdatedDate(projectsConfigJS)}` !== tailwindClasses[6]) {
2398
2400
  logger.info(chalk.yellow('config.js'), 'file changed!, rebuilding tailwind.tss...');
2401
+ checkIfColorModule();
2399
2402
  buildTailwindBasedOnConfigOptions();
2400
2403
  createDefinitionsFile();
2401
2404
  tailwindClasses = fs.readFileSync(projectsTailwind_TSS, 'utf8').split(/\r?\n/);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "purgetss",
3
- "version": "6.2.7",
3
+ "version": "6.2.9",
4
4
  "description": "An extension for Titanium SDK that contains a set of Tailwind-like classes to easily and quickly create beautifully designed mobile apps.",
5
5
  "main": "index.js",
6
6
  "bin": {