#!env node
"use strict";
var gitSemverTags = require('git-semver-tags');
var shelljs = require('shelljs');
var path = require('path');
var fs = require('fs');

var CORE = `core`;
var CORE_PKG = `@uirouter/${CORE}`;
var CORE_DIR = path.join(__dirname, "..", "..", CORE);
var SHOWCHANGELOG_SCRIPT = path.join(CORE_DIR, "scripts", "show_changelog.js");

var currentPackage = require('../package.json');
if (!currentPackage.dependencies || !currentPackage.dependencies[CORE_PKG]) {
  console.error(stringify(currentPackage.dependencies));
  throw new Error("No dependency on " + CORE_PKG + " found in package.json.")
}

if (!fs.existsSync(CORE_DIR)) {
  throw new Error(CORE_PKG + " not found at " + path.resolve(CORE_DIR));
}

if (!fs.existsSync(SHOWCHANGELOG_SCRIPT)) {
  throw new Error("show_changelog.js not found at " + path.resolve(SHOWCHANGELOG_SCRIPT));
}

shelljs.config.silent = true;
gitSemverTags(function (err, val) {
  var fromTag;
  if (require.main === module && process.argv[2]) {
    fromTag = process.argv[2];
  } else {
    var prevRaw = shelljs.exec('git show ' + val[0] + ':package.json', {silent:true}).stdout;
    var prevPackage;
    try {
      prevPackage = JSON.parse(prevRaw);
    } catch (error) {
      console.error("Unable to parse previous package.json in ${val[0]}");
      console.error(prevRaw);
      throw error;
    }

    if (!prevPackage.dependencies) {
      console.error(stringify(prevPackage));
      throw new Error(`previous package.json in ${val[0]} has no "dependencies" key.`);
    } else if (!prevPackage.dependencies[CORE_PKG]) {
      console.error(stringify(prevPackage.dependencies));
      throw new Error(`previous package.json in ${val[0]} has no "dependencies['${CORE_PKG}']" key.`);
    }

    fromTag = prevPackage.dependencies[CORE_PKG].replace(/[=~^]/, "");
  }

  var toTag = require("../package.json").dependencies[CORE_PKG].replace(/[=~^]/g, "");
  shelljs.pushd(CORE_DIR);
  // console.log("node " + SHOWCHANGELOG_SCRIPT + " " + fromTag + " " + toTag)
  shelljs.config.silent = false;
  shelljs.exec("node " + SHOWCHANGELOG_SCRIPT + " " + fromTag + " " + toTag)
});


function stringify(object) {
  return JSON.stringify(object, null, 2);
}
@@ -18,16 +18,17 @@
 trict%22;%0A
+%0A
 var gitS
@@ -162,20 +162,34 @@
 var CORE
- = %60
+_PKG = %60@uirouter/
 core%60;%0Av
@@ -187,24 +187,28 @@
 /core%60;%0Avar 
+ALT_
 CORE_PKG = %60
@@ -211,25 +211,22 @@
  = %60
-@
 ui
+-
 router
-/$%7BCORE%7D
+-core
 %60;%0Av
@@ -272,20 +272,22 @@
 , %22..%22, 
-CORE
+'core'
 );%0Avar S
@@ -447,16 +447,17 @@
 cies %7C%7C 
+(
 !current
@@ -482,24 +482,58 @@
 es%5BCORE_PKG%5D
+ && !currentPackage%5BALT_CORE_PKG%5D)
 ) %7B%0A  consol
@@ -1622,16 +1622,59 @@
 ORE_PKG%5D
+ && !prevPackage.dependencies%5BALT_CORE_PKG%5D
 ) %7B%0A    
@@ -1841,25 +1841,67 @@
  %7D%0A%0A    
-fromTag =
+var prevDep = prevPackage.dependencies%5BCORE_PKG%5D %7C%7C
  prevPac
@@ -1910,32 +1910,36 @@
 ge.dependencies%5B
+ALT_
 CORE_PKG%5D.replac
@@ -1923,32 +1923,55 @@
 es%5BALT_CORE_PKG%5D
+;%0A    fromTag = prevDep
 .replace(/%5B=~%5E%5D/
@@ -1988,16 +1988,14 @@
 %0A%0A  
-var toTa
+let pk
 g = 
@@ -2020,39 +2020,123 @@
 e.json%22)
-.dependencies%5BCORE_PKG%5D
+;%0A  let currentDep = pkg.dependencies%5BCORE_PKG%5D %7C%7C pkg.dependencies%5BALT_CORE_PKG%5D;%0A  var toTag = currentDep
 .replace
@@ -2151,16 +2151,17 @@
 g, %22%22);%0A
+%0A
   shellj

Fix changelog generator for core to work with either npm package