forked from web3-storage/example-image-gallery
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdeploy.js
More file actions
33 lines (27 loc) · 1.07 KB
/
deploy.js
File metadata and controls
33 lines (27 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// This script will upload the contents of the `dist` folder to web3.storage, so you
// can view the application using an IPFS gateway.
const fs = require('fs')
const { Web3Storage, getFilesFromPath } = require('web3.storage')
function die(message) {
console.error(message)
process.exit(1)
}
async function deploy() {
const { WEB3STORAGE_TOKEN } = process.env
if (!WEB3STORAGE_TOKEN) {
die('this script needs an env variable named WEB3STORAGE_TOKEN containing API token for web3.storage')
}
if (!fs.existsSync('./dist')) {
die('dist folder not found. Try running this first: npm run build')
}
const web3Storage = new Web3Storage({ token: WEB3STORAGE_TOKEN })
console.log('Loading site files...')
const files = await getFilesFromPath('./dist')
console.log(`Uploading ${files.length} files to Web3.Storage...`)
const cid = await web3Storage.put(files, { wrapWithDirectory: false })
console.log('Deployed to Web3.Storage!')
console.log('Root cid: ', cid)
console.log(`Gateway url: https://${cid}.ipfs.dweb.link`)
}
deploy()
.catch(console.error)