Skip to content
This repository has been archived by the owner on May 11, 2021. It is now read-only.

Commit

Permalink
mono-repo to single project
Browse files Browse the repository at this point in the history
  • Loading branch information
neonphog committed Mar 5, 2019
1 parent 6501c5b commit 0f3f899
Show file tree
Hide file tree
Showing 179 changed files with 2,346 additions and 14,717 deletions.
20 changes: 1 addition & 19 deletions README.md
Expand Up @@ -35,13 +35,7 @@ First, make sure our own dependencies are installed:
npm install
```

Next, install all project dependencies (through lerna monorepo manager):

```shell
npm run bootstrap
```

Now, test all projects:
Now, to test:

```shell
npm test
Expand All @@ -51,18 +45,6 @@ npm test

Holochain is an open source project. We welcome all sorts of participation and are actively working on increasing surface area to accept it. Please see our [contributing guidelines](https://github.com/holochain/org/blob/master/CONTRIBUTING.md) for our general practices and protocols on participating in the community.

### Lerna

This monorepo is managed with the [Lerna](https://www.npmjs.com/package/lerna) helper tool.

### New projects

To create a new project, execute the following and fill out the prompts:

```shell
npm run new
```

## License
[![License: Apache-2.0](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0)

Expand Down
157 changes: 157 additions & 0 deletions bin/n3h
@@ -0,0 +1,157 @@
#!/usr/bin/env node

const fs = require('fs')
const path = require('path')
const os = require('os')

const { mkdirp } = require('../lib/n3h-common')
const tweetlog = require('../lib/tweetlog')
const log = tweetlog('n3h-bin')

const { buildLogHandler } = require('../lib/file-logger')
const { N3hNode, N3hHackMode, N3hMock } = require('../lib/index')
const { unhandledRejection } = require('../lib/n3h-common')
unhandledRejection.strict()

async function main () {
const workDir = 'N3H_WORK_DIR' in process.env
? process.env.N3H_WORK_DIR
: path.resolve(path.join(
os.homedir(), '.n3h'))

// Move into working directory?
await mkdirp(workDir)
process.chdir(workDir)

const logDir = path.join(workDir, 'logs')
await mkdirp(logDir)

const logHandler = buildLogHandler({
dir: logDir
})

// setup logging
tweetlog.set('t') // enable trace logging
tweetlog.listen(logHandler)

const quietMode = 'N3H_QUIET' in process.env
if (!quietMode) {
tweetlog.listen((level, tag, ...args) => {
args = args.map(a => {
if (a instanceof Error) {
return a.stack || a.toString()
} else if (typeof a === 'object') {
return JSON.stringify(a)
}
return a.toString()
}).join(' ')
console.error(`(${tag}) [${level}] ${args}`)
})
}

let rawConfigData = null

try {
rawConfigData = JSON.parse((await _tryReadStdin()).toString())
log.w('got stdin config!', rawConfigData)
} catch (e) {
log.w('could not read stdin', e)
}

if (!rawConfigData) {
try {
rawConfigData = JSON.parse(fs.readFileSync(path.resolve('n3h-config.json')))
} catch (e) {
log.w('failed to load config', e)
}
}

let mode = 'HACK'

// mode from config
if (rawConfigData && 'mode' in rawConfigData) {
mode = rawConfigData.mode
}

// environment mode override
if ('N3H_MODE' in process.env) {
mode = process.env.N3H_MODE
}

var n3hNode = null

let terminated = false
const terminate = async () => {
if (terminated) {
return
}
try {
if (n3hNode) {
await n3hNode.destroy()
}
log.i('n3h exited cleanly')
await logHandler.cleanup()
process.exit(0)
} catch (e) {
try {
await logHandler.cleanup()
} catch (e) { /* pass */ }
log.e(e.stack || e.toString())
process.exit(1)
}
}

process.on('SIGINT', terminate)
process.on('SIGTERM', terminate)
process.on('unhandledRejection', err => {
log.e(err)
terminate()
})

log.i('executing mode ' + mode)
switch(mode) {
case 'MOCK':
n3hNode = await new N3hMock(workDir, rawConfigData)
break
case 'HACK':
n3hNode = await new N3hHackMode(workDir, rawConfigData)
break
default:
log.e('so called "real" mode disabled while running POC on hackmode / mockmode')
process.exit(1)
//n3hNode = await N3hNode.constructDefault(workDir, rawConfigData)
//break
}

await n3hNode.run()
}

main().then(() => {}, (err) => {
log.e(err)
process.exit(1)
})

/**
* read from stdin until closed
* timeout if not read in 4 seconds
*/
async function _tryReadStdin () {
const timeout = (new Error('timeout')).stack
return new Promise((resolve, reject) => {
const timer = setTimeout(() => {
reject(timeout)
}, 4000)

log.w('attempting read stdin')
process.stdin.resume()

let data = Buffer.alloc(0)
process.stdin.on('data', chunk => {
data = Buffer.concat([data, chunk])
})
process.stdin.on('end', () => {
clearTimeout(timer)
resolve(data)
})
})
}
File renamed without changes.
6 changes: 0 additions & 6 deletions lerna.json

This file was deleted.

File renamed without changes.
@@ -1,5 +1,5 @@
const { expect } = require('chai')
const { $sleep } = require('@holochain/n3h-common')
const { $sleep } = require('./n3h-common')
const fs = require('fs')
const path = require('path')
const tmp = require('tmp')
Expand Down
2 changes: 1 addition & 1 deletion packages/hackmode/lib/config.js → lib/hackmode/config.js
@@ -1,4 +1,4 @@
const { config } = require('@holochain/n3h-common')
const { config } = require('../n3h-common')

module.exports = exports = config.createDefinition({
ipc: {
Expand Down
6 changes: 3 additions & 3 deletions packages/hackmode/lib/index.js → lib/hackmode/index.js
@@ -1,13 +1,13 @@
const msgpack = require('msgpack-lite')

const { P2p } = require('@holochain/n3h-mod-spec')
const { P2p } = require('../n3h-mod-spec')
const { P2pBackendHackmodePeer } = require('./p2p-backend-hackmode-peer')

const { N3hMode } = require('../../n3h-ipc/lib/n3hMode')
const { N3hMode } = require('../n3h-ipc/n3hMode')

const { Mem, getHash } = require('./mem')

const tweetlog = require('@holochain/tweetlog')
const tweetlog = require('../tweetlog')
const log = tweetlog('@hackmode@')

/**
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -1,7 +1,7 @@
const { AsyncClass, Track } = require('@holochain/n3h-common')
const { Keypair } = require('@holochain/hc-dpki')
const mosodium = require('@holochain/mosodium')
const tweetlog = require('@holochain/tweetlog')
const { AsyncClass, Track } = require('../n3h-common')
const { Keypair } = require('../hc-dpki')
const mosodium = require('../mosodium')
const tweetlog = require('../tweetlog')
const log = tweetlog('p2p-hackmode')

const { URL } = require('url')
Expand All @@ -12,10 +12,10 @@ const {
Dht,
DhtEvent,
P2pEvent
} = require('@holochain/n3h-mod-spec')
} = require('../n3h-mod-spec')

const { ConnectionBackendWss } = require('@holochain/n3h-mod-connection-wss')
const { DhtBackendFullsync } = require('@holochain/n3h-mod-dht-fullsync')
const { ConnectionBackendWss } = require('../n3h-mod-connection-wss')
const { DhtBackendFullsync } = require('../n3h-mod-dht-fullsync')

/**
* @param {object} options
Expand Down
@@ -1,15 +1,15 @@
const { $sleep, unhandledRejection } = require('@holochain/n3h-common')
const { $sleep, unhandledRejection } = require('../n3h-common')
unhandledRejection.strict()
const msgpack = require('msgpack-lite')

const tweetlog = require('@holochain/tweetlog')
const tweetlog = require('../tweetlog')
tweetlog.set('t')
const log = tweetlog('@@-unit-test-@@')
tweetlog.listen(tweetlog.console)

const { expect } = require('chai')

const { P2p } = require('@holochain/n3h-mod-spec')
const { P2p } = require('../n3h-mod-spec')
const { P2pBackendHackmodePeer } = require('./p2p-backend-hackmode-peer')

describe('hackmode module p2p peer backend Suite', () => {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions packages/hc-dpki/lib/keypair.js → lib/hc-dpki/keypair.js
@@ -1,7 +1,7 @@
const msgpack = require('msgpack-lite')

const { AsyncClass } = require('@holochain/n3h-common')
const mosodium = require('@holochain/mosodium')
const { AsyncClass } = require('../n3h-common')
const mosodium = require('../mosodium')

const util = require('./util')

Expand Down
@@ -1,6 +1,6 @@
const { expect } = require('chai')

const mosodium = require('@holochain/mosodium')
const mosodium = require('../mosodium')
mosodium.SecBuf.setLockLevel(mosodium.SecBuf.LOCK_NONE)

const { Keypair } = require('./index')
Expand Down
4 changes: 2 additions & 2 deletions packages/hc-dpki/lib/seed.js → lib/hc-dpki/seed.js
@@ -1,5 +1,5 @@
const { AsyncClass } = require('@holochain/n3h-common')
const mosodium = require('@holochain/mosodium')
const { AsyncClass } = require('../n3h-common')
const mosodium = require('../mosodium')
const bip39 = require('bip39')

const { Keypair } = require('./keypair')
Expand Down
@@ -1,6 +1,6 @@
const { expect } = require('chai')

const mosodium = require('@holochain/mosodium')
const mosodium = require('../mosodium')
mosodium.SecBuf.setLockLevel(mosodium.SecBuf.LOCK_NONE)

const util = require('./util')
Expand Down
2 changes: 1 addition & 1 deletion packages/hc-dpki/lib/util.js → lib/hc-dpki/util.js
@@ -1,4 +1,4 @@
const mosodium = require('@holochain/mosodium')
const mosodium = require('../mosodium')
const msgpack = require('msgpack-lite')
const { Encoder, Decoder } = require('@holochain/n-bch-rs')

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion packages/hc-dpki/lib/work.js → lib/hc-dpki/work.js
@@ -1,4 +1,4 @@
const mosodium = require('@holochain/mosodium')
const mosodium = require('../mosodium')

const DEF_WORK_TARGET = Buffer.from('000000000000000000000000000000000000000000000000000000000000b400', 'hex')

Expand Down
@@ -1,4 +1,4 @@
const mosodium = require('@holochain/mosodium')
const mosodium = require('../mosodium')
const { expect } = require('chai')

const work = require('./work')
Expand Down
20 changes: 12 additions & 8 deletions packages/n3h/lib/index.js → lib/index.js
@@ -1,27 +1,31 @@
const path = require('path')
const os = require('os')
const { URL } = require('url')
const { AsyncClass, mkdirp, ModMod } = require('@holochain/n3h-common')
const { AsyncClass, mkdirp, ModMod } = require('./n3h-common')

const { IpcServer } = require('@holochain/n3h-ipc')
// const { IpcServer } = require('./n3h-ipc')

/*
const DEFAULT_MODULES = [
require('@holochain/n3h-mod-nv-persist-sqlite3').NvPersistSqlite3,
require('@holochain/n3h-mod-persist-cache-lru').PersistCacheLru,
require('@holochain/n3h-mod-message-libp2p').MessageLibP2p
require('./n3h-mod-nv-persist-sqlite3').NvPersistSqlite3,
require('./n3h-mod-persist-cache-lru').PersistCacheLru,
require('./n3h-mod-message-libp2p').MessageLibP2p
]
*/

exports.N3hHackMode = require('@holochain/hackmode').N3hHackMode
exports.N3hMock = require('@holochain/n3h-mock').N3hMock
exports.N3hHackMode = require('./hackmode').N3hHackMode
exports.N3hMock = require('./n3h-mock').N3hMock

/**
*/
class N3hNode extends AsyncClass {
/**
*/
/*
static async constructDefault (workDir, rawConfigData, modules) {
return new N3hNode(workDir, (modules || []).concat(DEFAULT_MODULES))
}
*/

/**
*/
Expand Down Expand Up @@ -110,7 +114,7 @@ class N3hNode extends AsyncClass {

this._state = 'need_config'

this._ipc = await new IpcServer()
// this._ipc = await new IpcServer()

// hack for module init
this._ipc.ready = () => {}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file added lib/n3h-ipc/index.js
Empty file.
File renamed without changes.
File renamed without changes.

0 comments on commit 0f3f899

Please sign in to comment.