Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,12 @@ git merge template/main --allow-unrelated-histories

For more information, read [the instructions on the wiki](https://github.com/paranext/paranext-extension-template/wiki/Merging-Template-Changes-into-Your-Extension).

After updating this extension from the template, clear all temp/cache files and regenerate the extension's `package-lock.json` with this command:

```bash
npm run core:reinstall
```
Comment thread
coderabbitai[bot] marked this conversation as resolved.

**Note:** The merge/squash commits created when updating this repo from the template are important; Git uses them to compare the files for future updates. If you edit this repo's Git history, please preserve these commits (do not squash them, for example) to avoid duplicated merge conflicts in the future.

## Special features in this project
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"test:coverage": "jest --coverage",
"core:start": "npm --prefix ../paranext-core start",
"core:stop": "npm --prefix ../paranext-core stop",
"core:reset": "npm run core:stop && node ./scripts/delete-temp-dirs.cjs --core --ext",
"core:reset": "npm run core:stop && node ./scripts/delete-temp-files.cjs --core --ext",
"core:reinstall": "npm run core:reset && node ./scripts/delete-temp-files.cjs --npm && npm run core:update && npm i",
"core:install": "npm --prefix ../paranext-core install",
"core:pull": "git -C ../paranext-core pull --ff-only",
"core:update": "npm run core:pull && npm run core:install"
Expand Down
95 changes: 0 additions & 95 deletions scripts/delete-temp-dirs.cjs

This file was deleted.

113 changes: 113 additions & 0 deletions scripts/delete-temp-files.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
const fs = require('fs');
const path = require('path');

/**
* Cross-platform script to delete temporary and cache paths. Run this if Platform.Bible is holding
* on to outdated resources, such as localization strings, project data, or WebView ids.
*
* Warning: The `--core` flag deletes:
*
* - The `Electron` cache folder, which affect any other Electron apps
* - `paranext-core/dev-appdata/`, which includes `installed-extensions/`
*/

// Check command-line arguments

const hasCoreFlag = process.argv.includes('--core');
const hasExtFlag = process.argv.includes('--ext');
const hasNpmFlag = process.argv.includes('--npm');

if (!hasCoreFlag && !hasExtFlag && !hasNpmFlag) {
console.error('Usage: node delete-temp-files.cjs [--core] [--ext] [--npm]');
console.error(' --core Delete Electron and core caches (Electron, dev-appdata)');
console.error(' --ext Delete extension directories (coverage, dist, src/temp-build)');
console.error(' --npm Delete both node_modules and extension package-lock.json');
process.exit(1);
}

// Define directory lists

let electronParent = '';
if (hasCoreFlag) {
/* eslint-disable no-nested-ternary */
electronParent =
process.platform === 'win32'
? process.env.APPDATA
: process.platform === 'linux'
? process.env.XDG_CONFIG_HOME
: '';
if (!electronParent && process.env.HOME) {
electronParent =
process.platform === 'linux'
? path.join(process.env.HOME, '.config')
: process.platform === 'darwin'
? path.join(process.env.HOME, 'Library', 'Application Support')
: '';
}
/* eslint-enable no-nested-ternary */
}

const CORE_DIRS = [
electronParent ? path.join(electronParent, 'Electron') : '',
path.join(__dirname, '..', '..', 'paranext-core', 'dev-appdata'),
];

const EXT_DIRS = [
path.join(__dirname, '..', 'coverage'),
path.join(__dirname, '..', 'dist'),
path.join(__dirname, '..', 'src', 'temp-build'),
];

const NPM_PATHS = [
path.join(__dirname, '..', '..', 'paranext-core', 'node_modules'),
path.join(__dirname, '..', 'node_modules'),
path.join(__dirname, '..', 'package-lock.json'),
];

/**
* Delete a path if it exists
*
* @param {string} pathToDelete - The path to delete
*/
function deletePath(pathToDelete) {
if (!pathToDelete) {
console.log('⊘ Skipping empty path');
return;
}

try {
if (fs.existsSync(pathToDelete)) {
fs.rmSync(pathToDelete, { recursive: true, force: true });
console.log(`✓ Deleted ${pathToDelete}`);
} else {
console.log(`⊘ ${pathToDelete} does not exist`);
}
} catch (error) {
console.error(`✗ Failed to delete ${pathToDelete}:`, error.message);
}
}

// Delete paths based on command-line flags

try {
if (hasCoreFlag) {
console.log('Deleting core cache directories...');
CORE_DIRS.forEach(deletePath);
}

if (hasExtFlag) {
console.log('Deleting extension directories...');
EXT_DIRS.forEach(deletePath);
}

if (hasNpmFlag) {
console.log('Deleting node_modules and package-lock.json...');
NPM_PATHS.forEach(deletePath);
}

console.log('Complete!');
process.exit(0);
} catch (error) {
console.error('Error during cleanup:', error);
process.exit(1);
}
Loading