Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Aug 28 21:10
    KillyMXI commented #964
  • Aug 28 19:39
    jonschlinkert commented #964
  • Aug 28 19:00
    KillyMXI commented #964
  • Aug 28 18:58
    KillyMXI commented #964
  • Aug 28 18:25
    jonschlinkert commented #964
  • Aug 28 18:22
    jonschlinkert commented #964
  • Aug 28 18:22
    jonschlinkert reopened #964
  • Aug 28 18:20
    jonschlinkert closed #964
  • Aug 28 17:38
    KillyMXI edited #964
  • Aug 28 17:37
    assemblebot commented #964
  • Aug 28 17:37
    KillyMXI opened #964
  • Aug 13 17:16
    rscarpim closed #963
  • Aug 13 17:16
    rscarpim commented #963
  • Aug 13 17:10
    jonschlinkert commented #963
  • Aug 13 17:01
    assemblebot commented #963
  • Aug 13 17:01
    rscarpim opened #963
  • Aug 12 17:19
    doowb closed #962
  • Aug 12 17:19
    doowb commented #962
  • Aug 12 16:58
    rscarpim commented #962
  • Aug 12 16:45
    jonschlinkert commented #961
Ernesto Navarro
@enavarrocu
method*
gulp.task('assemble', ['config-assemble'], function (done) {
    log('Assemble');
    return asm.toStream('pages')
        .on('error', console.log)
        .pipe(asm.renderFile())
        .on('error', console.log)
        .pipe($.extname())
        .pipe(asm.dest(config.build))
        .pipe(browserSync.stream())
        ;
});
Brian Woodward
@doowb
you don't need the done in the assemble task, just the config-assemble task... also log out a message before and after loading templates inside the config-assemble task
Ernesto Navarro
@enavarrocu
you are thinking maybe that is failing not completing the config-assemble task?
Brian Woodward
@doowb
maybe... these are the steps I would be taking if I had the code in front of me
Ernesto Navarro
@enavarrocu
[23:25:10] Starting 'config-assemble'...
[23:25:10] Before templates
[23:25:10] After templates
[23:25:10] Finished 'config-assemble' after 130 ms
then after don't run assemble
this give you more info
[23:25:10] HBS file changed:/src/html/partials/menu.hbs
[Browsersync] Reloading Browsers...
[23:25:10] Starting 'config-assemble'...
[23:25:10] Before templates
[23:25:10] After templates
[23:25:10] Finished 'config-assemble' after 130 ms
is doing the Reloading before running the assemble
that shouldn't happen
Brian Woodward
@doowb
That's because of the .on('change', ...) listener after the .watch
Ernesto Navarro
@enavarrocu
of course, but with the stream that I added to the assemble the I don't need that anymore
Indeed I don't need it
Brian Woodward
@doowb
does it change anything if you remove the listener?
Ernesto Navarro
@enavarrocu
you mean the .on('change' ...?
I remove the browserSync.reload() only no the entire listener. I will try
no, the same
Brian Woodward
@doowb
I'm not sure then, it seems like a gulp.watch issue since the config-assemble task is finishing, but gulp isn't even starting the assemble task
Ernesto Navarro
@enavarrocu
yeah, something like that can be the problem, I'm always having weird errors :(
Anyway thank you very much for the help. You really help me a lot
Brian Woodward
@doowb
no problem
hope you figure it out
Ernesto Navarro
@enavarrocu
@doowb Fixed!!!!!!
gulp.task('assemble', ['config-assemble'], function () {
    log('Assemble');
    return asm.toStream('pages')
        .pipe($.plumber({errorHandler: sassErrorHandler})) // .on('error', console.log)
        .pipe(asm.renderFile())
        .pipe($.plumber({errorHandler: sassErrorHandler})) // .on('error', console.log)
        .pipe($.extname())
        .pipe(asm.dest(config.build))
        .pipe(browserSync.stream())
        ;
});
of course I have to refactor but that solve the issue
Brian Woodward
@doowb
good idea... it probably has something to do with how gulp plumber messes with streams to handle errors
boneyfantaseas
@boneyfantaseas

hey there,
I'm lost on this one: I tried to cache my html files in order to stop assemble parsing each and every existing hbs to html when I edited a single file. Can anybody point me in the right direction? My setup here is: gulp (3!), gulp-cached and assemble

assemble task

app.task('parse', () => {
    const bss = bs.get('bsServer');
    return app.toStream('pages')
        .pipe(cache(config.cache.html))
        .pipe(plumberNotifier())
        .pipe(extname())
        .pipe(app.renderFile())
        . ...

gulp.task('html:parse', (cb) => {
    app.build('parse', (err) => {
        if (err) throw err;
        cb();
    });
});

gulp.task('html:init', (cb) => {
    app.build('init', (err) => {
        if (err) throw err;
        cb();
    });
});

gulp.task('html:go', cb => runSequence(['html:init', 'html:parse'], cb));

First run is fine as I need to generate everything at least once but then...
watch.js

function changeHandler(cacheName, event) {
        if (event.type === 'deleted' && cache.caches[cacheName][event.path] !== undefined && cache.caches[cacheName] !== undefined) {
            delete cache.caches[cacheName][event.path];
            log('Deleted from cache:', event.path);
        }
    }
gulp.watch(
        "src/html/**/*.hbs", { interval: 500 }, ['html:go']);
    html.on('change', changeHandler.bind(this, config.cache.html));

gulp-cached obviously empties the stream contents so I wonder how to cope with that.

Brian Woodward
@doowb
I'm not familiar with gulp-cached but are you attempting to remove files from the pages collection if the file has been deleted? Or are you attempting to not rebuild a file unless it's been changed?
cc: @boneyfantaseas
boneyfantaseas
@boneyfantaseas
@doowb I'm trying to not rebuild it unless it changed - and I'm not sure about how to alter toStream(pages) beforehand.
Brian Woodward
@doowb
@boneyfantaseas I was on a call...
There isn’t a general way this is done with assemble because it can be specific to your needs
the main flow is this:
  • templates loaded onto a collection (pages)
  • the collection is streamed into a plugin pipeline to render each template
  • files are writen to the filesystem
The simpiliest way to achieve not re-rendering pages (that I can think of is this)
  • customize how the templates are loaded (e.g. keep a cache of what’s been rendered and only re-load changed files)
  • use gulp-cached? to remove the pages from the collection for re-rendering
One thing to point out is if you’re using layouts or partials that change, you’d probably want to re-render all of the pages
also, you can access pages directly through the pages collection: app.pages or app.views.pages
boneyfantaseas
@boneyfantaseas
Thanks for your quick reply! I understand that changing layouts and partials requires re-rendering of all pages. as far as I understand gulp-cached does keep a cache of unchanged file and what is does is not passing those files down the pipeline. This results in an error in app.renderfile() because there is no file in the pipeline.
Thinking about adapting app.pages to match the changed file I needed access to the underlying process, something to pinpoint the right object type for app.pages and such. Is there something like a debug plugin you can recommend?
Brian Woodward
@doowb
@boneyfantaseas what error are you getting? If no files come through, it shouldn't even touch app.renderfile()
Also, how are you re-loading the templates onto the collection, I don't see that part in your code above. If you don't reload the files, then the file.path will be the same as it was after the first time through (which I assume would be something.html instead of something.hbs) which would cause gulp-cached to miss because it uses file.path
boneyfantaseas
@boneyfantaseas

@doowb hm, actually you bring me to a point where I wonder about that caching mechanism, too :worried:
Actually the gulp watch will notice the change in the hbs file and call "html:go" which then calls html:init and html:parse as shown above. The line .pipe(cache(config.cache.html))will create and also compare against the cache. (cache is the gulp-cached instance, config.cache.html is just a string holding the cache name "html"). I run html:go once when I start gulp and then on every .hbs file change.
According to the description of gulp-cached (https://www.npmjs.com/package/gulp-cached#usage) it won't pass files downstream that are in the cache and unchanged. It also states

Please note that this will not work with plugins that operate on sets of files (concat for example).

Might that be the problem?
I can't tell what gulp-cached really does as I don't fully understand the gulp pipeline workflow. So maybe that might be a topic for the gulp-cached owners to answer.

stevefuentes
@stevefuentes
Hey, wondering if anyone who may be a bit better versed in assemble is around for a few quick implementation questions. Really having trouble finding how to implement lists, pagination in the docs. Thanks!
John O'Donnell
@criticalmash
Hi @stevefuentes , I have a sample project I developed while learning how to use pagination (https://github.com/criticalmash/asm-pager-test). I used this as a testbed for learning and then a reference when building out paginated pages for a recent project. If you follow the README and the assemblefile.js you should be off to a great start. Good Luck!
stevefuentes
@stevefuentes
@criticalmash thanks, ill take a look
Jon Bloomer
@freaksauce

can anyone help me I am trying to access a variable I pass in at runtime in an npm script:

"build": "assemble --option=production:true"

which I then want to use in a conditional:

{{#isnt production}}hide this in prod{{/production}}

I've tried using just --production & --production=true and nothing seems to work?

John O'Donnell
@criticalmash
Hi @freaksauce you need to use a library like minimist to parse the command then use Assemble's app.data() function to pass that value to your templates.
const argv = minimist(process.argv.slice(2));
const environment = argv.production ||false;
Something like this to get your value
Then set a data attribute like so
app.data({production: environment});
John O'Donnell
@criticalmash
One-more-thing: you should also look into using dotenv . That library can load variables from either the *nix system environment or a .env file. A great solution if you're building a 12-factor app.
Jon Bloomer
@freaksauce
thank you @criticalmash I will look into both of your suggestions 👍