Created
August 25, 2016 11:58
-
-
Save ibratoev/0caca1b3b7a122595523f790e2620301 to your computer and use it in GitHub Desktop.
JS script to update typings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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."); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thank you