Skip to content

Commit 89cae6d

Browse files
committed
Add full upgrade script
1 parent 83f0d60 commit 89cae6d

File tree

3 files changed

+77
-42
lines changed

3 files changed

+77
-42
lines changed

gulpfile.js

Lines changed: 66 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const gulp = require('gulp');
44
const log = require('fancy-log');
5+
const chalk = require('chalk');
56
const ejs = require('gulp-ejs');
67
const zip = require('gulp-zip');
78
const mergeStream = require('merge-stream');
@@ -59,7 +60,9 @@ gulp.task('outdated', () => {
5960
.sort(({ name: a }, { name: b }) => compareStrings(a, b));
6061

6162
if (validUpgrades.length === 0) {
62-
log.warn(`All ${allUpgrades.length} packages up-to-date`);
63+
log.warn(
64+
chalk`All {yellow ${allUpgrades.length}} packages up-to-date`
65+
);
6366

6467
return;
6568
}
@@ -69,41 +72,71 @@ ${formatPackageUpgrades(validUpgrades)}`);
6972
});
7073
});
7174

72-
gulp.task('upgrade-patch', () => {
73-
const allUpgradesPromises = libraries.map(library =>
74-
getUpgradeVersions(library).then(upgrades =>
75-
Object.assign(library, { upgrades })
76-
)
77-
);
78-
79-
return Promise.all(allUpgradesPromises).then(allUpgrades => {
80-
const validUpgrades = allUpgrades.filter(({ upgrades }) =>
81-
upgrades.get('patch')
75+
['patch', 'minor', 'major'].forEach(upgradeType =>
76+
gulp.task(`upgrade-${upgradeType}`, () => {
77+
const allUpgradesPromises = libraries.map(library =>
78+
getUpgradeVersions(library).then(upgrades =>
79+
Object.assign(library, { upgrades })
80+
)
8281
);
8382

84-
if (validUpgrades.length === 0) {
85-
log.warn(`No patch upgrades to process`);
83+
return Promise.all(allUpgradesPromises).then(allUpgrades => {
84+
const validUpgrades = allUpgrades.filter(({ upgrades }) =>
85+
upgrades.get(upgradeType)
86+
);
8687

87-
return;
88-
}
88+
if (validUpgrades.length === 0) {
89+
log.warn(`No ${upgradeType} upgrades to process`);
90+
91+
return;
92+
}
93+
94+
const upgradeWarnings = validUpgrades.map(
95+
({ name, version, upgrades, manifest }) => {
96+
const newVersion = upgrades.get(upgradeType);
97+
log(
98+
chalk`Upgrading {magenta ${name}} from {yellow ${version}} to {yellow ${newVersion}}`
99+
);
100+
101+
const spawn = require('cross-spawn');
102+
spawn.sync(
103+
'yarn',
104+
[
105+
'upgrade',
106+
'--exact',
107+
'--non-interactive',
108+
`${name}@${newVersion}`,
109+
],
110+
{
111+
stdio: 'inherit',
112+
}
113+
);
114+
spawn.sync(
115+
'git',
116+
[
117+
'commit',
118+
'--all',
119+
'--message',
120+
`Upgrade ${name} to ${newVersion} (from ${version})`,
121+
],
122+
{ stdio: 'inherit' }
123+
);
124+
125+
if (
126+
manifest.files
127+
.concat(manifest.resources || [])
128+
.some(f => !f.startsWith('node_modules'))
129+
) {
130+
return name;
131+
}
132+
}
133+
);
89134

90-
validUpgrades.forEach(({ name, version, upgrades }) => {
91-
const patchVersion = upgrades.get('patch');
92-
log(`Upgrading ${name} from ${version} to ${patchVersion}`);
93-
94-
const eos = require('end-of-stream');
95-
const { spawn } = require('child_process');
96-
eos(
97-
spawn('yarn', ['upgrade', `${name}@${patchVersion}`]),
98-
err =>
99-
err
100-
? log.error(err)
101-
: spawn('git', [
102-
'commit',
103-
'-am',
104-
`Upgraded ${name} from ${version} to ${patchVersion}`,
105-
])
135+
upgradeWarnings.forEach(libraryName =>
136+
log.warn(
137+
chalk`The library {magenta ${libraryName}} has some resources that do not come from {gray node_modules}, please verify that the upgrade was complete`
138+
)
106139
);
107140
});
108-
});
109-
});
141+
})
142+
);

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"scripts": {
99
"package": "gulp",
1010
"outdated": "gulp outdated",
11+
"upgrade": "gulp upgrade-patch && gulp upgrade-minor && gulp upgrade-major",
1112
"new": "yo ./_new"
1213
},
1314
"dependencies": {
@@ -78,6 +79,7 @@
7879
"devDependencies": {
7980
"chalk": "^2.4.1",
8081
"cliui": "4.1.0",
82+
"cross-spawn": "6.0.5",
8183
"fancy-log": "1.3.2",
8284
"glob": "^7.1.2",
8385
"globby": "^8.0.1",

yarn.lock

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -789,15 +789,7 @@ cross-spawn-async@^2.1.1:
789789
lru-cache "^4.0.0"
790790
which "^1.2.8"
791791

792-
cross-spawn@^5.0.1:
793-
version "5.1.0"
794-
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-5.1.0.tgz#e8bd0efee58fcff6f8f94510a0a554bbfa235449"
795-
dependencies:
796-
lru-cache "^4.0.1"
797-
shebang-command "^1.2.0"
798-
which "^1.2.9"
799-
800-
cross-spawn@^6.0.5:
792+
cross-spawn@6.0.5, cross-spawn@^6.0.5:
801793
version "6.0.5"
802794
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-6.0.5.tgz#4a5ec7c64dfae22c3a14124dbacdee846d80cbc4"
803795
dependencies:
@@ -807,6 +799,14 @@ cross-spawn@^6.0.5:
807799
shebang-command "^1.2.0"
808800
which "^1.2.9"
809801

802+
cross-spawn@^5.0.1:
803+
version "5.1.0"
804+
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-5.1.0.tgz#e8bd0efee58fcff6f8f94510a0a554bbfa235449"
805+
dependencies:
806+
lru-cache "^4.0.1"
807+
shebang-command "^1.2.0"
808+
which "^1.2.9"
809+
810810
cryptiles@2.x.x:
811811
version "2.0.5"
812812
resolved "https://registry.yarnpkg.com/cryptiles/-/cryptiles-2.0.5.tgz#3bdfecdc608147c1c67202fa291e7dca59eaa3b8"

0 commit comments

Comments
 (0)