Skip to content

Commit

Permalink
Add a script to check/update the latest and next tags. (#4899)
Browse files Browse the repository at this point in the history
This just prints out the commands that should be run right now, so they can be verified by hand.
  • Loading branch information
jasongrout authored and blink1073 committed Jul 15, 2018
1 parent 56de6c0 commit 485ad61
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
82 changes: 82 additions & 0 deletions buildutils/src/update-dist-tag.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*-----------------------------------------------------------------------------
| Copyright (c) Jupyter Development Team.
| Distributed under the terms of the Modified BSD License.
|----------------------------------------------------------------------------*/

import * as path from 'path';
import * as childProcess from 'child_process';
import * as utils from './utils';

// Handle the packages
utils.getLernaPaths().forEach(pkgPath => {
handlePackage(pkgPath);
});
handlePackage(path.resolve('.'));

/**
* Handle an individual package on the path - update the dependency.
*/
function handlePackage(packagePath: string): void {
let cmd: string;

// Read in the package.json.
packagePath = path.join(packagePath, 'package.json');
let data: any;
try {
data = utils.readJSONFile(packagePath);
} catch (e) {
console.log('Skipping package ' + packagePath);
return;
}

if (data.private) {
return;
}

const pkg = data.name;

cmd = `npm view ${pkg} versions --json`;
const versions: string[] = JSON.parse(
String(childProcess.execSync(cmd)).trim()
);

// Find latest stable
versions.reverse();
let prerelease = versions.find(v => !!v.match(/-\d$/));
let stable = versions.find(v => !v.match(/-\d$/));

// Make sure the prerelease we found is *after* the stable release
if (
prerelease &&
stable &&
versions.indexOf(prerelease) > versions.indexOf(stable)
) {
prerelease = undefined;
}

cmd = `npm dist-tag list ${pkg}`;
let tags = String(childProcess.execSync(cmd))
.trim()
.split('\n');

console.log();
console.log(pkg, stable, prerelease, tags);

let stableCmd: string;
let prereleaseCmd: string;

if (stable) {
stableCmd = `npm dist-tag add ${pkg}@${stable} latest`;
} else {
stableCmd = `npm dist-tag rm ${pkg} latest`;
}

if (prerelease) {
prereleaseCmd = `npm dist-tag add ${pkg}@${prerelease} next`;
} else {
prereleaseCmd = `npm dist-tag rm ${pkg} next`;
}

console.log(stableCmd);
console.log(prereleaseCmd);
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"test:services": "cd packages/services && jlpm test && cd examples/node && python main.py",
"prettier": "prettier --write '**/*{.ts,.tsx,.js,.jsx,.css,.json,.md}'",
"update:dependency": "node buildutils/lib/update-dependency.js",
"update:dist-tag": "node buildutils/lib/update-dist-tag.js",
"watch": "run-p watch:dev watch:themes",
"watch:dev": "python scripts/watch_dev.py",
"watch:main": "jlpm run watch",
Expand Down

0 comments on commit 485ad61

Please sign in to comment.