purgetss 7.1.5 → 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 +40 -17
- package/dist/purgetss.ui.js +1 -1
- package/experimental/completions2.js +16 -2
- package/package.json +1 -1
- package/src/cli/commands/build.js +2 -2
- package/src/cli/commands/color-module.js +2 -2
- package/src/cli/commands/init.js +17 -10
- package/src/cli/commands/purge.js +2 -2
- package/src/cli/commands/shades.js +12 -9
- package/src/cli/commands/watch.js +4 -1
- package/src/cli/utils/file-operations.js +3 -10
- package/src/shared/config-manager.js +28 -0
package/bin/purgetss
CHANGED
|
@@ -45,12 +45,34 @@ program
|
|
|
45
45
|
.allowUnknownOption(false)
|
|
46
46
|
.action(async (options) => {
|
|
47
47
|
try {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
|
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
|
-
|
|
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 {
|
package/dist/purgetss.ui.js
CHANGED
|
@@ -30,12 +30,12 @@ const logger = {
|
|
|
30
30
|
file: (...args) => console.log(purgeLabel, chalk.yellow(args.join(' ')), 'file created!')
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
|
|
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
|
-
|
|
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
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
import { alloyProject } from '../../shared/utils.js'
|
|
14
|
-
import {
|
|
14
|
+
import { ensureConfig } from '../../shared/config-manager.js'
|
|
15
15
|
import { buildTailwindBasedOnConfigOptions } from '../../core/builders/tailwind-builder.js'
|
|
16
16
|
import { createDefinitionsFile } from './init.js'
|
|
17
17
|
|
|
@@ -27,7 +27,7 @@ import { buildFontAwesome, buildFontAwesomeJS } from '../../dev/builders/fontawe
|
|
|
27
27
|
*/
|
|
28
28
|
export function build(options) {
|
|
29
29
|
if (alloyProject()) {
|
|
30
|
-
|
|
30
|
+
ensureConfig()
|
|
31
31
|
buildTailwindBasedOnConfigOptions(options)
|
|
32
32
|
buildFontAwesome()
|
|
33
33
|
buildFontAwesomeJS()
|
|
@@ -16,7 +16,7 @@ import { createRequire } from 'module'
|
|
|
16
16
|
import { alloyProject, makeSureFolderExists } from '../../shared/utils.js'
|
|
17
17
|
import { projectsConfigJS, projectsLibFolder } from '../../shared/constants.js'
|
|
18
18
|
import { logger } from '../../shared/logger.js'
|
|
19
|
-
import {
|
|
19
|
+
import { ensureConfig } from '../../shared/config-manager.js'
|
|
20
20
|
import { cleanDoubleQuotes } from '../utils/file-operations.js'
|
|
21
21
|
|
|
22
22
|
// Create require for ESM compatibility
|
|
@@ -34,7 +34,7 @@ export function colorModule(options) {
|
|
|
34
34
|
return false
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
ensureConfig()
|
|
38
38
|
const colorModuleConfigFile = require(projectsConfigJS)
|
|
39
39
|
makeSureFolderExists(projectsLibFolder)
|
|
40
40
|
const mainColors = { ...colorModuleConfigFile.theme.colors, ...colorModuleConfigFile.theme.extend.colors }
|
package/src/cli/commands/init.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
2
2
|
/**
|
|
3
3
|
* PurgeTSS v7.1 - Init Command
|
|
4
4
|
*
|
|
@@ -30,7 +30,7 @@ import {
|
|
|
30
30
|
PurgeTSSPackageJSON
|
|
31
31
|
} from '../../shared/constants.js'
|
|
32
32
|
import { logger } from '../../shared/logger.js'
|
|
33
|
-
import { getConfigOptions, getConfigFile } from '../../shared/config-manager.js'
|
|
33
|
+
import { getConfigOptions, getConfigFile, ensureConfig } from '../../shared/config-manager.js'
|
|
34
34
|
import { addHook, deleteHook, createJMKFile } from '../utils/hook-management.js'
|
|
35
35
|
import { getFiles } from '../utils/font-utilities.js'
|
|
36
36
|
import { buildTailwindBasedOnConfigOptions } from '../../core/builders/tailwind-builder.js'
|
|
@@ -156,27 +156,34 @@ 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
|
-
//
|
|
166
|
-
const
|
|
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
|
|
168
|
+
|
|
169
|
+
// SUPER SIMPLE: Ensure config exists (migrate or create)
|
|
170
|
+
ensureConfig()
|
|
167
171
|
|
|
168
|
-
// config
|
|
169
|
-
if (
|
|
170
|
-
|
|
172
|
+
// Show warning ONLY if this is an explicit init command AND config already existed
|
|
173
|
+
if (isExplicitInitCommand && configExisted) {
|
|
174
|
+
logger.warn('./purgetss/config.cjs', chalk.red('file already exists!'))
|
|
171
175
|
}
|
|
172
176
|
|
|
177
|
+
// Get commands when needed
|
|
178
|
+
const { methodCommand, oppositeCommand } = getCommands()
|
|
179
|
+
|
|
173
180
|
// tailwind.tss
|
|
174
|
-
if (!fs.existsSync(projectsTailwind_TSS)
|
|
181
|
+
if (!fs.existsSync(projectsTailwind_TSS)) {
|
|
175
182
|
buildTailwindBasedOnConfigOptions(options)
|
|
176
183
|
}
|
|
177
184
|
|
|
178
185
|
// definitions file
|
|
179
|
-
if (!fs.existsSync(`${cwd}/purgetss/styles/definitions.css`)
|
|
186
|
+
if (!fs.existsSync(`${cwd}/purgetss/styles/definitions.css`)) {
|
|
180
187
|
createDefinitionsFile()
|
|
181
188
|
}
|
|
182
189
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
2
2
|
/**
|
|
3
3
|
* PurgeTSS v7.1 - Purge Command
|
|
4
4
|
*
|
|
@@ -28,7 +28,7 @@ import {
|
|
|
28
28
|
import { logger, setDebugMode } from '../../shared/logger.js'
|
|
29
29
|
import { start, finish, localStart, localFinish } from '../utils/cli-helpers.js'
|
|
30
30
|
import { init } from './init.js'
|
|
31
|
-
import { getConfigOptions, getConfigFile } from '../../shared/config-manager.js'
|
|
31
|
+
import { getConfigOptions, getConfigFile, ensureConfig } from '../../shared/config-manager.js'
|
|
32
32
|
|
|
33
33
|
// Import purger functions from core modules
|
|
34
34
|
import { purgeTailwind } from '../../core/purger/tailwind-purger.js'
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
2
2
|
/**
|
|
3
3
|
* PurgeTSS v7.1 - Shades Commands
|
|
4
4
|
*
|
|
@@ -17,7 +17,8 @@ import { createRequire } from 'module'
|
|
|
17
17
|
import { alloyProject, makeSureFolderExists } from '../../shared/utils.js'
|
|
18
18
|
import { projectsConfigJS, projectsLibFolder } from '../../shared/constants.js'
|
|
19
19
|
import { logger } from '../../shared/logger.js'
|
|
20
|
-
import {
|
|
20
|
+
import { ensureConfig, getConfigFile } from '../../shared/config-manager.js'
|
|
21
|
+
import { cleanDoubleQuotes } from '../utils/file-operations.js'
|
|
21
22
|
|
|
22
23
|
// Create require for ESM compatibility
|
|
23
24
|
const require = createRequire(import.meta.url)
|
|
@@ -33,7 +34,7 @@ export function colorModule() {
|
|
|
33
34
|
return false
|
|
34
35
|
}
|
|
35
36
|
|
|
36
|
-
|
|
37
|
+
ensureConfig()
|
|
37
38
|
|
|
38
39
|
const colorModuleConfigFile = require(projectsConfigJS)
|
|
39
40
|
|
|
@@ -101,10 +102,15 @@ export async function shades(args, options) {
|
|
|
101
102
|
const colorObject = createColorObject(colorFamily, colorFamily.hexcode, options)
|
|
102
103
|
|
|
103
104
|
const silent = options.tailwind || options.json || options.log
|
|
104
|
-
|
|
105
|
-
//
|
|
105
|
+
|
|
106
|
+
// Ensure config migration happens before getting config file
|
|
107
|
+
if (alloyProject(silent) && !silent) {
|
|
108
|
+
ensureConfig()
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// Get config file (after potential migration)
|
|
106
112
|
const configFile = getConfigFile()
|
|
107
|
-
|
|
113
|
+
|
|
108
114
|
if (alloyProject(silent) && !silent) {
|
|
109
115
|
|
|
110
116
|
if (options.override) {
|
|
@@ -174,9 +180,6 @@ function createColorObject(family, hexcode, options) {
|
|
|
174
180
|
return colors
|
|
175
181
|
}
|
|
176
182
|
|
|
177
|
-
// Import config manager
|
|
178
|
-
import { getConfigFile } from '../../shared/config-manager.js'
|
|
179
|
-
|
|
180
183
|
/**
|
|
181
184
|
* Export for CLI usage
|
|
182
185
|
*/
|
|
@@ -15,7 +15,7 @@ import chalk from 'chalk'
|
|
|
15
15
|
import { alloyProject } from '../../shared/utils.js'
|
|
16
16
|
import { projectsAlloyJMKFile } from '../../shared/constants.js'
|
|
17
17
|
import { logger } from '../../shared/logger.js'
|
|
18
|
-
import { getConfigFile } from '../../shared/config-manager.js'
|
|
18
|
+
import { getConfigFile, ensureConfig } from '../../shared/config-manager.js'
|
|
19
19
|
import { disableHook, deleteHook, addHook, enableHook, createJMKFile } from '../utils/hook-management.js'
|
|
20
20
|
|
|
21
21
|
/**
|
|
@@ -58,6 +58,9 @@ export function watchMode(options) {
|
|
|
58
58
|
return false
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
+
// Ensure config exists before accessing it
|
|
62
|
+
ensureConfig()
|
|
63
|
+
|
|
61
64
|
if (fs.existsSync(projectsAlloyJMKFile)) {
|
|
62
65
|
// Get commands when needed
|
|
63
66
|
const { methodCommand } = getCommands()
|
|
@@ -12,22 +12,15 @@
|
|
|
12
12
|
|
|
13
13
|
import fs from 'fs'
|
|
14
14
|
import util from 'util'
|
|
15
|
-
import {
|
|
16
|
-
import { createConfigFile } from '../commands/init.js'
|
|
17
|
-
import { migrateConfigIfNeeded } from '../../shared/config-manager.js'
|
|
15
|
+
import { ensureConfig } from '../../shared/config-manager.js'
|
|
18
16
|
|
|
19
17
|
/**
|
|
18
|
+
* @deprecated Use ensureConfig() from config-manager.js instead
|
|
20
19
|
* Initialize config if it doesn't exist
|
|
21
20
|
* FIRST migrates any existing config.js, THEN creates default if needed
|
|
22
21
|
*/
|
|
23
22
|
export function initIfNotConfig() {
|
|
24
|
-
|
|
25
|
-
migrateConfigIfNeeded()
|
|
26
|
-
|
|
27
|
-
// Now check if we need to create default config
|
|
28
|
-
if (!fs.existsSync(projectsConfigJS)) {
|
|
29
|
-
createConfigFile()
|
|
30
|
-
}
|
|
23
|
+
ensureConfig()
|
|
31
24
|
}
|
|
32
25
|
|
|
33
26
|
/**
|
|
@@ -25,6 +25,34 @@ import { makeSureFolderExists } from './utils.js'
|
|
|
25
25
|
const require = createRequire(import.meta.url)
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
|
+
* Ensure config file exists - SIMPLE logic
|
|
29
|
+
* 1. If config.cjs exists → use it
|
|
30
|
+
* 2. If config.js exists → rename to config.cjs
|
|
31
|
+
* 3. If nothing exists → create config.cjs
|
|
32
|
+
*/
|
|
33
|
+
export function ensureConfig() {
|
|
34
|
+
// 1. ¿Existe config.cjs? → Úsalo
|
|
35
|
+
if (fs.existsSync(projectsConfigJS)) {
|
|
36
|
+
return
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// 2. ¿Existe config.js? → Renómbralo
|
|
40
|
+
const oldConfigPath = `${projectsPurgeTSSFolder}/config.js`
|
|
41
|
+
if (fs.existsSync(oldConfigPath)) {
|
|
42
|
+
makeSureFolderExists(projectsPurgeTSSFolder)
|
|
43
|
+
fs.renameSync(oldConfigPath, projectsConfigJS)
|
|
44
|
+
logger.info('Migrated config.js to config.cjs for ESM compatibility')
|
|
45
|
+
return
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// 3. No existe nada → Crear config.cjs
|
|
49
|
+
makeSureFolderExists(projectsPurgeTSSFolder)
|
|
50
|
+
fs.copyFileSync(srcConfigFile, projectsConfigJS)
|
|
51
|
+
logger.file('./purgetss/config.cjs')
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @deprecated Use ensureConfig() instead
|
|
28
56
|
* Migrate config.js to config.cjs for ESM compatibility
|
|
29
57
|
* This must be called BEFORE any config file creation
|
|
30
58
|
*/
|