Skip to content

Commit

Permalink
Merge pull request #9 from doug-wade/generator-clefs-plugin
Browse files Browse the repository at this point in the history
Add yeoman generator and boilerplate as clefs-googledrive
  • Loading branch information
doug-wade authored Jun 13, 2016
2 parents 1d5de5b + ffa8308 commit 7b5aa47
Show file tree
Hide file tree
Showing 28 changed files with 469 additions and 4 deletions.
3 changes: 3 additions & 0 deletions packages/clefs-googledrive/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["es2015", "stage-0"]
}
3 changes: 3 additions & 0 deletions packages/clefs-googledrive/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
npm-debug.log*
node_modules
/index.js
1 change: 1 addition & 0 deletions packages/clefs-googledrive/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
src
21 changes: 21 additions & 0 deletions packages/clefs-googledrive/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# clefs-googledrive

A [clefs](https://npmjs.com/package/clefs) layer.

![Clefs logo](http://doug-wade.github.io/clefs/img/logo.svg)

# Getting started

## Installing

npm i -S clefs clefs-googledrive


## Usage

import clefs from 'clefs';
import googledrive from 'clefs-googledrive';

const fs = clefs([simpleobject]);
const fileContents = await fs.readFile('/path/to/file.txt');
console.log(fileContents);
36 changes: 36 additions & 0 deletions packages/clefs-googledrive/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "clefs-googledrive",
"version": "0.0.4",
"description": "An fs layer backed by googledrive",
"main": "index.js",
"scripts": {
"clean": "del-cli npm-debug.log* index.js",
"test": "xo src/index.js && snyk test",
"compile": "babel src/index.js --presets es2015,stage-0 -o index.js",
"prepublish": "npm run clean && npm run compile",
"nuke": "del-cli node_modules"
},
"repository": {
"type": "git",
"url": "git+ssh://[email protected]/doug-wade/clefs.git"
},
"keywords": [
"fs",
"isomorphic",
"layers"
],
"license": "MIT",
"bugs": {
"url": "https://github.com/doug-wade/clefs/issues"
},
"homepage": "https://github.com/doug-wade/clefs#readme",
"devDependencies": {
"ava": "^0.15.2",
"babel-cli": "^6.9.0",
"babel-preset-es2015": "^6.9.0",
"babel-preset-stage-0": "^6.5.0",
"del-cli": "^0.2.0",
"snyk": "^1.14.3",
"xo": "^0.15.1"
}
}
20 changes: 20 additions & 0 deletions packages/clefs-googledrive/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const fs = {};

module.exports = {
writeFile(file, data) {
return new Promise((resolve) => {
fs[file] = data;
resolve();
});
},
readFile(file) {
return new Promise((resolve, reject) => {
if (fs[file]) {
resolve(fs[file]);
} else {
reject(new Error(`file not found ${file}`));
}
});
},
name: 'googledrive'
};
7 changes: 6 additions & 1 deletion packages/clefs/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ function getHandler(api, layers) {
if (layers.length === 1) {
return promises[0];
}
return Promise.all(promises);

if (name === 'readFile') {
return Promise.race(promises);
} else if (name === 'writeFile') {
return Promise.all(promises);
}
};
}
}
Expand Down
2 changes: 2 additions & 0 deletions packages/generator-clefs-plugin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
coverage
21 changes: 21 additions & 0 deletions packages/generator-clefs-plugin/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2016 Doug Wade <[email protected]> (dougwade.io)

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.
38 changes: 38 additions & 0 deletions packages/generator-clefs-plugin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# generator-clefs-plugin [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][daviddm-image]][daviddm-url] [![Coverage percentage][coveralls-image]][coveralls-url]
> Generate a new clefs plugin

## Installation

