New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing the Destination Directory issue #222

Closed
himan72 opened this Issue Jun 3, 2018 · 7 comments

Comments

Projects
None yet
3 participants
@himan72
Copy link

himan72 commented Jun 3, 2018

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

@hellocosmin

This comment has been minimized.

Copy link

hellocosmin commented Jun 3, 2018

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();
            }
        });
    }),
@himan72

This comment has been minimized.

Copy link

himan72 commented Jun 3, 2018

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

@hellocosmin

This comment has been minimized.

Copy link

hellocosmin commented Jun 3, 2018

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.

@damiani

This comment has been minimized.

Copy link
Contributor

damiani commented Jun 3, 2018

@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.

@himan72

This comment has been minimized.

Copy link

himan72 commented Jun 3, 2018

@damiani @hellocosmin Got it Thanks a lot

@himan72 himan72 closed this Jun 3, 2018

@damiani damiani reopened this Jun 5, 2018

@damiani

This comment has been minimized.

Copy link
Contributor

damiani commented Jun 5, 2018

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.

@hellocosmin

This comment has been minimized.

Copy link

hellocosmin commented Jun 5, 2018

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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment