Skip to content

Commit 74bd141

Browse files
authored
Add script to remove temp/cache dirs (#58)
1 parent 4fa1343 commit 74bd141

4 files changed

Lines changed: 98 additions & 2 deletions

File tree

.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ module.exports = {
171171
},
172172
},
173173
{
174-
files: ['./lib/*', './webpack/*'],
174+
files: ['./lib/*', './scripts/*', './webpack/*'],
175175
rules: {
176176
// These files are scripts not running in Platform.Bible, so they can't use the logger
177177
'no-console': 'off',

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"test:coverage": "jest --coverage",
3232
"core:start": "npm --prefix ../paranext-core start",
3333
"core:stop": "npm --prefix ../paranext-core stop",
34+
"core:reset": "npm run core:stop && node ./scripts/delete-temp-dirs.cjs --core --ext",
3435
"core:install": "npm --prefix ../paranext-core install",
3536
"core:pull": "git -C ../paranext-core pull --ff-only",
3637
"core:update": "npm run core:pull && npm run core:install"

scripts/delete-temp-dirs.cjs

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
4+
/**
5+
* Cross-platform script to delete temporary and cache directories. Run this if Platform.Bible is
6+
* holding on to outdated resources, such as localization strings, project data, or WebView ids.
7+
*
8+
* Warning: The `--core` flag deletes:
9+
*
10+
* - The `Electron` cache folder, which affect any other Electron apps
11+
* - `paranext-core/dev-appdata/`, which includes `installed-extensions/`
12+
*/
13+
14+
// Define directory lists
15+
16+
/* eslint-disable no-nested-ternary */
17+
let electronParent =
18+
process.platform === 'win32'
19+
? process.env.APPDATA
20+
: process.platform === 'linux'
21+
? process.env.XDG_CONFIG_HOME
22+
: '';
23+
if (!electronParent && process.env.HOME) {
24+
electronParent =
25+
process.platform === 'linux'
26+
? path.join(process.env.HOME, '.config')
27+
: process.platform === 'darwin'
28+
? path.join(process.env.HOME, 'Library', 'Application Support')
29+
: '';
30+
}
31+
/* eslint-enable no-nested-ternary */
32+
33+
const CORE_DIRS = [
34+
electronParent ? path.join(electronParent, 'Electron') : '',
35+
path.join(__dirname, '..', '..', 'paranext-core', 'dev-appdata'),
36+
];
37+
38+
const EXT_DIRS = [
39+
path.join(__dirname, '..', 'coverage'),
40+
path.join(__dirname, '..', 'dist'),
41+
path.join(__dirname, '..', 'src', 'temp-build'),
42+
];
43+
44+
/**
45+
* Delete a directory if it exists
46+
*
47+
* @param {string} dirPath - The directory path to delete
48+
*/
49+
function deleteDirectory(dirPath) {
50+
if (!dirPath) {
51+
console.log('⊘ Skipping empty path');
52+
return;
53+
}
54+
55+
try {
56+
if (fs.existsSync(dirPath)) {
57+
fs.rmSync(dirPath, { recursive: true, force: true });
58+
console.log(`✓ Deleted ${dirPath}`);
59+
} else {
60+
console.log(`⊘ ${dirPath} does not exist`);
61+
}
62+
} catch (error) {
63+
console.error(`✗ Failed to delete ${dirPath}:`, error.message);
64+
}
65+
}
66+
67+
// Delete directories based on command-line flags
68+
69+
try {
70+
const hasCoreFlag = process.argv.includes('--core');
71+
const hasExtFlag = process.argv.includes('--ext');
72+
73+
if (!hasCoreFlag && !hasExtFlag) {
74+
console.error('Usage: node delete-temp-dirs.cjs [--core] [--ext]');
75+
console.error(' --core Delete AppData and core cache directories (Electron, dev-appdata)');
76+
console.error(' --ext Delete extension directories (coverage, dist, src/temp-build)');
77+
process.exit(1);
78+
}
79+
80+
if (hasCoreFlag) {
81+
console.log('Deleting core cache directories...');
82+
CORE_DIRS.forEach(deleteDirectory);
83+
}
84+
85+
if (hasExtFlag) {
86+
console.log('Deleting extension directories...');
87+
EXT_DIRS.forEach(deleteDirectory);
88+
}
89+
90+
console.log('Complete!');
91+
process.exit(0);
92+
} catch (error) {
93+
console.error('Error during cleanup:', error);
94+
process.exit(1);
95+
}

tsconfig.lint.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
"compilerOptions": {
44
"allowJs": true
55
},
6-
"include": [".eslintrc.js", "*.ts", "*.js", "lib", "src", "webpack"]
6+
"include": [".*.js", "*.js", "*.ts", "lib", "scripts", "src", "webpack"]
77
}

0 commit comments

Comments
 (0)