Skip to content

feat(postinstall): force update TypeScript if you use NS 3.0 #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 9, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions postinstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@ var upgrader = require("./tsconfig-upgrader");
var projectDir = hook.findProjectDir();
if (projectDir) {
var tsconfigPath = path.join(projectDir, "tsconfig.json");
var hasModules30 = upgrader.hasModules30(projectDir);
if (fs.existsSync(tsconfigPath)) {
upgrader.migrateTsConfig(tsconfigPath, projectDir);
} else {
createTsconfig(tsconfigPath);
}
if (!upgrader.hasModules30(projectDir)) {

if (!hasModules30) {
createReferenceFile();
}
installTypescript();

installTypescript({force: hasModules30});
}

function createReferenceFile() {
Expand Down Expand Up @@ -60,12 +63,17 @@ function getProjectTypeScriptVersion() {
}
}

function installTypescript() {
var installedTypeScriptVersion = getProjectTypeScriptVersion();
if (installedTypeScriptVersion) {
function installTypescript({force = false} = {}) {
const installedTypeScriptVersion = getProjectTypeScriptVersion();

if (installedTypeScriptVersion && !force) {
console.log("Project already targets TypeScript " + installedTypeScriptVersion);
} else {
require("child_process").exec("npm install --save-dev typescript", { cwd: projectDir }, function (err, stdout, stderr) {
const command = force ? "npm install -D typescript" : "npm update -D typescript";

console.log("Installing TypeScript...");

require("child_process").exec(command, { cwd: projectDir }, function (err, stdout, stderr) {
if (err) {
console.warn("npm: " + err.toString());
}
Expand Down