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

'use strict'

const shell = require('shelljs');
const cv = require('compare-version');
const fs = require('fs');

const FLAGFILE = "/tmp/deployment.flag";

const pjson = require('../package.json');
const oldPjson = JSON.parse(shell.exec("git show HEAD~1:package.json").output);

const lastPublishedVersion = shell.exec("npm show "+pjson.name+" version").output.trim();

if (process.env.TRAVIS_BRANCH !== "develop"){
    console.log("--- Not publishing.");
    return;
};

fs.writeFile(FLAGFILE);

console.log("--- Latest published version: ", lastPublishedVersion);
console.log("--- Previous package.json version: ", oldPjson.version);
console.log("--- Current package.json version: ", pjson.version);

let versionBump = (cv(oldPjson.version, pjson.version) !== 0);
console.log("===== Bumped version:", versionBump);

if (!versionBump){
    console.log("--- Publishing...");
    if(cv(pjson.version, lastPublishedVersion) !== 0){
        shell.exec("npm version " + lastPublishedVersion);
    }
    shell.exec("npm version --no-git-tag-version prerelease");
    shell.exec("git status");
    shell.exec("git add package.json");
    shell.exec("git config --global user.name travis");
    shell.exec("git config --global user.email <EMAIL>");
    shell.exec("git commit --amend -C $(git rev-parse --verify HEAD)");
};<commit_msg>Fix beta npm package CD versioning<commit_after>#!/usr/bin/env node

'use strict'

const shell = require('shelljs');
const cv = require('compare-version');
const fs = require('fs');
const path = require('path');

const cwd = path.dirname(require.main.filename);
const project_dir = path.dirname(cwd);

const FLAGFILE = "/tmp/deployment.flag";

const pjson = require(path.join(project_dir, 'package.json'));
const oldPjson = JSON.parse(shell.exec("git show HEAD~1:package.json").output);

const lastPublishedVersion = shell.exec("npm show "+pjson.name+" version").output.trim();

if (process.env.TRAVIS_BRANCH !== "develop"){
    console.log("--- Not publishing.");
    return;
};

fs.writeFile(FLAGFILE);

console.log("--- Latest published version: ", lastPublishedVersion);
console.log("--- Previous package.json version: ", oldPjson.version);
console.log("--- Current package.json version: ", pjson.version);

let versionBump = (cv(oldPjson.version, pjson.version) < 0);
console.log("===== Bumped version:", versionBump);

if (!versionBump){
    console.log("--- Publishing...");
    pjson.version = lastPublishedVersion;
    fs.writeFileSync(path.join(project_dir, 'package.json'), JSON.stringify(pjson, null, 2));
    shell.exec("git add package.json");
    shell.exec("git config --global user.name travis");
    shell.exec("git config --global user.email <EMAIL>");
    shell.exec("git commit --amend -C $(git rev-parse --verify HEAD)");
    shell.exec("npm version --no-git-tag-version prerelease");
    shell.exec("git status");
    shell.exec("git add package.json");
    shell.exec("git commit --amend -C $(git rev-parse --verify HEAD)");
};
{'fraction_non_alphanumeric': 0.18606965174129353, 'fraction_numerical': 0.001990049751243781, 'mean_word_length': 4.395348837209302, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 5, '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': '3474046', 'n_tokens_mistral': 960, 'n_tokens_neox': 928, 'n_words': 225}