Skip to content

Commit

Permalink
add alwaysCleanCache flag to always remove it in case is passed
Browse files Browse the repository at this point in the history
  • Loading branch information
hugomontero committed Jan 31, 2025
1 parent baaadc1 commit 953c282
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 27 deletions.
4 changes: 2 additions & 2 deletions src/cmd/download-tachyon-package.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ module.exports = class DownloadTachyonPackageCommand extends CLICommandBase {
const answer = await this.ui.prompt(question);
return answer.version;
}
async download ({ region, version }) {
async download ({ region, version, alwaysCleanCache = false }) {
// prompt for region and version if not provided
if (!region) {
region = await this._selectRegion();
Expand All @@ -52,7 +52,7 @@ module.exports = class DownloadTachyonPackageCommand extends CLICommandBase {
}
const { artifact_url: url, sha256_checksum: expectedChecksum } = build.artifacts[0];
const outputFileName = url.replace(/.*\//, '');
const filePath = await manager.download({ url, outputFileName, expectedChecksum });
const filePath = await manager.download({ url, outputFileName, expectedChecksum, options: { alwaysCleanCache } });
this.ui.write(`Downloaded package to: ${filePath}`);

return filePath;
Expand Down
55 changes: 30 additions & 25 deletions src/cmd/setup-tachyon.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,7 @@ module.exports = class SetupTachyonCommands extends CLICommandBase {

async setup({ skip_flashing_os: skipFlashingOs, version, load_config: loadConfig, save_config: saveConfig }) {
try {
this.ui.write(`
===========================================================
Particle Tachyon Setup Command
===========================================================
Welcome to the Particle Tachyon setup! This interactive command:
- Flashes your Tachyon device
- Configures it (password, WiFi credentials etc...)
- Connects it to the internet and the Particle Cloud!
**What you'll need:**
1. Your Tachyon device
2. The Tachyon battery
3. A USB-C cable
**Important:**
- This tool requires you to be logged into your Particle account.
- For more details, check out the documentation at: https://part.cl/setup-tachyon`);

this._showWelcomeMessage();
this._formatAndDisplaySteps("Okay—first up! Checking if you're logged in...", 1);

await this._verifyLogin();
Expand All @@ -66,6 +46,7 @@ Welcome to the Particle Tachyon setup! This interactive command:
}

let config = { systemPassword: null, wifi: null, sshPublicKey: null };
let alwaysCleanCache = false;

if ( !loadConfig ) {
config = await this._runStepWithTiming(
Expand All @@ -81,6 +62,7 @@ Welcome to the Particle Tachyon setup! This interactive command:
0
);
} else {
alwaysCleanCache = true;
this.ui.write(
`${os.EOL}${os.EOL}Skipping to Step 3 - Using configuration file: ` + loadConfig + `${os.EOL}`
);
Expand All @@ -100,7 +82,7 @@ Welcome to the Particle Tachyon setup! This interactive command:
`if it's interrupted. If you have to kill the CLI, it will pick up where it left. You can also${os.EOL}` +
"just let it run in the background. We'll wait for you to be ready when its time to flash the device.",
4,
() => this._download({ region, version })
() => this._download({ region, version, alwaysCleanCache })
);

const registrationCode = await this._runStepWithTiming(
Expand Down Expand Up @@ -168,6 +150,29 @@ Welcome to the Particle Tachyon setup! This interactive command:
}
}

async _showWelcomeMessage() {
this.ui.write(`
===================================================================================
Particle Tachyon Setup Command
===================================================================================
Welcome to the Particle Tachyon setup! This interactive command:
- Flashes your Tachyon device
- Configures it (password, WiFi credentials etc...)
- Connects it to the internet and the Particle Cloud!
**What you'll need:**
1. Your Tachyon device
2. The Tachyon battery
3. A USB-C cable
**Important:**
- This tool requires you to be logged into your Particle account.
- For more details, check out the documentation at: https://part.cl/setup-tachyon`);
}

async _runStepWithTiming(stepDesc, stepNumber, asyncTask, minDuration = 2000) {
this._formatAndDisplaySteps(stepDesc, stepNumber);

Expand All @@ -189,7 +194,7 @@ Welcome to the Particle Tachyon setup! This interactive command:

async _formatAndDisplaySteps(text, step) {
// Display the formatted step
this.ui.write(`${os.EOL}===========================================================${os.EOL}`);
this.ui.write(`${os.EOL}===================================================================================${os.EOL}`);
this.ui.write(`Step ${step}:${os.EOL}`);
this.ui.write(`${text}${os.EOL}`);
}
Expand Down Expand Up @@ -325,7 +330,7 @@ Welcome to the Particle Tachyon setup! This interactive command:
return { systemPassword, wifi, sshPublicKey };
}

async _download({ region, version }) {
async _download({ region, version, alwaysCleanCache }) {

//before downloading a file, we need to check if 'version' is a local file or directory
//if it is a local file or directory, we need to return the path to the file
Expand All @@ -344,7 +349,7 @@ Welcome to the Particle Tachyon setup! This interactive command:
const outputFileName = url.replace(/.*\//, '');
const expectedChecksum = artifact.sha256_checksum;

return manager.download({ url, outputFileName, expectedChecksum });
return manager.download({ url, outputFileName, expectedChecksum, options: { alwaysCleanCache } });
}

async _getSystemPassword() {
Expand Down

0 comments on commit 953c282

Please sign in to comment.