Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Stephen Kao
    @stephenkao
    That works!
    Lifesaver!!! :tada: :tada: :tada:
    Brian Woodward
    @doowb
    np
    @stephenkao btw… here’s a neat tip… we support setting macros so you can alias the longer version as a shorter version...
    $ gen —macro foo @my-org/generate-foo
    Brian Woodward
    @doowb
    then $ gen foo works as if you were doing $ gen @my-org/generate-foo
    Stephen Kao
    @stephenkao
    Ah, that's very good to know!
    Jon Schlinkert
    @jonschlinkert
    @stephenkao sorry I thought I setup notifs on here, apparently not! Looks like you got it worked out, but let us know if something else comes up! (thanks for the kind words about verb/generate!)
    Stephen Kao
    @stephenkao
    Ah, sorry about the late response, but thank you both very much! :)
    Jon Schlinkert
    @jonschlinkert
    no worries, happy to help!
    David Fox-Powell
    @dtothefp
    hey hipsters...is there something magical about app.cache.answers, i.e. if i use <%= ask('cool.stuff') %> and app.cache.answers.cool.stuff is defined already, will it not ask again for it?
    @stephenkao seems to think that somehow in his current app all answers are automatically appended to app.cache.answers
    also, a little confused about the .data-store, it seems like if I set {save: true} as an option to my questions, and the value is previously populated in the data-store, it will skip the question entirely, rather than setting the stored value as a default option
    Brian Woodward
    @doowb
    base-questions does store answers on app.cache.answers and uses the values stored on that object as either defaults or answers when asking the questions
    {save: true} will save the answers to the data-store like you said… this should be one specified for the current project that you’re working in. To force the question to be asked event when there is a value already set, use {force: true} for that question
    Jon Schlinkert
    @jonschlinkert
    @dtothefp you're not the only one to say that save: true is confusing. We're going to change those settings to make them more intuitive. that's high on the priority list
    David Fox-Powell
    @dtothefp
    @doowb I'm assuming generate is using base-questions under the hood cause I can do stuff like app.questions.set, but it doesn't seem to be storing values on app.cache.answers? is there something I have to do to enable this?
    David Fox-Powell
    @dtothefp
    so if I do this
    import path from 'path'
    import isValid from 'is-valid-app'
    import lodashEngine from 'engine-lodash'
    import defaults from 'generate-defaults'
    
    export default function(app) {
      if (!isValid(app, 'generate-slo-mo')) return
    
      app.use(defaults)
      app.engine('*', lodashEngine)
      app.questions.clearQuestions();
      app.questions.clearAnswers();
    
      app.task('default', () => {
        app.questions.set('¯\_(ツ)_/¯.why', 'why does\'nt this work')
    
        const dest = 'dist'
        const src = path.join('src', 'index.html')
    
        app.ask('¯\_(ツ)_/¯', { save: true }, function(err, answers) {
          app.src(src, {cwd: __dirname})
            .pipe(app.renderFile('*'))
            .pipe(app.conflicts(app.cwd))
            .pipe(app.dest(dest))
            .on('end', err => {
              console.log(app.cache.answers) // {}
            });
        })
      })
    }
    app.cache.answers is an empty object?
    even though answers passed in the callback is defined
    { '¯_(ツ)_/¯': { why: 'dunno' } }
    Brian Woodward
    @doowb
    @dtothefp base-questions stores the answers on app.cache.answers after the question is asked. I copied your example and it works for me. I changed the imports to var foo = require(‘…’) and changed export default to module.exports = since I’m not sure how you’re doing the transpiling step.
    Which version of generate are you using?
    It could be that an older version has an older base-questions or that something is happening during the transpiling… also, you should be passing a callback to the default task and calling it after the console.log to indicate that the task has finished.
    David Fox-Powell
    @dtothefp
    @doowb it might be that I'm testing this locally in an npm script without installing generate globally. maybe that's messing something up?
    not sure the best way to test generator functionality locally?
    Jon Schlinkert
    @jonschlinkert
    @dtothefp you shouldn't need to install it globally. are you trying to get "cached" answers or persisted answers?
    David Fox-Powell
    @dtothefp
    I have a directory structure like this
    ./packages
    ├── generator-slo-mo
    │   ├── dist
    │   │   └── index.html
    │   ├── generator.js
    │   ├── package.json
    │   └── src
    │       ├── generator.js
    │       └── index.html
    └── slo-mo
        ├── bin
        │   └── cli.js
        ├── dist
        │   ├── github.js
        │   ├── slack.js
        │   ├── slo-mo.js
        │   ├── speedcurve.js
        │   └── task.js
        ├── package.json
        ├── src
        │   ├── github.js
        │   ├── slack.js
        │   ├── slo-mo.js
        │   ├── speedcurve.js
        │   └── task.js
        └── test
            └── sample-spec.js
    where generator-slo-mo/generator.js is my compiled generator from src/generator.js
    and I run generate in an npm script in package.json
    it all works, I'm just not seeing those answers appended on the cache
    @jonschlinkert I'm not sure the difference between "cached answers" and "persisted answers"
    I was under the impression that answers would be added to app.cache.answers after the ask
    @doowb I'm on "version": "0.9.8"
    I can make a small example and push it up to github
    David Fox-Powell
    @dtothefp
    @doowb @jonschlinkert crisis averted, bumping to 0.12.1 did the trick, not sure why I had an older version
    Brian Woodward
    @doowb
    :+1:
    I thought it might be a version issue
    Jon Schlinkert
    @jonschlinkert
    :+1:
    by cached I meant "in-memory" and by persisted I meant stored on disk and available across sessions
    David Fox-Powell
    @dtothefp
    cool, thanks for the help
    just out of curiosity why if you have a default task does it look like [14:13:48] ✔ running tasks: [ 'default:default' ]
    with the doubled up default?
    Jon Schlinkert
    @jonschlinkert
    depends on what you're running. The left side of default:default is the generator name, the right side is the task name
    so in that case it's coincidental that you're running the default task on the default generator (which is the local generator.js if you happen to have one)
    David Fox-Powell
    @dtothefp
    @jonschlinkert is there a way to to rename the local generator? i'm assuming if my generator was installed globally it would have a name other than default
    Jon Schlinkert
    @jonschlinkert
    yeah, if it's installed globally it will use the generator's "alias" which is the full name of the generator with generate- stripped off
    but you can also namespace generators locally by making them sub-generators. Example
    module.exports = function(app) {
      this.task('default', function(cb) {
        console.log(app.namespace, 'task >', this.name);
        cb();
      });
    
      // sub-generator "foo"
      this.generator('foo', function(foo) {
        this.task('default', function(cb) {
          console.log(foo.namespace, 'task >', this.name);
    
          // run the `default` task on `app`
          app.build('default', cb);
        });
    
        // sub-generator "foo.bar"
        this.generator('bar', function(bar) {
          this.task('default', function(cb) {
            console.log(bar.namespace, 'task >', this.name);
    
            // run the `default` task on `foo`
            foo.build('default', cb);
          });
        });
      });
    };
    the awesome thing about sub-generators is that you can require in other generators, like how you organize your tasks sometimes into different files
    David Fox-Powell
    @dtothefp
    cool, I'll have to try this out