purgetss 7.1.6 → 7.1.7

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
@@ -45,12 +45,34 @@ program
45
45
  .allowUnknownOption(false)
46
46
  .action(async (options) => {
47
47
  try {
48
- const result = await purgeClasses(options)
49
- if (!result) {
50
- process.exit(1)
48
+ if (options.all) {
49
+ // When --all is specified, run the 3 commands in sequence
50
+ console.log(chalk.yellow('Running all commands: build, build-fonts, and purge...'))
51
+
52
+ // Run commands in sequence to avoid race conditions
53
+ console.log(chalk.cyan('\n1. Running build command...'))
54
+ await build(options)
55
+
56
+ console.log(chalk.cyan('\n2. Running build-fonts command...'))
57
+ await buildFonts(options)
58
+
59
+ console.log(chalk.cyan('\n3. Running purge command...'))
60
+ const result = await purgeClasses(options)
61
+
62
+ if (!result) {
63
+ process.exit(1)
64
+ }
65
+
66
+ console.log(chalk.green('\n✅ All commands completed successfully!'))
67
+ } else {
68
+ // Default behavior: just run purgeClasses
69
+ const result = await purgeClasses(options)
70
+ if (!result) {
71
+ process.exit(1)
72
+ }
51
73
  }
52
74
  } catch (error) {
53
- console.error(chalk.red('Error running purgeClasses:'), error.message)
75
+ console.error(chalk.red('Error running command:'), error.message)
54
76
  process.exit(1)
55
77
  }
56
78
  })
@@ -182,7 +204,8 @@ program
182
204
  .option('--all', 'Create all files')
183
205
  .action(async (options) => {
184
206
  try {
185
- const result = await init(options)
207
+ // Pass flag to indicate this is an explicit init command
208
+ const result = await init({ ...options, isExplicitInit: true })
186
209
  if (!result) {
187
210
  process.exit(1)
188
211
  }
@@ -421,16 +444,16 @@ program
421
444
  // Function to calculate string similarity (Levenshtein distance)
422
445
  function calculateSimilarity(str1, str2) {
423
446
  const matrix = []
424
-
447
+
425
448
  // Create distance matrix
426
449
  for (let i = 0; i <= str2.length; i++) {
427
450
  matrix[i] = [i]
428
451
  }
429
-
452
+
430
453
  for (let j = 0; j <= str1.length; j++) {
431
454
  matrix[0][j] = j
432
455
  }
433
-
456
+
434
457
  // Fill the matrix
435
458
  for (let i = 1; i <= str2.length; i++) {
436
459
  for (let j = 1; j <= str1.length; j++) {
@@ -445,24 +468,24 @@ function calculateSimilarity(str1, str2) {
445
468
  }
446
469
  }
447
470
  }
448
-
471
+
449
472
  return matrix[str2.length][str1.length]
450
473
  }
451
474
 
452
475
  // Function to find similar commands
453
476
  function findSimilarCommands(input, validCommands) {
454
477
  const suggestions = []
455
-
478
+
456
479
  validCommands.forEach(cmd => {
457
480
  const distance = calculateSimilarity(input.toLowerCase(), cmd.toLowerCase())
458
481
  const similarity = 1 - (distance / Math.max(input.length, cmd.length))
459
-
482
+
460
483
  // Suggest commands with similarity > 0.4 or that start with the same letter
461
484
  if (similarity > 0.4 || cmd.toLowerCase().startsWith(input.toLowerCase().charAt(0))) {
462
485
  suggestions.push({ command: cmd, similarity })
463
486
  }
464
487
  })
465
-
488
+
466
489
  // Sort by similarity and return top 3
467
490
  return suggestions
468
491
  .sort((a, b) => b.similarity - a.similarity)
@@ -488,20 +511,20 @@ if (args.length > 0) {
488
511
  // Check if it's an unknown command (doesn't start with - and not in valid commands)
489
512
  if (!firstArg.startsWith('-') && !validCommands.includes(firstArg)) {
490
513
  console.log(chalk.red(`\nUnknown command: ${firstArg}`))
491
-
514
+
492
515
  // Find similar commands and suggest them
493
516
  const suggestions = findSimilarCommands(firstArg, validCommands)
494
517
  if (suggestions.length > 0) {
495
518
  console.log(chalk.yellow('Did you mean one of these?'))
496
519
  suggestions.forEach(suggestion => {
497
520
  // Get the command info to show alias if available
498
- const commandInfo = program.commands.find(cmd =>
521
+ const commandInfo = program.commands.find(cmd =>
499
522
  cmd.name() === suggestion || cmd.alias() === suggestion
500
523
  )
501
-
524
+
502
525
  if (commandInfo) {
503
- const displayName = commandInfo.alias()
504
- ? `${commandInfo.name()}|${commandInfo.alias()}`
526
+ const displayName = commandInfo.alias()
527
+ ? `${commandInfo.name()}|${commandInfo.alias()}`
505
528
  : commandInfo.name()
506
529
  console.log(` ${chalk.cyan(displayName)}`)
507
530
  } else {
@@ -1,4 +1,4 @@
1
- // PurgeTSS v7.1.6
1
+ // PurgeTSS v7.1.7
2
2
  // Created by César Estrada
3
3
  // https://purgetss.com
4
4
 
@@ -30,12 +30,12 @@ const logger = {
30
30
  file: (...args) => console.log(purgeLabel, chalk.yellow(args.join(' ')), 'file created!')
31
31
  }
32
32
 
33
- const configFile = getConfigFile()
33
+ let configFile = getConfigFile()
34
34
  configFile.purge = configFile.purge ?? { mode: 'all' }
35
35
  configFile.theme = configFile.theme ?? {}
36
36
  configFile.theme.extend = configFile.theme.extend ?? {}
37
37
 
38
- const configOptions = (configFile.purge && configFile.purge.options) ? configFile.purge.options : {}
38
+ let configOptions = (configFile.purge && configFile.purge.options) ? configFile.purge.options : {}
39
39
  if (configOptions) {
40
40
  configOptions.plugins = configOptions.plugins ?? []
41
41
  configOptions.safelist = configOptions.safelist ?? []
@@ -44,6 +44,20 @@ if (configOptions) {
44
44
  }
45
45
 
46
46
  function autoBuildTailwindTSS(options = {}) {
47
+ // Refresh config at the start of the function to ensure it's up-to-date
48
+ configFile = getConfigFile()
49
+ configFile.purge = configFile.purge ?? { mode: 'all' }
50
+ configFile.theme = configFile.theme ?? {}
51
+ configFile.theme.extend = configFile.theme.extend ?? {}
52
+
53
+ configOptions = (configFile.purge && configFile.purge.options) ? configFile.purge.options : {}
54
+ if (configOptions) {
55
+ configOptions.plugins = configOptions.plugins ?? []
56
+ configOptions.safelist = configOptions.safelist ?? []
57
+ configOptions.missing = configOptions.missing ?? true
58
+ configOptions.widgets = configOptions.widgets ?? false
59
+ }
60
+
47
61
  saveGlossary = options.glossary ?? false
48
62
  let tailwindStyles = fs.readFileSync(path.resolve(__dirname, '../lib/templates/tailwind/template.tss'), 'utf8')
49
63
  tailwindStyles += fs.readFileSync(path.resolve(__dirname, '../lib/templates/tailwind/custom-template.tss'), 'utf8')
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "purgetss",
4
- "version": "7.1.6",
4
+ "version": "7.1.7",
5
5
  "main": "src/index.js",
6
6
  "bin": {
7
7
  "purgetss": "bin/purgetss"
@@ -1,4 +1,4 @@
1
-
1
+
2
2
  /**
3
3
  * PurgeTSS v7.1 - Init Command
4
4
  *
@@ -156,20 +156,21 @@ function createDefinitionsFile() {
156
156
  */
157
157
  export { createDefinitionsFile }
158
158
 
159
- export function init(options) {
159
+ export function init(options = {}) {
160
160
  // Check if we're in an Alloy project first
161
161
  if (!alloyProject()) {
162
162
  return false
163
163
  }
164
164
 
165
- // Check if config.cjs already exists to show appropriate message
166
- const configExisted = fs.existsSync(projectsConfigJS)
165
+ // Only show warning for explicit init command (not when called from other commands)
166
+ const isExplicitInitCommand = options.isExplicitInit === true
167
+ const configExisted = isExplicitInitCommand ? fs.existsSync(projectsConfigJS) : false
167
168
 
168
169
  // SUPER SIMPLE: Ensure config exists (migrate or create)
169
170
  ensureConfig()
170
171
 
171
- // Show warning if config already existed (for init command specifically)
172
- if (configExisted) {
172
+ // Show warning ONLY if this is an explicit init command AND config already existed
173
+ if (isExplicitInitCommand && configExisted) {
173
174
  logger.warn('./purgetss/config.cjs', chalk.red('file already exists!'))
174
175
  }
175
176
 
@@ -177,12 +178,12 @@ export function init(options) {
177
178
  const { methodCommand, oppositeCommand } = getCommands()
178
179
 
179
180
  // tailwind.tss
180
- if (!fs.existsSync(projectsTailwind_TSS) || options.all) {
181
+ if (!fs.existsSync(projectsTailwind_TSS)) {
181
182
  buildTailwindBasedOnConfigOptions(options)
182
183
  }
183
184
 
184
185
  // definitions file
185
- if (!fs.existsSync(`${cwd}/purgetss/styles/definitions.css`) || options.all) {
186
+ if (!fs.existsSync(`${cwd}/purgetss/styles/definitions.css`)) {
186
187
  createDefinitionsFile()
187
188
  }
188
189