AmpersandJS / ampersand

Quickest way to get started with ampersand.
MIT License
812 stars 41 forks source link

New project generation fails when creating .ampersandrc #92

Closed e2jk closed 9 years ago

e2jk commented 9 years ago

Generating a new project with ampersand works fine.

Going through the documentation I wanted to experiment with a .ampersandrc file, so I've copy/pasted the content of the sample mentioned in the docs, and kept only 2 lines (which I've modified to see if that would have any impact on the template that is generated, in particular the double quotes)

{
    framework: 'hapi',
    quotes: 'double'
};

But running ampersand now results in a crash:

$ ampersand 

undefined:2
    framework: 'hapi',
    ^
SyntaxError: Unexpected token f
    at Object.parse (native)
    at exports.parse (/usr/local/lib/node_modules/ampersand/node_modules/rc/lib/utils.js:13:17)
    at Object.exports.json (/usr/local/lib/node_modules/ampersand/node_modules/rc/lib/utils.js:27:10)
    at module.exports (/usr/local/lib/node_modules/ampersand/node_modules/rc/index.js:30:15)
    at Object.<anonymous> (/usr/local/lib/node_modules/ampersand/bin/ampersand:10:14)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)

Trying to figure out if this was related to the keyword framework I've removed the first line in the dotfile, but now the error complains about

undefined:2
    quotes: 'double'
    ^
SyntaxError: Unexpected token q

So it looks to break on the first character. I thought "Let's just quote the first elements 'framework' and 'quotes'", but it still fails, this time with SyntaxError: Unexpected token '. So it's still having issues with the first character.

Any suggestions on how to create a proper .ampersandrc file?

fyockm commented 9 years ago

Double quote all the things.

{
    "framework" : 'hapi",
    "quotes" : "double"
}

Also, I think you'll need to remove that semicolon at the end.

Somewhere along the way, it seems the parsing of this file required strict json.

e2jk commented 9 years ago

Indeed, using double quotes is the solution.

I first tried with the code you pasted (which still has a single quotes before 'hapi"), and it failed on that first single quote (it would not have worked anyway, as opening with single and closing with double quote is not valid. Just for the sake of testing I replaced the double quote by a single quote, and that still failed the same way):

    "framework" : 'hapi",
                  ^
SyntaxError: Unexpected token '

When replacing all the single quotes by double quotes, the wizard just works fine. I will submit a pull request to replace all the single quotes by double quotes in the documentation.

fyockm commented 9 years ago

Sorry- was responding from my phone. Glad you got it figured out.

Yes, please submit a PR for the documentation. Thanks!