yeoman / generator-node Goto Github PK
View Code? Open in Web Editor NEWCreate a Node.js module
Home Page: http://yeoman.io
License: MIT License
Create a Node.js module
Home Page: http://yeoman.io
License: MIT License
I've just installed and it has failed with yo node
then I've search some information and I've found the #53 so I've installed the generator by using npm i [email protected] -g
and it works.
I'm suggesting to add this information in the README.md or change the stable version to 0.4.2
Currently, generator-node only allows using nodeunit as the test framework. Albeit, it can be changed later in package.json but it will be nice to have an option, --test <name-of-the-desired-test-framework>
(maybe?) to allow working with other test frameworks such as mocha, expresso etc.
Under ubuntu 13.10
Linux FC-lab 3.11.0-13-generic #20-Ubuntu SMP Wed Oct 23 17:26:33 UTC 2013 i686 i686 i686 GNU/Linux
When I generate a project with yo node
, all the files are in DOS
format with \r\n
as line ending, e.g. package.json
, Gruntfile.js
and etc.
I tried other generator such as generator-chrome-extension
but didn't meet the same issue.
When I open the original template files under ~/.nvm/v0.10.22/lib/node_modules/generator-node
, they are in DOS
format. But the templates in other node modules are unix
format.
Any hint?
When visiting generator-node/app/templates
on Github, README.md hasn't been compiled, breaking it's output.
@SBoudrias you forgot this in package.json. Otherwise the dist
directory doesn't get published to npm.
Time to add some babel support and use es6
features wherever we can?
#110 is not in the git history. Where is it? π
Currently this is failing. That's kind of related to #123, but this issue is probably going to take a while, so let's make sure we're fixing JSHint ASAP.
Any chance of adding code coverage tool (e.g. Istanbul or jscoverage) integration to the generated modules?
When Windows users start to contribute to a software project, the issue of DOS-style vs. Unix-style newlines invariably raises it ugly head.
I therefore propose that this generator should set grunt.util.linefeed = '\n';
and generate an appropriate .gitattributes
file (similar to https://github.com/twbs/bootlint/blob/master/.gitattributes) so as to standardize newlines in a project right from the get-go.
Was going to start a new project, but updated my generator and spent an hour Googling for this before giving up. I used to be prompted for things like a CLI, but now it is always created. The "Options" section of the documentation makes it sound like it is possible to disable this, but I can't seem to figure out how to actually use the option. I've tried all kinds of different ways to specify it:
yo node --cli=false
yo node --cli="false"
yo node --cli=no
yo node --cli false
yo node --cli
yo node cli=false
None of these work, and I always end up with a lib/cli.js
file. How am I supposed to specify this option? Is it just broken, or is there a syntax I haven't guessed yet?
Here's what I get:
The name of your project shouldn't contain "node" or "js" and
should be a unique ID not already in use at search.npmjs.org.
[?] Module Name: (dir-name)
events.js:74ter a valid value
throw TypeError('Uncaught, unspecified "error" event.');
^
TypeError: Uncaught, unspecified "error" event.
at TypeError (<anonymous>)
at emit (events.js:74:15)
at done (C:\Users\tom\AppData\Roaming\npm\node_modules\generator-node\node_modules\yeo
man-generator\lib\base.js:375:23)
at onResponse (C:\Users\tom\AppData\Roaming\npm\node_modules\generator-node\app\index.
js:38:17)
at C:\Users\tom\AppData\Roaming\npm\node_modules\generator-node\node_modules\npm-name\
index.js:8:11
at ClientRequest.<anonymous> (C:\Users\tom\AppData\Roaming\npm\node_modules\generator-
node\node_modules\npm-name\node_modules\got\index.js:47:5)
at ClientRequest.g (events.js:180:16)
at ClientRequest.emit (events.js:95:17)
at HTTPParser.parserOnIncomingClient [as onIncoming] (http.js:1688:21)
at HTTPParser.parserOnHeadersComplete [as onHeadersComplete] (http.js:121:23)
While the current implementation will catch the case where a name is already used on NPM, it does not allow the user to re-enter a new name. Instead, the user chooses Y/n
and, regardless of the answer, the generator moves to the next prompt.
Validation of user input should utilize the Inquirer.js validate option. This forces the user to enter a new name which is then validated before progressing to the next prompt.
A couple days ago we started talking about consolidating the yeoman core build system in a reusable module yeoman/yeoman#1440 - This module obviously is generator-node
.
All the features contained in https://github.com/yeoman/generator will be added or updated to match our internal style.
To make a short list:
Default build will use gulp
, but we intend to provide the choice between:
Any requests or comments is welcome! (Help marking this happens is also welcome!)
In the template file
for example
{
"name": "<%= slugname %>",
"version": "0.0.0",
"main": "lib/<%= slugname %>.js",
"description": "<%= props.description %>",<% if (props.homepage) { %>
"homepage": "<%= props.homepage %>",<%}%>
"bugs": "<%= repoUrl %>/issues",
"author": {
"name": "<%= props.authorName %>",
"email": "<%= props.authorEmail %>"<% if (props.authorUrl) { %>,
"url": "<%= props.authorUrl %>"<% } %>
}
}
In this case we have variable slugname
props.homepage
Can we select just one type
props
variable
(assign all props to a variable, let props.authorName
=> authorName
)Easier for maintenance.
Thanks
Currently they're linted and most of the time will raise jshint issue.
Let's make sure they're removed from our linting target.
I think the smartest thing to do here is to consume the .gitignore
file content and exclude these files from the linting process. That way we only have a single place to define them.
~ $ npm install -g git+https://[email protected]/yeoman/generator-node
npm ERR! registry error parsing json
I just noticed that when I scaffold a new module with CLI by using yo node --cli
, in package.json
bin
points to non-existent path ("dist/cli.js"
).
As an example, I tried to link my new module with following result:
C:\Projects\testapp-node-cli
Ξ» npm link
npm ERR! Windows_NT 6.1.7601
npm ERR! argv "C:\\Program Files\\nodejs\\\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "link"
npm ERR! node v0.12.5
npm ERR! npm v2.11.2
npm ERR! path C:\Users\<user>\AppData\Roaming\npm\node_modules\testapp-node-cli\dist\cli.js
npm ERR! code ENOENT
npm ERR! errno -4058
And real dir structure:
...
ββββlib
β cli.js
β index.js
β
ββββnode_modules
ββββtest
However, if I run yo node:cli
this issue doesn't happen. Not sure about the specifics, but I think it originates from here https://github.com/yeoman/generator-node/blob/master/generators/cli/index.js#L14
We could base ourselves on yeoman-environment who's not using Gulp. (see yeoman/environment@d89bdc3#commitcomment-9690814)
You are prompted to name your module like so:
Module Name: (yo-node)
However, if you actually include a hyphen in your module name ('best-module-evar'),and then try to run the grunt build, you get lots of errors.
Minor issue for sure, but bit me, so wanted to mention in.
This is introduced in 49d1816. It creates a script
key in package.json
, not scripts
as it should be.
Will it be useful for the Gruntfile to have tasks for npm adduser
and npm publish
?
Also will be useful if we go a step further and make a publish
task that would not only publish to npmjs repo but also push to the remote origin.
why not create a structure with sources folder?
.
βββ Gruntfile.js
βββ index.js
βββ package.json
βββ README.md
βββ src
βΒ Β βββ index.js
βββ test
βββ test.js
/index.js -> exporting require src/index
/Gruntfile.js
js: {
src: ['src/**/*.js']
},
Sorry for bothering you again but Babel is missing in the README. There might be other stuff missing as well but I haven't checked.
Currently generator-node
populates the repository
field in package.json
using the username which is prompted for and the package name. Often the github repo name and the npm package name are different. I think it would be better to check whether the target directory is a git repo and then get the repo url from either .git/config
or .git/FETCH_HEAD
. If it isn't a git repository then fall back to asking the user for their username and guessing repo name.
var <%= slugname %> = require('<%= slugname %>');
Is this a bug?
Both cli.js and browserify options are being ignored if the user types "no".
If a user writes "no" (or anything else) when asked if they want to include cli.js and/or browserify support, the choice always gets ignored and both scripts get inserted.
It seems that the values are being read as strings but interpreted as boolean (as they should).
This is more of a discussion topic.
I'm one of the last people to force TDD down anyone's throat, but what do people think of the generator scaffolding a test that fails first off?
I only say this as I've seen a few modules with the default test left in, and I've been guilty myself of quickly publishing one without writing tests and then going back to implement some.
An initial failing test may remind or prompt people to fix it/amend it to suit their module.
We use jshint to detect errors and potential problems so why not adding jscs to check code style? indent
option is deprecated (this was the main reason I personally start using jshint). http://jshint.com/docs/options/#indent
This feature request applies to all other generators.
"Create a Node.js module with yo, including Nodeunit unit tests."
-->
"Create a Node.js module with yo, including Mocha unit tests."
running yo node and not entering anything to the questions seems to result into a broken package.json -there are comas inside the quotes, for example:
"description": "The best module ever.,"
"homepage": "https://github.com//nodegen,"
fixing the errors and running it again (without overwriting package.json) fixes the problem.
Is it intentional? I think the cli option is quite useful.
I can't see why main
isn't added to the package.json file since the entry point file is created in /lib/[module].js
When a name is taken in npm
, you will NOT be re-prompted to choose a new name (npmName(answers.name) === false
)
When a name is available in npm
, you will be re-prompted to choose a new name (npmName(answers.name) === true
)
This is happening in a fresh install of node, npm, yeoman, and generator-node, on OSX 10.10.3
In line 72 of index.js
, done(...)
is directly provided the result of the call to npmName(answers.name)
. So the done(...)
function is given true
when a name is available - but true
being provided to done(...)
indicates the question should be asked again - so the solution is just flipping this boolean.
Will have an incredibly brief PR submitted shortly!
Hopefully I'm not missing something obvious or seeing atypical behaviour (wrong version of something, or something), feel free to let me know here or in the PR if I am!
to whom it may concern,
by default generator-node proposes yeoman-express as module name (the slugname)
unfortunately this slugname is used in many places, even defining variable names.
Variable names can't contain dashes '-' which generates an error while running grunt if the user accepted all the default values
the filetest/yeoman-express_test.js
contains the following mistaken piece of code
'use strict';
var yeoman-express = require('../lib/yeoman-express.js');
...
test.equal(yeoman-express.awesome(), 'awesome', 'should be awesome.');
...
update the file generator-node / app / templates / test / name_test.js
Just got this one trying to start a project today:
JayAir:site_api jdivock$ yo node
Unable to register generator-node/app/index.js (Error: Cannot find module 'grunt-prompts')
Error node
Bad or missing dependancy?
edit: looks like async is missing as well
Our current JSCS setup doesn't work well with ES2015 (and thus not with the babel option). If you choose to include babel it fails and reports syntax errors.
Also, if you the dist
directory is present it lints that directory too.
Hi, I'm admittedly a newb to yo, but I just used this generator to create a node package with a cli. It was a great boost to getting started, and getting the module working. But, after I published it to npm, I tried to add it as a dependency in another project but the install kept failing with this error:
$ npm install --save approximate-number
npm ERR! Error: ENOENT, chmod 'c:\Users\IBM_ADMIN\service-dashboard\node_modules\approximate-number\cli.js'
npm ERR! If you need help, you may report this *entire* log,
npm ERR! including the npm and node versions, at:
npm ERR! <http://github.com/npm/npm/issues>
npm ERR! System Windows_NT 6.1.7601
npm ERR! command "c:\\Program Files (x86)\\nodejs\\node.exe" "c:\\Program Files (x86)\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "--save" "approximate-number"
npm ERR! cwd c:\Users\IBM_ADMIN\service-dashboard
npm ERR! node -v v0.10.31
npm ERR! npm -v 1.4.23
npm ERR! path c:\Users\IBM_ADMIN\service-dashboard\node_modules\approximate-number\cli.js
npm ERR! code ENOENT
npm ERR! errno 34
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! c:\Users\IBM_ADMIN\service-dashboard\npm-debug.log
npm ERR! not ok code 0
It took me a while, but eventually I figured out that the generator had add a "files": ["lib/"]
entry in my package.json, and that instructs npm to skip everything else, including the cli.js
file that the generator put in the project root.
I did a yo node
with v1.2.0 and then ran gulp
in the output directory with the flowing result:
$ gulp
[11:09:09] Using gulpfile ~/running-average/gulpfile.js
[11:09:09] Starting 'static'...
[11:09:09] Starting 'pre-test'...
[11:09:09] Finished 'pre-test' after 109 ms
[11:09:09] Starting 'test'...
[11:09:09] 'test' errored after 5.69 ms
[11:09:09] Error: Cannot find module 'babel/register'
at Function.Module._resolveFilename (module.js:336:15)
at Function.Module._load (module.js:278:25)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Array.forEach (native)
at module.exports (/Users/nfriedly/running-average/node_modules/gulp-mocha/index.js:27:16)
at Gulp.<anonymous> (/Users/nfriedly/running-average/gulpfile.js:41:11)
at module.exports (/Users/nfriedly/running-average/node_modules/gulp/node_modules/orchestrator/lib/runTask.js:34:7)
at Gulp.Orchestrator._runTask (/Users/nfriedly/running-average/node_modules/gulp/node_modules/orchestrator/index.js:273:3)
at Gulp.Orchestrator._runStep (/Users/nfriedly/running-average/node_modules/gulp/node_modules/orchestrator/index.js:214:10)
at /Users/nfriedly/running-average/node_modules/gulp/node_modules/orchestrator/index.js:279:18
at finish (/Users/nfriedly/running-average/node_modules/gulp/node_modules/orchestrator/lib/runTask.js:21:8)
at /Users/nfriedly/running-average/node_modules/gulp/node_modules/orchestrator/lib/runTask.js:52:4
at f (/Users/nfriedly/running-average/node_modules/gulp/node_modules/orchestrator/node_modules/end-of-stream/node_modules/once/once.js:17:25)
at DestroyableTransform.onend (/Users/nfriedly/running-average/node_modules/gulp/node_modules/orchestrator/node_modules/end-of-stream/index.js:31:18)
at DestroyableTransform.emit (events.js:129:20)
at /Users/nfriedly/running-average/node_modules/gulp-istanbul/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:965:16
at process._tickDomainCallback (node.js:381:11)
/Users/nfriedly/running-average/test/index.js
line 3 col 8 'runningAverage' is defined but never used.
β 1 warning
events.js:85
throw er; // Unhandled 'error' event
^
Error: JSHint failed for: /Users/nfriedly/running-average/test/index.js
That looks like a gulp-mocha issue, but if you dig in, it's just loading the dependencies that the generated gulp.js config tells it to:
gulp.task('test', ['pre-test'], function (cb) {
var mochaErr;
gulp.src('test/**/*.js')
.pipe(plumber())
.pipe(mocha({reporter: 'spec', require: ['babel/register']}))
//...
However, babel
is not directly required by the generated package.json
:
{
//...
"devDependencies": {
"gulp": "^3.6.0",
"gulp-babel": "^5.1.0",
"gulp-coveralls": "^0.1.0",
"gulp-istanbul": "^0.8.1",
"gulp-jscs": "^1.1.0",
"gulp-jshint": "^1.5.3",
"gulp-mocha": "^2.0.0",
"gulp-plumber": "^1.0.0",
"jshint-stylish": "^1.0.0"
},
//...
}
(Presumably it's there in gulp-babel
's node_modules folder, but that isn't good enough for npm 2.x and I don't think it would be correct to skip it even after npm 3.x goes live.)
Would there be interest in adding an option to setup the project for CoffeeScript?
I think its the same change made in generator-grunt at 1848e06c97b52c28bf286453e4b1bd20f822d65f
Thanks.
I would love to be a maintainer for this generator.
/cc @addyosmani
I scaffolded a new node package and after adding a CLI submodule (yo node:cli
or yo node:cli customname
) I get cli.js
with missing stuff (see var = require('./')
and help string).
#!/usr/bin/env node
'use strict';
var meow = require('meow');
var = require('./');
var pkg = require('../');
var cli = meow({
pkg: pkg,
help: [
'Usage',
' $ [input]',
'',
'Examples',
' $ ',
' unicorns',
'',
' $ rainbows',
' unicorns & rainbows',
'',
'Options',
' --foo Lorem ipsum. Default: false'
]
});
I found a solution, see my PR #132
Sorry I didn't raise this issue because I thought it might be just my local environment (I've been debugging and symlinking the project) but I got this by running yo node
.
$ yo node
? Module Name: n
? Description:
? Project homepage url: n
? GitHub username or organization: n
? Author's Name: n
? Author's Email: n
? Author's Homepage: n
? Key your keywords (comma to split) n
? Send coverage reports to coveralls: No
(node) warning: possible EventEmitter memory leak detected. 11 end listeners added. Use emitter.setMaxListeners() to increase limit.
Trace
at Queue.addListener (events.js:179:15)
at Queue.once (events.js:204:8)
at run (/usr/local/lib/node_modules/generator-node/node_modules/yeoman-generator/lib/base.js:396:20)
at composeWith (/usr/local/lib/node_modules/generator-node/node_modules/yeoman-generator/lib/base.js:625:15)
at module.exports.generators.Base.extend [as default] (/usr/local/lib/node_modules/generator-node/generators/app/index.js:213:12)
at /usr/local/lib/node_modules/generator-node/node_modules/yeoman-generator/lib/base.js:428:16
at processImmediate [as _immediateCallback] (timers.js:358:17)
(node) warning: possible EventEmitter memory leak detected. 11 change listeners added. Use emitter.setMaxListeners() to increase limit.
Trace
at addListener (events.js:179:15)
at run (/usr/local/lib/node_modules/generator-node/node_modules/yeoman-generator/lib/base.js:473:21)
at composeWith (/usr/local/lib/node_modules/generator-node/node_modules/yeoman-generator/lib/base.js:625:15)
at module.exports.generators.Base.extend [as default] (/usr/local/lib/node_modules/generator-node/generators/app/index.js:213:12)
at /usr/local/lib/node_modules/generator-node/node_modules/yeoman-generator/lib/base.js:428:16
at processImmediate [as _immediateCallback] (timers.js:358:17)
? Which license do you want to use? Apache 2.0
It works fine nevertheless
I tried
$ yo node --no-babel
and I don't get this warning anymore so I thought it might not just be my local env
Can you confirm? I'm not sure how this would happen. Many thanks.
@SBoudrias You forgot to add a prepublish script, the dist
files don't get generated.
When the new node module has a repo in a github organization the README.md links and package.json 'repository' property, contain the github username instead of the organization name.
Is it possible to add another prompt for 'GitHub organization name (if applicable)'?
Thanks!
(related to #13)
Is it possible to add an option which framework to use for testing?
When I run npm test
in the freshly scaffolded project directory, I get the following error:
Ξ» npm test
> [email protected] test C:\Projects\test-module
> gulp
[12:13:42] Using gulpfile C:\Projects\test-module\gulpfile.js
[12:13:42] Starting 'static'...
[12:13:42] Starting 'pre-test'...
C:\Projects\test-module\gulpfile.js
line 2 col 5 'path' is defined but never used.
βΌ 1 warning
[12:13:43] Finished 'pre-test' after 216 ms
[12:13:43] Starting 'test'...
C:\Projects\test-module\test\index.js
line 5 col 3 Missing "use strict" statement.
line 2 col 8 'testModule' is defined but never used.
Γ 1 error
βΌ 1 warnings
events.js:85
throw er; // Unhandled 'error' event
^
Error: JSHint failed for: C:\Projects\test-module\gulpfile.js, C:\Projects\test-module\test\index.js
npm ERR! Test failed. See above for more details.
Can someone please take a look this? Thanks.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.