From e7698a18a2f8b81fa152e6c3b533b356f79c0a52 Mon Sep 17 00:00:00 2001 From: Glenn Vandeuren Date: Tue, 21 Feb 2017 00:20:43 +0100 Subject: [PATCH] :metal: Initial commit --- .editorconfig | 11 +++++ .gitattributes | 1 + .gitignore | 3 ++ .travis.yml | 7 +++ LICENSE | 21 +++++++++ README.md | 27 +++++++++++ bin/backed-cli.js | 58 +++++++++++++++++++++++ config/backed.json | 6 +++ gulpfile.js | 114 +++++++++++++++++++++++++++++++++++++++++++++ package.json | 69 +++++++++++++++++++++++++++ src/backed-cli.js | 16 +++++++ src/builder.js | 39 ++++++++++++++++ test/index.js | 10 ++++ 13 files changed, 382 insertions(+) create mode 100644 .editorconfig create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 .travis.yml create mode 100644 LICENSE create mode 100644 README.md create mode 100644 bin/backed-cli.js create mode 100644 config/backed.json create mode 100644 gulpfile.js create mode 100644 package.json create mode 100644 src/backed-cli.js create mode 100644 src/builder.js create mode 100644 test/index.js diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..beffa30 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,11 @@ +root = true + +[*] +indent_style = space +indent_size = 2 +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.md] +trim_trailing_whitespace = false diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..176a458 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text=auto diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cac19fa --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +node_modules +coverage +.tmp diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..cd92e86 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,7 @@ +language: node_js +node_js: + - v7 + - v6 + - v5 + - v4 + - '0.12' diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..3f083f2 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2017 Glenn Vandeuren + +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..926b5ee --- /dev/null +++ b/README.md @@ -0,0 +1,27 @@ +# backed-cli [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][daviddm-image]][daviddm-url] [![Coverage percentage][coveralls-image]][coveralls-url] +> A command line interface for fast es6 development + +## Installation + +```sh +$ npm install --save backed-cli +``` + +## Usage + +- Create a 'backed.json' file in your projects root [example](https://githug.com/vandeurenglenn/backed-cli/config/backed.json) + +Soon + +## License + +MIT © [Glenn Vandeuren]() + +[npm-image]: https://badge.fury.io/js/backed-cli.svg +[npm-url]: https://npmjs.org/package/backed-cli +[travis-image]: https://travis-ci.org/VandeurenGlenn/backed-cli.svg?branch=master +[travis-url]: https://travis-ci.org/VandeurenGlenn/backed-cli +[daviddm-image]: https://david-dm.org/VandeurenGlenn/backed-cli.svg?theme=shields.io +[daviddm-url]: https://david-dm.org/VandeurenGlenn/backed-cli +[coveralls-image]: https://coveralls.io/repos/VandeurenGlenn/backed-cli/badge.svg +[coveralls-url]: https://coveralls.io/r/VandeurenGlenn/backed-cli diff --git a/bin/backed-cli.js b/bin/backed-cli.js new file mode 100644 index 0000000..0e0b3f5 --- /dev/null +++ b/bin/backed-cli.js @@ -0,0 +1,58 @@ +#!/usr/bin/env node +(function () { +'use strict'; + +const {rollup} = require('rollup'); +const json = require('rollup-plugin-json'); +const babel = require('rollup-plugin-babel'); +let cache; + +const importConfig = () => { + let config; + try { + config = require('backed.json'); + return config; + } catch (error) { + return console.warn('Backed::backed.json not found, checkout https://github.com/basicelements/backed-cli for more info'); + } +}; + +const backedBuilder$1 = () => { + const config = importConfig(); + + return rollup({ + entry: config.src, + // Use the previous bundle as starting point. + cache: cache + }).then(bundle => { + // Cache our bundle for later use (optional) + cache = bundle; + + bundle.write({ + format: config.format || 'es', + sourceMap: config.sourceMap || true, + plugins: [ + json(), + babel() + ], + dest: config.dest + }); + }); +}; + +process.title = 'backed'; +const commander = require('commander'); +const {version} = require('package.json'); + +commander + .version(version) + .option('-b, --build', 'build your app/component') + .parse(process.argv); + +let build = commander.build; + +if (build) { + backedBuilder$1(); +} + +}()); diff --git a/config/backed.json b/config/backed.json new file mode 100644 index 0000000..8111e19 --- /dev/null +++ b/config/backed.json @@ -0,0 +1,6 @@ +export default { + "src": "src/backed-cli", + "dest": "dist/backed-cli.js", + "format": "es", + "sourceMap": true +} diff --git a/gulpfile.js b/gulpfile.js new file mode 100644 index 0000000..9cfd119 --- /dev/null +++ b/gulpfile.js @@ -0,0 +1,114 @@ +'use strict'; +var path = require('path'); +var {task, src, dest, watch, series} = require('gulp'); +var eslint = require('gulp-eslint'); +var excludeGitignore = require('gulp-exclude-gitignore'); +var mocha = require('gulp-mocha'); +var istanbul = require('gulp-istanbul'); +var nsp = require('gulp-nsp'); +var plumber = require('gulp-plumber'); +var coveralls = require('gulp-coveralls'); +var rollup = require('rollup'); +var json = require('rollup-plugin-json'); +var babel = require('rollup-plugin-babel'); +var fs = require('fs'); +var del = require('del'); +var merge = require('merge-stream'); + +let cache; +let cliCache; + +task('static', () => { + return src('**/*.js') + .pipe(excludeGitignore()) + .pipe(eslint()) + .pipe(eslint.format()) + .pipe(eslint.failAfterError()); +}); + +task('nsp', cb => { + nsp({package: path.resolve('package.json')}, cb); +}); + +task('pre-test', () => { + return src('lib/**/*.js') + .pipe(excludeGitignore()) + .pipe(istanbul({ + includeUntested: true + })) + .pipe(istanbul.hookRequire()); +}); +task('test:after', cb => { + var mochaErr; + + src('test/**/*.js') + .pipe(plumber()) + .pipe(mocha({reporter: 'spec'})) + .on('error', err => { + mochaErr = err; + }) + .pipe(istanbul.writeReports()) + .on('end', () => { + cb(mochaErr); + }); +}); +task('test', series('pre-test', 'test:after')); + +task('watch', () => { + watch(['lib/**/*.js', 'test/**'], ['test']); +}); + +task('coveralls:after', () => { + if (!process.env.CI) { + return; + } + + return src(path.join(__dirname, 'coverage/lcov.info')) + .pipe(coveralls()); +}); + +task('coveralls', series('test', 'coveralls:after')); + +task('rollup:run', () => { + return rollup.rollup({ + entry: 'src/backed-cli.js', + // Use the previous bundle as starting point. + cache: cliCache + }).then(bundle => { + var result = bundle.generate({ + format: 'iife', + moduleName: 'backedCli', + plugins: [json(), babel()] + }); + // Cache our bundle for later use (optional) + cache = bundle; + fs.writeFileSync('.tmp/backed-cli.js', result.code); + }); +}); + +task('rollup:before', cb => { + fs.mkdirSync('.tmp'); + cb(); +}); + +task('rollup:after', () => { + var string = fs.readFileSync('.tmp/backed-cli.js').toString(); + string = string.replace('(function', `#!/usr/bin/env node +(function`); + fs.unlinkSync('.tmp/backed-cli.js'); + fs.writeFileSync('.tmp/backed-cli.js', string); + var cli = src('.tmp/backed-cli.js').pipe(dest('bin')); + + return merge(cli); +}); + +task('clean', cb => { + del.sync(['.tmp/', 'bin/', 'lib/']); + cb(); +}); + +task('rollup', series('rollup:before', 'rollup:run', 'rollup:after')); + +task('build', series('clean', 'rollup')); +task('prepublish', series('nsp')); +task('default', series('static', 'test', 'coveralls')); diff --git a/package.json b/package.json new file mode 100644 index 0000000..bda56cb --- /dev/null +++ b/package.json @@ -0,0 +1,69 @@ +{ + "name": "backed-cli", + "version": "0.0.0", + "description": "The official command line interface for Backed", + "homepage": "https://github.com/vandeurenglenn/backed-cli", + "author": { + "name": "Glenn Vandeuren", + "email": "vandeurenglenn@gmail.com", + "url": "" + }, + "files": [ + "lib", + "bin", + "src" + ], + "main": "lib/index.js", + "keywords": [ + "" + ], + "devDependencies": { + "babel-plugin-external-helpers": "^6.18.0", + "babel-preset-es2015": "^6.18.0", + "del": "^2.2.2", + "eslint": "^3.1.1", + "eslint-config-xo-space": "^0.15.0", + "gulp": "gulpjs/gulp#4.0", + "gulp-coveralls": "^0.1.0", + "gulp-eslint": "^3.0.1", + "gulp-exclude-gitignore": "^1.0.0", + "gulp-istanbul": "^1.0.0", + "gulp-line-ending-corrector": "^1.0.1", + "gulp-mocha": "^3.0.1", + "gulp-nsp": "^2.1.0", + "gulp-plumber": "^1.0.0", + "merge-stream": "^1.0.1", + "rollup": "^0.40.2", + "rollup-plugin-babel": "^2.7.1", + "rollup-plugin-json": "^2.1.0" + }, + "eslintConfig": { + "extends": "xo-space", + "env": { + "browser": true, + "mocha": true + } + }, + "repository": "VandeurenGlenn/backed-cli", + "scripts": { + "prepublish": "gulp prepublish", + "test": "gulp" + }, + "license": "MIT", + "dependencies": { + "inject-template": "^0.2.0" + }, + "babel": { + "presets": [ + [ + "es2015", + { + "modules": false + } + ] + ], + "plugins": [ + "external-helpers" + ] + } +} diff --git a/src/backed-cli.js b/src/backed-cli.js new file mode 100644 index 0000000..39a0183 --- /dev/null +++ b/src/backed-cli.js @@ -0,0 +1,16 @@ +process.title = 'backed'; +const commander = require('commander'); +const {version} = require('package.json'); + +import builder from './builder.js'; + +commander + .version(version) + .option('-b, --build', 'build your app/component') + .parse(process.argv); + +let build = commander.build; + +if (build) { + builder(); +} diff --git a/src/builder.js b/src/builder.js new file mode 100644 index 0000000..e02497c --- /dev/null +++ b/src/builder.js @@ -0,0 +1,39 @@ +'use strict'; +const {rollup} = require('rollup'); +const json = require('rollup-plugin-json'); +const babel = require('rollup-plugin-babel'); +let cache; + +const importConfig = () => { + let config; + try { + config = require('backed.json'); + return config; + } catch (error) { + return console.warn('Backed::backed.json not found, checkout https://github.com/basicelements/backed-cli for more info'); + } +}; + +const backedBuilder = () => { + const config = importConfig(); + + return rollup({ + entry: config.src, + // Use the previous bundle as starting point. + cache: cache + }).then(bundle => { + // Cache our bundle for later use (optional) + cache = bundle; + + bundle.write({ + format: config.format || 'es', + sourceMap: config.sourceMap || true, + plugins: [ + json(), + babel() + ], + dest: config.dest + }); + }); +}; +export default backedBuilder; diff --git a/test/index.js b/test/index.js new file mode 100644 index 0000000..d8055fe --- /dev/null +++ b/test/index.js @@ -0,0 +1,10 @@ +'use strict'; + +var assert = require('assert'); +var backed = require('../lib'); + +describe('backed', function () { + it('should have unit test!', function () { + assert(false, 'we expected this package author to add actual unit tests.'); + }); +});