Skip to content

Commit b242d7e

Browse files
committed
feat(cmd): add node/ghost deprecation checks
1 parent 15122c9 commit b242d7e

File tree

6 files changed

+100
-8
lines changed

6 files changed

+100
-8
lines changed

lib/command.js

+7
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,14 @@ class Command {
174174
debug('loading operating system information');
175175
await ui.run(() => system.loadOsInfo(), 'Inspecting operating system', {clear: true});
176176

177+
if (!this.skipDeprecationCheck) {
178+
debug('running deprecation checks');
179+
const deprecationChecks = require('./utils/deprecation-checks');
180+
await ui.run(() => deprecationChecks(ui, system), 'Checking for deprecations', {clear: true});
181+
}
182+
177183
if (this.runPreChecks) {
184+
debug('running pre-checks');
178185
const preChecks = require('./utils/pre-checks');
179186
await preChecks(ui, system);
180187
}

lib/commands/run.js

+1
Original file line numberDiff line numberDiff line change
@@ -118,5 +118,6 @@ class RunCommand extends Command {
118118
}
119119

120120
RunCommand.description = 'Run a Ghost instance directly (used by process managers and for debugging)';
121+
RunCommand.skipDeprecationCheck = true;
121122

122123
module.exports = RunCommand;

lib/utils/deprecation-checks.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const semver = require('semver');
2+
const boxen = require('boxen');
3+
const chalk = require('chalk');
4+
5+
const nodeDeprecated = () => boxen(chalk.yellow(`
6+
The current Node.js version (${process.versions.node}) has reached end-of-life status.
7+
Ghost-CLI will drop support for this Node.js version in an upcoming release, please update your Node.js version.
8+
See ${chalk.cyan('https://ghost.org/docs/faq/node-versions/')}.
9+
`.trim()), {borderColor: 'yellow', align: 'center'});
10+
11+
const ghostDeprecated = () => boxen(chalk.yellow(`
12+
Ghost 2.x has reached end-of-life status.
13+
Ghost-CLI will drop support for unmaintained Ghost versions in an upcoming release, please update your Ghost version.
14+
See ${chalk.cyan('https://ghost.org/docs/faq/major-versions-lts/')}.
15+
`.trim()), {borderColor: 'yellow', align: 'center'});
16+
17+
async function deprecationChecks(ui, system) {
18+
if (semver.lt(process.versions.node, '12.0.0')) {
19+
ui.log(nodeDeprecated());
20+
}
21+
22+
const showGhostDeprecation = (await system.getAllInstances(false)).some(instance => semver.lt(instance.version, '3.0.0'));
23+
if (showGhostDeprecation) {
24+
ui.log(ghostDeprecated());
25+
}
26+
}
27+
28+
module.exports = deprecationChecks;

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"abbrev": "1.1.1",
4747
"adm-zip": "0.5.5",
4848
"bluebird": "3.7.2",
49+
"boxen": "5.0.1",
4950
"chalk": "4.1.1",
5051
"cli-table3": "0.5.0",
5152
"debug": "4.3.1",

test/unit/command-spec.js

+20-7
Original file line numberDiff line numberDiff line change
@@ -312,10 +312,12 @@ describe('Unit: Command', function () {
312312
const setEnvironmentStub = sinon.stub();
313313
const loadOsInfo = sinon.stub().resolves();
314314
const systemStub = sinon.stub().returns({setEnvironment: setEnvironmentStub, loadOsInfo});
315+
const deprecationChecks = sinon.stub().resolves();
315316

316317
const Command = proxyquire(modulePath, {
317318
'./ui': uiStub,
318-
'./system': systemStub
319+
'./system': systemStub,
320+
'./utils/deprecation-checks': deprecationChecks
319321
});
320322

321323
class TestCommand extends Command {}
@@ -339,8 +341,9 @@ describe('Unit: Command', function () {
339341
expect(setEnvironmentStub.calledWithExactly(true, true)).to.be.true;
340342
expect(systemStub.calledOnce).to.be.true;
341343
expect(systemStub.calledWithExactly({ui: true, run}, [{extensiona: true}])).to.be.true;
342-
expect(run.calledOnce).to.be.true;
344+
expect(run.calledTwice).to.be.true;
343345
expect(loadOsInfo.calledOnce).to.be.true;
346+
expect(deprecationChecks.calledOnce).to.be.true;
344347
expect(runStub.calledOnce).to.be.true;
345348
expect(runStub.calledWithExactly({verbose: true, prompt: true, development: true, auto: false})).to.be.true;
346349
});
@@ -351,16 +354,19 @@ describe('Unit: Command', function () {
351354
const setEnvironmentStub = sinon.stub();
352355
const loadOsInfo = sinon.stub().resolves();
353356
const systemStub = sinon.stub().returns({setEnvironment: setEnvironmentStub, loadOsInfo});
357+
const deprecationChecks = sinon.stub().resolves();
354358

355359
const Command = proxyquire(modulePath, {
356360
'./ui': uiStub,
357-
'./system': systemStub
361+
'./system': systemStub,
362+
'./utils/deprecation-checks': deprecationChecks
358363
});
359364

360365
class TestCommand extends Command {
361366
cleanup() {}
362367
}
363368
TestCommand.global = true;
369+
TestCommand.skipDeprecationCheck = true;
364370

365371
const runStub = sinon.stub(TestCommand.prototype, 'run');
366372
const onStub = sinon.stub(process, 'on').returnsThis();
@@ -384,6 +390,7 @@ describe('Unit: Command', function () {
384390
expect(systemStub.calledWithExactly({ui: true, run}, [{extensiona: true}])).to.be.true;
385391
expect(run.calledOnce).to.be.true;
386392
expect(loadOsInfo.calledOnce).to.be.true;
393+
expect(deprecationChecks.called).to.be.false;
387394
expect(runStub.calledOnce).to.be.true;
388395
expect(runStub.calledWithExactly({verbose: false, prompt: false, development: false, auto: true})).to.be.true;
389396
expect(onStub.calledThrice).to.be.true;
@@ -398,12 +405,14 @@ describe('Unit: Command', function () {
398405
const setEnvironmentStub = sinon.stub();
399406
const loadOsInfo = sinon.stub().resolves();
400407
const systemStub = sinon.stub().returns({setEnvironment: setEnvironmentStub, loadOsInfo});
408+
const deprecationChecks = sinon.stub().resolves();
401409
const preChecksStub = sinon.stub().resolves();
402410

403411
const Command = proxyquire(modulePath, {
404412
'./ui': uiStub,
405413
'./system': systemStub,
406-
'./utils/pre-checks': preChecksStub
414+
'./utils/pre-checks': preChecksStub,
415+
'./utils/deprecation-checks': deprecationChecks
407416
});
408417

409418
class TestCommand extends Command {}
@@ -429,8 +438,9 @@ describe('Unit: Command', function () {
429438
expect(setEnvironmentStub.calledWithExactly(true, true)).to.be.true;
430439
expect(systemStub.calledOnce).to.be.true;
431440
expect(systemStub.calledWithExactly({ui: true, run}, [{extensiona: true}])).to.be.true;
432-
expect(run.calledOnce).to.be.true;
441+
expect(run.calledTwice).to.be.true;
433442
expect(loadOsInfo.calledOnce).to.be.true;
443+
expect(deprecationChecks.calledOnce).to.be.true;
434444
expect(preChecksStub.calledOnce).to.be.true;
435445
expect(preChecksStub.calledWithExactly({ui: true, run}, {setEnvironment: setEnvironmentStub, loadOsInfo})).to.be.true;
436446
expect(runStub.calledOnce).to.be.true;
@@ -444,10 +454,12 @@ describe('Unit: Command', function () {
444454
const loadOsInfo = sinon.stub().resolves();
445455
const setEnvironmentStub = sinon.stub();
446456
const systemStub = sinon.stub().returns({setEnvironment: setEnvironmentStub, loadOsInfo});
457+
const deprecationChecks = sinon.stub().resolves();
447458

448459
const Command = proxyquire(modulePath, {
449460
'./ui': uiStub,
450-
'./system': systemStub
461+
'./system': systemStub,
462+
'./utils/deprecation-checks': deprecationChecks
451463
});
452464

453465
class TestCommand extends Command {
@@ -477,8 +489,9 @@ describe('Unit: Command', function () {
477489
expect(setEnvironmentStub.calledWithExactly(false, true)).to.be.true;
478490
expect(systemStub.calledOnce).to.be.true;
479491
expect(systemStub.calledWithExactly({error: errorStub, run}, [{extensiona: true}])).to.be.true;
480-
expect(run.calledOnce).to.be.true;
492+
expect(run.calledTwice).to.be.true;
481493
expect(loadOsInfo.calledOnce).to.be.true;
494+
expect(deprecationChecks.calledOnce).to.be.true;
482495
expect(runStub.calledOnce).to.be.true;
483496
expect(runStub.calledWithExactly({verbose: false, prompt: false, development: false, auto: false})).to.be.true;
484497
expect(errorStub.calledOnce).to.be.true;

yarn.lock

+43-1
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,13 @@ ajv@^6.12.4:
362362
json-schema-traverse "^0.4.1"
363363
uri-js "^4.2.2"
364364

365+
ansi-align@^3.0.0:
366+
version "3.0.0"
367+
resolved "https://registry.yarnpkg.com/ansi-align/-/ansi-align-3.0.0.tgz#b536b371cf687caaef236c18d3e21fe3797467cb"
368+
integrity sha512-ZpClVKqXN3RGBmKibdfWzqCY4lnjEuoNzU5T0oEFpfd/z5qJHVarukridD4juLO2FXMiwUQxr9WqQtaYa8XRYw==
369+
dependencies:
370+
string-width "^3.0.0"
371+
365372
[email protected], ansi-colors@^4.1.1:
366373
version "4.1.1"
367374
resolved "https://registry.yarnpkg.com/ansi-colors/-/ansi-colors-4.1.1.tgz#cbb9ae256bf750af1eab344f229aa27fe94ba348"
@@ -582,6 +589,20 @@ [email protected]:
582589
resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.7.2.tgz#9f229c15be272454ffa973ace0dbee79a1b0c36f"
583590
integrity sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg==
584591

592+
593+
version "5.0.1"
594+
resolved "https://registry.yarnpkg.com/boxen/-/boxen-5.0.1.tgz#657528bdd3f59a772b8279b831f27ec2c744664b"
595+
integrity sha512-49VBlw+PrWEF51aCmy7QIteYPIFZxSpvqBdP/2itCPPlJ49kj9zg/XPRFrdkne2W+CfwXUls8exMvu1RysZpKA==
596+
dependencies:
597+
ansi-align "^3.0.0"
598+
camelcase "^6.2.0"
599+
chalk "^4.1.0"
600+
cli-boxes "^2.2.1"
601+
string-width "^4.2.0"
602+
type-fest "^0.20.2"
603+
widest-line "^3.1.0"
604+
wrap-ansi "^7.0.0"
605+
585606
brace-expansion@^1.1.7:
586607
version "1.1.11"
587608
resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd"
@@ -711,7 +732,7 @@ camelcase@^5.0.0, camelcase@^5.3.1:
711732
resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-5.3.1.tgz#e3c9b31569e106811df242f715725a1f4c494320"
712733
integrity sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==
713734

714-
camelcase@^6.0.0:
735+
camelcase@^6.0.0, camelcase@^6.2.0:
715736
version "6.2.0"
716737
resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-6.2.0.tgz#924af881c9d525ac9d87f40d964e5cea982a1809"
717738
integrity sha512-c7wVvbw3f37nuobQNtgsgG9POC9qMbNuMQmTCqZv23b6MIz0fcYpBiOlv9gEN/hdLdnZTDQhg6e9Dq5M1vKvfg==
@@ -806,6 +827,11 @@ clean-stack@^2.0.0:
806827
resolved "https://registry.yarnpkg.com/clean-stack/-/clean-stack-2.2.0.tgz#ee8472dbb129e727b31e8a10a427dee9dfe4008b"
807828
integrity sha512-4diC9HaTE+KRAMWhDhrGOECgWZxoevMc5TlkObMqNSsVU62PYzXZ/SMTjzyGAFF1YusgxGcSWTEXBhp0CPwQ1A==
808829

830+
cli-boxes@^2.2.1:
831+
version "2.2.1"
832+
resolved "https://registry.yarnpkg.com/cli-boxes/-/cli-boxes-2.2.1.tgz#ddd5035d25094fce220e9cab40a45840a440318f"
833+
integrity sha512-y4coMcylgSCdVinjiDBuR8PCC2bLjyGTwEmPb9NHR/QaNU6EUOXcTY/s6VjGMD6ENSEaeQYHCY0GNGS5jfMwPw==
834+
809835
cli-cursor@^2.0.0, cli-cursor@^2.1.0:
810836
version "2.1.0"
811837
resolved "https://registry.yarnpkg.com/cli-cursor/-/cli-cursor-2.1.0.tgz#b35dac376479facc3e94747d41d0d0f5238ffcb5"
@@ -4667,6 +4693,15 @@ string-width@^3.0.0:
46674693
is-fullwidth-code-point "^2.0.0"
46684694
strip-ansi "^5.1.0"
46694695

4696+
string-width@^4.0.0:
4697+
version "4.2.2"
4698+
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.2.tgz#dafd4f9559a7585cfba529c6a0a4f73488ebd4c5"
4699+
integrity sha512-XBJbT3N4JhVumXE0eoLU9DCjcaF92KLNqTmFCnG1pf8duUxFGwtP6AD6nkjw9a3IdiRtL3E2w3JDiE/xi3vOeA==
4700+
dependencies:
4701+
emoji-regex "^8.0.0"
4702+
is-fullwidth-code-point "^3.0.0"
4703+
strip-ansi "^6.0.0"
4704+
46704705
string-width@^4.1.0, string-width@^4.2.0:
46714706
version "4.2.0"
46724707
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.0.tgz#952182c46cc7b2c313d1596e623992bd163b72b5"
@@ -5177,6 +5212,13 @@ [email protected]:
51775212
dependencies:
51785213
string-width "^1.0.2 || 2"
51795214

5215+
widest-line@^3.1.0:
5216+
version "3.1.0"
5217+
resolved "https://registry.yarnpkg.com/widest-line/-/widest-line-3.1.0.tgz#8292333bbf66cb45ff0de1603b136b7ae1496eca"
5218+
integrity sha512-NsmoXalsWVDMGupxZ5R08ka9flZjjiLvHVAWYOKtiKM8ujtZWr9cRffak+uSE48+Ob8ObalXpwyeUiyDD6QFgg==
5219+
dependencies:
5220+
string-width "^4.0.0"
5221+
51805222
word-wrap@^1.2.3, word-wrap@~1.2.3:
51815223
version "1.2.3"
51825224
resolved "https://registry.yarnpkg.com/word-wrap/-/word-wrap-1.2.3.tgz#610636f6b1f703891bd34771ccb17fb93b47079c"

0 commit comments

Comments
 (0)