diff --git a/.babelrc b/.babelrc index a2a2f0a..3c45d73 100755 --- a/.babelrc +++ b/.babelrc @@ -3,23 +3,5 @@ "es2015", "react", "stage-0" - ], - "plugins": [ - "transform-object-assign" - ], - "env": { - "test": { - "plugins": [ - [ - "__coverage__", - { - "ignore": "src/test/" - } - ] - ] - } - }, - "ignore": [ - "*.es5.js" ] } diff --git a/.gitignore b/.gitignore index 4817213..73acc1e 100755 --- a/.gitignore +++ b/.gitignore @@ -42,7 +42,4 @@ jspm_packages /.idea/ .idea/ -TextLogger* -dist/* - log.txt diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..c62be13 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2015 Oliver Mader + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. \ No newline at end of file diff --git a/src/app/core/main.js b/app/core/main.js old mode 100755 new mode 100644 similarity index 55% rename from src/app/core/main.js rename to app/core/main.js index e1bae72..1c20f9c --- a/src/app/core/main.js +++ b/app/core/main.js @@ -1,10 +1,10 @@ -import {app, globalShortcut, clipboard} from 'electron'; +import {app, globalShortcut, clipboard, ipcMain} from 'electron'; import fs from 'fs'; import menubar from 'menubar'; const dir = process.cwd(); const logPath = `${dir}/log.txt`; -const indexPath = `file://${dir}/dist/static/index.html`; +const indexPath = `file://${dir}/app/view/popup.html`; const mb = menubar({index: indexPath}); function saveContents() { @@ -14,10 +14,17 @@ function saveContents() { } mb.on('ready', () => { + console.log(dir); globalShortcut.register('Control+Command+S', saveContents); if (!globalShortcut.isRegistered('Control+Command+S')) { - // TODO: alert and eld process + // TODO: alert and end process } }); +mb.on('show', () => { + ipcMain.on('synchronous-message', (event) => { + event.returnValue = 'haha';// fs.readFileSync(logPath, 'utf-8'); + }); + mb.window.reload(); +}); diff --git a/app/view/app-component.js b/app/view/app-component.js new file mode 100644 index 0000000..c5266df --- /dev/null +++ b/app/view/app-component.js @@ -0,0 +1,16 @@ +import React from 'react'; +import ClipList from './clip-list'; + +export default class AppComponent extends React.Component { + constructor() { + super(); + } + + render() { + return ( +
+ +
+ ); + } +} diff --git a/app/view/clip-list.js b/app/view/clip-list.js new file mode 100644 index 0000000..1b806ad --- /dev/null +++ b/app/view/clip-list.js @@ -0,0 +1,32 @@ +import React from 'react'; +import readlines from 'gen-readlines'; +import fs from 'fs'; + +export default class ClipList extends React.Component { + constructor() { + super(); + this.fd = this.openLogFile(); + this.buffer = this.openBuffer(); + this.contents = '2'; + } + + async openLogFile() { + return await fs.openSync('log.txt', 'r'); + } + + async openBuffer() { + return await fs.fstatSync(this.fd); + } + + renderClip(contents) { + return
hii
; + } + + render() { + return ( +
+ {readlines(this.fd, this.buffer.size).forEach(console.log)} +
+ ); + } +} \ No newline at end of file diff --git a/app/view/clip.js b/app/view/clip.js new file mode 100644 index 0000000..aedd1b3 --- /dev/null +++ b/app/view/clip.js @@ -0,0 +1,15 @@ +import React from 'react'; + +export default class Clip extends React.Component { + constructor(props) { + super(props); + } + + render() { + return ( +
+
{this.props.contents}
+
+ ); + } +} diff --git a/app/view/popup.html b/app/view/popup.html new file mode 100644 index 0000000..f54da7d --- /dev/null +++ b/app/view/popup.html @@ -0,0 +1,15 @@ + + + + electron es6 react boilerplate + + + + +
+ + diff --git a/app/view/popup.js b/app/view/popup.js new file mode 100644 index 0000000..4b32aac --- /dev/null +++ b/app/view/popup.js @@ -0,0 +1,7 @@ +import React from 'react'; +import ReactDOM from 'react-dom'; +import App from './app-component'; + +window.onload = function(){ + ReactDOM.render(, document.getElementById('app')); +} diff --git a/gulpfile.babel.js b/gulpfile.babel.js deleted file mode 100755 index aa7aa38..0000000 --- a/gulpfile.babel.js +++ /dev/null @@ -1,109 +0,0 @@ -//Include required modules -import babel from 'gulp-babel'; -import changed from 'gulp-changed'; -import eslint from 'gulp-eslint'; -import gulp from 'gulp'; -import gutil from 'gulp-util'; -import nodemon from 'gulp-nodemon'; -import rimraf from 'rimraf'; -import sourcemaps from 'gulp-sourcemaps'; -import unitest from 'unitest'; -import image from 'gulp-image'; -import browserify from 'browserify'; -import babelify from 'babelify'; -import configify from 'config-browserify'; -import envify from 'envify'; -import source from 'vinyl-source-stream'; -import buffer from 'vinyl-buffer'; - -// Default task. This will be run when no task is passed in arguments to gulp -gulp.task('default', ['start']); - -// Convert ES6 code in all js files in src/js folder and copy to -// build folder as bundle.js -gulp.task('build:static', ['clean:static'], () => - gulp.src('./src/app/static/*') - .pipe(image()) - .pipe(gulp.dest('./dist/static')) -); -gulp.task('build:view', ['clean:view'], () => compileViewJS(['./src/app/static/index.js'], 'index.js', './dist/static')); -gulp.task('build:core', ['clean:core'], () => compileNodeJS('src/app/**/*.js', './dist')); -gulp.task('build:test', ['clean:test'], () => compileNodeJS('src/test/**/*.js', './dist-test')); -gulp.task('build', ['build:static', 'build:view', 'build:core']); - -// clean -gulp.task('clean:static', () => rimraf.sync('./dist/static')); -gulp.task('clean:core', () => rimraf.sync('./dist/core')); -gulp.task('clean:view', () => rimraf.sync('./dist/static/index.js')); -gulp.task('clean:test', () => rimraf.sync('./dist-test')); -gulp.task('clean', ['clean:static', 'clean:core', 'clean:view', 'clean:test'], () => { - rimraf.sync('./dist'); - rimraf.sync('./TextLogger*'); -}); - -gulp.task('run:eslint', () => gulp.src('src/**/*.js') - .pipe(eslint()) - .pipe(eslint.format()) - .pipe(eslint.results(lintReporter)) - .pipe(eslint.failAfterError()) -); - -gulp.task('run:test', ['build:test'], () => { - const output = unitest({ - browser: 'dist-test/test/browser/index.js', - node: 'dist-test/test/node/index.js', - report: ['text'] - }, (exitCode) => { - if (exitCode !== 0) { - console.error('Tests failed! - Test script exited with non-zero status code.'); - } - return true; - }); - output.pipe(process.stdout); -}); - -gulp.task('lint', ['run:eslint']); -gulp.task('test', ['lint', 'run:test']); - -gulp.task('start', ['build'], () => { - nodemon({ - script: 'index.js', - watch: 'src', - tasks: ['build'], - env: {'NODE_ENV': 'production'} - }) -}); - -// Compile js to be run in node and dependent sources using babel -// with options specified -// in ./babelrc and place them in dest. Works for server and test js. -const compileNodeJS = (src, dest) => - gulp.src(src) - .pipe(changed(dest)) - .pipe(sourcemaps.init()) - .pipe(babel()) - .pipe(sourcemaps.write({ - includeContent: false, - sourceRoot: (file) => file.base - })) - .pipe(gulp.dest(dest)); - -const compileViewJS = (entries, destName, destDir) => - browserify({ - entries: entries - }).transform(babelify) - .transform(configify) - .transform(envify) - .bundle() - .pipe(source(destName)) - .pipe(buffer()) - .pipe(sourcemaps.init({loadMaps: true})) - .pipe(sourcemaps.write()) - .pipe(gulp.dest(destDir)); - -const lintReporter = (results) => { - const logColor = results.errorCount ? gutil.colors.red : gutil.colors.green; - gutil.log('Total Results: ' + results.length); - gutil.log('Total Warnings: ' + results.warningCount); - gutil.log(logColor('Total Errors: ' + results.errorCount)); -}; diff --git a/index.js b/index.js index ba1d022..81cbdeb 100644 --- a/index.js +++ b/index.js @@ -1,3 +1,3 @@ -#!/usr/bin/env node -require('source-map-support').install(); -require('./dist/core/main.js'); +// install babel hooks in the main process +require('babel-register'); +require('./app/core/main.js'); diff --git a/package.json b/package.json old mode 100755 new mode 100644 index 810c7f0..3734f06 --- a/package.json +++ b/package.json @@ -1,60 +1,21 @@ { "name": "text-logger", "version": "0.0.0", - "private": true, "main": "index.js", - "description": "log text with hotkeys", - "license": "N/A", - "repository": { - "type": "git", - "url": "git@github.com:ovekyc/----.git" - }, + "license": "MIT", + "repository": "git@github.com:ovekyc/textlogger.git", "scripts": { - "build-test": "gulp build:test", - "test": "BABEL_ENV=test NODE_ENV=test npm run build-test && gulp test", - "lint": "gulp lint", - "start": "electron .", - "build": "gulp build && electron-packager . TextLogger --platform=darwin --arch=x64 --version=0.36.0 --icon=Icon.icns --overwrite", - "clean": "gulp clean" + "start": "electron ." }, - "pre-commit": [ - "test" - ], "dependencies": { - "electron": "^1.4.13", - "gulp": "^3.9.1", "menubar": "^5.2.0", - "node-simple-logger": "0.0.1", "react": "^15.4.1", - "react-dom": "^15.4.1", - "source-map-support": "^0.4.2" + "react-dom": "^15.4.1" }, "devDependencies": { - "babel-core": "^6.21.0", - "babel-plugin-__coverage__": "^11.0.0", - "babel-plugin-transform-object-assign": "^6.8.0", "babel-preset-es2015": "^6.18.0", "babel-preset-react": "^6.16.0", - "babel-preset-stage-0": "^6.16.0", - "babelify": "^7.3.0", - "browserify": "^13.1.1", - "config-browserify": "^1.0.5", - "electron-packager": "^8.4.0", - "envify": "^4.0.0", - "gulp": "^3.9.1", - "gulp-babel": "^6.1.2", - "gulp-changed": "^1.3.2", - "gulp-eslint": "^3.0.1", - "gulp-image": "^2.7.2", - "gulp-nodemon": "^2.2.1", - "gulp-sourcemaps": "^1.9.1", - "gulp-util": "^3.0.8", - "rimraf": "^2.5.4", - "unitest": "^0.14.2", - "vinyl-buffer": "^1.0.0", - "vinyl-source-stream": "^1.1.0" - }, - "engines": { - "node": "6.4.0" + "babel-register": "^6.18.0", + "electron": "^1.4.3" } } diff --git a/src/app/static/Icon.icns b/src/app/static/Icon.icns deleted file mode 100755 index 607318a..0000000 Binary files a/src/app/static/Icon.icns and /dev/null differ diff --git a/src/app/static/IconTemplate.png b/src/app/static/IconTemplate.png deleted file mode 100755 index bb85ee9..0000000 Binary files a/src/app/static/IconTemplate.png and /dev/null differ diff --git a/src/app/static/IconTemplate@2x.png b/src/app/static/IconTemplate@2x.png deleted file mode 100755 index 2e1e827..0000000 Binary files a/src/app/static/IconTemplate@2x.png and /dev/null differ diff --git a/src/app/static/index.html b/src/app/static/index.html deleted file mode 100755 index edb3a3d..0000000 --- a/src/app/static/index.html +++ /dev/null @@ -1,10 +0,0 @@ - - -Example App - - - hello worldl -
- - - diff --git a/src/app/static/index.js b/src/app/static/index.js deleted file mode 100644 index 22b195e..0000000 --- a/src/app/static/index.js +++ /dev/null @@ -1,7 +0,0 @@ -import React from 'react'; -import ReactDOM from 'react-dom'; -import AppComponent from '../view/app-component'; - -window.React = React; - -ReactDOM.render(, document.getElementById('container')); diff --git a/src/app/view/app-component.js b/src/app/view/app-component.js deleted file mode 100644 index d08ca61..0000000 --- a/src/app/view/app-component.js +++ /dev/null @@ -1,31 +0,0 @@ -import {Component} from 'react'; -import fs from 'fs'; -import Clip from './clip'; - -// TODO: refactoring -const dir = process.cwd(); -const logPath = `${dir}/log.txt`; - -export default class AppComponent extends Component { - constructor() { - super(); - this.state = { - clipLog: '123' - }; - this.readLogFile = this.readLogFile.bind(this); - //this.readLogFile(); - } - - readLogFile() { - this.setState({clipLog: fs.readFileSync(logPath)}) - } - - render() { - return ( -
-
{fs.readFileSync(logPath)}
- -
- ); - } -} diff --git a/src/app/view/clip.js b/src/app/view/clip.js deleted file mode 100644 index 71b8b35..0000000 --- a/src/app/view/clip.js +++ /dev/null @@ -1,16 +0,0 @@ -import {Component} from 'react'; - -export default class Clip extends Component { - constructor(props) { - super(props); - // this.props = props; - } - - render() { - return ( -
-
{this.props.word}
-
- ); - } -}