Skip to content

Commit 53ce7a6

Browse files
committed
feat: Parameterize binary and library
- Add MIT as license option BREAKING CHANGE: - Ask for path to deploy when running binary - Move dotenv call from library to binary - Use IPFS_DEPLOY prefix in env variables and change their names - Change deploy() signature to take credentials & domain as parameters
1 parent 990e6b8 commit 53ce7a6

File tree

6 files changed

+150
-43
lines changed

6 files changed

+150
-43
lines changed

LICENSE.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,25 @@ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
102102
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
103103
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
104104
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
105+
106+
---
107+
108+
# The MIT License
109+
110+
Permission is hereby granted, free of charge, to any person obtaining a copy of
111+
this software and associated documentation files (the "Software"), to deal in
112+
the Software without restriction, including without limitation the rights to
113+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
114+
of the Software, and to permit persons to whom the Software is furnished to do
115+
so, subject to the following conditions:
116+
117+
The above copyright notice and this permission notice shall be included in all
118+
copies or substantial portions of the Software.
119+
120+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
121+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
122+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
123+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
124+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
125+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
126+
SOFTWARE.

README.md

Lines changed: 86 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
> Pin directory locally, send hash to pinning service, and update dnslink.
66
7-
## 🚨 WARNING: This is alpha software and very much in "quick hack that works for me" status. Use with caution.
7+
## 🚨 WARNING: This is alpha software and very much in "works for me" status. APIs and CLI options will change. Use with caution, but please do, give feedback, and consider contributing :)
88

9-
The goal of @agentofuser/ipfs-deploy is to make it as easy as possible to
9+
The goal of `@agentofuser/ipfs-deploy` is to make it as easy as possible to
1010
deploy a static website to IPFS.
1111

1212
## Table of Contents
@@ -45,62 +45,125 @@ add it to the README.
4545

4646
## Install
4747

48-
```
48+
### As a library:
49+
50+
```bash
4951
npm install --save-dev @agentofuser/ipfs-deploy
5052
```
5153

54+
### As an executable:
55+
56+
```bash
57+
npm install -g @agentofuser/ipfs-deploy
58+
```
59+
60+
You might want to alias that in your terminal. I added this to my `~/.bashrc`:
61+
62+
```bash
63+
alias ipd='ipfs-deploy public'
64+
```
65+
66+
### No install:
67+
68+
You can run it directly with [npx](https://www.npmjs.com/package/npx 'npx')
69+
without needing to install anything:
70+
71+
```bash
72+
npx ipfs-deploy _site
73+
```
74+
75+
Just remember to have the credentials properly set up as instructed below.
76+
5277
## Usage
5378

79+
### As an executable:
80+
5481
I won't go over how to set up Pinata and Cloudflare right now, but you can read
5582
up on that over at:
5683

57-
https://www.cloudflare.com/distributed-web-gateway/
84+
https://www.cloudflare.com/distributed-web-gateway
5885

5986
and:
6087

6188
https://pinata.cloud/documentation#GettingStarted
6289

6390
(Infura doesn't require creating an account.)
6491

65-
Then copy over `.env.sample` to `.env` and fill out your credentials:
92+
After setting up your Cloudflare and Pinata accounts, in your website's
93+
repository root, create or edit the file `.env` with your domain and
94+
credentials:
6695

6796
```
68-
PINATA_API_KEY=
69-
PINATA_SECRET_API_KEY=
70-
SITE_DOMAIN=
71-
CF_API_KEY=
72-
CF_API_EMAIL=
97+
IPFS_DEPLOY_SITE_DOMAIN=
98+
IPFS_DEPLOY_PINATA__API_KEY=
99+
IPFS_DEPLOY_PINATA__SECRET_API_KEY=
100+
IPFS_DEPLOY_CLOUDFLARE__API_EMAIL=
101+
IPFS_DEPLOY_CLOUDFLARE__API_KEY=
73102
```
74103

75-
(**Don't** commit it!)
104+
(**Don't** commit it to source control unless you know what you're doing.)
76105

77106
```
78107
$ echo '.env' >> .gitignore
79108
```
80109

81-
Put this somewhere in a `deploy.js` file:
110+
Assuming your website's production build is at the `public` subdirectory
111+
(that's what Gatsby and Hugo use; Jekyll and Hakyll use `_site`), run this at
112+
the project's root:
82113

83-
```javascript
84-
const ipfsDeploy = require(@agentofuser/ipfs-deploy)
85-
ipfsDeploy()
114+
```bash
115+
ipfs-daemon public
86116
```
87117

88-
Add a deploy command to your `package.json`:
118+
To see more details about command line usage, run:
119+
120+
```bash
121+
ipfs-deploy --help
122+
```
123+
124+
You can optionally add a deploy command to your `package.json`:
89125

90126
```javascript
91127
//
92128
"scripts": {
93129
//
94-
"deploy": "node ./ipfs-deploy.js",
130+
"deploy": "npx ipfs-daemon public",
95131
//
96132
}
97133
//
98134
```
99135

100-
And when you have built your website into `./public/`, run:
136+
Then to run it, execute:
101137

