Jigsaw: Changing the Destination Directory issue

Created on 3 Jun 2018  路  9Comments  路  Source: tighten/jigsaw

Hello
I want to build the pages one level up of the root project. I have added the build key in the config file as shown on the documentation.
'build' => [ 'destination' => '../public_html', ],

But the pages are built in the root directory of the project what ever path i put in the config array.
Thanks for your help
Mo

Most helpful comment

@himan72 Setting destination in config.php to a directory above Jigsaw's root _should_ work, but was broken in a recent release with an overzealous path sanitizer. Providing the full system path (as @hellocosmin just pointed out) will work, and I'm going to restore the documented behavior today.

One important thing to be aware of: be _very careful_ when setting destination paths above Jigsaw's root, because upon build, that directory is immediately deleted _without warning_. I am going to add a warning when the build command is run with a destination outside of Jigsaw's root, requiring the user to confirm the destination, so people don't accidentally remove a directory due to a bad path name.

All 9 comments

You could use the event bus to do it in PHP, or a Node script to move that folder anywhere on your disk.

PHP

For Jigsaw events, see docs in #189 - afterBuild is what you need.

NodeJS

This is easily achievable with fs-extra in Node.

  1. Install it: npm install fs-extra --save-dev

  2. require() it at the top of tasks/build.js:

    // tasks/build.js
    let fs = require('fs-extra');
    
  3. Use it in the build command callback:

    jigsaw: new AfterWebpack(() => {
        command.get(bin.path() + ' build ' + env, (error, stdout, stderr) => {
            console.log(error ? stderr : stdout);
    
            // move the build outside the project folder
            fs.move('build_'+env, '../public_html', { overwrite: true }, (err) => {
                if (err) return console.error(err);
    
                console.log('I like to move it move it!');
            })
    
            if (browserSyncInstance) {
                browserSyncInstance.reload();
            }
        });
    }),
    

@hellocosmin Thanks a lot very helpful. So the build key is no more working ?

It is working, just not like that with ../. I think you might be able to provide a full path there (not tested, never needed it) - maybe @damiani can confirm.

@himan72 Setting destination in config.php to a directory above Jigsaw's root _should_ work, but was broken in a recent release with an overzealous path sanitizer. Providing the full system path (as @hellocosmin just pointed out) will work, and I'm going to restore the documented behavior today.

One important thing to be aware of: be _very careful_ when setting destination paths above Jigsaw's root, because upon build, that directory is immediately deleted _without warning_. I am going to add a warning when the build command is run with a destination outside of Jigsaw's root, requiring the user to confirm the destination, so people don't accidentally remove a directory due to a bad path name.

@damiani @hellocosmin Got it Thanks a lot

After a discussion with @hellocosmin I think it would be prudent to add a console warning whenever the default destination path has been modified (the user could disable it once they're satisfied the path is correct). At the moment there's the potential for users to unwittingly delete a directory inside their project, or their entire project, if they get the destination path wrong. Will have to investigate how this would work with watching files.

Thanks Keith :)

Context, for others

I got the destination wrong when trying to set it by returning from a function instead of just using a string. While Webpack was watching files. It went into a recursive death roll until it finally died and exited the process. Lost entire project folder contents - hadn't commited anything yet. Fun times.

Until further notice, be careful with output paths :)

@damiani I was wondering if this functionality was ever restored. I am running into this same issue that I cannot build outside of my jigsaw root (where config.php is located).

Setting destination in config.php to a directory above Jigsaw's root should work, but was broken in a recent release with an overzealous path sanitizer. Providing the full system path will work, and I'm going to restore the documented behavior today.

@itguy614 Yes it was

Was this page helpful?
0 / 5 - 0 ratings

Related issues

michielgerritsen picture michielgerritsen  路  7Comments

knorthfield picture knorthfield  路  3Comments

royvanv picture royvanv  路  10Comments

cossssmin picture cossssmin  路  12Comments

GenieTim picture GenieTim  路  4Comments