Skip to content

Instantly share code, notes, and snippets.

@stisa
Last active October 2, 2015 20:10
Show Gist options
  • Save stisa/5382a2f89a80633c2e21 to your computer and use it in GitHub Desktop.
Save stisa/5382a2f89a80633c2e21 to your computer and use it in GitHub Desktop.

To use this hook, add the following to project.flow:

build : {
  dependencies : {
    luxe : '*',
  },
  post : {    
    priority : 1,
    name : 'move-to-gh-pages',
    desc : 'copy bin/web to gh-pages',
    script : './hooks/post.js',
  }
}

Make a script, post.js, inside a folder named hooks inside your project folder.

    var fs = require('fs-extra');
    var path = require('path');
    var done = false;
    exports.hook = function(){
      // generic json reading function
      function read_json (file_path) {
          var temp;
          //console.log(path.resolve(file_path))
          temp = fs.readFileSync(path.resolve(file_path));
          return JSON.parse(temp);
      };
      function done() {
        done = true;
      }
      //read our config file
      var config_file = "./hooks/config.json";
      var config = read_json(config_file)
      var dirs = config.dirs
      console.log("- Source dir: "+ dirs.bin+", Target dir: "+ dirs.gh_pages)
      fs.copy(dirs.bin,dirs.gh_pages, function copy_site(err){
      	if (err) throw err //failed copy
      	console.log("- Project copied")
        console.log("- Copying git_files...")
        fs.readdir(dirs.git_files,function copy_git_files(err,files){
          if (err) throw err
          for (var i = 0; i<files.length;i++) {
            var file = files[i]
            console.log("- Copied "+file)
            fs.copy(path.join(dirs.git_files,file),path.join(dirs.gh_pages,file), function copy_file(err){
          		if (err) throw err
          	})
          }
          done()
        })
      })
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment