Skip to content

Commit

Permalink
refactor: Spin start/stop and configuration out of core repo and into…
Browse files Browse the repository at this point in the history
… quickstart.
  • Loading branch information
haydenyoung committed Jan 18, 2024
1 parent 2136a60 commit 3c1955c
Show file tree
Hide file tree
Showing 22 changed files with 14,602 additions and 128 deletions.
3 changes: 0 additions & 3 deletions .eslintignore

This file was deleted.

3 changes: 0 additions & 3 deletions .eslintrc

This file was deleted.

12 changes: 12 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# These are supported funding model platforms

github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: # Replace with a single Patreon username
open_collective: orbitdb
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: ["https://github.com/orbitdb/funding"]
26 changes: 26 additions & 0 deletions .github/workflows/npm-publish-next.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
name: Node.js Package (next tag)

on:
push:
branches:
- main

jobs:
publish-npm:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 'lts/*'
registry-url: https://registry.npmjs.org/
- run: npm ci
- run: npm run lint
- run: npm test
- run: |
npm version prerelease --no-git-tag-version \
--preid=`git rev-parse --short HEAD`
npm publish --tag next
env:
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
22 changes: 22 additions & 0 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
name: Node.js Package

on:
push:
tags:
- 'v*'

jobs:
publish-npm:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 'lts/*'
registry-url: https://registry.npmjs.org/
- run: npm ci
- run: npm test
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
36 changes: 36 additions & 0 deletions .github/workflows/run-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
name: Run Tests

on: [push, pull_request]

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 'lts/*'
registry-url: https://registry.npmjs.org/
- name: Install dependencies
run: npm ci
- name: Run linter
run: npm run lint
- name: Run tests
run: npm run test:ci
test-browser:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 'lts/*'
registry-url: https://registry.npmjs.org/
- name: Install dependencies
run: npm ci
- name: Run linter
run: npm run lint
- name: Run a webrtc relay in the background
run: npm run webrtc:background
- name: Run browser tests
run: npm run test:browser
18 changes: 18 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Don't distribute the dependencies
node_modules/

#Don't track ipfs files
test/ipfs/
test/browser/ipfs/
test/browser/bundle.js*

# Don't track builds in git
# Distribution builds are available via npm
dist/

# Don't track Visual Studio Code settings
.vscode

# JSDoc output folder
docs/api/*
!docs/api/README.md
10 changes: 10 additions & 0 deletions .mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"reporter": "spec",
"colors": true,
"recursive": true,
"exit": true,
"bail": false,
"slow": 1000,
"exclude": ["test/browser/**/*.js", "test/utils/relay.js"],
"timeout": 30000
}
14 changes: 7 additions & 7 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ orbitdb/
# Don't distribute the dependencies
node_modules/

# Don't distribute examples with the module
# See examples at https://github.com/orbitdb/orbit-db
examples/

