-
Notifications
You must be signed in to change notification settings - Fork 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
WIP: Create separate commits per upgraded package #39
base: master
Are you sure you want to change the base?
Changes from all commits
5fdaaca
608022c
20d34de
5f84495
5897e9f
1ce6b6f
35767e7
9995d7c
2ff6903
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import {writeFileSync} from 'fs'; | ||
import {writeFileSync, existsSync} from 'fs'; | ||
|
||
import _ from 'lodash'; | ||
import {flow, map, partition} from 'lodash/fp'; | ||
|
@@ -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: 'Update immediately and create a separate commit', value: 'commit'}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's better move it below |
||
{name: 'No', value: false}, | ||
// Don't show this option if we couldn't find module's changelog url | ||
(changelogUrl !== null) && | ||
|
@@ -218,6 +220,47 @@ 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` + | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It will always show a single package, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, should update the text |
||
createUpdatedModulesTable(updatedModules) + | ||
'\n' | ||
); | ||
|
||
const {indent} = detectIndent(packageSource); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's move this block of code into a separate function e.g. |
||
writeFileSync( | ||
packageFile, | ||
// Adding newline to the end of file | ||
`${JSON.stringify(packageJson, null, indent)}\n` | ||
); | ||
|
||
try { | ||
if (existsSync('yarn.lock')) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need to make this check every time, right? It can be done only once. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True |
||
// 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'}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think it's right to generate a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea |
||
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not just |
||
} catch(err) { | ||
console.error(err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we need to show more user-friendly errors e.g. |
||
} | ||
break; | ||
|
||
case true: | ||
updatedModules.push(outdatedModule); | ||
setModuleVersion(name, to, packageJson); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's move it below
import {writeFileSync, existsSync} from 'fs'