remix-project mirror
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
remix-project/apps/remix-ide/ci/publish_plugin.ts

79 lines
2.3 KiB

2 years ago
import fetch from "node-fetch";
2 years ago
import fs from "fs";
2 years ago
import IpfsHttpClient from 'ipfs-http-client'
2 years ago
2 years ago
(async () => {
const pluginsDirectory = 'https://raw.githubusercontent.com/ethereum/remix-plugins-directory/master/build/metadata.json'
const metadata = await fetch(pluginsDirectory, { method: 'GET' })
2 years ago
2 years ago
// get command line arguments
2 years ago
const args = process.argv.slice(2)
2 years ago
const pluginName = args[0]
const sha = args[1]
const build = args[2]
2 years ago
let sha_field = 'sha_' + build
let url_field = 'url_' + build
if(build === 'master') {
sha_field = 'sha'
url_field = 'url'
}
2 years ago
2 years ago
console.log(process.argv)
2 years ago
if (!pluginName || !sha || !build) {
console.error('missing arguments')
process.exit(1)
}
// search for the plugin in the metadata
const plugins = await metadata.json()
const plugin = plugins.find((p: any) => p.name === pluginName)
2 years ago
let profileJSON: any = null
try{
profileJSON = JSON.parse(fs.readFileSync(`apps/${pluginName}/profile.json`, 'utf8'))
}catch(e){
console.log('local profile.json not found')
}
2 years ago
if (!plugin) {
2 years ago
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)
}
2 years ago
}
// update the plugin
2 years ago
plugin[url_field] = 'someurl'
plugin[sha_field] = sha
2 years ago
console.log('publishing plugin', plugin, 'with sha', sha, 'and build', build)
2 years ago
// publish the plugin
2 years ago
const host = 'ipfs.infura.io'
const projectId = process.env.infura_project_id
const projectSecret = process.env.infura_project_secret
const auth = 'Basic ' + Buffer.from(projectId + ':' + projectSecret).toString('base64')
const ipfs = IpfsHttpClient({ port: 5001, host, protocol: 'https', headers: {
authorization: auth
} })
const { globSource } = IpfsHttpClient
2 years ago
const folder = `dist/apps/${pluginName}`
2 years ago
2 years ago
const result = await ipfs.add(globSource(folder, { recursive: true}), { pin: true })
const hash = result.cid.toString()
2 years ago
const url = `https://ipfs-cluster.ethdevops.io/ipfs/${hash}`
console.log('ipfs hash', hash, 'url', url)
2 years ago
2 years ago
})()