Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Van Camp committed Feb 13, 2016
0 parents commit 8f7cb91
Show file tree
Hide file tree
Showing 19 changed files with 1,130 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitattributes
@@ -0,0 +1 @@
* text=auto
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@
node_modules
coverage
5 changes: 5 additions & 0 deletions .travis.yml
@@ -0,0 +1,5 @@
sudo: false
language: node_js
node_js:
- v4
- v5
21 changes: 21 additions & 0 deletions LICENSE
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2016 Alex Van Camp <email@alexvan.camp> (http://alexvan.camp)

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.
50 changes: 50 additions & 0 deletions README.md
@@ -0,0 +1,50 @@
# generator-nodecg [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][daviddm-image]][daviddm-url]
> Yeoman generator for [NodeCG](http://nodecg.com/) bundles
## Installation

First, install [Yeoman](http://yeoman.io) and generator-nodecg 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-nodecg
```

Then generate your new bundle:

```bash
yo nodecg
```

generator-nodecg also has specific sub-generators that can be used on existing bundles:

```bash
yo nodecg:panel
yo nodecg:graphic
yo nodecg:extension
```

## Getting To Know Yeoman

Yeoman has a heart of gold. He&#39;s a person with feelings and opinions, but he&#39;s very easy to work with.
If you think he&#39;s too opinionated, he can be easily convinced.
Feel free to [learn more about him](http://yeoman.io/).

## Special Thanks

Significant portions of this generator are based on [generator-node](https://github.com/yeoman/generator-node).
We thank the developers of [generator-node](https://github.com/yeoman/generator-node) and
[Yeoman](http://yeoman.io/) for their years of hard work.

## License

MIT © [Alex Van Camp](http://alexvan.camp)


[npm-image]: https://badge.fury.io/js/generator-nodecg.svg
[npm-url]: https://npmjs.org/package/generator-nodecg
[travis-image]: https://travis-ci.org/nodecg/generator-nodecg.svg?branch=master
[travis-url]: https://travis-ci.org/nodecg/generator-nodecg
[daviddm-image]: https://david-dm.org/nodecg/generator-nodecg.svg?theme=shields.io
[daviddm-url]: https://david-dm.org/nodecg/generator-nodecg
248 changes: 248 additions & 0 deletions generators/app/index.js
@@ -0,0 +1,248 @@
'use strict';

var path = require('path');
var yeoman = require('yeoman-generator');
var chalk = require('chalk');
var yosay = require('yosay');
var _ = require('lodash');
var askName = require('inquirer-npm-name');
var extend = require('deep-extend');
var mkdirp = require('mkdirp');
var githubUsername = require('github-username');
var parseAuthor = require('parse-author');

module.exports = yeoman.Base.extend({
constructor: function () {
yeoman.generators.Base.apply(this, arguments);

this.option('editorconfig', {
type: Boolean,
required: false,
desc: 'Add NodeCG\'s recommended editorconfig to your bundle'
});
},

initializing: function () {
// Have Yeoman greet the user.
this.log(yosay(
'Welcome to the ' + chalk.red('NodeCG bundle') + ' generator!'
));

this.pkg = this.fs.readJSON(this.destinationPath('package.json'), {});

// Pre set the default props from the information we have at this point
this.props = {
name: this.pkg.name,
description: this.pkg.description,
version: this.pkg.version,
homepage: this.pkg.homepage
};

if (_.isObject(this.pkg.author)) {
this.props.authorName = this.pkg.author.name;
this.props.authorEmail = this.pkg.author.email;
this.props.authorUrl = this.pkg.author.url;
} else if (_.isString(this.pkg.author)) {
var info = parseAuthor(this.pkg.author);
this.props.authorName = info.name;
this.props.authorEmail = info.email;
this.props.authorUrl = info.url;
}
},

prompting: {
askForModuleName: function () {
var done = this.async();

askName({
name: 'name',
message: 'Your bundle Name',
default: _.kebabCase(path.basename(process.cwd())),
filter: _.kebabCase,
validate: function (str) {
return str.length > 0;
}
}, this, function (name) {
this.props.name = name;
done();
}.bind(this));
},

askFor: function () {
var done = this.async();

var prompts = [{
name: 'description',
message: 'Description',
when: !this.props.description
}, {
name: 'homepage',
message: 'Project homepage url',
when: !this.props.homepage
}, {
name: 'authorName',
message: 'Author\'s Name',
when: !this.props.authorName,
default: this.user.git.name(),
store: true
}, {
name: 'authorEmail',
message: 'Author\'s Email',
when: !this.props.authorEmail,
default: this.user.git.email(),
store: true
}, {
name: 'authorUrl',
message: 'Author\'s Homepage',
when: !this.props.authorUrl,
store: true
}, {
name: 'keywords',
message: 'Package keywords (comma to split)',
when: !this.pkg.keywords,
filter: function (words) {
return words.split(/\s*,\s*/g);
}
}, {
name: 'compatibleRange',
message: 'What semver range of NodeCG versions is this bundle compatible with?',
type: 'input',
default: '~0.7.0'
}, {
name: 'dashboardPanel',
message: 'Would you like to make a dashboard panel for your bundle?',
type: 'confirm'
}, {
name: 'graphic',
message: 'Would you like to make a graphic for your bundle?',
type: 'confirm'
}, {
name: 'extension',
message: 'Would you like to add an extension to your bundle?',
type: 'confirm'
}];

this.prompt(prompts, function (props) {
this.props = extend(this.props, props);
done();
}.bind(this));
},

askForGithubAccount: function () {
var done = this.async();

githubUsername(this.props.authorEmail, function (err, username) {
if (err) {
username = username || '';
}
this.prompt({
name: 'githubAccount',
message: 'GitHub username or organization',
default: username
}, function (prompt) {
this.props.githubAccount = prompt.githubAccount;
done();
}.bind(this));
}.bind(this));
}
},

writing: function () {
// Re-read the content at this point because a composed generator might modify it.
var currentPkg = this.fs.readJSON(this.destinationPath('package.json'), {});

var pkg = extend({
name: _.kebabCase(this.props.name),
version: '0.0.0',
description: this.props.description,
homepage: this.props.homepage,
author: {
name: this.props.authorName,
email: this.props.authorEmail,
url: this.props.authorUrl
},
files: [
'dashboard',
'graphics',
'extension.js',
'extension'
],
keywords: [
'nodecg-bundle'
],
nodecg: {
compatibleRange: this.props.compatibleRange
}
}, currentPkg);

// Combine the keywords
if (this.props.keywords) {
pkg.keywords = _.uniq(this.props.keywords.concat(pkg.keywords));
}

// Let's extend package.json so we're not overwriting user previous fields
this.fs.writeJSON(this.destinationPath('package.json'), pkg);

// Populate and write the readme template
if (!this.fs.exists(this.destinationPath('README.md'))) {
this.fs.copyTpl(
this.templatePath('README.md'),
this.destinationPath('README.md'),
{
name: this.props.name,
compatibleRange: this.props.compatibleRange
}
);
}
},

default: function () {
if (path.basename(this.destinationPath()) !== this.props.name) {
this.log(
'Your bundle must be inside a folder named ' + this.props.name + '\n' +
'I\'ll automatically create this folder.'
);
mkdirp(this.props.name);
this.destinationRoot(this.destinationPath(this.props.name));
}

this.composeWith('node:git', {
options: {
name: this.props.name,
githubAccount: this.props.githubAccount
}
}, {
local: require.resolve('generator-node/generators/git')
});

if (!this.pkg.license) {
this.composeWith('license', {
options: {
name: this.props.authorName,
email: this.props.authorEmail,
website: this.props.authorUrl
}
}, {
local: require.resolve('generator-license/app')
});
}

if (this.props.dashboardPanel) {
this.composeWith('nodecg:panel', {}, {
local: require.resolve('./../panel')
});
}

if (this.props.graphic) {
this.composeWith('nodecg:graphic', {}, {
local: require.resolve('./../graphic')
});
}

if (this.props.extension) {
this.composeWith('nodecg:extension', {}, {
local: require.resolve('./../extension')
});
}
}
});
4 changes: 4 additions & 0 deletions generators/app/templates/README.md
@@ -0,0 +1,4 @@
<%- name %> is a [NodeCG](http://github.com/nodecg/nodecg) bundle.
It works with NodeCG versions which satisfy this [semver](https://docs.npmjs.com/getting-started/semantic-versioning) range: `<%- compatibleRange %>`
You will need to have an appropriate version of NodeCG installed to use it.

53 changes: 53 additions & 0 deletions generators/extension/index.js
@@ -0,0 +1,53 @@
'use strict';

var yeoman = require('yeoman-generator');
var extend = require('deep-extend');

module.exports = yeoman.Base.extend({
initializing: function () {
this.props = {};
},

prompting: {
askFor: function () {
var done = this.async();

var prompts = [{
type: 'list',
name: 'type',
message: 'How should your extension be organized?',
choices: [{
name: 'In one file (extension.js)',
value: 'file',
short: 'file'
}, {
name: 'In a folder (extension/index.js)',
value: 'folder',
short: 'folder'
}],
default: 'file'
}];

this.prompt(prompts, function (props) {
this.props = extend(this.props, props);
done();
}.bind(this));
}
},

writing: function () {
// If this bundle already has an extension, do nothing.
if (this.fs.exists(this.destinationPath('extension.js'))
|| this.fs.exists(this.destinationPath('extension/index.js'))) {
return;
}

var js = this.fs.read(this.templatePath('extension.js'));

if (this.props.type === 'file') {
this.fs.write(this.destinationPath('extension.js'), js);
} else {
this.fs.write(this.destinationPath('extension/index.js'), js);
}
}
});
5 changes: 5 additions & 0 deletions generators/extension/templates/extension.js
@@ -0,0 +1,5 @@
'use strict';

module.exports = function (nodecg) {

};

0 comments on commit 8f7cb91

Please sign in to comment.