Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Electron app working, adding binary and moving src folder
- Loading branch information
Showing
19 changed files
with
234 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,3 +26,4 @@ node_modules | |
|
||
.idea/ | ||
db-data/ | ||
lib/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
!lib/ | ||
src/ | ||
test/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/usr/bin/env node | ||
|
||
var path = require('path'); | ||
var program = require('commander'); | ||
var root = path.join(__dirname, '..'); | ||
var pkg = require(path.join(root, 'package.json')); | ||
var electron = require('electron-prebuilt'); | ||
var proc = require('child_process'); | ||
|
||
program.version(pkg.version) | ||
.usage('[options]') | ||
.description(pkg.description) | ||
.option('-s, --server', 'Run server only') | ||
.option('-d --develop', 'Run in development mode') | ||
.parse(process.argv); | ||
|
||
process.env.NODE_ENV = program.develop ? 'development' : 'production'; | ||
|
||
if(program.develop) { | ||
process.env.DEBUG = process.env.DEBUG ? process.env.DEBUG + ',mysam:*' : 'mysam:*'; | ||
} | ||
|
||
if(program.server) { | ||
require('../lib/server'); | ||
} else { | ||
proc.spawn(electron, [root], {stdio: 'inherit'}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"port": 9090, | ||
"frontend": "mysam-frontend" | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,29 @@ | ||
# Say hi to SAM | ||
# Say hi SAM | ||
|
||
[ ![Codeship Status for daffl/mysam](https://codeship.com/projects/b26a3f10-3c66-0133-d19d-1276d5d0a1e7/status?branch=master)](https://codeship.com/projects/102258) | ||
|
||
An open source, web based "intelligent agent" that can listen to you and learn. | ||
Sam is an open-source, web-based "intelligent" assistant. It can listen to you, learn new actions and easily be extended with JavaScript plugins. Sam runs as an [Electron](http://electron.atom.io/) desktop application or in a modern browser. | ||
|
||
> I'm still very alpha... | ||
# Installation | ||
|
||
Install Sam globally via: | ||
|
||
> npm install mysam -g | ||
And then run either the desktop application with: | ||
|
||
> mysam | ||
Or the server (which is available at [localhost:9090](http://localhost:9090)) via: | ||
|
||
> mysam --server | ||
# Getting started | ||
|
||
# Plugins | ||
|
||
Plugins can be installed via [NPM](). To ask Sam about the weather run: | ||
|
||
> npm install mysam-weather -g | ||
Then restart the application. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import bodyParser from 'body-parser'; | ||
import feathers from 'feathers'; | ||
import hooks from 'feathers-hooks'; | ||
import path from 'path'; | ||
|
||
import config from '../config.json'; | ||
import services from './services/index'; | ||
import loader from './loader'; | ||
|
||
const publicPath = path.join(__dirname, '..', 'node_modules', config.frontend); | ||
const app = feathers() | ||
.configure(feathers.rest()) | ||
.configure(feathers.socketio()) | ||
.configure(hooks()) | ||
.use(bodyParser.json()) | ||
.use(bodyParser.urlencoded({ extended: true })) | ||
.use('/', function(req, res, next) { | ||
if(req.url === '/' && process.env.NODE_ENV === 'production') { | ||
return res.sendFile(path.join(publicPath, 'production.html')); | ||
} | ||
|
||
next(); | ||
}) | ||
.use('/', feathers.static(publicPath)) | ||
.configure(services) | ||
.configure(loader); | ||
|
||
export default app; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import app from 'app'; | ||
import BrowserWindow from 'browser-window'; | ||
import crashReporter from 'crash-reporter'; | ||
|
||
import server from './app'; | ||
|
||
const config = require('../config.json'); | ||
|
||
let mainWindow = null; | ||
|
||
crashReporter.start(); | ||
server.listen(process.env.PORT || config.port); | ||
|
||
app.on('window-all-closed', () => { | ||
if (process.platform !== 'darwin') { | ||
app.quit(); | ||
} | ||
}); | ||
|
||
app.on('ready', () => { | ||
mainWindow = new BrowserWindow({ | ||
width: 800, | ||
height: 600 | ||
}); | ||
|
||
mainWindow.loadUrl(`http://localhost:${config.port}`); | ||
mainWindow.openDevTools(); | ||
mainWindow.on('closed', () => { | ||
mainWindow = null; | ||
}); | ||
}); | ||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import Q from 'q'; | ||
import path from 'path'; | ||
import npm from 'npm'; | ||
import _ from 'lodash'; | ||
import debug from 'debug'; | ||
import feathers from 'feathers'; | ||
|
||
const log = debug('mysam:plugins'); | ||
|
||
export default function() { | ||
const app = this; | ||
const plugins = app.service('plugins'); | ||
const loadPlugin = moduleName => { | ||
if(!moduleName){ | ||
return Q(null); | ||
} | ||
|
||
let pkgPath = require.resolve(path.join(moduleName, 'package.json')); | ||
let pkg = require(pkgPath); | ||
let config = pkg.mysam; | ||
|
||
if(!config) { | ||
return Q(null); | ||
} | ||
|
||
log(`Found plugin ${pkg.name}`); | ||
|
||
let pluginLoader = require(moduleName); | ||
|
||
if(typeof pluginLoader !== 'function') { | ||
throw new Error(`Can not configure plugin ${pkg.name}`); | ||
} else { | ||
} | ||
if(config.public) { | ||
let dirname = path.dirname(pkgPath); | ||
let staticPath = path.join(dirname, config.public); | ||
|
||
log(`Setting up ${staticPath} at /${pkg.name}`); | ||
|
||
app.use(`/${pkg.name}`, feathers.static(staticPath)); | ||
} | ||
|
||
return Q.ninvoke(plugins, 'create', pkg) | ||
.then(() => { | ||
try { | ||
let pluginLoader = require(moduleName); | ||
app.configure(pluginLoader); | ||
} catch(e) { | ||
log(`No server configuration module for ${pkg.name}.`); | ||
} | ||
}); | ||
}; | ||
|
||
Q.ninvoke(npm, 'load', { loaded: false, global: true, depth: 0 }) | ||
.then(() => { | ||
const dfd = Q.defer(); | ||
|
||
npm.commands.ls([], true, function (error, data) { | ||
if(error) { | ||
return dfd.reject(error); | ||
} | ||
|
||
let configurers = []; | ||
|
||
_.each(data.dependencies, dependency => | ||
dependency && configurers.push(loadPlugin(dependency.path))); | ||
|
||
dfd.resolve(Q.all(configurers)); | ||
}); | ||
|
||
return dfd.promise; | ||
}).fail(error => console.error(error.stack)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import app from './app'; | ||
|
||
const config = require('../config.json'); | ||
|
||
app.listen(process.env.PORT || config.port); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
Oops, something went wrong.