purgetss 6.2.16 → 6.2.17

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.
Files changed (3) hide show
  1. package/bin/purgetss +1 -0
  2. package/index.js +31 -6
  3. package/package.json +1 -1
package/bin/purgetss CHANGED
@@ -96,6 +96,7 @@ program
96
96
  .description(`Auto-runs ${chalk.green('PurgeTSS')} every time you compile your project`)
97
97
  .help(`Auto-runs ${chalk.green('PurgeTSS')} every time you compile your project\nThis is very useful in combination with ${chalk.green('LiveView')} by purging your files every time you make a change`)
98
98
  .option('-o, --off', 'To turn off watch mode')
99
+ .option('-d, --delete', 'To completely delete the Auto-Purging hook')
99
100
  .action((args, options, logger) => {
100
101
  purgetss.watchMode(options);
101
102
  });
package/index.js CHANGED
@@ -117,7 +117,7 @@ const srcJMKFile = path.resolve(__dirname, './lib/templates/alloy.jmk');
117
117
  //! Command: purgetss
118
118
  function purgeClasses(options) {
119
119
  purgingDebug = options.debug;
120
- if (alloyProject()) {
120
+ if (alloyProject() && Date.now() > (fs.statSync(projectsAppTSS).mtimeMs + 1000)) {
121
121
  start();
122
122
 
123
123
  init(options);
@@ -128,6 +128,8 @@ function purgeClasses(options) {
128
128
 
129
129
  let tempPurged = copyResetTemplateAnd_appTSS();
130
130
 
131
+ tempPurged += `// ${Date.now()}\n`;
132
+
131
133
  tempPurged += purgeTailwind(uniqueClasses);
132
134
 
133
135
  let cleanUniqueClasses = cleanClasses(uniqueClasses);
@@ -174,6 +176,9 @@ function init(options) {
174
176
  if (fs.existsSync(projectsAlloyJMKFile)) {
175
177
  if (!fs.readFileSync(projectsAlloyJMKFile, 'utf8').includes('::PurgeTSS::')) {
176
178
  addHook();
179
+ } else if (fs.readFileSync(projectsAlloyJMKFile, 'utf8').includes("require('child_process').execSync('purgetss")) {
180
+ deleteHook();
181
+ addHook();
177
182
  }
178
183
  } else {
179
184
  createJMKFile();
@@ -206,10 +211,12 @@ function watchMode(options) {
206
211
  if (fs.existsSync(projectsAlloyJMKFile)) {
207
212
  //! TODO: Refactor with readline or line-reader: https://stackabuse.com/reading-a-file-line-by-line-in-node-js/
208
213
  if (options.off) {
209
- removeHook();
214
+ disableHook();
215
+ } else if (options.delete) {
216
+ deleteHook();
210
217
  } else if (!fs.readFileSync(projectsAlloyJMKFile, 'utf8').includes('::PurgeTSS::')) {
211
218
  addHook();
212
- } else if (fs.readFileSync(projectsAlloyJMKFile, 'utf8').includes("//\trequire('child_process').execSync('")) {
219
+ } else if (fs.readFileSync(projectsAlloyJMKFile, 'utf8').includes("//\trequire('child_process').exec('purgetss")) {
213
220
  enableHook();
214
221
  } else {
215
222
  logger.warn(chalk.yellow('Auto-Purging hook already present!'));
@@ -1065,7 +1072,7 @@ function addHook() {
1065
1072
 
1066
1073
  originalJMKFile.split(/\r?\n/).forEach((line) => {
1067
1074
  if (line.includes('pre:compile')) {
1068
- line += `\n\trequire('child_process').execSync('purgetss', logger.warn('::PurgeTSS:: Auto-Purging ' + event.dir.project));`;
1075
+ line += `\n\trequire('child_process').exec('purgetss', logger.warn('::PurgeTSS:: Auto-Purging ' + event.dir.project));`;
1069
1076
  }
1070
1077
  updatedJMKFile.push(line);
1071
1078
  });
@@ -1078,7 +1085,7 @@ function addHook() {
1078
1085
 
1079
1086
  alloyJMKTemplate.split(/\r?\n/).forEach((line) => {
1080
1087
  if (line.includes('pre:compile')) {
1081
- line += `\n\trequire('child_process').execSync('purgetss', logger.warn('::PurgeTSS:: Auto-Purging ' + event.dir.project));`;
1088
+ line += `\n\trequire('child_process').exec('purgetss', logger.warn('::PurgeTSS:: Auto-Purging ' + event.dir.project));`;
1082
1089
  }
1083
1090
  updatedJMKFile.push(line);
1084
1091
  });
@@ -1087,7 +1094,7 @@ function addHook() {
1087
1094
  }
1088
1095
  }
1089
1096
 
1090
- function removeHook() {
1097
+ function disableHook() {
1091
1098
  let updatedJMKFile = [];
1092
1099
  let originalJMKFile = fs.readFileSync(projectsAlloyJMKFile, 'utf8');
1093
1100
  let purgeCmdPresent = (originalJMKFile.includes('::PurgeTSS::'));
@@ -1109,6 +1116,24 @@ function removeHook() {
1109
1116
  }
1110
1117
  }
1111
1118
 
1119
+ function deleteHook() {
1120
+ let updatedJMKFile = [];
1121
+ let originalJMKFile = fs.readFileSync(projectsAlloyJMKFile, 'utf8');
1122
+ let purgeCmdPresent = (originalJMKFile.includes('::PurgeTSS::'));
1123
+
1124
+ if (purgeCmdPresent) {
1125
+ originalJMKFile.split(/\r?\n/).forEach((line) => {
1126
+ if (!line.includes("::PurgeTSS::")) {
1127
+ updatedJMKFile.push(line);
1128
+ } else {
1129
+ logger.warn(chalk.red('Auto-Purging hook deleted!'));
1130
+ }
1131
+ });
1132
+
1133
+ saveFile(projectsAlloyJMKFile, updatedJMKFile.join("\n"));
1134
+ }
1135
+ }
1136
+
1112
1137
  function enableHook() {
1113
1138
  let updatedJMKFile = [];
1114
1139
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "purgetss",
3
- "version": "6.2.16",
3
+ "version": "6.2.17",
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": {