From d8654db47221f2917fbdf10be79d38a8f7e8fad3 Mon Sep 17 00:00:00 2001 From: filip mertens Date: Mon, 20 Mar 2023 14:41:00 +0100 Subject: [PATCH] ipfs --- apps/remix-ide/ci/publish_plugin.ts | 54 ++++++++++++++++++++++++++--- 1 file changed, 49 insertions(+), 5 deletions(-) diff --git a/apps/remix-ide/ci/publish_plugin.ts b/apps/remix-ide/ci/publish_plugin.ts index ffbfadb3ee..90d41410ae 100644 --- a/apps/remix-ide/ci/publish_plugin.ts +++ b/apps/remix-ide/ci/publish_plugin.ts @@ -1,13 +1,23 @@ import fetch from "node-fetch"; +import fs from "fs"; +import ipfsClient from 'ipfs-http-client' + (async () => { const pluginsDirectory = 'https://raw.githubusercontent.com/ethereum/remix-plugins-directory/master/build/metadata.json' const metadata = await fetch(pluginsDirectory, { method: 'GET' }) - + // get command line arguments const args = process.argv.slice(2) const pluginName = args[0] const sha = args[1] const build = args[2] + let sha_field = 'sha_' + build + let url_field = 'url_' + build + + if(build === 'master') { + sha_field = 'sha' + url_field = 'url' + } console.log(process.argv) @@ -19,14 +29,48 @@ import fetch from "node-fetch"; // search for the plugin in the metadata const plugins = await metadata.json() const plugin = plugins.find((p: any) => p.name === pluginName) + let profileJSON: any = null + try{ + profileJSON = JSON.parse(fs.readFileSync(`apps/${pluginName}/profile.json`, 'utf8')) + }catch(e){ + console.log('local profile.json not found') + } + if (!plugin) { - console.error('plugin not found') - process.exit(1) + console.error('plugin not found in the directory, attempting to create it...') + if(!profileJSON){ + console.error('create a profile.json file in the plugin folder') + process.exit(1) + } + } + + // check if build and sha exist + if (plugin[url_field] && plugin[sha_field]) { + // compare the sha + if (plugin[sha_field] === sha) { + console.log('plugin already published') + process.exit(0) + } } // update the plugin - plugin[build] = 'someurl' - plugin.sha = sha + plugin[url_field] = 'someurl' + plugin[sha_field] = sha console.log('publishing plugin', plugin, 'with sha', sha, 'and build', build) + + // publish the plugin + const globalIPFSConfig = { + host: 'ipfs-cluster.ethdevops.io', + port: 5001, + protocol: 'https', + ipfsurl: 'https://ipfs.io/ipfs/' + } + const ipfs = ipfsClient(globalIPFSConfig) + const { globSource } = ipfsClient + const folder = `apps/${pluginName}` + + console.log(ipfs) + let result = await ipfs.add(globSource(folder, { recursive: true}), { pin: true }) + })() \ No newline at end of file