First, install [Yeoman](http://yeoman.io) and generator-clefs-plugin using [npm](https://www.npmjs.com/) (we assume you have pre-installed [node.js](https://nodejs.org/)).

```bash
npm install -g yo
npm install -g generator-clefs-plugin
```

Then generate your new project:

```bash
yo clefs-plugin
```

## Getting To Know Yeoman

* Yeoman has a heart of gold.
* Yeoman is a person with feelings and opinions, but is very easy to work with.
* Yeoman can be too opinionated at times but is easily convinced not to be.
* Feel free to [learn more about Yeoman](http://yeoman.io/).

## License

MIT © [Doug Wade](dougwade.io)


[npm-image]: https://badge.fury.io/js/generator-clefs-plugin.svg
[npm-url]: https://npmjs.org/package/generator-clefs-plugin
[travis-image]: https://travis-ci.org/doug-wade/generator-clefs-plugin.svg?branch=master
[travis-url]: https://travis-ci.org/doug-wade/generator-clefs-plugin
[daviddm-image]: https://david-dm.org/doug-wade/generator-clefs-plugin.svg?theme=shields.io
[daviddm-url]: https://david-dm.org/doug-wade/generator-clefs-plugin
[coveralls-image]: https://coveralls.io/repos/doug-wade/generator-clefs-plugin/badge.svg
[coveralls-url]: https://coveralls.io/r/doug-wade/generator-clefs-plugin
53 changes: 53 additions & 0 deletions packages/generator-clefs-plugin/generators/app/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
'use strict';
const path = require('path');
const yeoman = require('yeoman-generator');
const chalk = require('chalk');
const yosay = require('yosay');

module.exports = yeoman.Base.extend({
prompting: function () {
let _this = this;
_this.log(yosay(
'Welcome to the shining ' + chalk.green('clefs plugin') + ' generator!'
));

let prompts = [{
type: 'input',
name: 'name',
message: 'What would you like to call your plugin?',
default: this.appname
}];

return _this.prompt(prompts).then((props) => {
if (props.name.startsWith('clefs-')) {
props.name = props.name.replace('clefs-', '');
}
_this.props = props;
});
},

writing: function () {
let _this = this;

let files = [
'src/index.js',
'.babelrc',
'.gitignore',
'.npmignore',
'package.json',
'README.md'
];

files.forEach((filename) => {
_this.fs.copyTpl(
_this.templatePath(filename),
_this.destinationPath(path.join('packages', 'clefs-' + _this.props.name, filename)),
_this.props
);
});
},

install: function () {
this.npmInstall();
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["es2015", "stage-0"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
npm-debug.log*
node_modules
/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
src
21 changes: 21 additions & 0 deletions packages/generator-clefs-plugin/generators/app/templates/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# clefs-<%= name %>

A [clefs](https://npmjs.com/package/clefs) layer.

![Clefs logo](http://doug-wade.github.io/clefs/img/logo.svg)

# Getting started

## Installing

npm i -S clefs clefs-<%= name %>


## Usage

import clefs from 'clefs';
import <%= name %> from 'clefs-<%= name %>';

const fs = clefs([simpleobject]);
const fileContents = await fs.readFile('/path/to/file.txt');
console.log(fileContents);
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "clefs-<%= name %>",
"version": "0.0.4",
"description": "An fs layer backed by <%= name %>",
"main": "index.js",
"scripts": {
"clean": "del-cli npm-debug.log* index.js",
"test": "xo src/index.js && snyk test",
"compile": "babel src/index.js --presets es2015,stage-0 -o index.js",
"prepublish": "npm run clean && npm run compile",
"nuke": "del-cli node_modules"
},
"repository": {
"type": "git",
"url": "git+ssh://[email protected]/doug-wade/clefs.git"
},
"keywords": [
"fs",
"isomorphic",
"layers"
],
"license": "MIT",
"bugs": {
"url": "https://github.com/doug-wade/clefs/issues"
},
"homepage": "https://github.com/doug-wade/clefs#readme",
"devDependencies": {
"ava": "^0.15.2",
"babel-cli": "^6.9.0",
"babel-preset-es2015": "^6.9.0",
"babel-preset-stage-0": "^6.5.0",
"del-cli": "^0.2.0",
"snyk": "^1.14.3",
"xo": "^0.15.1"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const fs = {};

module.exports = {
writeFile(file, data) {
return new Promise((resolve) => {
fs[file] = data;
resolve();
});
},
readFile(file) {
return new Promise((resolve, reject) => {
if (fs[file]) {
resolve(fs[file]);
} else {
reject(new Error(`file not found ${file}`));
}
});
},
name: '<%= name %>'
};
49 changes: 49 additions & 0 deletions packages/generator-clefs-plugin/gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
'use strict';
var path = require('path');
var gulp = require('gulp');
var ava = require('gulp-ava');
var xo = require('gulp-xo');
var nsp = require('gulp-nsp');
var plumber = require('gulp-plumber');
var coveralls = require('gulp-coveralls');

gulp.task('static', function () {
return gulp.src('generators/app/index.js')
.pipe(xo({
esnext: true
}));
});

gulp.task('nsp', function (cb) {
nsp({package: path.resolve('package.json')}, cb);
});

gulp.task('test', function (cb) {
var avaErr;

gulp.src('test/**/*.js')
.pipe(plumber())
.pipe(ava())
.on('error', function (err) {
avaErr = err;
})
.on('end', function () {
cb(avaErr);
});
});

gulp.task('watch', function () {
gulp.watch(['generators/**/*.js', 'test/**'], ['test']);
});

gulp.task('coveralls', ['test'], function () {
if (!process.env.CI) {
return;
}

return gulp.src(path.join(__dirname, 'coverage/lcov.info'))
.pipe(coveralls());
});

gulp.task('prepublish', ['nsp']);
gulp.task('default', ['static', 'test', 'coveralls']);
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Loading

0 comments on commit 7b5aa47

Please sign in to comment.