diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fabfb3c --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +node_modules +*.map +dist +!gulpfile.js +*.tgz +*.log +.node-version diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..994aec9 --- /dev/null +++ b/.jshintrc @@ -0,0 +1,22 @@ +{ + "node": true, + "browser": false, + "mocha": true, + "esnext": true, + "module": true, + "bitwise": true, + "camelcase": true, + "curly": true, + "eqeqeq": true, + "immed": true, + "indent": 2, + "latedef": true, + "newcap": true, + "noarg": true, + "quotmark": "single", + "undef": true, + "unused": true, + "strict": true, + "globals" : { + } +} diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..56a3841 --- /dev/null +++ b/.npmignore @@ -0,0 +1,16 @@ +.git +.node-red +node_modules +images +src +tests +.gitignore +.npmignore +.jshintrc +.travis.yml +gulpfile.js +*.tgz +*.zip +*.log +.dockerignore +.node-version diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..56f3523 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,19 @@ +language: node_js +node_js: + - 4.7 + +addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - g++-4.8 + - bluez + +sudo: require + +install: + - if [[ $TRAVIS_OS_NAME == "linux" ]]; then export CXX=g++-4.8; fi + - $CXX --version + - npm install --unsafe-perm + - npm install diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..c5ce395 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2017 CANDY LINE INC. + +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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/gulpfile.js b/gulpfile.js new file mode 100644 index 0000000..4fc51d6 --- /dev/null +++ b/gulpfile.js @@ -0,0 +1,145 @@ +const gulp = require('gulp'); +const util = require("gulp-util"); +const babel = require('gulp-babel'); +const browserify = require('browserify'); +const babelify = require('babelify'); +const uglify = require('gulp-uglify'); +const del = require('del'); +const source = require('vinyl-source-stream'); +const buffer = require('vinyl-buffer'); +const jshint = require('gulp-jshint'); +const mocha = require('gulp-mocha'); +const sourcemaps = require('gulp-sourcemaps'); +const gulpif = require('gulp-if'); +const htmlmin = require('gulp-htmlmin'); +const cleancss = require('gulp-clean-css'); +const less = require('gulp-less'); +const manifest = require('gulp-manifest'); +const shim = require('browserify-shim'); +const yaml = require('gulp-yaml'); + +const minified = process.env.NODE_ENV === 'production'; +const sourcemapEnabled = process.env.NODE_ENV !== 'production'; + +gulp.task('lint', () => { + return gulp.src([ + './tests/**/*.js', + './src/**/*.js' + ]) + .pipe(jshint()) + .pipe(jshint.reporter('jshint-stylish')) + .pipe(jshint.reporter('fail')); +}); + +gulp.task('clean', () => { + return del([ + 'dist/*', + './dist', + '!node_modules/**/*', + './*.tgz', + ]); +}); + +gulp.task('i18n', () => { + return gulp.src([ + './src/locales/**/*.{yaml,yml}' + ]) + .pipe(yaml({ safe: true })) + .pipe(gulp.dest('./dist/locales')); +}); + +gulp.task('assets', ['i18n'], () => { + return gulp.src([ + './src/**/*.{less,ico,png,json,yaml,yml}', + '!./src/locales/**/*.{yaml,yml}' + ]) + .pipe(gulp.dest('./dist')); +}); + +gulp.task('js', ['assets'], () => { + return browserify({ + entries: './src/generic-ble.js', + debug: true + }) + .transform(babelify, { + minified: minified, + compact: minified, + presets: ["es2015"], + plugins: ['add-module-exports'], + sourceMaps: sourcemapEnabled, + }).on('error', util.log) + .transform(shim, { + global: true + }).on('error', util.log) + .bundle() + .pipe(source('generic-ble.js')) + .pipe(buffer()) + .pipe(gulpif(sourcemapEnabled, sourcemaps.init({loadMaps: true}), util.noop())) + .pipe(uglify({ + mangle: minified, + compress: { + dead_code: true, + drop_debugger: true, + properties: true, + unused: true, + toplevel: true, + if_return: true, + drop_console: !sourcemapEnabled, + conditionals: true, + unsafe_math: true, + unsafe: true + }, + })) + .pipe(gulpif(sourcemapEnabled, sourcemaps.write(), util.noop())) + .pipe(gulp.dest('./dist')); +}); + +gulp.task('less', () => { + return gulp.src('./src/**/*.less') + .pipe(gulpif(sourcemapEnabled, sourcemaps.init(), util.noop())) + .pipe(less()) + .pipe(cleancss({compatibility: 'ie8'})) + .pipe(gulpif(sourcemapEnabled, sourcemaps.write(), util.noop())) + .pipe(gulp.dest('./dist')); +}); + +gulp.task('html', () => { + return gulp.src('./src/**/*.html') + .pipe(htmlmin({collapseWhitespace:true, conservativeCollapse:true})) + .pipe(gulp.dest('./dist')); +}); + +gulp.task('build', ['lint', 'js', 'less', 'html', 'assets'], () => { + gulp.src(['./dist/*'], { base: './dist' }) + .pipe(gulp.dest('./dist')); +}); + +gulp.task('testAssets', () => { + return gulp.src('./tests/**/*.{css,less,ico,png,html,json,yaml,yml}') + .pipe(gulp.dest('./dist')); +}); + +gulp.task('testJs', ['build'], () => { + return gulp.src('./tests/**/*.js') + .pipe(sourcemaps.init()) + .pipe(babel({ + presets: ['es2015'], + plugins: ['add-module-exports'] + })) + .pipe(sourcemaps.write('.')) + .pipe(gulp.dest('./dist')); +}); + +gulp.task('test', ['testJs', 'testAssets'], () => { + return gulp.src([ + './dist/**/*.test.js', + ], {read: false}) + .pipe(mocha({ + require: ['source-map-support/register'], + reporter: 'spec' + })) + .once('error', () => process.exit(1)) + .once('end', () => process.exit()) +}); + +gulp.task('default', ['build']); diff --git a/package.json b/package.json new file mode 100644 index 0000000..a165896 --- /dev/null +++ b/package.json @@ -0,0 +1,79 @@ +{ + "name": "node-red-contrib-generic-ble", + "version": "1.0.0", + "description": "Node-RED nodes for generic BLE devices", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/CANDY-LINE/node-red-contrib-generic-ble.git" + }, + "author": "Daisuke Baba ", + "bugs": { + "url": "https://github.com/CANDY-LINE/node-red-contrib-generic-ble/issues" + }, + "scripts": { + "build": "gulp build", + "test": "gulp test", + "clean": "gulp clean", + "prepublish": "gulp build" + }, + "homepage": "https://github.com/CANDY-LINE/node-red-contrib-generic-ble#readme", + "keywords": [ + "node-red", + "bluetooth", + "BLE", + "bluetooth low energy", + "bluetooth smart", + "CANDY RED", + "CANDY EGG" + ], + "browserify-shim": { + }, + "devDependencies": { + "node-red": "^0.16.2", + "babel": "^6.23.0", + "babel-cli": "^6.24.0", + "babel-plugin-add-module-exports": "^0.2.1", + "babel-plugin-transform-runtime": "^6.23.0", + "babel-preset-babili": "0.0.12", + "babel-preset-es2015": "^6.24.0", + "babelify": "^7.3.0", + "browserify": "^14.3.0", + "browserify-shim": "^3.8.14", + "chai": "^3.3.0", + "del": "^2.2.2", + "gulp": "^3.9.1", + "gulp-babel": "^6.1.2", + "gulp-clean-css": "^2.4.0", + "gulp-cli": "^1.2.2", + "gulp-header": "^1.8.8", + "gulp-htmlmin": "^3.0.0", + "gulp-if": "^2.0.2", + "gulp-jshint": "^2.0.4", + "gulp-less": "^3.3.0", + "gulp-manifest": "^0.1.1", + "gulp-mocha": "^4.3.0", + "gulp-resources": "^0.5.0", + "gulp-sourcemaps": "^2.5.1", + "gulp-uglify": "^2.1.2", + "gulp-util": "^3.0.8", + "gulp-yaml": "^1.0.1", + "jshint": "^2.9.1", + "jshint-stylish": "^2.0.1", + "mocha": "^3.0.2", + "sinon": "^2.1.0", + "supertest": "^1.1.0", + "vinyl-buffer": "^1.0.0", + "vinyl-source-stream": "^1.1.0" + }, + "dependencies": { + "noble": "^1.8.1", + "source-map-support": "^0.4.2", + "lru-cache": "^4.0.0" + }, + "node-red": { + "nodes": { + "generic-ble": "dist/generic-ble.js" + } + } +} diff --git a/src/generic-ble.js b/src/generic-ble.js new file mode 100644 index 0000000..e69de29 diff --git a/src/locales/en-US/generic-ble.html b/src/locales/en-US/generic-ble.html new file mode 100644 index 0000000..0e6bc57 --- /dev/null +++ b/src/locales/en-US/generic-ble.html @@ -0,0 +1,8 @@ + + + + + diff --git a/src/locales/en-US/generic-ble.yml b/src/locales/en-US/generic-ble.yml new file mode 100644 index 0000000..105b0df --- /dev/null +++ b/src/locales/en-US/generic-ble.yml @@ -0,0 +1,4 @@ +# Message Resources for English (fallback language) +generic-ble: + label: + node: Generic BLE diff --git a/tests/generic-ble.test.js b/tests/generic-ble.test.js new file mode 100644 index 0000000..e69de29