Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Desktop: Bundle default plugins with desktop application #6679

Merged
merged 20 commits into from
Sep 1, 2022
Merged
Changes from 2 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
12 changes: 6 additions & 6 deletions packages/tools/bundleDefaultPlugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,13 @@ export const localPluginsVersion = async (defaultPluginDir: string, defaultPlugi

async function downloadFile(url: string, outputPath: string) {
const response = await fetch(url);
laurent22 marked this conversation as resolved.
Show resolved Hide resolved
if (!response.ok) {
throw new Error(`Cannot download file from ${url}`);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here too you might want to provide more info such as response.status or response.text

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 👍

}
await writeFile(outputPath, await response.buffer());
}

export async function extractPlugins(currentDir: string, defaultPluginDir: string, downloadedPluginsNames: PluginIdAndName) {
export async function extractPlugins(currentDir: string, defaultPluginDir: string, downloadedPluginsNames: PluginIdAndName): Promise<void> {
for (const pluginId of Object.keys(downloadedPluginsNames)) {
await execCommand2(`tar xzf ${currentDir}/${downloadedPluginsNames[pluginId]}`);
await move(`package/publish/${pluginId}.jpl`,`${defaultPluginDir}/${pluginId}/plugin.jpl`, { overwrite: true });
Expand All @@ -45,16 +48,15 @@ export async function extractPlugins(currentDir: string, defaultPluginDir: strin
}
}

export const downloadPlugins = async (localPluginsVersions: PluginAndVersion, defaultPluginsInfo: DefaultPluginsInfo, manifests: any): Promise<any> => {
export const downloadPlugins = async (localPluginsVersions: PluginAndVersion, defaultPluginsInfo: DefaultPluginsInfo, manifests: any): Promise<PluginIdAndName> => {

const downloadedPluginsNames: PluginIdAndName = {};
for (const pluginId of Object.keys(defaultPluginsInfo)) {
if (localPluginsVersions[pluginId] === defaultPluginsInfo[pluginId].version) continue;
const response = await fetch(`https://registry.npmjs.org/${manifests[pluginId]._npm_package_name}`);

if (!response.ok) {
const responseText = await response.text();
throw new Error(`Cannot download plugin file ${responseText.substr(0,500)}`);
throw new Error(`Cannot fetch ${manifests[pluginId]._npm_package_name} release info from NPM`);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually your previous code was good, as you were showing the actual error message. Any reason you removed it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, while testing locally I thought that .text() will show buffer data but on failing to fetch it won't have any buffer data to show 😅 . Restored the previous message.

}
const releaseText = await response.text();
const release = JSON.parse(releaseText);
Expand All @@ -64,8 +66,6 @@ export const downloadPlugins = async (localPluginsVersions: PluginAndVersion, de
const pluginName = `${manifests[pluginId]._npm_package_name}-${defaultPluginsInfo[pluginId].version}.tgz`;
await downloadFile(pluginUrl, pluginName);

if (!await pathExists(pluginName)) throw new Error(`${pluginName} cannot be downloaded`);

downloadedPluginsNames[pluginId] = pluginName;
}
return downloadedPluginsNames;
Expand Down