<commit_before>#!/usr/bin/env node

let execSync = require('child_process').execSync;
let spawnOptions = { stdio: 'pipe' };

let execute = (cmd) => {
  try {
    let output = execSync(cmd, spawnOptions).toString();
    console.log(output);
    return output;
  }
  catch (e) {
    //Doesn't feel write to swallow the exceptions but there doesn't seem
    //to be a built in way to supress exceptions if git add and git push fail
  }
}

const skipMeta = process.argv.includes('--skip-meta');
const force = process.argv.includes('--force');

const defaultBranch = 'master';
const deployBranch = 'gh-pages';
const stage1 = 'deploy-stage-1';
const stage2 = 'deploy-stage-2';

console.log('Getting ready for deployment...hold on!');

execute(`git fetch origin`);

let isBehindUpstream = execute('git log HEAD..origin/master --oneline').length > 0;

if (isBehindUpstream && !force) {
  console.log('Your current HEAD is behind origin/master. Use --force to ignore.')
  return;
}

if (!skipMeta) {
  // generate meta data for posts
  execute(`$(npm bin)/jrp ${__dirname}/_posts`);
  execute(`git add -A . && git commit -m "chore: adds meta data for related posts and videos"`);
}

// perform jekyll build
execute(`jekyll build`);

// cleanup temp branches
execute(`git branch -D ${stage1}`);
execute(`git branch -D ${stage2}`);

// make sure deploy branch is reset to latest version from origin
execute(`git branch -f ${deployBranch} origin/${deployBranch}`);

// prepare stage 1
execute(`git checkout -b ${stage1}`);
execute(`git add -f _site`);
execute(`git commit -m "${stage1}"`);

// prepare stage 2
execute(`git subtree split -P _site -b ${stage2}`);

// get contents from stage 2 and create a commit
execute(`git checkout ${deployBranch}`);
execute(`git checkout ${stage2} .`);
execute(`git add -A`);
execute(`git commit -m "rebuilt site"`);

execute(`git push origin ${deployBranch}`);

execute(`git checkout ${defaultBranch}`);

console.log('Everything should be live at http://blog.thoughtram.io');<commit_msg>feat: give more output while deploying<commit_after>#!/usr/bin/env node

let execSync = require('child_process').execSync;
let spawnOptions = { stdio: 'pipe' };

let execute = (cmd) => {
  try {
    let output = execSync(cmd, spawnOptions).toString();
    console.log(output);
    return output;
  }
  catch (e) {
    //Doesn't feel write to swallow the exceptions but there doesn't seem
    //to be a built in way to supress exceptions if git add and git push fail
  }
}

const skipMeta = process.argv.includes('--skip-meta');
const force = process.argv.includes('--force');

const defaultBranch = 'master';
const deployBranch = 'gh-pages';
const stage1 = 'deploy-stage-1';
const stage2 = 'deploy-stage-2';

console.log('Getting ready for deployment...hold on!');

console.log('Fetching from origin...');
execute(`git fetch origin`);

let isBehindUpstream = execute('git log HEAD..origin/master --oneline').length > 0;

if (isBehindUpstream && !force) {
  console.log('Your current HEAD is behind origin/master. Use --force to ignore.')
  return;
}

if (!skipMeta) {
  // generate meta data for posts
  console.log('Generating meta data for posts (related posts & videos)...');
  execute(`$(npm bin)/jrp ${__dirname}/_posts`);
  execute(`git add -A . && git commit -m "chore: adds meta data for related posts and videos"`);
}

console.log('Performing jekyll build...');
// perform jekyll build
execute(`jekyll build`);

console.log('Generating deploy artifacts...');
// cleanup temp branches
execute(`git branch -D ${stage1}`);
execute(`git branch -D ${stage2}`);

// make sure deploy branch is reset to latest version from origin
execute(`git branch -f ${deployBranch} origin/${deployBranch}`);

// prepare stage 1
execute(`git checkout -b ${stage1}`);
execute(`git add -f _site`);
execute(`git commit -m "${stage1}"`);

// prepare stage 2
execute(`git subtree split -P _site -b ${stage2}`);

// get contents from stage 2 and create a commit
execute(`git checkout ${deployBranch}`);
execute(`git checkout ${stage2} .`);
execute(`git add -A`);
execute(`git commit -m "rebuilt site"`);

console.log('Deploying...');
execute(`git push origin ${deployBranch}`);

execute(`git checkout ${defaultBranch}`);

console.log('Everything should be live at http://blog.thoughtram.io');
{'fraction_non_alphanumeric': 0.15931887100536507, 'fraction_numerical': 0.006531373921156987, 'mean_word_length': 4.300370828182942, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5669244', 'n_tokens_mistral': 1324, 'n_tokens_neox': 1321, 'n_words': 450}