purgetss 6.2.50 → 6.3.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/index.js +107 -7
- package/lib/helpers.js +2 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1106,14 +1106,14 @@ function findMissingClasses(tempPurged) {
|
|
|
1106
1106
|
tempPurged += '\n' + fs.readFileSync(file, 'utf8')
|
|
1107
1107
|
})
|
|
1108
1108
|
|
|
1109
|
-
// ! Get Styles from Widgets
|
|
1109
|
+
// ! Get Styles from Widgets
|
|
1110
1110
|
if (configOptions.widgets && fs.existsSync(cwd + '/app/widgets/')) {
|
|
1111
1111
|
_.each(getFiles(cwd + '/app/widgets').filter(file => file.endsWith('.tss')), file => {
|
|
1112
1112
|
tempPurged += '\n' + fs.readFileSync(file, 'utf8')
|
|
1113
1113
|
})
|
|
1114
1114
|
}
|
|
1115
1115
|
|
|
1116
|
-
// ! Get Views from Themes
|
|
1116
|
+
// ! Get Views from Themes
|
|
1117
1117
|
if (fs.existsSync(cwd + '/app/themes/')) {
|
|
1118
1118
|
_.each(getFiles(cwd + '/app/themes').filter(file => file.endsWith('.tss')), file => {
|
|
1119
1119
|
tempPurged += '\n' + fs.readFileSync(file, 'utf8')
|
|
@@ -1126,7 +1126,20 @@ function findMissingClasses(tempPurged) {
|
|
|
1126
1126
|
})
|
|
1127
1127
|
}
|
|
1128
1128
|
|
|
1129
|
-
|
|
1129
|
+
const classesFromXmlFiles = getClassesOnlyFromXMLFiles().filter(item => !tempPurged.includes(item))
|
|
1130
|
+
|
|
1131
|
+
let classesFromJsFiles = []
|
|
1132
|
+
const controllerPaths = getControllerPaths()
|
|
1133
|
+
_.each(controllerPaths, controllerPath => {
|
|
1134
|
+
const data = fs.readFileSync(controllerPath, 'utf8')
|
|
1135
|
+
if (data) classesFromJsFiles.push(processControllers(data))
|
|
1136
|
+
})
|
|
1137
|
+
const reservedWords = 'Alloy.isTablet Alloy.isHandheld ? ,'
|
|
1138
|
+
classesFromJsFiles = [...new Set([...classesFromJsFiles.flat().filter(item => !reservedWords.includes(item))])]
|
|
1139
|
+
|
|
1140
|
+
classesFromJsFiles = classesFromJsFiles.filter(item => !reservedWords.includes(item))
|
|
1141
|
+
|
|
1142
|
+
return [...new Set([...classesFromJsFiles.filter(item => !tempPurged.includes(item)), ...classesFromXmlFiles])]
|
|
1130
1143
|
}
|
|
1131
1144
|
|
|
1132
1145
|
function addHook() {
|
|
@@ -1249,12 +1262,12 @@ function getViewPaths() {
|
|
|
1249
1262
|
// ! Parse Views from App
|
|
1250
1263
|
viewPaths.push(...glob.sync(cwd + '/app/views/**/*.xml'))
|
|
1251
1264
|
|
|
1252
|
-
// ! Parse Views from Widgets
|
|
1265
|
+
// ! Parse Views from Widgets
|
|
1253
1266
|
if (configOptions.widgets && fs.existsSync(cwd + '/app/widgets/')) {
|
|
1254
1267
|
viewPaths.push(...glob.sync(cwd + '/app/widgets/**/views/*.xml'))
|
|
1255
1268
|
}
|
|
1256
1269
|
|
|
1257
|
-
// ! Parse Views from Themes
|
|
1270
|
+
// ! Parse Views from Themes
|
|
1258
1271
|
if (fs.existsSync(cwd + '/app/themes/')) {
|
|
1259
1272
|
viewPaths.push(...glob.sync(cwd + '/app/themes/**/views/*.xml'))
|
|
1260
1273
|
}
|
|
@@ -1262,6 +1275,25 @@ function getViewPaths() {
|
|
|
1262
1275
|
return viewPaths
|
|
1263
1276
|
}
|
|
1264
1277
|
|
|
1278
|
+
function getControllerPaths() {
|
|
1279
|
+
const controllerPaths = []
|
|
1280
|
+
|
|
1281
|
+
// ! Parse Controllers from App
|
|
1282
|
+
controllerPaths.push(...glob.sync(cwd + '/app/controllers/**/*.js'))
|
|
1283
|
+
|
|
1284
|
+
// ! Parse Controllers from Widgets
|
|
1285
|
+
if (configOptions.widgets && fs.existsSync(cwd + '/app/widgets/')) {
|
|
1286
|
+
controllerPaths.push(...glob.sync(cwd + '/app/widgets/**/controllers/*.js'))
|
|
1287
|
+
}
|
|
1288
|
+
|
|
1289
|
+
// ! Parse Controllers from Themes
|
|
1290
|
+
if (fs.existsSync(cwd + '/app/themes/')) {
|
|
1291
|
+
controllerPaths.push(...glob.sync(cwd + '/app/themes/**/controllers/*.js'))
|
|
1292
|
+
}
|
|
1293
|
+
|
|
1294
|
+
return controllerPaths
|
|
1295
|
+
}
|
|
1296
|
+
|
|
1265
1297
|
function getClassesOnlyFromXMLFiles() {
|
|
1266
1298
|
const allClasses = []
|
|
1267
1299
|
const viewPaths = getViewPaths()
|
|
@@ -1285,6 +1317,12 @@ function getUniqueClasses() {
|
|
|
1285
1317
|
if (file) allClasses.push((configFile.purge.mode === 'all') ? file.match(/[^<>"'`\s]*[^<>"'`\s:]/g) : extractClasses(file, viewPath))
|
|
1286
1318
|
})
|
|
1287
1319
|
|
|
1320
|
+
const controllerPaths = getControllerPaths()
|
|
1321
|
+
_.each(controllerPaths, controllerPath => {
|
|
1322
|
+
const data = fs.readFileSync(controllerPath, 'utf8')
|
|
1323
|
+
if (data) allClasses.push(processControllers(data))
|
|
1324
|
+
})
|
|
1325
|
+
|
|
1288
1326
|
if (configOptions.safelist) _.each(configOptions.safelist, safe => allClasses.push(safe))
|
|
1289
1327
|
|
|
1290
1328
|
const uniqueClasses = []
|
|
@@ -1297,6 +1335,68 @@ function getUniqueClasses() {
|
|
|
1297
1335
|
return uniqueClasses.sort()
|
|
1298
1336
|
}
|
|
1299
1337
|
|
|
1338
|
+
function extractWordsFromLine(line) {
|
|
1339
|
+
let words = []
|
|
1340
|
+
|
|
1341
|
+
// Matching apply
|
|
1342
|
+
const applyRegex = /apply:\s*'([^']+)'/
|
|
1343
|
+
const applyMatch = applyRegex.exec(line)
|
|
1344
|
+
if (applyMatch) {
|
|
1345
|
+
const applyContent = applyMatch[1]
|
|
1346
|
+
words = words.concat(applyContent.split(/\s+/))
|
|
1347
|
+
}
|
|
1348
|
+
|
|
1349
|
+
// Matching classes as array
|
|
1350
|
+
const classesArrayRegex = /classes:\s*\[([^\]]+)\]/
|
|
1351
|
+
const classesArrayMatch = classesArrayRegex.exec(line)
|
|
1352
|
+
if (classesArrayMatch) {
|
|
1353
|
+
const classesContent = classesArrayMatch[1]
|
|
1354
|
+
const classesArray = classesContent.split(',').map(item => item.trim().replace(/['"]/g, ''))
|
|
1355
|
+
words = words.concat(classesArray)
|
|
1356
|
+
}
|
|
1357
|
+
|
|
1358
|
+
// Matching classes as string
|
|
1359
|
+
const classesStringRegex = /classes:\s*'([^']+)'/
|
|
1360
|
+
const classesStringMatch = classesStringRegex.exec(line)
|
|
1361
|
+
if (classesStringMatch) {
|
|
1362
|
+
const classesContent = classesStringMatch[1]
|
|
1363
|
+
words = words.concat(classesContent.split(/\s+/))
|
|
1364
|
+
}
|
|
1365
|
+
|
|
1366
|
+
// Matching addClass, removeClass, resetClass
|
|
1367
|
+
const classFunctionRegex = /(?:\.\w+Class|resetClass)\([^,]+,\s*'([^']+)'/g
|
|
1368
|
+
let classFunctionMatch
|
|
1369
|
+
while ((classFunctionMatch = classFunctionRegex.exec(line)) !== null) {
|
|
1370
|
+
const classFunctionContent = classFunctionMatch[1]
|
|
1371
|
+
words = words.concat(classFunctionContent.split(/\s+/))
|
|
1372
|
+
}
|
|
1373
|
+
|
|
1374
|
+
// Matching generic arrays
|
|
1375
|
+
// const genericArrayRegex = /(\w+:\s*\[([^\]]+)\])/g
|
|
1376
|
+
// let genericArrayMatch
|
|
1377
|
+
// while ((genericArrayMatch = genericArrayRegex.exec(line)) !== null) {
|
|
1378
|
+
// const genericArrayContent = genericArrayMatch[2]
|
|
1379
|
+
// const genericArray = genericArrayContent.split(',').map(item => item.trim().replace(/['"]/g, ''))
|
|
1380
|
+
// words = words.concat(genericArray)
|
|
1381
|
+
// }
|
|
1382
|
+
|
|
1383
|
+
return words
|
|
1384
|
+
}
|
|
1385
|
+
|
|
1386
|
+
function processControllers(data) {
|
|
1387
|
+
const allWords = []
|
|
1388
|
+
const lines = data.split(/\r?\n/)
|
|
1389
|
+
|
|
1390
|
+
lines.forEach(line => {
|
|
1391
|
+
const words = extractWordsFromLine(line)
|
|
1392
|
+
if (words.length > 0) {
|
|
1393
|
+
allWords.push(...words)
|
|
1394
|
+
}
|
|
1395
|
+
})
|
|
1396
|
+
|
|
1397
|
+
return allWords
|
|
1398
|
+
}
|
|
1399
|
+
|
|
1300
1400
|
function filterCharacters(uniqueClass) {
|
|
1301
1401
|
if (uniqueClass.length === 1 && !/^[a-zA-Z_]/.test(uniqueClass)) {
|
|
1302
1402
|
return false
|
|
@@ -1893,7 +1993,7 @@ function createDefinitionsFile() {
|
|
|
1893
1993
|
})
|
|
1894
1994
|
}
|
|
1895
1995
|
|
|
1896
|
-
// ! Get Styles from Themes
|
|
1996
|
+
// ! Get Styles from Themes
|
|
1897
1997
|
if (fs.existsSync(cwd + '/app/themes/')) {
|
|
1898
1998
|
_.each(getFiles(cwd + '/app/themes').filter(file => file.endsWith('.tss')), file => {
|
|
1899
1999
|
classDefinitions += fs.readFileSync(file, 'utf8')
|
|
@@ -2296,7 +2396,7 @@ function extractClassesOnly(currentText, currentFile) {
|
|
|
2296
2396
|
const jsontext = convert.xml2json(encodeHTML(currentText), { compact: true })
|
|
2297
2397
|
|
|
2298
2398
|
return traverse(JSON.parse(jsontext)).reduce(function (acc, value) {
|
|
2299
|
-
if (this.key === 'class' || this.key === 'classes' || this.key === 'icon') acc.push(value.split(' '))
|
|
2399
|
+
if (this.key === 'class' || this.key === 'classes' || this.key === 'icon' || this.key === 'activeIcon') acc.push(value.split(' '))
|
|
2300
2400
|
return acc
|
|
2301
2401
|
}, [])
|
|
2302
2402
|
} catch (error) {
|
package/lib/helpers.js
CHANGED
|
@@ -3117,7 +3117,8 @@ function orientationModes() {
|
|
|
3117
3117
|
'landscape-right': '[ Ti.UI.LANDSCAPE_RIGHT ]',
|
|
3118
3118
|
portrait: '[ Ti.UI.PORTRAIT ]',
|
|
3119
3119
|
'upside-portrait': '[ Ti.UI.UPSIDE_PORTRAIT ]',
|
|
3120
|
-
landscape: '[ Ti.UI.LANDSCAPE_LEFT, Ti.UI.LANDSCAPE_RIGHT ]'
|
|
3120
|
+
landscape: '[ Ti.UI.LANDSCAPE_LEFT, Ti.UI.LANDSCAPE_RIGHT ]',
|
|
3121
|
+
all: '[ Ti.UI.PORTRAIT, Ti.UI.UPSIDE_PORTRAIT, Ti.UI.LANDSCAPE_LEFT, Ti.UI.LANDSCAPE_RIGHT ]'
|
|
3121
3122
|
}
|
|
3122
3123
|
})
|
|
3123
3124
|
|