# Don't distribute source maps
dist/*.map

# Don't distribute the debug build
dist/orbitdb.js

# Don't distribute screenshot
# See examples at https://github.com/orbitdb/orbit-db
screenshots/
.git
benchmarks
test
conf
Makefile
CONTRIBUTING.md
CODE_OF_CONDUCT.md
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Please contribute! Here are some things that would be great:

- [Open an issue!](https://github.com/orbitdb/<Replace Title>/issues/new)
- [Open an issue!](https://github.com/orbitdb/quickstart/issues/new)
- Open a pull request!
- Say hi! :wave:

Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2019 Haja Networks Oy
Copyright (c) 2024 OrbitDB Community

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
93 changes: 31 additions & 62 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,88 +1,57 @@
# Repo Template
# OrbitDB Quickstart

[![Gitter](https://img.shields.io/gitter/room/nwjs/nw.js.svg)](https://gitter.im/orbitdb/Lobby) [![Matrix](https://img.shields.io/badge/matrix-%23orbitdb%3Apermaweb.io-blue.svg)](https://riot.permaweb.io/#/room/#orbitdb:permaweb.io)
[![Matrix](https://img.shields.io/matrix/orbit-db%3Amatrix.org)](https://app.element.io/#/room/#orbit-db:matrix.org) [![npm (scoped)](https://img.shields.io/npm/v/%40orbitdb/quickstart)](https://www.npmjs.com/package/@orbitdb/quickstart) [![node-current (scoped)](https://img.shields.io/node/v/%40orbitdb/quickstart)](https://www.npmjs.com/package/@orbitdb/quickstart)

> A template for creating new repositories in the @orbitdb organization
A preconfigured instance which allows developers to "test drive" OrbitDB.

This repository is meant to serve as a general template for how to set up new repositories in the @orbitdb organization. In general, setting up a new repository should take only a few minutes; use this repository as a way of finding example files, and use the following checklist to ensure that you've set up the repository correctly.
This repository provides convenience functions and configurations to deploy OrbitDB quickly and with minimal knowledge of Helia/Libp2p.

## Install

These instructions are basic; you can use any method to do this work. The important part is making sure that you follow the checklist below before publishing the repository.
This project uses [npm](http://npmjs.com/) and [nodejs](https://nodejs.org/).

```sh
# Let's make a new folder
mkdir new-repo && cd new-repo
# Start a Git instance and copy over template files.
git init
cp ../repo-template/* .
# Overwrite this README
mv README.md setup-checklist.md
mv example-README.md README.md
# Go over and check off the checklist, and finally
rm setup-checklist
npm i @orbitdb/quickstart
```

## Checklist
## Usage

Go through this checklist after creating your repository. It should only take a couple of minutes; if there is a way to make this more efficient, open an issue and let's talk about it here! \m/
To launch a OrbitDB instance and open a database, run `startOrbitDB`:

### README
- [ ] Copy `example-README.md` from this repository to your directory.
- [ ] Rename all instances of `<Replace Title>` in README to match the new repo title
- [ ] Manually go through and edit the rest of the README.
```js
import { startOrbitDB, stopOrbitDB } from '@orbitdb/quickstart'

### Other Files
- [ ] Copy `CODE_OF_CONDUCT.md` verbatim.
- [ ] Copy `CONTRIBUTING.md` and ensure that you've added any repository-specific instructions. (Replace `<Replace Title>` again).
- [ ] Should you have a `CHANGELOG.md`? Document your release process, if you plan on having one, in the `CONTRIBUTING.md` file.

### Dotfiles
- [ ] Do you need a `.gitignore` file?
- [ ] Do you need an `.npmignore` file?

### License
- [ ] Copy the MIT license from the example repo.
- [ ] Is `Haja Networks Oy` the licensor?
- [ ] Have you added `MIT` as the license in the `package.json`?
- [ ] If you made changes, were these reflected in the last section of the README?
const orbitdb = await startOrbitDB()
const db1 = await orbitdb.open('db1')
await db1.add('hello world!')
await stopOrbitDB(orbitdb)
```

### GitHub Metadata
- [ ] Have you added a short description to the repository?
- [ ] Is the description matched in the byline under the title in the README?
- [ ] Have you added topics to the GitHub repository: `orbitdb`, `orbit`, and so on?
- [ ] Have you added these topics as keywords in the `package.json`?
OrbitDB Quickstart also includes default Libp2p configurations for Node.js and browser for basic connections between multiple peers:

### `package.json`
```js
import { createOrbitDB } from '@orbitdb/core'
import { DefaultLibp2pOptions } from '@orbitdb/quickstart'

- [ ] Is the `author` field correct?
- [ ] Have you added `keywords`?
- [ ] Are the `bugs` and `homepage` fields correct?
- [ ] Have you added tests? Are they matched, here?
- [ ] Have you added a `lint` command, if using [`eslint-config-orbitdb`](https://github.com/orbitdb/eslint-config-orbitdb)?
const libp2p = createLibp2p({ ...DefaultLibp2pOptions })
const ipfs = await createHelia({ libp2p })

### Tests
const orbitdb = await createOrbitDB({ ipfs })

- [ ] Are there automated tests?
- [ ] ...for the browser as well?
- [ ] Are those reflected in CI?
- [ ] Bonus points: Using CircleCI workflows to segment tests?
- [ ] Extra bonus points: Are you cross-testing dependencies (i.e. are changes in `orbit-db-keystore` tested in `orbit-db` as well
const db1 = await orbitdb.open('db1')
await db1.add('hello world!')
```

### Benchmarks
- [ ] Are there benchmarks?
- [ ] Did you run the benchmarks before / after the change or PR?
## Contribute

### Examples
- [ ] Is there an example folder with usage examples?
- [ ] For the browser as well?
We would be happy to accept PRs! If you want to work on something, it'd be good to talk beforehand to make sure nobody else is working on it. You can reach us [on Gitter](https://gitter.im/orbitdb/Lobby), or in the [issues section](https://github.com/orbitdb/<Replace Title>/issues).

## Contribute
We also have **regular community calls**, which we announce in the issues in [the @orbitdb welcome repository](https://github.com/orbitdb/welcome/issues). Join us!

If you think this could be better, please [open an issue](https://github.com/orbitdb/repo-template/issues/new)!
If you want to code but don't know where to start, check out the issues labelled ["help wanted"](https://github.com/orbitdb/quickstart/issues?q=is%3Aopen+is%3Aissue+label%3A%22help+wanted%22+sort%3Areactions-%2B1-desc).

Please note that all interactions in [@OrbitDB](https://github.com/orbitdb) fall under our [Code of Conduct](CODE_OF_CONDUCT.md).
For specific guidelines for contributing to this repository, check out the [Contributing guide](CONTRIBUTING.md). For more on contributing to OrbitDB in general, take a look at the [@OrbitDB welcome repository](https://github.com/orbitdb/welcome). Please note that all interactions in [@OrbitDB](https://github.com/orbitdb) fall under our [Code of Conduct](CODE_OF_CONDUCT.md).

## License

[MIT](LICENSE) © 2018 Haja Networks Oy
[MIT](LICENSE) © 2024 OrbitDB Community
38 changes: 38 additions & 0 deletions conf/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import path from 'path'
import { fileURLToPath } from 'url'

export default (env, argv) => {
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)

return {
mode: 'production',
entry: './src/index.js',
output: {
filename: '../dist/orbitdb-quickstart.min.js',
library: {
name: 'OrbitDB',
type: 'var'
}
},
target: 'web',
externals: {
fs: '{ existsSync: () => true }',
mkdirp: '{}'
},
resolve: {
modules: [
'node_modules',
path.resolve(__dirname, '../node_modules')
]
},
resolveLoader: {
modules: [
'node_modules',
path.resolve(__dirname, '../node_modules')
],
extensions: ['.js', '.json'],
mainFields: ['loader', 'main']
}
}
}
39 changes: 39 additions & 0 deletions conf/webpack.debug.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import path from 'path'
import { fileURLToPath } from 'url'

export default (env, argv) => {
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)

return {
mode: 'development',
entry: './src/index.js',
output: {
filename: '../dist/orbitdb-quickstart.js',
library: {
name: 'OrbitDB',
type: 'var'
}
},
target: 'web',
devtool: 'source-map',
externals: {
fs: '{ existsSync: () => true }',
mkdirp: '{}'
},
resolve: {
modules: [
'node_modules',
path.resolve(__dirname, '../node_modules')
]
},
resolveLoader: {
modules: [
'node_modules',
path.resolve(__dirname, '../node_modules')
],
extensions: ['.js', '.json'],
mainFields: ['loader', 'main']
}
}
}
Loading

0 comments on commit 3c1955c

Please sign in to comment.