138+
```bash
139+
npm run deploy
102140
```
103-
$ npm run deploy
141+
142+
### As a library:
143+
144+
````javascript
145+
const deploy = require('ipfs-deploy')
146+
147+
;(async () => {
148+
try {
149+
deploy({
150+
updateDns: true,
151+
open: false, // opens browser after deploying
152+
publicDirPath: 'public',
153+
remote: {
154+
siteDomain: 'example.com',
155+
cloudflare: {
156+
apiEmail,
157+
apiKey,
158+
},
159+
pinata: {
160+
apiKey,
161+
secretApiKey,
162+
},
163+
},
164+
})
165+
} catch (e) {}
166+
})()
104167
```
105168

106169
## Contributing
@@ -118,6 +181,8 @@ specification.
118181

119182
## License
120183

121-
[BlueOak-1.0.0 OR BSD-2-Clause-Patent © Agent of User](./LICENSE.md)
184+
[BlueOak-1.0.0 OR BSD-2-Clause-Patent OR MIT © Agent of User](./LICENSE.md)
122185

123-
(These are the most permissive possible ever.)
186+
(The first two are the most permissive possible ever, more than MIT, which
187+
doesn't have a patent waiver. Use whichever satisfies your lawyer better.)
188+
````

bin/ipfs-deploy.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ const chalk = require('chalk')
33

44
const deploy = require('../index')
55

6+
require('dotenv').config()
7+
68
const argv = require('yargs')
79
.scriptName('ipfs-deploy')
810
.usage(
@@ -15,6 +17,7 @@ const argv = require('yargs')
1517
default: './public/',
1618
describe: 'The path to deploy',
1719
})
20+
.env('IPFS_DEPLOY')
1821
.options({
1922
D: {
2023
type: 'boolean',
@@ -84,6 +87,17 @@ function main() {
8487
// pinners: argv.p, TODO
8588
// pinRemotely: !argv.P, TODO
8689
publicDirPath: argv.path,
90+
remote: {
91+
siteDomain: argv.siteDomain,
92+
cloudflare: {
93+
apiKey: argv.cloudflare.apiKey,
94+
apiEmail: argv.cloudflare.apiEmail,
95+
},
96+
pinata: {
97+
apiKey: argv.pinata.apiKey,
98+
secretApiKey: argv.pinata.secretApiKey,
99+
},
100+
},
87101
})
88102
}
89103

index.js

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,22 @@ const ora = require('ora')
88
const chalk = require('chalk')
99
const openUrl = require('open')
1010

11-
require('dotenv').config()
12-
13-
async function doUpdateDns(hash) {
14-
const key = process.env.CF_API_KEY
15-
const email = process.env.CF_API_EMAIL
16-
const domain = process.env.SITE_DOMAIN
17-
11+
async function doUpdateDns({ siteDomain, cloudflare }, hash) {
1812
const spinner = ora()
1913

20-
if (!key || !email || !domain || !hash) {
14+
const { apiEmail, apiKey } = cloudflare
15+
if (!apiKey || !apiEmail || !siteDomain || !hash) {
2116
throw new Error('Missing information for doUpdateDns()')
2217
}
2318

2419
const api = {
25-
key,
26-
email,
20+
email: apiEmail,
21+
key: apiKey,
2722
}
2823

2924
const opts = {
30-
record: domain,
31-
zone: domain,
25+
record: siteDomain,
26+
zone: siteDomain,
3227
link: `/ipfs/${hash}`,
3328
}
3429

@@ -44,7 +39,7 @@ async function doUpdateDns(hash) {
4439
spinner.info(`${chalk.whiteBright(content)}.`)
4540
spinner.succeed('🌐 Your website is deployed now.')
4641
} catch (err) {
47-
console.log(err)
42+
console.error(err)
4843
process.exit(1)
4944
}
5045
}
@@ -55,6 +50,17 @@ async function deploy({
5550
// pinners = ['pinata', 'infura'], TODO
5651
// pinRemotely = true, TODO
5752
publicDirPath = 'public',
53+
remote = {
54+
siteDomain,
55+
cloudflare: {
56+
apiEmail,
57+
apiKey,
58+
},
59+
pinata: {
60+
apiKey,
61+
secretApiKey,
62+
},
63+
},
5864
} = {}) {
5965
const ipfsBinAbsPath =
6066
which.sync('ipfs', { nothrow: true }) ||
@@ -104,16 +110,16 @@ async function deploy({
104110
const pinataOptions = {
105111
host_nodes: publicMultiaddresses,
106112
pinataMetadata: {
107-
name: process.env.SITE_DOMAIN,
113+
name: remote.siteDomain,
108114
keyvalues: {
109115
gitCommitHash: 'TODO',
110116
},
111117
},
112118
}
113119

114120
const pinata = pinataSDK(
115-
process.env.PINATA_API_KEY,
116-
process.env.PINATA_SECRET_API_KEY
121+
remote.pinata.apiKey,
122+
remote.pinata.secretApiKey
117123
)
118124

119125
spinner.info(
@@ -151,9 +157,9 @@ async function deploy({
151157
`📋 Hash ${chalk.green(hash)} copied to clipboard.`
152158
)
153159

154-
if (updateDns) doUpdateDns(hash)
160+
if (updateDns) doUpdateDns(remote, hash)
155161

156-
if (open) openUrl(`https://${process.env.SITE_DOMAIN}`)
162+
if (open) openUrl(`https://${remote.siteDomain}`)
157163
})
158164
.catch(err5 => {
159165
throw err5

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"lint-staged": "^8.1.5",
5757
"ndb": "^1.0.44",
5858
"prettier": "^1.16.4",
59-
"semantic-git-commit-cli": "^3.2.1",
59+
"semantic-git-commit-cli": "^3.2.2",
6060
"semantic-release": "^15.13.8",
6161
"semantic-release-cli": "^4.1.1"
6262
},

0 commit comments

Comments
 (0)