From 5fdaaca70045da33e86bf893e18d5fad951f191e Mon Sep 17 00:00:00 2001 From: Olavi Haapala Date: Mon, 16 Sep 2019 19:52:36 +0300 Subject: [PATCH 1/9] Add dummy WIP that would create commits --- src/commands/check.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/commands/check.js b/src/commands/check.js index e72c0bd..2d12c65 100644 --- a/src/commands/check.js +++ b/src/commands/check.js @@ -18,6 +18,7 @@ import askUser from '../askUser'; import {toSentence} from '../stringUtils'; import {askIgnoreFields} from './ignore'; import Config from '../Config'; +import { execSync } from 'child_process'; const pkg = require('../../package.json'); @@ -154,6 +155,7 @@ export const handler = catchAsyncError(async opts => { `from ${from} to ${colorizeDiff(from, to)}?`, choices: _.compact([ {name: 'Yes', value: true}, + {name: 'Yes and create a separate commit', value: 'commit'}, {name: 'No', value: false}, // Don't show this option if we couldn't find module's changelog url (changelogUrl !== null) && @@ -218,6 +220,31 @@ export const handler = catchAsyncError(async opts => { isUpdateFinished = true; break; + case 'commit': + updatedModules.push(outdatedModule); + setModuleVersion(name, to, packageJson); + delete config.ignore[name]; + + // Showing the list of modules that are going to be updated + console.log( + `\n${strong('These packages will be updated:')}\n\n` + + createUpdatedModulesTable(updatedModules) + + '\n' + ); + + const {indent} = detectIndent(packageSource); + writeFileSync( + packageFile, + // Adding newline to the end of file + `${JSON.stringify(packageJson, null, indent)}\n` + ); + console.log('NOW WE SHOULD COMMIT!'); + + // execSync('npm i',{stdio: 'inherit'}) + execSync('git add package.json',{stdio: 'inherit'}) + execSync(`git commit -m "Upgraded ${outdatedModule}"`,{stdio: 'inherit'}) + break; + case true: updatedModules.push(outdatedModule); setModuleVersion(name, to, packageJson); From 608022ccdbe0b1fc0bdebd274adac1f429ec449b Mon Sep 17 00:00:00 2001 From: Olavi Haapala Date: Mon, 16 Sep 2019 19:56:58 +0300 Subject: [PATCH 2/9] Add better commit message --- src/commands/check.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/check.js b/src/commands/check.js index 2d12c65..4ee053e 100644 --- a/src/commands/check.js +++ b/src/commands/check.js @@ -242,7 +242,7 @@ export const handler = catchAsyncError(async opts => { // execSync('npm i',{stdio: 'inherit'}) execSync('git add package.json',{stdio: 'inherit'}) - execSync(`git commit -m "Upgraded ${outdatedModule}"`,{stdio: 'inherit'}) + execSync(`git commit -m "Upgraded ${name} from ${from} to ${to}"`,{stdio: 'inherit'}) break; case true: From 20d34de220298ab9eb7cea02aaad44b5a0a98dcc Mon Sep 17 00:00:00 2001 From: Olavi Haapala Date: Mon, 16 Sep 2019 19:57:20 +0300 Subject: [PATCH 3/9] Make commit the default --- src/commands/check.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/check.js b/src/commands/check.js index 4ee053e..062262d 100644 --- a/src/commands/check.js +++ b/src/commands/check.js @@ -154,8 +154,8 @@ export const handler = catchAsyncError(async opts => { message: `${changelogUrl === undefined ? 'U' : 'So, u'}pdate "${name}" in package.json ` + `from ${from} to ${colorizeDiff(from, to)}?`, choices: _.compact([ - {name: 'Yes', value: true}, {name: 'Yes and create a separate commit', value: 'commit'}, + {name: 'Yes', value: true}, {name: 'No', value: false}, // Don't show this option if we couldn't find module's changelog url (changelogUrl !== null) && From 5f8449578e738627a62b945d44fe055e8b09b7a8 Mon Sep 17 00:00:00 2001 From: Olavi Haapala Date: Mon, 16 Sep 2019 20:18:48 +0300 Subject: [PATCH 4/9] Run yarn and inlcude lock file TODO: Detect if yarn or npm used, also detect if lock file exists and should be included --- src/commands/check.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/commands/check.js b/src/commands/check.js index 062262d..1507dbc 100644 --- a/src/commands/check.js +++ b/src/commands/check.js @@ -238,10 +238,9 @@ export const handler = catchAsyncError(async opts => { // Adding newline to the end of file `${JSON.stringify(packageJson, null, indent)}\n` ); - console.log('NOW WE SHOULD COMMIT!'); - - // execSync('npm i',{stdio: 'inherit'}) - execSync('git add package.json',{stdio: 'inherit'}) + // Assume yarn for now + execSync('yarn',{stdio: 'inherit'}) + execSync('git add package.json yarn.lock',{stdio: 'inherit'}) execSync(`git commit -m "Upgraded ${name} from ${from} to ${to}"`,{stdio: 'inherit'}) break; From 5897e9f68c5d6d4d1d4f3afccdd0ba7579e82f95 Mon Sep 17 00:00:00 2001 From: Olavi Haapala Date: Mon, 16 Sep 2019 20:24:32 +0300 Subject: [PATCH 5/9] Change commit message from upgraded to upgrade --- src/commands/check.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/check.js b/src/commands/check.js index 1507dbc..e99b9c7 100644 --- a/src/commands/check.js +++ b/src/commands/check.js @@ -241,7 +241,7 @@ export const handler = catchAsyncError(async opts => { // Assume yarn for now execSync('yarn',{stdio: 'inherit'}) execSync('git add package.json yarn.lock',{stdio: 'inherit'}) - execSync(`git commit -m "Upgraded ${name} from ${from} to ${to}"`,{stdio: 'inherit'}) + execSync(`git commit -m "Upgrade ${name} from ${from} to ${to}"`,{stdio: 'inherit'}) break; case true: From 1ce6b6ff95f5fc78847ea6f4bc5b3c4a6080aea8 Mon Sep 17 00:00:00 2001 From: Olavi Haapala Date: Mon, 16 Sep 2019 19:57:20 +0300 Subject: [PATCH 6/9] Revert "Make commit the default" This reverts commit 20d34de220298ab9eb7cea02aaad44b5a0a98dcc. --- src/commands/check.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/check.js b/src/commands/check.js index e99b9c7..2832767 100644 --- a/src/commands/check.js +++ b/src/commands/check.js @@ -154,8 +154,8 @@ export const handler = catchAsyncError(async opts => { message: `${changelogUrl === undefined ? 'U' : 'So, u'}pdate "${name}" in package.json ` + `from ${from} to ${colorizeDiff(from, to)}?`, choices: _.compact([ - {name: 'Yes and create a separate commit', value: 'commit'}, {name: 'Yes', value: true}, + {name: 'Yes and create a separate commit', value: 'commit'}, {name: 'No', value: false}, // Don't show this option if we couldn't find module's changelog url (changelogUrl !== null) && From 35767e73252d27ffc0fc30c5f7ed040ad2ac115c Mon Sep 17 00:00:00 2001 From: Olavi Haapala Date: Wed, 15 Jan 2020 17:27:41 +0200 Subject: [PATCH 7/9] Use yarn or npm based on the existence of corresponding lock files --- src/commands/check.js | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/commands/check.js b/src/commands/check.js index 2832767..ea970f5 100644 --- a/src/commands/check.js +++ b/src/commands/check.js @@ -1,4 +1,4 @@ -import {writeFileSync} from 'fs'; +import {writeFileSync, existsSync} from 'fs'; import _ from 'lodash'; import {flow, map, partition} from 'lodash/fp'; @@ -238,10 +238,25 @@ export const handler = catchAsyncError(async opts => { // Adding newline to the end of file `${JSON.stringify(packageJson, null, indent)}\n` ); - // Assume yarn for now - execSync('yarn',{stdio: 'inherit'}) - execSync('git add package.json yarn.lock',{stdio: 'inherit'}) - execSync(`git commit -m "Upgrade ${name} from ${from} to ${to}"`,{stdio: 'inherit'}) + + try { + if (existsSync('yarn.lock')) { + // Assume the user wants to use yarn + execSync('yarn', {stdio: 'inherit'}) + execSync('git add package.json yarn.lock', {stdio: 'inherit'}) + } else if (existsSync('package-lock.json')) { + // Use npm and package-lock.json + execSync('npm install', {stdio: 'inherit'}) + execSync('git add package.json package-lock.json', {stdio: 'inherit'}) + } else { + // Default to only using npm install and not including a lock file + execSync('npm install', {stdio: 'inherit'}) + execSync('git add package.json', {stdio: 'inherit'}) + } + execSync(`git commit -m "Upgrade ${name} from ${from} to ${to}"`,{stdio: 'inherit'}) + } catch(err) { + console.error(err) + } break; case true: From 9995d7c4f1212ed2cb780da31cf95844c43dc049 Mon Sep 17 00:00:00 2001 From: Olavi Haapala Date: Wed, 15 Jan 2020 17:52:09 +0200 Subject: [PATCH 8/9] Empty the list of packages to be updated after updating and commiting --- src/commands/check.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/commands/check.js b/src/commands/check.js index ea970f5..44e6c4c 100644 --- a/src/commands/check.js +++ b/src/commands/check.js @@ -254,6 +254,8 @@ export const handler = catchAsyncError(async opts => { execSync('git add package.json', {stdio: 'inherit'}) } execSync(`git commit -m "Upgrade ${name} from ${from} to ${to}"`,{stdio: 'inherit'}) + // Clean the list of packages to be updated after updating and commiting + updatedModules.splice(0, updatedModules.length); } catch(err) { console.error(err) } From 2ff6903c46a2f375490201b9d70674b8a8a8c008 Mon Sep 17 00:00:00 2001 From: Olavi Haapala Date: Wed, 15 Jan 2020 17:52:27 +0200 Subject: [PATCH 9/9] Change the wording and add semicolons --- src/commands/check.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/commands/check.js b/src/commands/check.js index 44e6c4c..9b2f17b 100644 --- a/src/commands/check.js +++ b/src/commands/check.js @@ -155,7 +155,7 @@ export const handler = catchAsyncError(async opts => { `from ${from} to ${colorizeDiff(from, to)}?`, choices: _.compact([ {name: 'Yes', value: true}, - {name: 'Yes and create a separate commit', value: 'commit'}, + {name: 'Update immediately and create a separate commit', value: 'commit'}, {name: 'No', value: false}, // Don't show this option if we couldn't find module's changelog url (changelogUrl !== null) && @@ -242,18 +242,18 @@ export const handler = catchAsyncError(async opts => { try { if (existsSync('yarn.lock')) { // Assume the user wants to use yarn - execSync('yarn', {stdio: 'inherit'}) - execSync('git add package.json yarn.lock', {stdio: 'inherit'}) + execSync('yarn', {stdio: 'inherit'}); + execSync('git add package.json yarn.lock', {stdio: 'inherit'}); } else if (existsSync('package-lock.json')) { // Use npm and package-lock.json - execSync('npm install', {stdio: 'inherit'}) - execSync('git add package.json package-lock.json', {stdio: 'inherit'}) + execSync('npm install', {stdio: 'inherit'}); + execSync('git add package.json package-lock.json', {stdio: 'inherit'}); } else { // Default to only using npm install and not including a lock file - execSync('npm install', {stdio: 'inherit'}) - execSync('git add package.json', {stdio: 'inherit'}) + execSync('npm install', {stdio: 'inherit'}); + execSync('git add package.json', {stdio: 'inherit'}); } - execSync(`git commit -m "Upgrade ${name} from ${from} to ${to}"`,{stdio: 'inherit'}) + execSync(`git commit -m "Upgrade ${name} from ${from} to ${to}"`,{stdio: 'inherit'}); // Clean the list of packages to be updated after updating and commiting updatedModules.splice(0, updatedModules.length); } catch(err) {