Skip to content

Instantly share code, notes, and snippets.

@ibratoev
Created August 25, 2016 11:58
Show Gist options
  • Save ibratoev/0caca1b3b7a122595523f790e2620301 to your computer and use it in GitHub Desktop.
Save ibratoev/0caca1b3b7a122595523f790e2620301 to your computer and use it in GitHub Desktop.
JS script to update typings
#!/usr/bin/env node
// Script to update typings to their latest versions.
// Note that it should be executed in the folder where typings.json is.
const { exec, execSync } = require('child_process');
const path = require('path');
const typings = require(path.join(process.cwd(), 'typings.json'));
exec('typings ls', (error, _, stderr) => {
if (error) {
console.error(`exec error: ${error}`);
exit(1);
}
if (stderr) {
lines = stderr.match(/[^\r\n]+/g);
lines.forEach(line => {
const re = /registry:(\S*)\/(\S*)(#|$)/;
const m = re.exec(line);
if (m !== null) {
const [, source, name] = m;
const isGlobal = typings.globalDependencies && typings.globalDependencies[name];
const isLocal = typings.dependencies && typings.dependencies[name];
if (isGlobal === isLocal) {
console.error(`error searching for typings: ${name}`);
exit(1);
}
console.log(`Updating typings for ${name}`);
execSync(`typings i ${source}~${name} -S ${isGlobal ? '-G' : ''}`);
}
});
}
else {
console.log("Typings are up to date.");
}
});
@bitabs
Copy link

bitabs commented Feb 5, 2017

Where should this file be called from?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment