Skip to content
Open
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
Binary file modified assets/qdl/darwin/arm64/libusb-1.0.0.dylib
Binary file not shown.
Binary file modified assets/qdl/darwin/arm64/qdl
Binary file not shown.
Binary file modified assets/qdl/darwin/x64/libusb-1.0.0.dylib
Binary file not shown.
Binary file modified assets/qdl/darwin/x64/qdl
Binary file not shown.
Binary file modified assets/qdl/linux/arm64/qdl
Binary file not shown.
Binary file modified assets/qdl/linux/x64/qdl
Binary file not shown.
Binary file modified assets/qdl/win32/x64/liblzma-5.dll
Binary file not shown.
Binary file modified assets/qdl/win32/x64/libusb-1.0.dll
Binary file not shown.
Binary file added assets/qdl/win32/x64/libxml2-16.dll
Binary file not shown.
Binary file modified assets/qdl/win32/x64/qdl.exe
Binary file not shown.
671 changes: 112 additions & 559 deletions src/cmd/setup-tachyon.js

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions src/lib/download-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ class DownloadManager {
}
}

async fetchManifest({ version = 'stable', isRb3Board = false }) {
const type = isRb3Board ? 'rb3g2' : 'tachyon';
async fetchManifest({ version = 'stable', type = 'tachyon' }) {
const metadataUrl = `${settings.tachyonMeta}/${type}-${encodeURIComponent(version)}.json`;

try {
Expand All @@ -49,7 +48,6 @@ class DownloadManager {

return response.json();
} catch (err) {
console.log(err);
throw new Error('Could not download the version file. Please check your internet connection.');
}
}
Expand Down
62 changes: 61 additions & 1 deletion src/lib/tachyon-utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const fs = require('fs-extra');
const os = require('os');
const semver = require('semver');
const { getEdlDevices } = require('particle-usb');
const { delay } = require('./utilities');
const unzip = require('unzipper');
const DEVICE_READY_WAIT_TIME = 500; // ms
const UI = require('./ui');
const QdlFlasher = require('./qdl');
Expand Down Expand Up @@ -485,6 +487,61 @@ async function handleFlashError({ error, ui }) {
return false;
}

/**
*
* @param ui
* @return {Promise<Workflow>}
*/
async function promptOSSelection({ ui, workflows }) {
const choices = Object.values(workflows);
const question = [{
type: 'list',
name: 'osType',
message: ui.chalk.bold.white('Select the OS Type to setup in your device'),
choices
}];
const { osType } = await ui.prompt(question);
return workflows[osType];
}

async function isFile(version) {
const validChannels = ['latest', 'stable', 'beta', 'rc'];
const isValidChannel = validChannels.includes(version);
const isValidSemver = semver.valid(version);
const isFile = !isValidChannel && !isValidSemver;

// access(OK
if (isFile) {
try {
await fs.access(version, fs.constants.F_OK | fs.constants.R_OK);
} catch (error) {
if (error.code === 'ENOENT') {
throw new Error(`The file "${version}" does not exist.`);
} else if (error.code === 'EACCES') {
throw new Error(`The file "${version}" is not accessible (permission denied).`);
}
throw error;
}
}
return isFile;
}

async function readManifestFromLocalFile(path, targetFile = 'manifest.json') {
const directory = await unzip.Open.file(path);
const entry = directory.files.find(f => f.path.endsWith(targetFile));

if (!entry) {
throw new Error(`File "${targetFile}" not found in ${path}`);
}
// Stream and parse
const content = await entry.buffer();
try {
return JSON.parse(content.toString('utf8'));
} catch (err) {
throw new Error(`Invalid JSON in ${targetFile}: ${err.message}`);
}
}

module.exports = {
addLogHeaders,
addManifestInfoLog,
Expand All @@ -493,5 +550,8 @@ module.exports = {
prepareFlashFiles,
getTachyonInfo,
promptWifiNetworks,
handleFlashError
handleFlashError,
promptOSSelection,
isFile,
readManifestFromLocalFile
};
Loading
Loading